Skip to content

Commit 8831f54

Browse files
authored
Improve detection of ESM support
1 parent d0e2161 commit 8831f54

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lib/esm-probe.mjs

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/worker/subprocess.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ require('./ensure-forked'); // eslint-disable-line import/no-unassigned-import
66

77
const ipc = require('./ipc');
88

9+
const supportsESM = async () => {
10+
try {
11+
await import('data:text/javascript,');
12+
return true;
13+
} catch {}
14+
15+
return false;
16+
};
17+
918
ipc.send({type: 'ready-for-options'});
1019
ipc.options.then(async options => {
1120
require('./options').set(options);
@@ -134,23 +143,18 @@ ipc.options.then(async options => {
134143
return null;
135144
}).filter(provider => provider !== null);
136145

137-
// Lazily determine support since this prints an experimental warning.
138-
let supportsESM = async () => {
139-
try {
140-
await import('../esm-probe.mjs');
141-
supportsESM = async () => true;
142-
} catch {
143-
supportsESM = async () => false;
144-
}
145-
146-
return supportsESM();
147-
};
148-
149146
let requireFn = require;
147+
let isESMSupported;
150148
const load = async ref => {
151149
for (const extension of extensionsToLoadAsModules) {
152150
if (ref.endsWith(`.${extension}`)) {
153-
if (await supportsESM()) { // eslint-disable-line no-await-in-loop
151+
if (typeof isESMSupported !== 'boolean') {
152+
// Lazily determine support since this prints an experimental warning.
153+
// eslint-disable-next-line no-await-in-loop
154+
isESMSupported = await supportsESM();
155+
}
156+
157+
if (isESMSupported) {
154158
return import(pathToFileURL(ref));
155159
}
156160

0 commit comments

Comments
 (0)