Перейти к основному содержимому
Версия: 10.x

Фильтрация

Фильтрация позволяет ограничить команды определенными подмножествами пакетов.

pnpm поддерживает расширенный синтаксис селектора для выбора пакетов по имени или по отношению.

Selectors may be specified via the --filter (or -F) flag:

pnpm --filter <package_selector> <command>

Соответствие

--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/*).

Примеры:

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

Вы можете использовать шаблон для выбора набора корневых пакетов:

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

--filter <package_name>^...

Чтобы выбрать ТОЛЬКО зависимости пакета (как прямые, так и непрямые), добавьте к имени вышеупомянутое многоточие, которому предшествует шеврон. 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>"

Чтобы выбрать ТОЛЬКО зависимые пакеты (прямые и непрямые), добавьте к имени пакета префикс с многоточием, за которым следует шеврон. For instance, this will run tests for all packages dependent on foo:

pnpm --filter "...^foo" test

--filter ./<glob>, --filter {<glob>}

Шаблон glob относительно текущего рабочего каталога, соответствующего проектам.

pnpm --filter "./packages/**" <cmd>

Включает все проекты, находящиеся в указанном каталоге.

Его также можно использовать с операторами многоточия и шеврона для выбора зависимых/зависимостей:

pnpm --filter ...{<directory>} <cmd>
pnpm --filter {<directory>}... <cmd>
pnpm --filter ...{<directory>}... <cmd>

It may also be combined with [<since>]. Например, чтобы выбрать все измененные проекты внутри каталога:

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

Или вы можете выбрать все пакеты из каталога с именами, соответствующими заданному шаблону:

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

--filter "[<since>]"

Выбирает все измененные пакеты с момента указанного 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 --filter "...[origin/master]" test

--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.

Исключения

Любой из селекторов фильтра может работать как оператор исключения, если перед ним стоит "!". 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 under the lib directory:

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

Множественность

Когда пакеты фильтруются, берется каждый пакет, который соответствует хотя бы одному из селекторов. Вы можете использовать столько фильтров, сколько хотите:

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

--filter-prod <filtering_pattern>

Acts the same a --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. Если они есть, то зависимые пакеты таких измененных пакетов не включаются.

Этот параметр полезен с фильтром «изменилось с» (дата, время). Например, следующая команда запустит тесты во всех измененных пакетах, а если изменения находятся в исходном коде пакета, тесты будут запущены и в зависимых пакетах:

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

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

Позволяет игнорировать измененные файлы по шаблонам glob при фильтрации измененных проектов, начиная с указанного commit/branch.

Пример использования:

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