Skip to content

Commit c5e9d73

Browse files
docs: Document npm_old_version and npm_new_version environment variables (#9389)
Backport of #9385 to `release/v11`. Co-authored-by: Oliver Byford <oliver.byford@digital.cabinet-office.gov.uk>
1 parent dba4863 commit c5e9d73

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

docs/lib/content/commands/npm-version.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ The exact order of execution is as follows:
7070
6. Run the `postversion` script.
7171
Use it to clean up the file system or automatically push the commit and/or tag.
7272

73+
For the `preversion`, `version` and `postversion` scripts, npm also sets the [environment variables](/using-npm/scripts#environment) `npm_old_version` and `npm_new_version`.
74+
7375
Take the following example:
7476

7577
```json

docs/lib/content/using-npm/scripts.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ For example, if you had `{"name":"foo", "version":"1.2.5"}` in your package.json
290290

291291
See [`package.json`](/configuring-npm/package-json) for more on package configs.
292292

293+
#### versioning variables
294+
295+
For versioning scripts (`preversion`, `version`, `postversion`), npm sets these environment variables:
296+
297+
* `npm_old_version` - The version before being bumped
298+
* `npm_new_version` – The version after being bumped
299+
293300
#### current lifecycle event
294301

295302
Lastly, the `npm_lifecycle_event` environment variable is set to whichever stage of the cycle is being executed.

workspaces/libnpmversion/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ The exact order of execution is as follows:
8686
6. Run the `postversion` script. Use it to clean up the file system or
8787
automatically push the commit and/or tag.
8888

89+
For the `preversion`, `version` and `postversion` scripts, npm also sets the
90+
environment variables `npm_old_version` and `npm_new_version`.
91+
8992
Take the following example:
9093

9194
```json

0 commit comments

Comments
 (0)