Skip to content

Commit

Permalink
feat: add lifecycle_hooks_use_default_shell_env to npm lifecycle hooks (
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Feb 23, 2024
1 parent 99113f2 commit 93e53bb
Show file tree
Hide file tree
Showing 14 changed files with 2,875 additions and 14 deletions.
11 changes: 6 additions & 5 deletions docs/npm_import.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion docs/npm_translate_lock.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/pnpm.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ which is equivalent to setting the `lifecycle_hooks` to an empty list for that p

You can set environment variables for hook build actions using the `lifecycle_hooks_envs` attribute of `npm_translate_lock`.

Some hooks may depend on environment variables specified depending on [use_default_shell_env](https://bazel.build/rules/lib/builtins/actions#run.use_default_shell_env) which may be enabled for hook build actions using the `lifecycle_hooks_use_default_shell_env` attribute of `npm_translate_lock`. Requires bazel-lib >= 2.4.2.

In case there are multiple matches, some attributes are additive.
(More specific matches are appended to previous matches.)
Other attributes have specificity: the most specific match wins and the others are ignored.
Expand Down
13 changes: 13 additions & 0 deletions e2e/gyp_no_install_script/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@aspect_rules_js//js:defs.bzl", "js_test")

Expand All @@ -10,3 +11,15 @@ js_test(
],
entry_point = "test.js",
)

write_source_files(
name = "write_npm_translate_lock",
files = {
"test/repositories.bzl.checked": "@npm//:repositories.bzl",
"test/segfault-handler_defs.bzl.checked": "@npm__segfault-handler__1.3.0__links//:defs.bzl",
},
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
4 changes: 4 additions & 0 deletions e2e/gyp_no_install_script/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bazel_dep(name = "aspect_bazel_lib", version = "2.4.2")
bazel_dep(name = "aspect_rules_js", version = "0.0.0")
local_path_override(
module_name = "aspect_rules_js",
Expand All @@ -8,6 +9,9 @@ npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
npm.npm_translate_lock(
name = "npm",
data = ["//:package.json"],
lifecycle_hooks_use_default_shell_env = {
"segfault-handler": "true",
},
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
update_pnpm_lock = True,
Expand Down
12 changes: 12 additions & 0 deletions e2e/gyp_no_install_script/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

local_repository(
name = "aspect_rules_js",
path = "../..",
)

http_archive(
name = "aspect_bazel_lib",
sha256 = "f75d03783588e054899eb0729a97fb5b8973c1a26f30373fafd485c90bf207d1",
strip_prefix = "bazel-lib-2.4.2",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.4.2/bazel-lib-v2.4.2.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()
Expand All @@ -19,6 +28,9 @@ load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
npm_translate_lock(
name = "npm",
data = ["//:package.json"],
lifecycle_hooks_use_default_shell_env = {
"segfault-handler": True,
},
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
update_pnpm_lock = True,
Expand Down

0 comments on commit 93e53bb

Please sign in to comment.