New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call version lifecycle scripts during publish #1029
Conversation
@@ -595,7 +609,7 @@ export default class PublishCommand extends Command { | |||
} | |||
|
|||
gitCommitAndTagVersionForUpdates() { | |||
const tags = this.updates.map(({ package: { name } }) => | |||
const tags = this.updates.map(({ "package": { name } }) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can back out this change, but package is a reserved keyword and shouldn't be referenced without quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, good call!
I corrected the tests to work with windows path separators - it should rerun the build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far, a couple nits and we can merge.
test/PublishCommand.js
Outdated
@@ -2,7 +2,6 @@ import chalk from "chalk"; | |||
import log from "npmlog"; | |||
import normalizeNewline from "normalize-newline"; | |||
import path from "path"; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These newlines are significant (and mostly consistent across the other test files), please keep them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
test/PublishCommand.js
Outdated
script, | ||
[], | ||
path.resolve(testDir, "packages", "package-2"), | ||
jasmine.any(Function) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure expect.any(Function)
should work here? Or is this Jest 19 (not upgraded yet for reasons) biting us again?
The appveyor test failed on node 4, but it seems to be unrelated - can those tests be re-run? |
Nah, those appveyor tests have been flapping due to some unrelated reason. It's quite likely a re-run would just fail randomly in the node 8 matrix. We're fine here. |
Looks great, thanks @cwmoo740! |
Oh, and I don't see this as breaking, since they were never run previously, and moreover shouldn't have been run by a manual |
@@ -536,12 +536,26 @@ export default class PublishCommand extends Command { | |||
this.updatePackageDepsObject(pkg, "devDependencies", exact); | |||
this.updatePackageDepsObject(pkg, "peerDependencies", exact); | |||
|
|||
// exec preversion script | |||
pkg.runScript("preversion", (err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will run script asynchronously, wouldn't it? Same goes for other hooks that were added.
Are we fine with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s true. I forgot that almost everything in publish is synchronous, unlike bootstrap where parallelism is important.
If I read correctly, hooks are called in handled package, not on the root package. Can we also call hooks on the rootpackage? I'd like to call a hook on postversion, when everything is done (I'd like to create a merge commit between two branches). If we can't, I'm stuck with a wrapper command
|
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Following the guidelines here: https://docs.npmjs.com/cli/version
Lerna will now call preversion, version, and postversion scripts at the appropriate times in each package when running
lerna publish
.Motivation and Context
This allows more hooks into the lerna publish command. For example, I want to run a custom changelog generation script after package.json version is updated, but before the git commit.
Closes: #774
How Has This Been Tested?
Added some tests to verify that the three lifecycle scripts are called.
I wanted to mock Package.js but found no easy way to do that - the changes I was working on ended up affecting many of the tests in Publish.js, since it doesn't import or have access to the Package class directly.
Types of changes
This may be a breaking change because it now calls version scripts on publish, whereas before they were ignored.
Checklist: