diff --git a/lib/calc-dep-flags.js b/lib/calc-dep-flags.js index 73f1e60d7..d6ae266db 100644 --- a/lib/calc-dep-flags.js +++ b/lib/calc-dep-flags.js @@ -11,7 +11,7 @@ const calcDepFlags = (tree, resetRoot = true) => { tree, visit: node => calcDepFlagsStep(node), filter: node => node, - getChildren: node => [...node.edgesOut.values()].map(edge => edge.to), + getChildren: (node, tree) => [...tree.edgesOut.values()].map(edge => edge.to), }) return ret } 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 d05cfc148..4437e4302 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 @@ -5,6 +5,99 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' +exports[`test/arborist/build-ideal-tree.js TAP a direct link dep has a dep with optional dependencies > should not mark children of the optional dep as extraneous 1`] = ` +ArboristNode { + "children": Map { + "a" => ArboristLink { + "edgesIn": Set { + EdgeIn { + "from": "", + "name": "a", + "spec": "./a", + "type": "prod", + }, + }, + "location": "node_modules/a", + "name": "a", + "path": "{CWD}/test/fixtures/link-dep-has-dep-with-optional-dep/node_modules/a", + "realpath": "{CWD}/test/fixtures/link-dep-has-dep-with-optional-dep/a", + "resolved": "file:../a", + "target": Object { + "location": "a", + }, + "version": "1.0.0", + }, + "graceful-fs" => ArboristNode { + "edgesIn": Set { + EdgeIn { + "from": "node_modules/rimraf", + "name": "graceful-fs", + "spec": "~2", + "type": "optional", + }, + }, + "location": "node_modules/graceful-fs", + "name": "graceful-fs", + "optional": true, + "path": "{CWD}/test/fixtures/link-dep-has-dep-with-optional-dep/node_modules/graceful-fs", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz", + "version": "2.0.3", + }, + "rimraf" => ArboristNode { + "edgesIn": Set { + EdgeIn { + "from": "a", + "name": "rimraf", + "spec": "2.2.4", + "type": "prod", + }, + }, + "edgesOut": Map { + "graceful-fs" => EdgeOut { + "name": "graceful-fs", + "spec": "~2", + "to": "node_modules/graceful-fs", + "type": "optional", + }, + }, + "location": "node_modules/rimraf", + "name": "rimraf", + "path": "{CWD}/test/fixtures/link-dep-has-dep-with-optional-dep/node_modules/rimraf", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.4.tgz", + "version": "2.2.4", + }, + }, + "edgesOut": Map { + "a" => EdgeOut { + "name": "a", + "spec": "./a", + "to": "node_modules/a", + "type": "prod", + }, + }, + "fsChildren": Set { + ArboristNode { + "edgesOut": Map { + "rimraf" => EdgeOut { + "name": "rimraf", + "spec": "2.2.4", + "to": "node_modules/rimraf", + "type": "prod", + }, + }, + "location": "a", + "name": "a", + "path": "{CWD}/test/fixtures/link-dep-has-dep-with-optional-dep/a", + "version": "1.0.0", + }, + }, + "location": "", + "name": "link-dep-has-dep-with-optional-dep", + "path": "{CWD}/test/fixtures/link-dep-has-dep-with-optional-dep", + "version": "1.0.0", +} +` + exports[`test/arborist/build-ideal-tree.js TAP a tree with an outdated dep, missing dep, no lockfile > should not update all 1`] = ` ArboristNode { "children": Map { diff --git a/tap-snapshots/test-arborist-load-actual.js-TAP.test.js b/tap-snapshots/test-arborist-load-actual.js-TAP.test.js index 45454a3b3..443fdea95 100644 --- a/tap-snapshots/test-arborist-load-actual.js-TAP.test.js +++ b/tap-snapshots/test-arborist-load-actual.js-TAP.test.js @@ -863,7 +863,6 @@ ArboristLink { "location": "node_modules/@scope/y", "name": "@scope/y", "path": "root/node_modules/@scope/y", - "peer": true, "version": "1.2.3", }, "foo" => ArboristNode { @@ -2646,7 +2645,6 @@ ArboristLink { "location": "node_modules/@scope/y", "name": "@scope/y", "path": "root/node_modules/@scope/y", - "peer": true, "version": "1.2.3", }, "foo" => ArboristNode { diff --git a/tap-snapshots/test-shrinkwrap.js-TAP.test.js b/tap-snapshots/test-shrinkwrap.js-TAP.test.js index f825b72f8..64157a41a 100644 --- a/tap-snapshots/test-shrinkwrap.js-TAP.test.js +++ b/tap-snapshots/test-shrinkwrap.js-TAP.test.js @@ -1445,7 +1445,6 @@ Object { "version": "1.2.3", }, "@scope/y": Object { - "peer": true, "requires": Object { "foo": "99.x", }, @@ -1533,7 +1532,6 @@ Object { "dependencies": Object { "foo": "99.x", }, - "peer": true, "version": "1.2.3", }, "../../root/node_modules/foo": Object { @@ -2523,7 +2521,6 @@ Object { "version": "1.2.3", }, "@scope/y": Object { - "peer": true, "requires": Object { "foo": "99.x", }, @@ -2611,7 +2608,6 @@ Object { "dependencies": Object { "foo": "99.x", }, - "peer": true, "version": "1.2.3", }, "../root/node_modules/foo": Object { diff --git a/test/arborist/build-ideal-tree.js b/test/arborist/build-ideal-tree.js index 56a673c26..5dded72f4 100644 --- a/test/arborist/build-ideal-tree.js +++ b/test/arborist/build-ideal-tree.js @@ -174,6 +174,11 @@ t.test('bad shrinkwrap file', t => { return t.resolveMatchSnapshot(printIdeal(path), 'bad shrinkwrap') }) +t.test('a direct link dep has a dep with optional dependencies', t => { + const path = resolve(fixtures, 'link-dep-has-dep-with-optional-dep') + return t.resolveMatchSnapshot(printIdeal(path), 'should not mark children of the optional dep as extraneous') +}) + t.test('cyclical peer deps', t => { const paths = [ resolve(fixtures, 'peer-dep-cycle'), diff --git a/test/fixtures/link-dep-has-dep-with-optional-dep/a/package.json b/test/fixtures/link-dep-has-dep-with-optional-dep/a/package.json new file mode 100644 index 000000000..83bce000e --- /dev/null +++ b/test/fixtures/link-dep-has-dep-with-optional-dep/a/package.json @@ -0,0 +1,7 @@ +{ + "name": "a", + "version": "1.0.0", + "dependencies": { + "rimraf": "2.2.4" + } +} diff --git a/test/fixtures/link-dep-has-dep-with-optional-dep/package.json b/test/fixtures/link-dep-has-dep-with-optional-dep/package.json new file mode 100644 index 000000000..3bc4c7175 --- /dev/null +++ b/test/fixtures/link-dep-has-dep-with-optional-dep/package.json @@ -0,0 +1,7 @@ +{ + "name": "link-dep-has-dep-with-optional-dep", + "version": "1.0.0", + "dependencies": { + "a": "./a" + } +}