Skip to content

Commit

Permalink
refactor: add index.bzl
Browse files Browse the repository at this point in the history
The build_bazel_rules_nodejs workspace is the last one using defs.bzl

see bazel-contrib#1068
  • Loading branch information
alexeagle committed Sep 21, 2019
1 parent 6612671 commit ce3aed8
Show file tree
Hide file tree
Showing 102 changed files with 233 additions and 128 deletions.
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@build_bazel_rules_nodejs//:defs.bzl", "COMMON_REPLACEMENTS", "npm_package")
load("@build_bazel_rules_nodejs//:index.bzl", "COMMON_REPLACEMENTS", "npm_package")

package(default_visibility = ["//visibility:public"])

Expand All @@ -28,7 +28,7 @@ bzl_library(
name = "bzl",
srcs = [
"declaration_provider.bzl",
"defs.bzl",
"index.bzl",
"index.for_docs.bzl",
],
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ rules_nodejs_dev_dependencies()
# Setup rules_nodejs npm dependencies
#

load("//:defs.bzl", "npm_install", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install", "yarn_install")

yarn_install(
name = "npm",
Expand Down
13 changes: 0 additions & 13 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ npm_package = _npm_package
npm_package_bin = _npm_bin
# ANY RULES ADDED HERE SHOULD BE DOCUMENTED, see index.for_docs.bzl

# Allows us to avoid a transitive dependency on bazel_skylib from leaking to users
def dummy_bzl_library(name, **kwargs):
native.filegroup(name = name)

# @unsorted-dict-items
COMMON_REPLACEMENTS = {
# Replace loads from @bazel_skylib with the dummy rule above
"(load\\(\"@bazel_skylib//:bzl_library.bzl\", \"bzl_library\"\\))": "# bazel_skylib mocked out\n# $1\nload(\"@build_bazel_rules_nodejs//:defs.bzl\", bzl_library = \"dummy_bzl_library\")",
# Cleanup up package.json @bazel/foobar package deps for published packages:
# "@bazel/foobar": "file:///..." => "@bazel/foobar": "0.0.0-PLACEHOLDER"
"\"@bazel/([a-zA-Z_-]+)\":\\s+\"(file|bazel)[^\"]+\"": "\"@bazel/$1\": \"0.0.0-PLACEHOLDER\"",
}

def node_modules_filegroup(packages, patterns = [], **kwargs):
native.filegroup(
srcs = native.glob(["/".join([
Expand Down
8 changes: 4 additions & 4 deletions docs/Built-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ See the `npm_install` and `yarn_install` rules, and the discussion in the README
Example:

```
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
node_repositories(package_json = ["//:package.json", "//subpkg:package.json"])
```

Expand Down Expand Up @@ -746,7 +746,7 @@ The npm_package rule creates a directory containing a publishable npm artifact.
Example:

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

npm_package(
name = "my_package",
Expand Down Expand Up @@ -851,7 +851,7 @@ npm_package(name, deps, packages, rename_build_files, replace_with_version, repl
Produces several bundled JavaScript files using Rollup and terser.

Load it with
`load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")`
`load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")`

It performs this work in several separate processes:
1. Call rollup on the original sources
Expand Down Expand Up @@ -1260,7 +1260,7 @@ early as possible. For example:

```
# in WORKSPACE:
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version")
load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version")
check_bazel_version("0.26.0")
```

Expand Down
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
14 changes: 7 additions & 7 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

Now you can choose from a few options to finish installation.
Expand Down Expand Up @@ -96,7 +96,7 @@ If you'd like to use a version of NodeJS and/or Yarn that are not currently supp
specify those in your `WORKSPACE`:

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

# NOTE: this rule does NOT install your npm dependencies into your node_modules folder.
# You must still run the package manager to do this.
Expand Down Expand Up @@ -124,7 +124,7 @@ Finally, you could check Node.js and Yarn into your repository, and not fetch
them from the internet. This is what we do internally at Google.

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

# Point node_repositories to use locally installed versions of Node.js and Yarn.
# The vendored_node and vendored_yarn labels point to the extracted contents of
Expand Down Expand Up @@ -182,7 +182,7 @@ file:
Using Yarn (preferred):

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

yarn_install(
name = "npm",
Expand All @@ -194,7 +194,7 @@ yarn_install(
Using NPM:

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

npm_install(
name = "npm",
Expand Down Expand Up @@ -234,7 +234,7 @@ common --experimental_allow_incremental_repository_updates
You can then reference individual npm packages in your `BUILD` rules via:

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

nodejs_binary(
name = "bar",
Expand Down Expand Up @@ -308,7 +308,7 @@ with the `node_modules` attribute of nodejs rules.
* `@npm//:node_modules` includes all packages under `node_modules` as well as the `.bin` folder

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

nodejs_binary(
name = "bar",
Expand Down
2 changes: 1 addition & 1 deletion e2e/bazel_managed_deps/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/fine_grained_symlinks/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

# Test for regressions to https://github.com/bazelbuild/rules_nodejs/issues/428
# and https://github.com/bazelbuild/rules_nodejs/issues/438.
Expand Down
2 changes: 1 addition & 1 deletion e2e/fine_grained_symlinks/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")

# This test needs to run with yarn 1.9.2 to test the fix for
# https://github.com/bazelbuild/rules_nodejs/issues/438 and
Expand Down
2 changes: 1 addition & 1 deletion e2e/jasmine/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/karma/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/karma_stack_trace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/karma_typescript/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/node_loader_no_preserve_symlinks/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

package(default_visibility = ["//visibility:public"])

Expand Down
2 changes: 1 addition & 1 deletion e2e/node_loader_no_preserve_symlinks/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")

node_repositories(preserve_symlinks = False)

Expand Down
2 changes: 1 addition & 1 deletion e2e/node_loader_preserve_symlinks/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

package(default_visibility = ["//visibility:public"])

Expand Down
2 changes: 1 addition & 1 deletion e2e/node_loader_preserve_symlinks/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

# This is like a "js_library", but there are no actions to run on JS files so a
# filegroup is semantically equivalent.
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "check_rules_nodejs_version", "node_repositories")
load("@build_bazel_rules_nodejs//:index.bzl", "check_rules_nodejs_version", "node_repositories")

# Test that check_rules_nodejs_version works as expected
check_rules_nodejs_version(minimum_version_string = "0.11.2")
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/setup_workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Helper function to setup @e2e_packages workspace.
"""

load("@build_bazel_rules_nodejs//:defs.bzl", "npm_install", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install", "yarn_install")

def e2e_packages_setup_workspace():
"""Node repositories for @e2e_packagess
Expand Down
2 changes: 1 addition & 1 deletion e2e/symlinked_node_modules_npm/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

nodejs_test(
name = "test",
Expand Down
2 changes: 1 addition & 1 deletion e2e/symlinked_node_modules_npm/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dev_dependencies")

rules_nodejs_dev_dependencies()

load("@build_bazel_rules_nodejs//:defs.bzl", "npm_install")
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")

npm_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/symlinked_node_modules_yarn/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

nodejs_test(
name = "test",
Expand Down
2 changes: 1 addition & 1 deletion e2e/symlinked_node_modules_yarn/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dev_dependencies")

rules_nodejs_dev_dependencies()

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/ts_auto_deps/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dev_dependencies")

rules_nodejs_dev_dependencies()

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/ts_devserver/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/typescript/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
load("@npm_bazel_typescript//:index.bzl", "ts_library")

Expand Down
2 changes: 1 addition & 1 deletion e2e/typescript/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/webapp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_terser//:index.bzl", "terser_minified")

Expand Down
2 changes: 1 addition & 1 deletion e2e/webapp/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion e2e/webpack/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ http_archive(
)

# Check the bazel version and download npm dependencies
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "yarn_install")

# Bazel version must be at least the following version because:
# - 0.27.0 Adds managed directories support
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
Expand Down
2 changes: 1 addition & 1 deletion examples/app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//:index.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@npm//http-server:index.bzl", "http_server")
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
Expand Down
2 changes: 1 addition & 1 deletion examples/app/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.1/rules_nodejs-0.37.1.tar.gz"],
)

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

yarn_install(
name = "npm",
Expand Down
Loading

0 comments on commit ce3aed8

Please sign in to comment.