Langsung ke konten utama
Versi: 8.x

Filtering

Filtering memungkinkan anda membatasi perintah ke subset paket tertentu.

pnpm mendukung banyak sintaks selektor untuk memilih paket berdasarkan nama atau relasi.

Selektor dapat dispesifikasikan dengan --filter (atau dengan flag -F) :

pnpm --filter <package_selector> <command>

Sesuai dengan

--filter <nama_paket>

Untuk memilih paket yang tepat identik, cukup tentukan namanya (@scope/pkg) atau gunakan pola untuk memilih satu set paket (@scope/*).

Contohnya:

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

Menentukan cakupan paket adalah opsional, jadi --filter=core akan memilih @babel/core jika core tidak ditemukan. Namun, jika ruang kerja (folder workspace) memiliki beberapa paket dengan nama yang sama (misalnya, @babel/core dan @types/core), maka pemfilteran tanpa cakupan tidak akan menghasilkan apa-apa.

--filter <nama_paket>...

Untuk memilih paket dan dependensinya (langsung dan tidak langsung), akhiri nama paket dengan elipsis: <name_paket>.... Sebagai contoh, perintah berikutnya akan menjalankan pengujian dari foo dan semua dependensinya:

pnpm --filter foo... test

Anda dapat menggunakan pola untuk memilih satu set paket root:

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

--filter <nama_paket>^...

Untuk HANYA memilih dependensi suatu paket (baik langsung maupun tidak langsung), akhiri nama dengan elipsis yang disebutkan di atas didahului dengan chevron. Sebagai contoh, perintah berikutnya akan menjalankan pengujian dari foo dan semua dependensinya:

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

--filter ...<nama_paket>

Untuk memilih paket dan dependensinya (langsung dan tidak langsung), akhiri nama paket dengan elipsis: <nama_paket>.... Sebagai contoh, kode ini akan menjalankan tes dari foo dan semua paket yang bergantung padanya:

pnpm --filter ...foo test

--filter "...^<nama_paket>"

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>

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

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

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

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

--filter "[<since>]"

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 --filter "...[origin/master]" test

--fail-if-no-match

Ditambahkan di: v8.13.1

Use this flag if you want the CLI to fail if no packages have matched the filters.

Diluar dari

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 --filter=!foo <cmd>

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

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

Pilih banyak

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

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