bazelbuild / bazelbuild/rules_closure

Disable default externs

Open
#81 0 comments 1 reaction 1 assignee Claimed by @jart View on GitHub
redesign
Dominant language
Java
Stars
159
Forks
111
PR merge metrics
No merged PRs in 30d

Description

Closure Compiler by default is `--env=BROWSER` which causes 28,606 lines of `@externs` code to be added to each compilation. This has a _four second_ impact on compilation time. It can't really be optimized away because externs aren't namespaced. So we'd be better off if we:
1. Only load [es{3,5,6}.js](https://github.com/google/closure-compiler/tree/master/externs) by default, depending on the input language.
2. Define a `closure_js_library` for each [browser externs file](https://github.com/google/closure-compiler/tree/master/externs/browser), e.g. `//closure/externs/browser:html5`
3. Update `//closure/library` to have the _minimum number_ of deps on these externs. Break hard edges if possible. For example, if only one .js file in Closure Library depends on the gigantic `webgl.js` externs, then maybe that part of Closure Library should be broken out into a separate build rule.
4. Define a combined `//closure/externs/browser` rule for the lazy, that basically `exports` all the libraries in the package. Adding that as a dep will be equivalent to saying `--env=BROWSER`.
5. Repeat for [contrib externs](https://github.com/google/closure-compiler/tree/master/contrib/externs), e.g. `//closure/externs/contrib/angular:v1_5`, as per #51.
6. Write a `file_test()` that checks the directory listing of externs.zip so Closure Rules maintainers integrating a compiler new release can be informed when they need to update our externs rules.

This is a breaking change that deviates from the design chosen by the Closure Compiler team. I think this is a good idea for two reasons:
1. It makes compiles go four seconds faster.
2. It will teach new users about externs.

If the user gets an error saying, "hey! `document` is undefined. you probably want to depend on `@io_bazel_rules_closure//closure/externs/browser:window`!" Then he's going to wonder what externs are. He'll read the file. See how Closure rigorously defines type information for everything—even code that isn't in the compilation. And then he's going to begin to _understand_ the Closure Compiler and why it is good.

Blocked by: #80

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.