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"); +});