Skip to content

Commit

Permalink
chore: make defs.bzl error
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Users must now switch to loading from index.bzl

Fixes bazel-contrib#1068
  • Loading branch information
alexeagle committed Dec 5, 2019
1 parent f8035aa commit cfefeac
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 64 deletions.
5 changes: 4 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ filegroup(

npm_package(
name = "rules_nodejs_package",
srcs = glob(["*.bzl"]) + [
srcs = glob([
"*.bzl",
"*.patch",
]) + [
"BUILD.bazel",
"LICENSE",
],
Expand Down
99 changes: 38 additions & 61 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,54 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Public API surface is re-exported here.
Users should not load files under "/internal"
"""No longer usable - you must load from index.bzl
"""

load("//internal/common:check_bazel_version.bzl", _check_bazel_version = "check_bazel_version")
load("//internal/common:check_version.bzl", "check_version")
load("//internal/jasmine_node_test:jasmine_node_test.bzl", _jasmine_node_test = "jasmine_node_test")
load(
"//internal/node:node.bzl",
_nodejs_binary = "nodejs_binary",
_nodejs_test = "nodejs_test",
def _error(*args, **kwargs):
fail("""
ERROR: defs.bzl has been removed from build_bazel_rules_nodejs
Please update your load statements to use index.bzl instead.
If you depend on another ruleset that has not updated to index.bzl, you can patch it locally.
For example, for rules_sass:
http_archive(
name = "io_bazel_rules_sass",
patch_args = ["-p1"],
patches = ["@build_bazel_rules_nodejs//:rules_sass.patch"],
...
)
and for rules_docker:
http_archive(
name = "io_bazel_rules_docker",
patch_args = ["-p1"],
patches = ["@build_bazel_rules_nodejs//:rules_docker.patch"],
...
)
load("//internal/node:node_repositories.bzl", _node_repositories = "node_repositories")
load("//internal/node:npm_package_bin.bzl", _npm_bin = "npm_package_bin")
load("//internal/npm_install:npm_install.bzl", _npm_install = "npm_install", _yarn_install = "yarn_install")
load("//internal/npm_package:npm_package.bzl", _npm_package = "npm_package")
load(":index.bzl", "VERSION")
check_bazel_version = _check_bazel_version
nodejs_binary = _nodejs_binary
nodejs_test = _nodejs_test
node_repositories = _node_repositories
jasmine_node_test = _jasmine_node_test
npm_package = _npm_package
npm_package_bin = _npm_bin
Note that due to version skew, these patches might not apply cleanly. In that case
create your own patch file in your repo.
""")

check_bazel_version = _error
nodejs_binary = _error
nodejs_test = _error
node_repositories = _error
jasmine_node_test = _error
npm_package = _error
npm_package_bin = _error
# ANY RULES ADDED HERE SHOULD BE DOCUMENTED, see index.for_docs.bzl

def node_modules_filegroup(packages, patterns = [], **kwargs):
native.filegroup(
srcs = native.glob(["/".join([
"node_modules",
pkg,
"**",
ext,
]) for pkg in packages for ext in [
"*.js",
"*.json",
"*.d.ts",
]] + patterns),
**kwargs
)
_error()

def npm_install(**kwargs):
# Just in case the user didn't install nodejs, do it now
_node_repositories()
_npm_install(**kwargs)
_error()

def yarn_install(**kwargs):
# Just in case the user didn't install nodejs, do it now
_node_repositories()
_yarn_install(**kwargs)
_error()

def check_rules_nodejs_version(minimum_version_string):
"""
Verify that a minimum build_bazel_rules_nodejs is loaded a WORKSPACE.
This should be called from the `WORKSPACE` file so that the build fails as
early as possible. For example:
```
# in WORKSPACE:
load("@build_bazel_rules_nodejs//:package.bzl", "check_rules_nodejs_version")
check_rules_nodejs_version("0.11.2")
```
Args:
minimum_version_string: a string indicating the minimum version
"""
if not check_version(VERSION, minimum_version_string):
fail("\nCurrent build_bazel_rules_nodejs version is {}, expected at least {}\n".format(
VERSION,
minimum_version_string,
))
_error()
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ See [Built-ins]
If you have installed the [rollup] package, you could write this rule:

```python
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

nodejs_binary(
name = "rollup",
Expand All @@ -66,7 +66,7 @@ See the `examples/parcel` example.
We can reference a path in the local workspace to run a program we write.

```python
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

nodejs_binary(
name = "example",
Expand Down
4 changes: 4 additions & 0 deletions examples/angular/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ http_archive(
# Fetch sass rules for compiling sass files
http_archive(
name = "io_bazel_rules_sass",
patch_args = ["-p1"],
patches = ["@build_bazel_rules_nodejs//:rules_sass.patch"],
sha256 = "4f05239080175a3f4efa8982d2b7775892d656bb47e8cf56914d5f9441fb5ea6",
strip_prefix = "rules_sass-86ca977cf2a8ed481859f83a286e164d07335116",
url = "https://github.com/bazelbuild/rules_sass/archive/86ca977cf2a8ed481859f83a286e164d07335116.zip",
Expand Down Expand Up @@ -109,6 +111,8 @@ http_archive(

http_archive(
name = "io_bazel_rules_docker",
patch_args = ["-p1"],
patches = ["@build_bazel_rules_nodejs//:rules_docker.patch"],
sha256 = "413bb1ec0895a8d3249a01edf24b82fd06af3c8633c9fb833a0cb1d4b234d46d",
strip_prefix = "rules_docker-0.12.0",
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.12.0/rules_docker-v0.12.0.tar.gz"],
Expand Down
2 changes: 2 additions & 0 deletions examples/angular_view_engine/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ http_archive(
# Fetch sass rules for compiling sass files
http_archive(
name = "io_bazel_rules_sass",
patch_args = ["-p1"],
patches = ["@build_bazel_rules_nodejs//:rules_sass.patch"],
sha256 = "4f05239080175a3f4efa8982d2b7775892d656bb47e8cf56914d5f9441fb5ea6",
strip_prefix = "rules_sass-86ca977cf2a8ed481859f83a286e164d07335116",
url = "https://github.com/bazelbuild/rules_sass/archive/86ca977cf2a8ed481859f83a286e164d07335116.zip",
Expand Down
2 changes: 2 additions & 0 deletions examples/nestjs/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ install_bazel_dependencies()

http_archive(
name = "io_bazel_rules_docker",
patch_args = ["-p1"],
patches = ["@build_bazel_rules_nodejs//:rules_docker.patch"],
sha256 = "7d453450e1eb70e238eea6b31f4115607ec1200e91afea01c25f9804f37e39c8",
strip_prefix = "rules_docker-0.10.0",
urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.10.0.tar.gz"],
Expand Down
2 changes: 2 additions & 0 deletions package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def rules_nodejs_dev_dependencies():
# Dependencies for generating documentation
http_archive(
name = "io_bazel_rules_sass",
patch_args = ["-p1"],
patches = ["//:rules_sass.patch"],
sha256 = "4f05239080175a3f4efa8982d2b7775892d656bb47e8cf56914d5f9441fb5ea6",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/86ca977cf2a8ed481859f83a286e164d07335116.zip",
Expand Down
13 changes: 13 additions & 0 deletions rules_docker.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/nodejs/image.bzl b/nodejs/image.bzl
index a01ea3e..617aa06 100644
--- a/nodejs/image.bzl
+++ b/nodejs/image.bzl
@@ -17,7 +17,7 @@ The signature of this rule is compatible with nodejs_binary.
"""

load("@bazel_skylib//lib:dicts.bzl", "dicts")
-load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
+load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load(
"//container:container.bzl",
"container_pull",
25 changes: 25 additions & 0 deletions rules_sass.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/sass/BUILD b/sass/BUILD
index 8963525..dccce74 100644
--- a/sass/BUILD
+++ b/sass/BUILD
@@ -1,6 +1,6 @@
package(default_visibility = ["//visibility:public"])

-load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
+load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

exports_files([
"sass.bzl",
diff --git a/sass/sass_repositories.bzl b/sass/sass_repositories.bzl
index 4833f41..9cb2056 100644
--- a/sass/sass_repositories.bzl
+++ b/sass/sass_repositories.bzl
@@ -14,7 +14,7 @@

"Install Sass toolchain dependencies"

-load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install", "check_rules_nodejs_version")
+load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install", "check_rules_nodejs_version")

def sass_repositories():
"""Set up environment for Sass compiler.

0 comments on commit cfefeac

Please sign in to comment.