Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
2800b80e3b fix(resolver): resolve tsconfig paths with .js extension pattern correctly
When matching tsconfig paths like `@src/*.js` -> `./src/*.ts`, the
resolver was incorrectly appending the pattern suffix (`.js`) to the
resolved path. This caused paths like `./src/lib.ts/.js` instead of
`./src/lib.ts`.

The fix removes the erroneous append of `longest_match.suffix` since
`matched_text_with_suffix` already contains the complete suffix from
the target path in the tsconfig mapping.

Fixes #26193

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 15:22:15 +00:00
2 changed files with 69 additions and 1 deletions

View File

@@ -3089,7 +3089,6 @@ pub const Resolver = struct {
var parts = [_]string{
prefix,
if (matched_text_with_suffix_len > 0) std.mem.trimLeft(u8, matched_text_with_suffix[0..matched_text_with_suffix_len], "/") else "",
std.mem.trimLeft(u8, longest_match.suffix, "/"),
};
const absolute_original_path = r.fs.absBuf(
&parts,

View File

@@ -0,0 +1,69 @@
import { expect, test } from "bun:test";
import { bunEnv, bunExe, tempDir } from "harness";
// https://github.com/oven-sh/bun/issues/26193
// tsconfig paths with .js extension pattern were not resolved correctly
test("tsconfig paths with .js extension pattern resolves correctly", async () => {
using dir = tempDir("issue-26193", {
"tsconfig.json": JSON.stringify({
compilerOptions: {
module: "NodeNext",
moduleResolution: "NodeNext",
paths: {
"@src/*.js": ["./src/*.ts"],
},
},
}),
"src/lib.ts": `export const greeting = "Hello";`,
"main.ts": `import { greeting } from "@src/lib.js";
console.log(greeting);`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), "run", "main.ts"],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stdout.trim()).toBe("Hello");
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});
test("tsconfig paths with complex extension patterns", async () => {
using dir = tempDir("issue-26193-complex", {
"tsconfig.json": JSON.stringify({
compilerOptions: {
module: "NodeNext",
moduleResolution: "NodeNext",
paths: {
"@utils/*.js": ["./utils/*.ts"],
"@components/*.jsx": ["./components/*.tsx"],
},
},
}),
"utils/helper.ts": `export const helper = () => "helper";`,
"components/Button.tsx": `export const Button = () => "Button";`,
"main.ts": `import { helper } from "@utils/helper.js";
import { Button } from "@components/Button.jsx";
console.log(helper(), Button());`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), "run", "main.ts"],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stdout.trim()).toBe("helper Button");
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});