Skip to content

Commit

Permalink
Implement --filter RFC (#887)
Browse files Browse the repository at this point in the history
Implement #105
  • Loading branch information
Greg Soltis authored Mar 23, 2022
1 parent 9d8c2a5 commit 6ac2a24
Show file tree
Hide file tree
Showing 11 changed files with 1,474 additions and 240 deletions.
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

1 comment on commit 6ac2a24

@vercel
Copy link

@vercel vercel bot commented on 6ac2a24 Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.