diff --git a/WORKSPACE b/WORKSPACE index 16bcc8e3f..ea2d18c95 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -18,12 +18,6 @@ nodejs_register_toolchains( node_version = "16.9.0", ) -load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "register_yq_toolchains") - -register_yq_toolchains( - version = DEFAULT_YQ_VERSION, -) - load("@bazel_skylib//lib:unittest.bzl", "register_unittest_toolchains") register_unittest_toolchains() diff --git a/docs/npm_import.md b/docs/npm_import.md index 379a107d3..b2299d250 100644 --- a/docs/npm_import.md +++ b/docs/npm_import.md @@ -144,7 +144,7 @@ and must depend on packages with their versioned label like `@npm__types_node-15
npm_import(name, package, version, deps, transitive_closure, root_path, link_paths, - run_lifecycle_hooks, integrity, patch_args, patches, custom_postinstall, yq) + run_lifecycle_hooks, integrity, patch_args, patches, custom_postinstall)Import a single npm package into Bazel. @@ -232,6 +232,5 @@ common --experimental_downloader_config=.bazel_downloader_config | patch_args | Arguments to pass to the patch tool.
-p1
will usually be needed for patches generated by git. | ["-p0"]
|
| patches | Patch files to apply onto the downloaded npm package. | []
|
| custom_postinstall | Custom string postinstall script to run on the installed npm package. Runs after any existing lifecycle hooks if run_lifecycle_hooks
is True. | ""
|
-| yq | The label to the yq binary to use. If executing on a windows host, the .exe extension will be appended if there is no .exe, .bat, or .cmd extension on the label. | "@yq//:yq"
|
diff --git a/e2e/link_js_package/WORKSPACE b/e2e/link_js_package/WORKSPACE
index 23a6cfb8c..58f92ae25 100644
--- a/e2e/link_js_package/WORKSPACE
+++ b/e2e/link_js_package/WORKSPACE
@@ -14,12 +14,6 @@ nodejs_register_toolchains(
node_version = "16.9.0",
)
-load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "register_yq_toolchains")
-
-register_yq_toolchains(
- version = DEFAULT_YQ_VERSION,
-)
-
load("@aspect_rules_js//js:npm_import.bzl", "translate_pnpm_lock")
translate_pnpm_lock(
diff --git a/e2e/pnpm_workspace/WORKSPACE b/e2e/pnpm_workspace/WORKSPACE
index 8e90ee4bd..0b613883d 100644
--- a/e2e/pnpm_workspace/WORKSPACE
+++ b/e2e/pnpm_workspace/WORKSPACE
@@ -16,12 +16,6 @@ nodejs_register_toolchains(
node_version = DEFAULT_NODE_VERSION,
)
-load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "register_yq_toolchains")
-
-register_yq_toolchains(
- version = DEFAULT_YQ_VERSION,
-)
-
load("@aspect_rules_js//js:npm_import.bzl", "translate_pnpm_lock")
translate_pnpm_lock(
diff --git a/e2e/pnpm_workspace_dot_dot/WORKSPACE b/e2e/pnpm_workspace_dot_dot/WORKSPACE
index 978cdc930..689d01213 100644
--- a/e2e/pnpm_workspace_dot_dot/WORKSPACE
+++ b/e2e/pnpm_workspace_dot_dot/WORKSPACE
@@ -14,12 +14,6 @@ nodejs_register_toolchains(
node_version = "16.9.0",
)
-load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "register_yq_toolchains")
-
-register_yq_toolchains(
- version = DEFAULT_YQ_VERSION,
-)
-
load("@aspect_rules_js//js:npm_import.bzl", "translate_pnpm_lock")
translate_pnpm_lock(
diff --git a/e2e/rules_foo/WORKSPACE b/e2e/rules_foo/WORKSPACE
index 03456ff26..a4982f3ce 100644
--- a/e2e/rules_foo/WORKSPACE
+++ b/e2e/rules_foo/WORKSPACE
@@ -17,12 +17,6 @@ nodejs_register_toolchains(
node_version = "16.9.0",
)
-load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "register_yq_toolchains")
-
-register_yq_toolchains(
- version = DEFAULT_YQ_VERSION,
-)
-
load("@rules_foo//:repositories.bzl", rules_foo_repositories = "repositories")
rules_foo_repositories()
diff --git a/js/npm_import.bzl b/js/npm_import.bzl
index e56e75d4d..5101b7f13 100644
--- a/js/npm_import.bzl
+++ b/js/npm_import.bzl
@@ -41,8 +41,7 @@ def npm_import(
integrity = "",
patch_args = ["-p0"],
patches = [],
- custom_postinstall = "",
- yq = "@yq//:yq"):
+ custom_postinstall = ""):
"""Import a single npm package into Bazel.
Normally you'd want to use `translate_pnpm_lock` to import all your packages at once.
@@ -138,8 +137,6 @@ def npm_import(
patch_args: Arguments to pass to the patch tool.
`-p1` will usually be needed for patches generated by git.
patches: Patch files to apply onto the downloaded npm package.
- yq: The label to the yq binary to use. If executing on a windows host, the .exe extension will be appended if
- there is no .exe, .bat, or .cmd extension on the label.
"""
# By convention, the `{name}` repository contains the actual npm
@@ -153,7 +150,6 @@ def npm_import(
patches = patches,
custom_postinstall = custom_postinstall,
run_lifecycle_hooks = run_lifecycle_hooks,
- yq = yq,
)
# By convention, the `{name}{pnpm_utils.links_postfix}` repository contains the generated
diff --git a/js/private/BUILD.bazel b/js/private/BUILD.bazel
index 43381f53a..aa10b027a 100644
--- a/js/private/BUILD.bazel
+++ b/js/private/BUILD.bazel
@@ -59,21 +59,11 @@ bzl_library(
visibility = ["//js:__subpackages__"],
deps = [
":pnpm_utils",
- ":repo_toolchains",
":starlark_codegen_utils",
"@aspect_bazel_lib//lib:repo_utils",
],
)
-bzl_library(
- name = "repo_toolchains",
- srcs = ["repo_toolchains.bzl"],
- visibility = ["//js:__subpackages__"],
- deps = [
- "@aspect_bazel_lib//lib:repo_utils",
- ],
-)
-
bzl_library(
name = "translate_pnpm_lock",
srcs = ["translate_pnpm_lock.bzl"],
diff --git a/js/private/npm_import.bzl b/js/private/npm_import.bzl
index b81a34f1f..6f25dc179 100644
--- a/js/private/npm_import.bzl
+++ b/js/private/npm_import.bzl
@@ -5,7 +5,6 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load(":pnpm_utils.bzl", "pnpm_utils")
load(":starlark_codegen_utils.bzl", "starlark_codegen_utils")
-load(":repo_toolchains.bzl", "yq_path")
_LINK_JS_PACKAGE_TMPL = """load("@aspect_rules_js//js:defs.bzl", _js_package = "js_package")
load("@aspect_rules_js//js:run_js_binary.bzl", _run_js_binary = "run_js_binary")
@@ -414,28 +413,21 @@ _ATTRS = dicts.add(_COMMON_ATTRS, {
"patches": attr.label_list(),
"run_lifecycle_hooks": attr.bool(),
"custom_postinstall": attr.string(),
- "yq": attr.label(default = "@yq//:yq"),
})
def _inject_run_lifecycle_hooks(rctx, pkg_json_path):
- rctx.execute([
- yq_path(rctx),
- "-P",
- "-o=json",
- "--inplace",
- ".scripts._rules_js_run_lifecycle_hooks=\"1\"",
- pkg_json_path,
- ], quiet = False)
+ package_json = json.decode(rctx.read(pkg_json_path))
+ package_json.setdefault("scripts", {})["_rules_js_run_lifecycle_hooks"] = "1"
+
+ # TODO: The order of fields in package.json is not preserved making it harder to read
+ rctx.file(pkg_json_path, json.encode_indent(package_json, indent = " "))
def _inject_custom_postinstall(rctx, pkg_json_path, custom_postinstall):
- rctx.execute([
- yq_path(rctx),
- "-P",
- "-o=json",
- "--inplace",
- ".scripts._rules_js_custom_postinstall=\"%s\"" % custom_postinstall,
- pkg_json_path,
- ], quiet = False)
+ package_json = json.decode(rctx.read(pkg_json_path))
+ package_json.setdefault("scripts", {})["_rules_js_custom_postinstall"] = custom_postinstall
+
+ # TODO: The order of fields in package.json is not preserved making it harder to read
+ rctx.file(pkg_json_path, json.encode_indent(package_json, indent = " "))
def _get_bin_entries(pkg_json, package):
# https://docs.npmjs.com/cli/v7/configuring-npm/package-json#bin
diff --git a/js/private/repo_toolchains.bzl b/js/private/repo_toolchains.bzl
deleted file mode 100644
index c6b05ffd1..000000000
--- a/js/private/repo_toolchains.bzl
+++ /dev/null
@@ -1,20 +0,0 @@
-"Helpers to locate toolchains from within repository rules"
-
-load("@aspect_bazel_lib//lib:repo_utils.bzl", "repo_utils")
-
-def _ext(rctx, str_label):
- return ".exe" if repo_utils.is_windows(rctx) and not str_label.endswith(".exe") and not str_label.ends_with(".bat") and not str_label.endswith(".cmd") else ""
-
-def yq_path(rctx):
- """Find the path to the host resolved yq binary from a repository rule.
-
- Args:
- rctx: Repository rule context containing a "yq" label attr. If executing
- on windows and there is no .exe, .bat, or .cmd extension on the input label,
- then .exe will be automatically appended.
-
- Returns:
- Path to yq.
- """
- str_label = str(rctx.attr.yq)
- return rctx.path(Label(str_label + _ext(rctx, str_label)))