From 11dfe9cb7411c706a4feb1bf60ff538ac9616fe1 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Mon, 28 Aug 2023 14:11:03 -0700 Subject: [PATCH] remove fake topo nodes and fix tests --- cli/internal/core/engine.go | 11 ++++++++--- .../integration/tests/task-dependencies/complex.t | 11 ++--------- .../integration/tests/task-dependencies/topological.t | 3 +-- .../tests/task-dependencies/workspace-tasks.t | 5 +---- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/cli/internal/core/engine.go b/cli/internal/core/engine.go index 73c49e732969d..5df0be5a81de4 100644 --- a/cli/internal/core/engine.go +++ b/cli/internal/core/engine.go @@ -365,7 +365,13 @@ func (e *Engine) Prepare(options *EngineBuildingOptions) error { // hasTopoDeps will be true if the task depends on any tasks from dependency packages // E.g. `dev: { dependsOn: [^dev] }` - hasTopoDeps := topoDeps.Len() > 0 && e.completeGraph.WorkspaceGraph.DownEdges(pkg).Len() > 0 + nonRootDepPkgs := e.completeGraph.WorkspaceGraph.DownEdges(pkg).Filter(func(node interface{}) bool { + if packageName, ok := node.(string); ok { + return packageName != ROOT_NODE_NAME + } + return true + }) + hasTopoDeps := topoDeps.Len() > 0 && nonRootDepPkgs.Len() > 0 // hasDeps will be true if the task depends on any tasks from its own package // E.g. `build: { dependsOn: [dev] }` @@ -380,10 +386,9 @@ func (e *Engine) Prepare(options *EngineBuildingOptions) error { } if hasTopoDeps { - depPkgs := e.completeGraph.WorkspaceGraph.DownEdges(pkg) for _, from := range topoDeps.UnsafeListOfStrings() { // add task dep from all the package deps within repo - for depPkg := range depPkgs { + for depPkg := range nonRootDepPkgs { fromTaskID := util.GetTaskId(depPkg, from) e.TaskGraph.Add(fromTaskID) e.TaskGraph.Add(toTaskID) diff --git a/turborepo-tests/integration/tests/task-dependencies/complex.t b/turborepo-tests/integration/tests/task-dependencies/complex.t index e25a00a54cdea..d7372d14c8d88 100644 --- a/turborepo-tests/integration/tests/task-dependencies/complex.t +++ b/turborepo-tests/integration/tests/task-dependencies/complex.t @@ -22,12 +22,11 @@ We can scope the run to specific packages \tcompound = "true" (esc) \tnewrank = "true" (esc) \tsubgraph "root" { (esc) - \t\t"[root] ___ROOT___#build1" -> "[root] ___ROOT___" (esc) \t\t"[root] app-b#build1" -> "[root] lib-b#build1" (esc) \t\t"[root] app-b#build1" -> "[root] lib-c#build1" (esc) \t\t"[root] lib-b#build1" -> "[root] lib-d#build1" (esc) - \t\t"[root] lib-c#build1" -> "[root] ___ROOT___#build1" (esc) - \t\t"[root] lib-d#build1" -> "[root] ___ROOT___#build1" (esc) + \t\t"[root] lib-c#build1" -> "[root] ___ROOT___" (esc) + \t\t"[root] lib-d#build1" -> "[root] ___ROOT___" (esc) \t} (esc) } @@ -53,8 +52,6 @@ Complex dependency chain \tcompound = "true" (esc) \tnewrank = "true" (esc) \tsubgraph "root" { (esc) - \t\t"[root] ___ROOT___#build0" -> "[root] ___ROOT___#prepare" (esc) - \t\t"[root] ___ROOT___#prepare" -> "[root] ___ROOT___" (esc) \t\t"[root] app-a#prepare" -> "[root] ___ROOT___" (esc) \t\t"[root] app-a#test" -> "[root] app-a#prepare" (esc) \t\t"[root] app-a#test" -> "[root] lib-a#build0" (esc) @@ -72,15 +69,11 @@ Complex dependency chain \t\t"[root] lib-b#prepare" -> "[root] ___ROOT___" (esc) \t\t"[root] lib-b#test" -> "[root] lib-b#prepare" (esc) \t\t"[root] lib-b#test" -> "[root] lib-d#build0" (esc) - \t\t"[root] lib-c#build0" -> "[root] ___ROOT___#build0" (esc) \t\t"[root] lib-c#build0" -> "[root] lib-c#prepare" (esc) \t\t"[root] lib-c#prepare" -> "[root] ___ROOT___" (esc) - \t\t"[root] lib-c#test" -> "[root] ___ROOT___#build0" (esc) \t\t"[root] lib-c#test" -> "[root] lib-c#prepare" (esc) - \t\t"[root] lib-d#build0" -> "[root] ___ROOT___#build0" (esc) \t\t"[root] lib-d#build0" -> "[root] lib-d#prepare" (esc) \t\t"[root] lib-d#prepare" -> "[root] ___ROOT___" (esc) - \t\t"[root] lib-d#test" -> "[root] ___ROOT___#build0" (esc) \t\t"[root] lib-d#test" -> "[root] lib-d#prepare" (esc) \t} (esc) } diff --git a/turborepo-tests/integration/tests/task-dependencies/topological.t b/turborepo-tests/integration/tests/task-dependencies/topological.t index 9ec6043984cbb..a597500d34ddd 100644 --- a/turborepo-tests/integration/tests/task-dependencies/topological.t +++ b/turborepo-tests/integration/tests/task-dependencies/topological.t @@ -36,9 +36,8 @@ Graph \tnewrank = "true" (esc) \tsubgraph "root" { (esc) \t\t"[root] //#build" -> "[root] ___ROOT___" (esc) - \t\t"[root] ___ROOT___#build" -> "[root] ___ROOT___" (esc) \t\t"[root] my-app#build" -> "[root] util#build" (esc) - \t\t"[root] util#build" -> "[root] ___ROOT___#build" (esc) + \t\t"[root] util#build" -> "[root] ___ROOT___" (esc) \t} (esc) } diff --git a/turborepo-tests/integration/tests/task-dependencies/workspace-tasks.t b/turborepo-tests/integration/tests/task-dependencies/workspace-tasks.t index 3aaf57cba7cd7..29da443fc7cbb 100644 --- a/turborepo-tests/integration/tests/task-dependencies/workspace-tasks.t +++ b/turborepo-tests/integration/tests/task-dependencies/workspace-tasks.t @@ -27,11 +27,9 @@ Can depend on root tasks \tnewrank = "true" (esc) \tsubgraph "root" { (esc) \t\t"[root] //#exists" -> "[root] ___ROOT___" (esc) - \t\t"[root] ___ROOT___#build2" -> "[root] //#exists" (esc) \t\t"[root] workspace-a#build2" -> "[root] //#exists" (esc) \t\t"[root] workspace-a#build2" -> "[root] workspace-b#build2" (esc) \t\t"[root] workspace-b#build2" -> "[root] //#exists" (esc) - \t\t"[root] workspace-b#build2" -> "[root] ___ROOT___#build2" (esc) \t} (esc) } @@ -50,9 +48,8 @@ Package tasks can depend on things \tcompound = "true" (esc) \tnewrank = "true" (esc) \tsubgraph "root" { (esc) - \t\t"[root] ___ROOT___#build4" -> "[root] ___ROOT___" (esc) \t\t"[root] workspace-a#special" -> "[root] workspace-b#build4" (esc) - \t\t"[root] workspace-b#build4" -> "[root] ___ROOT___#build4" (esc) + \t\t"[root] workspace-b#build4" -> "[root] ___ROOT___" (esc) \t} (esc) }