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
3 changes: 3 additions & 0 deletions src/Global.zig
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ pub fn exit(code: u32) noreturn {
bun.debug_allocator_data.backing = null;
}

// Flush output before exiting to ensure all messages are visible
Output.flush();

switch (Environment.os) {
.mac => std.c.exit(@bitCast(code)),
.windows => {
Expand Down
11 changes: 11 additions & 0 deletions src/cli/build_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ pub const BuildCommand = struct {
}
}

if (ctx.bundler_options.transform_only) {
// Check if any entry point is an HTML file
for (this_transpiler.options.entry_points) |entry_point| {
if (strings.hasSuffixComptime(entry_point, ".html")) {
Output.prettyErrorln("<r><red>error<r><d>:<r> HTML imports are only supported when bundling", .{});
Global.exit(1);
return;
}
}
}

if (ctx.bundler_options.outdir.len == 0 and !ctx.bundler_options.compile and fetcher == null) {
if (this_transpiler.options.entry_points.len > 1) {
Output.prettyErrorln("<r><red>error<r><d>:<r> Must use <b>--outdir<r> when specifying more than one entry point.", .{});
Expand Down
86 changes: 86 additions & 0 deletions test/regression/issue/23569.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { expect, test } from "bun:test";
import { bunEnv, bunExe, tempDir } from "harness";

test("bun build --no-bundle with HTML entrypoint should error with helpful message - issue #23569", async () => {
using dir = tempDir("23569-html-no-bundle", {
"index.html": `<!DOCTYPE html>
<html>
<head>
<script src="./script.js"></script>
</head>
<body>
<h1>Test</h1>
</body>
</html>`,
"script.js": `console.log('Hello');`,
});

await using proc = Bun.spawn({
cmd: [bunExe(), "build", "./index.html", "--no-bundle"],
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(exitCode).toBe(1);
expect(stderr).toContain("HTML imports are only supported when bundling");
});

test("bun build --no-bundle with HTML entrypoint and --outdir should also error - issue #23569", async () => {
using dir = tempDir("23569-html-no-bundle-outdir", {
"index.html": `<!DOCTYPE html>
<html>
<head>
<script src="./script.js"></script>
</head>
<body>
<h1>Test</h1>
</body>
</html>`,
"script.js": `console.log('Hello');`,
});

await using proc = Bun.spawn({
cmd: [bunExe(), "build", "./index.html", "--outdir", "./build", "--no-bundle"],
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(exitCode).toBe(1);
expect(stderr).toContain("HTML imports are only supported when bundling");
});

test("bun build with HTML entrypoint without --no-bundle should succeed", async () => {
using dir = tempDir("23569-html-bundle", {
"index.html": `<!DOCTYPE html>
<html>
<head>
<script src="./script.js"></script>
</head>
<body>
<h1>Test</h1>
</body>
</html>`,
"script.js": `console.log('Hello');`,
});

await using proc = Bun.spawn({
cmd: [bunExe(), "build", "./index.html", "--outdir", "./build"],
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(exitCode).toBe(0);
expect(stderr).not.toContain("HTML imports are only supported when bundling");
});