diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index 574d3b408f..968117da55 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -2175,7 +2175,7 @@ declare module "bun" { root?: string; // project root splitting?: boolean; // default true, enable code splitting /** - * Controls how entry point signatures are preserved. + * Controls how entry point signatures are preserved. * - `"strict"`: Entry chunks contain only their direct code * - `"allow-extension"`: Shared modules can be merged into entry chunks (default) * - `"exports-only"`: Only explicitly exported symbols are preserved @@ -2270,7 +2270,7 @@ declare module "bun" { /** * Advanced chunking options for custom module grouping and size constraints. - * + * * @example * ```ts * Bun.build({ @@ -2297,31 +2297,31 @@ declare module "bun" { * @default undefined */ minShareCount?: number; - + /** * Minimum size for a chunk in bytes. * @default undefined */ minSize?: number; - + /** * Maximum size for a chunk in bytes. * @default undefined */ maxSize?: number; - + /** * Minimum size for a module to be considered for chunking. * @default undefined */ minModuleSize?: number; - + /** * Maximum size for a module to be included in a chunk. * @default undefined */ maxModuleSize?: number; - + /** * Custom grouping rules for modules. */ @@ -2330,44 +2330,44 @@ declare module "bun" { * Name of the group. */ name: string; - + /** * Test pattern for matching modules (string will be treated as regex). */ test?: string | RegExp; - + /** * Priority for group matching (higher priority groups are matched first). * @default 0 */ priority?: number; - + /** * Type of modules to include. * @default "all" */ type?: "javascript" | "css" | "asset" | "all"; - + /** * Minimum size for the group. */ minSize?: number; - + /** * Maximum size for the group. */ maxSize?: number; - + /** * Minimum number of modules in the group. */ minChunks?: number; - + /** * Maximum number of modules in the group. */ maxChunks?: number; - + /** * Enforce creation of this group even if it would be empty. * @default false diff --git a/test/bundler/advanced-chunks-edge-cases.test.ts b/test/bundler/advanced-chunks-edge-cases.test.ts index 3e1ab32c44..12b82faaa2 100644 --- a/test/bundler/advanced-chunks-edge-cases.test.ts +++ b/test/bundler/advanced-chunks-edge-cases.test.ts @@ -1,5 +1,5 @@ -import { describe, test, expect } from "bun:test"; -import { bunExe, bunEnv, tempDirWithFiles } from "harness"; +import { describe, expect, test } from "bun:test"; +import { bunEnv, bunExe, tempDirWithFiles } from "harness"; describe("Advanced Chunks Edge Cases", () => { test("should handle empty advancedChunks config", async () => { @@ -355,4 +355,4 @@ describe("Advanced Chunks Edge Cases", () => { expect(exitCode).toBe(0); expect(stdout).toContain("Type test: true"); }); -}); \ No newline at end of file +}); diff --git a/test/bundler/advanced-chunks.test.ts b/test/bundler/advanced-chunks.test.ts index d65b461ea9..3139c77958 100644 --- a/test/bundler/advanced-chunks.test.ts +++ b/test/bundler/advanced-chunks.test.ts @@ -1,5 +1,5 @@ -import { describe, test, expect } from "bun:test"; -import { bunExe, bunEnv, tempDirWithFiles } from "harness"; +import { describe, expect, test } from "bun:test"; +import { bunEnv, bunExe, tempDirWithFiles } from "harness"; describe("Advanced Chunks", () => { test("should accept advancedChunks config option", async () => { @@ -243,4 +243,4 @@ describe("Advanced Chunks", () => { expect(stdout).toContain("Advanced chunks test passed: true"); expect(stderr).toBe(""); }); -}); \ No newline at end of file +}); diff --git a/test/bundler/splitting-preserve-entry-signatures.test.ts b/test/bundler/splitting-preserve-entry-signatures.test.ts index 21746ddebc..8762cf0b05 100644 --- a/test/bundler/splitting-preserve-entry-signatures.test.ts +++ b/test/bundler/splitting-preserve-entry-signatures.test.ts @@ -151,7 +151,10 @@ describe("bundler", () => { run: [ { file: "/out/entry-a.js", stdout: "Shared loaded\nEntry A loaded" }, { file: "/out/entry-b.js", stdout: "Shared loaded\nEntry B: shared-value" }, - { file: "/test.js", stdout: "Shared loaded\nEntry A loaded\nImported a: entry-a\nShared via function: shared-value" }, + { + file: "/test.js", + stdout: "Shared loaded\nEntry A loaded\nImported a: entry-a\nShared via function: shared-value", + }, ], }); @@ -352,4 +355,4 @@ describe("bundler", () => { }, }); }); -}); \ No newline at end of file +}); diff --git a/test/bundler/splitting-preserve-signatures-cli.test.ts b/test/bundler/splitting-preserve-signatures-cli.test.ts index cf6c621d65..dd47133a08 100644 --- a/test/bundler/splitting-preserve-signatures-cli.test.ts +++ b/test/bundler/splitting-preserve-signatures-cli.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; -import { tempDirWithFiles, bunExe, bunEnv } from "harness"; import { readdirSync } from "fs"; +import { bunEnv, bunExe, tempDirWithFiles } from "harness"; import { join } from "path"; describe("bundler", () => { @@ -27,9 +27,10 @@ describe("bundler", () => { "build", join(dir, "entry-a.js"), join(dir, "entry-b.js"), - "--outdir", outDir, + "--outdir", + outDir, "--splitting", - "--preserve-entry-signatures=strict" + "--preserve-entry-signatures=strict", ], env: bunEnv, cwd: dir, @@ -82,9 +83,10 @@ describe("bundler", () => { "build", join(dir, "entry-a.js"), join(dir, "entry-b.js"), - "--outdir", outDir, + "--outdir", + outDir, "--splitting", - "--preserve-entry-signatures=allow-extension" + "--preserve-entry-signatures=allow-extension", ], env: bunEnv, cwd: dir, @@ -112,8 +114,8 @@ describe("bundler", () => { const entryB = await Bun.file(join(outDir, "entry-b.js")).text(); const utilInA = entryA.includes('util = "util"'); const utilInB = entryB.includes('util = "util"'); - + expect(utilInA !== utilInB).toBe(true); // Exactly one has util }); }); -}); \ No newline at end of file +}); diff --git a/test/bundler/splitting-rolldown-optimization.test.ts b/test/bundler/splitting-rolldown-optimization.test.ts index 12de726a16..9f0bf7a7be 100644 --- a/test/bundler/splitting-rolldown-optimization.test.ts +++ b/test/bundler/splitting-rolldown-optimization.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; -import { tempDirWithFiles, bunExe, bunEnv } from "harness"; import { readdirSync, readFileSync } from "fs"; +import { bunEnv, bunExe, tempDirWithFiles } from "harness"; import { join } from "path"; // Comprehensive test suite for the Rolldown chunk extension optimization @@ -21,7 +21,16 @@ describe("bundler", () => { const outDir = join(dir, "out"); await using proc = Bun.spawn({ - cmd: [bunExe(), "build", "entry-a.js", "entry-b.js", "--outdir", outDir, "--splitting", "--preserve-entry-signatures=strict"], + cmd: [ + bunExe(), + "build", + "entry-a.js", + "entry-b.js", + "--outdir", + outDir, + "--splitting", + "--preserve-entry-signatures=strict", + ], env: bunEnv, cwd: dir, }); @@ -46,7 +55,16 @@ describe("bundler", () => { const outDir = join(dir, "out"); await using proc = Bun.spawn({ - cmd: [bunExe(), "build", "entry-a.js", "entry-b.js", "--outdir", outDir, "--splitting", "--preserve-entry-signatures=allow-extension"], + cmd: [ + bunExe(), + "build", + "entry-a.js", + "entry-b.js", + "--outdir", + outDir, + "--splitting", + "--preserve-entry-signatures=allow-extension", + ], env: bunEnv, cwd: dir, }); @@ -54,11 +72,11 @@ describe("bundler", () => { expect(await proc.exited).toBe(0); const files = readdirSync(outDir); expect(files.length).toBe(2); // Optimization merged shared into an entry - + // Verify cross-imports const entryA = readFileSync(join(outDir, "entry-a.js"), "utf-8"); const entryB = readFileSync(join(outDir, "entry-b.js"), "utf-8"); - + // One should have the shared code, other should import const hasShared = (content: string) => content.includes("shared-value"); expect(hasShared(entryA) !== hasShared(entryB)).toBe(true); @@ -85,7 +103,16 @@ describe("bundler", () => { const outDir = join(dir, "out"); await using proc = Bun.spawn({ - cmd: [bunExe(), "build", "entry-a.js", "entry-b.js", "--outdir", outDir, "--splitting", "--preserve-entry-signatures=allow-extension"], + cmd: [ + bunExe(), + "build", + "entry-a.js", + "entry-b.js", + "--outdir", + outDir, + "--splitting", + "--preserve-entry-signatures=allow-extension", + ], env: bunEnv, cwd: dir, }); @@ -119,7 +146,17 @@ describe("bundler", () => { const outDir = join(dir, "out"); await using proc = Bun.spawn({ - cmd: [bunExe(), "build", "entry-a.js", "entry-b.js", "entry-c.js", "--outdir", outDir, "--splitting", "--preserve-entry-signatures=allow-extension"], + cmd: [ + bunExe(), + "build", + "entry-a.js", + "entry-b.js", + "entry-c.js", + "--outdir", + outDir, + "--splitting", + "--preserve-entry-signatures=allow-extension", + ], env: bunEnv, cwd: dir, }); @@ -127,16 +164,16 @@ describe("bundler", () => { expect(await proc.exited).toBe(0); const files = readdirSync(outDir); expect(files.length).toBe(3); // Each entry has its unique module - + // Verify shared module is in one of entry-a or entry-b const entryA = readFileSync(join(outDir, "entry-a.js"), "utf-8"); const entryB = readFileSync(join(outDir, "entry-b.js"), "utf-8"); const entryC = readFileSync(join(outDir, "entry-c.js"), "utf-8"); - + const sharedInA = entryA.includes('shared = "shared"'); const sharedInB = entryB.includes('shared = "shared"'); const sharedInC = entryC.includes('shared = "shared"'); - + expect(sharedInC).toBe(false); // C doesn't use shared expect(sharedInA !== sharedInB).toBe(true); // Exactly one of A or B has it }); @@ -166,29 +203,41 @@ describe("bundler", () => { const outDir = join(dir, "out"); await using proc = Bun.spawn({ - cmd: [bunExe(), "build", "entry-a.js", "entry-b.js", "entry-c.js", "--outdir", outDir, "--splitting", "--preserve-entry-signatures=allow-extension"], + cmd: [ + bunExe(), + "build", + "entry-a.js", + "entry-b.js", + "entry-c.js", + "--outdir", + outDir, + "--splitting", + "--preserve-entry-signatures=allow-extension", + ], env: bunEnv, cwd: dir, }); expect(await proc.exited).toBe(0); const files = readdirSync(outDir); - + // With optimization, shared modules should be consolidated expect(files.length).toBeLessThan(6); // Less than 3 entries + 3 shared expect(files).toContain("entry-a.js"); expect(files).toContain("entry-b.js"); expect(files).toContain("entry-c.js"); - + // Count how many files contain each shared module - let abCount = 0, bcCount = 0, abcCount = 0; + let abCount = 0, + bcCount = 0, + abcCount = 0; for (const file of files) { const content = readFileSync(join(outDir, file), "utf-8"); if (content.includes("shared-by-ab")) abCount++; if (content.includes("shared-by-bc")) bcCount++; if (content.includes("shared-by-all")) abcCount++; } - + // Each shared module should appear exactly once expect(abCount).toBe(1); expect(bcCount).toBe(1); @@ -211,7 +260,16 @@ describe("bundler", () => { const outDir = join(dir, "out"); await using proc = Bun.spawn({ - cmd: [bunExe(), "build", "entry.js", "other.js", "--outdir", outDir, "--splitting", `--preserve-entry-signatures=${mode}`], + cmd: [ + bunExe(), + "build", + "entry.js", + "other.js", + "--outdir", + outDir, + "--splitting", + `--preserve-entry-signatures=${mode}`, + ], env: bunEnv, cwd: dir, }); @@ -233,4 +291,4 @@ describe("bundler", () => { expect(falseCount).toBe(2); }); }); -}); \ No newline at end of file +});