Support pnpm link and file protocols for external packages #1328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Test plan
workspace:
protocol tests first-party packages in workspace)I've been testing manually by setting
file:/abs/path/to/3rdparty/package/dist
andlink:/abs/path/to/3rdparty/package/dist
in my package.json. Thefile:
protocol works without any additional stpes, but thelink
protocol requires thatnode_modules
can be found in the dist folder.Notes
This works towards #1165
Added support for using the
file:
andlink:
protocols when setting package versions in package.json and using paths to projects external to the Bazel workspace.I've extended the npm_import rule to accept
path
attributes (in addition to url).When
path
is set, a repository is created with the same structure as whenurl
is set, only the external package is symlinked to it's file location, instead of downloaded.In order to support existing behavior with the
workspace:
protocol, I've also added asrc
arg to the npm_import macro which will only create the npm import links repository, which is similar how the targets were set up previously, except the links are created in a links repository instead of the workspacenode_modules
targets. This isn't a necessary change, it just made the logic for generating defs.bzl and repositories.bzl a little easier to implement.This is a draft. This change still needs some polish before it is ready to be implemented. The following are some use cases that I think would help make this change more robust:
Using relative paths to external packages, ie
file:../../path/to/package
Since the package.json is copied to the
npm
repository before runningpnpm install --lockfile-only
, the paths would have to be adapted to be relative to the source repository or made absoluteThe end goal here would be able to support a command similar to
pnpm link
It seems to me that
pnpm link
is meant to be used after runningpnpm install
, since it modifies the lock file and the installed node_modules package. Maybe an equivalent rules_js executable could be implemented which would write some output file that is read while generating repositories.bzl and know which packages should be linked to where.The new behavior in this PR still needs documentation and tests
I'm a bit short on time for the next couple of weeks. I'll do my best to help get it to a stage where it's ready to be merged, but it might just take me a little while to make big changes. Any help and/or feedback would be greatly appreciated. I think this change would be a great improvement for rules_js because at the present time it's quite difficult for developers to work with first party dependencies outside of the workspace (in particular, those not use a Bazel build).