Skip to content

Commit

Permalink
loader: return empty globalPreload when not using off-thread loader
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 7, 2023
1 parent 92c3ce3 commit 99a5b73
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions esm.mjs
@@ -1,5 +1,6 @@
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
import { versionGteLt } from './dist/util.js';
const require = createRequire(fileURLToPath(import.meta.url));

/** @type {import('./dist/esm')} */
Expand All @@ -8,7 +9,11 @@ export const { resolve, load, getFormat, transformSource } =
esm.registerAndCreateEsmHooks();

// Affordance for node 20, where load() happens in an isolated thread
const offThreadLoader = versionGteLt(process.versions.node, '20.0.0');
export const globalPreload = () => {
if (!offThreadLoader) {
return '';
}
const self = fileURLToPath(import.meta.url);
return `
const { createRequire } = getBuiltin('module');
Expand Down

0 comments on commit 99a5b73

Please sign in to comment.