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
This commit is contained in:
Claude
2026-02-11 14:22:01 +00:00
parent 3a955bc824
commit 6e8a9996b1
2 changed files with 68 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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 <div>Hello</div>; }`,
});
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");
});