-
Notifications
You must be signed in to change notification settings - Fork 570
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7b58396
Example of regenerated minified files
myitcv 3e59050
Address feedback from shurcooL
myitcv 608b874
Fix name of prelude generator in output file
myitcv de4b2cb
Don't require user to have set PATH; derive path to uglify js from
myitcv f5861c4
No need to set PATH in circle.yml now
myitcv 854f5a7
Fix error message in genmin.go
myitcv 7a4eb53
Address feedback from hajimehoshi
myitcv 1e68e31
Recommit feedback for @hajimehoshi
myitcv 3de38f5
Use Output to exclusively read standard output from uglifyjs command
myitcv 4db25b2
Make comments option match hand-driven version
myitcv dad80cd
Address style feedback
myitcv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"go/build" | ||
"io/ioutil" | ||
"log" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/gopherjs/gopherjs/compiler/prelude" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func run() error { | ||
bpkg, err := build.Import("github.com/gopherjs/gopherjs", "", build.FindOnly) | ||
if err != nil { | ||
return fmt.Errorf("failed to locate path for github.com/gopherjs/gopherjs: %v", err) | ||
} | ||
|
||
preludeDir := filepath.Join(bpkg.Dir, "compiler", "prelude") | ||
|
||
args := []string{ | ||
filepath.Join(bpkg.Dir, "node_modules", ".bin", "uglifyjs"), | ||
"--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 | ||
|
||
out, err := cmd.Output() | ||
if err != nil { | ||
return fmt.Errorf("failed to run %v: %v\n%s", strings.Join(args, " "), err, stderr.String()) | ||
} | ||
|
||
fn := "prelude_min.go" | ||
|
||
outStr := fmt.Sprintf(`// Code generated by genmin; DO NOT EDIT. | ||
|
||
package prelude | ||
|
||
// Minified is an uglifyjs-minified version of Prelude. | ||
const Minified = %q | ||
`, out) | ||
|
||
if err := ioutil.WriteFile(fn, []byte(outStr), 0644); err != nil { | ||
return fmt.Errorf("failed to write to %v: %v", fn, err) | ||
} | ||
|
||
return nil | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"compress": { | ||
"arrows": true, | ||
"booleans": true, | ||
"collapse_vars": true, | ||
"comparisons": true, | ||
"computed_props": true, | ||
"conditionals": true, | ||
"dead_code": true, | ||
"drop_console": false, | ||
"drop_debugger": true, | ||
"ecma": 5, | ||
"evaluate": true, | ||
"expression": false, | ||
"global_defs": {}, | ||
"hoist_funs": false, | ||
"hoist_props": true, | ||
"hoist_vars": false, | ||
"ie8": false, | ||
"if_return": true, | ||
"inline": true, | ||
"join_vars": true, | ||
"keep_classnames": false, | ||
"keep_fargs": true, | ||
"keep_fnames": false, | ||
"keep_infinity": false, | ||
"loops": true, | ||
"negate_iife": true, | ||
"passes": 1, | ||
"properties": true, | ||
"pure_funcs": null, | ||
"pure_getters": "strict", | ||
"reduce_funcs": true, | ||
"reduce_vars": true, | ||
"sequences": true, | ||
"side_effects": true, | ||
"switches": true, | ||
"top_retain": null, | ||
"toplevel": false, | ||
"typeofs": true, | ||
"unsafe": false, | ||
"unsafe_Function": false, | ||
"unsafe_arrows": false, | ||
"unsafe_comps": false, | ||
"unsafe_math": false, | ||
"unsafe_methods": false, | ||
"unsafe_proto": false, | ||
"unsafe_regexp": false, | ||
"unsafe_undefined": false, | ||
"unused": true, | ||
"warnings": false | ||
}, | ||
"mangle": { | ||
"eval": false, | ||
"ie8": false, | ||
"keep_classnames": false, | ||
"keep_fnames": false, | ||
"properties": false, | ||
"reserved": [], | ||
"safari10": false, | ||
"toplevel": false | ||
}, | ||
"output": { | ||
"ascii_only": false, | ||
"beautify": false, | ||
"bracketize": false, | ||
"comments": "/@license|@preserve|^!/", | ||
"ecma": 5, | ||
"ie8": false, | ||
"indent_level": 4, | ||
"indent_start": 0, | ||
"inline_script": true, | ||
"keep_quoted_props": false, | ||
"max_line_len": false, | ||
"preamble": null, | ||
"preserve_line": false, | ||
"quote_keys": false, | ||
"quote_style": 0, | ||
"safari10": false, | ||
"semicolons": true, | ||
"shebang": true, | ||
"source_map": null, | ||
"webkit": false, | ||
"width": 80, | ||
"wrap_iife": false | ||
}, | ||
"parse": { | ||
"bare_returns": false, | ||
"ecma": 8, | ||
"expression": false, | ||
"filename": null, | ||
"html5_comments": true, | ||
"shebang": true, | ||
"strict": false, | ||
"toplevel": null | ||
}, | ||
"wrap": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "gopherjs", | ||
"devDependencies": { | ||
"uglify-es": "3.3.9" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
bpkg.Dir
is not a very readable name here. I would've copied theimportPathToDir
helper from:gopherjs/compiler/natives/fs.go
Lines 15 to 21 in e14987c
Then code above can be
gopherjsRoot := importPathToDir("github.com/gopherjs/gopherjs")
, and this line can befilepath.Join(gopherjsRoot, "node_modules", ".bin", "uglifyjs")
.In theory, you could also just resolve both dirs directly via
importPathToDir("github.com/gopherjs/gopherjs/compiler/prelude")
andimportPathToDir("github.com/gopherjs/gopherjs/node_modules/.bin")
.importPathToDir
can resolve any existing directory in a GOPATH workspace, it doesn't need to be a valid Go package.Not a big deal, just pointing it out.
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 tend to disagree; using
go/build
a lot, it feels very idiomatic to do exactly this sort of resolution. Wrapping exactly the same behaviour in a function just adds to the non-exported API surface and therefore cognitive overhead to my mind (i.e. I have to remember thatimportPathToDir
exists and to then use it). So I'll leave as is if that's ok with you.