Skip to content

Instantly share code, notes, and snippets.

@nmccready
Created June 26, 2020 16:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nmccready/9b90d52737d4c89514ae12f282bd2101 to your computer and use it in GitHub Desktop.
Save nmccready/9b90d52737d4c89514ae12f282bd2101 to your computer and use it in GitHub Desktop.
npm version described

npm version

read https://docs.npmjs.com/cli/version it's very straight forward.

Everything in npm config cli is available to be set in .npmrc like preid.

IE this allows your to define your prerelease identifier. By default npm follows this format.

MAJOR.MINOR.PATCH-PRE

Example Minor Workflow

Let say we start at 0.0.1.

  1. We want to publish a pre / alpha release of a upcoming minor release.

    • npm version preminor

      This will bump the package.json and git tag the repo in one atomic step at 0.1.0-0

  2. Lets say we found another bug in our preminor, well then we make the fix and cut a new release

    • npm version prerelease (you always use prerelease to stay within current semver context)

      now we're at 0.1.0-1

  3. Finally ready for a stable release

    • npm version minor at 0.1.0

Full Blown chart for explicitness

Without any .npmrc mods to local repo

scenario command package.json version git tag
new minor pre npm version preminor 0.1.0-0 v0.1.0-0
new minor pre (staying in current pre) npm version prerelease 0.1.0-1 v0.1.0-1
stable minor ready npm version minor 0.1.0 v0.1.0
new pre patch npm version prepatch 0.1.1-0 v0.1.1-0
skip ahead to next pre patch (some odd reason as this is rare) npm version prepatch 0.1.2-0 v0.1.2-0
another pre patch fix npm version prerelease 0.1.2-1 v0.1.2-1
release patch npm version patch 0.1.2 v0.1.2
almost ready for a major release npm version premajor 1.0.0-0 v1.0.0-0
major release npm version major 1.0.0 v1.0.0

With .npmrc mods to local repo

./.npmrc

tag-version-prefix=""
preid=alpha
scenario command package.json version git tag
new minor pre npm version preminor 0.1.0-0 0.1.0-alpha.0
new minor pre (staying in current pre) npm version prerelease 0.1.0-1 0.1.0-alpha.1
stable minor ready npm version minor 0.1.0 0.1.0
new pre patch npm version prepatch 0.1.1-0 0.1.1-alpha.0
skip ahead to next pre patch (some odd reason as this is rare) npm version prepatch 0.1.2-0 0.1.2-alpha.0
another pre patch fix npm version prerelease 0.1.2-1 0.1.2-alpha.1
release patch npm version patch 0.1.2 0.1.2
almost ready for a major release npm version premajor 1.0.0-0 1.0.0-alpha.0
major release npm version major 1.0.0 1.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment