From dc52834af0f38d3822918571f20d149218a60c66 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Fri, 5 Feb 2021 12:03:44 -0500 Subject: [PATCH] fix: read-package-json-fast update dependencies are now pruned if they appear in optionalDependencies, this updates a bunch of snapshot files that were expecting that info. --- lib/arborist/build-ideal-tree.js | 1 + ...t-arborist-build-ideal-tree.js-TAP.test.js | 33 +++++++++++++++++ .../test-arborist-rebuild.js-TAP.test.js | 1 - tap-snapshots/test-shrinkwrap.js-TAP.test.js | 37 ------------------- test/arborist/build-ideal-tree.js | 31 ++++++++++++++++ 5 files changed, 65 insertions(+), 38 deletions(-) diff --git a/lib/arborist/build-ideal-tree.js b/lib/arborist/build-ideal-tree.js index ae92b74ce..4c2665021 100644 --- a/lib/arborist/build-ideal-tree.js +++ b/lib/arborist/build-ideal-tree.js @@ -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] = '*' } diff --git a/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js b/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js index 4e3a7671a..8c46e23fb 100644 --- a/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js +++ b/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js @@ -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 { diff --git a/tap-snapshots/test-arborist-rebuild.js-TAP.test.js b/tap-snapshots/test-arborist-rebuild.js-TAP.test.js index ee6659169..03b775126 100644 --- a/tap-snapshots/test-arborist-rebuild.js-TAP.test.js +++ b/tap-snapshots/test-arborist-rebuild.js-TAP.test.js @@ -15,7 +15,6 @@ Array [ "_id": "devdep@1.0.0", "dependencies": Object { "devopt": "", - "opt-and-dev": "", }, "name": "devdep", "optionalDependencies": Object { diff --git a/tap-snapshots/test-shrinkwrap.js-TAP.test.js b/tap-snapshots/test-shrinkwrap.js-TAP.test.js index 300a18616..f825b72f8 100644 --- a/tap-snapshots/test-shrinkwrap.js-TAP.test.js +++ b/tap-snapshots/test-shrinkwrap.js-TAP.test.js @@ -372,7 +372,6 @@ Object { "a": "", "link": "", "link2": "", - "optin": "", }, "devDependencies": Object { "d": "", @@ -641,7 +640,6 @@ Object { "a": "", "link": "", "link2": "", - "optin": "", }, "devDependencies": Object { "d": "", @@ -664,7 +662,6 @@ Object { "a": "", "link": "", "link2": "", - "optin": "", }, "devDependencies": Object { "d": "", @@ -1177,7 +1174,6 @@ Object { "packages": Object { "": Object { "dependencies": Object { - "inflight": "^1.0.6", "once": "^1.4.0", }, "license": "ISC", @@ -1391,9 +1387,6 @@ Object { }, }, "node_modules/z": Object { - "dependencies": Object { - "a": "", - }, "optionalDependencies": Object { "a": "", }, @@ -1479,7 +1472,6 @@ Object { "": Object { "dependencies": Object { "@scope/x": "1", - "notinstalledhere": "", }, "devDependencies": Object { "foo": "*", @@ -1494,7 +1486,6 @@ Object { }, "../../root/node_modules/@scope/x": Object { "dependencies": Object { - "@scope/y": "", "glob": "4", }, "optionalDependencies": Object { @@ -1547,7 +1538,6 @@ Object { }, "../../root/node_modules/foo": Object { "dependencies": Object { - "@scope/x": "", "express": "npm:abbrev@*", }, "optionalDependencies": Object { @@ -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", @@ -2563,7 +2550,6 @@ Object { "": Object { "dependencies": Object { "@scope/x": "1", - "notinstalledhere": "", }, "devDependencies": Object { "foo": "*", @@ -2578,7 +2564,6 @@ Object { }, "../root/node_modules/@scope/x": Object { "dependencies": Object { - "@scope/y": "", "glob": "4", }, "optionalDependencies": Object { @@ -2631,7 +2616,6 @@ Object { }, "../root/node_modules/foo": Object { "dependencies": Object { - "@scope/x": "", "express": "npm:abbrev@*", }, "optionalDependencies": Object { @@ -2866,9 +2850,6 @@ Object { "name": "root", "packages": Object { "": Object { - "dependencies": Object { - "a": "", - }, "devDependencies": Object { "c": "", }, @@ -2988,14 +2969,7 @@ Object { "packages": Object { "": Object { "dependencies": Object { - "a": "", - "b": "", - "c": "", - "k": "", - "l": "", - "m": "", "x": "", - "y": "", }, "devDependencies": Object { "i": "", @@ -3131,7 +3105,6 @@ Object { "packages": Object { "": Object { "dependencies": Object { - "a": "", "c": "", }, "optionalDependencies": Object { @@ -3210,7 +3183,6 @@ Object { }, "node_modules/a": Object { "dependencies": Object { - "b": "", "d": "", }, "dev": true, @@ -3522,7 +3494,6 @@ Object { "": Object { "dependencies": Object { "@scope/x": "1", - "notinstalledhere": "", }, "devDependencies": Object { "foo": "*", @@ -3537,7 +3508,6 @@ Object { }, "node_modules/@scope/x": Object { "dependencies": Object { - "@scope/y": "", "glob": "4", }, "optionalDependencies": Object { @@ -3589,7 +3559,6 @@ Object { }, "node_modules/foo": Object { "dependencies": Object { - "@scope/x": "", "express": "npm:abbrev@*", }, "optionalDependencies": Object { @@ -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", @@ -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", @@ -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", @@ -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" @@ -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" @@ -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" diff --git a/test/arborist/build-ideal-tree.js b/test/arborist/build-ideal-tree.js index 26c38bfab..1835f1902 100644 --- a/test/arborist/build-ideal-tree.js +++ b/test/arborist/build-ideal-tree.js @@ -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(