-
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: Prevents hoisting through peer dependencies (#4086)
**Summary** Fixes #3933. Currently, the code hoists depedencies without ensuring hoisting doesn't break the final structure's `peerDependencies` requirements. This patch fixes that by adding extra checks before hoisting. It comes with a little performance impact but shouldn't be too much. **Test plan** A new integration test that simulates the reported behavior and ensures `yarn` now behaves correctly.
- Loading branch information
Showing
13 changed files
with
97 additions
and
3 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
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/a/index.js
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 @@ | ||
require("c") |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/a/package.json
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 @@ | ||
{"name":"a", "version":"1.0.0", "dependencies":{"b":"file:../b-2", "c":"file:../c"}} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/b-1/package.json
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 @@ | ||
{"name":"b", "version":"1.0.0"} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/b-2/package.json
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 @@ | ||
{"name":"b", "version":"2.0.0"} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/c/index.js
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 @@ | ||
console.log(require("b/package.json").version) |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/c/package.json
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 @@ | ||
{"name":"c", "version":"1.0.0", "peerDependencies":{"b":"2.0.0"}} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/d/package.json
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 @@ | ||
{"name":"d", "version":"1.0.0", "dependencies":{"b":"file:../b-1"}} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/e/package.json
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 @@ | ||
{"name":"e", "version":"1.0.0", "dependencies":{"b":"file:../b-1"}} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/index.js
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 @@ | ||
require("a") |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/package.json
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 @@ | ||
{"dependencies":{"a":"file:./a", "d":"file:./d", "e":"file:./e"}} |
28 changes: 28 additions & 0 deletions
28
__tests__/fixtures/install/install-should-not-hoist-through-peer-deps/yarn.lock
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,28 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"a@file:./a": | ||
version "1.0.0" | ||
dependencies: | ||
b "file:../../../Users/mael/Library/Caches/Yarn/v1/b-2" | ||
c "file:../../../Users/mael/Library/Caches/Yarn/v1/c" | ||
|
||
"b@file:b-1": | ||
version "1.0.0" | ||
|
||
"b@file:b-2": | ||
version "2.0.0" | ||
|
||
"c@file:c": | ||
version "1.0.0" | ||
|
||
"d@file:./d": | ||
version "1.0.0" | ||
dependencies: | ||
b "file:../../../Users/mael/Library/Caches/Yarn/v1/b-1" | ||
|
||
"e@file:./e": | ||
version "1.0.0" | ||
dependencies: | ||
b "file:../../../Users/mael/Library/Caches/Yarn/v1/b-1" |
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