From ec90f791832858a703c9cd092cd2486d0a3c657b Mon Sep 17 00:00:00 2001 From: kchindam-infy Date: Wed, 9 Apr 2025 08:28:12 -0700 Subject: [PATCH 1/2] omitted name from package-lock.json --- .../test/lib/commands/shrinkwrap.js.test.cjs | 7 -- workspaces/arborist/lib/shrinkwrap.js | 4 +- .../test/arborist/reify.js.test.cjs | 63 +-------------- .../tap-snapshots/test/shrinkwrap.js.test.cjs | 79 ------------------- workspaces/arborist/test/shrinkwrap.js | 1 - 5 files changed, 7 insertions(+), 147 deletions(-) diff --git a/tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs b/tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs index 96b41b117d19b..8414685ac1ab3 100644 --- a/tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs +++ b/tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs @@ -16,7 +16,6 @@ exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile ancient > must }, "config": {}, "shrinkwrap": { - "name": "prefix", "lockfileVersion": 1, "requires": true }, @@ -40,7 +39,6 @@ exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile ancient upgrad "lockfile-version": 3 }, "shrinkwrap": { - "name": "prefix", "lockfileVersion": 3, "requires": true, "packages": {} @@ -65,7 +63,6 @@ exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile existing > mus }, "config": {}, "shrinkwrap": { - "name": "prefix", "lockfileVersion": 2, "requires": true, "packages": {} @@ -90,7 +87,6 @@ exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile existing downg "lockfile-version": 1 }, "shrinkwrap": { - "name": "prefix", "lockfileVersion": 1, "requires": true }, @@ -116,7 +112,6 @@ exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile existing upgra "lockfile-version": 3 }, "shrinkwrap": { - "name": "prefix", "lockfileVersion": 3, "requires": true, "packages": {} @@ -135,7 +130,6 @@ exports[`test/lib/commands/shrinkwrap.js TAP with nothing ancient > must match s "localPrefix": {}, "config": {}, "shrinkwrap": { - "name": "prefix", "lockfileVersion": 3, "requires": true, "packages": {} @@ -154,7 +148,6 @@ exports[`test/lib/commands/shrinkwrap.js TAP with nothing ancient upgrade > must "lockfile-version": 3 }, "shrinkwrap": { - "name": "prefix", "lockfileVersion": 3, "requires": true, "packages": {} diff --git a/workspaces/arborist/lib/shrinkwrap.js b/workspaces/arborist/lib/shrinkwrap.js index e4b159c568250..76291ffaf733e 100644 --- a/workspaces/arborist/lib/shrinkwrap.js +++ b/workspaces/arborist/lib/shrinkwrap.js @@ -985,7 +985,9 @@ class Shrinkwrap { #buildLegacyLockfile (node, lock, path = []) { if (node === this.tree) { // the root node - lock.name = node.packageName || node.name + if (node.packageName) { + lock.name = node.packageName + } if (node.version) { lock.version = node.version } 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 b94ccc76df7f5..b97846340c184 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs @@ -205,7 +205,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add a new pkg to a prefix that needs to be mkdirpd not dry run > should place expected lockfile file into place 1`] = ` { - "name": "root", "lockfileVersion": 3, "requires": true, "packages": { @@ -237,7 +236,6 @@ exports[`test/arborist/reify.js TAP add a new pkg to a prefix that needs to be m exports[`test/arborist/reify.js TAP add deps to workspaces add a to root > lockfile added workspace as dep 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-add-a-to-root", "packages": Object { "": Object { "dependencies": Object { @@ -469,7 +467,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add deps to workspaces add mkdirp 0.5.0 to b > lockfile 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-add-mkdirp-0.5.0-to-b", "packages": Object { "": Object { "dependencies": Object { @@ -768,7 +765,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add deps to workspaces add mkdirp 0.5.0 to b, empty start > lockfile 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-add-mkdirp-0.5.0-to-b-empty-start", "packages": Object { "": Object { "dependencies": Object { @@ -979,7 +975,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add deps to workspaces no args > lockfile 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-no-args", "packages": Object { "": Object { "dependencies": Object { @@ -1198,7 +1193,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add deps to workspaces remove mkdirp from a > lockfile 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-remove-mkdirp-from-a", "packages": Object { "": Object { "dependencies": Object { @@ -1355,7 +1349,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add deps to workspaces remove mkdirp from a, empty start > lockfile 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-remove-mkdirp-from-a-empty-start", "packages": Object { "": Object { "dependencies": Object { @@ -1472,7 +1465,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add deps to workspaces upgrade mkdirp in a, dedupe on root > lockfile 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-upgrade-mkdirp-in-a-dedupe-on-root", "packages": Object { "": Object { "dependencies": Object { @@ -1649,7 +1641,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP add deps to workspaces upgrade mkdirp in a, dedupe on root, empty start > lockfile 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-add-deps-to-workspaces-upgrade-mkdirp-in-a-dedupe-on-root-empty-start", "packages": Object { "": Object { "dependencies": Object { @@ -3677,7 +3668,6 @@ ArboristNode { exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden lockfile - c 1`] = ` { - "name": "tap-testdir-reify-filtered-reification-in-workspaces", "lockfileVersion": 3, "requires": true, "packages": { @@ -3704,7 +3694,6 @@ exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden lockfile - c, old x, removed a 1`] = ` { - "name": "tap-testdir-reify-filtered-reification-in-workspaces", "lockfileVersion": 3, "requires": true, "packages": { @@ -3738,7 +3727,6 @@ exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden lockfile - c, x 1`] = ` { - "name": "tap-testdir-reify-filtered-reification-in-workspaces", "lockfileVersion": 3, "requires": true, "packages": { @@ -3772,7 +3760,6 @@ exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden lockfile - c, x, a 1`] = ` { - "name": "tap-testdir-reify-filtered-reification-in-workspaces", "lockfileVersion": 3, "requires": true, "packages": { @@ -3832,7 +3819,6 @@ exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden exports[`test/arborist/reify.js TAP filtered reification in workspaces > hidden lockfile - foo/x linked, c, old x, removed a 1`] = ` { - "name": "tap-testdir-reify-filtered-reification-in-workspaces", "lockfileVersion": 3, "requires": true, "packages": { @@ -4725,7 +4711,6 @@ exports[`test/arborist/reify.js TAP just the shrinkwrap cli-750-fresh > must mat exports[`test/arborist/reify.js TAP just the shrinkwrap yarn-lock-mkdirp > must match snapshot 1`] = ` { - "name": "tap-testdir-reify-just-the-shrinkwrap-yarn-lock-mkdirp", "lockfileVersion": 3, "requires": true, "packages": { @@ -5141,40 +5126,6 @@ exports[`test/arborist/reify.js TAP modules bundled by the root should be instal ` -exports[`test/arborist/reify.js TAP move aside symlink clutter > must match snapshot 1`] = ` -ArboristNode { - "children": Map { - "abbrev" => ArboristNode { - "edgesIn": Set { - EdgeIn { - "from": "", - "name": "abbrev", - "spec": "latest", - "type": "prod", - }, - }, - "location": "node_modules/abbrev", - "name": "abbrev", - "path": "{CWD}/test/arborist/tap-testdir-reify-move-aside-symlink-clutter/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": "latest", - "to": "node_modules/abbrev", - "type": "prod", - }, - }, - "isProjectRoot": true, - "location": "", - "name": "tap-testdir-reify-move-aside-symlink-clutter", - "path": "{CWD}/test/arborist/tap-testdir-reify-move-aside-symlink-clutter", -} -` - exports[`test/arborist/reify.js TAP multiple bundles at the same level > must match snapshot 1`] = ` ArboristNode { "children": Map { @@ -18433,7 +18384,6 @@ exports[`test/arborist/reify.js TAP packageLockOnly can add deps > must match sn exports[`test/arborist/reify.js TAP packageLockOnly can add deps > must match snapshot 2`] = ` { - "name": "tap-testdir-reify-packageLockOnly-can-add-deps", "lockfileVersion": 3, "requires": true, "packages": { @@ -33452,7 +33402,6 @@ exports[`test/arborist/reify.js TAP save package.json on update should not save exports[`test/arborist/reify.js TAP save package.json on update should not save many deps in multiple package.json when using save=false > should update lockfile with many deps updated package.json save=false 1`] = ` { - "name": "tap-testdir-reify-save-package.json-on-update-should-not-save-many-deps-in-multiple-package.json-when-using-save-false", "lockfileVersion": 3, "requires": true, "packages": { @@ -33512,7 +33461,6 @@ exports[`test/arborist/reify.js TAP save package.json on update should not save exports[`test/arborist/reify.js TAP save package.json on update should save many deps in multiple package.json when using save=true > should update lockfile with many deps updated package.json save=true 1`] = ` { - "name": "tap-testdir-reify-save-package.json-on-update-should-save-many-deps-in-multiple-package.json-when-using-save-true", "lockfileVersion": 3, "requires": true, "packages": { @@ -33572,7 +33520,7 @@ exports[`test/arborist/reify.js TAP save package.json on update should save many exports[`test/arborist/reify.js TAP save package.json on update should update named dep across multiple package.json using save=true > should update lockfile with many deps updated package.json save=true 1`] = ` { - "name": "tap-testdir-reify-save-package.json-on-update-should-update-named-dep-across-multiple-package.json-using-save-true", + "name": "workspaces-need-update", "lockfileVersion": 2, "requires": true, "packages": { @@ -33663,7 +33611,7 @@ exports[`test/arborist/reify.js TAP save package.json on update should update na exports[`test/arborist/reify.js TAP save package.json on update should update single named dep across multiple package.json using save=true > should update lockfile with single dep updated package.json save=true 1`] = ` { - "name": "tap-testdir-reify-save-package.json-on-update-should-update-single-named-dep-across-multiple-package.json-using-save-true", + "name": "workspaces-need-update", "lockfileVersion": 2, "requires": true, "packages": { @@ -33754,7 +33702,6 @@ exports[`test/arborist/reify.js TAP save package.json on update should update si exports[`test/arborist/reify.js TAP save proper lockfile with bins when upgrading lockfile complete=false > should upgrade, with bins in place 1`] = ` { - "name": "tap-testdir-reify-save-proper-lockfile-with-bins-when-upgrading-lockfile-complete-false", "lockfileVersion": 3, "requires": true, "packages": { @@ -33782,7 +33729,6 @@ exports[`test/arborist/reify.js TAP save proper lockfile with bins when upgradin exports[`test/arborist/reify.js TAP save proper lockfile with bins when upgrading lockfile complete=true > should upgrade, with bins in place 1`] = ` { - "name": "tap-testdir-reify-save-proper-lockfile-with-bins-when-upgrading-lockfile-complete-true", "lockfileVersion": 3, "requires": true, "packages": { @@ -33819,7 +33765,6 @@ exports[`test/arborist/reify.js TAP saveBundle > must match snapshot 1`] = ` exports[`test/arborist/reify.js TAP saving the ideal tree save some stuff > lock after save 1`] = ` Object { "lockfileVersion": 3, - "name": "tap-testdir-reify-saving-the-ideal-tree-save-some-stuff", "packages": Object { "": Object { "bundleDependencies": Array [ @@ -47645,7 +47590,7 @@ mkdirp@^1.0.2: exports[`test/arborist/reify.js TAP warn and correct if damaged data in lockfile first pass logs > "fixed" lockfile 1`] = ` { - "name": "tap-testdir-reify-warn-and-correct-if-damaged-data-in-lockfile", + "name": "garbage-in-reify-tree", "lockfileVersion": 2, "requires": true, "packages": { @@ -47661,7 +47606,7 @@ exports[`test/arborist/reify.js TAP warn and correct if damaged data in lockfile exports[`test/arborist/reify.js TAP warn and correct if damaged data in lockfile second pass just does the right thing > actually fixed lockfile 1`] = ` { - "name": "tap-testdir-reify-warn-and-correct-if-damaged-data-in-lockfile", + "name": "garbage-in-reify-tree", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs index a061ef5fbe493..6b41483b2e74c 100644 --- a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs @@ -1865,7 +1865,6 @@ Object { exports[`test/shrinkwrap.js TAP loadActual tests link-dep-cycle > shrinkwrap data 1`] = ` Object { "lockfileVersion": 3, - "name": "link-dep-cycle", "packages": Object { "": Object { "dependencies": Object { @@ -2319,7 +2318,6 @@ Object { exports[`test/shrinkwrap.js TAP loadActual tests noname > shrinkwrap data 1`] = ` Object { "lockfileVersion": 3, - "name": "noname", "packages": Object { "node_modules/foo": Object { "extraneous": true, @@ -2422,7 +2420,6 @@ Object { exports[`test/shrinkwrap.js TAP loadActual tests other > shrinkwrap data 1`] = ` Object { "lockfileVersion": 3, - "name": "other", "packages": Object { "../root/node_modules/@scope/x/node_modules/glob": Object { "dependencies": Object { @@ -2742,81 +2739,6 @@ Object { } ` -exports[`test/shrinkwrap.js TAP loadActual tests selflink > shrinkwrap data 2`] = ` -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, @@ -9958,7 +9880,6 @@ Object { exports[`test/shrinkwrap.js TAP loadActual tests yarn-lock-mkdirp-file-dep > shrinkwrap data 1`] = ` Object { "lockfileVersion": 3, - "name": "yarn-lock-mkdirp-file-dep", "packages": Object { "": Object { "dependencies": Object { diff --git a/workspaces/arborist/test/shrinkwrap.js b/workspaces/arborist/test/shrinkwrap.js index bc0e56cf3928d..55f33244f7102 100644 --- a/workspaces/arborist/test/shrinkwrap.js +++ b/workspaces/arborist/test/shrinkwrap.js @@ -152,7 +152,6 @@ t.test('loading in empty dir gets empty lockfile', async t => { root.extraneous = false sw.add(root) t.strictSame(sw.commit(), { - name: 'empty', lockfileVersion: 3, requires: true, packages: {}, From eaa2f8fe95d09e3e1d83d0c0d5afa4cbe7289d05 Mon Sep 17 00:00:00 2001 From: kchindam-infy Date: Wed, 9 Apr 2025 09:18:46 -0700 Subject: [PATCH 2/2] fixed test cases fails with mac and windows --- .../test/arborist/reify.js.test.cjs | 34 +++++++++ .../tap-snapshots/test/shrinkwrap.js.test.cjs | 75 +++++++++++++++++++ 2 files changed, 109 insertions(+) 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 b97846340c184..a0c65f0c50916 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs @@ -5126,6 +5126,40 @@ exports[`test/arborist/reify.js TAP modules bundled by the root should be instal ` +exports[`test/arborist/reify.js TAP move aside symlink clutter > must match snapshot 1`] = ` +ArboristNode { + "children": Map { + "abbrev" => ArboristNode { + "edgesIn": Set { + EdgeIn { + "from": "", + "name": "abbrev", + "spec": "latest", + "type": "prod", + }, + }, + "location": "node_modules/abbrev", + "name": "abbrev", + "path": "{CWD}/test/arborist/tap-testdir-reify-move-aside-symlink-clutter/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": "latest", + "to": "node_modules/abbrev", + "type": "prod", + }, + }, + "isProjectRoot": true, + "location": "", + "name": "tap-testdir-reify-move-aside-symlink-clutter", + "path": "{CWD}/test/arborist/tap-testdir-reify-move-aside-symlink-clutter", +} +` + exports[`test/arborist/reify.js TAP multiple bundles at the same level > must match snapshot 1`] = ` ArboristNode { "children": Map { diff --git a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs index 6b41483b2e74c..c1ecd23c78601 100644 --- a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs @@ -2739,6 +2739,81 @@ Object { } ` +exports[`test/shrinkwrap.js TAP loadActual tests selflink > shrinkwrap data 2`] = ` +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,