Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created June 3, 2021 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/fc8a644e53b712608129b88b4c1d6f04 to your computer and use it in GitHub Desktop.
Save isaacs/fc8a644e53b712608129b88b4c1d6f04 to your computer and use it in GitHub Desktop.
diff --git a/lib/arborist/build-ideal-tree.js b/lib/arborist/build-ideal-tree.js
index 73a6f667..5db11eb3 100644
--- a/lib/arborist/build-ideal-tree.js
+++ b/lib/arborist/build-ideal-tree.js
@@ -7,7 +7,7 @@ const semver = require('semver')
const promiseCallLimit = require('promise-call-limit')
const getPeerSet = require('../peer-set.js')
const realpath = require('../../lib/realpath.js')
-const { resolve } = require('path')
+const { resolve, dirname } = require('path')
const { promisify } = require('util')
const treeCheck = require('../tree-check.js')
const readdir = promisify(require('readdir-scoped-modules'))
@@ -661,7 +661,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
const ancient = meta.ancientLockfile
const old = meta.loadedFromDisk && !(meta.originalLockfileVersion >= 2)
- if (inventory.size === 0 || !ancient && !(old && this[_complete]))
+ if (inventory.size === 0 || !ancient && !old)
return
// if the lockfile is from node v5 or earlier, then we'll have to reload
@@ -688,10 +688,12 @@ This is a one-time fix-up, please be patient...
this.log.silly('inflate', node.location)
const { resolved, version, path, name, location, integrity } = node
// don't try to hit the registry for linked deps
- const useResolved = !version ||
- resolved && resolved.startsWith('file:')
- const id = useResolved ? resolved : version
- const spec = npa.resolve(name, id, path)
+ const useResolved = resolved && (
+ !version || resolved.startsWith('file:')
+ )
+ const id = useResolved ? resolved
+ : version || `file:${node.path}`
+ const spec = npa.resolve(name, id, dirname(path))
const sloc = location.substr('node_modules/'.length)
const t = `idealTree:inflate:${sloc}`
this.addTracker(t)
diff --git a/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs b/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs
index 94571bd4..1adf566b 100644
--- a/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs
+++ b/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs
@@ -13167,7 +13167,6 @@ ArboristNode {
},
"location": "node_modules/linked-dep",
"name": "linked-dep",
- "packageName": "target",
"path": "{CWD}/test/fixtures/link-dep-empty/node_modules/linked-dep",
"realpath": "{CWD}/test/fixtures/link-dep-empty/target",
"resolved": "file:../target",
@@ -121526,6 +121525,36 @@ ArboristNode {
},
"dev": true,
"edgesIn": Set {
+ EdgeIn {
+ "from": "node_modules/@babel/plugin-proposal-object-rest-spread",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/@babel/plugin-syntax-jsx",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/@babel/plugin-syntax-object-rest-spread",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/@babel/plugin-transform-destructuring",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/@babel/plugin-transform-react-jsx",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
EdgeIn {
"from": "node_modules/import-jsx",
"name": "@babel/core",
@@ -121968,6 +121997,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -121998,6 +122033,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -122022,6 +122063,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -122046,6 +122093,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -122070,6 +122123,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-builder-react-jsx" => EdgeOut {
"name": "@babel/helper-builder-react-jsx",
"spec": "^7.7.4",
@@ -122798,6 +122857,14 @@ ArboristNode {
"type": "prod",
},
},
+ "edgesOut": Map {
+ "@types/react" => EdgeOut {
+ "name": "@types/react",
+ "spec": ">=16.8.0",
+ "to": null,
+ "type": "peerOptional",
+ },
+ },
"location": "node_modules/auto-bind",
"name": "auto-bind",
"path": "{CWD}/test/fixtures/tap-react15-collision-legacy-sw/node_modules/auto-bind",
@@ -125600,6 +125667,13 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@types/react" => EdgeOut {
+ "error": "MISSING",
+ "name": "@types/react",
+ "spec": ">=16.8.0",
+ "to": null,
+ "type": "peer",
+ },
"ansi-escapes" => EdgeOut {
"name": "ansi-escapes",
"spec": "^4.2.1",
@@ -125660,6 +125734,13 @@ ArboristNode {
"to": "node_modules/prop-types",
"type": "prod",
},
+ "react" => EdgeOut {
+ "error": "INVALID",
+ "name": "react",
+ "spec": ">=16.8.0",
+ "to": "node_modules/react",
+ "type": "peer",
+ },
"react-reconciler" => EdgeOut {
"name": "react-reconciler",
"spec": "^0.24.0",
@@ -128695,6 +128776,27 @@ ArboristNode {
"spec": "15",
"type": "prod",
},
+ EdgeIn {
+ "error": "INVALID",
+ "from": "node_modules/ink",
+ "name": "react",
+ "spec": ">=16.8.0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "error": "INVALID",
+ "from": "node_modules/react-reconciler",
+ "name": "react",
+ "spec": "^16.0.0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "error": "INVALID",
+ "from": "node_modules/treport",
+ "name": "react",
+ "spec": "^16.8.6",
+ "type": "peer",
+ },
},
"edgesOut": Map {
"create-react-class" => EdgeOut {
@@ -128778,6 +128880,13 @@ ArboristNode {
"to": "node_modules/prop-types",
"type": "prod",
},
+ "react" => EdgeOut {
+ "error": "INVALID",
+ "name": "react",
+ "spec": "^16.0.0",
+ "to": "node_modules/react",
+ "type": "peer",
+ },
"scheduler" => EdgeOut {
"name": "scheduler",
"spec": "^0.18.0",
@@ -131266,6 +131375,13 @@ ArboristNode {
"to": "node_modules/ms",
"type": "prod",
},
+ "react" => EdgeOut {
+ "error": "INVALID",
+ "name": "react",
+ "spec": "^16.8.6",
+ "to": "node_modules/react",
+ "type": "peer",
+ },
"string-length" => EdgeOut {
"name": "string-length",
"spec": "^3.1.0",
@@ -131342,6 +131458,12 @@ ArboristNode {
"to": "node_modules/source-map-support",
"type": "prod",
},
+ "typescript" => EdgeOut {
+ "name": "typescript",
+ "spec": ">=2.0",
+ "to": "node_modules/typescript",
+ "type": "peer",
+ },
"yn" => EdgeOut {
"name": "yn",
"spec": "^3.0.0",
@@ -131450,6 +131572,12 @@ ArboristNode {
"spec": "^3.7.2",
"type": "prod",
},
+ EdgeIn {
+ "from": "node_modules/ts-node",
+ "name": "typescript",
+ "spec": ">=2.0",
+ "type": "peer",
+ },
},
"location": "node_modules/typescript",
"name": "typescript",
@@ -150196,12 +150324,36 @@ ArboristNode {
"spec": ">=16.8.0",
"type": "peer",
},
+ EdgeIn {
+ "from": "node_modules/react-reconciler",
+ "name": "react",
+ "spec": "^16.0.0",
+ "type": "peer",
+ },
EdgeIn {
"from": "node_modules/tap",
"name": "react",
"spec": "^16.12.0",
"type": "prod",
},
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/ink",
+ "name": "react",
+ "spec": ">=16.8.0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/react-reconciler",
+ "name": "react",
+ "spec": "^16.0.0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/treport",
+ "name": "react",
+ "spec": "^16.8.6",
+ "type": "peer",
+ },
},
"edgesOut": Map {
"loose-envify" => EdgeOut {
@@ -150272,6 +150424,12 @@ ArboristNode {
"to": "node_modules/prop-types",
"type": "prod",
},
+ "react" => EdgeOut {
+ "name": "react",
+ "spec": "^16.0.0",
+ "to": "node_modules/react",
+ "type": "peer",
+ },
"scheduler" => EdgeOut {
"name": "scheduler",
"spec": "^0.18.0",
@@ -151649,15 +151807,9 @@ ArboristNode {
},
"tap" => ArboristNode {
"bundleDependencies": Array [
- "@types/react",
- "import-jsx",
"ink",
- "minipass",
- "signal-exit",
- "tap-parser",
- "tap-yaml",
"treport",
- "yaml",
+ "@types/react",
],
"children": Map {
"@babel/code-frame" => ArboristNode {
@@ -151718,6 +151870,36 @@ ArboristNode {
},
},
"edgesIn": Set {
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/@babel/plugin-proposal-object-rest-spread",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/@babel/plugin-syntax-jsx",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/@babel/plugin-syntax-object-rest-spread",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/@babel/plugin-transform-destructuring",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/@babel/plugin-transform-react-jsx",
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "type": "peer",
+ },
EdgeIn {
"from": "node_modules/tap/node_modules/import-jsx",
"name": "@babel/core",
@@ -152210,6 +152392,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/tap/node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -152240,6 +152428,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/tap/node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -152264,6 +152458,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/tap/node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -152288,6 +152488,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/tap/node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-plugin-utils" => EdgeOut {
"name": "@babel/helper-plugin-utils",
"spec": "^7.0.0",
@@ -152312,6 +152518,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@babel/core" => EdgeOut {
+ "name": "@babel/core",
+ "spec": "^7.0.0-0",
+ "to": "node_modules/tap/node_modules/@babel/core",
+ "type": "peer",
+ },
"@babel/helper-builder-react-jsx" => EdgeOut {
"name": "@babel/helper-builder-react-jsx",
"spec": "^7.7.4",
@@ -152624,6 +152836,18 @@ ArboristNode {
"spec": "^16.9.16",
"type": "prod",
},
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/auto-bind",
+ "name": "@types/react",
+ "spec": ">=16.8.0",
+ "type": "peerOptional",
+ },
+ EdgeIn {
+ "from": "node_modules/tap/node_modules/ink",
+ "name": "@types/react",
+ "spec": ">=16.8.0",
+ "type": "peer",
+ },
},
"edgesOut": Map {
"@types/prop-types" => EdgeOut {
@@ -152773,6 +152997,14 @@ ArboristNode {
"type": "prod",
},
},
+ "edgesOut": Map {
+ "@types/react" => EdgeOut {
+ "name": "@types/react",
+ "spec": ">=16.8.0",
+ "to": "node_modules/tap/node_modules/@types/react",
+ "type": "peerOptional",
+ },
+ },
"location": "node_modules/tap/node_modules/auto-bind",
"name": "auto-bind",
"path": "{CWD}/test/fixtures/tap-and-flow/node_modules/tap/node_modules/auto-bind",
@@ -153380,6 +153612,12 @@ ArboristNode {
},
},
"edgesOut": Map {
+ "@types/react" => EdgeOut {
+ "name": "@types/react",
+ "spec": ">=16.8.0",
+ "to": "node_modules/tap/node_modules/@types/react",
+ "type": "peer",
+ },
"ansi-escapes" => EdgeOut {
"name": "ansi-escapes",
"spec": "^4.2.1",
@@ -153440,6 +153678,12 @@ ArboristNode {
"to": "node_modules/tap/node_modules/prop-types",
"type": "prod",
},
+ "react" => EdgeOut {
+ "name": "react",
+ "spec": ">=16.8.0",
+ "to": "node_modules/react",
+ "type": "peer",
+ },
"react-reconciler" => EdgeOut {
"name": "react-reconciler",
"spec": "^0.24.0",
@@ -154260,6 +154504,12 @@ ArboristNode {
"to": "node_modules/tap/node_modules/prop-types",
"type": "prod",
},
+ "react" => EdgeOut {
+ "name": "react",
+ "spec": "^16.0.0",
+ "to": "node_modules/react",
+ "type": "peer",
+ },
"scheduler" => EdgeOut {
"name": "scheduler",
"spec": "^0.18.0",
@@ -154998,6 +155248,12 @@ ArboristNode {
"to": "node_modules/tap/node_modules/ms",
"type": "prod",
},
+ "react" => EdgeOut {
+ "name": "react",
+ "spec": "^16.8.6",
+ "to": "node_modules/react",
+ "type": "peer",
+ },
"string-length" => EdgeOut {
"name": "string-length",
"spec": "^3.1.0",
@@ -155878,6 +156134,12 @@ ArboristNode {
"to": "node_modules/source-map-support",
"type": "prod",
},
+ "typescript" => EdgeOut {
+ "name": "typescript",
+ "spec": ">=2.0",
+ "to": "node_modules/typescript",
+ "type": "peer",
+ },
"yn" => EdgeOut {
"name": "yn",
"spec": "^3.0.0",
@@ -155981,6 +156243,12 @@ ArboristNode {
"spec": "^3.7.2",
"type": "prod",
},
+ EdgeIn {
+ "from": "node_modules/ts-node",
+ "name": "typescript",
+ "spec": ">=2.0",
+ "type": "peer",
+ },
},
"location": "node_modules/typescript",
"name": "typescript",
diff --git a/test/arborist/build-ideal-tree.js b/test/arborist/build-ideal-tree.js
index 6b5cf4a9..8a3cbcc4 100644
--- a/test/arborist/build-ideal-tree.js
+++ b/test/arborist/build-ideal-tree.js
@@ -1153,7 +1153,17 @@ t.test('no fix available', async t => {
await arb.audit()
t.matchSnapshot(printTree(await arb.buildIdealTree()))
t.equal(arb.idealTree.children.get('mkdirp').package.version, '0.5.1')
- t.match(checkLogs(), [['warn', 'audit', 'No fix available for mkdirp@*']])
+ t.match(checkLogs(), [
+ [
+ 'warn',
+ 'old lockfile',
+ '\nThe package-lock.json file was created with an old version of npm,\n' +
+ 'so supplemental metadata must be fetched from the registry.\n' +
+ '\n' +
+ 'This is a one-time fix-up, please be patient...\n',
+ ],
+ ['warn', 'audit', 'No fix available for mkdirp@*'],
+ ])
})
t.test('no fix available, linked top package', async t => {
@@ -1169,10 +1179,19 @@ t.test('no fix available, linked top package', async t => {
await arb.audit()
t.matchSnapshot(printTree(await arb.buildIdealTree()))
- t.strictSame(checkLogs(), [['warn', 'audit',
- 'Manual fix required in linked project at ./mkdirp-unfixable for mkdirp@*.\n' +
+ t.strictSame(checkLogs(), [
+ [
+ 'warn',
+ 'old lockfile',
+ '\nThe package-lock.json file was created with an old version of npm,\n' +
+ 'so supplemental metadata must be fetched from the registry.\n' +
+ '\n' +
+ 'This is a one-time fix-up, please be patient...\n',
+ ],
+ ['warn', 'audit',
+ 'Manual fix required in linked project at ./mkdirp-unfixable for mkdirp@*.\n' +
"'cd ./mkdirp-unfixable' and run 'npm audit' for details.",
- ]])
+ ]])
})
t.test('workspaces', t => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment