codeceptjs 4.0.0-beta.16 → 4.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/typescript.js +35 -1
- package/package.json +1 -1
package/lib/utils/typescript.js
CHANGED
|
@@ -25,6 +25,9 @@ export async function transpileTypeScript(mainFilePath, typescript) {
|
|
|
25
25
|
target: 99, // ScriptTarget.ESNext
|
|
26
26
|
esModuleInterop: true,
|
|
27
27
|
allowSyntheticDefaultImports: true,
|
|
28
|
+
lib: ['lib.esnext.d.ts'], // Enable latest features including top-level await
|
|
29
|
+
suppressOutputPathCheck: true,
|
|
30
|
+
skipLibCheck: true,
|
|
28
31
|
})
|
|
29
32
|
|
|
30
33
|
// Check if the code uses CommonJS globals
|
|
@@ -41,7 +44,38 @@ export async function transpileTypeScript(mainFilePath, typescript) {
|
|
|
41
44
|
// This ensures dynamic require() calls work with relative paths from the original file location
|
|
42
45
|
const originalFileUrl = `file://${filePath.replace(/\\/g, '/')}`
|
|
43
46
|
esmGlobals += `import { createRequire } from 'module';
|
|
44
|
-
|
|
47
|
+
import { extname as __extname } from 'path';
|
|
48
|
+
const __baseRequire = createRequire('${originalFileUrl}');
|
|
49
|
+
|
|
50
|
+
// Wrap require to auto-resolve extensions (mimics CommonJS behavior)
|
|
51
|
+
const require = (id) => {
|
|
52
|
+
try {
|
|
53
|
+
return __baseRequire(id);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
// If module not found and it's a relative/absolute path without extension, try common extensions
|
|
56
|
+
if (err.code === 'MODULE_NOT_FOUND' && (id.startsWith('./') || id.startsWith('../') || id.startsWith('/'))) {
|
|
57
|
+
const ext = __extname(id);
|
|
58
|
+
// Only treat known file extensions as real extensions (so names like .TEST don't block probing)
|
|
59
|
+
const __knownExts = ['.js', '.cjs', '.mjs', '.json', '.node'];
|
|
60
|
+
const hasKnownExt = ext && __knownExts.includes(ext.toLowerCase());
|
|
61
|
+
if (!hasKnownExt) {
|
|
62
|
+
// Try common extensions in order: .js, .cjs, .json, .node
|
|
63
|
+
// Note: .ts files cannot be required - they need transpilation first
|
|
64
|
+
const extensions = ['.js', '.cjs', '.json', '.node'];
|
|
65
|
+
for (const testExt of extensions) {
|
|
66
|
+
try {
|
|
67
|
+
return __baseRequire(id + testExt);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// Continue to next extension
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Re-throw original error if all attempts failed
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
45
79
|
const module = { exports: {} };
|
|
46
80
|
const exports = module.exports;
|
|
47
81
|
|