diff --git a/src/utils/path.ts b/src/utils/path.ts index b34c6b0800d..caff7ae5980 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -249,6 +249,10 @@ export function join(...paths: string[]): string { * @returns a resolved path! */ export function resolve(...paths: string[]): string { + /** + * When normalizing, we should _not_ attempt to relativize the path returned by the native Node `resolve` method. When + * calculating the path from each of the string-based parts, Node does not prepend './' to the calculated path. + */ return normalizePath(path.resolve(...paths), false); } @@ -263,5 +267,9 @@ export function resolve(...paths: string[]): string { * @returns a normalized path! */ export function normalize(toNormalize: string): string { + /** + * When normalizing, we should _not_ attempt to relativize the path returned by the native Node `normalize` method. + * When calculating the path from each of the string-based parts, Node does not prepend './' to the calculated path. + */ return normalizePath(path.normalize(toNormalize), false); } diff --git a/src/utils/test/path.spec.ts b/src/utils/test/path.spec.ts index 2828a43e7c8..a0697b75945 100644 --- a/src/utils/test/path.spec.ts +++ b/src/utils/test/path.spec.ts @@ -164,6 +164,11 @@ describe('normalizeFsPathQuery', () => { }); it('normalize should always return a POSIX path', () => { + expect(normalize('')).toBe('.'); + expect(normalize('.')).toBe('.'); + expect(normalize('..')).toBe('..'); + expect(normalize('/')).toBe('/'); + expect(normalize('\\')).toBe('/'); // these examples taken from // https://nodejs.org/api/path.html#pathnormalizepath expect(normalize('\\temp\\\\foo\\bar\\..\\')).toBe('/temp/foo');