diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index 937166db65204..20218dfdd30dd 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -4,16 +4,6 @@ import ( "bufio" "flag" "fmt" - "io" - "log" - "os" - "os/exec" - "path/filepath" - "sort" - "strconv" - "strings" - "sync" - "time" "github.com/vercel/turborepo/cli/internal/cache" "github.com/vercel/turborepo/cli/internal/config" "github.com/vercel/turborepo/cli/internal/context" @@ -27,6 +17,16 @@ import ( "github.com/vercel/turborepo/cli/internal/util" "github.com/vercel/turborepo/cli/internal/util/browser" "github.com/vercel/turborepo/cli/internal/util/filter" + "io" + "log" + "os" + "os/exec" + "path/filepath" + "sort" + "strconv" + "strings" + "sync" + "time" "github.com/pyr-sh/dag" @@ -873,7 +873,19 @@ func getScopedPackages(ctx *context.Context, scopePatterns []string) (scopePkgs if len(scopePatterns) == 0 { return scopePkgs, nil } - glob, err := filter.Compile(scopePatterns) + + include := make([]string, 0, len(scopePatterns)) + exclude := make([]string, 0, len(scopePatterns)) + + for _, pattern := range scopePatterns { + if strings.HasPrefix(pattern, "!") { + exclude = append(exclude, pattern[1:]) + } else { + include = append(include, pattern) + } + } + + glob, err := filter.NewIncludeExcludeFilter(include, exclude) if err != nil { return nil, err } diff --git a/cli/scripts/e2e/e2e.ts b/cli/scripts/e2e/e2e.ts index 8bed2151dc0a7..0e686fc974d93 100644 --- a/cli/scripts/e2e/e2e.ts +++ b/cli/scripts/e2e/e2e.ts @@ -189,6 +189,21 @@ function runSmokeTests( ) >= 0, "After running, changing source of b, and running `turbo run test` again, should print `c:test: cache hit, replaying output` since c should not be impacted by changes to b" ); + + const scopeCommandOutput = getCommandOutputAsArray( + repo.turbo("run", ["test", '--scope="!b"', "--stream"], options) + ); + + assert.fixture( + `• Packages in scope: a, c`, + scopeCommandOutput[0], + "Packages in scope" + ); + assert.fixture( + `• Running test in 2 packages`, + scopeCommandOutput[1], + "Runs only in changed packages" + ); } );