From d22957db79f0bbd35307aa09f3e40c4e0a604b31 Mon Sep 17 00:00:00 2001 From: Bayheck Date: Thu, 22 Feb 2024 17:29:08 +0600 Subject: [PATCH] fix: esm loader fix --- src/compiler/compilers.js | 4 ++-- src/compiler/esm-loader.ts | 2 +- src/compiler/index.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/compilers.js b/src/compiler/compilers.js index b625e7afb2c..f0d3f8c0392 100644 --- a/src/compiler/compilers.js +++ b/src/compiler/compilers.js @@ -20,9 +20,9 @@ function createTestFileCompilers (compilerOptions = {}, { baseUrl, esm } = {}) { let testFileCompilers = []; -export function getTestFileCompilers () { +export function getTestFileCompilers (esm) { if (!testFileCompilers.length) - initTestFileCompilers(); + initTestFileCompilers({}, { baseUrl: '', esm }); return testFileCompilers; } diff --git a/src/compiler/esm-loader.ts b/src/compiler/esm-loader.ts index b9ec9a05eae..74a3bab5f4d 100644 --- a/src/compiler/esm-loader.ts +++ b/src/compiler/esm-loader.ts @@ -32,7 +32,7 @@ export async function load (url: string, context: Context, defaultLoad: Function if (isNodeModulesDep || isTestcafeLibDep || !filename) return defaultLoad(url, context, defaultLoad); - const testFilesInfo = await Compiler.createTestFileInfo(filename); + const testFilesInfo = await Compiler.createTestFileInfo(filename, true); if (testFilesInfo?.compiler) { const [compiledCode] = await testFilesInfo.compiler.precompile([testFilesInfo]); diff --git a/src/compiler/index.js b/src/compiler/index.js index 984d1acdb54..4210e340793 100644 --- a/src/compiler/index.js +++ b/src/compiler/index.js @@ -26,7 +26,7 @@ export default class Compiler { return uniq(flattenDeep(getTestFileCompilers().map(compiler => compiler.getSupportedExtension()))); } - static async createTestFileInfo (filename) { + static async createTestFileInfo (filename, esm = false) { let code = null; try { @@ -38,7 +38,7 @@ export default class Compiler { code = stripBom(code).toString(); - const compiler = find(getTestFileCompilers(), someCompiler => someCompiler.canCompile(code, filename)); + const compiler = find(getTestFileCompilers(esm), someCompiler => someCompiler.canCompile(code, filename)); if (!compiler) return null;