From b821eb0b5c4679cd359ea069d8e5fc5dc34ea741 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Tue, 18 Feb 2025 14:10:34 -0500 Subject: [PATCH 1/3] chore(arborist): run tests to update snapshots --- .../test/arborist/load-actual.js.test.cjs | 231 ----------- .../test/audit-report.js.test.cjs | 369 ------------------ .../tap-snapshots/test/shrinkwrap.js.test.cjs | 75 ---- 3 files changed, 675 deletions(-) diff --git a/workspaces/arborist/tap-snapshots/test/arborist/load-actual.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/load-actual.js.test.cjs index 35ba9f7cafa84..352836b44f5b8 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/load-actual.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/load-actual.js.test.cjs @@ -6161,237 +6161,6 @@ ArboristNode { } ` -exports[`test/arborist/load-actual.js TAP selflink > loaded tree 1`] = ` -ArboristNode { - "children": Map { - "@scope/y" => ArboristNode { - "edgesIn": Set { - EdgeIn { - "from": "", - "name": "@scope/y", - "spec": "*", - "type": "prod", - }, - }, - "edgesOut": Map { - "foo" => EdgeOut { - "name": "foo", - "spec": "*", - "to": "node_modules/foo", - "type": "prod", - }, - }, - "location": "node_modules/@scope/y", - "name": "@scope/y", - "path": "selflink/node_modules/@scope/y", - "version": "1.2.3", - }, - "@scope/z" => ArboristNode { - "children": Map { - "glob" => ArboristLink { - "dev": true, - "edgesIn": Set { - EdgeIn { - "from": "node_modules/@scope/z", - "name": "glob", - "spec": "4", - "type": "prod", - }, - }, - "extraneous": true, - "location": "node_modules/@scope/z/node_modules/glob", - "name": "glob", - "optional": true, - "path": "selflink/node_modules/@scope/z/node_modules/glob", - "peer": true, - "realpath": "selflink/node_modules/foo/node_modules/glob", - "resolved": "file:../../../foo/node_modules/glob", - "target": ArboristNode { - "children": Map { - "graceful-fs" => ArboristNode { - "dev": true, - "extraneous": true, - "location": "node_modules/foo/node_modules/glob/node_modules/graceful-fs", - "name": "graceful-fs", - "optional": true, - "path": "selflink/node_modules/foo/node_modules/glob/node_modules/graceful-fs", - "peer": true, - "version": "3.0.2", - }, - "inherits" => ArboristNode { - "dev": true, - "extraneous": true, - "location": "node_modules/foo/node_modules/glob/node_modules/inherits", - "name": "inherits", - "optional": true, - "path": "selflink/node_modules/foo/node_modules/glob/node_modules/inherits", - "peer": true, - "version": "2.0.1", - }, - "minimatch" => ArboristNode { - "children": Map { - "lru-cache" => ArboristNode { - "dev": true, - "extraneous": true, - "location": "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/lru-cache", - "name": "lru-cache", - "optional": true, - "path": "selflink/node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/lru-cache", - "peer": true, - "version": "2.5.0", - }, - "sigmund" => ArboristNode { - "dev": true, - "extraneous": true, - "location": "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/sigmund", - "name": "sigmund", - "optional": true, - "path": "selflink/node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/sigmund", - "peer": true, - "version": "1.0.0", - }, - }, - "dev": true, - "extraneous": true, - "location": "node_modules/foo/node_modules/glob/node_modules/minimatch", - "name": "minimatch", - "optional": true, - "path": "selflink/node_modules/foo/node_modules/glob/node_modules/minimatch", - "peer": true, - "version": "1.0.0", - }, - "once" => ArboristNode { - "dev": true, - "extraneous": true, - "location": "node_modules/foo/node_modules/glob/node_modules/once", - "name": "once", - "optional": true, - "path": "selflink/node_modules/foo/node_modules/glob/node_modules/once", - "peer": true, - "version": "1.3.0", - }, - }, - "edgesIn": Set { - EdgeIn { - "from": "node_modules/foo", - "name": "glob", - "spec": "4", - "type": "prod", - }, - }, - "location": "node_modules/foo/node_modules/glob", - "name": "glob", - "path": "selflink/node_modules/foo/node_modules/glob", - "version": "4.0.5", - }, - "version": "4.0.5", - }, - }, - "dev": true, - "edgesOut": Map { - "glob" => EdgeOut { - "name": "glob", - "spec": "4", - "to": "node_modules/@scope/z/node_modules/glob", - "type": "prod", - }, - }, - "extraneous": true, - "location": "node_modules/@scope/z", - "name": "@scope/z", - "optional": true, - "path": "selflink/node_modules/@scope/z", - "peer": true, - "version": "1.2.3", - }, - "foo" => ArboristNode { - "children": Map { - "glob" => ArboristNode { - "location": "node_modules/foo/node_modules/glob", - }, - "selflink" => ArboristLink { - "edgesIn": Set { - EdgeIn { - "from": "node_modules/foo", - "name": "selflink", - "spec": "*", - "type": "prod", - }, - }, - "location": "node_modules/foo/node_modules/selflink", - "name": "selflink", - "path": "selflink/node_modules/foo/node_modules/selflink", - "realpath": "selflink", - "resolved": "file:../../..", - "target": ArboristNode { - "location": "", - }, - "version": "1.2.3", - }, - }, - "edgesIn": Set { - EdgeIn { - "from": "", - "name": "foo", - "spec": "*", - "type": "prod", - }, - EdgeIn { - "from": "node_modules/@scope/y", - "name": "foo", - "spec": "*", - "type": "prod", - }, - }, - "edgesOut": Map { - "glob" => EdgeOut { - "name": "glob", - "spec": "4", - "to": "node_modules/foo/node_modules/glob", - "type": "prod", - }, - "selflink" => EdgeOut { - "name": "selflink", - "spec": "*", - "to": "node_modules/foo/node_modules/selflink", - "type": "prod", - }, - }, - "location": "node_modules/foo", - "name": "foo", - "path": "selflink/node_modules/foo", - "version": "1.2.3", - }, - }, - "edgesOut": Map { - "@scope/x" => EdgeOut { - "error": "MISSING", - "name": "@scope/x", - "spec": "*", - "to": null, - "type": "prod", - }, - "@scope/y" => EdgeOut { - "name": "@scope/y", - "spec": "*", - "to": "node_modules/@scope/y", - "type": "prod", - }, - "foo" => EdgeOut { - "name": "foo", - "spec": "*", - "to": "node_modules/foo", - "type": "prod", - }, - }, - "isProjectRoot": true, - "location": "", - "name": "selflink", - "path": "selflink", - "version": "1.2.3", -} -` - exports[`test/arborist/load-actual.js TAP shake out Link target timing issue > loaded tree 1`] = ` ArboristNode { "children": Map { diff --git a/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs b/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs index cc1354e64c818..2d2374afff4af 100644 --- a/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs @@ -1269,375 +1269,6 @@ exports[`test/audit-report.js TAP audit outdated nyc and mkdirp with before: opt } ` -exports[`test/audit-report.js TAP audit outdated nyc and mkdirp with newer endpoint > json version 1`] = ` -{ - "auditReportVersion": 2, - "vulnerabilities": { - "handlebars": { - "name": "handlebars", - "severity": "critical", - "isDirect": false, - "via": [ - { - "source": 1164, - "name": "handlebars", - "dependency": "handlebars", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1164", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.3.0" - }, - { - "source": 1300, - "name": "handlebars", - "dependency": "handlebars", - "title": "Denial of Service", - "url": "https://npmjs.com/advisories/1300", - "severity": "moderate", - "range": ">=4.0.0 <4.4.5" - }, - { - "source": 1316, - "name": "handlebars", - "dependency": "handlebars", - "title": "Arbitrary Code Execution", - "url": "https://npmjs.com/advisories/1316", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.5.2" - }, - { - "source": 1324, - "name": "handlebars", - "dependency": "handlebars", - "title": "Arbitrary Code Execution", - "url": "https://npmjs.com/advisories/1324", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.5.3" - }, - { - "source": 1325, - "name": "handlebars", - "dependency": "handlebars", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1325", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.5.3" - }, - { - "source": 755, - "name": "handlebars", - "dependency": "handlebars", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/755", - "severity": "critical", - "range": "<=4.0.13 || >=4.1.0 <4.1.2" - }, - "optimist" - ], - "effects": [], - "range": "<=4.7.3", - "nodes": [ - "node_modules/nyc/node_modules/handlebars" - ], - "fixAvailable": true - }, - "kind-of": { - "name": "kind-of", - "severity": "low", - "isDirect": false, - "via": [ - { - "source": 1490, - "name": "kind-of", - "dependency": "kind-of", - "title": "Validation Bypass", - "url": "https://npmjs.com/advisories/1490", - "severity": "low", - "range": ">=6.0.0 <6.0.3" - } - ], - "effects": [], - "range": "6.0.0 - 6.0.2", - "nodes": [ - "node_modules/nyc/node_modules/base/node_modules/kind-of", - "node_modules/nyc/node_modules/define-property/node_modules/kind-of", - "node_modules/nyc/node_modules/extglob/node_modules/kind-of", - "node_modules/nyc/node_modules/micromatch/node_modules/kind-of", - "node_modules/nyc/node_modules/nanomatch/node_modules/kind-of", - "node_modules/nyc/node_modules/snapdragon-node/node_modules/kind-of", - "node_modules/nyc/node_modules/test-exclude/node_modules/kind-of", - "node_modules/nyc/node_modules/use/node_modules/kind-of" - ], - "fixAvailable": true - }, - "lodash": { - "name": "lodash", - "severity": "high", - "isDirect": false, - "via": [ - { - "source": 1065, - "name": "lodash", - "dependency": "lodash", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1065", - "severity": "high", - "range": "<4.17.12" - }, - { - "source": 782, - "name": "lodash", - "dependency": "lodash", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/782", - "severity": "high", - "range": "<4.17.11" - } - ], - "effects": [], - "range": "<=4.17.11", - "nodes": [ - "node_modules/nyc/node_modules/lodash" - ], - "fixAvailable": true - }, - "mem": { - "name": "mem", - "severity": "low", - "isDirect": false, - "via": [ - { - "source": 1084, - "name": "mem", - "dependency": "mem", - "title": "Denial of Service", - "url": "https://npmjs.com/advisories/1084", - "severity": "low", - "range": "<4.0.0" - } - ], - "effects": [ - "os-locale" - ], - "range": "<4.0.0", - "nodes": [ - "node_modules/nyc/node_modules/mem" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "minimist": { - "name": "minimist", - "severity": "low", - "isDirect": false, - "via": [ - { - "source": 1179, - "name": "minimist", - "dependency": "minimist", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1179", - "severity": "low", - "range": "<0.2.1 || >=1.0.0 <1.2.3" - } - ], - "effects": [ - "mkdirp", - "optimist" - ], - "range": "<0.2.1 || >=1.0.0 <1.2.3", - "nodes": [ - "node_modules/minimist", - "node_modules/nyc/node_modules/minimist" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "mixin-deep": { - "name": "mixin-deep", - "severity": "high", - "isDirect": false, - "via": [ - { - "source": 1013, - "name": "mixin-deep", - "dependency": "mixin-deep", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1013", - "severity": "high", - "range": "<1.3.2 || >=2.0.0 <2.0.1" - } - ], - "effects": [], - "range": "<=1.3.1 || 2.0.0", - "nodes": [ - "node_modules/nyc/node_modules/mixin-deep" - ], - "fixAvailable": true - }, - "mkdirp": { - "name": "mkdirp", - "severity": "low", - "isDirect": true, - "via": [ - "minimist" - ], - "effects": [ - "nyc" - ], - "range": "0.4.1 - 0.5.1", - "nodes": [ - "node_modules/mkdirp", - "node_modules/nyc/node_modules/mkdirp" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "nyc": { - "name": "nyc", - "severity": "low", - "isDirect": true, - "via": [ - "mkdirp", - "yargs" - ], - "effects": [], - "range": "6.2.0-alpha - 13.1.0", - "nodes": [ - "node_modules/nyc" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "optimist": { - "name": "optimist", - "severity": "low", - "isDirect": false, - "via": [ - "minimist" - ], - "effects": [ - "handlebars" - ], - "range": ">=0.6.0", - "nodes": [ - "node_modules/nyc/node_modules/optimist" - ], - "fixAvailable": true - }, - "os-locale": { - "name": "os-locale", - "severity": "low", - "isDirect": false, - "via": [ - "mem" - ], - "effects": [ - "yargs" - ], - "range": "2.0.0 - 3.0.0", - "nodes": [ - "node_modules/nyc/node_modules/os-locale" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "set-value": { - "name": "set-value", - "severity": "high", - "isDirect": false, - "via": [ - { - "source": 1012, - "name": "set-value", - "dependency": "set-value", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1012", - "severity": "high", - "range": "<2.0.1 || >=3.0.0 <3.0.1" - } - ], - "effects": [ - "union-value" - ], - "range": "<=2.0.0 || 3.0.0", - "nodes": [ - "node_modules/nyc/node_modules/set-value", - "node_modules/nyc/node_modules/union-value/node_modules/set-value" - ], - "fixAvailable": true - }, - "union-value": { - "name": "union-value", - "severity": "high", - "isDirect": false, - "via": [ - "set-value" - ], - "effects": [], - "range": "<=1.0.0 || 2.0.0", - "nodes": [ - "node_modules/nyc/node_modules/union-value" - ], - "fixAvailable": true - }, - "yargs": { - "name": "yargs", - "severity": "low", - "isDirect": false, - "via": [ - "os-locale" - ], - "effects": [ - "nyc" - ], - "range": "8.0.1 - 11.1.0 || 12.0.0-candidate.0 - 12.0.1", - "nodes": [ - "node_modules/nyc/node_modules/yargs" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - } - }, - "metadata": { - "vulnerabilities": { - "info": 0, - "low": 8, - "moderate": 0, - "high": 4, - "critical": 1, - "total": 13 - }, - "dependencies": { - "prod": 318, - "dev": 0, - "optional": 12, - "peer": 0, - "peerOptional": 0, - "total": 329 - } - } -} -` - exports[`test/audit-report.js TAP audit report with a lying v5 lockfile > must match snapshot 1`] = ` Object { "auditReportVersion": 2, diff --git a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs index 9103febb644ee..49abbc631b3aa 100644 --- a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs @@ -2644,81 +2644,6 @@ Object { } ` -exports[`test/shrinkwrap.js TAP loadActual tests selflink > shrinkwrap data 1`] = ` -Object { - "lockfileVersion": 3, - "name": "selflink", - "packages": Object { - "": Object { - "dependencies": Object { - "@scope/x": "", - "@scope/y": "", - "foo": "", - }, - "name": "selflink", - "version": "1.2.3", - }, - "node_modules/@scope/y": Object { - "dependencies": Object { - "foo": "*", - }, - "version": "1.2.3", - }, - "node_modules/@scope/z": Object { - "dependencies": Object { - "glob": "4", - }, - "extraneous": true, - "version": "1.2.3", - }, - "node_modules/@scope/z/node_modules/glob": Object { - "link": true, - "resolved": "node_modules/foo/node_modules/glob", - }, - "node_modules/foo": Object { - "dependencies": Object { - "glob": "4", - "selflink": "*", - }, - "version": "1.2.3", - }, - "node_modules/foo/node_modules/glob": Object { - "version": "4.0.5", - }, - "node_modules/foo/node_modules/glob/node_modules/graceful-fs": Object { - "extraneous": true, - "version": "3.0.2", - }, - "node_modules/foo/node_modules/glob/node_modules/inherits": Object { - "extraneous": true, - "version": "2.0.1", - }, - "node_modules/foo/node_modules/glob/node_modules/minimatch": Object { - "extraneous": true, - "version": "1.0.0", - }, - "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/lru-cache": Object { - "extraneous": true, - "version": "2.5.0", - }, - "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/sigmund": Object { - "extraneous": true, - "version": "1.0.0", - }, - "node_modules/foo/node_modules/glob/node_modules/once": Object { - "extraneous": true, - "version": "1.3.0", - }, - "node_modules/foo/node_modules/selflink": Object { - "link": true, - "resolved": "", - }, - }, - "requires": true, - "version": "1.2.3", -} -` - exports[`test/shrinkwrap.js TAP loadActual tests symlinked-node-modules/example > shrinkwrap data 1`] = ` Object { "lockfileVersion": 3, From e8bd8bc8016c6de2eec86378a838188565f5ac1b Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Tue, 18 Feb 2025 14:10:34 -0500 Subject: [PATCH 2/3] test(arborist): add load-virtual and reify tests to demonstrate #4205 The tests show that the virtual tree ignores overrides on workspace dependencies, causing the corresponding nodes to have only their spec versions after reification. --- .../test/arborist/load-virtual.js.test.cjs | 86 +++++++++++++++++++ .../test/arborist/reify.js.test.cjs | 33 +++++++ .../arborist/test/arborist/load-virtual.js | 6 ++ workspaces/arborist/test/arborist/reify.js | 7 ++ .../reify-cases/workspaces-with-overrides.js | 54 ++++++++++++ .../package-lock.json | 29 +++++++ .../workspaces-with-overrides/package.json | 9 ++ .../workspaces-with-overrides/ws/package.json | 7 ++ 8 files changed, 231 insertions(+) create mode 100644 workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js create mode 100644 workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json create mode 100644 workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json create mode 100644 workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json diff --git a/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs index c0210aabc54f3..261ecb4736b7f 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs @@ -16375,6 +16375,92 @@ ArboristNode { } ` +exports[`test/arborist/load-virtual.js TAP workspaces load installed workspace with dependency overrides > virtual tree with overrides 1`] = ` +ArboristNode { + "children": Map { + "arg" => ArboristNode { + "edgesIn": Set { + EdgeIn { + "error": "INVALID", + "from": "ws", + "name": "arg", + "spec": "4.1.2", + "type": "prod", + }, + }, + "location": "node_modules/arg", + "name": "arg", + "overrides": Map { + "arg" => "4.1.3", + }, + "path": "{CWD}/test/fixtures/workspaces-with-overrides/node_modules/arg", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "version": "4.1.3", + }, + "ws" => ArboristLink { + "edgesIn": Set { + EdgeIn { + "from": "", + "name": "ws", + "spec": "file:{CWD}/test/fixtures/workspaces-with-overrides/ws", + "type": "workspace", + }, + }, + "isWorkspace": true, + "location": "node_modules/ws", + "name": "ws", + "overrides": Map { + "arg" => "4.1.3", + }, + "path": "{CWD}/test/fixtures/workspaces-with-overrides/node_modules/ws", + "realpath": "{CWD}/test/fixtures/workspaces-with-overrides/ws", + "resolved": "file:../ws", + "target": ArboristNode { + "location": "ws", + }, + "version": "1.0.0", + }, + }, + "edgesOut": Map { + "ws" => EdgeOut { + "name": "ws", + "spec": "file:{CWD}/test/fixtures/workspaces-with-overrides/ws", + "to": "node_modules/ws", + "type": "workspace", + }, + }, + "fsChildren": Set { + ArboristNode { + "edgesOut": Map { + "arg" => EdgeOut { + "error": "INVALID", + "name": "arg", + "spec": "4.1.2", + "to": "node_modules/arg", + "type": "prod", + }, + }, + "isWorkspace": true, + "location": "ws", + "name": "ws", + "path": "{CWD}/test/fixtures/workspaces-with-overrides/ws", + "version": "1.0.0", + }, + }, + "isProjectRoot": true, + "location": "", + "name": "workspaces-with-overrides", + "overrides": Map { + "arg" => "4.1.3", + }, + "packageName": "workspace-with-overrides", + "path": "{CWD}/test/fixtures/workspaces-with-overrides", + "workspaces": Map { + "ws" => "ws", + }, +} +` + exports[`test/arborist/load-virtual.js TAP workspaces load installed workspace with transitive dependencies > virtual tree with transitive deps 1`] = ` ArboristNode { "children": Map { diff --git a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs index cec3560033241..8138d2d5f2ac6 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs @@ -53497,6 +53497,39 @@ Object { } ` +exports[`test/arborist/reify.js TAP workspaces reify workspaces with overrides > should retain override version (4.1.3) 1`] = ` +Object { + "lockfileVersion": 3, + "name": "workspace-with-overrides", + "packages": Object { + "": Object { + "name": "workspace-with-overrides", + "workspaces": Array [ + "ws", + ], + }, + "node_modules/a": Object { + "link": true, + "resolved": "ws", + }, + "ws": Object { + "dependencies": Object { + "arg": "4.1.2", + }, + "name": "a", + "version": "1.0.0", + }, + "ws/node_modules/arg": Object { + "integrity": "sha512-+ytCkGcBtHZ3V2r2Z06AncYO8jz46UEamcspGoU8lHcEbpn6J77QK0vdWvChsclg/tM5XIJC5tnjmPp7Eq6Obg==", + "license": "MIT", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.2.tgz", + "version": "4.1.2", + }, + }, + "requires": true, +} +` + exports[`test/arborist/reify.js TAP workspaces root as-a-workspace > should produce expected package-lock file 1`] = ` Object { "lockfileVersion": 3, diff --git a/workspaces/arborist/test/arborist/load-virtual.js b/workspaces/arborist/test/arborist/load-virtual.js index 3b50444c851ae..4540d969d71a9 100644 --- a/workspaces/arborist/test/arborist/load-virtual.js +++ b/workspaces/arborist/test/arborist/load-virtual.js @@ -204,6 +204,12 @@ t.test('workspaces', t => { ).then(tree => t.matchSnapshot(printTree(tree), 'virtual tree ignoring nested node_modules'))) + t.test('load installed workspace with dependency overrides', t => + loadVirtual( + resolve(__dirname, '../fixtures/workspaces-with-overrides') + ).then(tree => + t.matchSnapshot(printTree(tree), 'virtual tree with overrides'))) + t.end() }) diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js index 65148c9993f80..a85678d2acd45 100644 --- a/workspaces/arborist/test/arborist/reify.js +++ b/workspaces/arborist/test/arborist/reify.js @@ -1348,6 +1348,13 @@ t.test('workspaces', async t => { t.matchSnapshot(require(path + '/package-lock.json'), 'should lock workspaces config') }) + await t.test('reify workspaces with overrides', async t => { + const path = fixture(t, 'workspaces-with-overrides') + createRegistry(t, true) + await reify(path, { workspacesEnabled: true, workspaces: ['ws'] }) + t.matchSnapshot(require(path + '/package-lock.json'), 'should retain override version (4.1.3)') + }) + await t.test('reify workspaces bin files', t => { const path = fixture(t, 'workspaces-link-bin') createRegistry(t, false) diff --git a/workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js b/workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js new file mode 100644 index 0000000000000..b20ba236d87e1 --- /dev/null +++ b/workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js @@ -0,0 +1,54 @@ +// generated from test/fixtures/workspaces-with-overrides +module.exports = t => { + const path = t.testdir({ + "package-lock.json": JSON.stringify({ + "name": "workspace-with-overrides", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ] + }, + "node_modules/a": { + "resolved": "ws", + "link": true + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "license": "MIT" + }, + "ws": { + "name": "a", + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } + } + } + }), + "package.json": JSON.stringify({ + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ], + "overrides": { + "arg": "4.1.3" + } + }), + "ws": { + "package.json": JSON.stringify({ + "name": "a", + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } + }) + } +}) + return path +} diff --git a/workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json new file mode 100644 index 0000000000000..a7bbd20bbcb93 --- /dev/null +++ b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json @@ -0,0 +1,29 @@ +{ + "name": "workspace-with-overrides", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ] + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "license": "MIT" + }, + "node_modules/ws": { + "resolved": "ws", + "link": true + }, + "ws": { + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } + } + } +} diff --git a/workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json new file mode 100644 index 0000000000000..9f35f2abd82fc --- /dev/null +++ b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json @@ -0,0 +1,9 @@ +{ + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ], + "overrides": { + "arg": "4.1.3" + } +} diff --git a/workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json b/workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json new file mode 100644 index 0000000000000..b44d12e431fbe --- /dev/null +++ b/workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json @@ -0,0 +1,7 @@ +{ + "name": "ws", + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } +} From 7e510a143994cfbf1a758d560945479bfe6b043d Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Tue, 18 Feb 2025 14:10:34 -0500 Subject: [PATCH 3/3] fix(arborist): inherit overrides from fsParent Fixes #4205 In the virtual tree, workspace nodes are `fsChildren` of the root, not `children`. As a result, they weren't inheriting the root's overrides, causing those overrides to be ignored for all dependencies of workspaces. The fix here is to inherit `fsParent.overrides` whenever possible. --- workspaces/arborist/lib/node.js | 8 ++++++-- .../test/arborist/load-virtual.js.test.cjs | 7 +++++-- .../tap-snapshots/test/arborist/reify.js.test.cjs | 12 ++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/workspaces/arborist/lib/node.js b/workspaces/arborist/lib/node.js index dccbf99bf6080..dc7d01b595e6e 100644 --- a/workspaces/arborist/lib/node.js +++ b/workspaces/arborist/lib/node.js @@ -822,8 +822,12 @@ class Node { target.root = root } - if (!this.overrides && this.parent && this.parent.overrides) { - this.overrides = this.parent.overrides.getNodeRule(this) + if (!this.overrides) { + if (this.parent && this.parent.overrides) { + this.overrides = this.parent.overrides.getNodeRule(this) + } else if (this.fsParent && this.fsParent.overrides) { + this.overrides = this.fsParent.overrides.getNodeRule(this) + } } // tree should always be valid upon root setter completion. treeCheck(this) diff --git a/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs index 261ecb4736b7f..1abab1c97caca 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs @@ -16381,9 +16381,9 @@ ArboristNode { "arg" => ArboristNode { "edgesIn": Set { EdgeIn { - "error": "INVALID", "from": "ws", "name": "arg", + "override": "4.1.3", "spec": "4.1.2", "type": "prod", }, @@ -16433,8 +16433,8 @@ ArboristNode { ArboristNode { "edgesOut": Map { "arg" => EdgeOut { - "error": "INVALID", "name": "arg", + "override": "4.1.3", "spec": "4.1.2", "to": "node_modules/arg", "type": "prod", @@ -16443,6 +16443,9 @@ ArboristNode { "isWorkspace": true, "location": "ws", "name": "ws", + "overrides": Map { + "arg" => "4.1.3", + }, "path": "{CWD}/test/fixtures/workspaces-with-overrides/ws", "version": "1.0.0", }, diff --git a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs index 8138d2d5f2ac6..797f102234f5d 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs @@ -53512,6 +53512,12 @@ Object { "link": true, "resolved": "ws", }, + "node_modules/arg": Object { + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "license": "MIT", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "version": "4.1.3", + }, "ws": Object { "dependencies": Object { "arg": "4.1.2", @@ -53519,12 +53525,6 @@ Object { "name": "a", "version": "1.0.0", }, - "ws/node_modules/arg": Object { - "integrity": "sha512-+ytCkGcBtHZ3V2r2Z06AncYO8jz46UEamcspGoU8lHcEbpn6J77QK0vdWvChsclg/tM5XIJC5tnjmPp7Eq6Obg==", - "license": "MIT", - "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.2.tgz", - "version": "4.1.2", - }, }, "requires": true, }