Skip to content

Commit

Permalink
refactor: npm_install and yarn_install no longer create node reposito…
Browse files Browse the repository at this point in the history
…ries

This convenience is now too magical and confusing. If the user registers nodejs toolchains, this will create an extra toolchain they don't use,
but can be fetched by rules that reference the default.
It also makes a @Yarn workspace available even for users who only need npm.

BREAKING CHANGE:
you now need to explicitly register nodejs toolchains or use the node_repositories helper
  • Loading branch information
alexeagle committed Jan 15, 2022
1 parent 5ad9753 commit 72a85cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ nodejs_register_toolchains(
node_version = "15.14.0",
)

load("@rules_nodejs//nodejs:yarn_repositories.bzl", "yarn_repositories")

yarn_repositories(
name = "yarn",
node_repository = "node16",
)

load("@build_bazel_rules_nodejs//:npm_deps.bzl", "npm_deps")

npm_deps()
Expand Down
12 changes: 2 additions & 10 deletions index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ copy_to_bin = _copy_to_bin
params_file = _params_file
generated_file_test = _generated_file_test
js_library = _js_library
npm_install = _npm_install
yarn_install = _yarn_install
# ANY RULES ADDED HERE SHOULD BE DOCUMENTED, see index.for_docs.bzl

# @unsorted-dict-items
Expand All @@ -55,16 +57,6 @@ COMMON_REPLACEMENTS = {
"\"@bazel/([a-zA-Z_-]+)\":\\s+\"(file|bazel)[^\"]+\"": "\"@bazel/$1\": \"0.0.0-PLACEHOLDER\"",
}

def npm_install(**kwargs):
# Just in case the user didn't install nodejs, do it now
_node_repositories()
_npm_install(**kwargs)

def yarn_install(**kwargs):
# Just in case the user didn't install nodejs, do it now
_node_repositories()
_yarn_install(**kwargs)

# Currently used Bazel version. This version is what the rules here are tested
# against.
# This version should be updated together with the version of the Bazel
Expand Down

0 comments on commit 72a85cf

Please sign in to comment.