Filtración
El filtrado permite restringir los comandos a un subconjunto específico de paquetes.
pnpm admite un selector de sintaxis enriquecida para seleccionar paquetes por nombre o por relación.
Selectors may be specified via the --filter (or -F) flag:
pnpm --filter <package_selector> <command>
Emparejamiento#
--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/*).
Ejemplos:
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
Puede usar un patrón para seleccionar un conjunto de paquetes raíz:
pnpm --filter "@babel/preset-*..." test
--filter <package_name>^...#
Para seleccionar SOLAMENTE las dependencias de un paquete (tanto directas como no directas),
agregue al nombre los puntos suspensivos antes mencionados precedidos por un cheurón. 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>"#
Para seleccionar SOLAMENTE a los dependientes de un paquete (tanto directos como no directos), prefije el nombre del paquete
con puntos suspensivos seguidos de un cheurón. For instance, this will
run tests for all packages dependent on foo:
pnpm --filter "...^foo" test
--filter ./<glob>, --filter {<glob>}#
Un patrón global relativo a los proyectos que coincidan con el directorio de trabajo actual.
pnpm --filter "./packages/**" <cmd>
Incluye todos los proyectos que están bajo el directorio especificado.
También se puede usar con los operadores de puntos suspensivos y cheurón para seleccionar dependientes/dependencias:
pnpm --filter ...{<directory>} <cmd>
pnpm --filter {<directory>}... <cmd>
pnpm --filter ...{<directory>}... <cmd>
It may also be combined with [<since>]. Por ejemplo, para seleccionar todos los
proyectos modificados dentro de un directorio:
pnpm --filter "{packages/**}[origin/master]" <cmd>
pnpm --filter "...{packages/**}[origin/master]" <cmd>
pnpm --filter "{packages/**}[origin/master]..." <cmd>
pnpm --filter "...{packages/**}[origin/master]..." <cmd>
O puede seleccionar todos los paquetes de un directorio con nombres que coincidan con el patrón dado:
pnpm --filter "@babel/*{components/**}" <cmd>
pnpm --filter "@babel/*{components/**}[origin/master]" <cmd>
pnpm --filter "...@babel/*{components/**}[origin/master]" <cmd>
legacyDirFiltering#
- Default: false
- Type: Boolean
{<dir>} is matched as a glob pattern: {packages/*} selects the projects one
level below packages/, and it takes a ** to reach deeper. Set
legacyDirFiltering to true in pnpm-workspace.yaml to restore the older
behavior, where the selector named a directory and matched every project in
the subtree below it:
legacyDirFiltering: true
The setting only applies to the selectors you write. The workspace-root
selectors pnpm generates for itself (the !{<workspace-root>} a recursive
run / exec / add / test appends, and the {<workspace-root>} that
--workspace-root appends) are always matched as globs, since v11.24.0. Read
as subtree matches they named every project below the root, so a recursive
command under this setting selected nothing at all, and --workspace-root
pulled in the whole workspace instead of the root alone
(#14101).
--filter "[<since>]"#
Selecciona todos los paquetes cambiados desde el commit/rama especificado. May be
suffixed or prefixed with ... to include dependencies/dependents.
For example, the next command will run tests in all changed packages since
master and on any dependent packages:
pnpm --filter "...[origin/master]" test
Since v11.28.0, pnpm compares against the commit where the current branch
forked from <since> (their merge base), so projects changed only by newer
commits on <since> are not selected. Uncommitted changes are still included.
In a shallow clone that lacks the merge base, pnpm compares against <since>
directly.
This selector requires Git 2.24 or newer.
A change to a version in a catalog in pnpm-workspace.yaml
selects the projects that use that catalog entry. A project that files were
moved out of is selected when Git detects the move as a rename.
--fail-if-no-match#
Use this flag if you want the CLI to fail if no packages have matched the filters.
You may also set this permanently with a failIfNoMatch setting.
Excluyendo#
Cualquiera de los selectores de filtro puede funcionar como operadores de exclusión cuando tienen un
inicial "!". In zsh (and possibly other shells), "!" should be escaped: \!.
For instance, this will run a command in all projects except for foo:
pnpm --filter=!foo <cmd>
And this will run a command in all projects that are not in the lib
directory or below it:
pnpm --filter='!./lib/**' <cmd>
Since v11.28.0, selectors are applied in the order they are given. An exclusion
removes projects selected by the selectors before it, and an inclusion after it
can add excluded projects back. When the first selector is an exclusion, it
starts from every project in the workspace. For instance, this runs a command
in a but in no other project under packages:
pnpm --filter="!./packages/**" --filter=a <cmd>
Multiplicidad#
When packages are filtered, every package is taken that matches at least one of the inclusion selectors, unless a later exclusion removes it. When the first selector is an exclusion, filtering starts from every project in the workspace. Puedes usar tantos filtros como quieras:
pnpm --filter ...foo --filter bar --filter baz... test
--filter-prod <filtering_pattern>#
Acts the same as --filter but omits devDependencies when selecting dependency projects
from the workspace.
--test-pattern <glob>#
test-pattern allows detecting whether the modified files are related to tests.
Si lo son, los paquetes dependientes de dichos paquetes modificados no están incluidos.
Esta opción es útil con el filtro "cambiado desde". Por ejemplo, el siguiente comando ejecutará pruebas en todos los paquetes modificados, y si los cambios están en el código fuente del paquete, las pruebas también se ejecutarán en los paquetes dependientes:
pnpm --filter="...[origin/master]" --test-pattern="test/*" test
--changed-files-ignore-pattern <glob>#
Permite ignorar los archivos cambiados por patrones de glob al filtrar los proyectos cambiados desde el commit/rama especificado.
Ejemplo de uso:
pnpm --filter="...[origin/master]" --changed-files-ignore-pattern="**/README.md" run build