Skip to content

Commit

Permalink
fix: read-package-json-fast update
Browse files Browse the repository at this point in the history
dependencies are now pruned if they appear in optionalDependencies, this
updates a bunch of snapshot files that were expecting that info.
  • Loading branch information
ruyadorno committed Feb 5, 2021
1 parent 9d4c87b commit dc52834
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 38 deletions.
1 change: 1 addition & 0 deletions lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
if (this[_global] && (this[_updateAll] || this[_updateNames].length)) {
const nm = resolve(this.path, 'node_modules')
for (const name of await readdir(nm)) {
tree.package.dependencies = tree.package.dependencies || {}
if (this[_updateAll] || this[_updateNames].includes(name))
tree.package.dependencies[name] = '*'
}
Expand Down
33 changes: 33 additions & 0 deletions tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128749,6 +128749,39 @@ ArboristNode {
}
`

exports[`test/arborist/build-ideal-tree.js TAP update global space single dep > should update global dependencies 1`] = `
ArboristNode {
"children": Map {
"abbrev" => ArboristNode {
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "abbrev",
"spec": "*",
"type": "prod",
},
},
"location": "node_modules/abbrev",
"name": "abbrev",
"path": "{CWD}/test/arborist/build-ideal-tree-update-global-space-single-dep/global-prefix/lib/node_modules/abbrev",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"version": "1.1.1",
},
},
"edgesOut": Map {
"abbrev" => EdgeOut {
"name": "abbrev",
"spec": "*",
"to": "node_modules/abbrev",
"type": "prod",
},
},
"location": "",
"name": "lib",
"path": "{CWD}/test/arborist/build-ideal-tree-update-global-space-single-dep/global-prefix/lib",
}
`

exports[`test/arborist/build-ideal-tree.js TAP update mkdirp to non-minimist-using version > must match snapshot 1`] = `
ArboristNode {
"children": Map {
Expand Down
1 change: 0 additions & 1 deletion tap-snapshots/test-arborist-rebuild.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Array [
"_id": "devdep@1.0.0",
"dependencies": Object {
"devopt": "",
"opt-and-dev": "",
},
"name": "devdep",
"optionalDependencies": Object {
Expand Down
37 changes: 0 additions & 37 deletions tap-snapshots/test-shrinkwrap.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ Object {
"a": "",
"link": "",
"link2": "",
"optin": "",
},
"devDependencies": Object {
"d": "",
Expand Down Expand Up @@ -641,7 +640,6 @@ Object {
"a": "",
"link": "",
"link2": "",
"optin": "",
},
"devDependencies": Object {
"d": "",
Expand All @@ -664,7 +662,6 @@ Object {
"a": "",
"link": "",
"link2": "",
"optin": "",
},
"devDependencies": Object {
"d": "",
Expand Down Expand Up @@ -1177,7 +1174,6 @@ Object {
"packages": Object {
"": Object {
"dependencies": Object {
"inflight": "^1.0.6",
"once": "^1.4.0",
},
"license": "ISC",
Expand Down Expand Up @@ -1391,9 +1387,6 @@ Object {
},
},
"node_modules/z": Object {
"dependencies": Object {
"a": "",
},
"optionalDependencies": Object {
"a": "",
},
Expand Down Expand Up @@ -1479,7 +1472,6 @@ Object {
"": Object {
"dependencies": Object {
"@scope/x": "1",
"notinstalledhere": "",
},
"devDependencies": Object {
"foo": "*",
Expand All @@ -1494,7 +1486,6 @@ Object {
},
"../../root/node_modules/@scope/x": Object {
"dependencies": Object {
"@scope/y": "",
"glob": "4",
},
"optionalDependencies": Object {
Expand Down Expand Up @@ -1547,7 +1538,6 @@ Object {
},
"../../root/node_modules/foo": Object {
"dependencies": Object {
"@scope/x": "",
"express": "npm:abbrev@*",
},
"optionalDependencies": Object {
Expand Down Expand Up @@ -2226,9 +2216,6 @@ Object {
"bin": Object {
"rimraf": "bin.js",
},
"dependencies": Object {
"glob": "^7.1.3",
},
"extraneous": true,
"integrity": "sha512-hKCr1HweNbIu6JN4K8WYBwikeg2ISRHU2D7OTX0fivTb+2dOM7mITni0cAjgWCsNGUQDFI+4BTNeGBVp/WbBow==",
"license": "ISC",
Expand Down Expand Up @@ -2563,7 +2550,6 @@ Object {
"": Object {
"dependencies": Object {
"@scope/x": "1",
"notinstalledhere": "",
},
"devDependencies": Object {
"foo": "*",
Expand All @@ -2578,7 +2564,6 @@ Object {
},
"../root/node_modules/@scope/x": Object {
"dependencies": Object {
"@scope/y": "",
"glob": "4",
},
"optionalDependencies": Object {
Expand Down Expand Up @@ -2631,7 +2616,6 @@ Object {
},
"../root/node_modules/foo": Object {
"dependencies": Object {
"@scope/x": "",
"express": "npm:abbrev@*",
},
"optionalDependencies": Object {
Expand Down Expand Up @@ -2866,9 +2850,6 @@ Object {
"name": "root",
"packages": Object {
"": Object {
"dependencies": Object {
"a": "",
},
"devDependencies": Object {
"c": "",
},
Expand Down Expand Up @@ -2988,14 +2969,7 @@ Object {
"packages": Object {
"": Object {
"dependencies": Object {
"a": "",
"b": "",
"c": "",
"k": "",
"l": "",
"m": "",
"x": "",
"y": "",
},
"devDependencies": Object {
"i": "",
Expand Down Expand Up @@ -3131,7 +3105,6 @@ Object {
"packages": Object {
"": Object {
"dependencies": Object {
"a": "",
"c": "",
},
"optionalDependencies": Object {
Expand Down Expand Up @@ -3210,7 +3183,6 @@ Object {
},
"node_modules/a": Object {
"dependencies": Object {
"b": "",
"d": "",
},
"dev": true,
Expand Down Expand Up @@ -3522,7 +3494,6 @@ Object {
"": Object {
"dependencies": Object {
"@scope/x": "1",
"notinstalledhere": "",
},
"devDependencies": Object {
"foo": "*",
Expand All @@ -3537,7 +3508,6 @@ Object {
},
"node_modules/@scope/x": Object {
"dependencies": Object {
"@scope/y": "",
"glob": "4",
},
"optionalDependencies": Object {
Expand Down Expand Up @@ -3589,7 +3559,6 @@ Object {
},
"node_modules/foo": Object {
"dependencies": Object {
"@scope/x": "",
"express": "npm:abbrev@*",
},
"optionalDependencies": Object {
Expand Down Expand Up @@ -7744,7 +7713,6 @@ Object {
"dependencies": Object {
"anymatch": "~3.1.1",
"braces": "~3.0.2",
"fsevents": "~2.1.1",
"glob-parent": "~5.1.0",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
Expand Down Expand Up @@ -8535,7 +8503,6 @@ Object {
"neo-async": "^2.6.0",
"optimist": "^0.6.1",
"source-map": "^0.6.1",
"uglify-js": "^3.1.4",
},
"engines": Object {
"node": ">=0.4.7",
Expand Down Expand Up @@ -10452,7 +10419,6 @@ Object {
"diff": "^1.3.2",
"escape-string-regexp": "^1.0.3",
"glob": "^7.0.5",
"readable-stream": "^2.1.5",
"tap-parser": "^10.0.0",
"tap-yaml": "^1.0.0",
"unicode-length": "^1.0.0",
Expand Down Expand Up @@ -11587,7 +11553,6 @@ exports[`test/shrinkwrap.js TAP loadActual tests tap-with-yarn-lock > yarn.lock
dependencies:
"anymatch" "~3.1.1"
"braces" "~3.0.2"
"fsevents" "~2.1.1"
"glob-parent" "~5.1.0"
"is-binary-path" "~2.1.0"
"is-glob" "~4.0.1"
Expand Down Expand Up @@ -12049,7 +12014,6 @@ exports[`test/shrinkwrap.js TAP loadActual tests tap-with-yarn-lock > yarn.lock
"neo-async" "^2.6.0"
"optimist" "^0.6.1"
"source-map" "^0.6.1"
"uglify-js" "^3.1.4"
optionalDependencies:
"uglify-js" "^3.1.4"
Expand Down Expand Up @@ -13356,7 +13320,6 @@ exports[`test/shrinkwrap.js TAP loadActual tests tap-with-yarn-lock > yarn.lock
"diff" "^1.3.2"
"escape-string-regexp" "^1.0.3"
"glob" "^7.0.5"
"readable-stream" "^2.1.5"
"tap-parser" "^10.0.0"
"tap-yaml" "^1.0.0"
"unicode-length" "^1.0.0"
Expand Down
31 changes: 31 additions & 0 deletions test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,37 @@ t.test('add symlink that points to a symlink', t => {
)
})

t.test('update global space single dep', t => {
const fixt = t.testdir({
'global-prefix': {
lib: {
node_modules: {
abbrev: {
'package.json': JSON.stringify({
name: 'abbrev',
version: '1.0.0',
}),
},
},
},
},
})
const path = resolve(fixt, 'global-prefix/lib')
const opts = {
path,
global: true,
update: true,
...OPT,
}
const arb = new Arborist(opts)
return arb.buildIdealTree(opts).then(tree =>
t.matchSnapshot(
printTree(tree),
'should update global dependencies'
)
)
})

// if we get this wrong, it'll spin forever and use up all the memory
t.test('pathologically nested dependency cycle', t =>
t.resolveMatchSnapshot(printIdeal(
Expand Down

0 comments on commit dc52834

Please sign in to comment.