diff --git a/BUILD.bazel b/BUILD.bazel index 931e93ef52..57b547ae53 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -64,7 +64,10 @@ filegroup( npm_package( name = "rules_nodejs_package", - srcs = glob(["*.bzl"]) + [ + srcs = glob([ + "*.bzl", + "*.patch", + ]) + [ "BUILD.bazel", "LICENSE", ], diff --git a/defs.bzl b/defs.bzl index eead5ed3e6..2ecb9a49fb 100644 --- a/defs.bzl +++ b/defs.bzl @@ -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() diff --git a/docs/index.md b/docs/index.md index 752b1184a5..b2c3850a44 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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", @@ -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", diff --git a/examples/angular/WORKSPACE b/examples/angular/WORKSPACE index 3f392b02d2..e44ec3b027 100644 --- a/examples/angular/WORKSPACE +++ b/examples/angular/WORKSPACE @@ -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", @@ -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"], diff --git a/examples/angular_view_engine/WORKSPACE b/examples/angular_view_engine/WORKSPACE index 535f3b065a..d5391e5831 100644 --- a/examples/angular_view_engine/WORKSPACE +++ b/examples/angular_view_engine/WORKSPACE @@ -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", diff --git a/examples/nestjs/WORKSPACE b/examples/nestjs/WORKSPACE index 7b10314e84..c6969a7688 100644 --- a/examples/nestjs/WORKSPACE +++ b/examples/nestjs/WORKSPACE @@ -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"], diff --git a/package.bzl b/package.bzl index 0ed9365497..24fa936f74 100644 --- a/package.bzl +++ b/package.bzl @@ -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", diff --git a/rules_docker.patch b/rules_docker.patch new file mode 100644 index 0000000000..311ce69664 --- /dev/null +++ b/rules_docker.patch @@ -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", diff --git a/rules_sass.patch b/rules_sass.patch new file mode 100644 index 0000000000..3a0782e9af --- /dev/null +++ b/rules_sass.patch @@ -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.