Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: esm loader fix #8146

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/compilers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/esm-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Loading