GitHub

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

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.

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

Read the original on github.com ↗