codekingpro/portable-devtools
114k
1<!DOCTYPE html><html><head>
2<meta charset="utf-8">
3<title>npm-run</title>
4<style>
5body {
6 background-color: #ffffff;
7 color: #24292e;
8
9 margin: 0;
10
11 line-height: 1.5;
12
13 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
14}
15#rainbar {
16 height: 10px;
17 background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
18}
19
20a {
21 text-decoration: none;
22 color: #0366d6;
23}
24a:hover {
25 text-decoration: underline;
26}
27
28pre {
29 margin: 1em 0px;
30 padding: 1em;
31 border: solid 1px #e1e4e8;
32 border-radius: 6px;
33
34 display: block;
35 overflow: auto;
36
37 white-space: pre;
38
39 background-color: #f6f8fa;
40 color: #393a34;
41}
42code {
43 font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
44 font-size: 85%;
45 padding: 0.2em 0.4em;
46 background-color: #f6f8fa;
47 color: #393a34;
48}
49pre > code {
50 padding: 0;
51 background-color: inherit;
52 color: inherit;
53}
54h1, h2, h3 {
55 font-weight: 600;
56}
57
58#logobar {
59 background-color: #333333;
60 margin: 0 auto;
61 padding: 1em 4em;
62}
63#logobar .logo {
64 float: left;
65}
66#logobar .title {
67 font-weight: 600;
68 color: #dddddd;
69 float: left;
70 margin: 5px 0 0 1em;
71}
72#logobar:after {
73 content: "";
74 display: block;
75 clear: both;
76}
77
78#content {
79 margin: 0 auto;
80 padding: 0 4em;
81}
82
83#table_of_contents > h2 {
84 font-size: 1.17em;
85}
86#table_of_contents ul:first-child {
87 border: solid 1px #e1e4e8;
88 border-radius: 6px;
89 padding: 1em;
90 background-color: #f6f8fa;
91 color: #393a34;
92}
93#table_of_contents ul {
94 list-style-type: none;
95 padding-left: 1.5em;
96}
97#table_of_contents li {
98 font-size: 0.9em;
99}
100#table_of_contents li a {
101 color: #000000;
102}
103
104header.title {
105 border-bottom: solid 1px #e1e4e8;
106}
107header.title > h1 {
108 margin-bottom: 0.25em;
109}
110header.title > .description {
111 display: block;
112 margin-bottom: 0.5em;
113 line-height: 1;
114}
115
116header.title .version {
117 font-size: 0.8em;
118 color: #666666;
119}
120
121footer#edit {
122 border-top: solid 1px #e1e4e8;
123 margin: 3em 0 4em 0;
124 padding-top: 2em;
125}
126
127table {
128 width: 100%;
129 margin: 1em 0;
130 border-radius: 6px;
131 border: 1px solid #e1e4e8;
132 overflow: hidden;
133 border-collapse: separate;
134 border-spacing: 0;
135}
136
137table thead {
138 background-color: #f6f8fa;
139}
140
141table tbody {
142 background-color: #ffffff;
143}
144
145table th,
146table td {
147 padding: 0.75em;
148 text-align: left;
149 border-right: 1px solid #e1e4e8;
150 border-bottom: 1px solid #e1e4e8;
151}
152
153table th:last-child,
154table td:last-child {
155 border-right: none;
156}
157
158table tbody tr:last-child td {
159 border-bottom: none;
160}
161
162table th {
163 font-weight: 600;
164 background-color: #f6f8fa;
165}
166
167table code {
168 white-space: nowrap;
169}
170
171</style>
172</head>
173<body>
174<div id="banner">
175<div id="rainbar"></div>
176<div id="logobar">
177<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
178<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
179<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
180</svg>
181<div class="title">
182npm command-line interface
183</div>
184</div>
185</div>
186
187<section id="content">
188<header class="title">
189<h1 id="----npm-run----11121">
190 <span>npm-run</span>
191 <span class="version">@11.12.1</span>
192</h1>
193<span class="description">Run arbitrary package scripts</span>
194</header>
195
196<section id="table_of_contents">
197<h2 id="table-of-contents">Table of contents</h2>
198<div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#workspaces-support">Workspaces support</a></li><ul><li><a href="#filtering-workspaces">Filtering workspaces</a></li></ul><li><a href="#configuration">Configuration</a></li><ul><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li><li><a href="#if-present"><code>if-present</code></a></li><li><a href="#ignore-scripts"><code>ignore-scripts</code></a></li><li><a href="#foreground-scripts"><code>foreground-scripts</code></a></li><li><a href="#script-shell"><code>script-shell</code></a></li></ul><li><a href="#see-also">See Also</a></li></ul></div>
199</section>
200
201<div id="_content"><h3 id="synopsis">Synopsis</h3>
202<pre><code class="language-bash">npm run <command> [-- <args>]
203
204aliases: run-script, rum, urn
205</code></pre>
206<h3 id="description">Description</h3>
207<p>This runs an arbitrary command from a package's <code>"scripts"</code> object.
208If no
209<code>"command"</code> is provided, it will list the available scripts.</p>
210<p><code>run[-script]</code> is used by the test, start, restart, and stop commands, but can be called directly, as well.
211When the scripts in the package are printed out, they're separated into lifecycle (test, start, restart) and directly-run scripts.</p>
212<p>Any positional arguments are passed to the specified script.
213Use <code>--</code> to pass <code>-</code>-prefixed flags and options which would otherwise be parsed by npm.</p>
214<p>For example:</p>
215<pre><code class="language-bash">npm run test -- --grep="pattern"
216</code></pre>
217<p>The arguments will only be passed to the script specified after <code>npm run</code> and not to any <code>pre</code> or <code>post</code> script.</p>
218<p>The <code>env</code> script is a special built-in command that can be used to list environment variables that will be available to the script at runtime.
219If an "env" command is defined in your package, it will take precedence over the built-in.</p>
220<p>In addition to the shell's pre-existing <code>PATH</code>, <code>npm run</code> adds <code>node_modules/.bin</code> to the <code>PATH</code> provided to scripts.
221Any binaries provided by locally-installed dependencies can be used without the <code>node_modules/.bin</code> prefix.
222For example, if there is a <code>devDependency</code> on <code>tap</code> in your package, you should write:</p>
223<pre><code class="language-bash">"scripts": {"test": "tap test/*.js"}
224</code></pre>
225<p>instead of</p>
226<pre><code class="language-bash">"scripts": {"test": "node_modules/.bin/tap test/*.js"}
227</code></pre>
228<p>The actual shell your script is run within is platform dependent.
229By default, on Unix-like systems it is the <code>/bin/sh</code> command, on Windows it is <code>cmd.exe</code>.
230The actual shell referred to by <code>/bin/sh</code> also depends on the system.
231You can customize the shell with the <a href="../using-npm/config#script-shell.html"><code>script-shell</code> config</a>.</p>
232<p>Scripts are run from the root of the package folder, regardless of what the current working directory is when <code>npm run</code> is called.
233If you want your script to use different behavior based on what subdirectory you're in, you can use the <code>INIT_CWD</code> environment variable, which holds the full path you were in when you ran <code>npm run</code>.</p>
234<p><code>npm run</code> sets the <code>NODE</code> environment variable to the <code>node</code> executable with which <code>npm</code> is executed.</p>
235<p>If you try to run a script without having a <code>node_modules</code> directory and it fails, you will be given a warning to run <code>npm install</code>, just in case you've forgotten.</p>
236<h3 id="workspaces-support">Workspaces support</h3>
237<p>You may use the <a href="../using-npm/config#workspace.html"><code>workspace</code></a> or <a href="../using-npm/config#workspaces.html"><code>workspaces</code></a> configs in order to run an arbitrary command from a package's <code>"scripts"</code> object in the context of the specified workspaces.
238If no <code>"command"</code> is provided, it will list the available scripts for each of these configured workspaces.</p>
239<p>Given a project with configured workspaces, e.g:</p>
240<pre><code>.
241+-- package.json
242`-- packages
243 +-- a
244 | `-- package.json
245 +-- b
246 | `-- package.json
247 `-- c
248 `-- package.json
249</code></pre>
250<p>Assuming the workspace configuration is properly set up at the root level <code>package.json</code> file.
251e.g:</p>
252<pre><code>{
253 "workspaces": [ "./packages/*" ]
254}
255</code></pre>
256<p>And that each of the configured workspaces has a configured <code>test</code> script, we can run tests in all of them using the <a href="../using-npm/config#workspaces.html"><code>workspaces</code> config</a>:</p>
257<pre><code>npm test --workspaces
258</code></pre>
259<h4 id="filtering-workspaces">Filtering workspaces</h4>
260<p>It's also possible to run a script in a single workspace using the <code>workspace</code> config along with a name or directory path:</p>
261<pre><code>npm test --workspace=a
262</code></pre>
263<p>The <code>workspace</code> config can also be specified multiple times in order to run a specific script in the context of multiple workspaces.
264When defining values for the <code>workspace</code> config in the command line, it also possible to use <code>-w</code> as a shorthand, e.g:</p>
265<pre><code>npm test -w a -w b
266</code></pre>
267<p>This last command will run <code>test</code> in both <code>./packages/a</code> and <code>./packages/b</code> packages.</p>
268<h3 id="configuration">Configuration</h3>
269<h4 id="workspace"><code>workspace</code></h4>
270<ul>
271<li>Default:</li>
272<li>Type: String (can be set multiple times)</li>
273</ul>
274<p>Enable running a command in the context of the configured workspaces of the
275current project while filtering by running only the workspaces defined by
276this configuration option.</p>
277<p>Valid values for the <code>workspace</code> config are either:</p>
278<ul>
279<li>Workspace names</li>
280<li>Path to a workspace directory</li>
281<li>Path to a parent workspace directory (will result in selecting all
282workspaces within that folder)</li>
283</ul>
284<p>When set for the <code>npm init</code> command, this may be set to the folder of a
285workspace which does not yet exist, to create the folder and set it up as a
286brand new workspace within the project.</p>
287<p>This value is not exported to the environment for child processes.</p>
288<h4 id="workspaces"><code>workspaces</code></h4>
289<ul>
290<li>Default: null</li>
291<li>Type: null or Boolean</li>
292</ul>
293<p>Set to true to run the command in the context of <strong>all</strong> configured
294workspaces.</p>
295<p>Explicitly setting this to false will cause commands like <code>install</code> to
296ignore workspaces altogether. When not set explicitly:</p>
297<ul>
298<li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
299will link workspaces into the <code>node_modules</code> folder. - Commands that do
300other things (test, exec, publish, etc.) will operate on the root project,
301<em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
302</ul>
303<p>This value is not exported to the environment for child processes.</p>
304<h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
305<ul>
306<li>Default: false</li>
307<li>Type: Boolean</li>
308</ul>
309<p>Include the workspace root when workspaces are enabled for a command.</p>
310<p>When false, specifying individual workspaces via the <code>workspace</code> config, or
311all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
312the specified workspaces, and not on the root project.</p>
313<p>This value is not exported to the environment for child processes.</p>
314<h4 id="if-present"><code>if-present</code></h4>
315<ul>
316<li>Default: false</li>
317<li>Type: Boolean</li>
318</ul>
319<p>If true, npm will not exit with an error code when <code>run</code> is invoked for a
320script that isn't defined in the <code>scripts</code> section of <code>package.json</code>. This
321option can be used when it's desirable to optionally run a script when it's
322present and fail if the script fails. This is useful, for example, when
323running scripts that may only apply for some builds in an otherwise generic
324CI setup.</p>
325<p>This value is not exported to the environment for child processes.</p>
326<h4 id="ignore-scripts"><code>ignore-scripts</code></h4>
327<ul>
328<li>Default: false</li>
329<li>Type: Boolean</li>
330</ul>
331<p>If true, npm does not run scripts specified in package.json files.</p>
332<p>Note that commands explicitly intended to run a particular script, such as
333<code>npm start</code>, <code>npm stop</code>, <code>npm restart</code>, <code>npm test</code>, and <code>npm run</code> will still
334run their intended script if <code>ignore-scripts</code> is set, but they will <em>not</em>
335run any pre- or post-scripts.</p>
336<h4 id="foreground-scripts"><code>foreground-scripts</code></h4>
337<ul>
338<li>Default: <code>false</code> unless when using <code>npm pack</code> or <code>npm publish</code> where it
339defaults to <code>true</code></li>
340<li>Type: Boolean</li>
341</ul>
342<p>Run all build scripts (ie, <code>preinstall</code>, <code>install</code>, and <code>postinstall</code>)
343scripts for installed packages in the foreground process, sharing standard
344input, output, and error with the main npm process.</p>
345<p>Note that this will generally make installs run slower, and be much noisier,
346but can be useful for debugging.</p>
347<h4 id="script-shell"><code>script-shell</code></h4>
348<ul>
349<li>Default: '/bin/sh' on POSIX systems, 'cmd.exe' on Windows</li>
350<li>Type: null or String</li>
351</ul>
352<p>The shell to use for scripts run with the <code>npm exec</code>, <code>npm run</code> and <code>npm init <package-spec></code> commands.</p>
353<h3 id="see-also">See Also</h3>
354<ul>
355<li><a href="../using-npm/scripts.html">npm scripts</a></li>
356<li><a href="../commands/npm-test.html">npm test</a></li>
357<li><a href="../commands/npm-start.html">npm start</a></li>
358<li><a href="../commands/npm-restart.html">npm restart</a></li>
359<li><a href="../commands/npm-stop.html">npm stop</a></li>
360<li><a href="../commands/npm-config.html">npm config</a></li>
361<li><a href="../using-npm/workspaces.html">npm workspaces</a></li>
362</ul></div>
363
364<footer id="edit">
365<a href="https://github.com/npm/cli/edit/latest/docs/lib/content/commands/npm-run.md">
366<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
367<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
368</svg>
369Edit this page on GitHub
370</a>
371</footer>
372</section>
373
374
375
376</body></html>