You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b317f16
Browse filesBrowse the repository at this point in the historyBrowse files
fix: write registry allowScripts keys under install-strategy=linked (#9941)
Under `install-strategy=linked`, `npm install-scripts approve <pkg>`
wrote verbose, duplicated `file:` entries pointing into
`node_modules/.store` (one per incoming symlink depth) instead of
`name@version` pins, and those store-path entries never matched at
install time.
There are two root causes.
In `findNodesForArgs` (allow-scripts-cmd.js), positional args matched
every `Link` pointing at the store package; each Link's relative
`file:.store/...` resolved spec became its own policy key and could even
strip the correct pin as stale.
In `script-allowed.js`, a store package has no `edgesIn` (they land on
its incoming Links), so `isRegistryNode` refused registry keys, and
`ls`, the post-install advisory, and prune treated a correct
`name@version` entry as matching nothing.
The fix skips `Link` nodes when matching positional args, mirroring
`collectUnreviewedScripts` and prune, so approvals key off the real
package's trusted registry identity.
`isRegistryNode` and `nameFromEdges` now delegate edge-based checks to a
link target's incoming Links, which also covers
`omit-lockfile-registry-resolved` (approve by name, like the hoisted
#9558 path).
`resolvedSourceSpecs` no longer fabricates `file:` specs from links into
the store, so store packages are never keyed by store paths and prune
cleans up the buggy entries while keeping the valid pin.
## References
Fixes#9939
Copy file name to clipboardExpand all lines: lib/utils/allow-scripts-cmd.js
+8-6Lines changed: 8 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -221,25 +221,27 @@ class AllowScriptsCmd extends BaseCommand {
221
221
// edge name. A version or range on the arg narrows the match to installed
222
222
// versions that satisfy it. Bundled deps are excluded for the same reason
223
223
// as --all. Args that match nothing are returned in `unmatched`.
224
+
// Links stay matchable by their edge name (e.g. `foo` -> `file:./local-foo`), but each match is dereferenced to its target and deduplicated, since scripts only run on the target and keying policy off a Link's resolved spec writes store paths under install-strategy=linked (npm/cli#9939).
224
225
constmatched=[]
225
226
constunmatched=[]
226
227
for(constargofargs){
227
228
const{name: wantName, range }=parsePositional(arg)
// Layout produced by install-strategy=linked: the real package lives in the store, node_modules holds a symlink to it, and the hidden lockfile records that isolated layout (npm/cli#9939).
// loadActual only trusts the hidden lockfile when it is newer than every dir under node_modules (assertNoNewer allows 10ms), and fixture creation order makes that racy, so bump its mtime past the fixture writes.
t.test('approve-scripts <name> finds a local file: dep through its link',asynct=>{
1019
+
// The Link is named `foo` while its target is named `local-foo`; positional matching must dereference the Link instead of skipping it (npm/cli#9939 review).
t.test('approve-scripts <pkg> under linked strategy without resolved URLs approves by name',asynct=>{
1040
+
// omit-lockfile-registry-resolved: the store package has no resolved URL, so it cannot be pinned but must still be approved by name via the incoming Link's edge.
t.test(`prune keeps denies with a ${state} hidden lockfile`,asynct=>{
1053
+
// With no trusted version, the versioned deny still blocks at runtime, so prune must fail closed and keep it instead of flipping the effective policy to allowed (npm/cli#9941 review).
Copy file name to clipboardExpand all lines: test/lib/commands/install-scripts.js
+61Lines changed: 61 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -334,3 +334,64 @@ t.test('install-scripts prune fails for global installs', async t => {
334
334
{code: 'EGLOBAL'}
335
335
)
336
336
})
337
+
338
+
t.test('install-scripts prune under linked strategy keeps the registry pin, drops store paths',asynct=>{
339
+
// Regression for npm/cli#9939: the buggy writer produced file:.store keys; prune must drop those and keep the valid registry pin covering the store package.
// loadActual only trusts the hidden lockfile when it is newer than every dir under node_modules (assertNoNewer allows 10ms), and fixture creation order makes that racy, so bump its mtime past the fixture writes.
0 commit comments