Skip to content

Commit 3873715

Browse files
committed
feat(rollup): new implementation of rollup_bundle in @bazel/rollup package
Fixes #532 Fixes #724
1 parent 65d8a36 commit 3873715

File tree

13 files changed

+432
-20
lines changed

13 files changed

+432
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"node_resolve_nested_main": "file:./tools/npm_packages/node_resolve_nested_main",
4141
"protobufjs": "6.8.8",
4242
"protractor": "^5.4.2",
43-
"rollup": "1.0.0",
43+
"rollup": "1.3.1",
4444
"rollup-plugin-amd": "^3.0.0",
4545
"rollup-plugin-commonjs": "^9.2.1",
4646
"rollup-plugin-json": "4.0.0",
@@ -53,7 +53,7 @@
5353
"source-map": "^0.7.3",
5454
"source-map-support": "0.5.9",
5555
"stylus": "~0.54.5",
56-
"terser": "3.17.0",
56+
"terser": "^4.2.1",
5757
"testy": "file:./tools/npm_packages/testy",
5858
"tmp": "0.1.0",
5959
"tsickle": "0.33.1",

packages/index.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ NESTED_PACKAGES = [
2222
"labs",
2323
"less",
2424
"protractor",
25+
"rollup",
2526
"stylus",
2627
"terser",
2728
"typescript",

packages/rollup/BUILD.bazel

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2017 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+
load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package")
16+
17+
# Ugly genrule depending on local linux environment to build the README out of skylark doc generation.
18+
# Only referenced when we do a release.
19+
# TODO: This ought to be possible with stardoc alone. Need to coordinate with Chris Parsons.
20+
genrule(
21+
name = "generate_README",
22+
srcs = [
23+
"//packages/rollup/docs:index.md",
24+
"//packages/rollup/docs:install.md",
25+
],
26+
outs = ["README.md"],
27+
cmd = """cat $(location //packages/rollup/docs:install.md) $(location //packages/rollup/docs:index.md) | sed 's/^##/\\\n##/' > $@""",
28+
visibility = ["//docs:__pkg__"],
29+
)
30+
31+
npm_package(
32+
name = "npm_package",
33+
srcs = [
34+
"@npm_bazel_rollup//:package_contents",
35+
],
36+
tags = ["do-not-publish"],
37+
vendor_external = [
38+
"npm_bazel_rollup",
39+
],
40+
deps = [
41+
":generate_README",
42+
],
43+
)

packages/rollup/docs/BUILD.bazel

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
load("//tools/stardoc:index.bzl", "stardoc")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
exports_files(["install.md"])
6+
7+
stardoc(
8+
name = "docs",
9+
testonly = True,
10+
out = "index.md",
11+
input = "@npm_bazel_rollup//:index.bzl",
12+
deps = [
13+
"@npm_bazel_rollup//:bzl",
14+
# We need to restate local workspace dependencies here in `//foo:bzl`
15+
# format to work-around a bug in stardoc where .bzl files from
16+
# `@build_bazel_rules_nodejs//foo:bzl` style deps are not found
17+
# by the doc generator:
18+
# ```
19+
# Exception in thread "main" java.lang.IllegalStateException: File external/npm_bazel_karma/karma_node_test.bzl imported '@build_bazel_rules_nodejs//internal/common:devmode_js_sources.bzl', yet internal/common/devmode_js_sources.bzl was not found, even at roots [.].
20+
# ```
21+
"//internal/common:bzl",
22+
"//internal/linker:bzl",
23+
],
24+
)

packages/rollup/docs/install.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# rollup rules for Bazel
2+
3+
**WARNING: this is beta-quality software. Breaking changes are likely. Not recommended for production use without expert support.**
4+
5+
The rollup rules run the rollup JS bundler with Bazel.
6+
7+
Wraps the rollup CLI documented at https://rollupjs.org/guide/en/#command-line-reference
8+
9+
## Installation
10+
11+
Add the `@bazel/rollup` npm package to your `devDependencies` in `package.json`.
12+
13+
Your `WORKSPACE` should declare a `yarn_install` or `npm_install` rule named `npm`.
14+
It should then install the rules found in the npm packages using the `install_bazel_dependencies` function.
15+
See https://github.com/bazelbuild/rules_nodejs/#quickstart
16+
17+
This causes the `@bazel/rollup` package to be installed as a Bazel workspace named `npm_bazel_rollup`.
18+
19+
## Installing with self-managed dependencies
20+
21+
If you didn't use the `yarn_install` or `npm_install` rule to create an `npm` workspace, you'll have to declare a rule in your root `BUILD.bazel` file to execute rollup:
22+
23+
```python
24+
# Create a rollup rule to use in rollup_bundle#rollup_bin
25+
# attribute when using self-managed dependencies
26+
nodejs_binary(
27+
name = "rollup_bin",
28+
entry_point = "//:node_modules/rollup/bin/rollup",
29+
# Point bazel to your node_modules to find the entry point
30+
node_modules = ["//:node_modules"],
31+
)
32+
```
33+

packages/rollup/src/BUILD.bazel

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16+
17+
package(default_visibility = ["//visibility:public"])
18+
19+
exports_files(["rollup.config.js"])
20+
21+
bzl_library(
22+
name = "bzl",
23+
srcs = glob(["*.bzl"]),
24+
deps = [
25+
"@build_bazel_rules_nodejs//:bzl",
26+
"@build_bazel_rules_nodejs//internal/common:bzl",
27+
"@build_bazel_rules_nodejs//internal/linker:bzl",
28+
],
29+
)
30+
31+
filegroup(
32+
name = "package_contents",
33+
srcs = [
34+
"BUILD.bazel",
35+
"index.bzl",
36+
"package.json",
37+
"rollup.config.js",
38+
"rollup_bundle.bzl",
39+
],
40+
)

packages/rollup/src/WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workspace(name = "npm_bazel_rollup")

packages/rollup/src/index.bzl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
"Public API for terser rules"
16+
17+
load(":rollup_bundle.bzl", _rollup_bundle = "rollup_bundle")
18+
19+
rollup_bundle = _rollup_bundle
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
""" Defaults for usage without @npm//@bazel/rollup
16+
"""
17+
18+
load(
19+
":index.bzl",
20+
_rollup_bundle = "rollup_bundle",
21+
)
22+
23+
def rollup_bundle(**kwargs):
24+
_rollup_bundle(
25+
# Override to point to the one installed by build_bazel_rules_nodejs in the root
26+
rollup_bin = "@npm//rollup/bin:rollup",
27+
**kwargs
28+
)

packages/rollup/src/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@bazel/rollup",
3+
"peerDependencies": {
4+
"rollup": ">1.0.0 <2.0.0"
5+
},
6+
"description": "Run rollup.js bundler under Bazel",
7+
"license": "Apache-2.0",
8+
"version": "0.0.0-PLACEHOLDER",
9+
"repository": {
10+
"type" : "git",
11+
"url" : "https://github.com/bazelbuild/rules_nodejs.git",
12+
"directory": "packages/rollup"
13+
},
14+
"bugs": {
15+
"url": "https://github.com/bazelbuild/rules_nodejs/issues"
16+
},
17+
"keywords": [
18+
"rollup",
19+
"bazel"
20+
],
21+
"bin": {
22+
"rollup": "index.js"
23+
},
24+
"bazelWorkspaces": {
25+
"npm_bazel_rollup": {
26+
"rootPath": "."
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)