Skip to content

Commit

Permalink
feat(rollup): add worker support to rollup_bundle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbedard authored and alexeagle committed Mar 27, 2020
1 parent e2fdb02 commit 66db579
Show file tree
Hide file tree
Showing 19 changed files with 357 additions and 34 deletions.
2 changes: 2 additions & 0 deletions e2e/webapp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ rollup_bundle(
srcs = ["strings.js"],
entry_point = "app.js",
output_dir = True,
# Enable experimental faster builds with Bazel workers
supports_workers = True,
)

terser_minified(
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg_npm/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
load("//internal/node:context.bzl", "node_context_data")
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg_web/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("@npm//@babel/cli:index.bzl", "babel")
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg_web/test2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("@npm//@babel/cli:index.bzl", "babel")
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")

rollup_bundle(
Expand Down
2 changes: 1 addition & 1 deletion packages/labs/test/grpc_web/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
load("@npm_bazel_karma//:index.from_src.bzl", "karma_web_test_suite")
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")

# This test checks that the protos can be resolved in a nodejs environment
Expand Down
2 changes: 1 addition & 1 deletion packages/protractor/test/protractor-2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@npm//http-server:index.bzl", "http_server")
load("@npm_bazel_protractor//:index.from_src.bzl", "protractor_web_test_suite")
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")
load("@npm_bazel_typescript//:index.bzl", "ts_config")
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_devserver", "ts_library")
Expand Down
28 changes: 27 additions & 1 deletion packages/rollup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

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

codeowners(
teams = ["@jbedard"],
Expand All @@ -33,12 +34,34 @@ genrule(
visibility = ["//docs:__pkg__"],
)

# Copy the proto file to a matching third_party/... nested directory
# so the runtime require() statements still work
_worker_proto_dir = "third_party/github.com/bazelbuild/bazel/src/main/protobuf"

genrule(
name = "copy_worker_js",
srcs = ["//packages/worker:npm_package"],
outs = ["worker.js"],
cmd = "cp $(execpath //packages/worker:npm_package)/index.js $@",
visibility = ["//visibility:public"],
)

copy_file(
name = "copy_worker_proto",
src = "@build_bazel_rules_typescript//%s:worker_protocol.proto" % _worker_proto_dir,
out = "%s/worker_protocol.proto" % _worker_proto_dir,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_package",
srcs = [
"@npm_bazel_rollup//:package_contents",
],
build_file_content = """exports_files(["rollup.config.js"])""",
substitutions = {
"//:rollup-worker-local": "@npm//@bazel/rollup/bin:rollup-worker",
},
vendor_external = [
"npm_bazel_rollup",
],
Expand All @@ -48,5 +71,8 @@ pkg_npm(
# external/npm_bazel_rollup/docs.raw: Generating proto for Starlark doc for docs failed (Exit 1)
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": [":generate_README"],
}),
}) + [
":copy_worker_proto",
":worker.js",
],
)
15 changes: 15 additions & 0 deletions packages/rollup/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("@build_bazel_rules_nodejs//tools/stardoc:index.bzl", "stardoc")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -42,8 +43,22 @@ filegroup(
name = "package_contents",
srcs = [
"index.bzl",
"index.js",
"package.json",
"rollup.config.js",
"rollup_bundle.bzl",
],
)

nodejs_binary(
name = "rollup-worker-local",
data = [
# NOTE: we ought to link to the original location instead of copying
# "@build_bazel_rules_nodejs//packages/worker:npm_package",
"@build_bazel_rules_nodejs//packages/rollup:worker.js",
"@build_bazel_rules_nodejs//packages/rollup:copy_worker_proto",
"@npm//protobufjs",
"@npm//rollup",
],
entry_point = "index.js",
)
20 changes: 0 additions & 20 deletions packages/rollup/src/index.from_src.bzl

This file was deleted.

Loading

0 comments on commit 66db579

Please sign in to comment.