Skip to content

Commit

Permalink
fix detection of import()
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 27, 2021
1 parent c879ca9 commit 5519f58
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {execSync} from 'child_process';
import * as nativeModule from 'module';
import * as path from 'path';
import {URL, fileURLToPath, pathToFileURL} from 'url';
Expand Down Expand Up @@ -159,16 +160,12 @@ const supportsNodeColonModulePrefixInRequire = (() => {
}
})();

const supportsNodeColonModulePrefixInImport = (async () => {
try {
// @ts-expect-error
// eslint-disable-next-line import/no-unresolved
await import('node:fs');
const supportsNodeColonModulePrefixInImport = (() => {
const res = execSync(
`node --eval 'import("node:fs").then(() => console.log(true), () => console.log(false));'`,
);

return true;
} catch {
return false;
}
return res.toString().trim() === 'true';
})();

export default class Runtime {
Expand Down Expand Up @@ -1378,7 +1375,7 @@ export default class Runtime {
private async _importCoreModule(moduleName: string, context: VMContext) {
const required = this._requireCoreModule(
moduleName,
await supportsNodeColonModulePrefixInImport,
supportsNodeColonModulePrefixInImport,
);

const module = new SyntheticModule(
Expand Down

0 comments on commit 5519f58

Please sign in to comment.