Skip to content

install: sync bun.lock catalog with package.json on bun update - #36381

Closed
robobun wants to merge 5 commits into
mainfrom
farm/5c4d074a/catalog-lockfile-latest
Closed

robobun wants to merge 5 commits into
mainfrom
farm/5c4d074a/catalog-lockfile-latest

Conversation

@robobun

@robobun robobun commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #36304.

Problem

bun update --latest in a catalog workspace rewrote each catalog entry to the placeholder "latest" in memory so the resolver would fetch the newest version, then wrote the resolved range (e.g. ^2.0.0) back to package.json after install. But the lockfile is saved inside install_with_manager, before the write-back runs, so bun.lock's catalog/catalogs maps persisted the temporary "latest". Without --latest, the same ordering left the stale pre-update range in the lockfile.

// package.json after bun update --latest
"catalog": { "no-deps": "^2.0.0" }
// bun.lock
"catalog": { "no-deps": "latest" }

From then on the two files disagree on every catalog entry, so the next bun install (including --frozen-lockfile) re-resolves them over the network and fails when the registry is unreachable:

error: no-deps@catalog: failed to resolve

Fix

Compute each catalog entry's resolved literal once, before the lockfile is cloned and saved. Lockfile::preprocess_updating_catalogs (called from clean_with_logger, mirroring preprocess_update_requests) walks manager.updating_catalogs, formats the resolved version with the entry's original ^/~/exact pin, stores it on CatalogUpdateInfo, and rewrites old.catalogs in place so the saved bun.lock carries the resolved range. edit_catalogs_after_update then writes the same precomputed literal to package.json, so the two files cannot diverge. Unresolved entries (no workspace references them, or they resolve to a non-npm target) are restored to their original literal in both places.

Tests

test/cli/install/catalogs.test.ts gains three cases (fail before, pass after):

  • bun.lock's catalog maps contain the resolved ranges, not "latest", after bun update --latest
  • bun install --frozen-lockfile succeeds with the registry pointed at a closed port after bun update --latest (from root and from inside a workspace)
  • after a plain bun update, bun.lock's catalog matches the range written to package.json

All 19 catalogs.test.ts, 6 bun-update.test.ts, and 19 bun-install-registry.test.ts -t 'update|catalog|frozen' cases pass.


[review] gate passed · iteration 1 · 5 files touched

fails on main (without fix)
ASAN without fix: 4 FAILED
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/cli/install/catalogs.test.ts
bun test v1.4.0 (8cbde11cc)

test/cli/install/catalogs.test.ts:
(pass) basic > both catalog and catalogs in top-level [450.39ms]
(pass) basic > both catalog and catalogs in workspaces [348.91ms]
(pass) basic > detect changes (bun.lockb) [545.71ms]
(pass) basic > detect changes (bun.lock) [509.33ms]
(pass) update > --latest updates catalog versions in top-level [434.46ms]
(pass) update > --latest updates catalog versions in workspaces [403.96ms]
(pass) update > --latest updates catalog versions with -r [421.36ms]
274 | 
275 |     // bun.lock's catalog maps must match package.json: the temporary `latest`
276 |     // used to drive resolution must not be persisted.
277 |     const lock = await file(join(packageDir, "bun.lock")).text();
278 |     const catalogSection = lock.slice(lock.indexOf('"catalog":'), lock.indexOf('"packages":'));
279 |     expect(catalogSection).toContain('"no-deps": "^2.0.0"');
                                 ^
error: expect(received).toContain(expected)

Expected to contain: "\"n
... (truncated)

release without fix: all passed
bun test v1.4.0-canary.1 (8ad21d479)

test/cli/install/catalogs.test.ts:
(pass) basic > both catalog and catalogs in top-level [81.96ms]
(pass) basic > both catalog and catalogs in workspaces [19.23ms]
(pass) basic > detect changes (bun.lockb) [31.16ms]
(pass) basic > detect changes (bun.lock) [34.74ms]
(pass) update > --latest updates catalog versions in top-level [27.41ms]
(pass) update > --latest updates catalog versions in workspaces [23.98ms]
(pass) update > --latest updates catalog versions with -r [25.29ms]
(pass) update > --frozen-lockfile passes after --latest updates catalogs [25.14ms]
(pass) update > --frozen-lockfile works offline after --latest updates catalogs (from root) [30.39ms]
(pass) update > --frozen-lockfile works offline after --latest updates catalogs (from workspace) [32.09ms]
(pass) update > bun.lock catalog matches package.json after update without --latest [21.58ms]
(pass) update > --latest run from inside a workspace package updates the root catalog [22.83ms]
(pass) update > --latest updates the same package independently per catalog [32.40ms]
(pass) update > --latest --dry-run does not modify any package.json (from root) [29.88ms]
(pass)
... (truncated)
passes on PR (with fix)
ASAN with fix: all passed
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/cli/install/catalogs.test.ts
bun test v1.4.0 (8cbde11cc)

test/cli/install/catalogs.test.ts:
(pass) basic > both catalog and catalogs in top-level [444.87ms]
(pass) basic > both catalog and catalogs in workspaces [372.68ms]
(pass) basic > detect changes (bun.lockb) [567.25ms]
(pass) basic > detect changes (bun.lock) [555.95ms]
(pass) update > --latest updates catalog versions in top-level [466.86ms]
(pass) update > --latest updates catalog versions in workspaces [409.22ms]
(pass) update > --latest updates catalog versions with -r [730.80ms]
(pass) update > --frozen-lockfile passes after --latest updates catalogs [561.93ms]
(pass) update > --frozen-lockfile works offline after --latest updates catalogs (from root) [579.11ms]
(pass) update > --frozen-lockfile works offline after --latest updates catalogs (from workspace) [583.64ms]
(pass) update > bun.lock catalog matches package.json after update without --latest [414.11ms]
(pass) update > --latest run from inside a workspace package updates the root catalog [403.80ms]
(pass) updat
... (truncated)

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 732ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[0/5] cargo bun_bin → libbun_rust.a (--target x86_64-unknown-linux-gnu)

  nightly-2026-07-20-x86_64-unknown-linux-gnu unchanged - rustc 1.99.0-nightly (9f36de775 2026-07-19)

�[1m�[92m   Compiling�[0m bun_core v0.0.0 (/workspace/bun/src/bun_core)
�[1m�[92m   Compiling�[0m bun_errno v0.0.0 (/workspace/bun/src/errno)
�[1m�[92m   Compiling�[0m bun_ptr v0.0.0 (/workspace/bun/src/ptr)
�[1m�[92m   Compiling�[0m bun_boringssl_sys v0.0.0 (/workspace/bun/src/boringssl_sys)
�[1m�[92m   Compiling�[0m bun_safety v0.0.0 (/workspace/bun/src/safety)
�[1m�[92m   Compiling�[0m bun_zlib_sys v0.0.0 (/workspace/bun/src/zlib_sys)
�[1m�[92m   Compiling�[0m bun_cares_sys v0.0.0 (/workspace/bun/src/cares_sys)
�[1m�[92m   Compiling�[0m bun_zstd v0.0.0 (/workspace/bun/src/zstd)
�[1m�[92m   Compiling�[0m bun_picohttp v0.0.0 (/workspace/bun/src/picohttp)
�[1m�[92m   Compiling�[0m bun_output v0.0.0 (/workspace/bun/src/output)
�[1m�[92m   Compiling�[0m bun_clap v0.0.0 (/workspace/bun/src/clap)
�[1m�[92m   Compiling�[0m bun_valkey v0
... (truncated)
diff hotspot
src/install/PackageManager.rs                      |   2 +
 src/install/PackageManager/PackageJSONEditor.rs    | 113 +-----------
 .../PackageManager/updatePackageJSONAndInstall.rs  |  19 +-
 src/install/lockfile.rs                            | 198 ++++++++++++++++++++-
 test/cli/install/catalogs.test.ts                  |  74 ++++++++
 5 files changed, 279 insertions(+), 127 deletions(-)

gate history · 3 passed · 0 rejected · iteration 1

evidence per changed file
file                                                      reads  edits  tests
src/install/PackageManager.rs                                 2      3      0
src/install/PackageManager/PackageJSONEditor.rs               4      5      0
…c/install/PackageManager/updatePackageJSONAndInstall.rs      3      2      0
src/install/lockfile.rs                                       9     15      0
test/cli/install/catalogs.test.ts                             1      3      0

bun update --latest in a catalog workspace rewrote each catalog entry to
the placeholder "latest" in memory so the resolver would fetch the newest
version, then wrote the resolved range (e.g. ^2.0.0) back to package.json
after install. But the lockfile is saved inside install_with_manager, before
the write-back runs, so bun.lock's catalog/catalogs maps persisted the
temporary "latest" (or, without --latest, the stale pre-update range).

From then on package.json and bun.lock disagree on every catalog entry, so
the next bun install (including --frozen-lockfile) re-resolves them over the
network and fails when the registry is unreachable:

    error: no-deps@catalog: failed to resolve

Fix: compute each catalog entry's resolved literal once, before the lockfile
is cloned and saved. Lockfile::preprocess_updating_catalogs (called from
clean_with_logger, mirroring preprocess_update_requests) walks
manager.updating_catalogs, formats the resolved version with the entry's
original ^/~/exact pin, stores it on CatalogUpdateInfo, and rewrites
old.catalogs in place. edit_catalogs_after_update then writes the same
precomputed literal to package.json, so the two files can't diverge.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 19b147a6-0c09-4129-8b02-96d5422c264c

📥 Commits

Reviewing files that changed from the base of the PR and between 8afcd4b and 8cbde11.

📒 Files selected for processing (5)
  • src/install/PackageManager.rs
  • src/install/PackageManager/PackageJSONEditor.rs
  • src/install/PackageManager/updatePackageJSONAndInstall.rs
  • src/install/lockfile.rs
  • test/cli/install/catalogs.test.ts

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

Comment thread src/install/lockfile.rs Resolved
Comment thread src/install/PackageManager.rs Resolved
Comment thread src/install/lockfile.rs Resolved
Comment thread src/install/lockfile.rs Resolved
Comment thread src/install/lockfile.rs Resolved
Comment thread src/install/lockfile.rs Resolved
Comment thread src/install/lockfile.rs Resolved
Comment thread src/install/lockfile.rs Resolved
@robobun

robobun commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI on 8cbde11 (build 85381) is green for everything this diff touches: catalogs.test.ts 19/19, bun-update.test.ts, bun-install-registry.test.ts all pass on every lane.

Remaining red is unrelated to src/install/:

Ready for review.

Comment thread src/install/lockfile.rs Resolved
@robobun

robobun commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found — the three earlier nits (dead EditOptions param, inserting get_or_put_adapted, pub on format_catalog_update_literal) are all addressed. Deferring to a human because this adds ~130 new lines of state mutation inside Lockfile::clean_with_logger, which runs on every install with a lockfile; that path is critical enough to warrant a maintainer look.

What was reviewed:

  • preprocess_updating_catalogs mirrors the sibling preprocess_update_requests (same string_builder! count→allocate→append→clamp shape, same #[cold] wrapper convention).
  • format_catalog_update_literal is a straight extraction of the pin-style logic that previously lived in edit_catalogs_after_update; behavior unchanged.
  • The catalog-map rewrite now uses non-inserting get_index_adapted, so a miss is a no-op — checked both the group and the entry lookup.
  • New tests cover --latest, plain update, and offline --frozen-lockfile from both root and workspace.
Extended reasoning...

Overview

Follow-up to #36304. bun update [--latest] in a catalog workspace was saving bun.lock before the resolved catalog versions were computed, so the lockfile persisted either the temporary "latest" placeholder or the stale pre-update range. This PR moves the resolved-literal computation earlier — into Lockfile::clean_with_logger via a new preprocess_updating_catalogs — so the same literal is written to both bun.lock and package.json. Touches PackageManager.rs (+1 field on CatalogUpdateInfo), PackageJSONEditor.rs (−107 lines: resolution logic moved out; dead EditOptions param dropped), updatePackageJSONAndInstall.rs (call sites updated), lockfile.rs (+~190 lines: new preprocess_updating_catalogs, format_catalog_update_literal, cold wrapper), and catalogs.test.ts (+74 lines: three new tests).

Security risks

None identified. All inputs are the user's own package.json and lockfile; no network, path, or privilege boundaries are crossed. The string_builder capacity accounting is bounded by the number of catalog entries the user wrote.

Level of scrutiny

High. clean_with_logger runs on every bun install/update with an existing lockfile, and old.catalogs is cloned into the saved bun.lock. A bug here could silently corrupt catalog entries in lockfiles across the user base. The new function is guarded by !manager.updating_catalogs.is_empty() (only populated during bun update with catalogs present), which limits the blast radius, but the path itself is critical infrastructure. This is not a mechanical change — it relocates ~100 lines of logic from post-install to pre-lockfile-save and rewires the data flow through a new CatalogUpdateInfo field.

Other factors

  • All three prior review findings were addressed in e4b3f28 and 8cbde11.
  • The new code closely follows the existing preprocess_update_requests sibling: same two-pass string_builder pattern, same #[cold] #[inline(never)] outlining, same dependency::parse invocation shape. format_catalog_update_literal is a verbatim extraction of the block removed from edit_catalogs_after_update.
  • Verified the Semver:: path in format_catalog_update_literal resolves via use bun_semver::{self as Semver, ...} at lockfile.rs:24.
  • Test coverage is good: the offline --frozen-lockfile test (registry pointed at a closed port) directly proves the fix; the plain-update test covers the non---latest path; assertions on the bun.lock catalog section check both ^ and ~ pin styles and assert "latest" is absent.
  • The !update_to_latest exact-pin check moved from resolve_catalog_dependency(dep) to old.catalogs.get(...) — semantically equivalent for this purpose (both read the catalog entry's version), and covered by the existing "update without --latest stays in range" test.

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

Closing this one: all of the bun update lockfile-staleness symptoms (declared ranges / pin style / npm: aliases / catalog entries / $ref overrides staying stale in bun.lock because it is saved before the package.json write-back, plus the stale nested copies after a direct-dep bump) share a root cause, so we're fixing the whole family together in one package-manager PR that's about to go up, tracked under #13388. The diff and tests here were used as input for that — thank you. (This comment was written by Claude, on behalf of the Bun team.)

@robobun

robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Sounds good, thanks. One thing worth carrying over to the consolidated fix: the catalog case is slightly different from the direct-dependency case in that --latest writes a temporary latest placeholder into the in-memory catalog map before resolution, so the lockfile needs the resolved literal written back into lockfile.catalogs (not just the root dependency literals) before clean() clones it. The offline --frozen-lockfile tests in this PR's catalogs.test.ts diff are a direct check for that.

Jarred-Sumner added a commit that referenced this pull request Aug 14, 2026
…ilter/--catalog, nested overrides, transitive update, and workspace fixes (#38333)

Brings Bun's package manager to parity with pnpm for monorepo workflows,
and fixes the bugs found while checking every command against pnpm's
implementation, pnpm's test suites, pnpm's open issue tracker, pnpm's
docs, npm's arborist fixtures, and — for `bun update` — running real
pnpm and Bun side by side on the same projects.

### What does this PR do?

#### New commands

- **`bun dedupe [--check]`** — collapses duplicate versions in
`bun.lock` onto the smallest set that still satisfies every dependent's
range, using only versions already in the lockfile, then installs. Never
downgrades a direct dependency unless that is the only way to drop a
version; keeps patched versions (and anything needed to reach them, and
says so); refuses to run on a lockfile that is behind `package.json`.
`--check` exits 1 without writing.
- **`bun prune [--production | --omit=…] [--dry-run] [--filter <ws>]`**
— removes everything in `node_modules` that the lockfile does not put
there; `--production` leaves exactly what `bun install --production`
would. Hoisted and isolated layouts, Windows junctions and shims,
workspace links, bundled deps; refuses when `package.json` and
`bun.lock` disagree or when `node_modules` was laid out by a different
linker; understands turbo-pruned checkouts.
- **`bun pm licenses [--json] [--prod|--dev] [--long] [--filter <ws>]`**
— installed packages grouped by license, with a `(dev)` marker and
`paths`/`license`/`description` in `--json`.
- **`bun audit fix [--latest] [--dry-run] [--json]`** — moves each
vulnerable package to the lowest safe version its dependents accept, per
installed instance; rewrites exact pins when that is the only way;
`--latest` also rewrites your own declared ranges (root, workspace,
catalog) so a semver-major fix can be taken, and every blocked or
unfixable item is followed by the command that resolves it (`bun audit
fix --latest`, `bun audit --ignore GHSA-…`); re-audits the tree it
actually installed and reports/exits from that second response (npm's
`_submitQuickAudit`), so an advisory that starts at the version it moved
to is not missed; works across registries; security fixes bypass
`minimumReleaseAge` with an annotation. `bun audit --json` honors
`--audit-level`/`--ignore` for its exit code; `--omit` is honored by
`audit` and `licenses`.

#### `bun update` semantics (pnpm's model)

- A bare `bun update` re-resolves **transitive** packages too — every
edge moves to the newest version its own range (or dist-tag) allows, per
dependent, so `bun.lock` no longer stays stale after an update;
overrides/catalogs changed since the last install are honored. From a
workspace member or `--filter`, only what the selected workspaces reach
is re-resolved; from the root, everything.
- `bun update <name>` reaches any depth, matches `npm:` aliases by real
name, updates in place, never adds to `package.json`, and errors on a
name nothing selected depends on. `-r`/`--filter` fan a named update out
across workspaces. `--latest` never downgrades a locked version that is
ahead of the tag, and `update <name> --latest` also refreshes that
package's own dependencies.
- Plain updates keep dist-tag literals and non-caret ranges (`*`, `1.x`,
`^1 || ^2`) exactly as written and only move the lockfile; `--latest`
rewrites them to the resolved version as before. `bun update -i` applies
only what you selected. New: positional patterns (`bun update
'@types/*'`), `--dev`/`--prod`/`--no-optional`, `-L`, `bun up`.
- `package.json` is written after resolution and `bun.lock`'s declared
ranges, overrides and catalogs are re-derived from the final
`package.json`, replacing the per-command literal rewriting; a no-op
update leaves the file byte-identical.

#### Overrides

- **Nested overrides** (#6608): npm's nested objects, yarn's `a/b` paths
and pnpm's `a>b` selectors, applied to the direct parent→child edge;
**version-scoped targets** (`"lodash@<4.17.21": "4.17.21"`, the shape
`pnpm audit --fix` writes), matched against the dependent's declared
range as pnpm does. Rules persist inside the `overrides` section and the
file is stamped `lockfileVersion: 3` **only when such rules exist** —
existing lockfiles are byte-identical. Flat overrides additionally fix
`$ref` to workspace-member deps, catalog-valued rules going stale, and
warn on pnpm's `-` / `pkg@` forms.

#### Workspaces and filters

- `bun add|remove|update … --filter <ws>` (also `-F`, also `bun install
<pkg> --filter`) edits the selected workspaces' `package.json` files and
**links only those workspaces**, like `bun install --filter`. Filters
gain pnpm's relation selectors (`foo...`, `...foo`, `foo^...`,
`...^foo`) and `{dir}` subtrees, for the install family **and** `bun run
--filter`; `--filter` may precede the subcommand; every command warns
about patterns that match nothing; `add`/`remove` no longer select the
root implicitly.
- `bun add <pkg> --catalog[=name]` reuses an existing catalog entry,
keeps a range an explicit version fits, catalogs the range a package
already declares, decides per target, and refuses workspace names and
local paths; a plain `bun add` uses a default-catalog entry when one
exists. A package defined in both `catalog` and `catalogs.default` is an
error. `catalog:` peers of registry packages bind to the importer's copy
instead of the root catalog.
- `--frozen-lockfile` / `bun ci` on turbo-pruned monorepos: pruned-away
workspaces are tolerated, a survivor depending on a pruned workspace is
an error, catalog subsets are accepted, and an overrides/catalogs change
is a frozen failure.

#### One output vocabulary

Every command here prints the install family's shapes: header, glyph
rows (`+`/`-`/`↑`, dedupe's `↳ name old → new`), exactly one noun-first
summary line with counts and a duration (`2 duplicate versions removed,
3 packages installed (checked 5 packages) [12ms]`, `N packages removed
(checked C) [t]`), no-ops that say what was checked, remedies printed as
copy-pasteable command lines, warnings as `warn:`, `--silent` printing
nothing, and errors with their remedy together on stderr. Transitive and
named updates render as the summary's `↑` rows (once per package;
`--dry-run` prints the same rows plus `N packages would be updated`);
dedupe reports after the install it triggers, so lifecycle-script output
never splits it. A lockfile whose bytes did not change is no longer
rewritten (`Saved lockfile` only prints on a real write;
`--lockfile-only` no-ops print `Done! Checked N packages (no changes)`).
This came out of running every command against fixtures and comparing
with `install`/`add`/`remove` (95 findings, all fixed).

#### Config precedence

A project's `bunfig.toml` now beats any `.npmrc` (project or user-level)
for the same key (npmrc files → bunfig's set fields → CLI); npmrc-only
settings such as `//host/:_authToken` still attach to bunfig-declared
registries, matched by host and path regardless of how either file
spells the trailing slash.

#### Lockfile migration

- `package-lock.json`: rebuilt around a reachability walk that derives
each resolution from the entry itself. Fixes `git+https://github.com/…`
resolutions being written unparseably (the next install threw the
lockfile away), root `bundleDependencies` migrating to an **empty**
lockfile, lockfileVersion 1 (and npm's upcoming 4) making `bun install`
exit 1 instead of resolving fresh, dependency-level bundles,
`dependencies`+`optionalDependencies` double edges, unreferenced entries
aborting the migration, duplicate packages for identical `name@version`
at nested paths, lost `optionalPeers`, lost integrity when a bundled
copy was seen first, and `overrides` not being carried over. All 57 of
arborist's v2/v3 fixture projects are vendored and migrated under
snapshot.
- `pnpm-lock.yaml` v9: bare-hash `patchedDependencies`, snapshot
aliases, `catalog:default`, recorded tarball URLs, git `path:`,
multi-document files, `runtime:` entries, named registries,
peer-suffixed keys chosen per importer, injected workspaces,
manifest-only importer deps.

#### Isolated linker

- An existing store entry whose dependencies re-resolved (override,
dedupe, update) now has its links refreshed on the next install
(measured cost below). `bun prune` builds the same store the installer
builds, so stale `name@version+<peerhash>` variants left by peer bumps
are removed and a kept package's real entry never is (whether it was
installed with full or `--production` features); on the hoisted linker,
dedupe / audit fix / update delete the nested copies whose rows they
collapsed instead of leaving the old copy loadable.
- Blocked entries resume through per-entry intrusive waiter lists
instead of a scan of every store entry after each completion (robobun's
#25983/#28425 attempted this). Measured on the reporter's repro from
#25799 (2,259 store entries) and a synthetic 6,425-entry monorepo, PR
build vs merge-base build: main-thread CPU in the link phase drops 0.85
→ 0.33 s and 5.5 → 0.85 s (the removed work grows quadratically); wall
time is unchanged with spare cores and 16% / 26% faster pinned to one
CPU, the CI/Docker shape in those reports. (The minute-long installs
originally reported were peer resolution, fixed before this PR's base.)
- Two pre-existing leaks surfaced by the new LSan-enabled tests are
fixed: the header buffer of every authenticated registry request, and
the per-entry lifecycle-script lists.

#### Other bug fixes

`bun add x@npm:pkg` writes a range; `bun add --trust a b` no longer
drops `b` when `a` was already trusted; `bun add x --dev` no longer
rewrote every group in `bun.lock`; `catalog:` peer hoisting;
`dependency::Version::eql` treated all `catalog:` specifiers as equal; a
`file:` package whose dependencies reach itself (its own name, an `npm:`
alias under its own name, two link targets depending on each other — the
shapes a `package-lock.json` migration produces, and #25202's
`workspace:.` self-reference) hung `bun install` forever in the hoisting
tree — the migration shapes now install, and #25202's literal shape now
terminates with `Workspace dependency "foo" not found` rather than
installing as npm does; a peer of a `file:` package that was only placed
nested was also written to `optionalPeers` in a migrated bun.lock, so
the next `--frozen-lockfile` failed and a plain install rewrote the
lockfile; `catalog:` literals in `bun update`; alias output in the
install summary; help/completions for everything above.

#### Behavior changes to note in the release notes

- `bun update` moves transitive packages; `bun update <name>` no longer
adds an undeclared package (exit 1); `--production`/`--prod` on update
means "only update `dependencies` and `optionalDependencies`" (a group
filter like `--dev`, not the install flag) and `-r`+names with no match
is an error; `-i` updates only the selection.
- Project `bunfig.toml` overrides any `.npmrc`.
- `bun install <pkg> --filter x` edits `x` (not the root); `bun add y
--filter x` no longer installs a package named `x`; `add`/`remove
--filter '*'` no longer includes the root.
- A plain `bun add x` in a workspace whose default catalog lists `x`
writes `catalog:`; `audit fix` may rewrite exact pins;
`--frozen-lockfile --lockfile-only` writes nothing; overrides/catalog
changes fail frozen installs.
- One-time lockfile churn after upgrading for projects with `catalog:`
peers or dead `pkg@range` override rows; lockfiles that use
nested/scoped overrides are v3 and unreadable by older Bun (only when
opted in). Turborepo, Nx and Dependabot have been checked; the needed
upstream changes are open (nrwl/nx#36666 covers v2 and v3;
vercel/turborepo#13740 accepts v3 and preserves the object rows through
prune — turborepo main today parses v2 and rejects v3; dependabot needs
nothing). Note v2 itself only exists on the 1.4 line.
- `bun audit --json` keeps npm's contract: `--audit-level`/`--ignore`
decide the exit code, the JSON document is the full registry report
(closes #31013 as won't-change). Automatic removal of stale
`node_modules` entries on plain `bun install` (#32974) is separate from
this PR: `bun prune` is the manual form, and dedupe / audit fix / update
now clean up the nested copies they collapse on the hoisted linker;
#32974 should reuse prune's planner, and #29512 (sbom) is sequenced
after this so it can build on `reachable.rs` instead of carrying its own
walk.
- Deliberately kept where we differ from pnpm: root `bun update` covers
the whole workspace; dependents whose ranges allow follow a moved
version (one copy, not two); `--latest` works on transitive names;
`--no-save` touches neither file; prune deletion failures exit 1; audit
requests stay per-registry.

#### Performance

Measured on a 1,113-package Next/Prisma/MUI app (PR build vs a PR build
of the merge base, interleaved, plus canary and 1.3.14): every hoisted
cell is within noise except no-op install, +0.8 ms (+2%, identical
syscalls); isolated no-op is +1.9 ms (+3.9%) — the deliberate cost of
re-checking existing entries' links every install rather than persisting
a stamp file. Everything added is otherwise off the plain-install path
(gated on the feature being used or on a diff), and id-indexed sets are
bitsets.

### How did you verify your code works?

~1,100 new or ported test cases across the install suites (designed
behavior, cases ported from pnpm's suites, pinning tests for pnpm bugs
this implementation is immune to, arborist's fixtures, and the CI review
findings), all `toStrictEqual`; the whole `test/cli/install` directory
passes locally and the existing suites are unchanged except where a
pre-existing expectation was deliberately changed (each listed above).
`bun update` was additionally verified with a rerunnable differential
harness that runs pnpm 11 and this branch on 26 scenario families
against one registry and diffs the resulting resolutions edge by edge —
after this PR only the deliberate differences above remain. Ecosystem:
Turborepo, Nx and Dependabot were checked against the new lockfile
output.

Co-authored work absorbed with credit: @kjanat's #38190 (alias handling,
co-author on the commit), @charpeni's #31143 and @crystalin's #34407
(both superseded), and the tests of the earlier `bun update` PRs (#31752
by @zlotnika, #33127, #36381, #36729, #38224). robobun's #34688
(folder-dependency cycles; its tests are lifted, co-author on the
commit) and #37289 (migrated optionalPeers; its test is lifted,
co-author on the commit) were fixed independently here and are closed by
this PR. #28422's quadratic scan is fixed here as well (already closed).

Related but not closed — `bun prune` gives these a manual fix while the
automatic-cleanup asks stay open: #8662, #26305, #29793, #21216, #16176.
Also related: #10930, #26970, #26751.

Fixes #1343
Fixes #3605
Fixes #14719
Fixes #24122
Fixes #18612
Fixes #20238
Fixes #25826
Fixes #23615
Fixes #26973
Fixes #20593
Closes #31013
Fixes #28959
Fixes #28402
Fixes #27897
Fixes #26675
Fixes #10949
Fixes #18504
Fixes #13388
Fixes #24523
Fixes #6608
Fixes #19059
Fixes #16569
Fixes #8262
Fixes #11901
Fixes #13469
Fixes #25202
Closes #29664
Closes #31143
Closes #34407
Closes #34688
Closes #37289
Closes #38190

---------

Co-authored-by: Kaj Kowalski <info@kajkowalski.nl>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: robobun <117481402+robobun@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants