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(esbuild): remove all node: imports from glob script to keep support for Jest v26 #5784

Merged
merged 2 commits into from
May 22, 2024
Merged
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
9 changes: 9 additions & 0 deletions scripts/esbuild/sys-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ async function sysNodeExternalBundles(opts: BuildOptions) {
bundleExternal(opts, opts.output.devServerDir, cachedDir, 'ws.js'),
]);

/**
* Some of globs dependencies are using imports with a `node:` prefix which
* is not supported by Jest v26. This is a workaround to remove the `node:`.
* TODO(STENCIL-1323): remove once we deprecated Jest v26 support
*/
const globOutputPath = join(opts.output.sysNodeDir, 'glob.js');
const glob = fs.readFileSync(globOutputPath, 'utf8');
fs.writeFileSync(globOutputPath, glob.replace(/require\("node:/g, 'require("'));
Comment on lines +104 to +106
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to just revert glob and block that upgrade until we drop Jest 26 support (in v5)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately that wouldn't work as glob itself is not the culprit here, it's glob dependencies, e.g. path-scurry, that bring in these node imports. If we would use pnpm we could use the overwrite or in Yarn we could use resolutions but there is nothing in NPM to do this. Hence tweaking the build artifact seemed like the easiest approach.


// open-in-editor's visualstudio.vbs file
// TODO(STENCIL-1052): remove once Rollup -> esbuild migration is complete
const visualstudioVbsSrc = join(opts.nodeModulesDir, 'open-in-editor', 'lib', 'editors', 'visualstudio.vbs');
Expand Down