Skip to content
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

Implement --filter RFC #887

Merged
merged 14 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ GO_FLAGS += "-ldflags=-s -w"
# Avoid embedding the build path in the executable for more reproducible builds
GO_FLAGS += -trimpath

turbo: cmd/turbo/version.go cmd/turbo/*.go internal/*/*.go go.mod
SRC_FILES = $(shell find . -name "*.go" | grep -v "_test.go")

turbo: $(SRC_FILES) go.mod
CGO_ENABLED=0 go build $(GO_FLAGS) ./cmd/turbo

# These tests are for development
Expand Down
18 changes: 16 additions & 2 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ Options:
--continue Continue execution even if a task exits with an error
or non-zero exit code. The default behavior is to bail
immediately. (default false)
--filter="<selector>" Use the given selector to specify package(s) to act as
entry points. The syntax mirror's pnpm's syntax, and
additional documentation and examples can be found in
turbo's documentation TODO: LINK.
--filter can be specified multiple times. Packages that
match any filter will be included.
--force Ignore the existing cache (to force execution).
(default false)
--graph Generate a Dot graph of the task execution.
Expand Down Expand Up @@ -190,7 +196,7 @@ func (c *RunCommand) Run(args []string) int {
return 1
}
}
filteredPkgs, err := scope.ResolvePackages(runOptions.ScopeOpts(), scmInstance, ctx, c.Ui, c.Config.Logger)
filteredPkgs, err := scope.ResolvePackages(runOptions.scopeOpts(), scmInstance, ctx, c.Ui, c.Config.Logger)
if err != nil {
c.logError(c.Config.Logger, "", fmt.Errorf("failed resolve packages to run %v", err))
}
Expand Down Expand Up @@ -405,6 +411,8 @@ func buildTaskGraph(topoGraph *dag.AcyclicGraph, pipeline map[string]fs.Pipeline
// RunOptions holds the current run operations configuration

type RunOptions struct {
// patterns supplied to --filter on the commandline
filterPatterns []string
// Whether to include dependent impacted consumers in execution (defaults to true)
includeDependents bool
// Whether to include includeDependencies (pkg.dependencies) in execution (defaults to false)
Expand Down Expand Up @@ -450,7 +458,7 @@ type RunOptions struct {
dryRunJson bool
}

func (ro *RunOptions) ScopeOpts() *scope.Opts {
func (ro *RunOptions) scopeOpts() *scope.Opts {
return &scope.Opts{
IncludeDependencies: ro.includeDependencies,
IncludeDependents: ro.includeDependents,
Expand All @@ -459,6 +467,7 @@ func (ro *RunOptions) ScopeOpts() *scope.Opts {
Cwd: ro.cwd,
IgnorePatterns: ro.ignore,
GlobalDepPatterns: ro.globalDeps,
FilterPatterns: ro.filterPatterns,
}
}

Expand Down Expand Up @@ -501,6 +510,11 @@ func parseRunArgs(args []string, cwd string, output cli.Ui) (*RunOptions, error)
break
} else if strings.HasPrefix(arg, "--") {
switch {
case strings.HasPrefix(arg, "--filter="):
filterPattern := arg[len("--filter="):]
if filterPattern != "" {
runOptions.filterPatterns = append(runOptions.filterPatterns, filterPattern)
}
case strings.HasPrefix(arg, "--since="):
if len(arg[len("--since="):]) > 0 {
runOptions.since = arg[len("--since="):]
Expand Down
16 changes: 16 additions & 0 deletions cli/internal/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ func TestParseConfig(t *testing.T) {
cacheMissLogsMode: FullLogs,
},
},
{
"can specify filter patterns",
[]string{"foo", "--filter=bar", "--filter=...[main]"},
&RunOptions{
includeDependents: true,
filterPatterns: []string{"bar", "...[main]"},
stream: true,
bail: true,
concurrency: 10,
cache: true,
cwd: defaultCwd,
cacheFolder: defaultCacheFolder,
cacheHitLogsMode: FullLogs,
cacheMissLogsMode: FullLogs,
},
},
}

ui := &cli.BasicUi{
Expand Down
Loading