Skip to content

Commit

Permalink
respond to PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
vpanta committed Dec 18, 2023
1 parent ba99e38 commit f60de04
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions esbuild/private/plugins/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ export function sandboxPlugin() {
async function resolveInSandbox(build, importPath, otherOptions) {
const result = await build.resolve(importPath, otherOptions)

if (result.errors && result.errors.length) {
// There was an error resolving, just return the error as-is.
return result
}

// If esbuild attempts to leave the sandbox, map the path back into the sandbox.
if (!result.path.startsWith(sandboxRoot)) {
const pathPieces = result.path.split(bindir)
if (pathPieces.length != 2) {
if (!result.path.startsWith(bindir)) {
// If it tried to leave bazel-bin, error out completely.
throw new Error(
`Error: esbuild resolved a path outside of BAZEL_BINDIR: ${result.path}`,
)
}
result.path = path.join(sandboxRoot, pathPieces[1])
result.path = path.join(sandboxRoot, result.slice(bindir.length))
}
return result
}
}

0 comments on commit f60de04

Please sign in to comment.