]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/html/doc/misc/npm-scripts.html
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / html / doc / misc / npm-scripts.html
1 <!doctype html>
2 <html>
3   <title>npm-scripts</title>
4   <meta charset="utf-8">
5   <link rel="stylesheet" type="text/css" href="../../static/style.css">
6   <link rel="canonical" href="https://www.npmjs.org/doc/misc/npm-scripts.html">
7   <script async=true src="../../static/toc.js"></script>
8
9   <body>
10     <div id="wrapper">
11
12 <h1><a href="../misc/npm-scripts.html">npm-scripts</a></h1> <p>How npm handles the &quot;scripts&quot; field</p>
13 <h2 id="description">DESCRIPTION</h2>
14 <p>npm supports the &quot;scripts&quot; property of the package.json script, for the
15 following scripts:</p>
16 <ul>
17 <li>prepublish:
18 Run BEFORE the package is published.  (Also run on local <code>npm
19 install</code> without any arguments.)</li>
20 <li>publish, postpublish:
21 Run AFTER the package is published.</li>
22 <li>preinstall:
23 Run BEFORE the package is installed</li>
24 <li>install, postinstall:
25 Run AFTER the package is installed.</li>
26 <li>preuninstall, uninstall:
27 Run BEFORE the package is uninstalled.</li>
28 <li>postuninstall:
29 Run AFTER the package is uninstalled.</li>
30 <li>preversion, version:
31 Run BEFORE bumping the package version.</li>
32 <li>postversion:
33 Run AFTER bumping the package version.</li>
34 <li>pretest, test, posttest:
35 Run by the <code>npm test</code> command.</li>
36 <li>prestop, stop, poststop:
37 Run by the <code>npm stop</code> command.</li>
38 <li>prestart, start, poststart:
39 Run by the <code>npm start</code> command.</li>
40 <li>prerestart, restart, postrestart:
41 Run by the <code>npm restart</code> command. Note: <code>npm restart</code> will run the
42 stop and start scripts if no <code>restart</code> script is provided.</li>
43 </ul>
44 <p>Additionally, arbitrary scripts can be executed by running <code>npm
45 run-script &lt;stage&gt;</code>. <em>Pre</em> and <em>post</em> commands with matching
46 names will be run for those as well (e.g. <code>premyscript</code>, <code>myscript</code>,
47 <code>postmyscript</code>). Scripts from dependencies can be run with `npm explore</p>
48 <p><pkg> -- npm run <stage>`.</p>
49 <h2 id="common-uses">COMMON USES</h2>
50 <p>If you need to perform operations on your package before it is used, in a way
51 that is not dependent on the operating system or architecture of the
52 target system, use a <code>prepublish</code> script.  This includes
53 tasks such as:</p>
54 <ul>
55 <li>Compiling CoffeeScript source code into JavaScript.</li>
56 <li>Creating minified versions of JavaScript source code.</li>
57 <li>Fetching remote resources that your package will use.</li>
58 </ul>
59 <p>The advantage of doing these things at <code>prepublish</code> time is that they can be done once, in a
60 single place, thus reducing complexity and variability.
61 Additionally, this means that:</p>
62 <ul>
63 <li>You can depend on <code>coffee-script</code> as a <code>devDependency</code>, and thus
64 your users don&#39;t need to have it installed.</li>
65 <li>You don&#39;t need to include minifiers in your package, reducing
66 the size for your users.</li>
67 <li>You don&#39;t need to rely on your users having <code>curl</code> or <code>wget</code> or
68 other system tools on the target machines.</li>
69 </ul>
70 <h2 id="default-values">DEFAULT VALUES</h2>
71 <p>npm will default some script values based on package contents.</p>
72 <ul>
73 <li><p><code>&quot;start&quot;: &quot;node server.js&quot;</code>:</p>
74 <p>If there is a <code>server.js</code> file in the root of your package, then npm
75 will default the <code>start</code> command to <code>node server.js</code>.</p>
76 </li>
77 <li><p><code>&quot;install&quot;: &quot;node-gyp rebuild&quot;</code>:</p>
78 <p>If there is a <code>binding.gyp</code> file in the root of your package and you
79 haven&#39;t defined your own <code>install</code> or <code>preinstall</code> scripts, npm will
80 default the <code>install</code> command to compile using node-gyp.</p>
81 </li>
82 </ul>
83 <h2 id="user">USER</h2>
84 <p>If npm was invoked with root privileges, then it will change the uid
85 to the user account or uid specified by the <code>user</code> config, which
86 defaults to <code>nobody</code>.  Set the <code>unsafe-perm</code> flag to run scripts with
87 root privileges.</p>
88 <h2 id="environment">ENVIRONMENT</h2>
89 <p>Package scripts run in an environment where many pieces of information
90 are made available regarding the setup of npm and the current state of
91 the process.</p>
92 <h3 id="path">path</h3>
93 <p>If you depend on modules that define executable scripts, like test
94 suites, then those executables will be added to the <code>PATH</code> for
95 executing the scripts.  So, if your package.json has this:</p>
96 <pre><code>{ &quot;name&quot; : &quot;foo&quot;
97 , &quot;dependencies&quot; : { &quot;bar&quot; : &quot;0.1.x&quot; }
98 , &quot;scripts&quot;: { &quot;start&quot; : &quot;bar ./test&quot; } }
99 </code></pre><p>then you could run <code>npm start</code> to execute the <code>bar</code> script, which is
100 exported into the <code>node_modules/.bin</code> directory on <code>npm install</code>.</p>
101 <h3 id="package-json-vars">package.json vars</h3>
102 <p>The package.json fields are tacked onto the <code>npm_package_</code> prefix. So,
103 for instance, if you had <code>{&quot;name&quot;:&quot;foo&quot;, &quot;version&quot;:&quot;1.2.5&quot;}</code> in your
104 package.json file, then your package scripts would have the
105 <code>npm_package_name</code> environment variable set to &quot;foo&quot;, and the
106 <code>npm_package_version</code> set to &quot;1.2.5&quot;</p>
107 <h3 id="configuration">configuration</h3>
108 <p>Configuration parameters are put in the environment with the
109 <code>npm_config_</code> prefix. For instance, you can view the effective <code>root</code>
110 config by checking the <code>npm_config_root</code> environment variable.</p>
111 <h3 id="special-package-json-config-object">Special: package.json &quot;config&quot; object</h3>
112 <p>The package.json &quot;config&quot; keys are overwritten in the environment if
113 there is a config param of <code>&lt;name&gt;[@&lt;version&gt;]:&lt;key&gt;</code>.  For example,
114 if the package.json has this:</p>
115 <pre><code>{ &quot;name&quot; : &quot;foo&quot;
116 , &quot;config&quot; : { &quot;port&quot; : &quot;8080&quot; }
117 , &quot;scripts&quot; : { &quot;start&quot; : &quot;node server.js&quot; } }
118 </code></pre><p>and the server.js is this:</p>
119 <pre><code>http.createServer(...).listen(process.env.npm_package_config_port)
120 </code></pre><p>then the user could change the behavior by doing:</p>
121 <pre><code>npm config set foo:port 80
122 </code></pre><h3 id="current-lifecycle-event">current lifecycle event</h3>
123 <p>Lastly, the <code>npm_lifecycle_event</code> environment variable is set to
124 whichever stage of the cycle is being executed. So, you could have a
125 single script used for different parts of the process which switches
126 based on what&#39;s currently happening.</p>
127 <p>Objects are flattened following this format, so if you had
128 <code>{&quot;scripts&quot;:{&quot;install&quot;:&quot;foo.js&quot;}}</code> in your package.json, then you&#39;d
129 see this in the script:</p>
130 <pre><code>process.env.npm_package_scripts_install === &quot;foo.js&quot;
131 </code></pre><h2 id="examples">EXAMPLES</h2>
132 <p>For example, if your package.json contains this:</p>
133 <pre><code>{ &quot;scripts&quot; :
134   { &quot;install&quot; : &quot;scripts/install.js&quot;
135   , &quot;postinstall&quot; : &quot;scripts/install.js&quot;
136   , &quot;uninstall&quot; : &quot;scripts/uninstall.js&quot;
137   }
138 }
139 </code></pre><p>then <code>scripts/install.js</code> will be called for the install
140 and post-install stages of the lifecycle, and <code>scripts/uninstall.js</code>
141 will be called when the package is uninstalled.  Since
142 <code>scripts/install.js</code> is running for two different phases, it would
143 be wise in this case to look at the <code>npm_lifecycle_event</code> environment
144 variable.</p>
145 <p>If you want to run a make command, you can do so.  This works just
146 fine:</p>
147 <pre><code>{ &quot;scripts&quot; :
148   { &quot;preinstall&quot; : &quot;./configure&quot;
149   , &quot;install&quot; : &quot;make &amp;&amp; make install&quot;
150   , &quot;test&quot; : &quot;make test&quot;
151   }
152 }
153 </code></pre><h2 id="exiting">EXITING</h2>
154 <p>Scripts are run by passing the line as a script argument to <code>sh</code>.</p>
155 <p>If the script exits with a code other than 0, then this will abort the
156 process.</p>
157 <p>Note that these script files don&#39;t have to be nodejs or even
158 javascript programs. They just have to be some kind of executable
159 file.</p>
160 <h2 id="hook-scripts">HOOK SCRIPTS</h2>
161 <p>If you want to run a specific script at a specific lifecycle event for
162 ALL packages, then you can use a hook script.</p>
163 <p>Place an executable file at <code>node_modules/.hooks/{eventname}</code>, and
164 it&#39;ll get run for all packages when they are going through that point
165 in the package lifecycle for any packages installed in that root.</p>
166 <p>Hook scripts are run exactly the same way as package.json scripts.
167 That is, they are in a separate child process, with the env described
168 above.</p>
169 <h2 id="best-practices">BEST PRACTICES</h2>
170 <ul>
171 <li>Don&#39;t exit with a non-zero error code unless you <em>really</em> mean it.
172 Except for uninstall scripts, this will cause the npm action to
173 fail, and potentially be rolled back.  If the failure is minor or
174 only will prevent some optional features, then it&#39;s better to just
175 print a warning and exit successfully.</li>
176 <li>Try not to use scripts to do what npm can do for you.  Read through
177 <code><a href="../files/package.json.html">package.json(5)</a></code> to see all the things that you can specify and enable
178 by simply describing your package appropriately.  In general, this
179 will lead to a more robust and consistent state.</li>
180 <li>Inspect the env to determine where to put things.  For instance, if
181 the <code>npm_config_binroot</code> environment variable is set to <code>/home/user/bin</code>, then
182 don&#39;t try to install executables into <code>/usr/local/bin</code>.  The user
183 probably set it up that way for a reason.</li>
184 <li>Don&#39;t prefix your script commands with &quot;sudo&quot;.  If root permissions
185 are required for some reason, then it&#39;ll fail with that error, and
186 the user will sudo the npm command in question.</li>
187 <li>Don&#39;t use <code>install</code>. Use a <code>.gyp</code> file for compilation, and <code>prepublish</code>
188 for anything else. You should almost never have to explicitly set a
189 preinstall or install script. If you are doing this, please consider if
190 there is another option. The only valid use of <code>install</code> or <code>preinstall</code>
191 scripts is for compilation which must be done on the target architecture.</li>
192 </ul>
193 <h2 id="see-also">SEE ALSO</h2>
194 <ul>
195 <li><a href="../cli/npm-run-script.html">npm-run-script(1)</a></li>
196 <li><a href="../files/package.json.html">package.json(5)</a></li>
197 <li><a href="../misc/npm-developers.html">npm-developers(7)</a></li>
198 <li><a href="../cli/npm-install.html">npm-install(1)</a></li>
199 </ul>
200
201 </div>
202
203 <table border=0 cellspacing=0 cellpadding=0 id=npmlogo>
204 <tr><td style="width:180px;height:10px;background:rgb(237,127,127)" colspan=18>&nbsp;</td></tr>
205 <tr><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td colspan=6 style="width:60px;height:10px;background:#fff">&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td></tr>
206 <tr><td colspan=2 style="width:20px;height:30px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=4 colspan=2>&nbsp;</td><td style="width:10px;height:20px;background:rgb(237,127,127)" rowspan=2>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=3 colspan=2>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td></tr>
207 <tr><td style="width:10px;height:10px;background:#fff" rowspan=2>&nbsp;</td></tr>
208 <tr><td style="width:10px;height:10px;background:#fff">&nbsp;</td></tr>
209 <tr><td style="width:60px;height:10px;background:rgb(237,127,127)" colspan=6>&nbsp;</td><td colspan=10 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td></tr>
210 <tr><td colspan=5 style="width:50px;height:10px;background:#fff">&nbsp;</td><td style="width:40px;height:10px;background:rgb(237,127,127)" colspan=4>&nbsp;</td><td style="width:90px;height:10px;background:#fff" colspan=9>&nbsp;</td></tr>
211 </table>
212 <p id="footer">npm-scripts &mdash; npm@2.15.11</p>
213