Fix tsconfig path longest prefix matching (#8892)

This commit is contained in:
James Anderson
2024-02-14 16:23:45 +00:00
committed by GitHub
parent 82a07430ed
commit 00cc2eae67
4 changed files with 7 additions and 3 deletions

View File

@@ -2877,8 +2877,8 @@ pub const Resolver = struct {
// because we want the output to always be deterministic
if (strings.startsWith(path, prefix) and
strings.endsWith(path, suffix) and
(prefix.len >= longest_match_prefix_length and
suffix.len > longest_match_suffix_length))
(prefix.len > longest_match_prefix_length or
(prefix.len == longest_match_prefix_length and suffix.len > longest_match_suffix_length)))
{
longest_match_prefix_length = @as(i32, @intCast(prefix.len));
longest_match_suffix_length = @as(i32, @intCast(suffix.len));

View File

@@ -0,0 +1,2 @@
// this file is used in resolve.test.js
export default {};

View File

@@ -71,6 +71,7 @@ it("import.meta.resolve", async () => {
expect(await import.meta.resolve("foo/bar")).toBe(join(import.meta.path, "../baz.js"));
expect(await import.meta.resolve("@faasjs/baz")).toBe(join(import.meta.path, "../baz.js"));
expect(await import.meta.resolve("@faasjs/bar")).toBe(join(import.meta.path, "../bar/src/index.js"));
expect(await import.meta.resolve("@faasjs/larger/bar")).toBe(join(import.meta.path, "../bar/larger-index.js"));
// works with package.json "exports"
expect(await import.meta.resolve("package-json-exports/baz")).toBe(

View File

@@ -26,7 +26,8 @@
"node-harness": ["js/node/harness.ts"],
"deno:harness": ["js/deno/harness.ts"],
"foo/bar": ["js/bun/resolve/baz.js"],
"@faasjs/*": ["js/bun/resolve/*.js", "js/bun/resolve/*/src/index.js"]
"@faasjs/*": ["js/bun/resolve/*.js", "js/bun/resolve/*/src/index.js"],
"@faasjs/larger/*": ["js/bun/resolve/*/larger-index.js"]
}
},