-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rollup): new implementation of rollup_bundle in @bazel/rollup pa…
- Loading branch information
Showing
13 changed files
with
432 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ NESTED_PACKAGES = [ | |
"labs", | ||
"less", | ||
"protractor", | ||
"rollup", | ||
"stylus", | ||
"terser", | ||
"typescript", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2017 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") | ||
|
||
# Ugly genrule depending on local linux environment to build the README out of skylark doc generation. | ||
# Only referenced when we do a release. | ||
# TODO: This ought to be possible with stardoc alone. Need to coordinate with Chris Parsons. | ||
genrule( | ||
name = "generate_README", | ||
srcs = [ | ||
"//packages/rollup/docs:index.md", | ||
"//packages/rollup/docs:install.md", | ||
], | ||
outs = ["README.md"], | ||
cmd = """cat $(location //packages/rollup/docs:install.md) $(location //packages/rollup/docs:index.md) | sed 's/^##/\\\n##/' > $@""", | ||
visibility = ["//docs:__pkg__"], | ||
) | ||
|
||
npm_package( | ||
name = "npm_package", | ||
srcs = [ | ||
"@npm_bazel_rollup//:package_contents", | ||
], | ||
tags = ["do-not-publish"], | ||
vendor_external = [ | ||
"npm_bazel_rollup", | ||
], | ||
deps = [ | ||
":generate_README", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("//tools/stardoc:index.bzl", "stardoc") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
exports_files(["install.md"]) | ||
|
||
stardoc( | ||
name = "docs", | ||
testonly = True, | ||
out = "index.md", | ||
input = "@npm_bazel_rollup//:index.bzl", | ||
deps = [ | ||
"@npm_bazel_rollup//:bzl", | ||
# We need to restate local workspace dependencies here in `//foo:bzl` | ||
# format to work-around a bug in stardoc where .bzl files from | ||
# `@build_bazel_rules_nodejs//foo:bzl` style deps are not found | ||
# by the doc generator: | ||
# ``` | ||
# 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 [.]. | ||
# ``` | ||
"//internal/common:bzl", | ||
"//internal/linker:bzl", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# rollup rules for Bazel | ||
|
||
**WARNING: this is beta-quality software. Breaking changes are likely. Not recommended for production use without expert support.** | ||
|
||
The rollup rules run the rollup JS bundler with Bazel. | ||
|
||
Wraps the rollup CLI documented at https://rollupjs.org/guide/en/#command-line-reference | ||
|
||
## Installation | ||
|
||
Add the `@bazel/rollup` npm package to your `devDependencies` in `package.json`. | ||
|
||
Your `WORKSPACE` should declare a `yarn_install` or `npm_install` rule named `npm`. | ||
It should then install the rules found in the npm packages using the `install_bazel_dependencies` function. | ||
See https://github.com/bazelbuild/rules_nodejs/#quickstart | ||
|
||
This causes the `@bazel/rollup` package to be installed as a Bazel workspace named `npm_bazel_rollup`. | ||
|
||
## Installing with self-managed dependencies | ||
|
||
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: | ||
|
||
```python | ||
# Create a rollup rule to use in rollup_bundle#rollup_bin | ||
# attribute when using self-managed dependencies | ||
nodejs_binary( | ||
name = "rollup_bin", | ||
entry_point = "//:node_modules/rollup/bin/rollup", | ||
# Point bazel to your node_modules to find the entry point | ||
node_modules = ["//:node_modules"], | ||
) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
exports_files(["rollup.config.js"]) | ||
|
||
bzl_library( | ||
name = "bzl", | ||
srcs = glob(["*.bzl"]), | ||
deps = [ | ||
"@build_bazel_rules_nodejs//:bzl", | ||
"@build_bazel_rules_nodejs//internal/common:bzl", | ||
"@build_bazel_rules_nodejs//internal/linker:bzl", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "package_contents", | ||
srcs = [ | ||
"BUILD.bazel", | ||
"index.bzl", | ||
"package.json", | ||
"rollup.config.js", | ||
"rollup_bundle.bzl", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
workspace(name = "npm_bazel_rollup") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"Public API for terser rules" | ||
|
||
load(":rollup_bundle.bzl", _rollup_bundle = "rollup_bundle") | ||
|
||
rollup_bundle = _rollup_bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" Defaults for usage without @npm//@bazel/rollup | ||
""" | ||
|
||
load( | ||
":index.bzl", | ||
_rollup_bundle = "rollup_bundle", | ||
) | ||
|
||
def rollup_bundle(**kwargs): | ||
_rollup_bundle( | ||
# Override to point to the one installed by build_bazel_rules_nodejs in the root | ||
rollup_bin = "@npm//rollup/bin:rollup", | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@bazel/rollup", | ||
"peerDependencies": { | ||
"rollup": ">1.0.0 <2.0.0" | ||
}, | ||
"description": "Run rollup.js bundler under Bazel", | ||
"license": "Apache-2.0", | ||
"version": "0.0.0-PLACEHOLDER", | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/bazelbuild/rules_nodejs.git", | ||
"directory": "packages/rollup" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bazelbuild/rules_nodejs/issues" | ||
}, | ||
"keywords": [ | ||
"rollup", | ||
"bazel" | ||
], | ||
"bin": { | ||
"rollup": "index.js" | ||
}, | ||
"bazelWorkspaces": { | ||
"npm_bazel_rollup": { | ||
"rootPath": "." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Note: we cannot require() any plugins here because the user may not have any installed | ||
|
||
module.exports = { | ||
output: { | ||
name: 'bundle', | ||
}, | ||
plugins: [], | ||
}; |
Oops, something went wrong.