Фільтрування
Фільтрування дозволяє обмежити команди певними підмножинами пакетів.
pnpm supports a rich selector syntax for picking packages by name or by relation.
Selectors may be specified via the --filter
(or -F
) flag:
pnpm --filter <package_selector> <command>
Matching
--filter <package_name>
To select an exact package, just specify its name (@scope/pkg
) or use a pattern to select a set of packages (@scope/*
).
Examples:
pnpm --filter "@babel/core" test
pnpm --filter "@babel/*" test
pnpm --filter "*core" test
Specifying the scope of the package is optional, so --filter=core
will pick @babel/core
if core
is not found. However, if the workspace has multiple packages with the same name (for instance, @babel/core
and @types/core
), then filtering without scope will pick nothing.
--filter <package_name>...
To select a package and its dependencies (direct and non-direct), suffix the package name with an ellipsis: <package_name>...
. For instance, the next command will run tests of foo
and all of its dependencies:
pnpm --filter foo... test
You may use a pattern to select a set of root packages:
pnpm --filter "@babel/preset-*..." test
--filter <package_name>^...
To ONLY select the dependencies of a package (both direct and non-direct), suffix the name with the aforementioned ellipsis preceded by a chevron. For instance, the next command will run tests for all of foo
's dependencies:
pnpm --filter "foo^..." test
--filter ...<package_name>
To select a package and its dependent packages (direct and non-direct), prefix the package name with an ellipsis: ...<package_name>
. For instance, this will run the tests of foo
and all packages dependent on it:
pnpm --filter ...foo test
--filter "...^<package_name>"
To ONLY select a package's dependents (both direct and non-direct), prefix the package name with an ellipsis followed by a chevron. For instance, this will run tests for all packages dependent on foo
:
pnpm --filter "...^foo" test
--filter ./<glob>, --filter {<glob>}
A glob pattern relative to the current working directory matching projects.
pnpm --filter "./packages/**" <cmd>
Includes all projects that are under the specified directory.
It may be used with the ellipsis and chevron operators to select dependents/dependencies as well:
pnpm --filter ...{<directory>} <cmd>
pnpm --filter {<directory>}... <cmd>
pnpm --filter ...{<directory>}... <cmd>