diff --git a/cli/internal/graph/graph.go b/cli/internal/graph/graph.go index eff3f0dba13de..c834faec3870e 100644 --- a/cli/internal/graph/graph.go +++ b/cli/internal/graph/graph.go @@ -4,7 +4,6 @@ package graph import ( gocontext "context" "fmt" - "path/filepath" "regexp" "sort" "strings" @@ -124,8 +123,15 @@ func (g *CompleteGraph) GetPackageTaskVisitor( expandedInputs := g.TaskHashTracker.GetExpandedInputs(packageTask) framework := g.TaskHashTracker.GetFramework(taskID) - logFile := repoRelativeLogFile(pkgDir, taskName) - packageTask.LogFile = logFile + logFileAbsolutePath := taskLogFile(g.RepoRoot, pkgDir, taskName) + + var logFileRelativePath string + if logRelative, err := logFileAbsolutePath.RelativeTo(g.RepoRoot); err == nil { + logFileRelativePath = logRelative.ToString() + } + + // Give packageTask a string version of the logFile relative to root. + packageTask.LogFile = logFileRelativePath packageTask.Command = command envVarPassThroughMap, err := g.TaskHashTracker.EnvAtExecutionStart.FromWildcards(taskDefinition.PassThroughEnv) @@ -146,7 +152,8 @@ func (g *CompleteGraph) GetPackageTaskVisitor( Dir: pkgDir.ToString(), Outputs: taskDefinition.Outputs.Inclusions, ExcludedOutputs: taskDefinition.Outputs.Exclusions, - LogFile: logFile, + LogFileRelativePath: logFileRelativePath, + LogFileAbsolutePath: logFileAbsolutePath, ResolvedTaskDefinition: taskDefinition, ExpandedInputs: expandedInputs, ExpandedOutputs: []turbopath.AnchoredSystemPath{}, @@ -229,10 +236,10 @@ func (g *CompleteGraph) GetPackageJSONFromWorkspace(workspaceName string) (*fs.P return nil, fmt.Errorf("No package.json for %s", workspaceName) } -// repoRelativeLogFile returns the path to the log file for this task execution as a -// relative path from the root of the monorepo. -func repoRelativeLogFile(dir turbopath.AnchoredSystemPath, taskName string) string { - return filepath.Join(dir.ToStringDuringMigration(), ".turbo", fmt.Sprintf("turbo-%v.log", taskName)) +// taskLogFile returns the path to the log file for this task execution as an absolute path +func taskLogFile(root turbopath.AbsoluteSystemPath, dir turbopath.AnchoredSystemPath, taskName string) turbopath.AbsoluteSystemPath { + pkgDir := dir.RestoreAnchor(root) + return pkgDir.UntypedJoin(".turbo", fmt.Sprintf("turbo-%v.log", taskName)) } // getTaskGraphAncestors gets all the ancestors for a given task in the graph. diff --git a/cli/internal/runsummary/format_text.go b/cli/internal/runsummary/format_text.go index 619789d025f93..022bce85bd081 100644 --- a/cli/internal/runsummary/format_text.go +++ b/cli/internal/runsummary/format_text.go @@ -82,7 +82,7 @@ func (rsm Meta) FormatAndPrintText(workspaceInfos workspace.Catalog) error { fmt.Fprintln(w, util.Sprintf(" ${GREY}Command\t=\t%s\t${RESET}", task.Command)) fmt.Fprintln(w, util.Sprintf(" ${GREY}Outputs\t=\t%s\t${RESET}", strings.Join(task.Outputs, ", "))) - fmt.Fprintln(w, util.Sprintf(" ${GREY}Log File\t=\t%s\t${RESET}", task.LogFile)) + fmt.Fprintln(w, util.Sprintf(" ${GREY}Log File\t=\t%s\t${RESET}", task.LogFileRelativePath)) fmt.Fprintln(w, util.Sprintf(" ${GREY}Dependencies\t=\t%s\t${RESET}", strings.Join(task.Dependencies, ", "))) fmt.Fprintln(w, util.Sprintf(" ${GREY}Dependendents\t=\t%s\t${RESET}", strings.Join(task.Dependents, ", "))) fmt.Fprintln(w, util.Sprintf(" ${GREY}Inputs Files Considered\t=\t%d\t${RESET}", len(task.ExpandedInputs))) diff --git a/cli/internal/runsummary/task_summary.go b/cli/internal/runsummary/task_summary.go index 5282a9faf41d3..1973a752255df 100644 --- a/cli/internal/runsummary/task_summary.go +++ b/cli/internal/runsummary/task_summary.go @@ -1,8 +1,6 @@ package runsummary import ( - "os" - "github.com/vercel/turbo/cli/internal/cache" "github.com/vercel/turbo/cli/internal/fs" "github.com/vercel/turbo/cli/internal/turbopath" @@ -67,7 +65,8 @@ type TaskSummary struct { CommandArguments []string `json:"cliArguments"` Outputs []string `json:"outputs"` ExcludedOutputs []string `json:"excludedOutputs"` - LogFile string `json:"logFile"` + LogFileRelativePath string `json:"logFile"` + LogFileAbsolutePath turbopath.AbsoluteSystemPath `json:"-"` Dir string `json:"directory,omitempty"` Dependencies []string `json:"dependencies"` Dependents []string `json:"dependents"` @@ -80,9 +79,9 @@ type TaskSummary struct { Execution *TaskExecutionSummary `json:"execution,omitempty"` // omit when it's not set } -// GetLogs reads the Logfile and returns the data +// GetLogs reads the log file and returns the data func (ts *TaskSummary) GetLogs() []byte { - bytes, err := os.ReadFile(ts.LogFile) + bytes, err := ts.LogFileAbsolutePath.ReadFile() if err != nil { return []byte{} }