-
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(linking): Handle missing package when using --ignore-optional (#5059
) **Summary** Closes #5054, closes #4876, closes #5152. Currently when running `yarn --ignore-optional` required dependencies can be marked as optional because they exist in the tree of `optionalDependencies` of one of the dependencies (but it's required by some other non-optional dependency). For example: `once` depends on `wrappy`, but `wrappy` is also in the chain from `fsevents` (`glob` -> `inflight` -> `wrappy`) which is an optional dependency of `chokidar`. So if the first `wrappy` comes from an "optional chain" when yarn processes it, it ends up being marked as `_reference.optional = true`, and the package hoister therefore doesn't mark it as required. When running the released version of yarn with https://github.com/spalger/reproduce-issues/blob/master/yarn-ignores-non-optional-dependencies you'll see ``` ~/dev/reproduce-issues/yarn-ignores-non-optional-dependencies $ yarn --ignore-optional yarn install v1.3.2-20171204.1856 [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... [4/4] 📃 Building fresh packages... ✨ Done in 0.17s. ~/dev/reproduce-issues/yarn-ignores-non-optional-dependencies $ yarn check --verify-tree yarn check v1.3.2-20171204.1856 error "once#wrappy" not installed error An unexpected error occurred: "Found 1 errors.". ``` This fix checks whether or not the parent is marked as required, and if so, marking the dependency as required _unless_ it's listed in the parent's `optionalDependencies`. **Test plan** I tested this implementation with both https://github.com/spalger/reproduce-issues/blob/master/yarn-ignores-non-optional-dependencies and #4876, and in both cases `yarn check --verify-tree` succeeded after running `yarn --ignore-optional`. Also added automated tests.
- Loading branch information
Showing
22 changed files
with
98 additions
and
44 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: 0 additions & 1 deletion
1
__tests__/fixtures/install/failing-sub-dep-optional-and-normal/normal-dep/install.js
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
__tests__/fixtures/install/failing-sub-dep-optional-and-normal/normal-dep/package.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
__tests__/fixtures/install/failing-sub-dep-optional-and-normal/optional-dep/install.js
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
__tests__/fixtures/install/failing-sub-dep-optional-and-normal/optional-dep/package.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
__tests__/fixtures/install/failing-sub-dep-optional-and-normal/sub-failing/install.js
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
__tests__/fixtures/install/failing-sub-dep-optional-and-normal/sub-failing/package.json
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...nstall/install-sub-dependency-if-any-parents-mark-it-non-optional/normal-dep/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,11 @@ | ||
{ | ||
"name": "normal-dep", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"sub-dep": "file:../sub-dep", | ||
"normal-sub-dep": "file:../normal-sub-dep" | ||
}, | ||
"optionalDependencies": { | ||
"optional-sub-dep": "file:../optional-sub-dep" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ll/install-sub-dependency-if-any-parents-mark-it-non-optional/normal-sub-dep/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,7 @@ | ||
{ | ||
"name": "normal-sub-dep", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"normal-sub-sub-dep": "file:../normal-sub-sub-dep" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...nstall-sub-dependency-if-any-parents-mark-it-non-optional/normal-sub-sub-dep/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,7 @@ | ||
{ | ||
"name": "normal-sub-sub-dep", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"sub-dep-2": "file:../sub-dep-2" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...tall/install-sub-dependency-if-any-parents-mark-it-non-optional/optional-dep/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,8 @@ | ||
{ | ||
"name": "optional-dep", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"sub-dep": "file:../sub-dep", | ||
"sub-dep-2": "file:../sub-dep-2" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../install-sub-dependency-if-any-parents-mark-it-non-optional/optional-sub-dep/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,7 @@ | ||
{ | ||
"name": "optional-sub-dep", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"normal-sub-sub-dep": "file:../normal-sub-sub-dep" | ||
} | ||
} |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
...install/install-sub-dependency-if-any-parents-mark-it-non-optional/sub-dep-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,7 @@ | ||
{ | ||
"name": "sub-dep-2", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"sub-sub-dep": "file:../sub-sub-dep" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...s/install/install-sub-dependency-if-any-parents-mark-it-non-optional/sub-dep/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,4 @@ | ||
{ | ||
"name": "sub-dep", | ||
"version": "0.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
...stall/install-sub-dependency-if-any-parents-mark-it-non-optional/sub-sub-dep/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,4 @@ | ||
{ | ||
"name": "sub-sub-dep", | ||
"version": "0.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
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
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