diff --git a/docs/lib/content/commands/npm-version.md b/docs/lib/content/commands/npm-version.md index 23ce28763f6cd..cca8106a00831 100644 --- a/docs/lib/content/commands/npm-version.md +++ b/docs/lib/content/commands/npm-version.md @@ -69,6 +69,8 @@ The exact order of execution is as follows: 6. Run the `postversion` script. Use it to clean up the file system or automatically push the commit and/or tag. +For the `preversion`, `version` and `postversion` scripts, npm also sets the [environment variables](/using-npm/scripts#environment) `npm_old_version` and `npm_new_version`. + Take the following example: ```json diff --git a/docs/lib/content/using-npm/scripts.md b/docs/lib/content/using-npm/scripts.md index 380c4aa49e36f..b01c0bc7ffd77 100644 --- a/docs/lib/content/using-npm/scripts.md +++ b/docs/lib/content/using-npm/scripts.md @@ -290,6 +290,13 @@ For example, if you had `{"name":"foo", "version":"1.2.5"}` in your package.json See [`package.json`](/configuring-npm/package-json) for more on package configs. +#### versioning variables + +For versioning scripts (`preversion`, `version`, `postversion`), npm sets these environment variables: + +* `npm_old_version` - The version before being bumped +* `npm_new_version` – The version after being bumped + #### current lifecycle event Lastly, the `npm_lifecycle_event` environment variable is set to whichever stage of the cycle is being executed. diff --git a/workspaces/libnpmversion/README.md b/workspaces/libnpmversion/README.md index 3a91bb471ba56..8f3f89e453a9b 100644 --- a/workspaces/libnpmversion/README.md +++ b/workspaces/libnpmversion/README.md @@ -85,6 +85,9 @@ The exact order of execution is as follows: 6. Run the `postversion` script. Use it to clean up the file system or automatically push the commit and/or tag. +For the `preversion`, `version` and `postversion` scripts, npm also sets the +environment variables `npm_old_version` and `npm_new_version`. + Take the following example: ```json