Skip to content

Commit 79b0927

Browse files
committed
feat(examples): add closure compiler example
1 parent 1ee00e6 commit 79b0927

12 files changed

Lines changed: 397 additions & 6 deletions

File tree

examples/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ example_integration_test(
5858
},
5959
)
6060

61+
example_integration_test(
62+
name = "examples_closure",
63+
)
64+
6165
example_integration_test(
6266
name = "examples_parcel",
6367
npm_packages = {

examples/closure/.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

examples/closure/.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import %workspace%/../../common.bazelrc

examples/closure/BUILD.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
2+
load("@npm//google-closure-compiler:index.bzl", "google_closure_compiler")
3+
4+
google_closure_compiler(
5+
name = "closure",
6+
outs = ["bundle.js"],
7+
args = [
8+
# workaround https://github.com/google/closure-compiler-npm/issues/147
9+
# --platform native would be faster but is failing on Windows
10+
"--platform=javascript",
11+
"--js=$(location hello.js)",
12+
"--js_output_file=$(location bundle.js)",
13+
],
14+
data = ["hello.js"],
15+
)
16+
17+
nodejs_test(
18+
name = "test",
19+
data = ["bundle.js"],
20+
entry_point = "test.js",
21+
)
22+
23+
# For testing from the root workspace of this repository with bazel_integration_test.
24+
filegroup(
25+
name = "all_files",
26+
srcs = glob(["*"]),
27+
visibility = ["//visibility:public"],
28+
)

examples/closure/WORKSPACE

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2019 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
workspace(
16+
name = "examples_closure",
17+
managed_directories = {"@npm": ["node_modules"]},
18+
)
19+
20+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
21+
22+
http_archive(
23+
name = "build_bazel_rules_nodejs",
24+
sha256 = "1249a60f88e4c0a46d78de06be04d3d41e7421dcfa0c956de65309a7b7ecf6f4",
25+
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.38.0/rules_nodejs-0.38.0.tar.gz"],
26+
)
27+
28+
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
29+
30+
yarn_install(
31+
name = "npm",
32+
package_json = "//:package.json",
33+
yarn_lock = "//:yarn.lock",
34+
)

examples/closure/hello.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function hello(name) {
2+
alert('Hello, ' + name);
3+
}
4+
hello('New user');

examples/closure/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"google-closure-compiler": "20190729.0.0"
5+
}
6+
}

examples/closure/test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {runfiles} = require('build_bazel_rules_nodejs/internal/linker');
2+
3+
const closureOutput = runfiles.resolve('examples_closure/bundle.js');
4+
5+
// Assert that it's minified
6+
require('fs').readFile(closureOutput, 'utf-8', (err, content) => {
7+
if (content.trim().split(/\r?\n/).length > 1) {
8+
console.error('Bundle is more than one line');
9+
console.error(content);
10+
process.exitCode = 1;
11+
}
12+
});
13+
14+
// Assert that the code works
15+
let alerted;
16+
global.alert = function(s) {
17+
alerted = s;
18+
};
19+
20+
require(closureOutput);
21+
const expected = 'Hello, New user';
22+
if (alerted !== expected) {
23+
console.error(`expected alert ${expected} but was ${alerted}`);
24+
process.exitCode = 1;
25+
}

examples/closure/yarn.lock

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
ansi-styles@^3.2.1:
6+
version "3.2.1"
7+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
8+
integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==
9+
dependencies:
10+
color-convert "^1.9.0"
11+
12+
chalk@2.x:
13+
version "2.4.2"
14+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
15+
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
16+
dependencies:
17+
ansi-styles "^3.2.1"
18+
escape-string-regexp "^1.0.5"
19+
supports-color "^5.3.0"
20+
21+
clone-buffer@^1.0.0:
22+
version "1.0.0"
23+
resolved "https://registry.yarnpkg.com/clone-buffer/-/clone-buffer-1.0.0.tgz#e3e25b207ac4e701af721e2cb5a16792cac3dc58"
24+
integrity sha1-4+JbIHrE5wGvch4staFnksrD3Fg=
25+
26+
clone-stats@^1.0.0:
27+
version "1.0.0"
28+
resolved "https://registry.yarnpkg.com/clone-stats/-/clone-stats-1.0.0.tgz#b3782dff8bb5474e18b9b6bf0fdfe782f8777680"
29+
integrity sha1-s3gt/4u1R04Yuba/D9/ngvh3doA=
30+
31+
clone@^2.1.1:
32+
version "2.1.2"
33+
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
34+
integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=
35+
36+
cloneable-readable@^1.0.0:
37+
version "1.1.3"
38+
resolved "https://registry.yarnpkg.com/cloneable-readable/-/cloneable-readable-1.1.3.tgz#120a00cb053bfb63a222e709f9683ea2e11d8cec"
39+
integrity sha512-2EF8zTQOxYq70Y4XKtorQupqF0m49MBz2/yf5Bj+MHjvpG3Hy7sImifnqD6UA+TKYxeSV+u6qqQPawN5UvnpKQ==
40+
dependencies:
41+
inherits "^2.0.1"
42+
process-nextick-args "^2.0.0"
43+
readable-stream "^2.3.5"
44+
45+
color-convert@^1.9.0:
46+
version "1.9.3"
47+
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
48+
integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==
49+
dependencies:
50+
color-name "1.1.3"
51+
52+
color-name@1.1.3:
53+
version "1.1.3"
54+
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
55+
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
56+
57+
core-util-is@~1.0.0:
58+
version "1.0.2"
59+
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
60+
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
61+
62+
escape-string-regexp@^1.0.5:
63+
version "1.0.5"
64+
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
65+
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
66+
67+
google-closure-compiler-java@^20190729.0.0:
68+
version "20190729.0.0"
69+
resolved "https://registry.yarnpkg.com/google-closure-compiler-java/-/google-closure-compiler-java-20190729.0.0.tgz#e531ead3f0e0fb7bad207fdae1fc686011e891de"
70+
integrity sha512-SGStZiyasN31tlmKUMMzCNRXTZqeij5N7iEeHSIGOsUdlKw5Zj8VPbaqbCcHvfgpQaUbn29zCTgTYiYFJRkbwA==
71+
72+
google-closure-compiler-js@^20190729.0.0:
73+
version "20190729.0.0"
74+
resolved "https://registry.yarnpkg.com/google-closure-compiler-js/-/google-closure-compiler-js-20190729.0.0.tgz#96e27f29f98e45aae9288b9a696ef8e30e846e51"
75+
integrity sha512-ZDJRK3eiNfKLsO1+uVxHnvB8RTQMLHlJNKouMBcPzPNOAurEFRboHf5nx/0llO+MXVWZDIPhxpbuuD3WnQsprA==
76+
77+
google-closure-compiler-linux@^20190729.0.0:
78+
version "20190729.0.0"
79+
resolved "https://registry.yarnpkg.com/google-closure-compiler-linux/-/google-closure-compiler-linux-20190729.0.0.tgz#74c2f0386295d2c8bd8ec27d0ace315224caf733"
80+
integrity sha512-W4TRrQ1+FrCFu3yn4M0JTWTJCFsqLlBjkliB/xLFuWb5E7XQ8Xe/sPtkmeNzCo+ftd6B/KD7acaH2oMU0brMag==
81+
82+
google-closure-compiler-osx@^20190729.0.0:
83+
version "20190729.0.0"
84+
resolved "https://registry.yarnpkg.com/google-closure-compiler-osx/-/google-closure-compiler-osx-20190729.0.0.tgz#586bd4e4335f21c8e8e7328902f45d7655c39283"
85+
integrity sha512-g3mLUVFD85nRwVyl8X6ywZ14YFP6fo+kXdIvrBGxxUkUU8VbeIgr6GlgtAUS0eZ0WVs2hr5w6kjk7+5kyeBSJg==
86+
87+
google-closure-compiler-windows@^20190729.0.0:
88+
version "20190729.0.0"
89+
resolved "https://registry.yarnpkg.com/google-closure-compiler-windows/-/google-closure-compiler-windows-20190729.0.0.tgz#f6b7b8f86c19ea86f4a82cf4d4706841155708c3"
90+
integrity sha512-tzFfu2ixOoAWJUcCsagNFE4o0xHV+LI4cD3AmI36ll2e0NW1aUjDPhiG5TSfAnMIvZwgkikG5tqnPnk8ljauAA==
91+
92+
google-closure-compiler@20190729.0.0:
93+
version "20190729.0.0"
94+
resolved "https://registry.yarnpkg.com/google-closure-compiler/-/google-closure-compiler-20190729.0.0.tgz#9f822f2e5e59478be5345c6f464709f9b5087b24"
95+
integrity sha512-z+egAPJmOkEgop6ZUjrE+bIOKqbKdx57J+SAGVgq9DAQnr3yVxQ+h9b8PSLcpgzMw/Y0rMCHpM3HkCTE2Y1ePQ==
96+
dependencies:
97+
chalk "2.x"
98+
google-closure-compiler-java "^20190729.0.0"
99+
google-closure-compiler-js "^20190729.0.0"
100+
minimist "1.x"
101+
vinyl "2.x"
102+
vinyl-sourcemaps-apply "^0.2.0"
103+
optionalDependencies:
104+
google-closure-compiler-linux "^20190729.0.0"
105+
google-closure-compiler-osx "^20190729.0.0"
106+
google-closure-compiler-windows "^20190729.0.0"
107+
108+
has-flag@^3.0.0:
109+
version "3.0.0"
110+
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
111+
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
112+
113+
inherits@^2.0.1, inherits@~2.0.3:
114+
version "2.0.4"
115+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
116+
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
117+
118+
isarray@~1.0.0:
119+
version "1.0.0"
120+
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
121+
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
122+
123+
minimist@1.x:
124+
version "1.2.0"
125+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
126+
integrity sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=
127+
128+
process-nextick-args@^2.0.0, process-nextick-args@~2.0.0:
129+
version "2.0.1"
130+
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
131+
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
132+
133+
readable-stream@^2.3.5:
134+
version "2.3.6"
135+
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
136+
integrity sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==
137+
dependencies:
138+
core-util-is "~1.0.0"
139+
inherits "~2.0.3"
140+
isarray "~1.0.0"
141+
process-nextick-args "~2.0.0"
142+
safe-buffer "~5.1.1"
143+
string_decoder "~1.1.1"
144+
util-deprecate "~1.0.1"
145+
146+
remove-trailing-separator@^1.0.1:
147+
version "1.1.0"
148+
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef"
149+
integrity sha1-wkvOKig62tW8P1jg1IJJuSN52O8=
150+
151+
replace-ext@^1.0.0:
152+
version "1.0.0"
153+
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"
154+
integrity sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs=
155+
156+
safe-buffer@~5.1.0, safe-buffer@~5.1.1:
157+
version "5.1.2"
158+
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
159+
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
160+
161+
source-map@^0.5.1:
162+
version "0.5.7"
163+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
164+
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
165+
166+
string_decoder@~1.1.1:
167+
version "1.1.1"
168+
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
169+
integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
170+
dependencies:
171+
safe-buffer "~5.1.0"
172+
173+
supports-color@^5.3.0:
174+
version "5.5.0"
175+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
176+
integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==
177+
dependencies:
178+
has-flag "^3.0.0"
179+
180+
util-deprecate@~1.0.1:
181+
version "1.0.2"
182+
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
183+
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
184+
185+
vinyl-sourcemaps-apply@^0.2.0:
186+
version "0.2.1"
187+
resolved "https://registry.yarnpkg.com/vinyl-sourcemaps-apply/-/vinyl-sourcemaps-apply-0.2.1.tgz#ab6549d61d172c2b1b87be5c508d239c8ef87705"
188+
integrity sha1-q2VJ1h0XLCsbh75cUI0jnI74dwU=
189+
dependencies:
190+
source-map "^0.5.1"
191+
192+
vinyl@2.x:
193+
version "2.2.0"
194+
resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-2.2.0.tgz#d85b07da96e458d25b2ffe19fece9f2caa13ed86"
195+
integrity sha512-MBH+yP0kC/GQ5GwBqrTPTzEfiiLjta7hTtvQtbxBgTeSXsmKQRQecjibMbxIXzVT3Y9KJK+drOz1/k+vsu8Nkg==
196+
dependencies:
197+
clone "^2.1.1"
198+
clone-buffer "^1.0.0"
199+
clone-stats "^1.0.0"
200+
cloneable-readable "^1.0.0"
201+
remove-trailing-separator "^1.0.1"
202+
replace-ext "^1.0.0"

examples/index.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
ALL_EXAMPLES = [
33
"angular",
44
"app",
5+
"closure",
56
"kotlin",
67
"nestjs",
78
"parcel",

0 commit comments

Comments
 (0)