Repository navigation
Conversation
When a shared module is listed as both an entry point AND imported by another entry point with splitting enabled, the bundler outputs duplicate export statements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…rted with splitting When a module is both an entry point AND imported by another entry point with splitting enabled, the bundler was generating duplicate export statements. This happened because: 1. generateEntryPointTailJS generates exports for entry point's exports 2. cross-chunk suffix also generates exports for symbols other chunks need The fix tracks which refs will be exported by the entry point tail and skips generating duplicate cross-chunk exports for those refs, while still populating exports_to_other_chunks so cross-chunk imports work. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Updated 12:41 PM PT - Jan 14th, 2026
❌ @alii, your commit 7561b46 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 25866That installs a local version of the PR into your bun-25866 --bun |
WalkthroughPrecomputes entry-point export aliases and updates cross-chunk export generation to avoid duplicate export statements when a shared module is also an entry point; adds numerous splitting tests verifying single export clauses and runtime outputs for overlapping entry scenarios. Changes
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)src/**/*.zig📄 CodeRabbit inference engine (src/CLAUDE.md)
Files:
**/*.zig📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (5)📓 Common learnings📚 Learning: 2025-09-06T03:37:41.154ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2026-01-05T16:32:07.551ZApplied to files:
🔇 Additional comments (4)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @src/bundler/linker_context/computeCrossChunkDependencies.zig:
- Around line 314-345: The entry-point export ref resolution in the block
building entry_point_export_refs follows imports_to_bind but never follows
CommonJS namespace aliases, so exports_to_other_chunks can map the wrong ref for
re-exported namespaces; update the code that assigns ref (starting from
resolved_export.data.import_ref and the entry_imports_to_bind lookup) to also
check deps.symbols.getConst(ref).?.namespace_alias and, if present, set ref =
namespace_alias.namespace_ref (mirroring the walk function’s logic), or if you
intentionally omit this case, add a clear comment on entry_point_export_refs
explaining why namespace_alias is not applied for entry points.
In @test/bundler/bundler_splitting.test.ts:
- Around line 326-356: The test's onAfterBundle validation should ensure exactly
one export exists, not just guard against duplicates; update the conditional
that currently checks exportMatches.length > 1 to check exportMatches.length !==
1 so missing exports are caught as well, and keep the error message referencing
sharedContent and exportMatches for context (symbols to locate: onAfterBundle,
sharedContent, exportMatches).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/bundler/linker_context/computeCrossChunkDependencies.zigtest/bundler/bundler_splitting.test.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.test.ts?(x)
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.test.ts?(x): Never usebun testdirectly - always usebun bd testto run tests with debug build changes
For single-file tests, prefer-eflag overtempDir
For multi-file tests, prefertempDirandBun.spawnover single-file tests
UsenormalizeBunSnapshotto normalize snapshot output of tests
Never write tests that check for 'panic', 'uncaught exception', or similar strings in test output
UsetempDirfromharnessto create temporary directories - do not usetmpdirSyncorfs.mkdtempSync
When spawning processes in tests, expect stdout before expecting exit code for more useful error messages on test failure
Do not write flaky tests - do not usesetTimeoutin tests; instead await the condition to be met
Verify tests fail withUSE_SYSTEM_BUN=1 bun test <file>and pass withbun bd test <file>- tests are invalid if they pass with USE_SYSTEM_BUN=1
Test files must end with.test.tsor.test.tsx
Avoid shell commands likefindorgrepin tests - use Bun's Glob and built-in tools instead
Files:
test/bundler/bundler_splitting.test.ts
test/**/*.test.ts?(x)
📄 CodeRabbit inference engine (CLAUDE.md)
Always use
port: 0in tests - do not hardcode ports or use custom random port number functions
Files:
test/bundler/bundler_splitting.test.ts
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}
📄 CodeRabbit inference engine (test/CLAUDE.md)
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}: Usebun bd test <...test file>to run tests with compiled code changes. Do not usebun testas it will not include your changes.
Usebun:testfor files ending in*.test.{ts,js,jsx,tsx,mjs,cjs}. For test files without .test extension in test/js/node/test/{parallel,sequential}/*.js, usebun bd <file>instead ofbun bd test <file>since they expect exit code 0.
Do not set a timeout on tests. Bun already has timeouts built-in.
Files:
test/bundler/bundler_splitting.test.ts
src/**/*.zig
📄 CodeRabbit inference engine (src/CLAUDE.md)
src/**/*.zig: Private fields in Zig are fully supported using the#prefix:struct { #foo: u32 };
Use decl literals in Zig for declaration initialization:const decl: Decl = .{ .binding = 0, .value = 0 };
Prefer@importat the bottom of the file (auto formatter will move them automatically)
Files:
src/bundler/linker_context/computeCrossChunkDependencies.zig
**/*.zig
📄 CodeRabbit inference engine (CLAUDE.md)
In Zig code, be careful with allocators and use defer for cleanup
Files:
src/bundler/linker_context/computeCrossChunkDependencies.zig
🧠 Learnings (18)
📓 Common learnings
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Export modules using `export default { ... }` syntax; modules are NOT ES modules
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-14T16:07:01.064Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun bd test <...test file>` to run tests with compiled code changes. Do not use `bun test` as it will not include your changes.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : For multi-file tests, prefer `tempDir` and `Bun.spawn` over single-file tests
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun:test` for files ending in `*.test.{ts,js,jsx,tsx,mjs,cjs}`. For test files without .test extension in test/js/node/test/{parallel,sequential}/*.js, use `bun bd <file>` instead of `bun bd test <file>` since they expect exit code 0.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : Never use `bun test` directly - always use `bun bd test` to run tests with debug build changes
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Export modules using `export default { ... }` syntax; modules are NOT ES modules
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : Verify tests fail with `USE_SYSTEM_BUN=1 bun test <file>` and pass with `bun bd test <file>` - tests are invalid if they pass with USE_SYSTEM_BUN=1
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8-module/main.cpp : Register new V8 API test functions in the Init method using NODE_SET_METHOD with exports object
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-10-19T02:52:37.412Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/tsconfig.json:1-15
Timestamp: 2025-10-19T02:52:37.412Z
Learning: In the Bun repository, packages under packages/ (e.g., bun-otel) can follow a TypeScript-first pattern where package.json exports point directly to .ts files (not compiled .js files). Bun natively runs TypeScript, so consumers import .ts sources directly and receive full type information without needing compiled .d.ts declaration files. For such packages, adding "declaration": true or "outDir" in tsconfig.json is unnecessary and would break the export structure.
<!-- [remove_learning]
ceedde95-980e-4898-a2c6-40ff73913664
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-06T00:58:23.965Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24417
File: test/js/bun/spawn/spawn.test.ts:903-918
Timestamp: 2025-11-06T00:58:23.965Z
Learning: In Bun test files, `await using` with spawn() is appropriate for long-running processes that need guaranteed cleanup on scope exit or when explicitly testing disposal behavior. For short-lived processes that exit naturally (e.g., console.log scripts), the pattern `const proc = spawn(...); await proc.exited;` is standard and more common, as evidenced by 24 instances vs 4 `await using` instances in test/js/bun/spawn/spawn.test.ts.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-09-06T03:37:41.154Z
Learnt from: taylordotfish
Repo: oven-sh/bun PR: 22229
File: src/bundler/LinkerGraph.zig:0-0
Timestamp: 2025-09-06T03:37:41.154Z
Learning: In Bun's codebase, when checking import record source indices in src/bundler/LinkerGraph.zig, prefer using `if (import_index >= self.import_records.len)` bounds checking over `isValid()` checks, as the bounds check is more robust and `isValid()` is a strict subset of this condition.
Applied to files:
src/bundler/linker_context/computeCrossChunkDependencies.zig
📚 Learning: 2025-08-30T09:09:18.384Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 22231
File: src/bundler/bundle_v2.zig:48-48
Timestamp: 2025-08-30T09:09:18.384Z
Learning: In Zig, when a module exports a top-level struct, import("./Module.zig") directly returns that struct type and can be used as a type alias without needing to access a field within the module. This is a common pattern in the Bun codebase.
Applied to files:
src/bundler/linker_context/computeCrossChunkDependencies.zig
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/src/napi/napi.zig : For each new V8 C++ method, add both GCC/Clang and MSVC mangled symbol names to the V8API struct in src/napi/napi.zig using extern fn declarations
Applied to files:
src/bundler/linker_context/computeCrossChunkDependencies.zig
📚 Learning: 2025-11-24T18:36:38.104Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:38.104Z
Learning: Applies to src/**/*.zig : Prefer `import` at the bottom of the file (auto formatter will move them automatically)
Applied to files:
src/bundler/linker_context/computeCrossChunkDependencies.zig
📚 Learning: 2026-01-05T16:32:07.551Z
Learnt from: alii
Repo: oven-sh/bun PR: 25474
File: src/bun.js/event_loop/Sigusr1Handler.zig:0-0
Timestamp: 2026-01-05T16:32:07.551Z
Learning: In Zig codebases (e.g., Bun), treat std.posix.sigaction as returning void and do not perform runtime error handling for its failure. The Zig standard library views sigaction failures as programmer errors (unreachable) because they only occur with invalid signals like SIGKILL/SIGSTOP. Apply this pattern across Zig files that call sigaction (e.g., crash_handler.zig, main.zig, filter_run.zig, process.zig) and ensure failures are not handled as recoverable errors; prefer reaching an explicit unreachable/compile-time assumption when such failures are detected.
Applied to files:
src/bundler/linker_context/computeCrossChunkDependencies.zig
🧬 Code graph analysis (1)
test/bundler/bundler_splitting.test.ts (1)
test/bundler/expectBundled.ts (1)
itBundled(1763-1797)
🔇 Additional comments (4)
src/bundler/linker_context/computeCrossChunkDependencies.zig (4)
299-301: LGTM!Clean extraction of graph metadata arrays needed for the entry-point export tracking logic. This follows the same pattern used in the
CrossChunkDependenciesstruct.
347-363: Core fix looks correct: skip clause_items but preserve exports_to_other_chunks.The logic correctly addresses the duplicate exports issue:
- For refs already exported by entry point tail, use the entry point's original alias (e.g.,
"shared") inexports_to_other_chunks- Skip adding to
clause_itemsto avoid generating a duplicateexport { ... }statement- Cross-chunk imports will still find the correct alias via
exports_to_other_chunksThis ensures the entry point's export statement handles the export, while cross-chunk dependency tracking remains intact.
365-380: LGTM!The export generation for non-entry-point refs remains unchanged in behavior. The switch from slice to
ArrayListwithappendAssumeCapacityis appropriate since some items may be skipped (entry point exports).
383-397: LGTM!The condition correctly uses
clause_items.items.len > 0to only generate the export clause when there are items to export. This handles the case where all exports are already provided by the entry point tail.
- Add namespace_alias resolution for CommonJS re-exports to match the walk function's behavior when resolving refs - Change test assertion from > 1 to !== 1 to catch both duplicate and missing exports 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add tests for additional scenarios where entry points interact with
code splitting:
- Named re-exports: `export { foo } from './shared'` where shared is
also an entry point
- Export star: `export * from './shared'` where shared is also an
entry point
- CommonJS imports: ESM importing from CJS module that is also an
entry point (tests namespace_alias resolution)
- Transitive imports: A imports B, B imports C, all three are entry
points (tests chained dependencies)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
05fbe03 to
97ad7a7
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In @test/bundler/bundler_splitting.test.ts:
- Around line 387-414: Update the test's onAfterBundle validation to also read
"/out/entry-a.js" (in the itBundled call) and assert that it re-exports both
"foo" and "bar" from shared — e.g., check that the entry-a output contains the
expected export statement(s) (such as "export { foo, bar }" or individual
"export" entries for foo and bar) and throw a descriptive Error if those exports
are missing, similar to the existing validation for "/out/shared.js".
- Around line 358-385: The test currently checks shared.js exports but not that
entry-a.js actually re-exports foo; update the onAfterBundle block (in the
NamedReExportWithEntryPointOverlap test) to also read "/out/entry-a.js" via
api.readFile and assert it contains an export that exposes foo (e.g. match
/export\s*\{[^}]*\bfoo\b[^}]*\}/ or equivalent) and throw a clear error if the
expected export is missing so consumers can verify the re-export binding from
entry-a.js.
- Around line 433-456: Add run validations for the other two entry points in the
"splitting/ESMReExportFromCJSWithEntryPointOverlap" test: extend the existing
run array to include { file: "/out/esm-reexport.js", stdout: "" } and { file:
"/out/cjs-module.js", stdout: "" } so the test executes the built esm-reexport
and cjs-module outputs (in addition to the existing consumer check) to ensure
they run without error; update the test's entryPoints/run section in the
itBundled invocation accordingly.
- Around line 416-431: The test uses
itBundled("splitting/CommonJSImportWithEntryPointOverlap", ...) but only
validates running "/out/entry-a.js"; add a second run validation entry for
"/out/shared.js" so the test also executes the shared chunk and ensures it runs
without error (e.g., add a run array item for file "/out/shared.js" expecting
empty stdout) while keeping the existing entryPoints, splitting, format, and
existing run for "/out/entry-a.js".
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between 05fbe031609380727d8e224a30e1b6a98c007bdf and 97ad7a7.
📒 Files selected for processing (1)
test/bundler/bundler_splitting.test.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.test.ts?(x)
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.test.ts?(x): Never usebun testdirectly - always usebun bd testto run tests with debug build changes
For single-file tests, prefer-eflag overtempDir
For multi-file tests, prefertempDirandBun.spawnover single-file tests
UsenormalizeBunSnapshotto normalize snapshot output of tests
Never write tests that check for 'panic', 'uncaught exception', or similar strings in test output
UsetempDirfromharnessto create temporary directories - do not usetmpdirSyncorfs.mkdtempSync
When spawning processes in tests, expect stdout before expecting exit code for more useful error messages on test failure
Do not write flaky tests - do not usesetTimeoutin tests; instead await the condition to be met
Verify tests fail withUSE_SYSTEM_BUN=1 bun test <file>and pass withbun bd test <file>- tests are invalid if they pass with USE_SYSTEM_BUN=1
Test files must end with.test.tsor.test.tsx
Avoid shell commands likefindorgrepin tests - use Bun's Glob and built-in tools instead
Files:
test/bundler/bundler_splitting.test.ts
test/**/*.test.ts?(x)
📄 CodeRabbit inference engine (CLAUDE.md)
Always use
port: 0in tests - do not hardcode ports or use custom random port number functions
Files:
test/bundler/bundler_splitting.test.ts
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}
📄 CodeRabbit inference engine (test/CLAUDE.md)
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}: Usebun bd test <...test file>to run tests with compiled code changes. Do not usebun testas it will not include your changes.
Usebun:testfor files ending in*.test.{ts,js,jsx,tsx,mjs,cjs}. For test files without .test extension in test/js/node/test/{parallel,sequential}/*.js, usebun bd <file>instead ofbun bd test <file>since they expect exit code 0.
Do not set a timeout on tests. Bun already has timeouts built-in.
Files:
test/bundler/bundler_splitting.test.ts
🧠 Learnings (16)
📓 Common learnings
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/V8*.h : Add BUN_EXPORT visibility attribute to all public V8 API functions to ensure proper symbol export across platforms
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Export modules using `export default { ... }` syntax; modules are NOT ES modules
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use `process.platform` and `process.arch` for platform detection; these values are inlined and dead-code eliminated at build time
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-14T16:07:01.064Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Export modules using `export default { ... }` syntax; modules are NOT ES modules
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun bd test <...test file>` to run tests with compiled code changes. Do not use `bun test` as it will not include your changes.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : For multi-file tests, prefer `tempDir` and `Bun.spawn` over single-file tests
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun:test` for files ending in `*.test.{ts,js,jsx,tsx,mjs,cjs}`. For test files without .test extension in test/js/node/test/{parallel,sequential}/*.js, use `bun bd <file>` instead of `bun bd test <file>` since they expect exit code 0.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use `$debug()` for debug logging and `$assert()` for assertions; both are stripped in release builds
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Organize unit tests by module in directories like `/test/js/bun/` and `/test/js/node/`.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-10-19T02:52:37.412Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/tsconfig.json:1-15
Timestamp: 2025-10-19T02:52:37.412Z
Learning: In the Bun repository, packages under packages/ (e.g., bun-otel) can follow a TypeScript-first pattern where package.json exports point directly to .ts files (not compiled .js files). Bun natively runs TypeScript, so consumers import .ts sources directly and receive full type information without needing compiled .d.ts declaration files. For such packages, adding "declaration": true or "outDir" in tsconfig.json is unnecessary and would break the export structure.
<!-- [remove_learning]
ceedde95-980e-4898-a2c6-40ff73913664
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Ensure V8 API tests compare identical C++ code output between Node.js and Bun through the test suite validation process
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*-fixture.ts : Test files that spawn Bun processes should end in `*-fixture.ts` to identify them as test fixtures rather than tests themselves.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : Verify tests fail with `USE_SYSTEM_BUN=1 bun test <file>` and pass with `bun bd test <file>` - tests are invalid if they pass with USE_SYSTEM_BUN=1
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to test/regression/issue/*.test.ts : Place regression tests for specific GitHub issues in `test/regression/issue/${issueNumber}.test.ts` with real issue numbers only
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-06T00:58:23.965Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24417
File: test/js/bun/spawn/spawn.test.ts:903-918
Timestamp: 2025-11-06T00:58:23.965Z
Learning: In Bun test files, `await using` with spawn() is appropriate for long-running processes that need guaranteed cleanup on scope exit or when explicitly testing disposal behavior. For short-lived processes that exit naturally (e.g., console.log scripts), the pattern `const proc = spawn(...); await proc.exited;` is standard and more common, as evidenced by 24 instances vs 4 `await using` instances in test/js/bun/spawn/spawn.test.ts.
Applied to files:
test/bundler/bundler_splitting.test.ts
🧬 Code graph analysis (1)
test/bundler/bundler_splitting.test.ts (1)
test/bundler/expectBundled.ts (1)
itBundled(1763-1797)
🔇 Additional comments (3)
test/bundler/bundler_splitting.test.ts (3)
327-356: Test correctly implements the fix for issue #22884.The test validates that no duplicate exports are emitted when a shared module is both an entry point and imported by another entry point. The validation logic correctly checks for exactly one export statement (
!== 1) as suggested in the previous review.
458-499: Comprehensive test for transitive entry point dependencies.This test appropriately validates both build-time export statement counts and runtime behavior for all three entry points. The validation logic correctly focuses on
b.jsandc.jssince these are the modules that export values, whilea.jsis purely a consumer.
327-499: Well-designed test suite for splitting edge cases.The six new tests comprehensively cover the scenarios where shared modules are also entry points:
- ✓ Basic shared module as entry point
- ✓ Named re-exports with overlap
- ✓ Export star with overlap
- ✓ CommonJS/ESM interop
- ✓ ESM re-exporting from CJS
- ✓ Transitive entry point chains
The validation strategy combining regex-based export counting in
onAfterBundlewith runtime checks inrunis sound. The tests follow established patterns in the codebase and align with the PR objective to fix duplicate export issues.
| // Test: Named re-export with entry point overlap | ||
| // When entry-a re-exports from shared, and shared is also an entry point | ||
| itBundled("splitting/NamedReExportWithEntryPointOverlap", { | ||
| files: { | ||
| "/shared.ts": `export const foo = "foo"; export const bar = "bar";`, | ||
| "/entry-a.ts": ` | ||
| export { foo } from "./shared"; | ||
| console.log("entry-a"); | ||
| `, | ||
| }, | ||
| entryPoints: ["/entry-a.ts", "/shared.ts"], | ||
| splitting: true, | ||
| outdir: "/out", | ||
| format: "esm", | ||
| onAfterBundle(api) { | ||
| const sharedContent = api.readFile("/out/shared.js"); | ||
| const exportMatches = sharedContent.match(/export\s*\{/g) || []; | ||
| if (exportMatches.length !== 1) { | ||
| throw new Error( | ||
| `shared.js contains ${exportMatches.length} export statements, expected exactly 1. Content:\n${sharedContent}`, | ||
| ); | ||
| } | ||
| }, | ||
| run: [ | ||
| { file: "/out/entry-a.js", stdout: "entry-a" }, | ||
| { file: "/out/shared.js", stdout: "" }, | ||
| ], | ||
| }); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider adding validation for entry-a.js exports.
The test validates that shared.js has exactly one export statement but doesn't verify that entry-a.js correctly exports foo. While the runtime validation confirms the module executes, it doesn't test that the re-exported binding is accessible to consumers of entry-a.js.
Optional: Add export validation for entry-a.js
onAfterBundle(api) {
const sharedContent = api.readFile("/out/shared.js");
const exportMatches = sharedContent.match(/export\s*\{/g) || [];
if (exportMatches.length !== 1) {
throw new Error(
`shared.js contains ${exportMatches.length} export statements, expected exactly 1. Content:\n${sharedContent}`,
);
}
+ const entryAContent = api.readFile("/out/entry-a.js");
+ const entryAExportMatches = entryAContent.match(/export\s*\{/g) || [];
+ if (entryAExportMatches.length !== 1) {
+ throw new Error(
+ `entry-a.js contains ${entryAExportMatches.length} export statements, expected exactly 1.`,
+ );
+ }
},🤖 Prompt for AI Agents
In @test/bundler/bundler_splitting.test.ts around lines 358 - 385, The test
currently checks shared.js exports but not that entry-a.js actually re-exports
foo; update the onAfterBundle block (in the NamedReExportWithEntryPointOverlap
test) to also read "/out/entry-a.js" via api.readFile and assert it contains an
export that exposes foo (e.g. match /export\s*\{[^}]*\bfoo\b[^}]*\}/ or
equivalent) and throw a clear error if the expected export is missing so
consumers can verify the re-export binding from entry-a.js.
| // Test: Export star with entry point overlap | ||
| // When entry-a does export * from shared, and shared is also an entry point | ||
| itBundled("splitting/ExportStarWithEntryPointOverlap", { | ||
| files: { | ||
| "/shared.ts": `export const foo = "foo"; export const bar = "bar";`, | ||
| "/entry-a.ts": ` | ||
| export * from "./shared"; | ||
| console.log("entry-a"); | ||
| `, | ||
| }, | ||
| entryPoints: ["/entry-a.ts", "/shared.ts"], | ||
| splitting: true, | ||
| outdir: "/out", | ||
| format: "esm", | ||
| onAfterBundle(api) { | ||
| const sharedContent = api.readFile("/out/shared.js"); | ||
| const exportMatches = sharedContent.match(/export\s*\{/g) || []; | ||
| if (exportMatches.length !== 1) { | ||
| throw new Error( | ||
| `shared.js contains ${exportMatches.length} export statements, expected exactly 1. Content:\n${sharedContent}`, | ||
| ); | ||
| } | ||
| }, | ||
| run: [ | ||
| { file: "/out/entry-a.js", stdout: "entry-a" }, | ||
| { file: "/out/shared.js", stdout: "" }, | ||
| ], | ||
| }); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider adding export validation for entry-a.js.
Similar to the previous test, this validates shared.js but not entry-a.js. For export * patterns, you might want to verify that entry-a.js correctly re-exports both foo and bar.
🤖 Prompt for AI Agents
In @test/bundler/bundler_splitting.test.ts around lines 387 - 414, Update the
test's onAfterBundle validation to also read "/out/entry-a.js" (in the itBundled
call) and assert that it re-exports both "foo" and "bar" from shared — e.g.,
check that the entry-a output contains the expected export statement(s) (such as
"export { foo, bar }" or individual "export" entries for foo and bar) and throw
a descriptive Error if those exports are missing, similar to the existing
validation for "/out/shared.js".
Tests the case where the same value is exported under multiple names
(e.g., `export const foo = "foo"; export { foo as bar };`) and the
module is both an entry point and imported by other entry points.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @test/bundler/bundler_splitting.test.ts:
- Around line 416-431: The test "splitting/CommonJSImportWithEntryPointOverlap"
only asserts running /out/entry-a.js; add a second run validation for the other
entry point by appending an object to the run array that executes
"/out/shared.js" with the expected stdout (likely an empty string since it only
exports), e.g. add { file: "/out/shared.js", stdout: "" } so both entry points
are validated consistently with the other tests.
- Around line 433-456: The test only runs and validates "/out/consumer.js" but
should also run the other entry outputs; update the itBundled call (the
entryPoints and run config) to include run validations for
"/out/esm-reexport.js" and "/out/cjs-module.js" in the run array (alongside
"/out/consumer.js"), mirroring how the other tests validate all entry points so
each entry point file produced by the entryPoints list is executed and its
stdout asserted.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
test/bundler/bundler_splitting.test.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.test.ts?(x)
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.test.ts?(x): Never usebun testdirectly - always usebun bd testto run tests with debug build changes
For single-file tests, prefer-eflag overtempDir
For multi-file tests, prefertempDirandBun.spawnover single-file tests
UsenormalizeBunSnapshotto normalize snapshot output of tests
Never write tests that check for 'panic', 'uncaught exception', or similar strings in test output
UsetempDirfromharnessto create temporary directories - do not usetmpdirSyncorfs.mkdtempSync
When spawning processes in tests, expect stdout before expecting exit code for more useful error messages on test failure
Do not write flaky tests - do not usesetTimeoutin tests; instead await the condition to be met
Verify tests fail withUSE_SYSTEM_BUN=1 bun test <file>and pass withbun bd test <file>- tests are invalid if they pass with USE_SYSTEM_BUN=1
Test files must end with.test.tsor.test.tsx
Avoid shell commands likefindorgrepin tests - use Bun's Glob and built-in tools instead
Files:
test/bundler/bundler_splitting.test.ts
test/**/*.test.ts?(x)
📄 CodeRabbit inference engine (CLAUDE.md)
Always use
port: 0in tests - do not hardcode ports or use custom random port number functions
Files:
test/bundler/bundler_splitting.test.ts
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}
📄 CodeRabbit inference engine (test/CLAUDE.md)
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}: Usebun bd test <...test file>to run tests with compiled code changes. Do not usebun testas it will not include your changes.
Usebun:testfor files ending in*.test.{ts,js,jsx,tsx,mjs,cjs}. For test files without .test extension in test/js/node/test/{parallel,sequential}/*.js, usebun bd <file>instead ofbun bd test <file>since they expect exit code 0.
Do not set a timeout on tests. Bun already has timeouts built-in.
Files:
test/bundler/bundler_splitting.test.ts
🧠 Learnings (21)
📓 Common learnings
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun bd test <...test file>` to run tests with compiled code changes. Do not use `bun test` as it will not include your changes.
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Export modules using `export default { ... }` syntax; modules are NOT ES modules
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Organize unit tests by module in directories like `/test/js/bun/` and `/test/js/node/`.
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Ensure V8 API tests compare identical C++ code output between Node.js and Bun through the test suite validation process
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8-module/main.cpp : Register new V8 API test functions in the Init method using NODE_SET_METHOD with exports object
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun:test` for files ending in `*.test.{ts,js,jsx,tsx,mjs,cjs}`. For test files without .test extension in test/js/node/test/{parallel,sequential}/*.js, use `bun bd <file>` instead of `bun bd test <file>` since they expect exit code 0.
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use `process.platform` and `process.arch` for platform detection; these values are inlined and dead-code eliminated at build time
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Write JS builtins for Bun's Node.js compatibility and APIs, and run `bun bd` after changes
📚 Learning: 2025-11-14T16:07:01.064Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Export modules using `export default { ... }` syntax; modules are NOT ES modules
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun bd test <...test file>` to run tests with compiled code changes. Do not use `bun test` as it will not include your changes.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : For multi-file tests, prefer `tempDir` and `Bun.spawn` over single-file tests
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun:test` for files ending in `*.test.{ts,js,jsx,tsx,mjs,cjs}`. For test files without .test extension in test/js/node/test/{parallel,sequential}/*.js, use `bun bd <file>` instead of `bun bd test <file>` since they expect exit code 0.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-10-19T02:52:37.412Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/tsconfig.json:1-15
Timestamp: 2025-10-19T02:52:37.412Z
Learning: In the Bun repository, packages under packages/ (e.g., bun-otel) can follow a TypeScript-first pattern where package.json exports point directly to .ts files (not compiled .js files). Bun natively runs TypeScript, so consumers import .ts sources directly and receive full type information without needing compiled .d.ts declaration files. For such packages, adding "declaration": true or "outDir" in tsconfig.json is unnecessary and would break the export structure.
<!-- [remove_learning]
ceedde95-980e-4898-a2c6-40ff73913664
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use `$debug()` for debug logging and `$assert()` for assertions; both are stripped in release builds
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use private globals and methods with `$` prefix (e.g., `$Array`, `map.$set()`) instead of public JavaScript globals
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Ensure V8 API tests compare identical C++ code output between Node.js and Bun through the test suite validation process
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Applies to test/**/*-fixture.ts : Test files that spawn Bun processes should end in `*-fixture.ts` to identify them as test fixtures rather than tests themselves.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : Verify tests fail with `USE_SYSTEM_BUN=1 bun test <file>` and pass with `bun bd test <file>` - tests are invalid if they pass with USE_SYSTEM_BUN=1
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to test/regression/issue/*.test.ts : Place regression tests for specific GitHub issues in `test/regression/issue/${issueNumber}.test.ts` with real issue numbers only
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Validate function arguments using validators from `internal/validators` and throw `$ERR_*` error codes for invalid arguments
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : Never use `bun test` directly - always use `bun bd test` to run tests with debug build changes
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-12-16T00:21:32.179Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T00:21:32.179Z
Learning: Applies to **/*.test.ts?(x) : When spawning processes in tests, expect stdout before expecting exit code for more useful error messages on test failure
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use `process.platform` and `process.arch` for platform detection; these values are inlined and dead-code eliminated at build time
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2026-01-05T23:04:01.518Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2026-01-05T23:04:01.518Z
Learning: Organize unit tests by module in directories like `/test/js/bun/` and `/test/js/node/`.
Applied to files:
test/bundler/bundler_splitting.test.ts
📚 Learning: 2025-11-06T00:58:23.965Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24417
File: test/js/bun/spawn/spawn.test.ts:903-918
Timestamp: 2025-11-06T00:58:23.965Z
Learning: In Bun test files, `await using` with spawn() is appropriate for long-running processes that need guaranteed cleanup on scope exit or when explicitly testing disposal behavior. For short-lived processes that exit naturally (e.g., console.log scripts), the pattern `const proc = spawn(...); await proc.exited;` is standard and more common, as evidenced by 24 instances vs 4 `await using` instances in test/js/bun/spawn/spawn.test.ts.
Applied to files:
test/bundler/bundler_splitting.test.ts
🧬 Code graph analysis (1)
test/bundler/bundler_splitting.test.ts (1)
test/bundler/expectBundled.ts (1)
itBundled(1763-1797)
🔇 Additional comments (5)
test/bundler/bundler_splitting.test.ts (5)
327-356: Well-structured test validating the duplicate exports fix.The test correctly validates issue #22884 by checking that
shared.jscontains exactly one export statement when it's both an entry point and imported by another entry point. The regex pattern/export\s*\{/gappropriately matches named export syntax, and the runtime validations confirm both files execute correctly.
358-385: LGTM - Named re-export test follows established pattern.The test correctly validates the scenario where
entry-are-exports named bindings fromshared, withsharedalso being an entry point. The validation and runtime checks are consistent with the previous test.
387-414: LGTM - Export star test maintains consistency.The test appropriately covers the
export * fromscenario with entry point overlap. Validation logic and runtime checks are consistent with the test suite pattern.
458-499: Excellent comprehensive test for transitive entry point chains.The test thoroughly validates the A → B → C transitive import scenario where all three are entry points. Both
onAfterBundlevalidations (checking for exactly one export inb.jsandc.js) and runtime validations for all three entry points ensure complete coverage of this edge case.
501-537: Well-designed test for aliased export edge case.The test validates an important scenario where the same value is exported under multiple names (
fooandbar), ensuring the bundler correctly handles aliased exports when the module is both an entry point and imported by other entries. The validation confirms no duplicate exports are generated, and the runtime checks verify both aliases resolve to the same value.
| // Test: CommonJS import with entry point overlap | ||
| // When entry-a imports from a CJS module that is also an entry point | ||
| itBundled("splitting/CommonJSImportWithEntryPointOverlap", { | ||
| files: { | ||
| "/shared.js": `module.exports = { foo: "foo", bar: "bar" };`, | ||
| "/entry-a.ts": ` | ||
| import { foo } from "./shared.js"; | ||
| console.log(foo); | ||
| `, | ||
| }, | ||
| entryPoints: ["/entry-a.ts", "/shared.js"], | ||
| splitting: true, | ||
| outdir: "/out", | ||
| format: "esm", | ||
| run: [{ file: "/out/entry-a.js", stdout: "foo" }], | ||
| }); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider adding run validation for shared.js for consistency.
The test currently only validates entry-a.js at line 430, while earlier tests in this suite validate both entry points. A past review comment on these exact lines suggested adding shared.js validation and was marked as addressed, but the current code doesn't reflect this change.
For consistency with tests at lines 352-355, 381-384, and 410-413, consider adding:
- run: [{ file: "/out/entry-a.js", stdout: "foo" }],
+ run: [
+ { file: "/out/entry-a.js", stdout: "foo" },
+ { file: "/out/shared.js", stdout: "" },
+ ],📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Test: CommonJS import with entry point overlap | |
| // When entry-a imports from a CJS module that is also an entry point | |
| itBundled("splitting/CommonJSImportWithEntryPointOverlap", { | |
| files: { | |
| "/shared.js": `module.exports = { foo: "foo", bar: "bar" };`, | |
| "/entry-a.ts": ` | |
| import { foo } from "./shared.js"; | |
| console.log(foo); | |
| `, | |
| }, | |
| entryPoints: ["/entry-a.ts", "/shared.js"], | |
| splitting: true, | |
| outdir: "/out", | |
| format: "esm", | |
| run: [{ file: "/out/entry-a.js", stdout: "foo" }], | |
| }); | |
| // Test: CommonJS import with entry point overlap | |
| // When entry-a imports from a CJS module that is also an entry point | |
| itBundled("splitting/CommonJSImportWithEntryPointOverlap", { | |
| files: { | |
| "/shared.js": `module.exports = { foo: "foo", bar: "bar" };`, | |
| "/entry-a.ts": ` | |
| import { foo } from "./shared.js"; | |
| console.log(foo); | |
| `, | |
| }, | |
| entryPoints: ["/entry-a.ts", "/shared.js"], | |
| splitting: true, | |
| outdir: "/out", | |
| format: "esm", | |
| run: [ | |
| { file: "/out/entry-a.js", stdout: "foo" }, | |
| { file: "/out/shared.js", stdout: "" }, | |
| ], | |
| }); |
🤖 Prompt for AI Agents
In @test/bundler/bundler_splitting.test.ts around lines 416 - 431, The test
"splitting/CommonJSImportWithEntryPointOverlap" only asserts running
/out/entry-a.js; add a second run validation for the other entry point by
appending an object to the run array that executes "/out/shared.js" with the
expected stdout (likely an empty string since it only exports), e.g. add { file:
"/out/shared.js", stdout: "" } so both entry points are validated consistently
with the other tests.
| // Test: ESM re-exporting namespace from CommonJS with entry point overlap (namespace_alias case) | ||
| // This specifically tests the namespace_alias resolution path where an ESM entry point | ||
| // re-exports from a CJS module that is also an entry point. | ||
| // Uses namespace import to avoid unrelated CJS re-export bugs. | ||
| itBundled("splitting/ESMReExportFromCJSWithEntryPointOverlap", { | ||
| files: { | ||
| "/cjs-module.js": ` | ||
| module.exports = { value: "from-cjs" }; | ||
| `, | ||
| "/esm-reexport.ts": ` | ||
| import * as cjs from "./cjs-module.js"; | ||
| export const value = cjs.value; | ||
| `, | ||
| "/consumer.ts": ` | ||
| import { value } from "./esm-reexport"; | ||
| console.log(value); | ||
| `, | ||
| }, | ||
| entryPoints: ["/consumer.ts", "/esm-reexport.ts", "/cjs-module.js"], | ||
| splitting: true, | ||
| outdir: "/out", | ||
| format: "esm", | ||
| run: [{ file: "/out/consumer.js", stdout: "from-cjs" }], | ||
| }); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Add run validations for all three entry points.
The test defines three entry points (consumer.ts, esm-reexport.ts, cjs-module.js) but only validates consumer.js at line 455. For consistency with tests at lines 494-498 and 532-536 (which validate all entry points), add validations for the other two entries:
- run: [{ file: "/out/consumer.js", stdout: "from-cjs" }],
+ run: [
+ { file: "/out/consumer.js", stdout: "from-cjs" },
+ { file: "/out/esm-reexport.js", stdout: "" },
+ { file: "/out/cjs-module.js", stdout: "" },
+ ],🤖 Prompt for AI Agents
In @test/bundler/bundler_splitting.test.ts around lines 433 - 456, The test only
runs and validates "/out/consumer.js" but should also run the other entry
outputs; update the itBundled call (the entryPoints and run config) to include
run validations for "/out/esm-reexport.js" and "/out/cjs-module.js" in the run
array (alongside "/out/consumer.js"), mirroring how the other tests validate all
entry points so each entry point file produced by the entryPoints list is
executed and its stdout asserted.
Use the export's source_index instead of the entry point's source_index when looking up imports_to_bind, matching the behavior in the walk function. Also add null check for symbol lookup to avoid panics. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
may be fixed by oven-sh/bun#25866 ? Signed-off-by: Steven Hoffman <fustrate@me.com>
|
Replaced by #26089 |
No description provided.