mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Fixes #23569 ## Summary HTML imports require bundling to work correctly, as they need to process and transform linked assets (JS/CSS). When `--no-bundle` is used, no bundling or transformation happens, which causes a crash. This change adds validation to detect HTML entrypoints when `--no-bundle` is used and provides a clear error message explaining that "HTML imports are only supported when bundling". ## Changes - Added validation in `src/cli/build_command.zig` to check for HTML entrypoints when `--no-bundle` flag is used - Shows clear error message: "HTML imports are only supported when bundling" - Added regression tests in `test/regression/issue/23569.test.ts` ## Test Plan ### Before ```bash $ bun build ./index.html --no-bundle # Crashes without helpful error ``` ### After ```bash $ bun build ./index.html --no-bundle error: HTML imports are only supported when bundling ``` ### Tests - ✅ Test with `--no-bundle` flag errors correctly - ✅ Test with `--no-bundle --outdir` errors correctly - ✅ Test without `--no-bundle` works normally - ✅ All 3 regression tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com>
87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
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");
|
|
});
|