Skip to content

Commit 66db579

Browse files
jbedardalexeagle
authored andcommitted
feat(rollup): add worker support to rollup_bundle
Adds rollup_bundle(supports_workers), disabled by default. This enables rollup to be run in a worker process to perform incremental builds when notified of file changes from bazel. Worker mode currently supports only a very small subset of the standard rollup CLI arguments.
1 parent e2fdb02 commit 66db579

19 files changed

Lines changed: 357 additions & 34 deletions

File tree

e2e/webapp/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ rollup_bundle(
77
srcs = ["strings.js"],
88
entry_point = "app.js",
99
output_dir = True,
10+
# Enable experimental faster builds with Bazel workers
11+
supports_workers = True,
1012
)
1113

1214
terser_minified(

internal/pkg_npm/test/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
22
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
3-
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
3+
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
44
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
55
load("//internal/node:context.bzl", "node_context_data")
66
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file")

internal/pkg_web/test/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
22
load("@npm//@babel/cli:index.bzl", "babel")
33
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
4-
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
4+
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
55
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")
66
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
77

internal/pkg_web/test2/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
22
load("@npm//@babel/cli:index.bzl", "babel")
33
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
4-
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
4+
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
55
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")
66

77
rollup_bundle(

packages/labs/test/grpc_web/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
22
load("@npm_bazel_karma//:index.from_src.bzl", "karma_web_test_suite")
3-
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
3+
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
44
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
55

66
# This test checks that the protos can be resolved in a nodejs environment

packages/protractor/test/protractor-2/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@npm//http-server:index.bzl", "http_server")
22
load("@npm_bazel_protractor//:index.from_src.bzl", "protractor_web_test_suite")
3-
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
3+
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
44
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")
55
load("@npm_bazel_typescript//:index.bzl", "ts_config")
66
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_devserver", "ts_library")

packages/rollup/BUILD.bazel

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "codeowners", "pkg_npm")
16+
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
1617

1718
codeowners(
1819
teams = ["@jbedard"],
@@ -33,12 +34,34 @@ genrule(
3334
visibility = ["//docs:__pkg__"],
3435
)
3536

37+
# Copy the proto file to a matching third_party/... nested directory
38+
# so the runtime require() statements still work
39+
_worker_proto_dir = "third_party/github.com/bazelbuild/bazel/src/main/protobuf"
40+
41+
genrule(
42+
name = "copy_worker_js",
43+
srcs = ["//packages/worker:npm_package"],
44+
outs = ["worker.js"],
45+
cmd = "cp $(execpath //packages/worker:npm_package)/index.js $@",
46+
visibility = ["//visibility:public"],
47+
)
48+
49+
copy_file(
50+
name = "copy_worker_proto",
51+
src = "@build_bazel_rules_typescript//%s:worker_protocol.proto" % _worker_proto_dir,
52+
out = "%s/worker_protocol.proto" % _worker_proto_dir,
53+
visibility = ["//visibility:public"],
54+
)
55+
3656
pkg_npm(
3757
name = "npm_package",
3858
srcs = [
3959
"@npm_bazel_rollup//:package_contents",
4060
],
4161
build_file_content = """exports_files(["rollup.config.js"])""",
62+
substitutions = {
63+
"//:rollup-worker-local": "@npm//@bazel/rollup/bin:rollup-worker",
64+
},
4265
vendor_external = [
4366
"npm_bazel_rollup",
4467
],
@@ -48,5 +71,8 @@ pkg_npm(
4871
# external/npm_bazel_rollup/docs.raw: Generating proto for Starlark doc for docs failed (Exit 1)
4972
"@bazel_tools//src/conditions:windows": [],
5073
"//conditions:default": [":generate_README"],
51-
}),
74+
}) + [
75+
":copy_worker_proto",
76+
":worker.js",
77+
],
5278
)

packages/rollup/src/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16+
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
1617
load("@build_bazel_rules_nodejs//tools/stardoc:index.bzl", "stardoc")
1718

1819
package(default_visibility = ["//visibility:public"])
@@ -42,8 +43,22 @@ filegroup(
4243
name = "package_contents",
4344
srcs = [
4445
"index.bzl",
46+
"index.js",
4547
"package.json",
4648
"rollup.config.js",
4749
"rollup_bundle.bzl",
4850
],
4951
)
52+
53+
nodejs_binary(
54+
name = "rollup-worker-local",
55+
data = [
56+
# NOTE: we ought to link to the original location instead of copying
57+
# "@build_bazel_rules_nodejs//packages/worker:npm_package",
58+
"@build_bazel_rules_nodejs//packages/rollup:worker.js",
59+
"@build_bazel_rules_nodejs//packages/rollup:copy_worker_proto",
60+
"@npm//protobufjs",
61+
"@npm//rollup",
62+
],
63+
entry_point = "index.js",
64+
)

packages/rollup/src/index.from_src.bzl

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)