|
1 | 1 | # allow-scripts
|
2 | 2 |
|
3 |
| -In `package.json`: |
| 3 | +Execute allowed `npm install` lifecycle scripts. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +Run your `npm install` with `--ignore-scripts` (or add `ignore-scripts=true` in your `.npmrc`), then: |
| 8 | + |
4 | 9 | ```
|
5 |
| - "allowScripts": { |
6 |
| - "fsevents": "*", # allow install scripts in all versions |
7 |
| - "node-sass": false # ignore install scripts |
8 |
| - } |
| 10 | +$ npx allow-scripts [--dry-run] |
9 | 11 | ```
|
10 | 12 |
|
11 |
| -Then: |
| 13 | +Running the command will scan the list of installed dependencies (from the first source available: `npm-shrinkwrap.json`, `package-lock.json`, `npm ls --json`). It will then execute the scripts for allowed dependencies that have them in the following order: |
| 14 | + |
| 15 | +- `preinstall` in the main package |
| 16 | +- `preinstall` in dependencies |
| 17 | +- `install` in dependencies |
| 18 | +- `postinstall` in dependencies |
| 19 | +- `install` in the main package |
| 20 | +- `postinstall` in the main package |
| 21 | +- `prepublish` in the main package |
| 22 | +- `prepare` in the main package |
| 23 | + |
| 24 | +Allowed package list is configurable in `package.json` by adding an `allowedScripts` property, with an object where the key is a package name and the value is one of: |
| 25 | + |
| 26 | +* a string with a semver specifier for allowed versions |
| 27 | + - non-matching versions will be ignored |
| 28 | +* `true` - allow all versions (equivalent to `'*'` semver specifier) |
| 29 | +* `false` - ignore all versions |
| 30 | + |
| 31 | +If a package has a lifecycle script, but is neither allowed nor ignored, `allow-scripts` will exit with an error. |
| 32 | + |
| 33 | +Example for `package.json`: |
12 | 34 | ```
|
13 |
| -$ npm install --ignore-scripts |
14 |
| -$ npx allow-scripts |
| 35 | + "allowScripts": { |
| 36 | + "fsevents": "*", # allow install scripts in all versions |
| 37 | + "node-sass": false, # ignore install scripts for all versions |
| 38 | + "webpack-cli": "3.x.x" # allow all minors for v3, ignore everything else |
| 39 | + } |
15 | 40 | ```
|
0 commit comments