フィルタリング
フィルタリングを使用すると、コマンドをの特定の一部のパッケージに制限できます。
pnpm はパッケージを名前またはリレーションで選択するための豊富なセレクタ構文をサポートしています。
Selectors may be specified via the --filter (or -F) flag:
pnpm --filter <package_selector> <command>
Matching
--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>}
プロジェクトに一致する、現在の作業ディレクトリからの相対的なグロブパターンです。
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>]"
指定されたコミット / ブランチ以降に変更されたすべてのパッケージを選択します。 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>
複数のフィルターを指定する
フィルタリングをする際は、少なくとも 1 つのフィルターに一致するすべてのパッケージが取得されます。 必要な数だけフィルターを使用できます。
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.
もしそうであれば、そのような変更されたパッケージの依存パッケージは含まれません。
このオプションは、"changed since" フィルタと一緒に使うと便利です。 例えば次のコマンドは、変更されたすべてのパッケージでテストを実行します。パッケージのソースコードに変更があった場合は、テストは依存パッケージでも実行されます。
pnpm --filter="...[origin/master]" --test-pattern="test/*" test
--changed-files-ignore-pattern <glob>
指定されたコミット/ブランチ以降に変更されたプロジェクトをフィルタリングする際に、globパターンによって変更されたファイルを無視できるようにします。
使用例:
pnpm --filter="...[origin/master]" --changed-files-ignore-pattern="**/README.md" run build