Properly ignore hoisted popular transitive devDeps in --prod mode. Fi… #3465
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes #3439 (Installed devDependencies in --production).
Because of this issue, yarn can install some packages which are only reachable through devDependencies. Those packages installed are the ones hoisted to the root because they are the popular versions of a package with multiple versions.
** Analysis **
The _seed function in the package hoister assumes that it is called with a depencency from the package.json file if no parent is provided. If no parent is provided, it looks at the package reference's ignore field to determine if the package should initially be ignored (that field is set for direct devDependencies in --production mode).
The prepass function which pre-hoists the packages versions with the highest usage counts does not provide a parent HoistManifest to the _seed function. The _seed function then incorrectly assumes that those packages are package.json dependencies, and immediately marks them as required (because their package reference's ignore field isn't set). It should just wait for the reset of the hoisting precess to dedupe to those packages, and let the after-processing mark them as required only if a path from a normal dependency to those packages exist.
This PR adds a parameter to the _seed function to indicate whether a pattern to hoist is a reference from the package.json file, instead of relying on the parent parameter.
Test plan
A test was added which reproduces the error (in integration-hoisting.js). This test fails without the fix, passes with it. The rest of the test suite also passes.