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

Conversation

jbedard
Copy link
Member

@jbedard jbedard commented Feb 22, 2024

Depends on aspect-build/bazel-lib@1c98ca9 if the feature is used, while maintaining support for bazel-lib <2.4.2 if not using this new feature.

Type of change

  • New feature or functionality (change which adds functionality)

For changes visible to end-users

  • Relevant documentation has been updated

Test plan

  • Covered by existing test cases
  • New test cases added

MODULE.bazel Outdated Show resolved Hide resolved
npm/private/npm_import.bzl Outdated Show resolved Hide resolved
npm/private/npm_import.bzl Outdated Show resolved Hide resolved
npm/private/npm_import.bzl Show resolved Hide resolved

This defaults to False to reduce the negative effects of `use_default_shell_env`.

Read more: [lifecycles](/docs/pnpm.md#lifecycles)
Copy link
Member

Choose a reason for hiding this comment

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

that link doesn't seem useful in this case

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking we should add to that doc?

Copy link
Member Author

Choose a reason for hiding this comment

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

See the update to that doc

npm/private/test/fsevents_links_defs_checked.bzl Outdated Show resolved Hide resolved
@jbedard jbedard force-pushed the lifecycle_hooks_use_default_shell_env branch 3 times, most recently from 219849d to 54cd703 Compare February 22, 2024 02:24
@jbedard jbedard marked this pull request as draft February 22, 2024 02:28
@jbedard
Copy link
Member Author

jbedard commented Feb 22, 2024

Sorry maybe this should have been a draft for now, although the general idea can be reviewed now.

@@ -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.

@jbedard jbedard force-pushed the lifecycle_hooks_use_default_shell_env branch 4 times, most recently from b1ffad4 to c904028 Compare February 22, 2024 08:09
@jbedard jbedard marked this pull request as ready for review February 22, 2024 17:36
@jbedard jbedard force-pushed the lifecycle_hooks_use_default_shell_env branch from c904028 to 5785ed3 Compare February 22, 2024 18:46
docs/pnpm.md Outdated
@@ -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`.
Copy link
Member

Choose a reason for hiding this comment

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

Worth mentioning that this feature depends on a minimum version of bazel-lib that adds use_default_shell_env to run_binary?. The MODULE.bazel of rules_js currently brings in 1.x bazel-lib that I'm not sure has that attribute.

Should also mention the minimum version in the docstrings of npm_translate_lock and npm_import if there is one

Copy link
Member

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

🌮

@jbedard jbedard force-pushed the lifecycle_hooks_use_default_shell_env branch from 5785ed3 to fe226e4 Compare February 22, 2024 23:44
@jbedard jbedard merged commit 93e53bb into aspect-build:main Feb 23, 2024
88 of 89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants