2021-03-01 11:38:43 -05:00
|
|
|
.TH "NPM\-RUN\-SCRIPT" "1" "March 2021" "" ""
|
2011-11-26 09:21:03 -08:00
|
|
|
.SH "NAME"
|
2019-11-18 21:01:39 +02:00
|
|
|
\fBnpm-run-script\fR \- Run arbitrary package scripts
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS Synopsis
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
|
|
|
.RS 2
|
2014-11-04 15:08:12 -08:00
|
|
|
.nf
|
2020-12-11 18:54:56 -05:00
|
|
|
npm run\-script <command> [\-\-if\-present] [\-\-silent] [\-\- <args>]
|
2015-10-09 23:13:57 -07:00
|
|
|
|
2020-12-11 18:54:56 -05:00
|
|
|
aliases: run, rum, urn
|
2014-11-04 15:08:12 -08:00
|
|
|
.fi
|
2014-09-24 14:41:07 -07:00
|
|
|
.RE
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS Description
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
This runs an arbitrary command from a package's \fB"scripts"\fP object\. If no
|
2020-12-11 18:54:56 -05:00
|
|
|
\fB"command"\fP is provided, it will list the available scripts\.
|
2014-11-04 15:08:12 -08:00
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
\fBrun[\-script]\fP is used by the test, start, restart, and stop commands, but
|
|
|
|
can be called directly, as well\. When the scripts in the package are
|
|
|
|
printed out, they're separated into lifecycle (test, start, restart) and
|
|
|
|
directly\-run scripts\.
|
|
|
|
.P
|
|
|
|
Any positional arguments are passed to the specified script\. Use \fB\-\-\fP to
|
|
|
|
pass \fB\-\fP\-prefixed flags and options which would otherwise be parsed by npm\.
|
|
|
|
.P
|
|
|
|
For example:
|
2014-11-04 15:08:12 -08:00
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
npm run test \-\- \-\-grep="pattern"
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
The arguments will only be passed to the script specified after \fBnpm run\fP
|
2021-01-28 17:38:39 -05:00
|
|
|
and not to any \fBpre\fP or \fBpost\fP script\.
|
2015-03-06 02:57:32 -06:00
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
The \fBenv\fP script is a special built\-in command that can be used to list
|
2015-03-06 02:57:32 -06:00
|
|
|
environment variables that will be available to the script at runtime\. If an
|
2017-10-26 22:35:25 -04:00
|
|
|
"env" command is defined in your package, it will take precedence over the
|
2015-03-06 02:57:32 -06:00
|
|
|
built\-in\.
|
2015-03-13 02:07:27 -07:00
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
In addition to the shell's pre\-existing \fBPATH\fP, \fBnpm run\fP adds
|
2020-12-11 18:54:56 -05:00
|
|
|
\fBnode_modules/\.bin\fP to the \fBPATH\fP provided to scripts\. Any binaries
|
|
|
|
provided by locally\-installed dependencies can be used without the
|
|
|
|
\fBnode_modules/\.bin\fP prefix\. For example, if there is a \fBdevDependency\fP on
|
|
|
|
\fBtap\fP in your package, you should write:
|
2015-07-20 20:07:07 -07:00
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
2020-12-11 18:54:56 -05:00
|
|
|
"scripts": {"test": "tap test/*\.js"}
|
2015-07-20 20:07:07 -07:00
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.P
|
2017-10-26 22:35:25 -04:00
|
|
|
instead of
|
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
2020-12-11 18:54:56 -05:00
|
|
|
"scripts": {"test": "node_modules/\.bin/tap test/*\.js"}
|
2017-10-26 22:35:25 -04:00
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.P
|
2017-12-07 14:05:23 -08:00
|
|
|
The actual shell your script is run within is platform dependent\. By default,
|
2021-01-28 17:38:39 -05:00
|
|
|
on Unix\-like systems it is the \fB/bin/sh\fP command, on Windows it is
|
|
|
|
\fBcmd\.exe\fP\|\.
|
2017-12-07 14:05:23 -08:00
|
|
|
The actual shell referred to by \fB/bin/sh\fP also depends on the system\.
|
2020-12-11 18:54:56 -05:00
|
|
|
You can customize the shell with the \fBscript\-shell\fP configuration\.
|
2017-12-07 14:05:23 -08:00
|
|
|
.P
|
2020-12-18 15:39:05 -05:00
|
|
|
Scripts are run from the root of the package folder, regardless of what the
|
|
|
|
current working directory is when \fBnpm run\fP is called\. If you want your
|
|
|
|
script to use different behavior based on what subdirectory you're in, you
|
|
|
|
can use the \fBINIT_CWD\fP environment variable, which holds the full path you
|
|
|
|
were in when you ran \fBnpm run\fP\|\.
|
|
|
|
.P
|
|
|
|
\fBnpm run\fP sets the \fBNODE\fP environment variable to the \fBnode\fP executable
|
|
|
|
with which \fBnpm\fP is executed\. Also, if the \fB\-\-scripts\-prepend\-node\-path\fP is
|
|
|
|
passed, the directory within which \fBnode\fP resides is added to the \fBPATH\fP\|\.
|
|
|
|
If \fB\-\-scripts\-prepend\-node\-path=auto\fP is passed (which has been the default
|
|
|
|
in \fBnpm\fP v3), this is only performed when that \fBnode\fP executable is not
|
|
|
|
found in the \fBPATH\fP\|\.
|
2016-05-06 15:22:02 -07:00
|
|
|
.P
|
2021-01-28 17:38:39 -05:00
|
|
|
If you try to run a script without having a \fBnode_modules\fP directory and it
|
|
|
|
fails, you will be given a warning to run \fBnpm install\fP, just in case you've
|
|
|
|
forgotten\.
|
|
|
|
.SS Configuration
|
|
|
|
.SS if\-present
|
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
|
|
|
Type: Boolean
|
|
|
|
.IP \(bu 2
|
|
|
|
Default: false
|
|
|
|
|
|
|
|
.RE
|
2018-04-20 18:26:37 -07:00
|
|
|
.P
|
|
|
|
You can use the \fB\-\-if\-present\fP flag to avoid exiting with a non\-zero exit code
|
|
|
|
when the script is undefined\. This lets you run potentially undefined scripts
|
|
|
|
without breaking the execution chain\.
|
2021-01-28 17:38:39 -05:00
|
|
|
.SS ignore\-scripts
|
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
|
|
|
Type: Boolean
|
|
|
|
.IP \(bu 2
|
|
|
|
Default: false
|
|
|
|
|
|
|
|
.RE
|
|
|
|
.P
|
|
|
|
Skips running \fBpre\fP and \fBpost\fP scripts\.
|
|
|
|
.SS script\-shell
|
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
|
|
|
Type: String
|
|
|
|
.IP \(bu 2
|
|
|
|
Default: \fBnull\fP
|
|
|
|
|
|
|
|
.RE
|
|
|
|
.P
|
|
|
|
Optional custom script to use to execute the command\. If not defined defaults
|
|
|
|
to \fB/bin/sh\fP on Unix, defaults to \fBenv\.comspec\fP or \fBcmd\.exe\fP on Windows\.
|
|
|
|
.SS silent
|
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
|
|
|
Type: Boolean
|
|
|
|
.IP \(bu 2
|
|
|
|
Default: false
|
|
|
|
|
|
|
|
.RE
|
|
|
|
.P
|
|
|
|
You can use the \fB\-\-silent\fP flag to prevent showing \fBnpm ERR!\fP output on error\.
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS See Also
|
2014-09-24 14:41:07 -07:00
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
2019-11-05 14:55:08 -05:00
|
|
|
npm help scripts
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help test
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help start
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help restart
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help stop
|
2017-12-07 14:05:23 -08:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help config
|
2014-09-24 14:41:07 -07:00
|
|
|
|
|
|
|
.RE
|