Pular para o conteúdo principal
Version: 6.x

Filtragem

Adicionado em: v2.13.0

A filtragem permite restringir comandos a subconjuntos específicos de pacotes.

O pnpm suporta uma sintaxe de seletor rica para selecionar pacotes por nome ou por relação.

Os seletores podem ser especificados através da flag --filter:

pnpm <command> --filter <package_selector>

--filter <nome_do_pacote>

Adicionado em: v2.13.0

Para selecionar um pacote exato apenas especifique o nome (@scope/pkg) ou use um padrão para selecionar um conjunto de pacotes (@scope/*).

Examples:

pnpm test --filter "@babel/core"
pnpm test --filter "@babel/*"
pnpm test --filter "*core"

Desde v6.19.0:

Especificar o escopo do pacote é opcional, portanto --filter=core escolherá @babel/core se core não for encontrado. No entanto, se o espaço de trabalho tem vários pacotes com o mesmo nome (por exemplo, @babel/core e @types/core), então a filtragem sem escopo não escolherá nada.

--filter <nome_do_pacote>...

Adicionado em: v2.13.0

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 test --filter foo...

You may use a pattern to select a set of root packages:

pnpm test --filter "@babel/preset-*..."

--filter <nome_do_pacote>^...

Added in: v4.4.0

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 test --filter "foo^..."

--filter ...<nome_do_pacote>

Added in: v2.14.0

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 test --filter ...foo

--filter "...^<nome_do_pacote>"

Added in: v4.4.0

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 test --filter "...^foo"

--filter ./<diretório>

Added in: v2.15.0

To only select packages under the specified directory, you may specify any relative path, typically in POSIX format.

--filter {<directory>}

Added in: v4.7.0

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 <cmd> --filter ...{<directory>}
pnpm <cmd> --filter {<directory>}...
pnpm <cmd> --filter ...{<directory>}...

It may also be combined with [<since>]. For instance, to select all changed projects inside a directory:

pnpm <cmd> --filter "{packages}[origin/master]"
pnpm <cmd> --filter "...{packages}[origin/master]"
pnpm <cmd> --filter "{packages}[origin/master]..."
pnpm <cmd> --filter "...{packages}[origin/master]..."

Or you may select all packages from a directory with names matching the given pattern:

pnpm <cmd> --filter "@babel/*{components}"
pnpm <cmd> --filter "@babel/*{components}[origin/master]"
pnpm <cmd> --filter "...@babel/*{components}[origin/master]"

--filter "[<since>]"

Added in: v4.6.0

Selects all the packages changed since the specified commit/branch. 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 test --filter "...[origin/master]"

Multiplicity

When packages are filtered, every package is taken that matches at least one of the selectors. You can use as many filters as you want:

pnpm test --filter ...foo --filter bar --filter baz...

Excluding

Added in: v5.8.0

Any of the filter selectors may work as exclusion operators when they have a leading "!". In zsh (and possibly other shells), "!" should be escaped: \!.

For instance, this will run a command in all projects except for foo:

pnpm <cmd> --filter=!foo

And this will run a command in all projects that are not under the lib directory:

pnpm <cmd> --filter=!./lib

--filter-prod <filtering_pattern>

Added in: v6.2.0

Acts the same a --filter but omits devDependencies when selecting dependency projects from the workspace.

--test-pattern <glob>

Added in: v5.14.0

test-pattern allows detecting whether the modified files are related to tests. If they are, the dependent packages of such modified packages are not included.

This option is useful with the "changed since" filter. For instance, the next command will run tests in all changed packages, and if the changes are in the source code of the package, tests will run in the dependent packages as well:

pnpm --filter="...[origin/master]" --test-pattern="test/*" test

--changed-files-ignore-pattern <glob>

Added in: v6.16.0

Allows to ignore changed files by glob patterns when filtering for changed projects since the specified commit/branch.

Usage example:

pnpm --filter="...[origin/master]" --changed-files-ignore-pattern="**/README.md" run build