Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions src/bundler/LinkerContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,10 +1774,12 @@ impl<'a> LinkerContext<'a> {
.path_with_pretty_initialized(&source.path, arena)
.expect("OOM");
}
// Note: `Path::assert_pretty_is_valid` lives on the
// resolver-side `Path<'a>`; the logger `Path` has no
// such debug hook yet.
debug_assert!(source.path.text.as_ptr() != source.path.pretty.as_ptr());
// FileMap keys may be relative; when the computed pretty
// equals text, `dupe_alloc` aliases them and that's fine.
debug_assert!(
source.path.text.as_ptr() != source.path.pretty.as_ptr()
|| !bun_paths::is_absolute(source.path.text)
);

break 'brk source.path.pretty;
} else {
Expand Down
8 changes: 7 additions & 1 deletion src/bundler/bundle_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2583,7 +2583,13 @@ pub mod bv2_impl {
None => return Ok(None),
};

path.assert_file_path_is_absolute();
// FileMap keys are user-supplied and may be relative; they are lookup
// identities, not real fs paths, so the absolute invariant does not apply.
if bun_core::Environment::CI_ASSERT
&& !self.file_map.is_some_and(|fm| fm.contains(path.text))
{
path.assert_file_path_is_absolute();
}
// borrowck: get-then-put instead of a single get-or-put.
if self
.path_to_source_index_map(target)
Expand Down
74 changes: 73 additions & 1 deletion test/bundler/bundler_files.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { tempDir } from "harness";
import { bunEnv, bunExe, tempDir } from "harness";

describe("bundler files option", () => {
test("basic in-memory file bundling", async () => {
Expand Down Expand Up @@ -582,4 +582,76 @@
const output = await result.outputs[0].text();
expect(output).toContain("injected by plugin");
});

// The debug assertion that file-namespace paths are absolute does not apply
// to FileMap keys, which are user-supplied lookup identities and may be
// relative. Run in a subprocess so a regression (assertion panic in the
// bundle thread) fails this test instead of taking down the runner.

Check warning on line 589 in test/bundler/bundler_files.test.ts

View check run for this annotation

Claude / Claude Code Review

Code comment exceeds 3-line maximum

nit: this comment block is 4 lines; the root `CLAUDE.md` asks for code comments to stay at 3 lines max (and "Regression tests get exactly one comment: the issue URL"). Could tighten to something like: ```ts // FileMap keys are user-supplied identities and may be relative; run in a // subprocess so an assertion panic fails the test instead of killing the runner. ``` or just replace it with the PR link.
Comment thread
robobun marked this conversation as resolved.
Outdated
test.each(["./e.js", "e.js", "./src/e.js"])(
Comment thread
robobun marked this conversation as resolved.
Outdated
"relative key %j as entry point does not trip the absolute-path assertion",
async key => {
const script = `
const r = await Bun.build({
entrypoints: [${JSON.stringify(key)}],
files: { ${JSON.stringify(key)}: 'console.log("from relative key")' },
target: "bun",
throw: false,
});
if (!r.success) {
for (const l of r.logs) console.error(l.message ?? l);
process.exit(1);
}
const out = await r.outputs[0].text();
if (!out.includes("from relative key")) {
console.error("missing content:", out);
process.exit(1);
}
console.log("ok");
`;
await using proc = Bun.spawn({
cmd: [bunExe(), "-e", script],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([
proc.stdout.text(),
proc.stderr.text(),
proc.exited,
]);
expect({ stdout: stdout.trim(), stderr, exitCode }).toEqual({
stdout: "ok",
stderr: "",
exitCode: 0,
});
},
);

test("relative key as entry point surfaces parse errors without crashing", async () => {
const script = `
const r = await Bun.build({
entrypoints: ["./e.js"],
files: { "./e.js": ")" },
target: "bun",
throw: false,
});
console.log(JSON.stringify({ success: r.success, logs: r.logs.length }));
`;
await using proc = Bun.spawn({
cmd: [bunExe(), "-e", script],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([
proc.stdout.text(),
proc.stderr.text(),
proc.exited,
]);
expect({ stdout: stdout.trim(), stderr, exitCode }).toEqual({
stdout: JSON.stringify({ success: false, logs: 1 }),
stderr: "",
exitCode: 0,
});
});
});
Loading