Skip to content

Commit

Permalink
fix: remove module cache in sandbox plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Strum355 authored and jbedard committed May 29, 2024
1 parent 66748a7 commit 8c1f40a
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions esbuild/private/plugins/bazel-sandbox.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const path = require('path')
const process = require('process')

// Regex matching any non-relative import path
const pkgImport = /^[^.]/

const bindir = process.env.BAZEL_BINDIR
const execroot = process.env.JS_BINARY__EXECROOT

Expand All @@ -14,7 +11,6 @@ function bazelSandboxPlugin() {
return {
name: 'bazel-sandbox',
setup(build) {
const moduleCache = new Map()
build.onResolve(
{ filter: /./ },
async ({ path: importPath, ...otherOptions }) => {
Expand All @@ -28,16 +24,6 @@ function bazelSandboxPlugin() {
}
otherOptions.pluginData.executedSandboxPlugin = true

// Prevent us from loading different forms of a module (CJS vs ESM).
if (pkgImport.test(importPath)) {
if (!moduleCache.has(importPath)) {
moduleCache.set(
importPath,
resolveInExecroot(build, importPath, otherOptions)
)
}
return await moduleCache.get(importPath)
}
return await resolveInExecroot(build, importPath, otherOptions)
}
)
Expand Down

1 comment on commit 8c1f40a

@data-enabler
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that this fixes an issue I was seeing where the wrong version of a package was being loaded when there were multiple versions in use in my dependency tree.

Please sign in to comment.