npm_run
npm_run runs a script from the selected package directory using managed Node.js. It runs pnpm run <script> -- <args...> when that directory's package.json declares pnpm 11+ through packageManager or devEngines.packageManager; otherwise it runs npm run <script> -- <args...> using npm bundled with Node.js. The script runs during xx run; pass the returned dependency to deps when another task must wait for it.
The package directory must exist inside the project when npm_run is called and is used as the command's working directory. xx selects the package manager from package.json at that time; a missing declaration selects npm. A regular, non-symlink package.json must exist after deps finish.
See nodejs for supported pnpm declarations and range resolution.
Arguments
| Argument | Required | Description |
|---|---|---|
script | Yes | Non-empty package script name that does not begin with -. |
args | No | String arguments passed to the script after --. Defaults to []. |
deps | No | Dependencies activated before the script, in list order. Defaults to []. |
dir | No | Project-relative package directory. Defaults to ".". |
Examples
Run a package script
load("@[email protected]", "npm_run")
npm_run("test")
Pass script arguments
load("@[email protected]", "npm_run")
npm_run("test", args=["--runInBand"])
Install before building
load("@[email protected]", "npm_install", "npm_run")
install = npm_install(frozen_lockfile=True, dir="frontend")
npm_run("build", deps=[install], dir="frontend")
Add the installation to deps when the script needs installed packages. Without deps=[install], installation and script may run concurrently.