codeceptjs 4.0.2-beta.17 → 4.0.2-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.
@@ -118,20 +118,25 @@ const __dirname = __dirname_fn(__filename);
118
118
  // Transpile this file
119
119
  let jsContent = transpileTS(filePath)
120
120
 
121
- // Find all relative TypeScript imports in this file
121
+ // Find all relative TypeScript imports in this file (both ESM imports and require() calls)
122
122
  const importRegex = /from\s+['"](\.[^'"]+?)(?:\.ts)?['"]/g
123
+ const requireRegex = /require\s*\(\s*['"](\.[^'"]+?)(?:\.ts)?['"]\s*\)/g
123
124
  let match
124
125
  const imports = []
125
126
 
126
127
  while ((match = importRegex.exec(jsContent)) !== null) {
127
- imports.push(match[1])
128
+ imports.push({ path: match[1], type: 'import' })
129
+ }
130
+
131
+ while ((match = requireRegex.exec(jsContent)) !== null) {
132
+ imports.push({ path: match[1], type: 'require' })
128
133
  }
129
134
 
130
135
  // Get the base directory for this file
131
136
  const fileBaseDir = path.dirname(filePath)
132
137
 
133
138
  // Recursively transpile each imported TypeScript file
134
- for (const relativeImport of imports) {
139
+ for (const { path: relativeImport } of imports) {
135
140
  let importedPath = path.resolve(fileBaseDir, relativeImport)
136
141
 
137
142
  // Handle .js extensions that might actually be .ts files
@@ -222,6 +227,41 @@ const __dirname = __dirname_fn(__filename);
222
227
  }
223
228
  )
224
229
 
230
+ // Also rewrite require() calls to point to transpiled TypeScript files
231
+ jsContent = jsContent.replace(
232
+ /require\s*\(\s*['"](\.[^'"]+?)(?:\.ts)?['"]\s*\)/g,
233
+ (match, requirePath) => {
234
+ let resolvedPath = path.resolve(fileBaseDir, requirePath)
235
+ const originalExt = path.extname(requirePath)
236
+
237
+ // Handle .js extension that might be .ts
238
+ if (resolvedPath.endsWith('.js')) {
239
+ const tsVersion = resolvedPath.replace(/\.js$/, '.ts')
240
+ if (transpiledFiles.has(tsVersion)) {
241
+ const tempFile = transpiledFiles.get(tsVersion)
242
+ const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
243
+ const finalPath = relPath.startsWith('.') ? relPath : './' + relPath
244
+ return `require('${finalPath}')`
245
+ }
246
+ return match
247
+ }
248
+
249
+ // Try with .ts extension
250
+ const tsPath = resolvedPath.endsWith('.ts') ? resolvedPath : resolvedPath + '.ts'
251
+
252
+ // If we transpiled this file, use the temp file
253
+ if (transpiledFiles.has(tsPath)) {
254
+ const tempFile = transpiledFiles.get(tsPath)
255
+ const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
256
+ const finalPath = relPath.startsWith('.') ? relPath : './' + relPath
257
+ return `require('${finalPath}')`
258
+ }
259
+
260
+ // Otherwise, keep the require as-is
261
+ return match
262
+ }
263
+ )
264
+
225
265
  // Write the transpiled file with updated imports
226
266
  const tempFile = filePath.replace(/\.ts$/, '.temp.mjs')
227
267
  fs.writeFileSync(tempFile, jsContent)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "4.0.2-beta.17",
3
+ "version": "4.0.2-beta.18",
4
4
  "type": "module",
5
5
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
6
6
  "keywords": [