Skip to content
This repository was archived by the owner on Aug 18, 2024. It is now read-only.

Commit 39ca0c0

Browse files
committed
docs: document usage
1 parent d96ec3a commit 39ca0c0

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
# allow-scripts
22

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+
49
```
5-
"allowScripts": {
6-
"fsevents": "*", # allow install scripts in all versions
7-
"node-sass": false # ignore install scripts
8-
}
10+
$ npx allow-scripts [--dry-run]
911
```
1012

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`:
1234
```
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+
}
1540
```

0 commit comments

Comments
 (0)