diff --git a/WORKSPACE b/WORKSPACE index 826c846796..c1138ddf57 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -51,6 +51,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "npm_install", "yarn_install") yarn_install( name = "npm", data = [ + "//:patches/jest-haste-map+25.3.0.patch", "//internal/npm_install/test:postinstall.js", ], environment = { diff --git a/examples/vendored_node_and_yarn/WORKSPACE b/examples/vendored_node_and_yarn/WORKSPACE index a430f6a74c..89409231b5 100644 --- a/examples/vendored_node_and_yarn/WORKSPACE +++ b/examples/vendored_node_and_yarn/WORKSPACE @@ -52,7 +52,7 @@ yarn_install( name = "npm", data = [ "@vendored_node_10_12_0//:node-v10.12.0-linux-x64/bin/node", - "@vendored_yarn_1_10_0//:vendored_yarn_1_10_0/yarn-v1.10.0/bin/yarn.js", + "@vendored_yarn_1_10_0//:yarn-v1.10.0/bin/yarn.js", ], package_json = "//:package.json", yarn_lock = "//:yarn.lock", diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index dfd11aed82..ba7ef66f9f 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -280,6 +280,9 @@ def _download_node(repository_ctx): repository_ctx: The repository rule context """ if repository_ctx.attr.vendored_node: + repository_ctx.file("node_info", content = "# vendored_node: {vendored_node}".format( + vendored_node = repository_ctx.attr.vendored_node, + )) return # The host is baked into the repository name by design. @@ -304,6 +307,15 @@ def _download_node(repository_ctx): sha256 = sha256, ) + repository_ctx.file("node_info", content = """# filename: {filename} +# strip_prefix: {strip_prefix} +# sha256: {sha256} +""".format( + filename = filename, + strip_prefix = strip_prefix, + sha256 = sha256, + )) + def _download_yarn(repository_ctx): """Used to download a yarn tool package. @@ -311,6 +323,9 @@ def _download_yarn(repository_ctx): repository_ctx: The repository rule context """ if repository_ctx.attr.vendored_yarn: + repository_ctx.file("yarn_info", content = "# vendored_yarn: {vendored_yarn}".format( + vendored_yarn = repository_ctx.attr.vendored_yarn, + )) return yarn_version = repository_ctx.attr.yarn_version @@ -329,6 +344,15 @@ def _download_yarn(repository_ctx): sha256 = sha256, ) + repository_ctx.file("yarn_info", content = """# filename: {filename} +# strip_prefix: {strip_prefix} +# sha256: {sha256} +""".format( + filename = filename, + strip_prefix = strip_prefix, + sha256 = sha256, + )) + def _prepare_node(repository_ctx): """Sets up BUILD files and shell wrappers for the versions of NodeJS, npm & yarn just set up. diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl index 2ba2dea28b..09beca1955 100644 --- a/internal/npm_install/npm_install.bzl +++ b/internal/npm_install/npm_install.bzl @@ -23,7 +23,7 @@ See discussion in the README. load("//:version.bzl", "VERSION") load("//internal/common:check_bazel_version.bzl", "check_bazel_version") -load("//internal/common:os_name.bzl", "is_windows_os") +load("//internal/common:os_name.bzl", "is_windows_os", "os_name") load("//internal/node:node_labels.bzl", "get_node_label", "get_npm_label", "get_yarn_label") COMMON_ATTRIBUTES = dict(dict(), **{ @@ -70,8 +70,14 @@ error. "data": attr.label_list( doc = """Data files required by this rule. -If symlink_node_modules is True, this attribute is ignored since -the dependency manager will run in the package.json location. +If symlink_node_modules is True, this attribute is optional since the package manager +will run in your workspace folder. It is recommended, however, that all files that the +package manager depends on, such as `.rc` files or files used in `postinstall`, are added +symlink_node_modules is True so that the repository rule is rerun when any of these files +change. + +If symlink_node_modules is False, the package manager is run in the bazel external +repository so all files that the package manager depends on must be listed. """, ), "environment": attr.string_dict( @@ -187,6 +193,18 @@ def _add_data_dependencies(repository_ctx): # files as npm file:// packages repository_ctx.template("/".join(to), f, {}) +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)), + repository_ctx.path("_node_info"), + ) + repository_ctx.symlink( + Label("@nodejs_%s//:yarn_info" % os_name(repository_ctx)), + repository_ctx.path("_yarn_info"), + ) + def _symlink_node_modules(repository_ctx): package_json_dir = repository_ctx.path(repository_ctx.attr.package_json).dirname repository_ctx.symlink(repository_ctx.path(str(package_json_dir) + "/node_modules"), repository_ctx.path("node_modules")) @@ -255,15 +273,14 @@ cd /D "{root}" && "{npm}" {npm_args} executable = True, ) - if not repository_ctx.attr.symlink_node_modules: - repository_ctx.symlink( - repository_ctx.attr.package_lock_json, - repository_ctx.path("package-lock.json"), - ) - _add_package_json(repository_ctx) - _add_data_dependencies(repository_ctx) - + repository_ctx.symlink( + repository_ctx.attr.package_lock_json, + repository_ctx.path("package-lock.json"), + ) + _add_package_json(repository_ctx) + _add_data_dependencies(repository_ctx) _add_scripts(repository_ctx) + _add_node_repositories_info_deps(repository_ctx) result = repository_ctx.execute( [node, "pre_process_package_json.js", repository_ctx.path(repository_ctx.attr.package_json), "npm"], @@ -393,15 +410,14 @@ cd /D "{root}" && "{yarn}" {yarn_args} executable = True, ) - if not repository_ctx.attr.symlink_node_modules: - repository_ctx.symlink( - repository_ctx.attr.yarn_lock, - repository_ctx.path("yarn.lock"), - ) - _add_package_json(repository_ctx) - _add_data_dependencies(repository_ctx) - + repository_ctx.symlink( + repository_ctx.attr.yarn_lock, + repository_ctx.path("yarn.lock"), + ) + _add_package_json(repository_ctx) + _add_data_dependencies(repository_ctx) _add_scripts(repository_ctx) + _add_node_repositories_info_deps(repository_ctx) result = repository_ctx.execute( [node, "pre_process_package_json.js", repository_ctx.path(repository_ctx.attr.package_json), "yarn"], diff --git a/package.json b/package.json index 8f6c6da554..c28f07973d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,10 @@ "homepage": "https://github.com/bazelbuild/rules_nodejs", "repository": "https://github.com/bazelbuild/rules_nodejs", "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0 < 13", + "yarn": ">=1.13.0" + }, "devDependencies": { "@angular/common": "^9.1.0", "@angular/compiler": "^9.1.0",