diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 99f85bc0be..404fdc506e 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -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" @@ -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" @@ -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" @@ -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" diff --git a/.circleci/config.yml b/.circleci/config.yml index 6aec7c66dd..3d16dee58c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: @@ -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//... diff --git a/docs/Built-ins.md b/docs/Built-ins.md index b705f5ab77..17ac6748e7 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -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. @@ -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`. @@ -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. @@ -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 ``` diff --git a/docs/TypeScript.md b/docs/TypeScript.md index e5bc0a9a0e..8e49d7753b 100755 --- a/docs/TypeScript.md +++ b/docs/TypeScript.md @@ -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 diff --git a/docs/install.md b/docs/install.md index 8c20eec65b..7eeb42bb3b 100644 --- a/docs/install.md +++ b/docs/install.md @@ -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 = [...])`). @@ -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 -- +$ bazel run @nodejs//:yarn -- ``` If you use npm instead, run: ```sh -$ bazel run @nodejs//:bin/npm -- +$ bazel run @nodejs//: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 +$ bazel run @nodejs//:yarn -- add ``` Note: the arguments passed to `bazel run` after `--` are forwarded to the executable being run. diff --git a/e2e/BUILD.bazel b/e2e/BUILD.bazel index 272b4ebff4..1fc8ce09bc 100644 --- a/e2e/BUILD.bazel +++ b/e2e/BUILD.bazel @@ -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 = { diff --git a/e2e/ts_auto_deps/package.json b/e2e/ts_auto_deps/package.json index d19324c206..df4b6b34d8 100644 --- a/e2e/ts_auto_deps/package.json +++ b/e2e/ts_auto_deps/package.json @@ -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" } diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index ad6d2fdc87..c6bc870fa2 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -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 diff --git a/examples/user_managed_deps/WORKSPACE b/examples/user_managed_deps/WORKSPACE index d7108ea97d..86b0e61fe4 100644 --- a/examples/user_managed_deps/WORKSPACE +++ b/examples/user_managed_deps/WORKSPACE @@ -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"], ) diff --git a/examples/user_managed_deps/package.json b/examples/user_managed_deps/package.json index f3829e4872..28966d52b8 100644 --- a/examples/user_managed_deps/package.json +++ b/examples/user_managed_deps/package.json @@ -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 ..." } } diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index cac71a97e5..ba0ad77be4 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -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. @@ -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 = { @@ -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( @@ -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) @@ -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") @@ -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}") @@ -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"], @@ -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), @@ -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): @@ -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") diff --git a/internal/npm_package/npm_package.bzl b/internal/npm_package/npm_package.bzl index 5f4e895232..3304429f0e 100644 --- a/internal/npm_package/npm_package.bzl +++ b/internal/npm_package/npm_package.bzl @@ -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 ``` diff --git a/packages/typescript/docs/install.md b/packages/typescript/docs/install.md index 41bdc7c1fa..043eb2f481 100644 --- a/packages/typescript/docs/install.md +++ b/packages/typescript/docs/install.md @@ -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