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.
What's the problem this PR addresses?
Some packages have improper declarations, requiring to either send a PR upstream (and waiting for it to be accepted), or manually patching the lockfile (which feels a bit dirty). We should have a better story to encourage people to unblock themselves.
How did you fix it?
Yarn now supports a
packageExtensions
object in the.yarnrc.yml
file which makes it possible to extend package declarations with new metadata. For example, the following rc would allowwebpack
to accesslodash
:The key is expected to by a semver range which will be matched against the effective version of the package (regardless of how the dependency got fetched - git dependencies will be semver-matched all the like).
This is a quite complicated fix because it involves making subtle changes to how the lockfile is generated. Before, Yarn used to store the resolved tree as-is - so just loading the tree (and running the virtual hydratation, since virtual packages are computed separately) used to be enough to get the representation of the dependency tree. This way nice, but it had a major drawback: making changes to the way the dependencies were resolved (for example adding a dependency, or using the
resolutions
field to remap them) caused the changes to be persisted inside the lockfile. Even after the edit sources were removed from the configuration the overrides were kept. It could be quite confusing, and made such features destructive by nature.So instead, I reworked the lockfile to instead store the original version of the package definitions, before any normalisation or patching. This implies a few things:
The lockfile doesn't reference anymore the
npm:
protocol in thedependencies
field, because this field doesn't get normalised anymore.npm:
protocol, because they are the fully normalised .Directly accessing
storedPackages
after instantiating a Project won't work, because at this point the Project will only contain the original versions of the package - before they have been normalised. In order to make it available, the consumer will have to callresolveEverything
(ideally with thelockfileOnly
flag) - cfyarn bin
for an example.