Skip to content
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: remapping of relative-path imports marked external that don't correspond to a filesystem path in sandbox #201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions esbuild/private/plugins/bazel-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,25 @@ async function resolveInExecroot(build, importPath, otherOptions) {
return result
}

return correctImportPath(result, otherOptions, false)
}

function correctImportPath(result, otherOptions, firstEntry) {
// If esbuild attempts to leave the execroot, map the path back into the execroot.
if (!result.path.startsWith(execroot)) {
// A relative path that is marked as external. If it was not marked as external, it would error in the build.resolve call.
// We need to make it an absolute path from its importer and then re-attempt correcting it to be within the execroot.
if (result.path.startsWith("..")) {
const absPath = path.resolve(otherOptions.importer, result.path)
if (!!process.env.JS_BINARY__LOG_DEBUG) {
console.error(
`DEBUG: [bazel-sandbox] relative & external path found ${result.path}, making absolute relative to its importer ${otherOptions.importer} and then reattempting making it relative to the execroot (${execroot}): ${absPath}`
)
}
result.path = absPath
return correctImportPath(result, otherOptions, true)
}

// If it tried to leave bazel-bin, error out completely.
if (!result.path.includes(bindir)) {
throw new Error(
Expand Down
Loading