Repository navigation
fix: keep installs of one package version apart when their dependencies differ - #29
Conversation
…ependencies differ Traced packages were grouped by name@version, so pnpm peer variants (e.g. @sentry/opentelemetry@10.53.1 with @opentelemetry/core 1.30.1 and 2.12.0) shared one output folder linked to whichever install came last. A group now splits into `.versions/<name>@<version>_<n>` copies only while its installs load different copies of a dependency; identical installs stay one copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
engines requires Node >=22 since bd236c4, whose native-binary lookup uses fs.glob; on Node 20 that lookup finds nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four installs of one version, two loading only part of its peers, could get three copies where two serve them all, depending on trace order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… another An install that loads only some of a package's dependencies could keep a copy of its own when the copy it matches only appeared after its dependency split. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The split loop kept each install inside the copy it got in the pass before, so a later split or merge one level down could leave extra copies above it. Each pass now groups every name@version anew from the copies its dependencies got, until a pass changes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picking the first matching copy could still leave one copy more than needed, e.g. four installs that each load a different two of a package's peers. Two installs need separate copies only when they load different copies of one dependency, so each version now gets the fewest copies that keeps such installs apart, found by trying 1, 2, ... copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The exact search for the fewest copies took minutes once one version had about 40 installs that load only part of its dependencies, so each version goes back to a single ordered pass, in which any two copies load a different copy of some dependency. The order is now fixed: the app's own install first, then the installs that load more, then by path, so identical builds give identical output and the top-level link names the app's own copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With several copies of one package, the top-level node_modules/<name> linked to the newest, so an app on an older version than an external dependency's loaded that dependency's copy. It now links to the copy the app's own files import, and to the newest only when the app imports none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the app imports none of a package's copies, the top-level link went to whichever copy of the newest version nft traced first, so identical builds could link different copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…very build Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fallback gave every install its own copy, so two installs that load the same dependency folders, or none, were copied twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sampling every folder copied a binary once per identical nested install into the same output copy and globbed each of them. Copies are now assigned first, binaries are looked up once per output copy, and optional dependencies are sampled per name@version again, as on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With bundle: false the app's files beside its entry are traced as its own package, so a version only they import lost the top-level link to the newest version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A package folder that only encloses the entry, such as the workspace root the app imports, is a dependency and must not take the app's top-level link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An entry under node_modules belongs to its node_modules/<name> folder, not to a nearer package.json that only sets the module type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
resolve conflict + refactor then I'll merge |
…pies PnP's local-fork version suffix now applies before assignCopies, so a fork and the npm package of its name and version never share a copy; the PnP app import and npm: alias links use output copies instead of versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I'm resolving the conflict with #27 and refactoring now, and I'll push both by 2026-10-30T04:00Z. |
…ackage stay apart Two npm: aliases of lodash at different versions are both traced as lodash, so the installs that load them looked identical and shared a copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… version An alias installing lodash@4.17.21 and one installing lodash-es@4.17.21 had the same copy label, so installs that loaded them under one name shared a copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Done in 44c5922: it merges The refactor found nothing worth changing in the new code. Its ratings of what the alias fixes touch, before ⇒ after them:
|
When pnpm installs one package version twice because its importers give it different peer versions, the output keeps one copy of it, and both importers get the dependency versions of whichever install was linked last.
main@sentry/node@10.53.1(core 2.x) next to its own@sentry/opentelemetry@10.53.1on@opentelemetry/core@1.30.1@sentry/node's@sentry/opentelemetryloads core 1.30.1This PR still keeps one copy per name and version, and splits it only where installs load different copies of one dependency, checked through their dependencies' own dependencies, so any two copies of a version differ in what they load. The one exception is a dependency cycle through several split packages whose grouping never settles: there, installs share a copy only when they load the very same folders, which can leave a copy more than needed. Identical installs stay one copy, as you asked in #28 (comment). CI moves to Node 22, the lowest version
enginesallows, because on Node 20 the lookup for prebuilt.nodebinaries finds nothing.Closes #28
What you should see
1. The Sentry app from #28 loads the same versions after the build as from source:
2. It adds only the copy that's needed: the Sentry output grows from 1178 to 1186 files, because
@sentry/opentelemetryis now two copies.test/vitebuilds the same 91 files as onmain.3.
test/peerschecks the versions each install loads and how many copies ship, including installs that differ only in peers they never load, and installs that load only part of a package. Withbundle: false, it also checks that the app's other files load the app's versions.Approach
Rated 8/10: per name and version, each install joins the first copy it doesn't conflict with, in a fixed order, repeated until nothing changes (if it never settles, installs share a copy only when they load the very same folders); the top-level link goes to the copy the app imports. The exact fewest copies is graph colouring: it took 128 s for 44 installs of one version, so this PR doesn't promise it. Keying every copy by its source folder (4/10) copies identical installs too. Full record: https://gist.github.com/nitedani-agent/3b9f560a214be09ffffde48f5dfc584d
Loop A: 16 passes, the last on d3c14e4 found nothing
Fixed, by area:
bundle: falseit missed what the app's other files import (5aad5b0, 75ead6d, 503b554).Below the bar: a dependency cycle through three split packages, each loaded only in part, can keep a copy more than needed, with the output still right. Full reports: https://gist.github.com/nitedani-agent/664c00e5c0d55d8901bf71328875533d
Loop B: seven rounds, the last clean on d3c14e4
Fixed: no test showed that each split copy ships its prebuilt binary (6bb268c, after a4c7838 moved CI to Node 22), and a greedy grouping that could keep three copies where two serve all installs (led to 75895a0, then e40cb4c). A pass over the file's history reused
uniquePackages(4418038). Full reports: https://gist.github.com/nitedani-agent/3db4150663fc0ed9bbaa0747a566f41fFresh read: nine reads as you, the last says merge as is on d3c14e4
Fixed: identical installs each got a copy when no pass settles (d1c8437), a prebuilt binary copied twice (02bbf8e), the top-level link with
bundle: false(5aad5b0, 75ead6d, 503b554), and under Yarn PnP, installs whosenpm:aliases point at different versions or packages shared a copy (39ec600, d3c14e4). Below the bar, and onmaintoo: a rebuild into an existing output folder traces nothing and keeps the first build's dependencies, and an optional peer missing from one install (debug'ssupports-color) is found after copying, because single-version packages sit at the output's top level. Full reports: https://gist.github.com/nitedani-agent/6ae84d184f7feafa41e038c8c6b9fa3dGates: install, build and the five test suites exit 0 on d3c14e4, on Node 22 and Node 26
pnpm install,pnpm buildtest/vite,test/isolated,test/assetstest/peerstest/pnp