Skip to content

Commit 7f2ab9d

Browse files
Max Blackowlstronaut
authored andcommitted
docs(scripts): replace deprecated prepublish and install examples with prepare
- Updated examples section to use prepare and test scripts instead of discouraged install/postinstall - Changed use case recommendations from prepublish to prepare - Replaced CoffeeScript example with TypeScript (more current) - Replaced make commands with modern build tools (tsc, jest) - Fixes #3992
1 parent 7896e51 commit 7f2ab9d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ See <https://github.com/npm/npm/issues/10074> for a much lengthier justification
8484

8585
**Use Cases**
8686

87-
If you need to perform operations on your package before it is used, in a way that is not dependent on the operating system or architecture of the target system, use a `prepublish` script.
87+
Use a `prepare` script to perform build tasks that are platform-independent and need to run before your package is used.
8888
This includes tasks such as:
8989

90-
* Compiling CoffeeScript source code into JavaScript.
90+
* Compiling TypeScript or other source code into JavaScript.
9191
* Creating minified versions of JavaScript source code.
9292
* Fetching remote resources that your package will use.
9393

94-
The advantage of doing these things at `prepublish` time is that they can be done once, in a single place, thus reducing complexity and variability.
94+
Running these build tasks in the `prepare` script ensures they happen once, in a single place, reducing complexity and variability.
9595
Additionally, this means that:
9696

97-
* You can depend on `coffee-script` as a `devDependency`, and thus your users don't need to have it installed.
97+
* You can depend on build tools as `devDependencies`, and thus your users don't need to have them installed.
9898
* You don't need to include minifiers in your package, reducing the size for your users.
9999
* You don't need to rely on your users having `curl` or `wget` or other system tools on the target machines.
100100

@@ -313,25 +313,24 @@ For example, if your package.json contains this:
313313
```json
314314
{
315315
"scripts" : {
316-
"install" : "scripts/install.js",
317-
"postinstall" : "scripts/install.js"
316+
"prepare" : "scripts/build.js",
317+
"test" : "scripts/test.js"
318318
}
319319
}
320320
```
321321

322-
then `scripts/install.js` will be called for the install and post-install stages of the lifecycle.
323-
Since `scripts/install.js` is running for two different phases, it would be wise in this case to look at the
324-
`npm_lifecycle_event` environment variable.
322+
then `scripts/build.js` will be called for the prepare stage of the lifecycle, and you can check the
323+
`npm_lifecycle_event` environment variable if your script needs to behave differently in different contexts.
325324

326-
If you want to run a make command, you can do so.
325+
If you want to run build commands, you can do so.
327326
This works just fine:
328327

329328
```json
330329
{
331330
"scripts" : {
332-
"preinstall" : "./configure",
333-
"install" : "make && make install",
334-
"test" : "make test"
331+
"prepare" : "npm run build",
332+
"build" : "tsc",
333+
"test" : "jest"
335334
}
336335
}
337336
```

0 commit comments

Comments
 (0)