필터링
필터링을 사용하면 패키지의 특정 하위 집합으로 명령을 제한할 수 있습니다.
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>
The pattern language is the usual one: * and ? match within one path
segment, ** crosses segments, and a character class such as [ab] matches one
of the listed characters. Neither * nor ? matches a name that begins with a
dot, so packages/* skips packages/.cache. Name a dot-prefixed directory
explicitly to select it.
또는 지정된 패턴과 일치하는 이름을 가진 디렉토리에서 모든 패키지를 선택할 수 있습니다.
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.
--filter "[<since>]"#
지정된 커밋/브랜치 이후 변경된 모든 패키지를 선택합니다. 종속성/종속 패키지를 포함하려면 뒤나 앞에 ...을 붙일 수 있습니다.
예를 들어, 다음 명령은 master 이후 변경된 모든 패키지와 그에 종속된 모든 패키지에서 테스트를 실행합니다:
pnpm --filter "...[origin/master]" test
Since v12.7.0, <since> is compared against the commit where the current
branch forked from it (the 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 project also counts as changed when:
- a version it takes from a catalog changes in
pnpm-workspace.yaml; - files were moved out of it and git detects the move as a rename.
--fail-if-no-match#
필터와 일치하는 패키지가 없는 경우 CLI가 실패하게 하려면 이 플래그를 사용하십시오.
failIfNoMatch setting으로 이를 영구적으로 설정할 수도 있습니다.
--no-fail-if-no-match overrides failIfNoMatch: true for one command.
제외하기#
필터 셀렉터는 선행으로 "!"를 가질 때 제외 연산자로서 작동할 수 있습니다. 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 v12.7.0, selectors are evaluated in the order they are given, so a later inclusion can bring back a project that an earlier exclusion removed:
pnpm --filter "!./packages/**" --filter @scope/core <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
To set it for every command, use the testPattern setting in
pnpm-workspace.yaml:
- 기본값: []
- 유형: string[]
--changed-files-ignore-pattern <glob>#
지정된 커밋/브랜치 이후 변경된 프로젝트를 필터링할 때 glob 패턴으로 변경된 파일을 무시할 수 있습니다.
사용 예:
pnpm --filter="...[origin/master]" --changed-files-ignore-pattern="**/README.md" run build
To set it for every command, use the changedFilesIgnorePattern setting in
pnpm-workspace.yaml:
- 기본값: []
- 유형: string[]