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 npm version #35

Open
JasonCust opened this issue Dec 17, 2017 · 7 comments
Open

Add support for npm version #35

JasonCust opened this issue Dec 17, 2017 · 7 comments

Comments

@JasonCust
Copy link
Contributor

Before submitting a PR, what are your thoughts for supporting npm version. This would have the benefit of working directly within existing npm scripting flows. Also this module could then leverage the npm variables exposed for getting/updating the version which would allow for support of various types of releases beyond major, minor, and patch.

The main concern I can see is supporting workflows for generating a change log outside of versioning... although that doesn't seem like a normal use case.

@robinjoseph08
Copy link
Contributor

Thanks for submitting an issue before the PR, we appreciate that!

I'm not sure I follow what you mean by "supporting npm version". Do you mean in the changelog code, it calls npm version?

@JasonCust
Copy link
Contributor Author

As you know, npm provides a built in manner for managing version bumps. As with most script support it also provides hooks throughout the various stages of running a script (e.g. pre, post, etc.). In the case of npm version there are three stages to work with:

preversion: Run BEFORE bumping the package version.
version: Run AFTER bumping the package version, but BEFORE commit.
postversion: Run AFTER bumping the package version, and AFTER commit.

During these stages npm also exposes variables to the script through name-spaced globals. A few have particular interest to changelog:

  • npm_package_version: the package version. The value is dependent on the current stage of the script.
  • npm_config_argv: the arguments passed to the script. In the case of npm version it would include the type argument (e.g. major, premajor, minor, preminor, patch, prepatch, or prerelease).

Using npm_package_version in the preversion stage would report the version before bumping and would report the properly bumped version in either version or postversion stages. The benefit here is that changelog could support all valid semver values for bumping a version without any duplicated logic inside of changelog.

To maintain current formatting support in the output from changelog, the semver bump type is available from the npm_config_argvglobal (I.e. with npm version minor: npm_config_argv: '{"remain":["minor"],"cooked":["version","minor"],"original":["version","minor"]}').

Then the package.json could simply use one of npm's version scripts to have changelog create an output at the correct stage for the implementor. For instance to generate a change-log for the new bumped version and including it in the versioning commit:

"scripts": {
  /* ... */
  "version": "changelog && git add CHANGELOG.md"
}

Thoughts?

@JasonCust
Copy link
Contributor Author

JasonCust commented Jan 23, 2018

Bump. @robinjoseph08 If this is out of scope for your intention for this module just let me know.

@robinjoseph08
Copy link
Contributor

Hey @JasonCust, sorry for the delay here. Your explanation makes sense, and I think that would be a pretty cool feature to implement. Some considerations:

  • We should make sure that things still work if changelog is run outside of npm version. Ideally, this isn't a breaking change in any way.
  • Ideally, this would work with yarn as well, but I'm not sure if it exposes the same variables that npm does.

If you'd like to put up a PR, we'd welcome it!

@JasonCust
Copy link
Contributor Author

@robinjoseph08 I think I came up with a good solution to support npm version directly in a fairly generic manner. See PR #42.

@JasonCust
Copy link
Contributor Author

Bump. @robinjoseph08, let me know if this does or doesn't work for you.

@julianlam
Copy link

Am finding that I'd like to use generate-changelog to generate a changelog for a pre-release, and so this PR would be great to be merged 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants