Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

compiler: automate regeneration of prelude #784

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

Merged
merged 11 commits into from
Apr 20, 2018
Prev Previous commit
Next Next commit
Use Output to exclusively read standard output from uglifyjs command
  • Loading branch information
myitcv committed Apr 20, 2018
commit 3de38f5a1cbc93f1aad88a5221735496df575b97
8 changes: 6 additions & 2 deletions 8 compiler/prelude/genmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
Expand Down Expand Up @@ -33,12 +34,15 @@ func run() error {
"--config-file",
filepath.Join(preludeDir, "uglifyjs_options.json"),
}

stderr := new(bytes.Buffer)
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = strings.NewReader(prelude.Prelude)
cmd.Stderr = stderr

byts, err := cmd.CombinedOutput()
byts, err := cmd.Output()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a big deal, but it's pretty unusual to see a []byte variable named byts. As far as I understand, it's a shortened version of "bytes"? It comes up a total of 5 times in the Go project.

In this context, just b or out would be more idiomatic and clear I think.

I see that out is already taken below, in that case, I would make this variable name more specific. For example, minified.

The reason I point this out is because I think it's a good idea to strive to write Go code that looks like Go code other Go programmers are most likely to write.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if err != nil {
return fmt.Errorf("failed to run %v: %v\n%s", strings.Join(args, " "), err, string(byts))
return fmt.Errorf("failed to run %v: %v\n%s", strings.Join(args, " "), err, stderr.String())
}

fn := "prelude_min.go"
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.