Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve relative bundle file path correctly [ROAD-329] #112

Merged
merged 2 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ export async function prepareExtendingBundle(
};
}

function getBundleFilePath(filePath: string, baseDir: string) {
const relPath = nodePath.relative(baseDir, filePath);
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);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
composeFilePayloads,
parseFileIgnores,
getFileInfo,
getBundleFilePath,
} from '../src/files';

import { sampleProjectPath, supportedFiles, bundleFiles, bundleFilesFull, bundleFileIgnores } from './constants/sample';
Expand Down Expand Up @@ -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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm afraid our engine will fail, if it receives this path.
can you please also add an explicit test for it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, stop, this is a reverse process. all good

expect(getBundleFilePath(windowsPath, baseDir)).toEqual(encodeURI(windowsPath));
})
});