rules_js icon indicating copy to clipboard operation
rules_js copied to clipboard

[FR]: provide select constraints for optional dependencies that define specific platforms

Open qtica opened this issue 2 years ago • 3 comments

What is the current behavior?

Currently when an NPM package contains optional dependencies, and npm_translate_lock has no_optional = False, all of the optional dependencies of a package are added without constraints to the deps attribute of the rerespective npm_package_store_internal for the desired package.

In the case of nextjs, for example, it means that all of these optional dependencies will be added to the deps. This results in all of the various platform binaries for @next/swc being installed on the user's machine.

Describe the feature

I am looking for something similar to this pnpm PR for rules_js: https://github.com/pnpm/pnpm/pull/3672

In short, I'd expect that all optional dependencies that provide a platform constraint, have the constraint mapped into a proper bazel select when adding the dependencies to the store target. We should be able to achieve this using the pnpm-lock file, as seen on this example swc-linux package: https://github.com/aspect-build/bazel-examples/blob/ec19825e711ef2d1db68352ed8b152cad65cd257/next.js/pnpm-lock.yaml#L268-L275

The end goal is that the build stage would only depend on dependencies that match the allowed host, which would result in fewer unneeded binaries from being installed when using packages like nextjs.

I can provide more information if necessary.

Fund our work

qtica avatar Dec 14 '22 07:12 qtica

For reference, there is some discussion on this feature and how to implement it in Bazel Slack here https://bazelbuild.slack.com/archives/CEZUUKQ6P/p1670931838633139

gregmagolan avatar Jan 13 '23 07:01 gregmagolan

Would be greate to have some solution or idea to solution. Bumped in same issue

SinimaWath avatar Apr 10 '24 19:04 SinimaWath

Related to https://github.com/evanw/esbuild/issues/789

gregmagolan avatar May 15 '24 19:05 gregmagolan