-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: automate regeneration of prelude (#784)
This is a rebase of #765. Whilst rebasing #669 I fell into a similar trap to #775 (#775 (comment)), by forgetting to commit the manually minified prelude. Then going through the manual process of manually minifying the prelude I wasted a whole load of time installing goexec, missing something the first time etc, issues that this PR addresses by automating the process, as previously discussed (#765 (comment)).
- Loading branch information
1 parent
27662f8
commit e1d10e7
Showing
7 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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" | ||
} | ||
} |