aspect-build / aspect-build/rules_js

[FR]: Peer dependency resolution of first party packages

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

Description

### What is the current behavior?

(somewhat related to #1092)

Consider a layout like:

```diff
| package.json
| packages/
+ | compiler
| package.json
+ | compiler-cli
| package.json
```

The `compiler` and `compiler-cli` packages are part of the pnpm workspace!

`compiler-cli` has a peer dependency on a specific compiler version (set via packaging substitutions). e.g.

```js
// compiler-cli/package.json
{
"peerDependencies": {
"@angular/compiler": "0.0.0-PLACEHOLDER"
}
}
```

To satisfy this peer dependency for local development, in some other folder of the project, where we rely on the `:pkg`-linked first party packages, we have a few options:

1. Rely on pnpm's auto-install peer dependency feature (enabled by default).
2. Specifically add a `dependency` to the `compiler-cli` `package.json`.
3. Leverage `.pnpmfile.cjs` to only insert a `dependency` (like 2) for Aspect/rules_js
4. Don't satisfy _officially_, but use a `js_library` that has a `data` dependency on the linked `compiler:pkg` then.

There are quite a few options, and that's good, emphasizing that there are tricks to achieve what is needed, but I believe it would make sense to also support `devDependencies` here (and was also highlighted in #1092).

Currently when we'd try to satisfy the peer dependency via `devDependency` in the compiler-cli package.json, it works with pnpm itself, but with `rules_js`, the compiler package is never picked up as **prod** dependency, and will never be propagated via the `npm_link_package_store` dependency chain (if I understand that correctly from a high-level analysis).

https://github.com/aspect-build/rules_js/blob/157f7553543036a72a318ec6147b11f8f09abd88/npm/private/npm_link_package_store.bzl#L131-L132

### Describe the feature

It would be great if there would be a way to control this behavior https://github.com/aspect-build/rules_js/blob/157f7553543036a72a318ec6147b11f8f09abd88/npm/private/npm_link_package_store.bzl#L131-L132, or if `rules_js` would pick up the "satisfied" compiler package as **prod** then.

Contributor guide

Open the contributing guide

Research direction

Start at npm/private/npm_link_package_store.bzl around lines 131-132 and trace how peer dependencies and the npm_link_package_store dependency chain determine production dependencies. Compare the package.json examples in the issue, especially devDependencies, and define how a satisfied first-party peer dependency should be propagated as a prod dependency; verify the behavior with the repository's relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system
Issue type
Feature
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.