Skip to content

Commit 6f9cb49

Browse files
nlflukekarrys
authored andcommitted
fix(arborist): handle link nodes in old lockfiles correctly
1 parent 6a4c8ff commit 6f9cb49

File tree

6 files changed

+96
-2
lines changed

6 files changed

+96
-2
lines changed

workspaces/arborist/lib/arborist/build-ideal-tree.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -743,15 +743,20 @@ This is a one-time fix-up, please be patient...
743743
continue
744744
}
745745

746+
// if the node's location isn't within node_modules then this is actually
747+
// a link target, so skip it. the link node itself will be queued later.
748+
if (!node.location.startsWith('node_modules')) {
749+
continue
750+
}
751+
746752
queue.push(async () => {
747753
log.silly('inflate', node.location)
748754
const { resolved, version, path, name, location, integrity } = node
749755
// don't try to hit the registry for linked deps
750756
const useResolved = resolved && (
751757
!version || resolved.startsWith('file:')
752758
)
753-
const id = useResolved ? resolved
754-
: version || `file:${node.path}`
759+
const id = useResolved ? resolved : version
755760
const spec = npa.resolve(name, id, dirname(path))
756761
const t = `idealTree:inflate:${location}`
757762
this.addTracker(t)

workspaces/arborist/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs

+47
Original file line numberDiff line numberDiff line change
@@ -36919,6 +36919,53 @@ ArboristNode {
3691936919
}
3692036920
`
3692136921

36922+
exports[`test/arborist/build-ideal-tree.js TAP inflating a link node in an old lockfile skips registry > must match snapshot 1`] = `
36923+
ArboristNode {
36924+
"children": Map {
36925+
"link-dep" => ArboristLink {
36926+
"edgesIn": Set {
36927+
EdgeIn {
36928+
"from": "",
36929+
"name": "link-dep",
36930+
"spec": "file:./link-dep",
36931+
"type": "prod",
36932+
},
36933+
},
36934+
"location": "node_modules/link-dep",
36935+
"name": "link-dep",
36936+
"path": "{CWD}/test/fixtures/old-lock-with-link/node_modules/link-dep",
36937+
"realpath": "{CWD}/test/fixtures/old-lock-with-link/link-dep",
36938+
"resolved": "file:../link-dep",
36939+
"target": ArboristNode {
36940+
"location": "link-dep",
36941+
},
36942+
"version": "1.0.0",
36943+
},
36944+
},
36945+
"edgesOut": Map {
36946+
"link-dep" => EdgeOut {
36947+
"name": "link-dep",
36948+
"spec": "file:./link-dep",
36949+
"to": "node_modules/link-dep",
36950+
"type": "prod",
36951+
},
36952+
},
36953+
"fsChildren": Set {
36954+
ArboristNode {
36955+
"location": "link-dep",
36956+
"name": "link-dep",
36957+
"path": "{CWD}/test/fixtures/old-lock-with-link/link-dep",
36958+
"version": "1.0.0",
36959+
},
36960+
},
36961+
"isProjectRoot": true,
36962+
"location": "",
36963+
"name": "old-lock-with-link",
36964+
"path": "{CWD}/test/fixtures/old-lock-with-link",
36965+
"version": "1.0.0",
36966+
}
36967+
`
36968+
3692236969
exports[`test/arborist/build-ideal-tree.js TAP link dep with a link dep > link metadeps with lockfile 1`] = `
3692336970
ArboristNode {
3692436971
"children": Map {

workspaces/arborist/test/arborist/build-ideal-tree.js

+20
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,26 @@ This is a one-time fix-up, please be patient...
11631163
])
11641164
})
11651165

1166+
t.test('inflating a link node in an old lockfile skips registry', async t => {
1167+
const checkLogs = warningTracker()
1168+
const path = resolve(fixtures, 'old-lock-with-link')
1169+
const arb = new Arborist({ path, ...OPT, registry: 'http://invalid.host' })
1170+
const tree = await arb.buildIdealTree()
1171+
t.matchSnapshot(printTree(tree))
1172+
t.strictSame(checkLogs(), [
1173+
[
1174+
'warn',
1175+
'old lockfile',
1176+
`
1177+
The package-lock.json file was created with an old version of npm,
1178+
so supplemental metadata must be fetched from the registry.
1179+
1180+
This is a one-time fix-up, please be patient...
1181+
`,
1182+
],
1183+
])
1184+
})
1185+
11661186
t.test('warn for ancient lockfile, even if we use v1', async t => {
11671187
const checkLogs = warningTracker()
11681188
const path = resolve(fixtures, 'sax')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "link-dep",
3+
"version": "1.0.0"
4+
}

workspaces/arborist/test/fixtures/old-lock-with-link/package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "old-lock-with-link",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"link-dep": "file:./link-dep"
6+
}
7+
}

0 commit comments

Comments
 (0)