pnpm run
Aliases: run-script
Запускает скрипт, определенный в файле манифеста пакета.
Примеры
Let's say you have a watch
script configured in your package.json
, like so:
"scripts": {
"watch": "webpack --watch"
}
You can now run that script by using pnpm run watch
! Просто, правда?
Another thing to note for those that like to save keystrokes and time is that
all scripts get aliased in as pnpm commands, so ultimately pnpm watch
is just
shorthand for pnpm run watch
(ONLY for scripts that do not share the same name
as already existing pnpm commands).
Running multiple scripts
You may run multiple scripts at the same time by using a regex instead of the script name.
pnpm run "/<regex>/"
Run all scripts that start with watch:
:
pnpm run "/^watch:.*/"
Подробности
In addition to the shell’s pre-existing PATH
, pnpm run
includes
node_modules/.bin
in the PATH
provided to scripts
. Это значит, до тех пор, пока у вас установлен пакет, вы можете использовать его в скрипте, как обычную команду. For example, if you have eslint
installed, you can write up a script
like so:
"lint": "eslint src --fix"
And even though eslint
is not installed globally in your shell, it will run.
For workspaces, <workspace root>/node_modules/.bin
is also added
to the PATH
, so if a tool is installed in the workspace root, it may be called
in any workspace package's scripts
.
Окружение
Есть некоторые переменные окружения, которые pnpm автоматически создает для исполняемых сценариев. Эти переменные окружения могут использоваться для получения контекстной информации о запущенном процессе.
Это переменные окружения, созданные pnpm:
- npm_command - contains the name of the executed command. If the executed command is
pnpm run
, then the value of this variable will be "run-script".
Опции
Any options for the run
command should be listed before the script's name.
Опции, перечисленные после имени скрипта передаются исполняемому скрипту.
All these will run pnpm CLI with the --silent
option:
pnpm run --silent watch
pnpm --silent run watch
pnpm --silent watch
Все аргументы после имени команды добавляются в исполняемый сценарий.
So if watch
runs webpack --watch
, then this command:
pnpm run watch --no-color
запустит:
webpack --watch --no-color