-
-
Notifications
You must be signed in to change notification settings - Fork 30
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: add onResolve plugin to enforce dependencies come from BAZEL_BIN #32
Conversation
Isn't this what Greg's symlink guards is meant to prevent? It should make these resolutions hermetic. |
Yes, but esbuild is Go, so Greg's work has no affect here. I'd imagine the same happens under swc |
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.
🌮
If we used swc for bundling it would likely have the same issue |
22f6f24
to
70ba5c2
Compare
@mattem: it seems like your Another problem with It seems to me that one definitive solution to all these problems is to write a hook that will resolve the symlinks but only within the confines of sandbox dir. I guess this is tantamount to recreating the sandbox symlink guard logic. Or another way to look at it is that the hook will only allow a file path through if there is a symlink in the sandbox terminating at that path. |
This will become simpler once the "unresolved" symlinks features stabilizes in Bazel: bazelbuild/bazel#10298. The end result will be symlinks in the sandbox and in runfiles will be relative to the sandbox and the runfiles so the symlink guards can be simplified to following the symlink chain as long as it stays within the sandbox. |
Until someone can jump back on this PR, we will convert it to draft. |
I believe you're referring to the following code in the PR: const bazelSandboxAwareOnResolvePlugin = {
name: 'Bazel Sandbox Guard',
setup(build) {
const BAZEL_BINDIR = process.env.BAZEL_BINDIR
build.onResolve({ filter: /.*/ }, args => {
if (args.resolveDir.indexOf(BAZEL_BINDIR) === -1) {
return {
errors: [
{
text: `Failed to resolve import '${args.path}'. Ensure that it is a dependency of an upstream target`,
location: null,
}
]
}
}
})
}
} What's the right way to do the check? The esbuild rule could emit a file that lists of all the files in the sandbox, presumably, and the symlink guard can use that instead to check if a symlink destination is allowed. input_sources = depset(
copy_files_to_bin_actions(ctx, [
file
for file in ctx.files.srcs + filter_files(entry_points)
if not (file.path.endswith(".d.ts") or file.path.endswith(".tsbuildinfo"))
]) + other_inputs + node_toolinfo.tool_files + esbuild_toolinfo.tool_files,
transitive = [js_lib_helpers.gather_files_from_js_providers(
targets = ctx.attr.srcs + ctx.attr.deps,
include_transitive_sources = True,
include_declarations = False,
include_npm_linked_packages = True,
)],
) |
"This won't work" ~Matt |
I think #112 supersedes this PR, and @gregmagolan seems to be looking at that one. |
Previously with
preserveSymlinks
set esbuild was unable to find transitive dependencies within the layout of node_modules that pnpm gives. This worked fine when using it under rules_nodejs, as that allowed us not to escape the sandbox and the layout was flat.This allows us to avoid the user needing to hoist pretty much every runtime dependency, which could be a lot.
We can't just turn off
preserveSymlinks
though, otherwise esbuild will resolve dependencies elsewhere in our workspace, such as back to our source tree.Building the following would now result in the error. Here we are intentionally commenting out
react-dom
We could improve the error message, but that gets tricky when the import doesn't cleanly relate to a package name, eg removing
react
results in an import that's gone via a mapping in thepackage.json
file (I guess?)