Skip to content

Commit

Permalink
feat(builtin): rename @nodejs//:npm and @nodejs//:yarn to @nodejs//:[…
Browse files Browse the repository at this point in the history
…yarn/npm]_node_repositories

BREAKING CHANGES:

bazel run @nodejs//:npm is replaced with bazel run @nodejs//:npm_node_repositories and bazel run @nodejs//:yarn is replaced with bazel run @nodejs//:yarn_node_repositories. @nodejs//:yarn and @nodejs//:npm now run yarn & npm in the current working directory instead of on all of the package.json files in node_repositories().

@nodejs//:bin/node & @nodejs//:bin/node.cmd (on Windows) are no longer valid targets. Use @nodejs//:node instead on all platforms. You can still call the old targets in their platform specific node repositories such as @nodejs_darwin_amd64//:bin/node.

@nodejs//:bin/yarn & @nodejs//:bin/yarn.cmd (on Windows) are no longer valid targets. Use @nodejs//:yarn instead on all platforms. You can still call the old targets in their platform specific node repositories such as @nodejs_darwin_amd64//:bin/yarn.

@nodejs//:bin/npm & @nodejs//:bin/npm.cmd (on Windows) are no longer valid targets. Use @nodejs//:npm instead on all platforms. You can still call the old targets in their platform specific node repositories such as @nodejs_darwin_amd64//:bin/npm.
  • Loading branch information
gregmagolan committed Nov 21, 2019
1 parent dc57136 commit 5d88741
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 46 deletions.
8 changes: 4 additions & 4 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tasks:
name: ubuntu1604
platform: ubuntu1604
run_targets:
- "@nodejs//:yarn"
- "@nodejs//:yarn_node_repositories"
- "//internal/node/test:no_deps"
- "//internal/node/test:has_deps_legacy"
- "//internal/node/test:has_deps"
Expand Down Expand Up @@ -79,7 +79,7 @@ tasks:
name: ubuntu1804
platform: ubuntu1804
run_targets:
- "@nodejs//:yarn"
- "@nodejs//:yarn_node_repositories"
- "//internal/node/test:no_deps"
- "//internal/node/test:has_deps_legacy"
- "//internal/node/test:has_deps"
Expand Down Expand Up @@ -194,7 +194,7 @@ tasks:
name: macos
platform: macos
run_targets:
- "@nodejs//:yarn"
- "@nodejs//:yarn_node_repositories"
- "//internal/node/test:no_deps"
- "//internal/node/test:has_deps_legacy"
- "//internal/node/test:has_deps"
Expand Down Expand Up @@ -291,7 +291,7 @@ tasks:
name: windows
platform: windows
run_targets:
- "@nodejs//:yarn"
- "@nodejs//:yarn_node_repositories"
- "//internal/node/test:no_deps"
- "//internal/node/test:has_deps_legacy"
- "//internal/node/test:has_deps"
Expand Down
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ jobs:
- *yarn_install
- *init_bazel

# Run yarn on all node_repositories
- run: bazel run @nodejs//:bin/yarn
# Run yarn
- run: bazel run @nodejs//:yarn

# Save all node_modules to the cache
- save_cache:
Expand Down Expand Up @@ -236,7 +236,7 @@ jobs:
# We should also be able to test targets in a different workspace
# TODO(gmagolan): move these tests into `build` job once
# https://github.com/bazelbuild/bazel/issues/6481 is resolved
- run: 'cd examples/user_managed_deps && bazel run @nodejs//:yarn'
- run: 'cd examples/user_managed_deps && bazel run @nodejs//:yarn_node_repositories'
- run: bazel test @examples_user_managed_deps//...
- run: bazel test @e2e_packages//...

Expand Down
10 changes: 5 additions & 5 deletions docs/Built-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ to point to those before calling node_repositories.
This rule exposes the `@nodejs` workspace containing some rules the user can call later:

- Run node: `bazel run @nodejs//:node path/to/program.js`
- Install dependencies using npm: `bazel run @nodejs//:npm install`
- Install dependencies using yarn: `bazel run @nodejs//:yarn`
- Install dependencies using npm: `bazel run @nodejs//:npm_node_repositories install`
- Install dependencies using yarn: `bazel run @nodejs//:yarn_node_repositories`

Note that the dependency installation scripts will run in each subpackage indicated by the `package_json` attribute.

Expand All @@ -50,7 +50,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
node_repositories(package_json = ["//:package.json", "//subpkg:package.json"])
```

Running `bazel run @nodejs//:yarn` in this repo would create `/node_modules` and `/subpkg/node_modules`.
Running `bazel run @nodejs//:yarn_node_repositories` in this repo would create `/node_modules` and `/subpkg/node_modules`.



Expand Down Expand Up @@ -114,7 +114,7 @@ and expect that file to have sha256sum `00b7a8426e076e9bf9d12ba2d571312e833fe962
#### `package_json`
(*[labels]*): a list of labels, which indicate the package.json files that will be installed
when you manually run the package manager, e.g. with
`bazel run @nodejs//:yarn` or `bazel run @nodejs//:npm install`.
`bazel run @nodejs//:yarn_node_repositories` or `bazel run @nodejs//:npm_node_repositories install`.
If you use bazel-managed dependencies, you can omit this attribute.


Expand Down Expand Up @@ -777,7 +777,7 @@ Actually publish the package with `npm publish` (also builds first):

```sh
# Check login credentials
$ bazel run @nodejs//:npm who
$ bazel run @nodejs//:npm_node_repositories who
# Publishes the package
$ bazel run :my_package.publish
```
Expand Down
2 changes: 1 addition & 1 deletion docs/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ node_repositories(package_json = ["//:package.json"])
You can then run `yarn` in your workspace with:

```sh
$ bazel run @nodejs//:yarn
$ bazel run @nodejs//:yarn_node_repositories
```

To use your workspace `node_modules` folder as a dependency in `ts_library` and
Expand Down
14 changes: 6 additions & 8 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,16 @@ To use the Yarn package manager, which we recommend for its built-in
verification command, you can run:

```sh
$ bazel run @nodejs//:yarn
$ bazel run @nodejs//:yarn_node_repositories
```

If you use npm instead, run:

```sh
$ bazel run @nodejs//:npm install
$ bazel run @nodejs//:npm_node_repositories install
```

The `@nodejs//:yarn` and `@nodejs//:npm` targets will run yarn/npm on all of the
The `@nodejs//:yarn_node_repositories` and `@nodejs//:npm_node_repositories` targets will run yarn/npm on all of the
package.json contexts listed `package_json` attribute of the `node_repositories`
repository rule in your WORKSPACE file (`node_repositories(package_json = [...])`).

Expand All @@ -403,22 +403,20 @@ run the bazel managed yarn or npm on a single context this can be done
using the following targets:

```sh
$ bazel run @nodejs//:bin/yarn -- <arguments passed to yarn>
$ bazel run @nodejs//:yarn -- <arguments passed to yarn>
```

If you use npm instead, run:

```sh
$ bazel run @nodejs//:bin/npm -- <arguments passed to npm>
$ bazel run @nodejs//:npm -- <arguments passed to npm>
```

Note: on **Windows** the targets are `@nodejs//:bin/yarn.cmd` and `@nodejs//:bin/npm.cmd`.

This will run yarn/npm in the current working directory. To add a package with the `yarn add` command,
for example, you would use:

```sh
$ bazel run @nodejs//:bin/yarn -- add <package>
$ bazel run @nodejs//:yarn -- add <package>
```

Note: the arguments passed to `bazel run` after `--` are forwarded to the executable being run.
Expand Down
4 changes: 2 additions & 2 deletions e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ e2e_integration_test(
e2e_integration_test(
name = "e2e_ts_auto_deps",
bazel_commands = [
"run @nodejs//:yarn",
"run @nodejs//:bin/yarn -- generate_build_file",
"run @nodejs//:yarn_node_repositories",
"run @nodejs//:yarn -- generate_build_file",
"build //simple:simple",
],
npm_packages = {
Expand Down
2 changes: 1 addition & 1 deletion e2e/ts_auto_deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"typescript": "2.9.2"
},
"scripts": {
"pretest": "bazel run @nodejs//:yarn",
"pretest": "bazel run @nodejs//:yarn_node_repositories",
"generate_build_file": "cd simple && ts_auto_deps",
"test": "yarn generate_build_file && bazel build simple"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ example_integration_test(

example_integration_test(
name = "examples_user_managed_deps",
# This test requires calling `bazel run @nodejs//:yarn` before `bazel test ...`
# This test requires calling `bazel run @nodejs//:yarn_node_repositories` before `bazel test ...`
bazel_commands = [
"run @nodejs//:yarn",
"run @nodejs//:yarn_node_repositories",
"test ...",
],
# replace the following repositories with the generated archives
Expand Down
8 changes: 4 additions & 4 deletions examples/user_managed_deps/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
# - NodeJS:
# @nodejs//:node
# - NPM:
# @nodejs//:npm
# @nodejs//:npm_node_repositories
# - The yarn package manager:
# @nodejs//:yarn
# @nodejs//:yarn_node_repositories
#
# To install the node_modules of all the listed package_json files run:
# bazel run @nodejs//:yarn
# bazel run @nodejs//:yarn_node_repositories
# or
# bazel run @nodejs//:npm
# bazel run @nodejs//:npm_node_repositories
node_repositories(
package_json = ["//:package.json"],
)
Expand Down
2 changes: 1 addition & 1 deletion examples/user_managed_deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"v8-coverage": "1.0.9"
},
"scripts": {
"pretest": "bazel run @nodejs//:yarn",
"pretest": "bazel run @nodejs//:yarn_node_repositories",
"test": "bazel test ..."
}
}
37 changes: 24 additions & 13 deletions internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ to point to those before calling node_repositories.
This rule exposes the `@nodejs` workspace containing some rules the user can call later:
- Run node: `bazel run @nodejs//:node path/to/program.js`
- Install dependencies using npm: `bazel run @nodejs//:npm install`
- Install dependencies using yarn: `bazel run @nodejs//:yarn`
- Install dependencies using npm: `bazel run @nodejs//:npm_node_repositories install`
- Install dependencies using yarn: `bazel run @nodejs//:yarn_node_repositories`
Note that the dependency installation scripts will run in each subpackage indicated by the `package_json` attribute.
Expand All @@ -59,7 +59,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
node_repositories(package_json = ["//:package.json", "//subpkg:package.json"])
```
Running `bazel run @nodejs//:yarn` in this repo would create `/node_modules` and `/subpkg/node_modules`.
Running `bazel run @nodejs//:yarn_node_repositories` in this repo would create `/node_modules` and `/subpkg/node_modules`.
"""

_ATTRS = {
Expand Down Expand Up @@ -159,7 +159,7 @@ and expect that file to have sha256sum `00b7a8426e076e9bf9d12ba2d571312e833fe962
"package_json": attr.label_list(
doc = """a list of labels, which indicate the package.json files that will be installed
when you manually run the package manager, e.g. with
`bazel run @nodejs//:yarn` or `bazel run @nodejs//:npm install`.
`bazel run @nodejs//:yarn_node_repositories` or `bazel run @nodejs//:npm_node_repositories install`.
If you use bazel-managed dependencies, you can omit this attribute.""",
),
"preserve_symlinks": attr.bool(
Expand Down Expand Up @@ -376,7 +376,6 @@ def _prepare_node(repository_ctx):

node_bin = ("%s/bin/node" % node_path) if not is_windows else ("%s/node.exe" % node_path)
node_bin_label = ("%s/bin/node" % node_package) if not is_windows else ("%s/node.exe" % node_package)
node_entry = "bin/node" if not is_windows else "bin/node.cmd"
npm_bin = ("%s/bin/npm" % node_path) if not is_windows else ("%s/npm.cmd" % node_path)
npm_bin_label = ("%s/bin/npm" % node_package) if not is_windows else ("%s/npm.cmd" % node_package)
npm_script = ("%s/lib/node_modules/npm/bin/npm-cli.js" % node_path) if not is_windows else ("%s/node_modules/npm/bin/npm-cli.js" % node_path)
Expand All @@ -386,6 +385,13 @@ def _prepare_node(repository_ctx):
yarn_bin_label = ("%s/bin/yarn" % yarn_package) if not is_windows else ("%s/npx.yarn" % yarn_package)
yarn_script = "%s/bin/yarn.js" % yarn_path

entry_ext = ".cmd" if is_windows else ""
node_entry = "bin/node%s" % entry_ext
npm_entry = "bin/npm%s" % entry_ext
yarn_entry = "bin/yarn%s" % entry_ext
npm_node_repositories_entry = "bin/npm_node_repositories%s" % entry_ext
yarn_node_repositories_entry = "bin/yarn_node_repositories%s" % entry_ext

node_bin_relative = node_bin if repository_ctx.attr.vendored_node else paths.relativize(node_bin, "bin")
npm_script_relative = npm_script if repository_ctx.attr.vendored_node else paths.relativize(npm_script, "bin")
yarn_script_relative = yarn_script if repository_ctx.attr.vendored_yarn else paths.relativize(yarn_script, "bin")
Expand Down Expand Up @@ -592,11 +598,11 @@ package(default_visibility = ["//visibility:public"])
exports_files([
"run_npm.sh.template",
"bin/node_repo_args.sh",{node_bin_export}{npm_bin_export}{npx_bin_export}{yarn_bin_export}
"bin/node{entry_ext}",
"bin/npm{entry_ext}",
"bin/npm_node_repositories{entry_ext}",
"bin/yarn{entry_ext}",
"bin/yarn_node_repositories{entry_ext}",
"{node_entry}",
"{npm_entry}",
"{yarn_entry}",
"{npm_node_repositories_entry}",
"{yarn_node_repositories_entry}",
])
alias(name = "node_bin", actual = "{node_bin_label}")
alias(name = "npm_bin", actual = "{npm_bin_label}")
Expand All @@ -605,6 +611,8 @@ alias(name = "yarn_bin", actual = "{yarn_bin_label}")
alias(name = "node", actual = "{node_entry}")
alias(name = "npm", actual = "{npm_entry}")
alias(name = "yarn", actual = "{yarn_entry}")
alias(name = "npm_node_repositories", actual = "{npm_node_repositories_entry}")
alias(name = "yarn_node_repositories", actual = "{yarn_node_repositories_entry}")
filegroup(
name = "node_files",
srcs = [":node", ":node_bin"],
Expand All @@ -618,7 +626,6 @@ filegroup(
srcs = glob(["bin/nodejs/**"]) + [":node_files"],
)
""".format(
entry_ext = ".cmd" if is_windows else "",
node_bin_export = "" if repository_ctx.attr.vendored_node else ("\n \"%s\"," % node_bin),
npm_bin_export = "" if repository_ctx.attr.vendored_node else ("\n \"%s\"," % npm_bin),
npx_bin_export = "" if repository_ctx.attr.vendored_node else ("\n \"%s\"," % npx_bin),
Expand All @@ -628,8 +635,10 @@ filegroup(
npx_bin_label = npx_bin_label,
yarn_bin_label = yarn_bin_label,
node_entry = node_entry,
npm_entry = "bin/npm_node_repositories" if not is_windows else "bin/npm_node_repositories.cmd",
yarn_entry = "bin/yarn_node_repositories" if not is_windows else "bin/yarn_node_repositories.cmd",
npm_entry = npm_entry,
yarn_entry = yarn_entry,
npm_node_repositories_entry = npm_node_repositories_entry,
yarn_node_repositories_entry = yarn_node_repositories_entry,
))

def _nodejs_repo_impl(repository_ctx):
Expand Down Expand Up @@ -660,6 +669,8 @@ alias(name = "yarn_bin", actual = "{node_repository}//:yarn_bin")
alias(name = "node", actual = "{node_repository}//:node")
alias(name = "npm", actual = "{node_repository}//:npm")
alias(name = "yarn", actual = "{node_repository}//:yarn")
alias(name = "npm_node_repositories", actual = "{node_repository}//:npm_node_repositories")
alias(name = "yarn_node_repositories", actual = "{node_repository}//:yarn_node_repositories")
alias(name = "node_files", actual = "{node_repository}//:node_files")
alias(name = "yarn_files", actual = "{node_repository}//:yarn_files")
alias(name = "npm_files", actual = "{node_repository}//:npm_files")
Expand Down
2 changes: 1 addition & 1 deletion internal/npm_package/npm_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Actually publish the package with `npm publish` (also builds first):
```sh
# Check login credentials
$ bazel run @nodejs//:npm who
$ bazel run @nodejs//:npm_node_repositories who
# Publishes the package
$ bazel run :my_package.publish
```
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ node_repositories(package_json = ["//:package.json"])
You can then run `yarn` in your workspace with:

```sh
$ bazel run @nodejs//:yarn
$ bazel run @nodejs//:yarn_node_repositories
```

To use your workspace `node_modules` folder as a dependency in `ts_library` and
Expand Down

0 comments on commit 5d88741

Please sign in to comment.