@@ -141,7 +141,7 @@ <h1 id="scripts">scripts</h1>
141
141
142
142
< section id ="table_of_contents ">
143
143
< h2 id ="table-of-contents "> Table of contents</ h2 >
144
- < div id ="_table_of_contents "> < ul > < li > < a href ="#description "> Description</ a > </ li > < li > < a href ="#pre--post-scripts "> Pre & Post Scripts</ a > </ li > < li > < a href ="#life-cycle-scripts "> Life Cycle Scripts</ a > </ li > < ul > < li > < a href ="#prepare-and-prepublish "> Prepare and Prepublish</ a > </ li > </ ul > < li > < a href ="#life-cycle-operation-order "> Life Cycle Operation Order</ a > </ li > < ul > < li > < a href ="#npm-cache-add "> < a href ="../commands/npm-cache.html "> < code > npm cache add</ code > </ a > </ a > </ li > < li > < a href ="#npm-ci "> < a href ="../commands/npm-ci.html "> < code > npm ci</ code > </ a > </ a > </ li > < li > < a href ="#npm-diff "> < a href ="../commands/npm-diff.html "> < code > npm diff</ code > </ a > </ a > </ li > < li > < a href ="#npm-install "> < a href ="../commands/npm-install.html "> < code > npm install</ code > </ a > </ a > </ li > < li > < a href ="#npm-pack "> < a href ="../commands/npm-pack.html "> < code > npm pack</ code > </ a > </ a > </ li > < li > < a href ="#npm-publish "> < a href ="../commands/npm-publish.html "> < code > npm publish</ code > </ a > </ a > </ li > < li > < a href ="#npm-rebuild "> < a href ="../commands/npm-rebuild.html "> < code > npm rebuild</ code > </ a > </ a > </ li > < li > < a href ="#npm-restart "> < a href ="../commands/npm-restart.html "> < code > npm restart</ code > </ a > </ a > </ li > < li > < a href ="#npm-run-user-defined "> < a href ="../commands/npm-run-script.html "> < code > npm run <user defined></ code > </ a > </ a > </ li > < li > < a href ="#npm-start "> < a href ="../commands/npm-start.html "> < code > npm start</ code > </ a > </ a > </ li > < li > < a href ="#npm-stop "> < a href ="../commands/npm-stop.html "> < code > npm stop</ code > </ a > </ a > </ li > < li > < a href ="#npm-test "> < a href ="../commands/npm-test.html "> < code > npm test</ code > </ a > </ a > </ li > </ ul > < li > < a href ="#user "> User</ a > </ li > < li > < a href ="#environment "> Environment</ a > </ li > < ul > < li > < a href ="#path "> path</ a > </ li > < li > < a href ="#packagejson-vars "> package.json vars</ a > </ li > < li > < a href ="#configuration "> configuration</ a > </ li > < li > < a href ="#special-packagejson-config-object "> Special: package.json “config” object</ a > </ li > < li > < a href ="#current-lifecycle-event "> current lifecycle event</ a > </ li > </ ul > < li > < a href ="#examples "> Examples</ a > </ li > < li > < a href ="#exiting "> Exiting</ a > </ li > < li > < a href ="#hook-scripts "> Hook Scripts</ a > </ li > < li > < a href ="#best-practices "> Best Practices</ a > </ li > < li > < a href ="#see-also "> See Also</ a > </ li > </ ul > </ div >
144
+ < div id ="_table_of_contents "> < ul > < li > < a href ="#description "> Description</ a > </ li > < li > < a href ="#pre--post-scripts "> Pre & Post Scripts</ a > </ li > < li > < a href ="#life-cycle-scripts "> Life Cycle Scripts</ a > </ li > < ul > < li > < a href ="#prepare-and-prepublish "> Prepare and Prepublish</ a > </ li > </ ul > < li > < a href ="#life-cycle-operation-order "> Life Cycle Operation Order</ a > </ li > < ul > < li > < a href ="#npm-cache-add "> < a href ="../commands/npm-cache.html "> < code > npm cache add</ code > </ a > </ a > </ li > < li > < a href ="#npm-ci "> < a href ="../commands/npm-ci.html "> < code > npm ci</ code > </ a > </ a > </ li > < li > < a href ="#npm-diff "> < a href ="../commands/npm-diff.html "> < code > npm diff</ code > </ a > </ a > </ li > < li > < a href ="#npm-install "> < a href ="../commands/npm-install.html "> < code > npm install</ code > </ a > </ a > </ li > < li > < a href ="#npm-pack "> < a href ="../commands/npm-pack.html "> < code > npm pack</ code > </ a > </ a > </ li > < li > < a href ="#npm-publish "> < a href ="../commands/npm-publish.html "> < code > npm publish</ code > </ a > </ a > </ li > < li > < a href ="#npm-rebuild "> < a href ="../commands/npm-rebuild.html "> < code > npm rebuild</ code > </ a > </ a > </ li > < li > < a href ="#npm-restart "> < a href ="../commands/npm-restart.html "> < code > npm restart</ code > </ a > </ a > </ li > < li > < a href ="#npm-run-user-defined "> < a href ="../commands/npm-run-script.html "> < code > npm run <user defined></ code > </ a > </ a > </ li > < li > < a href ="#npm-start "> < a href ="../commands/npm-start.html "> < code > npm start</ code > </ a > </ a > </ li > < li > < a href ="#npm-stop "> < a href ="../commands/npm-stop.html "> < code > npm stop</ code > </ a > </ a > </ li > < li > < a href ="#npm-test "> < a href ="../commands/npm-test.html "> < code > npm test</ code > </ a > </ a > </ li > </ ul > < li > < a href ="#user "> User</ a > </ li > < li > < a href ="#environment "> Environment</ a > </ li > < ul > < li > < a href ="#path "> path</ a > </ li > < li > < a href ="#packagejson-vars "> package.json vars</ a > </ li > < li > < a href ="#current-lifecycle-event "> current lifecycle event</ a > </ li > </ ul > < li > < a href ="#examples "> Examples</ a > </ li > < li > < a href ="#exiting "> Exiting</ a > </ li > < li > < a href ="#best-practices "> Best Practices</ a > </ li > < li > < a href ="#see-also "> See Also</ a > </ li > </ ul > </ div >
145
145
</ section >
146
146
147
147
< div id ="_content "> < h3 id ="description "> Description</ h3 >
@@ -367,30 +367,7 @@ <h4 id="packagejson-vars">package.json vars</h4>
367
367
< code > npm_package_version</ code > set to “1.2.5”. You can access these variables
368
368
in your code with < code > process.env.npm_package_name</ code > and
369
369
< code > process.env.npm_package_version</ code > , and so on for other fields.</ p >
370
- < h4 id ="configuration "> configuration</ h4 >
371
- < p > Configuration parameters are put in the environment with the
372
- < code > npm_config_</ code > prefix. For instance, you can view the effective < code > root</ code >
373
- config by checking the < code > npm_config_root</ code > environment variable.</ p >
374
- < h4 id ="special-packagejson-config-object "> Special: package.json “config” object</ h4 >
375
- < p > The package.json “config” keys are overwritten in the environment if
376
- there is a config param of < code > <name>[@<version>]:<key></ code > . For example,
377
- if the package.json has this:</ p >
378
- < pre lang ="json "> < code > {
379
- "name" : "foo",
380
- "config" : {
381
- "port" : "8080"
382
- },
383
- "scripts" : {
384
- "start" : "node server.js"
385
- }
386
- }
387
- </ code > </ pre >
388
- < p > and the server.js is this:</ p >
389
- < pre lang ="javascript "> < code > http.createServer(...).listen(process.env.npm_package_config_port)
390
- </ code > </ pre >
391
- < p > then the user could change the behavior by doing:</ p >
392
- < pre lang ="bash "> < code > npm config set foo:port 80
393
- </ code > </ pre >
370
+ < p > See < a href ="../using-npm/package-json.html "> < code > package-json.md</ code > </ a > for more on package configs.</ p >
394
371
< h4 id ="current-lifecycle-event "> current lifecycle event</ h4 >
395
372
< p > Lastly, the < code > npm_lifecycle_event</ code > environment variable is set to
396
373
whichever stage of the cycle is being executed. So, you could have a
@@ -434,15 +411,6 @@ <h3 id="exiting">Exiting</h3>
434
411
< p > Note that these script files don’t have to be nodejs or even
435
412
javascript programs. They just have to be some kind of executable
436
413
file.</ p >
437
- < h3 id ="hook-scripts "> Hook Scripts</ h3 >
438
- < p > If you want to run a specific script at a specific lifecycle event for
439
- ALL packages, then you can use a hook script.</ p >
440
- < p > Place an executable file at < code > node_modules/.hooks/{eventname}</ code > , and
441
- it’ll get run for all packages when they are going through that point
442
- in the package lifecycle for any packages installed in that root.</ p >
443
- < p > Hook scripts are run exactly the same way as package.json scripts.
444
- That is, they are in a separate child process, with the env described
445
- above.</ p >
446
414
< h3 id ="best-practices "> Best Practices</ h3 >
447
415
< ul >
448
416
< li > Don’t exit with a non-zero error code unless you < em > really</ em > mean it.
0 commit comments