Skip to content

Commit

Permalink
feat(typescript): add JSEcmaScriptModuleInfo provider to ts_library o…
Browse files Browse the repository at this point in the history
…utputs

This allows ts_library output to be piped into the new @bazel/rollup rollup_bundle
  • Loading branch information
gregmagolan authored and alexeagle committed Sep 26, 2019
1 parent 2904c6c commit 1433eb9
Show file tree
Hide file tree
Showing 35 changed files with 2,909 additions and 101 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bzl_library(
"declaration_provider.bzl",
"index.bzl",
"index.for_docs.bzl",
"providers.bzl",
],
visibility = ["//visibility:public"],
deps = [
Expand Down
7 changes: 7 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ example_integration_test(
npm_packages = {
"//packages/hide-bazel-files:npm_package": "@bazel/hide-bazel-files",
"//packages/protractor:npm_package": "@bazel/protractor",
"//packages/rollup:npm_package": "@bazel/rollup",
"//packages/terser:npm_package": "@bazel/terser",
"//packages/typescript:npm_package": "@bazel/typescript",
},
)
Expand All @@ -65,6 +67,8 @@ example_integration_test(
name = "examples_kotlin",
npm_packages = {
"//packages/jasmine:npm_package": "@bazel/jasmine",
"//packages/rollup:npm_package": "@bazel/rollup",
"//packages/terser:npm_package": "@bazel/terser",
},
# Kotlin's kt_js_import relies on a helper written in Python
# https://github.com/bazelbuild/rules_kotlin/blob/master/kotlin/internal/js/importer.py
Expand All @@ -91,6 +95,7 @@ example_integration_test(
"//packages/protractor:npm_package": "@bazel/protractor",
"//packages/rollup:npm_package": "@bazel/rollup",
"//packages/terser:npm_package": "@bazel/terser",
"//packages/typescript:npm_package": "@bazel/typescript",
},
)

Expand All @@ -117,6 +122,8 @@ example_integration_test(
"//packages/karma:npm_package": "@bazel/karma",
"//packages/labs:npm_package": "@bazel/labs",
"//packages/protractor:npm_package": "@bazel/protractor",
"//packages/rollup:npm_package": "@bazel/rollup",
"//packages/terser:npm_package": "@bazel/terser",
"//packages/typescript:npm_package": "@bazel/typescript",
},
# Runs out of memory on bazelci windows
Expand Down
14 changes: 8 additions & 6 deletions examples/app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@npm//http-server:index.bzl", "http_server")
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_terser//:index.bzl", "terser_minified")
load("@npm_bazel_typescript//:index.bzl", "ts_config", "ts_devserver", "ts_library")

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

rollup_bundle(
name = "bundle",
enable_code_splitting = False,
entry_point = ":app.ts",
deps = [":app"],
)

terser_minified(
name = "bundle.min",
src = ":bundle",
)

web_package(
name = "package",
assets = [
# For differential loading, we supply both an ESModule entry point and an es5 entry point
# The injector will put two complimentary script tags in the index.html
":bundle.min.js",
":bundle.min.es2015.js",
":bundle.min",
"//styles:base.css",
"//styles:test.css",
],
Expand Down
4 changes: 4 additions & 0 deletions examples/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
"devDependencies": {
"@bazel/hide-bazel-files": "latest",
"@bazel/protractor": "latest",
"@bazel/rollup": "latest",
"@bazel/terser": "latest",
"@bazel/typescript": "latest",
"@types/jasmine": "3.3.15",
"http-server": "^0.11.1",
"less": "^3.10.3",
"rollup": "1.20.3",
"stylus": "^0.54.7",
"terser": "4.3.1",
"typescript": "2.7.x"
},
"scripts": {
Expand Down
48 changes: 47 additions & 1 deletion examples/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@types/estree@0.0.39":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==

"@types/jasmine@3.3.15":
version "3.3.15"
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-3.3.15.tgz#545be0670e828ac570566c45be570bbffcbc66d8"
Expand All @@ -92,6 +97,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.9.tgz#2e8d678039d27943ce53a1913386133227fd9066"
integrity sha512-NelG/dSahlXYtSoVPErrp06tYFrvzj8XLWmKA+X8x0W//4MqbUyZu++giUG/v0bjAT6/Qxa8IjodrfdACyb0Fg==

"@types/node@^12.7.2":
version "12.7.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.8.tgz#cb1bf6800238898bc2ff6ffa5702c3cadd350708"
integrity sha512-FMdVn84tJJdV+xe+53sYiZS4R5yn1mAIxfj+DVoNiQjTYz1+OYmjwEZr1ev9nU0axXwda0QDbYl06QHanRVH3A==

"@types/q@^0.0.32":
version "0.0.32"
resolved "https://registry.yarnpkg.com/@types/q/-/q-0.0.32.tgz#bd284e57c84f1325da702babfc82a5328190c0c5"
Expand All @@ -102,6 +112,11 @@
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.16.tgz#50a4755f8e33edacd9c406729e9b930d2451902a"
integrity sha512-lMC2G0ItF2xv4UCiwbJGbnJlIuUixHrioOhNGHSCsYCJ8l4t9hMCUimCytvFv7qy6AfSzRxhRHoGa+UqaqwyeA==

acorn@^7.0.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.0.tgz#949d36f2c292535da602283586c2477c57eb2d6c"
integrity sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==

adm-zip@^0.4.9:
version "0.4.13"
resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.4.13.tgz#597e2f8cc3672151e1307d3e95cddbc75672314a"
Expand Down Expand Up @@ -265,6 +280,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

commander@^2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==

concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
Expand Down Expand Up @@ -986,6 +1006,15 @@ rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4:
dependencies:
glob "^7.1.3"

rollup@1.20.3:
version "1.20.3"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.20.3.tgz#6243f6c118ca05f56b2d9433112400cd834a1eb8"
integrity sha512-/OMCkY0c6E8tleeVm4vQVDz24CkVgvueK3r8zTYu2AQNpjrcaPwO9hE+pWj5LTFrvvkaxt4MYIp2zha4y0lRvg==
dependencies:
"@types/estree" "0.0.39"
"@types/node" "^12.7.2"
acorn "^7.0.0"

safe-buffer@^5.0.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
Expand Down Expand Up @@ -1064,6 +1093,14 @@ source-map-support@~0.4.0:
dependencies:
source-map "^0.5.6"

source-map-support@~0.5.12:
version "0.5.13"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
integrity sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
Expand All @@ -1074,7 +1111,7 @@ source-map@^0.5.6:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=

source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0:
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
Expand Down Expand Up @@ -1132,6 +1169,15 @@ supports-color@^2.0.0:
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
integrity sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=

terser@4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/terser/-/terser-4.3.1.tgz#09820bcb3398299c4b48d9a86aefc65127d0ed65"
integrity sha512-pnzH6dnFEsR2aa2SJaKb1uSCl3QmIsJ8dEkj0Fky+2AwMMcC9doMqLOQIH6wVTEKaVfKVvLSk5qxPBEZT9mywg==
dependencies:
commander "^2.20.0"
source-map "~0.6.1"
source-map-support "~0.5.12"

tmp@0.0.30:
version "0.0.30"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.30.tgz#72419d4a8be7d6ce75148fd8b324e593a711c2ed"
Expand Down
33 changes: 23 additions & 10 deletions examples/kotlin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Add rules here to build your software
# See https://docs.bazel.build/versions/master/build-ref.html#BUILD_files

load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import", "kt_js_library")
load("@npm//http-server:index.bzl", "http_server")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_terser//:index.bzl", "terser_minified")

# Grab a Maven dependency
kt_js_import(
Expand All @@ -21,28 +22,41 @@ kt_js_library(
deps = [":kotlinx-html-js"],
)

# Copy boostrap.js to the bin folder as _bootstrap.js
# so that relative import to `./hello.js` is valid
genrule(
name = "bootstrap",
srcs = ["bootstrap.js"],
outs = ["_bootstrap.js"],
cmd = "cp $< $@",
)

rollup_bundle(
name = "bundle",
srcs = ["hello.js"],
entry_point = "bootstrap.js",
config_file = "rollup.config.js",
entry_point = "_bootstrap.js",
# TODO: make this example work with format = "esm"
format = "cjs",
output_dir = True,
deps = [
"@npm//kotlin",
"@npm//kotlinx-html-js",
],
)

terser_minified(
name = "bundle.min",
src = ":bundle",
)

web_package(
name = "package",
assets = [
# For differential loading, we supply both an ESModule entry point and an es5 entry point
# The injector will put two complimentary script tags in the index.html
":bundle.min.js",
":bundle.min.es2015.js",
],
data = [":bundle"],
data = [":bundle.min"],
index_html = "index.html",
)

# TODO: fix prodserver; require.js is needed if rollup_bundle output is cjs
http_server(
name = "server",
data = [":package"],
Expand All @@ -54,7 +68,6 @@ jasmine_node_test(
srcs = ["spec.js"],
data = [
":bundle",
":bundle.js",
"@npm//domino",
],
templated_args = ["--node_options=--experimental-modules"],
Expand Down
8 changes: 7 additions & 1 deletion examples/kotlin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
"private": true,
"devDependencies": {
"@bazel/jasmine": "latest",
"@bazel/rollup": "latest",
"@bazel/terser": "latest",
"domino": "^2.1.3",
"http-server": "^0.11.1",
"kotlin": "^1.3.41",
"kotlinx-html-js": "^0.6.4"
"kotlinx-html-js": "^0.6.4",
"rollup": "1.20.3",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-commonjs": "10.1.0",
"terser": "4.3.1"
},
"scripts": {
"build": "bazel build //...",
Expand Down
11 changes: 11 additions & 0 deletions examples/kotlin/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const node = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');

module.exports = {
plugins: [
node({
mainFields: ['browser', 'es2015', 'module', 'jsnext:main', 'main'],
}),
commonjs(),
],
};
2 changes: 1 addition & 1 deletion examples/kotlin/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ describe('kotlin webapp', () => {
// Make all Domino types available as types in the global env.
Object.assign(global, domino.impl);

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

0 comments on commit 1433eb9

Please sign in to comment.