diff --git a/src/bundler/options.zig b/src/bundler/options.zig index daea5ced59a3..81a4933e3ae4 100644 --- a/src/bundler/options.zig +++ b/src/bundler/options.zig @@ -1572,9 +1572,9 @@ pub fn loadersFromTransformOptions(allocator: std.mem.Allocator, _loaders: ?api. bun.StringArrayHashMap(Loader), allocator, input_loaders.extensions.len + - if (target.isBun()) default_loader_ext_bun.len else 0 + - if (target == .browser) default_loader_ext_browser.len else 0 + - default_loader_ext.len, + (if (target.isBun()) default_loader_ext_bun.len else 0) + + (if (target == .browser) default_loader_ext_browser.len else 0) + + default_loader_ext.len, input_loaders.extensions, loader_values, ); diff --git a/test/bundler/bun-build-api.test.ts b/test/bundler/bun-build-api.test.ts index e904d421ff2e..d718edf5b409 100644 --- a/test/bundler/bun-build-api.test.ts +++ b/test/bundler/bun-build-api.test.ts @@ -575,6 +575,19 @@ describe("Bun.build", () => { expect(await bundle.outputs[0].text()).toBe("var o=/*@__PURE__*/console.log(1);export{o as OUT};\n"); }); + test.concurrent("many user conditions does not crash", async () => { + const fixture = tempDirWithFiles("build-many-conditions", { + "entry.ts": `export const x = 1;`, + }); + + const bundle = await Bun.build({ + entrypoints: [join(fixture, "entry.ts")], + target: "bun", + conditions: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"], + }); + expect(bundle.success).toBe(true); + }); + test.concurrent( "you can write onLoad and onResolve plugins using the 'html' loader, and it includes script and link tags as bundled entrypoints", async () => { diff --git a/test/js/bun/resolve/import-custom-condition.test.ts b/test/js/bun/resolve/import-custom-condition.test.ts index ac366209fed5..1b490e5f8cb1 100644 --- a/test/js/bun/resolve/import-custom-condition.test.ts +++ b/test/js/bun/resolve/import-custom-condition.test.ts @@ -167,3 +167,22 @@ it("custom condition when don't match condition should resolves to default", asy expect(exitCode).toBe(1); }); + +// https://github.com/oven-sh/bun/issues/30619 +it("many custom conditions resolve correctly", async () => { + for (const n of [4, 5, 6, 8, 12, 20]) { + const flags = []; + for (let i = 1; i < n; i++) flags.push(`--conditions=c${i}`); + flags.push("--conditions=first"); + const { exitCode, stdout, stderr } = Bun.spawnSync({ + cmd: [bunExe(), ...flags, `${dir}/test.js`], + env: bunEnv, + cwd: import.meta.dir, + }); + expect({ n, exitCode, stdout: stdout.toString("utf8"), stderr: stderr.toString("utf8") }).toMatchObject({ + n, + exitCode: 0, + stdout: "1\n", + }); + } +});