Skip to content

Commit 7b3817c

Browse files
committed
fix(publish): Update lerna.json version after root preversion lifecycle
Refs #1495
1 parent 60ff432 commit 7b3817c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

commands/publish/index.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ class PublishCommand extends Command {
191191

192192
const tasks = [];
193193

194-
if (!this.project.isIndependent() && !this.options.canary) {
195-
tasks.push(() => this.updateVersionInLernaJson());
196-
}
197-
198194
tasks.push(() => this.updateUpdatedPackages());
199195

200196
if (this.gitEnabled) {
@@ -461,16 +457,6 @@ class PublishCommand extends Command {
461457
return PromptUtilities.confirm("Are you sure you want to publish the above changes?");
462458
}
463459

464-
updateVersionInLernaJson() {
465-
this.project.version = this.globalVersion;
466-
467-
return this.project.serializeConfig().then(lernaConfigLocation => {
468-
if (!this.options.skipGit) {
469-
return gitAdd([lernaConfigLocation], this.execOpts);
470-
}
471-
});
472-
}
473-
474460
runPackageLifecycle(pkg, stage) {
475461
if (pkg.scripts[stage]) {
476462
return runLifecycle(pkg, stage, this.conf).catch(err => {
@@ -489,6 +475,11 @@ class PublishCommand extends Command {
489475
// my kingdom for async await :(
490476
let chain = Promise.resolve();
491477

478+
// preversion: Run BEFORE bumping the package version.
479+
// version: Run AFTER bumping the package version, but BEFORE commit.
480+
// postversion: Run AFTER bumping the package version, and AFTER commit.
481+
// @see https://docs.npmjs.com/misc/scripts
482+
492483
// exec preversion lifecycle in root (before all updates)
493484
chain = chain.then(() => this.runPackageLifecycle(rootPkg, "preversion"));
494485

@@ -559,6 +550,17 @@ class PublishCommand extends Command {
559550
);
560551
}
561552

553+
if (!independentVersions && !this.options.canary) {
554+
this.project.version = this.globalVersion;
555+
556+
chain = chain.then(() =>
557+
this.project.serializeConfig().then(lernaConfigLocation => {
558+
// commit the version update
559+
changedFiles.add(lernaConfigLocation);
560+
})
561+
);
562+
}
563+
562564
// exec version lifecycle in root (after all updates)
563565
chain = chain.then(() => this.runPackageLifecycle(rootPkg, "version"));
564566

0 commit comments

Comments
 (0)