feat(pack): Allow temporary changing the package.json during prepack #5275
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?
Making changes to the
package.json
during prepack is annoying, because whatever changes are made also need to be reverted (or committed, but if they are applied during build it's likely that the users don't want them).How did you fix it?
This diff implements a new environment variable when the
prepack
lifecycle script is called:PACK_MANIFEST
. If this file exists afterprepack
returns, Yarn will read it and merge it to the final manifest used to pack the package, before automatically removing it from the filesystem once it's no longer needed.This way, prepack scripts have the ability to modify:
publishConfig
(although they can now also directly modify themain
,exports
, etc fields)version
(can be handy to handle the versioning outside of Yarn itself)authors
(for example to automatically generate the authors list from the git commit)As well as all the other fields from
package.json
. They can even add new ones, for example to attach a commit link to the package.json during builds.Checklist