diff --git a/docs/Built-ins.md b/docs/Built-ins.md index 0f7a32fa7c..f78db9c837 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -746,9 +746,10 @@ Defaults to `None`
 npm_install(name, args, data, environment, exports_directories_only,
             generate_local_modules_build_files, included_files, links, manual_build_file_contents,
-            npm_command, package_json, package_json_remove, package_json_replace, package_lock_json,
-            package_path, patch_args, patch_tool, post_install_patches, pre_install_patches, quiet,
-            repo_mapping, strict_visibility, symlink_node_modules, timeout)
+            node_repository, npm_command, package_json, package_json_remove, package_json_replace,
+            package_lock_json, package_path, patch_args, patch_tool, post_install_patches,
+            pre_install_patches, quiet, repo_mapping, strict_visibility, symlink_node_modules,
+            timeout)
 
Runs npm install during workspace setup. @@ -976,6 +977,13 @@ fine grained npm dependencies. Defaults to `""` +

node_repository

+ +(*String*): The basename for nodejs toolchains. + Usually this is the value of the `name` attribute given to a nodejs_register_toolchains call in WORKSPACE + +Defaults to `"nodejs"` +

npm_command

(*String*): The npm command to run, to install dependencies. @@ -1413,8 +1421,8 @@ Defaults to `{}`
 yarn_install(name, args, data, environment, exports_directories_only, frozen_lockfile,
              generate_local_modules_build_files, included_files, links, manual_build_file_contents,
-             package_json, package_json_remove, package_json_replace, package_path, patch_args,
-             patch_tool, post_install_patches, pre_install_patches, quiet, repo_mapping,
+             node_repository, package_json, package_json_remove, package_json_replace, package_path,
+             patch_args, patch_tool, post_install_patches, pre_install_patches, quiet, repo_mapping,
              strict_visibility, symlink_node_modules, timeout, use_global_yarn_cache, yarn_lock)
 
@@ -1658,6 +1666,13 @@ fine grained npm dependencies. Defaults to `""` +

node_repository

+ +(*String*): The basename for nodejs toolchains. + Usually this is the value of the `name` attribute given to a nodejs_register_toolchains call in WORKSPACE + +Defaults to `"nodejs"` +

package_json

(*Label, mandatory*) diff --git a/internal/node/node_labels.bzl b/internal/node/node_labels.bzl index 393661ce9d..8c677612f7 100644 --- a/internal/node/node_labels.bzl +++ b/internal/node/node_labels.bzl @@ -19,22 +19,18 @@ Labels are different on windows and linux/OSX. load("//nodejs/private:os_name.bzl", "is_windows_os", "os_name") +def _get_label(rctx, tool): + ext = ".cmd" if is_windows_os(rctx) else "" + return Label("@{}_{}//:{}{}".format(rctx.attr.node_repository, os_name(rctx), tool, ext)) + def get_node_label(rctx): - if is_windows_os(rctx): - return Label("@nodejs_%s//:bin/node.cmd" % os_name(rctx)) - return Label("@nodejs_%s//:bin/node" % os_name(rctx)) + return _get_label(rctx, "bin/node") def get_npm_label(rctx): - if is_windows_os(rctx): - return Label("@nodejs_%s//:bin/npm.cmd" % os_name(rctx)) - return Label("@nodejs_%s//:bin/npm" % os_name(rctx)) + return _get_label(rctx, "bin/npm") def get_npm_node_repositories_label(rctx): - if is_windows_os(rctx): - return Label("@nodejs_%s//:bin/npm_node_repositories.cmd" % os_name(rctx)) - return Label("@nodejs_%s//:bin/npm_node_repositories" % os_name(rctx)) + return _get_label(rctx, "bin/npm_node_repositories") def get_yarn_label(rctx): - if is_windows_os(rctx): - return Label("@nodejs_%s//:bin/yarn.cmd" % os_name(rctx)) - return Label("@nodejs_%s//:bin/yarn" % os_name(rctx)) + return _get_label(rctx, "bin/yarn") diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl index adfcef1356..03c6e8adb0 100644 --- a/internal/npm_install/npm_install.bzl +++ b/internal/npm_install/npm_install.bzl @@ -219,6 +219,11 @@ node_modules target it is recommended to switch to using fine grained npm dependencies. """, ), + "node_repository": attr.string( + default = "nodejs", + doc = """The basename for nodejs toolchains. + Usually this is the value of the `name` attribute given to a nodejs_register_toolchains call in WORKSPACE""", + ), "package_json": attr.label( mandatory = True, allow_single_file = True, @@ -627,11 +632,11 @@ def _add_node_repositories_info_deps(repository_ctx): # Add a dep to the node_info & yarn_info files from node_repositories # so that if the node or yarn versions change we re-run the repository rule repository_ctx.symlink( - Label("@nodejs_%s//:node_info" % os_name(repository_ctx)), + Label("@{}_{}//:node_info".format(repository_ctx.attr.node_repository, os_name(repository_ctx))), repository_ctx.path("_node_info"), ) repository_ctx.symlink( - Label("@nodejs_%s//:yarn_info" % os_name(repository_ctx)), + Label("@{}_{}//:yarn_info".format(repository_ctx.attr.node_repository, os_name(repository_ctx))), repository_ctx.path("_yarn_info"), ) @@ -667,7 +672,6 @@ def _check_min_bazel_version(rule, repository_ctx): def _npm_install_impl(repository_ctx): """Core implementation of npm_install.""" - _check_min_bazel_version("npm_install", repository_ctx) is_windows_host = is_windows_os(repository_ctx) @@ -807,7 +811,6 @@ check if yarn is being run by the `npm_install` repository rule.""", def _yarn_install_impl(repository_ctx): """Core implementation of yarn_install.""" - _check_min_bazel_version("yarn_install", repository_ctx) is_windows_host = is_windows_os(repository_ctx) diff --git a/npm_deps.bzl b/npm_deps.bzl index 3fda83dda6..31632c3113 100644 --- a/npm_deps.bzl +++ b/npm_deps.bzl @@ -1,6 +1,18 @@ """Define npm deps in yarn_install && npm_install repositories""" -load("//:index.bzl", "npm_install", "yarn_install") +load("//:index.bzl", _npm_install = "npm_install", _yarn_install = "yarn_install") + +def npm_install(**kwargs): + _npm_install( + node_repository = "node16", + **kwargs + ) + +def yarn_install(**kwargs): + _yarn_install( + node_repository = "node16", + **kwargs + ) def npm_deps(): """Organize all yarn_install and npm_install calls here to prevent WORKSPACE bloat"""