From a8b6b08f453bc6be94106a83d48e117dd5e8dd22 Mon Sep 17 00:00:00 2001 From: michelkaporin Date: Fri, 15 Oct 2021 09:50:56 +0200 Subject: [PATCH 1/2] fix: resolve relative bundle file path correctly [ROAD-329] --- src/files.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files.ts b/src/files.ts index 313524ea..21900fbd 100644 --- a/src/files.ts +++ b/src/files.ts @@ -351,7 +351,7 @@ export async function prepareExtendingBundle( } function getBundleFilePath(filePath: string, baseDir: string) { - const relPath = nodePath.relative(baseDir, filePath); + const relPath = baseDir ? nodePath.relative(baseDir, filePath) : filePath; // relPath without explicit base makes no sense const posixPath = !isWindows ? relPath : relPath.replace(/\\/g, '/'); return encodeURI(posixPath); } From e3bfccb0a76337ee121dab0f39b4546852a437d3 Mon Sep 17 00:00:00 2001 From: michelkaporin Date: Fri, 15 Oct 2021 10:10:27 +0200 Subject: [PATCH 2/2] test: getBundleFilePath --- src/files.ts | 2 +- tests/files.spec.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/files.ts b/src/files.ts index 21900fbd..7c040452 100644 --- a/src/files.ts +++ b/src/files.ts @@ -350,7 +350,7 @@ export async function prepareExtendingBundle( }; } -function getBundleFilePath(filePath: string, baseDir: string) { +export function getBundleFilePath(filePath: string, baseDir: string) { const relPath = baseDir ? nodePath.relative(baseDir, filePath) : filePath; // relPath without explicit base makes no sense const posixPath = !isWindows ? relPath : relPath.replace(/\\/g, '/'); return encodeURI(posixPath); diff --git a/tests/files.spec.ts b/tests/files.spec.ts index f0be83e9..5f029b2b 100644 --- a/tests/files.spec.ts +++ b/tests/files.spec.ts @@ -8,6 +8,7 @@ import { composeFilePayloads, parseFileIgnores, getFileInfo, + getBundleFilePath, } from '../src/files'; import { sampleProjectPath, supportedFiles, bundleFiles, bundleFilesFull, bundleFileIgnores } from './constants/sample'; @@ -113,4 +114,16 @@ describe('files', () => { const fileMeta = await getFileInfo(filePath, sampleProjectPath); expect(fileMeta?.hash).toEqual('3e2979852cc2e97f48f7e7973a8b0837eb73ed0485c868176bc3aa58c499f534'); }); + + it('obtains correct bundle file path if no baseDir specified', () => { + const baseDir = ''; + const darwinPath = '/Users/user/Git/goof/routes/index.js'; + expect(getBundleFilePath(darwinPath, baseDir)).toEqual(darwinPath); + + const linuxPath = '/home/user/Git/goof/routes/index.js'; + expect(getBundleFilePath(linuxPath, baseDir)).toEqual(linuxPath); + + const windowsPath = 'C:\\Users\\user\\Git\\goof\\index.js'; + expect(getBundleFilePath(windowsPath, baseDir)).toEqual(encodeURI(windowsPath)); + }) });