diff --git a/cli/integration_tests/basic_monorepo/filter-run.t b/cli/integration_tests/basic_monorepo/filter-run.t index 527e8f2f6091d..c0dde95ffff72 100644 --- a/cli/integration_tests/basic_monorepo/filter-run.t +++ b/cli/integration_tests/basic_monorepo/filter-run.t @@ -2,8 +2,8 @@ Setup $ . ${TESTDIR}/../setup.sh $ . ${TESTDIR}/setup.sh $(pwd) -# Running with --filter works and exits - $ ${TURBO} run build --filter=main +# Running with --filter works and exits with success + $ ${TURBO} run build --filter="[main]" \xe2\x80\xa2 Packages in scope: (esc) \xe2\x80\xa2 Running build in 0 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc) @@ -13,4 +13,18 @@ Setup Tasks: 0 successful, 0 total Cached: 0 cached, 0 total Time:\s*[\.0-9]+m?s (re) + + +# with unstaged changes + $ echo "new file contents" >> bar.txt + $ ${TURBO} run build --filter="[main]" + \xe2\x80\xa2 Packages in scope: // (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + No tasks were executed as part of this run. + + Tasks: 0 successful, 0 total + Cached: 0 cached, 0 total + Time:\s*[\.0-9]+m?s (re) \ No newline at end of file diff --git a/cli/integration_tests/basic_monorepo/monorepo/bar.txt b/cli/integration_tests/basic_monorepo/monorepo/bar.txt new file mode 100644 index 0000000000000..5e849f85df5d1 --- /dev/null +++ b/cli/integration_tests/basic_monorepo/monorepo/bar.txt @@ -0,0 +1 @@ +other file, not a global dependency diff --git a/cli/integration_tests/setup_git.sh b/cli/integration_tests/setup_git.sh index 369df608c8a4f..b38301162863c 100755 --- a/cli/integration_tests/setup_git.sh +++ b/cli/integration_tests/setup_git.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash TARGET_DIR=$1 -git init ${TARGET_DIR} --quiet +git init ${TARGET_DIR} --quiet --initial-branch=main GIT_ARGS="--git-dir=${TARGET_DIR}/.git --work-tree=${TARGET_DIR}" git ${GIT_ARGS} config user.email "turbo-test@example.com" git ${GIT_ARGS} config user.name "Turbo Test" diff --git a/cli/internal/core/engine.go b/cli/internal/core/engine.go index 49dc8624aee8f..068be341015cb 100644 --- a/cli/internal/core/engine.go +++ b/cli/internal/core/engine.go @@ -172,27 +172,39 @@ func (e *Engine) Prepare(options *EngineBuildingOptions) error { // We do this by taking the input taskNames, and pkgs // and creating a queue of taskIDs that we can traverse and gather dependencies from. for _, pkg := range pkgs { - isRootPkg := pkg == util.RootPkgName for _, taskName := range taskNames { - // If it's not a task from the root workspace (i.e. tasks from every other workspace) - // or if it's a task that we know is rootEnabled task, add it to the traversal queue. - if !isRootPkg || e.rootEnabledTasks.Includes(taskName) { - taskID := util.GetTaskId(pkg, taskName) - // Skip tasks that don't have a definition - if _, err := e.getTaskDefinition(pkg, taskName, taskID); err != nil { - var e *MissingTaskError - if errors.As(err, &e) { - // Initially, non-package tasks are not required to exist, as long as some - // package in the list packages defines it as a package-task. Dependencies - // *are* required to have a definition. - continue - } - - return err + taskID := util.GetTaskId(pkg, taskName) + + // Look up the task in the package + foundTask, err := e.getTaskDefinition(pkg, taskName, taskID) + + // We can skip MissingTaskErrors because we'll validate against them later + // Return all other errors + if err != nil { + var e *MissingTaskError + if errors.As(err, &e) { + // Initially, non-package tasks are not required to exist, as long as some + // package in the list packages defines it as a package-task. Dependencies + // *are* required to have a definition. + continue } + + return err + } + + // If we found a task definition, remove it from the missing list + if foundTask != nil { // delete taskName if it was found missing.Delete(taskName) - traversalQueue = append(traversalQueue, taskID) + + // Even if a task definition was found, we _only_ want to add it as an entry point to + // the task graph (i.e. the traversalQueue), if it's: + // - A task from the non-root workspace (i.e. tasks from every other workspace) + // - A task that we *know* is rootEnabled task (in which case, the root workspace is acceptable) + isRootPkg := pkg == util.RootPkgName + if !isRootPkg || e.rootEnabledTasks.Includes(taskName) { + traversalQueue = append(traversalQueue, taskID) + } } } }