Use Java version of Google Closure Compiler (#12800)
* makes closure compiler threaded * Dans PR with a closure compiler java version * Remove unused dep * Pin GCC * Prettier * Nit rename * Fix error handling * Name plugins consistently * Fix lint * Maybe this works? * or this * AppVeyor * Fix lint
Dan Abramov committed
May 14, 2018 at 17:49 UTC
72542030cffee83ac359374a5e7cec9742183b11
8 files changed
+71
-45
.circleci/config.yml
+1
-1
@@ -3,7 +3,7 @@ jobs:
3
build:
4
5
docker:
6
- - image: circleci/node:8
6
+ - image: circleci/openjdk:8-jdk-node-browsers
7
8
environment:
9
TZ: /usr/share/zoneinfo/America/Los_Angeles
appveyor.yml
+2
-2
@@ -5,8 +5,8 @@ init:
5
- git config --global core.autocrlf input
6
7
environment:
8
- matrix:
9
- - nodejs_version: 8
8
+ nodejs_version: 8
9
+ JAVA_HOME: C:\Program Files\Java\jdk1.8.0
10
11
# Finish on first failed build
12
matrix:
package.json
+1
-1
@@ -65,6 +65,7 @@
65
"git-branch": "^0.3.0",
66
"glob": "^6.0.4",
67
"glob-stream": "^6.1.0",
68
+ "google-closure-compiler": "20180506.0.0",
69
"gzip-js": "~0.3.2",
70
"gzip-size": "^3.0.0",
71
"jasmine-check": "^1.0.0-rc.0",
@@ -84,7 +85,6 @@
85
"rimraf": "^2.6.1",
86
"rollup": "^0.52.1",
87
"rollup-plugin-babel": "^3.0.1",
87
- "rollup-plugin-closure-compiler-js": "^1.0.6",
88
"rollup-plugin-commonjs": "^8.2.6",
89
"rollup-plugin-node-resolve": "^2.1.1",
90
"rollup-plugin-prettier": "^0.3.0",
scripts/rollup/build.js
+14
-14
@@ -2,7 +2,7 @@
2
3
const {rollup} = require('rollup');
4
const babel = require('rollup-plugin-babel');
5
-const closure = require('rollup-plugin-closure-compiler-js');
5
+const closure = require('./plugins/closure-plugin');
6
const commonjs = require('rollup-plugin-commonjs');
7
const prettier = require('rollup-plugin-prettier');
8
const replace = require('rollup-plugin-replace');
@@ -62,15 +62,15 @@ const errorCodeOpts = {
62
};
63
64
const closureOptions = {
65
- compilationLevel: 'SIMPLE',
66
- languageIn: 'ECMASCRIPT5_STRICT',
67
- languageOut: 'ECMASCRIPT5_STRICT',
65
+ compilation_level: 'SIMPLE',
66
+ language_in: 'ECMASCRIPT5_STRICT',
67
+ language_out: 'ECMASCRIPT5_STRICT',
68
env: 'CUSTOM',
69
- warningLevel: 'QUIET',
70
- applyInputSourceMaps: false,
71
- useTypesForOptimization: false,
72
- processCommonJsModules: false,
73
- rewritePolyfills: false,
69
+ warning_level: 'QUIET',
70
+ apply_input_source_maps: false,
71
+ use_types_for_optimization: false,
72
+ process_common_js_modules: false,
73
+ rewrite_polyfills: false,
74
};
75
76
function getBabelConfig(updateBabelOptions, bundleType, filename) {
@@ -264,7 +264,7 @@ function getPlugins(
264
Object.assign({}, closureOptions, {
265
// Don't let it create global variables in the browser.
266
// https://github.com/facebook/react/issues/10909
267
- assumeFunctionWrapper: !isInGlobalScope,
267
+ assume_function_wrapper: !isInGlobalScope,
268
// Works because `google-closure-compiler-js` is forked in Yarn lockfile.
269
// We can remove this if GCC merges my PR:
270
// https://github.com/google/closure-compiler/pull/2707
@@ -460,9 +460,9 @@ function handleRollupError(error) {
460
console.error(
461
`\x1b[31m-- ${error.code}${error.plugin ? ` (${error.plugin})` : ''} --`
462
);
463
- console.error(error.message);
464
- const {file, line, column} = error.loc;
465
- if (file) {
463
+ console.error(error.stack);
464
+ if (error.loc && error.loc.file) {
465
+ const {file, line, column} = error.loc;
466
// This looks like an error from Rollup, e.g. missing export.
467
// We'll use the accurate line numbers provided by Rollup but
468
// use Babel code frame because it looks nicer.
@@ -473,7 +473,7 @@ function handleRollupError(error) {
473
highlightCode: true,
474
});
475
console.error(frame);
476
- } else {
476
+ } else if (error.codeFrame) {
477
// This looks like an error from a plugin (e.g. Babel).
478
// In this case we'll resort to displaying the provided code frame
479
// because we can't be sure the reported location is accurate.
scripts/rollup/plugins/closure-plugin.js
new
+35
@@ -0,0 +1,35 @@
1
+'use strict';
2
+
3
+const ClosureCompiler = require('google-closure-compiler').compiler;
4
+const {promisify} = require('util');
5
+const fs = require('fs');
6
+const tmp = require('tmp');
7
+const writeFileAsync = promisify(fs.writeFile);
8
+
9
+function compile(flags) {
10
+ return new Promise((resolve, reject) => {
11
+ const closureCompiler = new ClosureCompiler(flags);
12
+ closureCompiler.run(function(exitCode, stdOut, stdErr) {
13
+ if (!stdErr) {
14
+ resolve(stdOut);
15
+ } else {
16
+ reject(new Error(stdErr));
17
+ }
18
+ });
19
+ });
20
+}
21
+
22
+module.exports = function closure(flags = {}) {
23
+ return {
24
+ name: 'scripts/rollup/plugins/closure-plugin',
25
+ async transformBundle(code) {
26
+ const inputFile = tmp.fileSync();
27
+ const tempPath = inputFile.name;
28
+ flags = Object.assign({}, flags, {js: tempPath});
29
+ await writeFileAsync(tempPath, code, 'utf8');
30
+ const compiledCode = await compile(flags);
31
+ inputFile.removeCallback();
32
+ return {code: compiledCode};
33
+ },
34
+ };
35
+};
scripts/rollup/plugins/sizes-plugin.js
+1
@@ -10,6 +10,7 @@ const gzip = require('gzip-size');
10
11
module.exports = function sizes(options) {
12
return {
13
+ name: 'scripts/rollup/plugins/sizes-plugin',
14
ongenerate(bundle, obj) {
15
const size = Buffer.byteLength(obj.code);
16
const gzipSize = gzip.sync(obj.code);
scripts/rollup/plugins/use-forks-plugin.js
+1
@@ -37,6 +37,7 @@ function useForks(forks) {
37
);
38
});
39
return {
40
+ name: 'scripts/rollup/plugins/use-forks-plugin',
41
resolveId(importee, importer) {
42
if (!importer || !importee) {
43
return null;
yarn.lock
+16
-27
@@ -2548,13 +2548,13 @@ glogg@^1.0.0:
2548
dependencies:
2549
sparkles "^1.0.0"
2550
2551
-google-closure-compiler-js@>20170000:
2552
- version "20180402.0.0"
2553
- resolved "https://registry.yarnpkg.com/google-closure-compiler-js/-/google-closure-compiler-js-20180402.0.0.tgz#b90ee11c597030b90ed1c6a054dd728aba81ab2d"
2551
+google-closure-compiler@20180506.0.0:
2552
+ version "20180506.0.0"
2553
+ resolved "https://registry.yarnpkg.com/google-closure-compiler/-/google-closure-compiler-20180506.0.0.tgz#f59cc34dbf8c9a4f48fba3ebb2cf098d25e345ab"
2554
dependencies:
2555
- minimist "^1.2.0"
2555
+ chalk "^1.0.0"
2556
vinyl "^2.0.1"
2557
- webpack-core "^0.6.8"
2557
+ vinyl-sourcemaps-apply "^0.2.0"
2558
2559
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4:
2560
version "4.1.11"
@@ -4814,12 +4814,6 @@ rollup-plugin-babel@^3.0.1:
4814
dependencies:
4815
rollup-pluginutils "^1.5.0"
4816
4817
-rollup-plugin-closure-compiler-js@^1.0.6:
4818
- version "1.0.6"
4819
- resolved "https://registry.yarnpkg.com/rollup-plugin-closure-compiler-js/-/rollup-plugin-closure-compiler-js-1.0.6.tgz#58e3e31297ad1a532d9114108bc06f2756d72c3d"
4820
- dependencies:
4821
- google-closure-compiler-js ">20170000"
4822
-
4817
rollup-plugin-commonjs@^8.2.6:
4818
version "8.2.6"
4819
resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-8.2.6.tgz#27e5b9069ff94005bb01e01bb46a1e4873784677"
@@ -5007,10 +5001,6 @@ sntp@2.x.x:
5001
dependencies:
5002
hoek "4.x.x"
5003
5010
-source-list-map@~0.1.7:
5011
- version "0.1.8"
5012
- resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"
5013
-
5004
source-map-support@^0.2.10:
5005
version "0.2.10"
5006
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.2.10.tgz#ea5a3900a1c1cb25096a0ae8cc5c2b4b10ded3dc"
@@ -5035,7 +5025,7 @@ source-map@0.1.32:
5025
dependencies:
5026
amdefine ">=0.0.4"
5027
5038
-source-map@^0.4.4, source-map@~0.4.0, source-map@~0.4.1, source-map@~0.4.2:
5028
+source-map@^0.4.4, source-map@~0.4.0, source-map@~0.4.2:
5029
version "0.4.4"
5030
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
5031
dependencies:
@@ -5045,14 +5035,14 @@ source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.0, sour
5035
version "0.5.6"
5036
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
5037
5038
+source-map@^0.5.1, source-map@~0.5.6:
5039
+ version "0.5.7"
5040
+ resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
5041
+
5042
source-map@^0.6.0:
5043
version "0.6.1"
5044
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
5045
5052
-source-map@~0.5.6:
5053
- version "0.5.7"
5054
- resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
5055
-
5046
sparkles@^1.0.0:
5047
version "1.0.0"
5048
resolved "https://registry.yarnpkg.com/sparkles/-/sparkles-1.0.0.tgz#1acbbfb592436d10bbe8f785b7cc6f82815012c3"
@@ -5546,6 +5536,12 @@ verror@1.3.6:
5536
dependencies:
5537
extsprintf "1.0.2"
5538
5539
+vinyl-sourcemaps-apply@^0.2.0:
5540
+ version "0.2.1"
5541
+ resolved "https://registry.yarnpkg.com/vinyl-sourcemaps-apply/-/vinyl-sourcemaps-apply-0.2.1.tgz#ab6549d61d172c2b1b87be5c508d239c8ef87705"
5542
+ dependencies:
5543
+ source-map "^0.5.1"
5544
+
5545
vinyl@^0.5.0:
5546
version "0.5.3"
5547
resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-0.5.3.tgz#b0455b38fc5e0cf30d4325132e461970c2091cde"
@@ -5591,13 +5587,6 @@ webidl-conversions@^4.0.1, webidl-conversions@^4.0.2:
5587
version "4.0.2"
5588
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
5589
5594
-webpack-core@^0.6.8:
5595
- version "0.6.9"
5596
- resolved "https://registry.yarnpkg.com/webpack-core/-/webpack-core-0.6.9.tgz#fc571588c8558da77be9efb6debdc5a3b172bdc2"
5597
- dependencies:
5598
- source-list-map "~0.1.7"
5599
- source-map "~0.4.1"
5600
-
5590
whatwg-encoding@^1.0.1:
5591
version "1.0.1"
5592
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.1.tgz#3c6c451a198ee7aec55b1ec61d0920c67801a5f4"