diff --git a/src/__tests__/try-path.test.ts b/src/__tests__/try-path.test.ts index f681362..deb69a0 100644 --- a/src/__tests__/try-path.test.ts +++ b/src/__tests__/try-path.test.ts @@ -10,6 +10,16 @@ describe("mapping-entry", () => { { pattern: "pre/fix/*", paths: [join("/absolute", "base", "url", "foo3")] }, { pattern: "*", paths: [join("/absolute", "base", "url", "foo1")] }, ]; + const abosolutePathMappingsStarstWithSlash = [ + { + pattern: "/opt/*", + paths: [join("/absolute", "src", "aws-layer")], + }, + { + pattern: "*", + paths: [join("/absolute", "src")], + }, + ]; it("should return no paths for relative requested module", () => { const result = getPathsToTry( [".ts", "tsx"], @@ -125,6 +135,50 @@ describe("mapping-entry", () => { }, ]); }); + + it("should resolve paths starting with a slash", () => { + const result = getPathsToTry( + [".ts"], + abosolutePathMappingsStarstWithSlash, + "/opt/utils" + ); + expect(result).toEqual([ + // "opt/*" + { + path: join("/absolute", "src", "aws-layer"), + type: "file", + }, + { + path: join("/absolute", "src", "aws-layer.ts"), + type: "extension", + }, + { + path: join("/absolute", "src", "aws-layer", "package.json"), + type: "package", + }, + { + path: join("/absolute", "src", "aws-layer", "index.ts"), + type: "index", + }, + // "*" + { + path: join("/absolute", "src"), + type: "file", + }, + { + path: join("/absolute", "src.ts"), + type: "extension", + }, + { + path: join("/absolute", "src", "package.json"), + type: "package", + }, + { + path: join("/absolute", "src", "index.ts"), + type: "index", + }, + ]); + }); }); // describe("match-star", () => { diff --git a/src/try-path.ts b/src/try-path.ts index bf72304..f7ebede 100644 --- a/src/try-path.ts +++ b/src/try-path.ts @@ -20,12 +20,7 @@ export function getPathsToTry( absolutePathMappings: ReadonlyArray, requestedModule: string ): ReadonlyArray | undefined { - if ( - !absolutePathMappings || - !requestedModule || - requestedModule[0] === "." || - requestedModule[0] === path.sep - ) { + if (!absolutePathMappings || !requestedModule || requestedModule[0] === ".") { return undefined; }