Filtrage
Le filtrage vous permet de restreindre les commandes à des sous-ensembles spécifiques de packages.
pnpm supporte une syntaxe de sélecteur riche pour choisir les paquets par nom ou par relation.
Selectors may be specified via the --filter (or -F) flag:
pnpm --filter <package_selector> <command>
Correspondant#
--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/*).
Exemples :
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
Vous pouvez utiliser un paterne pour sélectionner un ensemble de packages racine :
pnpm --filter "@babel/preset-*..." test
--filter <package_name>^...#
Pour sélectionner UNIQUEMENT les dépendances d'un package (à la fois directes et non directes), suffixez le nom avec les points de suspension susmentionnés précédés d'un 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>"#
Pour sélectionner SEULEMENT les dépendants d'un paquet (direct et non-direct), préparez le nom du paquet
avec une ellipse suivie d'un chevron. For instance, this will
run tests for all packages dependent on foo:
pnpm --filter "...^foo" test
--filter ./<glob>, --filter {<glob>}#
Un modèle de glob relatif au répertoire de travail courant correspondant aux projets.
pnpm --filter "./packages/**" <cmd>
Inclut tous les projets qui sont dans le répertoire spécifié.
Il peut également être utilisé avec les opérateurs d'ellipse et chevron pour sélectionner dépendants/dépendances :
pnpm --filter ...{<directory>} <cmd>
pnpm --filter {<directory>}... <cmd>
pnpm --filter ...{<directory>}... <cmd>
It may also be combined with [<since>]. Par exemple, pour sélectionner tous les projets
modifiés dans un répertoire:
pnpm --filter "{packages/**}[origin/master]" <cmd>
pnpm --filter "...{packages/**}[origin/master]" <cmd>
pnpm --filter "{packages/**}[origin/master]..." <cmd>
pnpm --filter "...{packages/**}[origin/master]..." <cmd>
The pattern language is the usual one: * and ? match within one path
segment, ** crosses segments, and a character class such as [ab] matches one
of the listed characters. Neither * nor ? matches a name that begins with a
dot, so packages/* skips packages/.cache. Name a dot-prefixed directory
explicitly to select it.
Ou vous pouvez sélectionner tous les packages d'un répertoire avec des noms correspondant au modèle donné :
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.
--filter "[<since>]"#
Sélectionne tous les paquets modifiés depuis le commit ou la branche spécifiés. 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 v12.7.0, <since> is compared against the commit where the current
branch forked from it (the 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 project also counts as changed when:
- a version it takes from a catalog changes in
pnpm-workspace.yaml, including a catalog entry that anoverridesentry points its dependency at; - files were moved out of it and 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.
--no-fail-if-no-match overrides failIfNoMatch: true for one command.
Excepté#
N'importe lequel des sélecteurs de filtres peut fonctionner comme des opérateurs d'exclusion lorsqu'ils ont un
« !» en tête. 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 v12.7.0, selectors are evaluated in the order they are given, so a later inclusion can bring back a project that an earlier exclusion removed:
pnpm --filter "!./packages/**" --filter @scope/core <cmd>
Multiplicité#
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. Vous pouvez utiliser autant de filtres que vous le souhaitez :
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 tel est le cas, les paquets dépendants de ces paquets modifiés ne sont pas inclus.
Cette option est utile avec le filtre "changed since". Par exemple, la prochaine commande exécutera des tests dans tous les paquets modifiés, et si les changements sont dans le code source du paquet, les tests s'exécuteront également dans les paquets dépendants :
pnpm --filter="...[origin/master]" --test-pattern="test/*" test
To set it for every command, use the testPattern setting in
pnpm-workspace.yaml:
- Default: []
- Type: string[]
--changed-files-ignore-pattern <glob>#
Prefix a pattern with ! to keep matching files. A later pattern can override an earlier match.
Permet d'ignorer les fichiers modifiés par les motifs de glob lors du filtrage pour les projets modifiés depuis la commit/branche spécifiée.
Exemple d'utilisation:
pnpm --filter="...[origin/master]" --changed-files-ignore-pattern="**/README.md" run build
To set it for every command, use the changedFilesIgnorePattern setting in
pnpm-workspace.yaml:
- Default: []
- Type: string[]