-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(arborist): save workspace version (#4578)
When declaring dependencies to workspaces the common practice is to refer to their version numbers, currently the cli adds a link reference instead of the proper semver range when trying to install/declare as a direct direct dependency one of its own workspaces. This change fixes it by adding a new condition for handling workspace edges when saving the current ideal tree. Relates to: #3403
- Loading branch information
Showing
3 changed files
with
258 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,235 @@ 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 { | ||
"a": "^1.2.3", | ||
"mkdirp": "^1.0.4", | ||
}, | ||
"workspaces": Array [ | ||
"packages/*", | ||
], | ||
}, | ||
"node_modules/a": Object { | ||
"link": true, | ||
"resolved": "packages/a", | ||
}, | ||
"node_modules/b": Object { | ||
"link": true, | ||
"resolved": "packages/b", | ||
}, | ||
"node_modules/minimist": Object { | ||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", | ||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", | ||
"version": "1.2.5", | ||
}, | ||
"node_modules/mkdirp": Object { | ||
"bin": Object { | ||
"mkdirp": "bin/cmd.js", | ||
}, | ||
"engines": Object { | ||
"node": ">=10", | ||
}, | ||
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", | ||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", | ||
"version": "1.0.4", | ||
}, | ||
"packages/a": Object { | ||
"dependencies": Object { | ||
"mkdirp": "^0.5.0", | ||
}, | ||
"version": "1.2.3", | ||
}, | ||
"packages/a/node_modules/mkdirp": Object { | ||
"bin": Object { | ||
"mkdirp": "bin/cmd.js", | ||
}, | ||
"dependencies": Object { | ||
"minimist": "^1.2.5", | ||
}, | ||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", | ||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", | ||
"version": "0.5.5", | ||
}, | ||
"packages/b": Object { | ||
"version": "1.2.3", | ||
}, | ||
}, | ||
"requires": true, | ||
} | ||
` | ||
|
||
exports[`test/arborist/reify.js TAP add deps to workspaces add a to root > package.json added workspace as dep 1`] = ` | ||
Object { | ||
"dependencies": Object { | ||
"a": "^1.2.3", | ||
"mkdirp": "^1.0.4", | ||
}, | ||
"workspaces": Array [ | ||
"packages/*", | ||
], | ||
} | ||
` | ||
|
||
exports[`test/arborist/reify.js TAP add deps to workspaces add a to root > returned tree 1`] = ` | ||
ArboristNode { | ||
"children": Map { | ||
"a" => ArboristLink { | ||
"edgesIn": Set { | ||
EdgeIn { | ||
"from": "", | ||
"name": "a", | ||
"spec": "file:{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/a", | ||
"type": "workspace", | ||
}, | ||
}, | ||
"isWorkspace": true, | ||
"location": "node_modules/a", | ||
"name": "a", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/node_modules/a", | ||
"realpath": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/a", | ||
"resolved": "file:../packages/a", | ||
"target": ArboristNode { | ||
"location": "packages/a", | ||
}, | ||
"version": "1.2.3", | ||
}, | ||
"b" => ArboristLink { | ||
"edgesIn": Set { | ||
EdgeIn { | ||
"from": "", | ||
"name": "b", | ||
"spec": "file:{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/b", | ||
"type": "workspace", | ||
}, | ||
}, | ||
"isWorkspace": true, | ||
"location": "node_modules/b", | ||
"name": "b", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/node_modules/b", | ||
"realpath": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/b", | ||
"resolved": "file:../packages/b", | ||
"target": ArboristNode { | ||
"location": "packages/b", | ||
}, | ||
"version": "1.2.3", | ||
}, | ||
"minimist" => ArboristNode { | ||
"edgesIn": Set { | ||
EdgeIn { | ||
"from": "packages/a/node_modules/mkdirp", | ||
"name": "minimist", | ||
"spec": "^1.2.5", | ||
"type": "prod", | ||
}, | ||
}, | ||
"location": "node_modules/minimist", | ||
"name": "minimist", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/node_modules/minimist", | ||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", | ||
"version": "1.2.5", | ||
}, | ||
"mkdirp" => ArboristNode { | ||
"edgesIn": Set { | ||
EdgeIn { | ||
"from": "", | ||
"name": "mkdirp", | ||
"spec": "^1.0.4", | ||
"type": "prod", | ||
}, | ||
}, | ||
"location": "node_modules/mkdirp", | ||
"name": "mkdirp", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/node_modules/mkdirp", | ||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", | ||
"version": "1.0.4", | ||
}, | ||
}, | ||
"edgesOut": Map { | ||
"a" => EdgeOut { | ||
"name": "a", | ||
"spec": "file:{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/a", | ||
"to": "node_modules/a", | ||
"type": "workspace", | ||
}, | ||
"b" => EdgeOut { | ||
"name": "b", | ||
"spec": "file:{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/b", | ||
"to": "node_modules/b", | ||
"type": "workspace", | ||
}, | ||
"mkdirp" => EdgeOut { | ||
"name": "mkdirp", | ||
"spec": "^1.0.4", | ||
"to": "node_modules/mkdirp", | ||
"type": "prod", | ||
}, | ||
}, | ||
"fsChildren": Set { | ||
ArboristNode { | ||
"children": Map { | ||
"mkdirp" => ArboristNode { | ||
"edgesIn": Set { | ||
EdgeIn { | ||
"from": "packages/a", | ||
"name": "mkdirp", | ||
"spec": "^0.5.0", | ||
"type": "prod", | ||
}, | ||
}, | ||
"edgesOut": Map { | ||
"minimist" => EdgeOut { | ||
"name": "minimist", | ||
"spec": "^1.2.5", | ||
"to": "node_modules/minimist", | ||
"type": "prod", | ||
}, | ||
}, | ||
"location": "packages/a/node_modules/mkdirp", | ||
"name": "mkdirp", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/a/node_modules/mkdirp", | ||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", | ||
"version": "0.5.5", | ||
}, | ||
}, | ||
"edgesOut": Map { | ||
"mkdirp" => EdgeOut { | ||
"name": "mkdirp", | ||
"spec": "^0.5.0", | ||
"to": "packages/a/node_modules/mkdirp", | ||
"type": "prod", | ||
}, | ||
}, | ||
"isWorkspace": true, | ||
"location": "packages/a", | ||
"name": "a", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/a", | ||
"version": "1.2.3", | ||
}, | ||
ArboristNode { | ||
"isWorkspace": true, | ||
"location": "packages/b", | ||
"name": "b", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root/packages/b", | ||
"version": "1.2.3", | ||
}, | ||
}, | ||
"isProjectRoot": true, | ||
"location": "", | ||
"name": "tap-testdir-reify-add-deps-to-workspaces-add-a-to-root", | ||
"path": "{CWD}/test/arborist/tap-testdir-reify-add-deps-to-workspaces-add-a-to-root", | ||
"workspaces": Map { | ||
"a" => "packages/a", | ||
"b" => "packages/b", | ||
}, | ||
} | ||
` | ||
|
||
exports[`test/arborist/reify.js TAP add deps to workspaces add mkdirp 0.5.0 to b > lockfile 1`] = ` | ||
Object { | ||
"dependencies": Object { | ||
|
@@ -33222,7 +33451,7 @@ Object { | |
"a": "github:foo/bar#baz", | ||
"b": "^1.2.3", | ||
"d": "npm:[email protected] <1.9.9", | ||
"e": "file:e", | ||
"e": "*", | ||
"f": "git+https://user:[email protected]/baz/quux.git#asdf", | ||
"g": "*", | ||
"h": "~1.2.3", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -894,8 +894,7 @@ t.test('saving the ideal tree', t => { | |
a: 'git+ssh://[email protected]:foo/bar#baz', | ||
b: '', | ||
d: 'npm:[email protected] <1.9.9', | ||
// XXX: should we remove dependencies that are also workspaces? | ||
e: 'file:e', | ||
e: '*', | ||
f: 'git+https://user:[email protected]/baz/quux#asdf', | ||
g: '', | ||
h: '~1.2.3', | ||
|
@@ -1028,7 +1027,7 @@ t.test('saving the ideal tree', t => { | |
a: 'github:foo/bar#baz', | ||
b: '^1.2.3', | ||
d: 'npm:[email protected] <1.9.9', | ||
e: 'file:e', | ||
e: '*', | ||
f: 'git+https://user:[email protected]/baz/quux.git#asdf', | ||
g: '*', | ||
h: '~1.2.3', | ||
|
@@ -2045,6 +2044,15 @@ t.test('add deps to workspaces', async t => { | |
t.matchSnapshot(require(path + '/packages/a/package.json'), 'package.json a') | ||
t.matchSnapshot(require(path + '/package-lock.json'), 'lockfile') | ||
}) | ||
|
||
t.test('add a to root', async t => { | ||
const path = t.testdir(fixture) | ||
await reify(path) | ||
const tree = await reify(path, { add: ['a'], lockfileVersion: 3 }) | ||
t.matchSnapshot(printTree(tree), 'returned tree') | ||
t.matchSnapshot(require(path + '/package.json'), 'package.json added workspace as dep') | ||
t.matchSnapshot(require(path + '/package-lock.json'), 'lockfile added workspace as dep') | ||
}) | ||
}) | ||
|
||
t.test('reify audit only workspace deps when reifying workspace', async t => { | ||
|