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 16, 2023
1 parent 6e1e66c commit 6b9daf0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions esm.mjs
@@ -1,13 +1,18 @@
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')} */
const esm = require('./dist/esm');
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 6b9daf0

Please sign in to comment.