-
Notifications
You must be signed in to change notification settings - Fork 2k
Document --filter #914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Document --filter #914
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
a21025c
Start on filter docs for cli reference
e76d8d2
Add note about --ignore
97034c7
Rewrite scoped tasks page in terms of filter
ec1d354
Merge branch 'main' into gsoltis/filter_docs
b3d3f91
Merge branch 'main' into gsoltis/filter_docs
7105859
Merge branch 'main' into gsoltis/filter_docs
gaspar09 81cb9cf
Merge branch 'main' into gsoltis/filter_docs
jaredpalmer 6900588
Merge branch 'main' into gsoltis/filter_docs
db0c41a
Another pass at filter docs
3ef799d
Merge branch 'main' into gsoltis/filter_docs
8dbf294
Update docs/pages/docs/features/filtering-packages.mdx
61fddde
Update docs/pages/docs/features/filtering-packages.mdx
8acdd48
Update docs/pages/docs/features/filtering-packages.mdx
5cf0d7c
Update docs/pages/docs/features/filtering-packages.mdx
8b243ed
Update docs/pages/docs/features/filtering-packages.mdx
ed449e6
Update docs/pages/docs/features/filtering-packages.mdx
978d79a
Update docs/pages/docs/features/filtering-packages.mdx
0ac657d
Update docs/pages/docs/features/filtering-packages.mdx
aba2e2d
Update docs/pages/docs/features/filtering-packages.mdx
1650ee5
Update docs/pages/docs/features/filtering-packages.mdx
96e6551
Update docs/pages/docs/reference/command-line-reference.mdx
6b22569
Add redirect for scopes
6af4afb
Move filtering-packages -> filtering
4708935
Merge branch 'main' into gsoltis/filter_docs
f6f2cbe
Add deprecated callouts
3875433
Update docs/pages/docs/features/filtering.mdx
jaredpalmer 40a08e7
Document examples and hoist them up
efb5a92
Revive scope page, hide it, and deprecate it
9938a9a
Merge branch 'main' into gsoltis/filter_docs
19b08d9
Merge branch 'main' into gsoltis/filter_docs
1d9e140
Merge branch 'main' into gsoltis/filter_docs
126a83b
Merge branch 'main' into gsoltis/filter_docs
29b8376
Merge branch 'main' into gsoltis/filter_docs
jaredpalmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
--- | ||
title: Filtering Packages | ||
description: Only build the packages you care about | ||
--- | ||
|
||
import Callout from "../../../components/callout"; | ||
import HeartIcon from "@heroicons/react/solid/HeartIcon"; | ||
|
||
# Filtering Packages | ||
|
||
Filtering packages allows you to target your tasks to only the packages you care about. | ||
Turborepo supports a `pnpm`-like `--filter` flag that allows you to select the packages | ||
that will act as "entry points" into your monorepo's package/task graph. | ||
You can filter packages by name, directory, include dependents/dependencies, and by changes | ||
in git history. | ||
|
||
`turbo` will run each task against each matched package, ensuring that any dependencies | ||
are run first, according to the `pipeline` specification in [`turbo.json`](/docs/reference/configuration#pipeline). | ||
|
||
## Filter Syntax | ||
|
||
Filters specify combinations of package(s)/apps, directories, and git commits to act as entrypoints | ||
for execution. | ||
|
||
Multiple filters can be combined to select distinct sets of targets. Additionally, filters | ||
can also exclude targets. A target that matches any filter and is not explicitly excluded will | ||
be in the final entrypoint selection. | ||
|
||
Turborepo's filter syntax is based on pnpm's filter syntax, so it should feel familiar to pnpm users. | ||
|
||
### Filter by package | ||
|
||
Supports exact matches (`--filter=my-pkg`), and globs (`--filter=*my-pkg*`) are supported. | ||
Scoped packages (`@foo/bar`) can be abbreviated to just the package name (`bar`) as long as the package name | ||
is unique within the monorepo (e.g. `@foo/bar` exists, but `@baz/bar` does not). | ||
|
||
```sh | ||
# Build 'my-pkg', letting turbo infer task dependencies from the pipeline defined in turbo.json | ||
turbo run build --filter=my-pkg | ||
# Build '@foo/bar', letting turbo infer task dependencies from the pipeline defined in turbo.json | ||
turbo run build --filter=@foo/bar | ||
# Build all packages that start with 'admin-', letting turbo infer task dependencies from the pipeline defined in turbo.json | ||
turbo run build --filter=admin-* | ||
``` | ||
|
||
### Include dependents of matched packages | ||
|
||
Prepend `...` to the filter. If `my-app` depends on `my-lib`, `...my-lib` will select `my-app` and `my-lib`. | ||
Optionally including a `^` (`...^my-lib`) will select all of `my-lib`'s dependents, but not `my-lib` itself. In this case, just `my-app` will be | ||
selected. | ||
|
||
```sh | ||
# Test 'my-lib' and everything that depends on 'my-lib' | ||
turbo run test --filter=...my-lib | ||
# Test everything that depends on 'my-lib', but not 'my-lib' itself | ||
turbo run test --filter=...^my-lib | ||
``` | ||
|
||
### Include dependencies of matched packages | ||
|
||
Append `...` to the end of the filter. If `my-app` depends on `my-lib`, `my-app...` will select `my-app` and `my-lib`. | ||
Optionally including a `^` (`my-app^...`) will select all of `my-app`'s dependencies, but not `my-app` itself. In this case, just `my-lib` will be selected. | ||
|
||
```sh | ||
# Build 'my-app' and its dependencies | ||
turbo run build --filter=my-app... | ||
# Build 'my-app's dependencies, but not 'my-app' itself | ||
turbo run build --filter=my-app^... | ||
``` | ||
|
||
### Filter by directory or directory tree | ||
|
||
Supports exact matches (`--filter=./apps/docs`) and globs (`--filter=./apps/*`). | ||
When combined with other components, must be enclosed in `{}` (`--filter=...{./libs/*}`). | ||
|
||
```sh | ||
# Build all of the packages in the 'apps' directory | ||
turbo run build --filter=./apps/* | ||
# Build all of the packages in the 'libs' directory, and all the packages that depends on them | ||
turbo run build --filter=...{./libs/*} | ||
``` | ||
|
||
### Filter by changed packages | ||
|
||
Use the set of files changed since a specified commit to calculate packages. Enclose references in | ||
`[]`. For example, `--filter=[HEAD^1]` will select all packages that have changed in the most recent | ||
commit. | ||
|
||
You can use [`--ignore`](/docs/reference/command-line-reference#--ignore) to specify changed files to be ignored in the calculation of which packages have changed. | ||
|
||
You can additionally prepend the commit reference with `...` to match the dependencies of other components | ||
against the changed packages. For instance, to select `foo` if any of `foo`'s dependencies have changed in the last commit, | ||
you can pass `--filter=foo...[HEAD^1]`. Note that this feature is different from `pnpm`'s syntax. | ||
|
||
```sh | ||
# Test everything that changed in the last commit | ||
turbo run test --filter=[HEAD^1] | ||
# Build everything that depends on changes in branch 'my-feature' | ||
turbo run build --filter=...[origin/my-feature] | ||
# Build '@foo/bar' if it or any of its dependencies changed in the last commit | ||
turbo run build --filter=@foo/bar...[HEAD^1] | ||
# Test each package in the '@scope' scope that is in the 'packages' directory, if it has changed in the last commit | ||
turbo run test --filter=@scope/*{./packages/*}[HEAD^1] | ||
``` | ||
|
||
### Excluding packages | ||
|
||
Prepend `!` to the filter. Matched packages from the entire filter will be excluded from the set of targets. | ||
For example, match everything except `@foo/bar`: `--filter=!@foo/bar`. Note that you may need to escape `!` as appropriate for your shell (e.g. `\!`). | ||
|
||
```sh | ||
# Build everything except '@foo/bar' | ||
turbo run build --filter=!@foo/bar | ||
# Build all of the packages in the 'apps' directory, except the 'admin' package | ||
turbo run build --filter=./apps/* --filter=!admin | ||
``` | ||
|
||
<Callout type="idea" icon={<HeartIcon className="mt-1 h-5 w-5 text-gray-400" aria-hidden="true" />}> | ||
Turborepo's Filter API design and docs were/are inspired by | ||
[pnpm](https://pnpm.io/filtering) | ||
</Callout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"pipelines": "Pipelines", | ||
"scopes": "Scoped Tasks", | ||
"filtering": "Filtering Packages", | ||
"caching": "Caching", | ||
"remote-caching": "Remote Caching (Beta)" | ||
"remote-caching": "Remote Caching (Beta)", | ||
"scopes": { | ||
"hidden": true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.