필터링
필터링을 사용하면 패키지의 특정 하위 집합으로 명령을 제한할 수 있습니다.
pnpm은 이름 또는 관계로 패키지를 선택하기 위한 다양한 selector 구문을 지원합니다.
선택자는 --filter(또는 -F) 플래그를 통해 지정할 수 있습니다:
pnpm --filter <package_selector> <command>
매칭#
--filter <package_name>#
정확한 패키지를 선택하려면 이름(@scope/pkg)을 지정하거나, 패턴을 사용하여 패키지 집합(@scope/*)을 선택하세요.
예시:
pnpm --filter "@babel/core" test
pnpm --filter "@babel/*" test
pnpm --filter "*core" test
패키지의 스코프 지정은 선택 사항이므로, core를 찾을 수 없으면 --filter=core는 @babel/core를 선택합니다.
그러나 워크스페이스에 같은 이름을 가진 패키지가 여러 개 있는 경우(예: @babel/core와 @types/core), 스코프 없이 필터링하면 아무것도 선택되지 않습니다.
--filter <package_name>...#
패키지와 그 종속성(직접 및 간접)을 선택하려면 패키지 이름 뒤에 줄임표를 붙이세요: <package_name>.... 예를 들어, 다음 명령은 foo와 그 모든 종속성의 테스트를 실행합니다:
pnpm --filter foo... test
패턴을 사용하여 루트 패키지 세트를 선택할 수 있습니다.
pnpm --filter "@babel/preset-*..." test
--filter <package_name>^...#
패키지의 의존성 (직접 및 비직접) 만 선택하려면, 앞서 언급한 줄임표 앞에 셰브런 (^) 이 붙은 이름 접미사를 붙입니다. 예를 들어, 다음 명령은 foo의 모든 종속성에 대한 테스트를 실행합니다:
pnpm --filter "foo^..." test
--filter ...<package_name>#
패키지와 그 종속 패키지(직접 및 간접)를 선택하려면 패키지 이름 앞에 줄임표를 붙이세요: ...<package_name>. 예를 들어, 다음은 foo와 이에 종속된 모든 패키지의 테스트를 실행합니다:
pnpm --filter ...foo test
--filter "...^<package_name>"#
패키지의 의존 패키지만을 선택하기 위해 (직접 및 비직접 모두), 셰브런이 뒤에 붙은 줄임표를 접두사로 붙입니다. 예를 들어, 다음은 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>
[<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>
legacyDirFiltering#
- 기본값: false
- 유형: 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, since v11.24.0. Read
as subtree matches they named every project below the root, so a recursive
command under this setting selected nothing at all, and --workspace-root
pulled in the whole workspace instead of the root alone
(#14101).
--filter "[<since>]"#
지정된 커밋/브랜치 이후 변경된 모든 패키지를 선택합니다. 종속성/종속 패키지를 포함하려면 앞이나 뒤에 ...를 붙일 수 있습니다.
예를 들어, 다음 명령은 master 이후 변경된 모든 패키지와 그 종속 패키지에서 테스트를 실행합니다:
pnpm --filter "...[origin/master]" test
Since v11.28.0, pnpm compares against the commit where the current branch
forked from <since> (their 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 change to a version in a catalog in pnpm-workspace.yaml
selects the projects that use that catalog entry. A project that files were
moved out of is selected when Git detects the move as a rename.
--fail-if-no-match#
필터와 일치하는 패키지가 없는 경우 CLI가 실패하게 하려면 이 플래그를 사용하십시오.
failIfNoMatch setting으로 이를 영구적으로 설정할 수도 있습니다.
제외하기#
필터 셀렉터는 선행으로 "!"를 가질 때 제외 연산자로서 작동할 수 있습니다. 셸 중 zsh(및 다른 일부 셸)에서는 "!"를 이스케이프 처리해야 합니다: \!.
예를 들어, 다음은 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 v11.28.0, selectors are applied in the order they are given. An exclusion
removes projects selected by the selectors before it, and an inclusion after it
can add excluded projects back. When the first selector is an exclusion, it
starts from every project in the workspace. For instance, this runs a command
in a but in no other project under packages:
pnpm --filter="!./packages/**" --filter=a <cmd>
다중성#
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. 필터를 원하는 만큼 추가할 수 있습니다.
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을 사용하면 수정된 파일이 테스트와 관련되어 있는지 감지할 수 있습니다.
그렇다면 그러한 수정된 패키지의 의존 패키지는 포함되지 않습니다.
이 옵션은 "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