Repository navigation
Conversation
`changeset version` now runs the `preversion` and `postversion` scripts of the packages it versions, with the project's package manager, like `npm version` does. `preversion` runs before any file is changed, so a failing script stops the command before anything is written. `postversion` runs after the files are written and committed. The new `runVersionScripts` config option (default `true`) turns this off. Fixes changesets#982
🦋 Changeset detectedLatest commit: 54b628f The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
👷 Deploy request for changesets pending review.Visit the deploys page to approve it
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2355 +/- ##
==========================================
+ Coverage 87.47% 87.56% +0.08%
==========================================
Files 78 78
Lines 2971 2991 +20
Branches 851 859 +8
==========================================
+ Hits 2599 2619 +20
Misses 337 337
Partials 35 35 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #982
changeset versionbumps versions but never runs the packages'preversionorpostversionscripts, so setups that relied on them withnpm version(likereact-native-versionupdating the native app versions inpostversion) have no hook to use. @Andarist said on the issue this should be supported with an option to opt out, so this adds that.What changes:
nonereleases are skipped),changeset versionruns itspreversionscript before any file is changed, and itspostversionscript after the versions and changelogs are written, and after the commit whencommitis enabled. That's the same order asnpm version.npm run,pnpm run,yarn run,bun run, detected withpackage-manager-detector, which the CLI already uses) from the package's directory, with output inherited.npm_lifecycle_eventandnpm_package_versionare set as usual. Packages run one at a time so their output doesn't interleave.The preversion script of pkg-a failed.and exits with code 1. A failingpreversionstops it before anything is written.runVersionScripts(defaulttrue) to opt out. Added to@changesets/types(alsoscriptsonPackageJSON), the valibot schema and the regeneratedschema.json.versionscript itself is not run, because it's often the script that callschangeset version("version": "changeset version"), and running it would recurse.Docs: new
runVersionScriptssection insite/guide/config.mdanddocs/config-file-options.md, plus a short "Lifecycle scripts" note under theversioncommand insite/guide/cli.md. Changeset included, minor for@changesets/cli,@changesets/configand@changesets/types.Two things you may want to weigh in on:
preversionlikenpm testwill start running it duringchangeset version. If you'd rather ship it opt-in first, it's a one-line default change plus the docs.changeset versionfrom its ownversionscript vianpm run version, npm already runspreversion/postversionaround it, so they'd run twice.runVersionScripts: falsecovers that; I didn't add special handling for it.How I tested it:
packages/cli/src/commands/version/version.test.ts(taggedslow, as they spawn npm) using real scripts that write the package's current version to a file:preversionsees1.0.0andpostversionsees1.1.0, and an unreleased package with the same scripts runs neither.commitenabled,postversionhasn't run yet when the commit is made.runVersionScripts: falseruns neither script.preversionthrowsExitError, logs the message above, leavespackage.jsonat1.0.0, keeps the changeset file and doesn't runpostversion.packages/config/src/parse.test.ts: updated the default config snapshots, added a valid case (runVersionScripts: false) and an invalid one (non-boolean).pnpm build,pnpm test run(39 files, 822 passed, 2 todo),pnpm types:check,pnpm lintandpnpm formatall pass.preversionran withnpm_lifecycle_event=preversionand version1.0.0, thenpostversionran with1.1.0after the files were written.Happy to take suggested changes, including on the option name.