Skip to content
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

Add support for root-level version lifecycle #1149

Merged
merged 1 commit into from
Jan 9, 2018

Conversation

bigtimebuddy
Copy link
Contributor

@bigtimebuddy bigtimebuddy commented Nov 29, 2017

Description

This change introduces an optional, root-level postversion script that can be run when publishing. This happens after all per-package postversion scripts have been called.

Motivation and Context

Currently, postversion hooks can only be run per-package. It's useful to have a postversion hook immediately before publishing and after version bumping to rebuild or do anything else which might need to use the updated global version number. In my particular circumstance, I'm using Rollup to build all the packages at the top-level and not relying on lerna run (for performance and memory reasons). While my circumstance is admittedly somewhat specific, the utility of adding a hook here seems pretty generalized.

How Has This Been Tested?

It has been run locally within a project by running lerna publish --skip-npm within a project. This triggers postversion if it's set in the root-level package.json scripts. It has been run with and without the hook and performs as expected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@evocateur evocateur changed the title Adds support for root-level postversion hook Add support for root-level version lifecycle Jan 9, 2018
Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. I'll add preversion and version calls at the root level, too, because I like the symmetry.

@evocateur
Copy link
Member

What I'm thinking, additionally:

diff --git a/src/commands/PublishCommand.js b/src/commands/PublishCommand.js
index f1d3d994..f76c703b 100644
--- a/src/commands/PublishCommand.js
+++ b/src/commands/PublishCommand.js
@@ -570,6 +570,9 @@ export default class PublishCommand extends Command {
     const { exact, conventionalCommits } = this.options;
     const changedFiles = [];
 
+    // exec preversion lifecycle in root (before all updates)
+    this.runSyncScriptInPackage(this.repository.package, "preversion");
+
     this.updates.forEach((update) => {
       const pkg = update.package;
       const packageLocation = pkg.location;
@@ -632,6 +635,9 @@ export default class PublishCommand extends Command {
       }
     }
 
+    // exec version lifecycle in root (after all updates)
+    this.runSyncScriptInPackage(this.repository.package, "version");
+
     if (this.gitEnabled) {
       changedFiles.forEach((file) => GitUtilities.addFile(file, this.execOpts));
     }

@lock
Copy link

lock bot commented Dec 27, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants