Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/bundler/linker_context/generateChunksInParallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,20 +1076,19 @@ pub(crate) fn generate_chunks_in_parallel<const IS_DEV_SERVER: bool>(
..Default::default()
}));
} else {
// an error
// logger OOM-only
// Split-borrow — `static_route_visitor.c` holds a
// detached `&LinkerContext`; `log_disjoint` returns the
// disjoint `Transpiler.log` backref so no `&mut c` is
// materialized.
let _ = c.log_disjoint().add_error_fmt(
c.log_disjoint().add_error_fmt(
None,
bun_ast::Loc::EMPTY,
format_args!(
"Failed to generate bytecode for {}",
bstr::BStr::new(&chunk.final_rel_path)
),
);
return Err(crate::Error::BuildFailed);
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/bundler/linker_context/writeOutputFilesToDisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ pub(crate) fn write_output_files_to_disk(
Loader::Js
};

if loader.is_javascript_like() {
if matches!(chunk.content, Content::Javascript(_)) && loader.is_javascript_like() {
let mut fdpath = PathBuffer::uninit();
let source_provider_url = BunString::create_format(format_args!(
"{}{}",
Expand Down Expand Up @@ -493,6 +493,17 @@ pub(crate) fn write_output_files_to_disk(
source_index: IndexOptional::NONE,
bake_extra: BakeExtra::default(),
}));
} else {
// `log_disjoint`: split-borrow with `parse_graph` above.
c.log_disjoint().add_error_fmt(
None,
Loc::EMPTY,
format_args!(
"Failed to generate bytecode for {}",
bstr::BStr::new(&chunk.final_rel_path)
),
);
return Err(crate::Error::BuildFailed);
Comment thread
robobun marked this conversation as resolved.
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions test/bundler/bundler_compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,62 @@ describe("bundler", () => {
},
},
});
// https://github.com/oven-sh/bun/issues/15528
// When JSC rejects the bundled output (forced here by prepending a banner
// that JSC's parser cannot parse; bun's own parser never sees banner text),
// the build must exit non-zero instead of printing the error and then
// reporting success. Covers both the --compile path and the --outdir path
// (the latter previously swallowed the failure entirely).
for (const [name, extraArgs] of [
["compile/BytecodeFailureIsAnError", ["--compile", "--outfile", "./out"]],
["bytecode/OutdirBytecodeFailureIsAnError", ["--format=cjs", "--outdir", "./out"]],
] as const) {
test(name, async () => {
using dir = tempDir("bytecode-failure", {
"entry.ts": `console.log("Hello, world!");`,
});
await using proc = Bun.spawn({
cmd: [
bunExe(),
"build",
"./entry.ts",
"--bytecode",
"--target=bun",
"--banner",
"this is not valid js !!!",
...extraArgs,
],
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).toContain("error: Failed to generate bytecode");
expect(stdout).not.toContain("compile");
expect(exitCode).toBe(1);
});
}
// A CSS chunk created from a JS entry point has a JS-like loader. Bytecode
// must be skipped for it, not attempted and reported as a failure.
test("bytecode/OutdirBytecodeSkipsCssChunk", async () => {
using dir = tempDir("bytecode-css", {
"entry.ts": `import "./styles.css"; console.log(1);`,
"styles.css": `.foo { color: red }`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), "build", "./entry.ts", "--bytecode", "--target=bun", "--format=cjs", "--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(stdout).toContain("entry.js.jsc");
expect(stdout).toContain("entry.css");
expect(exitCode).toBe(0);
});

// `import defer * as ns from "..."` must not break bytecode generation.
// The bundler inlines the deferred module into the entry chunk (documented
Expand Down
Loading