Skip to content

Keep a nested copy from shadowing the package it is nested under - #9

Merged
davidwhitney merged 1 commit into
mainfrom
fix/resolver-nesting-shadows-dependent
Sep 21, 2026
Merged

davidwhitney merged 1 commit into
mainfrom
fix/resolver-nesting-shadows-dependent

Conversation

@davidwhitney

@davidwhitney davidwhitney commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Keep a nested copy from shadowing the package it is nested under

A dependency that finds the wrong version above it gets a nested copy, and the resolver put that copy in the shallowest scope on the way up with nothing of that name in it. Free is not the same as usable: a copy placed in a scope is what every package below it resolves the name to, so the slot has to be clear for them too, not just empty.

jest 30.5 is where this stopped being theoretical. glob 13 sits at the top and wants minimatch 10, so minimatch 10 sits at the top. test-exclude wants glob 10, which nests, and minimatch 10, which it finds at the top. The nested glob 10 wants minimatch 9. The first empty slot for that 9 is test-exclude's own node_modules, and a copy there is the one test-exclude itself now resolves minimatch to, which breaks it. npm puts the 9 one level down, inside glob, and the resolver now does the same: a scope is skipped when a package at or below it asks for the name, currently reaches a copy further up, and would reach this one instead without being satisfied by it.

Two things follow. The version has to be known before the scope is chosen, so the registry is asked first. And the scopes worth considering stop at the copy in the way: anything above it is no use to the dependent, which would still find that copy first. That was true before by accident, because a nested copy could only ever exist below a taken slot. Now that an empty slot can be skipped, it has to be said.

Two tests pin the shape on a registry served from memory, so they say what the graph is rather than depend on what npm holds today. The live jest test that caught this passes again, as do the other real graphs.

A dependency that finds the wrong version above it gets a nested copy, and the
resolver put that copy in the shallowest scope on the way up with nothing of
that name in it. Free is not the same as usable: a copy placed in a scope is
what every package below it resolves the name to, so the slot has to be clear
for them too, not just empty.

jest 30.5 is where this stopped being theoretical. glob 13 sits at the top and
wants minimatch 10, so minimatch 10 sits at the top. test-exclude wants glob 10,
which nests, and minimatch 10, which it finds at the top. The nested glob 10
wants minimatch 9. The first empty slot for that 9 is test-exclude's own
node_modules, and a copy there is the one test-exclude itself now resolves
minimatch to, which breaks it. npm puts the 9 one level down, inside glob, and
the resolver now does the same: a scope is skipped when a package at or below
it asks for the name, currently reaches a copy further up, and would reach
this one instead without being satisfied by it.

Two things follow. The version has to be known before the scope is chosen, so
the registry is asked first. And the scopes worth considering stop at the copy
in the way: anything above it is no use to the dependent, which would still
find that copy first. That was true before by accident, because a nested copy
could only ever exist below a taken slot. Now that an empty slot can be
skipped, it has to be said.

Two tests pin the shape on a registry served from memory, so they say what
the graph is rather than depend on what npm holds today. The live jest test
that caught this passes again, as do the other real graphs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@davidwhitney
davidwhitney merged commit 9ed634b into main Sep 21, 2026
3 checks passed
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.

1 participant