-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: workspace support in several commands (#4654)
* Use lockfileFolder for CLI check * Make "upgrade" work inside workspace packages Executes "fetchRequestFromCwd" in actual cwd, which ensures "outdated" and "upgrade" commands in workspace packages operate on the correct dependencies and preserve unrelated lockfile entries. * Support workspaces in outdated and upgrade-interactive
- Loading branch information
Showing
18 changed files
with
312 additions
and
39 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 |
---|---|---|
|
@@ -330,3 +330,46 @@ test.concurrent('--latest works if there is an install script on a hoisted depen | |
'latest-with-install-script', | ||
); | ||
}); | ||
|
||
test.concurrent('upgrade to workspace root preserves child dependencies', (): Promise<void> => { | ||
return runUpgrade(['[email protected]'], {latest: true}, 'workspaces', async (config): ?Promise<void> => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock'))); | ||
|
||
// child workspace deps | ||
expect(lockfile.indexOf('[email protected]:')).toBeGreaterThanOrEqual(0); | ||
expect(lockfile.indexOf('[email protected]:')).toBeGreaterThanOrEqual(0); | ||
// root dep | ||
expect(lockfile.indexOf('[email protected]:')).toBe(-1); | ||
expect(lockfile.indexOf('[email protected]:')).toBeGreaterThanOrEqual(0); | ||
|
||
const rootPkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
expect(rootPkg.devDependencies['max-safe-integer']).toEqual('1.0.1'); | ||
|
||
const childAPkg = await fs.readJson(path.join(config.cwd, 'child-a/package.json')); | ||
const childBPkg = await fs.readJson(path.join(config.cwd, 'child-b/package.json')); | ||
expect(childAPkg.dependencies['left-pad']).toEqual('1.0.0'); | ||
expect(childBPkg.dependencies['right-pad']).toEqual('1.0.0'); | ||
}); | ||
}); | ||
|
||
test.concurrent('upgrade to workspace child preserves root dependencies', (): Promise<void> => { | ||
const fixture = {source: 'workspaces', cwd: 'child-a'}; | ||
return runUpgrade(['[email protected]'], {latest: true}, fixture, async (config): ?Promise<void> => { | ||
const lockfile = explodeLockfile(await fs.readFile(path.join(config.lockfileFolder, 'yarn.lock'))); | ||
|
||
// untouched deps | ||
expect(lockfile.indexOf('[email protected]:')).toBeGreaterThanOrEqual(0); | ||
expect(lockfile.indexOf('[email protected]:')).toBeGreaterThanOrEqual(0); | ||
// upgraded child workspace | ||
expect(lockfile.indexOf('[email protected]:')).toBe(-1); | ||
expect(lockfile.indexOf('[email protected]:')).toBeGreaterThanOrEqual(0); | ||
|
||
const childAPkg = await fs.readJson(path.join(config.cwd, 'package.json')); | ||
expect(childAPkg.dependencies['left-pad']).toEqual('1.1.0'); | ||
|
||
const rootPkg = await fs.readJson(path.join(config.lockfileFolder, 'package.json')); | ||
const childBPkg = await fs.readJson(path.join(config.lockfileFolder, 'child-b/package.json')); | ||
expect(rootPkg.devDependencies['max-safe-integer']).toEqual('1.0.0'); | ||
expect(childBPkg.dependencies['right-pad']).toEqual('1.0.0'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "child-a", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"max-safe-integer": "1.0.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "child-b", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"left-pad": "1.0.1", | ||
"right-pad": "1.0.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "my-project", | ||
"private": true, | ||
"devDependencies": { | ||
"left-pad": "1.0.0" | ||
}, | ||
"workspaces": [ | ||
"child-a", | ||
"child-b" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.0.0.tgz#c84e2417581bbb8eaf2b9e3d7a122e572ab1af37" | ||
|
||
[email protected]: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.0.1.tgz#d11b8e17e70e6ecb3b6bf2858fa99c40f819d13a" | ||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/max-safe-integer/-/max-safe-integer-1.0.0.tgz#4662073a02c7e02d38153e25795489b20be6f01a" | ||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.0.tgz#5ba6e56c0d7ec162d3626315c27a61f8aff42f15" |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "child-a", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"left-pad": "1.0.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "child-b", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"right-pad": "1.0.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "my-project", | ||
"private": true, | ||
"devDependencies": { | ||
"max-safe-integer": "1.0.0" | ||
}, | ||
"workspaces": [ | ||
"child-a", | ||
"child-b" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.0.0.tgz#c84e2417581bbb8eaf2b9e3d7a122e572ab1af37" | ||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/max-safe-integer/-/max-safe-integer-1.0.0.tgz#4662073a02c7e02d38153e25795489b20be6f01a" | ||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.0.tgz#5ba6e56c0d7ec162d3626315c27a61f8aff42f15" |
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
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
Oops, something went wrong.