From 6e8a9996b162eeff327df94f98bcbf87dd58d356 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Feb 2026 14:22:01 +0000 Subject: [PATCH] fix: set dest_path for --no-bundle with --outdir When using `bun build --no-bundle --outdir`, the output file's dest_path was not being set, causing ENOENT error when trying to write to an empty filename. This fix computes dest_path by taking the input file's basename and replacing the extension with the appropriate output extension (e.g., .ts -> .js). Fixes #10370 https://claude.ai/code/session_01WTzMmxa1RL14NCnqw1scjn --- src/transpiler.zig | 4 ++ test/regression/issue/10370.test.ts | 64 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/regression/issue/10370.test.ts diff --git a/src/transpiler.zig b/src/transpiler.zig index 688c780038..7f41057a56 100644 --- a/src/transpiler.zig +++ b/src/transpiler.zig @@ -616,6 +616,9 @@ pub const Transpiler = struct { file_path.pretty = Linker.relative_paths_list.append(string, transpiler.fs.relativeTo(file_path.text)) catch unreachable; + const out_ext = transpiler.options.out_extensions.get(file_path.name.ext) orelse file_path.name.ext; + const dest_path = std.fmt.allocPrint(transpiler.allocator, "{s}{s}", .{ file_path.name.base, out_ext }) catch unreachable; + var output_file = options.OutputFile{ .src_path = file_path, .loader = loader, @@ -623,6 +626,7 @@ pub const Transpiler = struct { .side = null, .entry_point_index = null, .output_kind = .chunk, + .dest_path = dest_path, }; switch (loader) { diff --git a/test/regression/issue/10370.test.ts b/test/regression/issue/10370.test.ts new file mode 100644 index 0000000000..73798318fe --- /dev/null +++ b/test/regression/issue/10370.test.ts @@ -0,0 +1,64 @@ +import { expect, test } from "bun:test"; +import { bunEnv, bunExe, tempDir } from "harness"; +import { readdirSync, existsSync } from "fs"; +import { join } from "path"; + +test("bun build --no-bundle --outdir should output files correctly - issue #10370", async () => { + using dir = tempDir("10370-no-bundle-outdir", { + "index.ts": `console.log("hello from typescript");`, + }); + + await using proc = Bun.spawn({ + cmd: [bunExe(), "build", "./index.ts", "--no-bundle", "--outdir", "./dist"], + 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(stderr).not.toContain("error"); + expect(exitCode).toBe(0); + + // Verify the output file exists + const distDir = join(String(dir), "dist"); + expect(existsSync(distDir)).toBe(true); + + const files = readdirSync(distDir); + expect(files).toContain("index.js"); +}); + +test("bun build --no-bundle --outdir should handle .tsx extension - issue #10370", async () => { + using dir = tempDir("10370-no-bundle-outdir-tsx", { + "App.tsx": `export function App() { return
Hello
; }`, + }); + + await using proc = Bun.spawn({ + cmd: [bunExe(), "build", "./App.tsx", "--no-bundle", "--outdir", "./out"], + 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(stderr).not.toContain("error"); + expect(exitCode).toBe(0); + + // Verify the output file exists + const outDir = join(String(dir), "out"); + expect(existsSync(outDir)).toBe(true); + + const files = readdirSync(outDir); + expect(files).toContain("App.js"); +});