Performant npm (pnpm) Reference
Kip Landergren
(Updated: )
Contents
Selected Commands and Options
Common options:
-C [path], --dir [path] | run as if pnpm was started in [path] instead of the current directory |
-w, --workspace-root | Run as if pnpm was started in the root of the workspace instead of the current working directory |
pnpm add
Installs a package and any packages that it depends on.
Usage:
pnpm add <name>
pnpm add <name>@<tag>
pnpm add <name>@<version>
pnpm add <name>@<version range>
pnpm add <git host>:<git user>/<repo name>
pnpm add <git repo url>
pnpm add <tarball file>
pnpm add <tarball url>
pnpm add <dir>
Options:
--[no-]color Controls colors in the output. By default, output is always colored when it goes
directly to a terminal
-E, --[no-]save-exact Install exact version
--[no-]save-workspace-protocol Save packages from the workspace with a "workspace:" protocol. True by default
--aggregate-output Aggregate output from child processes that are run in parallel, and only print
output when child process is finished. It makes reading large logs after running
`pnpm recursive` with `--parallel` or with `--workspace-concurrency` much easier
(especially on CI). Only `--reporter=append-only` is supported.
-C, --dir <dir> Change to directory <dir> (default:
/private/var/tmp/_bazel_klandergren/e650345dbc8536911331222dcd3778e0/execroot/_
main/bazel-out/darwin_x86_64-fastbuild/bin/external/aspect_rules_js~~pnpm~pnpm/
pnpm.sh.runfiles/_main)
-g, --global Install as a global package
--global-dir Specify a custom directory to store global packages
-h, --help Output usage information
--ignore-scripts Don't run lifecycle scripts
--loglevel <level> What level of logs to report. Any logs at or higher than the given level will be
shown. Levels (lowest to highest): debug, info, warn, error. Or use "--silent" to
turn off all logging.
--offline Trigger an error if any required dependencies are not available in local store
--prefer-offline Skip staleness checks for cached data, but request missing data from the server
-r, --recursive Run installation recursively in every package found in subdirectories or in every
workspace package, when executed inside a workspace. For options that may be used
with `-r`, see "pnpm help recursive"
-D, --save-dev Save package to your `devDependencies`
-O, --save-optional Save package to your `optionalDependencies`
--save-peer Save package to your `peerDependencies` and `devDependencies`
-P, --save-prod Save package to your `dependencies`. The default behavior
--store-dir <dir> The directory in which all the packages are saved on the disk
--stream Stream output from child processes immediately, prefixed with the originating
package directory. This allows output from different packages to be interleaved.
--use-stderr Divert all output to stderr
--virtual-store-dir <dir> The directory with links to the store (default is node_modules/.pnpm). All direct
and indirect dependencies of the project are linked into this directory
--workspace Only adds the new dependency if it is found in the workspace
-w, --workspace-root Run the command on the root workspace project
Filtering options:
--changed-files-ignore-pattern <pattern> Defines files to ignore when filtering for changed projects since the
specified commit/branch. Usage example: pnpm
--filter="...[origin/master]"
--changed-files-ignore-pattern="**/README.md" build
--filter !<selector> If a selector starts with ! (or \! in zsh), it means the packages
matching the selector must be excluded. E.g., "pnpm --filter !foo"
selects all packages except "foo"
--filter . Includes all packages that are under the current working directory
--filter ...^<pattern> Includes only the direct and indirect dependents of the matched
packages without including the matched packages themselves. ^ must be
doubled at the Windows Command Prompt. E.g.: ...^foo (...^^foo in
Command Prompt)
--filter ...<pattern> Includes all direct and indirect dependents of the matched packages.
E.g.: ...foo, "...@bar/*"
--filter ./<dir> Includes all packages that are inside a given subdirectory. E.g.:
./components
--filter "[<since>]" Includes all packages changed since the specified commit/branch. E.g.:
"[master]", "[HEAD~2]". It may be used together with "...". So, for
instance, "...[HEAD~1]" selects all packages changed in the last commit
and their dependents
--filter {<dir>} Includes all projects that are under the specified directory. It may be
used with "..." to select dependents/dependencies as well. It also may
be combined with "[<since>]". For instance, all changed projects inside
a directory: "{packages}[origin/master]"
--filter <pattern> Restricts the scope to package names matching the given pattern. E.g.:
foo, "@bar/*"
--filter <pattern>... Includes all direct and indirect dependencies of the matched packages.
E.g.: foo...
--filter <pattern>^... Includes only the direct and indirect dependencies of the matched
packages without including the matched packages themselves. ^ must be
doubled at the Windows Command Prompt. E.g.: foo^... (foo^^... in
Command Prompt)
--filter-prod <pattern> Restricts the scope to package names matching the given pattern similar
to --filter, but it ignores devDependencies when searching for
dependencies and dependents.
--test-pattern <pattern> Defines files related to tests. Useful with the changed since filter.
When selecting only changed packages and their dependent packages, the
dependent packages will be ignored in case a package has changes only
in tests. Usage example: pnpm --filter="...[origin/master]"
--test-pattern="test/*" test
pnpm install
--lockfile-only | Only pnpm-lock.yaml is updated |
pnpm list
pnpm remove
Removes packages from node_modules and from the project’s package.json.
pnpm update
Updates packages to their latest version based on the specified range. Used to upgrade and downgrade packages. When used without arguments, updates all dependencies.
--recursive, -r |