-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(cli): add colors back for cache hit log line #1346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -60,7 +61,7 @@ func AddFlags(opts *Opts, flags *pflag.FlagSet) { | |||
Value: &logsModeValue{opts: opts}, | |||
}) | |||
_ = flags.Bool("stream", true, "Unused") | |||
if err := flags.MarkDeprecated("stream", "[WARNING] The --stream flag is unnecesary and has been deprecated. It will be removed in future versions of turbo."); err != nil { | |||
if err := flags.MarkDeprecated("stream", "[WARNING] The --stream flag is unnecessary and has been deprecated. It will be removed in future versions of turbo."); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo fix
cli/internal/run/run.go
Outdated
@@ -796,7 +797,7 @@ func (e *execContext) exec(pt *nodes.PackageTask, deps dag.Set) error { | |||
return nil | |||
} | |||
// Cache --------------------------------------------- | |||
taskCache := e.runCache.TaskCache(pt, hash) | |||
taskCache := e.runCache.TaskCache(pt, hash, e.colorCache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the initialized colorCache instead of creating a new one so we get the same colors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this stays constant throughout the run, maybe the reference should be on RunCache
rather than TaskCache
? Or maybe instead of sharing the colorCache
, we should be sharing the prefix with the TaskCache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I think the RunCache
makes the most sense here.
2425986
to
6ad201c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely like moving the ColorCache
into its own package. However the rest of this goes, we should definitely do that.
cli/internal/runcache/runcache.go
Outdated
bufWriter := bufio.NewWriter(output) | ||
if _, err := bufWriter.WriteString(fmt.Sprintf("%s: cache hit, replaying output %s\n", tc.pt.OutputPrefix(), ui.Dim(tc.hash))); err != nil { | ||
if _, err := bufWriter.WriteString(fmt.Sprintf("%s: cache hit, replaying output %s\n", actualPrefix, ui.Dim(tc.hash))); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, are we already baking the color into the log files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not prebaking this:
turborepo/cli/internal/run/run.go
Line 827 in 1cfaff0
logger := log.New(writer, "", 0) |
cli/internal/run/run.go
Outdated
@@ -796,7 +797,7 @@ func (e *execContext) exec(pt *nodes.PackageTask, deps dag.Set) error { | |||
return nil | |||
} | |||
// Cache --------------------------------------------- | |||
taskCache := e.runCache.TaskCache(pt, hash) | |||
taskCache := e.runCache.TaskCache(pt, hash, e.colorCache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this stays constant throughout the run, maybe the reference should be on RunCache
rather than TaskCache
? Or maybe instead of sharing the colorCache
, we should be sharing the prefix with the TaskCache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally not the place for a feature request, but a feature request: my logs for a particular package are always the same color across runs.
With only five colors available this is likely a bad experience as incidents of mod(int(hash(packageName)), 5)
resulting in adjacent duplicate colors will be frequent, but in some future true color terminal world...
Only one review comment is actually intended to block.
@@ -1,4 +1,4 @@ | |||
package run | |||
package colorcache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd maybe go with colorcache.go
since that's how we'll see it in code every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, the file should technically be named colorcache.go
.
cli/internal/runcache/runcache.go
Outdated
@@ -225,8 +227,10 @@ func (tc TaskCache) OutputWriter() (io.WriteCloser, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
pref := tc.colorCache.PrefixColor(tc.pt.PackageName) | |||
actualPrefix := pref(tc.pt.OutputPrefix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
computedPrefix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using existing verbage to stay consistent -
https://github.com/vercel/turborepo/blob/main/cli/internal/run/run.go#L772
But I do like this better so I'll make this change everywhere.
cli/internal/runcache/runcache.go
Outdated
@@ -225,8 +227,10 @@ func (tc TaskCache) OutputWriter() (io.WriteCloser, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
pref := tc.colorCache.PrefixColor(tc.pt.PackageName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual strong opinion: pref
is wired to "preferences" In my brain, can we maybe call this prefixColor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pref
is a function here (given a string, it colors it) - so I might tweak this slightly to be colorPrefixer
cli/internal/runcache/runcache.go
Outdated
bufWriter := bufio.NewWriter(output) | ||
if _, err := bufWriter.WriteString(fmt.Sprintf("%s: cache hit, replaying output %s\n", tc.pt.OutputPrefix(), ui.Dim(tc.hash))); err != nil { | ||
if _, err := bufWriter.WriteString(fmt.Sprintf("%s: cache hit, replaying output %s\n", actualPrefix, ui.Dim(tc.hash))); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not prebaking this:
turborepo/cli/internal/run/run.go
Line 827 in 1cfaff0
logger := log.New(writer, "", 0) |
remove extra semicolon
6ad201c
to
9d17d14
Compare
9d17d14
to
03e60f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a winner to me.
Also @nathanhammond I didn't forget about your feature request. I want that too. But I think I'll tackle that as part of followup. A reliable method to go from task prefix to color would be awesome. |
Yeah, but it definitely doesn't belong in this PR. 😅 And |
@@ -1,4 +1,4 @@ | |||
package run | |||
package colorcache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, the file should technically be named colorcache.go
.
@@ -225,8 +228,10 @@ func (tc TaskCache) OutputWriter() (io.WriteCloser, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
colorPrefixer := tc.rc.colorCache.PrefixColor(tc.pt.PackageName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not worth fixing right now, but if we end up revamping how we do coloring and logging, I think it would be good to have this prefix generation done once per task.
We also have a task somewhere to stop baking prefix (and color) into log files, but that's definitely beyond the scope here.
@nathanhammond the lines immediately following that We should stop writing cache status, our color, and task prefix to the logs. |
@gsoltis At first glance it looked like there was already a layer of indirection with a Agreed that we should tweak behavior, capture the process output 1:1, and then decorate it when we output to |
Updates the behavior of the `--graph` CLI flag and fixes a few bugs. > This command will generate an svg, png, jpg, pdf, json, html, or [other supported output formats](https://graphviz.org/doc/info/output.html) of the current task graph. The output file format defaults to jpg, but can be controlled by specifying the filename's extension. > If Graphviz is not installed, or no filename is provided, this command prints the dot graph to `stdout` This PR also: 1. Updates docs to reflect the current state of the `--graph` CLI flag 1. Refactors the graph visualization code out of `run.go` 1. Cleans up the file name of colors_cache (follow up from #1346) Fixes #1286
Updates the behavior of the `--graph` CLI flag and fixes a few bugs. > This command will generate an svg, png, jpg, pdf, json, html, or [other supported output formats](https://graphviz.org/doc/info/output.html) of the current task graph. The output file format defaults to jpg, but can be controlled by specifying the filename's extension. > If Graphviz is not installed, or no filename is provided, this command prints the dot graph to `stdout` This PR also: 1. Updates docs to reflect the current state of the `--graph` CLI flag 1. Refactors the graph visualization code out of `run.go` 1. Cleans up the file name of colors_cache (follow up from vercel/turborepo#1346) Fixes vercel/turborepo#1286
Fixes a bug introduced in 1.2.10 in which the first line (cache hit) is missing the correct color.
Caused by #1256