Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lifecycle_hooks_use_default_shell_env to npm lifecycle hooks #1489

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we had to do this elsewhere where we want a dict of boolean values? In WORKSPACE it is a macro and the use of strings is hidden unlike here...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a dict of boolean values seems like it ought to just be a list? I don't think the datatype has to match the other lifecycle_hooks_* necessarily

Copy link
Member Author

@jbedard jbedard Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work, would probably just require some (minor) changes to the utils to process these things. I would prefer keeping the same dict API as all the other hook params though, it's just this boolean thing makes it ugly in this case...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be rarely used so I'm fine with the option that makes maintenance easier rather than the more ergonomic one.

},
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
Loading
Loading