Skip to content

Commit 1433eb9

Browse files
gregmagolanalexeagle
authored andcommitted
feat(typescript): add JSEcmaScriptModuleInfo provider to ts_library outputs
This allows ts_library output to be piped into the new @bazel/rollup rollup_bundle
1 parent 2904c6c commit 1433eb9

35 files changed

+2909
-101
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ bzl_library(
3030
"declaration_provider.bzl",
3131
"index.bzl",
3232
"index.for_docs.bzl",
33+
"providers.bzl",
3334
],
3435
visibility = ["//visibility:public"],
3536
deps = [

examples/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ example_integration_test(
5050
npm_packages = {
5151
"//packages/hide-bazel-files:npm_package": "@bazel/hide-bazel-files",
5252
"//packages/protractor:npm_package": "@bazel/protractor",
53+
"//packages/rollup:npm_package": "@bazel/rollup",
54+
"//packages/terser:npm_package": "@bazel/terser",
5355
"//packages/typescript:npm_package": "@bazel/typescript",
5456
},
5557
)
@@ -65,6 +67,8 @@ example_integration_test(
6567
name = "examples_kotlin",
6668
npm_packages = {
6769
"//packages/jasmine:npm_package": "@bazel/jasmine",
70+
"//packages/rollup:npm_package": "@bazel/rollup",
71+
"//packages/terser:npm_package": "@bazel/terser",
6872
},
6973
# Kotlin's kt_js_import relies on a helper written in Python
7074
# https://github.com/bazelbuild/rules_kotlin/blob/master/kotlin/internal/js/importer.py
@@ -91,6 +95,7 @@ example_integration_test(
9195
"//packages/protractor:npm_package": "@bazel/protractor",
9296
"//packages/rollup:npm_package": "@bazel/rollup",
9397
"//packages/terser:npm_package": "@bazel/terser",
98+
"//packages/typescript:npm_package": "@bazel/typescript",
9499
},
95100
)
96101

@@ -117,6 +122,8 @@ example_integration_test(
117122
"//packages/karma:npm_package": "@bazel/karma",
118123
"//packages/labs:npm_package": "@bazel/labs",
119124
"//packages/protractor:npm_package": "@bazel/protractor",
125+
"//packages/rollup:npm_package": "@bazel/rollup",
126+
"//packages/terser:npm_package": "@bazel/terser",
120127
"//packages/typescript:npm_package": "@bazel/typescript",
121128
},
122129
# Runs out of memory on bazelci windows

examples/app/BUILD.bazel

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")
21
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
32
load("@npm//http-server:index.bzl", "http_server")
43
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
4+
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
5+
load("@npm_bazel_terser//:index.bzl", "terser_minified")
56
load("@npm_bazel_typescript//:index.bzl", "ts_config", "ts_devserver", "ts_library")
67

78
package(default_visibility = ["//visibility:public"])
@@ -20,18 +21,19 @@ ts_devserver(
2021

2122
rollup_bundle(
2223
name = "bundle",
23-
enable_code_splitting = False,
2424
entry_point = ":app.ts",
2525
deps = [":app"],
2626
)
2727

28+
terser_minified(
29+
name = "bundle.min",
30+
src = ":bundle",
31+
)
32+
2833
web_package(
2934
name = "package",
3035
assets = [
31-
# For differential loading, we supply both an ESModule entry point and an es5 entry point
32-
# The injector will put two complimentary script tags in the index.html
33-
":bundle.min.js",
34-
":bundle.min.es2015.js",
36+
":bundle.min",
3537
"//styles:base.css",
3638
"//styles:test.css",
3739
],

examples/app/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
"devDependencies": {
33
"@bazel/hide-bazel-files": "latest",
44
"@bazel/protractor": "latest",
5+
"@bazel/rollup": "latest",
6+
"@bazel/terser": "latest",
57
"@bazel/typescript": "latest",
68
"@types/jasmine": "3.3.15",
79
"http-server": "^0.11.1",
810
"less": "^3.10.3",
11+
"rollup": "1.20.3",
912
"stylus": "^0.54.7",
13+
"terser": "4.3.1",
1014
"typescript": "2.7.x"
1115
},
1216
"scripts": {

examples/app/yarn.lock

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
7878
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
7979

80+
"@types/estree@0.0.39":
81+
version "0.0.39"
82+
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
83+
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==
84+
8085
"@types/jasmine@3.3.15":
8186
version "3.3.15"
8287
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-3.3.15.tgz#545be0670e828ac570566c45be570bbffcbc66d8"
@@ -92,6 +97,11 @@
9297
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.9.tgz#2e8d678039d27943ce53a1913386133227fd9066"
9398
integrity sha512-NelG/dSahlXYtSoVPErrp06tYFrvzj8XLWmKA+X8x0W//4MqbUyZu++giUG/v0bjAT6/Qxa8IjodrfdACyb0Fg==
9499

100+
"@types/node@^12.7.2":
101+
version "12.7.8"
102+
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.8.tgz#cb1bf6800238898bc2ff6ffa5702c3cadd350708"
103+
integrity sha512-FMdVn84tJJdV+xe+53sYiZS4R5yn1mAIxfj+DVoNiQjTYz1+OYmjwEZr1ev9nU0axXwda0QDbYl06QHanRVH3A==
104+
95105
"@types/q@^0.0.32":
96106
version "0.0.32"
97107
resolved "https://registry.yarnpkg.com/@types/q/-/q-0.0.32.tgz#bd284e57c84f1325da702babfc82a5328190c0c5"
@@ -102,6 +112,11 @@
102112
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.16.tgz#50a4755f8e33edacd9c406729e9b930d2451902a"
103113
integrity sha512-lMC2G0ItF2xv4UCiwbJGbnJlIuUixHrioOhNGHSCsYCJ8l4t9hMCUimCytvFv7qy6AfSzRxhRHoGa+UqaqwyeA==
104114

115+
acorn@^7.0.0:
116+
version "7.1.0"
117+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.0.tgz#949d36f2c292535da602283586c2477c57eb2d6c"
118+
integrity sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==
119+
105120
adm-zip@^0.4.9:
106121
version "0.4.13"
107122
resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.4.13.tgz#597e2f8cc3672151e1307d3e95cddbc75672314a"
@@ -265,6 +280,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
265280
dependencies:
266281
delayed-stream "~1.0.0"
267282

283+
commander@^2.20.0:
284+
version "2.20.0"
285+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
286+
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
287+
268288
concat-map@0.0.1:
269289
version "0.0.1"
270290
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -986,6 +1006,15 @@ rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4:
9861006
dependencies:
9871007
glob "^7.1.3"
9881008

1009+
rollup@1.20.3:
1010+
version "1.20.3"
1011+
resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.20.3.tgz#6243f6c118ca05f56b2d9433112400cd834a1eb8"
1012+
integrity sha512-/OMCkY0c6E8tleeVm4vQVDz24CkVgvueK3r8zTYu2AQNpjrcaPwO9hE+pWj5LTFrvvkaxt4MYIp2zha4y0lRvg==
1013+
dependencies:
1014+
"@types/estree" "0.0.39"
1015+
"@types/node" "^12.7.2"
1016+
acorn "^7.0.0"
1017+
9891018
safe-buffer@^5.0.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
9901019
version "5.1.2"
9911020
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
@@ -1064,6 +1093,14 @@ source-map-support@~0.4.0:
10641093
dependencies:
10651094
source-map "^0.5.6"
10661095

1096+
source-map-support@~0.5.12:
1097+
version "0.5.13"
1098+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
1099+
integrity sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==
1100+
dependencies:
1101+
buffer-from "^1.0.0"
1102+
source-map "^0.6.0"
1103+
10671104
source-map-url@^0.4.0:
10681105
version "0.4.0"
10691106
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
@@ -1074,7 +1111,7 @@ source-map@^0.5.6:
10741111
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
10751112
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
10761113

1077-
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0:
1114+
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1:
10781115
version "0.6.1"
10791116
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
10801117
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
@@ -1132,6 +1169,15 @@ supports-color@^2.0.0:
11321169
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
11331170
integrity sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=
11341171

1172+
terser@4.3.1:
1173+
version "4.3.1"
1174+
resolved "https://registry.yarnpkg.com/terser/-/terser-4.3.1.tgz#09820bcb3398299c4b48d9a86aefc65127d0ed65"
1175+
integrity sha512-pnzH6dnFEsR2aa2SJaKb1uSCl3QmIsJ8dEkj0Fky+2AwMMcC9doMqLOQIH6wVTEKaVfKVvLSk5qxPBEZT9mywg==
1176+
dependencies:
1177+
commander "^2.20.0"
1178+
source-map "~0.6.1"
1179+
source-map-support "~0.5.12"
1180+
11351181
tmp@0.0.30:
11361182
version "0.0.30"
11371183
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.30.tgz#72419d4a8be7d6ce75148fd8b324e593a711c2ed"

examples/kotlin/BUILD.bazel

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Add rules here to build your software
22
# See https://docs.bazel.build/versions/master/build-ref.html#BUILD_files
33

4-
load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")
54
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
65
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import", "kt_js_library")
76
load("@npm//http-server:index.bzl", "http_server")
87
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
8+
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
9+
load("@npm_bazel_terser//:index.bzl", "terser_minified")
910

1011
# Grab a Maven dependency
1112
kt_js_import(
@@ -21,28 +22,41 @@ kt_js_library(
2122
deps = [":kotlinx-html-js"],
2223
)
2324

25+
# Copy boostrap.js to the bin folder as _bootstrap.js
26+
# so that relative import to `./hello.js` is valid
27+
genrule(
28+
name = "bootstrap",
29+
srcs = ["bootstrap.js"],
30+
outs = ["_bootstrap.js"],
31+
cmd = "cp $< $@",
32+
)
33+
2434
rollup_bundle(
2535
name = "bundle",
2636
srcs = ["hello.js"],
27-
entry_point = "bootstrap.js",
37+
config_file = "rollup.config.js",
38+
entry_point = "_bootstrap.js",
39+
# TODO: make this example work with format = "esm"
40+
format = "cjs",
41+
output_dir = True,
2842
deps = [
2943
"@npm//kotlin",
3044
"@npm//kotlinx-html-js",
3145
],
3246
)
3347

48+
terser_minified(
49+
name = "bundle.min",
50+
src = ":bundle",
51+
)
52+
3453
web_package(
3554
name = "package",
36-
assets = [
37-
# For differential loading, we supply both an ESModule entry point and an es5 entry point
38-
# The injector will put two complimentary script tags in the index.html
39-
":bundle.min.js",
40-
":bundle.min.es2015.js",
41-
],
42-
data = [":bundle"],
55+
data = [":bundle.min"],
4356
index_html = "index.html",
4457
)
4558

59+
# TODO: fix prodserver; require.js is needed if rollup_bundle output is cjs
4660
http_server(
4761
name = "server",
4862
data = [":package"],
@@ -54,7 +68,6 @@ jasmine_node_test(
5468
srcs = ["spec.js"],
5569
data = [
5670
":bundle",
57-
":bundle.js",
5871
"@npm//domino",
5972
],
6073
templated_args = ["--node_options=--experimental-modules"],

examples/kotlin/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
"private": true,
44
"devDependencies": {
55
"@bazel/jasmine": "latest",
6+
"@bazel/rollup": "latest",
7+
"@bazel/terser": "latest",
68
"domino": "^2.1.3",
79
"http-server": "^0.11.1",
810
"kotlin": "^1.3.41",
9-
"kotlinx-html-js": "^0.6.4"
11+
"kotlinx-html-js": "^0.6.4",
12+
"rollup": "1.20.3",
13+
"rollup-plugin-node-resolve": "5.2.0",
14+
"rollup-plugin-commonjs": "10.1.0",
15+
"terser": "4.3.1"
1016
},
1117
"scripts": {
1218
"build": "bazel build //...",

examples/kotlin/rollup.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const node = require('rollup-plugin-node-resolve');
2+
const commonjs = require('rollup-plugin-commonjs');
3+
4+
module.exports = {
5+
plugins: [
6+
node({
7+
mainFields: ['browser', 'es2015', 'module', 'jsnext:main', 'main'],
8+
}),
9+
commonjs(),
10+
],
11+
};

examples/kotlin/spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ describe('kotlin webapp', () => {
1010
// Make all Domino types available as types in the global env.
1111
Object.assign(global, domino.impl);
1212

13-
import(path.join(__dirname, 'bundle_chunks/bootstrap.js')).then(() => {expect(global.document.body.textContent).toEqual('Hello from Kotlin!')});
13+
import(path.join(__dirname, 'bundle/bundle.js')).then(() => {expect(global.document.body.textContent).toEqual('Hello from Kotlin!')});
1414
});
1515
});

0 commit comments

Comments
 (0)