-
-
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: remove module cache in sandbox plugin #209
Conversation
Have you been able to reproduce this in a test at all? Or any understandable way in your repo that you can describe here? |
So just for some context, this plugin was originally something I created internally for Fullstory and decided to upstream. The module cache was added because certain modules were getting dual-loaded by esbuild depending on their import-semantics: if it came from a require, it would load the CJS version of the module, and if it was from an import statement, it would load the ESM version of the module. If I remember correctly, this was at best causing bloat in our bundle but at worst causing full breakages (when something like I don't think I have explicit tests for this case, as it was something inherent to our internal build. Take all this with a grain of salt, YMMV. I'm not sure of the best way to approach this to be honest, because your case is perfectly valid. |
Thanks for the reply 🙏 Copying from my conversation with Jason:
const res = await resolveInExecroot(build, importPath, otherOptions)
if (importPath.includes('util.inspect')) {
res.path = res.path + ".js"
}
Does this sound similar to the issue you came across that you solved with the module cache? @vpanta |
First off, sorry, I saw this question and completely forgot about it. Like my only thought is esbuild is applying ESM rules to what should be a CJS package. |
I think I'd like to merge this then. @Strum355 did you have any thoughts on a test for this or is that not worth your time right now? |
This module cache came up as problematic with the presence of multiple versions of a package in a given dependency closure. In our case, we have
minipass
4.2.8 and 7.0.4 (required byglob
9.3.2 andpath-scurry
1.10.1 respectively) in a given closure. These are strictly not compatible with each other, so resolvingminipass
fromglob
should yield 4.2.8 and frompath-scurry
should yield 7.0.4. The module cache however results in everything getting the same version, as we are keying only by name sans version.Log output I added to illustrate the point:
from the following diff to 0.19.0:
The one thing Im unsure about is the comment about avoiding loading both ESM and CJS, Im not sure if theres an easy reproducer somewhere or a test case in this repo that covers it cc @vpanta
Test plan
This issue was being worked on as part of a series of issues that cropped up when upgrading to 0.19.0, including #201. As such, the manual testing I did was the same as mentioned over there, except for a different commit: github.com/sourcegraph/sourcegraph/commit/51503969643612665485aa8e6e150566b6863d54 with target
//client/web/dev:esbuild-config-production_bundle