-
Notifications
You must be signed in to change notification settings - Fork 5k
bundler: fix ESMConditions capacity with user-provided conditions #30470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -811,6 +811,24 @@ | |
| expect(text).toContain(" globalThis."); | ||
| }); | ||
|
|
||
| test("many custom conditions does not crash", async () => { | ||
|
Check warning on line 814 in test/bundler/bun-build-api.test.ts
|
||
| const dir = tempDirWithFiles("bun-build-many-conditions", { | ||
| "entry.js": `console.log(1);`, | ||
| }); | ||
|
|
||
| for (const target of ["bun", "browser", "node"] as const) { | ||
| for (const n of [1, 4, 6, 8, 12, 20]) { | ||
| const conditions = Array.from({ length: n }, (_, i) => `cond${i}`); | ||
| const build = await Bun.build({ | ||
| entrypoints: [join(dir, "entry.js")], | ||
| target, | ||
| conditions, | ||
| }); | ||
| expect(build.success).toBe(true); | ||
| } | ||
| } | ||
| }); | ||
|
Comment on lines
+819
to
+830
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Use parameterized cases instead of nested loops for this matrix. Please convert the ♻️ Suggested refactor-test("many custom conditions does not crash", async () => {
+describe.each(["bun", "browser", "node"] as const)("many custom conditions does not crash (%s)", target => {
+ test.concurrent.each([1, 4, 6, 8, 12, 20])("n=%i", async n => {
const dir = tempDirWithFiles("bun-build-many-conditions", {
"entry.js": `console.log(1);`,
});
- for (const target of ["bun", "browser", "node"] as const) {
- for (const n of [1, 4, 6, 8, 12, 20]) {
- const conditions = Array.from({ length: n }, (_, i) => `cond${i}`);
- const build = await Bun.build({
- entrypoints: [join(dir, "entry.js")],
- target,
- conditions,
- });
- expect(build.success).toBe(true);
- }
- }
-});
+ const conditions = Array.from({ length: n }, (_, i) => `cond${i}`);
+ const build = await Bun.build({
+ entrypoints: [join(dir, "entry.js")],
+ target,
+ conditions,
+ });
+ expect(build.success).toBe(true);
+ });
+});As per coding guidelines: "Use 🤖 Prompt for AI Agents |
||
|
|
||
| describe.concurrent("sourcemap boolean values", () => { | ||
| test("sourcemap: true should work (boolean)", async () => { | ||
| const dir = tempDirWithFiles("sourcemap-true-boolean", { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Nit: this should be
test.concurrentto match the neighboring top-level tests in this file (and pertest/CLAUDE.md's guidance to prefer concurrent tests when they write files / spawn builds with no shared state).Extended reasoning...
Summary
The new test
"many custom conditions does not crash"is declared with plaintest(...)rather thantest.concurrent(...). This is inconsistent with both the surrounding code in this file and the project's documented testing conventions.Project convention
test/CLAUDE.mdstates:This test writes files via
tempDirWithFilesand runs 18Bun.buildcalls — exactly the kind of test the guideline targets.Local consistency
Looking at the immediate neighbors at the top level of this file (outside the
describe("Bun.build")block):test.concurrent("macro with nested object", ...)test.concurrent("regression/NODE_PATHBuild api", ...)test.concurrent("regression/GlobalThis", ...)— directly abovedescribe.concurrent("sourcemap boolean values", ...)— directly belowEvery adjacent top-level test uses
.concurrent. The only nearby block that does not isdescribe("tsconfig option"), and that one has a clear reason: it callsprocess.chdir(), which is process-global and cannot safely run concurrently. The new test has no such constraint.Why concurrency is safe here
Step-by-step:
tempDirWithFiles("bun-build-many-conditions", ...)— no path collisions with other tests.Bun.build({ entrypoints, target, conditions })with nooutdir, so it doesn't write to any shared location.process.chdir(), mutateprocess.env, or touch any other process-global state.target,n,conditions) are all locals.There is therefore no obstacle to running it concurrently with the other tests in this file.
Impact
This is purely a consistency / test-suite-throughput nit — the test is functionally correct as written and will pass either way. It just runs sequentially when it could run in parallel with its neighbors, and it diverges from the established pattern at this location in the file.
Fix