Skip to content

Commit 51cfb5f

Browse files
devversiontinayuangao
authored andcommitted
build: run closure-compiler (#3789)
* build: run closure-compiler * Adds a script that runs the closure-compiler against the devapp / demo-app. * The script will run on the CI as a new mode. Ensuring that all our components are closure-compatible. Fixes #1206. * Address feedback
1 parent d7d2b16 commit 51cfb5f

File tree

6 files changed

+118
-1
lines changed

6 files changed

+118
-1
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ env:
2727
# Order: a slower build first, so that we don't occupy an idle travis worker waiting for others to complete.
2828
- MODE=lint
2929
- MODE=aot
30+
- MODE=closure-compiler
3031
- MODE=payload
3132
- MODE=e2e
3233
- MODE=saucelabs_required

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@
6060
"conventional-changelog": "^1.1.0",
6161
"dgeni": "^0.4.7",
6262
"dgeni-packages": "^0.16.5",
63+
"firebase": "^3.7.2",
6364
"firebase-admin": "^4.1.2",
6465
"firebase-tools": "^2.2.1",
65-
"firebase": "^3.7.2",
6666
"fs-extra": "^2.0.0",
6767
"glob": "^7.1.1",
68+
"google-closure-compiler": "^20170218.0.0",
6869
"google-cloud": "^0.48.0",
6970
"gulp": "^3.9.1",
7071
"gulp-clean": "^0.3.2",

scripts/ci/build-and-test.sh

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ elif is_aot; then
2121
$(npm bin)/gulp ci:aot
2222
elif is_payload; then
2323
$(npm bin)/gulp ci:payload
24+
elif is_closure_compiler; then
25+
./scripts/closure-compiler/build-devapp-bundle.sh
2426
else
2527
$(npm bin)/gulp ci:test
2628
fi

scripts/ci/sources/mode.sh

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ is_aot() {
1313
[[ "$MODE" = aot ]]
1414
}
1515

16+
is_closure_compiler() {
17+
[[ "$MODE" = closure-compiler ]]
18+
}
19+
1620
is_payload() {
1721
[[ "$MODE" = payload ]]
1822
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
# Script that bundles the dev-app using the Google Closure compiler.
4+
# This is script is used to verify closure-compatiblity of all Material components.
5+
6+
set -e -o pipefail
7+
8+
# Go to the project root directory
9+
cd $(dirname $0)/../..
10+
11+
# Build the demo-app and also create the release output.
12+
$(npm bin)/gulp build:devapp
13+
$(npm bin)/gulp :package:release
14+
15+
# Rebuild demo-app with ES2015 modules. Closure compiler is then able to parse imports.
16+
$(npm bin)/tsc -p src/demo-app/ --target ES2015 --module ES2015
17+
18+
# Re-compile RxJS sources into ES2015. Otherwise closure compiler can't parse it properly.
19+
$(npm bin)/ngc -p scripts/closure-compiler/tsconfig-rxjs.json
20+
21+
# Create a list of all RxJS source files.
22+
rxjsSourceFiles=$(find dist/packages/rxjs -name '*.js');
23+
24+
# Due a Closure Compiler issue https://github.com/google/closure-compiler/issues/2247
25+
# we need to add exports to the different RxJS ES2015 files.
26+
for i in $rxjsSourceFiles; do
27+
echo "export var __CLOSURE_WORKAROUND__" >> $i
28+
done
29+
30+
OPTS=(
31+
"--language_in=ES6_STRICT"
32+
"--language_out=ES5"
33+
"--compilation_level=ADVANCED_OPTIMIZATIONS"
34+
"--js_output_file=dist/closure/closure-bundle.js"
35+
"--variable_renaming_report=dist/closure/variable_renaming_report"
36+
"--property_renaming_report=dist/closure/property_renaming_report"
37+
"--warning_level=QUIET"
38+
"--rewrite_polyfills=false"
39+
40+
# List of path prefixes to be removed from ES6 & CommonJS modules.
41+
"--js_module_root=dist/packages"
42+
"--js_module_root=dist/release"
43+
"--js_module_root=node_modules/@angular/core"
44+
"--js_module_root=node_modules/@angular/common"
45+
"--js_module_root=node_modules/@angular/compiler"
46+
"--js_module_root=node_modules/@angular/forms"
47+
"--js_module_root=node_modules/@angular/http"
48+
"--js_module_root=node_modules/@angular/router"
49+
"--js_module_root=node_modules/@angular/platform-browser"
50+
"--js_module_root=node_modules/@angular/platform-browser/animations"
51+
"--js_module_root=node_modules/@angular/platform-browser-dynamic"
52+
"--js_module_root=node_modules/@angular/animations"
53+
"--js_module_root=node_modules/@angular/animations/browser"
54+
55+
# Flags to simplify debugging.
56+
"--formatting=PRETTY_PRINT"
57+
"--debug"
58+
59+
# Include the Material FESM bundle
60+
dist/release/@angular/material.js
61+
62+
# Include all Angular FESM bundles.
63+
node_modules/@angular/core/@angular/core.js
64+
node_modules/@angular/common/@angular/common.js
65+
node_modules/@angular/compiler/@angular/compiler.js
66+
node_modules/@angular/forms/@angular/forms.js
67+
node_modules/@angular/http/@angular/http.js
68+
node_modules/@angular/router/@angular/router.js
69+
node_modules/@angular/platform-browser/@angular/platform-browser.js
70+
node_modules/@angular/platform-browser/@angular/platform-browser/animations.js
71+
node_modules/@angular/platform-browser-dynamic/@angular/platform-browser-dynamic.js
72+
node_modules/@angular/animations/@angular/animations.js
73+
node_modules/@angular/animations/@angular/animations/browser.js
74+
75+
# Include other dependencies like Zone.js and RxJS
76+
node_modules/zone.js/dist/zone.js
77+
$rxjsSourceFiles
78+
79+
# Include all files from the demo-app package.
80+
$(find dist/packages/demo-app -name '*.js')
81+
82+
"--entry_point=./dist/packages/demo-app/main.js"
83+
"--dependency_mode=STRICT"
84+
)
85+
86+
# Write closure flags to a closure flagfile.
87+
closureFlags=$(mktemp)
88+
echo ${OPTS[*]} > $closureFlags
89+
90+
# Run the Google Closure compiler java runnable.
91+
java -jar node_modules/google-closure-compiler/compiler.jar --flagfile $closureFlags
92+
93+
echo "Finished bundling the dev-app using google closure compiler.."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"outDir": "../../dist/packages/rxjs",
5+
"target": "es5",
6+
"lib": ["es2015", "dom"]
7+
},
8+
"files": [
9+
"../../node_modules/rxjs/src/Rx.ts"
10+
],
11+
"angularCompilerOptions": {
12+
"annotateForClosureCompiler": true,
13+
"skipMetadataEmit": true,
14+
"skipTemplateCodegen": true
15+
}
16+
}

0 commit comments

Comments
 (0)