aspect-build / aspect-build/rules_js

[Bug]: Optional dep handling not consistent with pnpm

Open
#1,199 2 comments 1 reaction 0 assignees View on GitHub
bug help wanted need: funding
Dominant language
Starlark
Stars
378
Forks
183
Avg merge
1d 9h
Merged PRs (30d)
32

Description

### What happened?

In pnpm, if an `optional` dep's lifecycle hook fails, the failure is swallowed and the hook marked as "skipped". The package source is still linked into node_modules, and the overall installation is allowed to proceeed:
https://github.com/pnpm/pnpm/blob/main/exec/build-modules/src/index.ts#L151C28-L151C28

With rules_js, a lifecycle hook error bubbles up and fails the build, even for optional dependencies. There is a `no_optional` attr on `npm_translate_lock`, but this skips every aspect of optional dependencies installation (i.e. does not create the links and bazel targets), rather than merely allowing the hooks to fail.

This is important for us, and I imagine others, as some packages have install hooks that install or build native binaries that are not supported on all platforms (e.g. mac arm). On these platforms we want to allow the hook to fail, and the install or build to proceed, on the understanding certain aspects of that package will not operate at runtime on those platforms.

### Version

Development (host) and target OS/architectures:

Output of `bazel --version`:

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:

Language(s) and/or frameworks involved:

### How to reproduce

_No response_

### Any other information?

`lifecycle_hooks_exclude` is a workaround, but as you cannot use `select` in WORKSPACE, the change has to be manually edited in locally by developers wanting to build on the aforementioned platforms.

Contributor guide

Open the contributing guide

Research direction

Start by reading the linked pnpm build-modules behavior and tracing optional dependency handling in npm_translate_lock, including the lifecycle_hooks_exclude workaround. Done means optional package links and Bazel targets remain available while lifecycle hook failures are treated as skipped and installation proceeds on unsupported platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.