-
Notifications
You must be signed in to change notification settings - Fork 524
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
fix: exports_directories_only causes node to resolve from runfiles/node_modules #3380
Conversation
For reference, the relevant code in the launcher for this change are Resolution of entry point follows this logic
and then for a TreeArtifact (which exports_directories produces for npm packges) the path within the tree artifact is appended
|
@thesayyn , does changing the
|
that should work but I am not sure how'd behave when the linker is disabled. this might be the reason why we have |
Yeah. that works |
Great. That makes perfect sense then on the regression with |
Seems like a random repository download failure. I don't have permission to rerun the tests. Ready for review. |
internal/node/node.bzl
Outdated
# most likely a TreeArtifact exported by js_library with exports directories only. | ||
# since a TreeArtifact is generated by an action, it resides inside bazel-out directory. | ||
if file.is_directory and file.dirname.startswith(ctx.bin_dir.path + "/"): | ||
path = path.replace(ctx.bin_dir.path + "/", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. you had to drop the bazel-out portion here? why was that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when the file is a tree artifact, it is going to be created by an action thus bazel will put it into the bazel-out directory. something like bazel-out/darwin_arm64-fastbuild/bin/external/npm_directory_artifacts/node_modules/pkg_with_bin
then linker will pick up this package and put it into execroot/node_modules
.
so in order to perform the mapping to the linked location, it has to get rid of the bin_dir portion.
bazel-out/darwin_arm64-fastbuild/bin/external/npm_directory_artifacts/node_modules/pkg_with_bin
-> node_modules/pkg_with_bin
external/npm/node_modules/pkg_with_bin
-> node_modules/pkg_with_bin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I see. This is so we can match the special case of
if parts[0] == "external":
if parts[2] == "node_modules":
# external/npm/node_modules -> node_modules/foo
# the linker will make sure we can resolve node_modules from npm
return "/".join(parts[2:])
added 2 years ago in #1287
That bit of logic seems wrong now that we can link into sub-directories... but also seems out of scope to fix that here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorted it out. We don't want to strip the output path unless we're transforming from external/<npm>/node_modules/foo
to node_modules/foo
. With that in mind, the function becomes
def _to_execroot_path(ctx, file):
# Check for special case of external/<npm>/node_modules or
# bazel-out/<platform>/bin/external/<npm>/node_modules.
# TODO: This assumes we are linking this to the root node_modules which is not always the case
# since the linker was updated to support linking to sub-directories since this special case was
# added
parts = file.path.split("/")
if file.is_directory and not file.is_source:
# Strip the output root to handle the case of a TreeArtifact exported by js_library with
# exports directories only. Since a TreeArtifact is generated by an action, it resides
# inside bazel-out directory.
parts = parts[3:]
if len(parts) > 3 and parts[0] == "external" and parts[2] == "node_modules":
# Transform external/npm/node_modules/foo to node_modules/foo.
# The linker will make sure we can resolve node_modules from npm.
return "/".join(parts[2:])
return file.path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than that, this looks great. Thanks for tracking down the underlying issue @thesayyn . I'll push this little fix and this is landable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah great. It's more robust right now. Thanks!
2625b79
to
5f8c044
Compare
Ready again. bizarre |
… a exports_directories_only npm module
5f8c044
to
a0ddf20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌮
Awesome @thesayyn ! This has been blocking us! 💞 I know it hasn't even been 15 minutes, but got any idea when this could make it into a release @gregmagolan ? 🙏 |
We should be able to get a 5.4.0 release out tomorrow. Hasn't been that much landed since 5.3.1 2 days ago. 5.3.1...stable cc @alexeagle |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
fixes #3264 #3273
What is the new behavior?
Does this PR introduce a breaking change?
Other information