Skip to content

fix(resolve): #5914 — compilePackages wildcard misses bun's flat-store-only deps#5915

Open
proggeramlug wants to merge 3 commits into
PerryTS:mainfrom
proggeramlug:fix/bun-flat-store-hoisting
Open

fix(resolve): #5914 — compilePackages wildcard misses bun's flat-store-only deps#5915
proggeramlug wants to merge 3 commits into
PerryTS:mainfrom
proggeramlug:fix/bun-flat-store-hoisting

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #5914.

Problem

enumerate_installed_packages (which materializes perry.compilePackages's "*" / "@scope/*" wildcard into concrete package names, per #3527) only walks top-level node_modules/<name> entries plus npm's own nested node_modules dedup layout.

Bun's flat/isolated linker only creates top-level symlinks for packages that are a direct dependency of some workspace package. Purely-transitive dependencies live only inside node_modules/.bun/<pkg>@<version>/node_modules/<pkg> (and the scoped @scope+pkg@<version> variant) — the existing walker correctly skips .bun as a dotdir (it's bun's internal store, not a package), but that means those packages are invisible to the wildcard even though they're genuinely installed and importable.

Confirmed via a real bun install on sst/opencode: ~65 packages (ajv, openai, cliui, escalade, yargs-parser, …) have no top-level node_modules/<name> entry at all, only a .bun/-nested one. With compilePackages: ["*"] set, perry still reports them as "still routed to runtime JavaScript... not in perry.compilePackages", and the build hard-fails on any of them that's actually imported (V8 fallback is removed).

Fix

Also walk node_modules/.bun/*/node_modules/* when materializing the wildcard, reusing the existing collect_packages_in_node_modules walker since bun's per-package node_modules directory has the exact same shape as an ordinary one.

Testing

Added enumerate_installed_packages_finds_bun_flat_store_only_packages — lays out a synthetic node_modules with a normal hoisted package plus bun-flat-store-only packages (both unscoped and scoped), asserts all three are found. cargo test -p perry enumerate_installed_packages_finds_bun_flat_store_only_packages passes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved wildcard package discovery to include Bun-isolated transitive dependencies stored under .bun, including scoped packages.
    • Prevented rare cases where installed packages could be missed during compile-time package matching.
  • Tests
    • Added regression tests covering wildcard enumeration for Bun isolated dependency layouts and workspace scenarios.

…at-store-only deps

`enumerate_installed_packages` (backing perry.compilePackages's "*" /
"@scope/*" wildcard expansion) only walked top-level node_modules/<name>
entries plus npm's own nested node_modules dedup layout. Bun's
flat/isolated linker only symlinks packages that are a direct
dependency of some workspace package at the top level — purely
transitive dependencies live only inside
node_modules/.bun/<pkg>@<version>/node_modules/<pkg>, which the
existing walker correctly (but incompletely, for this case) skips as
a dotdir.

On a real bun install this silently drops dozens of installed,
importable packages from the wildcard (confirmed via sst/opencode:
ajv, openai, cliui, escalade, yargs-parser, and ~60 others), which
then fail with "still routed to runtime JavaScript... not in
perry.compilePackages" even with compilePackages: ["*"] set.

Fix: also walk node_modules/.bun/*/node_modules/* (reusing the
existing collect_packages_in_node_modules walker, since bun's
per-package node_modules dir has the identical shape).
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c4b19f5-ba28-4c63-a399-8677037e7894

📥 Commits

Reviewing files that changed from the base of the PR and between aea82d1 and ccecd2e.

📒 Files selected for processing (2)
  • crates/perry/src/commands/compile/resolve.rs
  • crates/perry/src/commands/compile/resolve/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/perry/src/commands/compile/resolve.rs

📝 Walkthrough

Walkthrough

Extends enumerate_installed_packages to scan Bun’s .bun store alongside normal node_modules traversal, so wildcard package discovery includes Bun-isolated transitive packages. Adds regression tests for flat-store and workspace-member cases.

Changes

Bun Flat-Store Package Discovery

Layer / File(s) Summary
Bun store scanning implementation
crates/perry/src/commands/compile/resolve.rs
Adds ancestor .bun store scanning and reuses the existing node_modules walker to collect package names from nested Bun store directories.
Bun store regression tests
crates/perry/src/commands/compile/resolve/tests.rs
Adds coverage for Bun flat-store-only packages and workspace-member resolution that should include a root Bun store dependency.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main fix for Bun flat-store-only dependencies in compilePackages wildcard expansion.
Description check ✅ Passed The description covers the problem, fix, related issue, and testing, even though it doesn't follow the template headings exactly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…e, not just the nearest node_modules

The first pass only checked the *nearest* node_modules dir found by
find_node_modules for a .bun subdirectory. In a real bun
workspace/monorepo, .bun typically lives ONLY at the true root, while
a workspace member commonly has its OWN nearer (bun-created,
.bun-less) node_modules holding just its first-party sibling-package
symlinks — find_node_modules stops there and never reaches the root.

Confirmed against sst/opencode: compiling packages/opencode/src/index.ts
as project_root (a workspace member) previously still expanded the
"*" wildcard to only 167 packages (all it could see was its own
node_modules, no .bun); after walking every ancestor's
node_modules/.bun independently, it correctly expands to 1927
packages and the "still routed to runtime JavaScript" hint for
ajv/openai/cliui/etc. disappears entirely.

Added a regression test with a synthetic workspace member whose own
node_modules has no .bun, only the root's does.
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Pushed a followup fix: the first pass only checked the nearest node_modules for .bun, but in a real bun workspace/monorepo .bun typically lives only at the root while a workspace member has its own nearer (.bun-less) node_modules that find_node_modules stops at. Now walks every ancestor's node_modules/.bun independently. Re-validated against sst/opencode: the wildcard now expands from 167 → 1927 packages and the "still routed to runtime JavaScript" hint for ajv/openai/cliui/etc. is gone entirely.

… cap)

resolve/tests.rs was already ~1939 lines; appending the two PerryTS#5914
regression tests pushed it past the workspace's 2000-line file-size
lint gate. Move them to a new resolve/bun_store_tests.rs sibling
module, matching the existing pattern of splitting resolve.rs's
concerns into focused files (native_library.rs, tsconfig_paths.rs).
No behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compilePackages wildcard ("*") misses bun's non-hoisted transitive deps

1 participant