codeceptjs 4.0.2-beta.18 → 4.0.2-beta.19
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/config.js +20 -15
- package/lib/utils/typescript.js +23 -15
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -156,27 +156,32 @@ async function loadConfigFile(configFile) {
|
|
|
156
156
|
try {
|
|
157
157
|
// For .ts files, try to compile and load as JavaScript
|
|
158
158
|
if (extensionName === '.ts') {
|
|
159
|
+
let transpileError = null
|
|
160
|
+
let tempFile = null
|
|
161
|
+
let allTempFiles = null
|
|
162
|
+
let fileMapping = null
|
|
163
|
+
|
|
159
164
|
try {
|
|
160
165
|
// Use the TypeScript transpilation utility
|
|
161
166
|
const typescript = require('typescript')
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
const result = await transpileTypeScript(configFile, typescript)
|
|
168
|
+
tempFile = result.tempFile
|
|
169
|
+
allTempFiles = result.allTempFiles
|
|
170
|
+
fileMapping = result.fileMapping
|
|
171
|
+
|
|
172
|
+
configModule = await import(tempFile)
|
|
173
|
+
cleanupTempFiles(allTempFiles)
|
|
174
|
+
} catch (err) {
|
|
175
|
+
transpileError = err
|
|
176
|
+
if (fileMapping) {
|
|
168
177
|
fixErrorStack(err, fileMapping)
|
|
169
|
-
cleanupTempFiles(allTempFiles)
|
|
170
|
-
throw err
|
|
171
178
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
try {
|
|
175
|
-
require('ts-node/register')
|
|
176
|
-
configModule = require(configFile)
|
|
177
|
-
} catch (tsNodeError) {
|
|
178
|
-
throw new Error(`Failed to load TypeScript config: ${tsError.message}`)
|
|
179
|
+
if (allTempFiles) {
|
|
180
|
+
cleanupTempFiles(allTempFiles)
|
|
179
181
|
}
|
|
182
|
+
// Throw immediately with the actual error - don't fall back to ts-node
|
|
183
|
+
// as it will mask the real error with "Unexpected token 'export'"
|
|
184
|
+
throw err
|
|
180
185
|
}
|
|
181
186
|
} else {
|
|
182
187
|
// Try ESM import first for JS files
|
package/lib/utils/typescript.js
CHANGED
|
@@ -158,11 +158,17 @@ const __dirname = __dirname_fn(__filename);
|
|
|
158
158
|
if (fs.existsSync(tsPath)) {
|
|
159
159
|
importedPath = tsPath
|
|
160
160
|
} else {
|
|
161
|
-
// Try .
|
|
162
|
-
const
|
|
163
|
-
if (fs.existsSync(
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
// Try index.ts for directory imports
|
|
162
|
+
const indexTsPath = path.join(importedPath, 'index.ts')
|
|
163
|
+
if (fs.existsSync(indexTsPath)) {
|
|
164
|
+
importedPath = indexTsPath
|
|
165
|
+
} else {
|
|
166
|
+
// Try .js extension as well
|
|
167
|
+
const jsPath = importedPath + '.js'
|
|
168
|
+
if (fs.existsSync(jsPath)) {
|
|
169
|
+
// Skip .js files, they don't need transpilation
|
|
170
|
+
continue
|
|
171
|
+
}
|
|
166
172
|
}
|
|
167
173
|
}
|
|
168
174
|
}
|
|
@@ -186,13 +192,11 @@ const __dirname = __dirname_fn(__filename);
|
|
|
186
192
|
if (transpiledFiles.has(tsVersion)) {
|
|
187
193
|
const tempFile = transpiledFiles.get(tsVersion)
|
|
188
194
|
const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
|
|
189
|
-
// Ensure the path starts with ./
|
|
190
195
|
if (!relPath.startsWith('.')) {
|
|
191
196
|
return `from './${relPath}'`
|
|
192
197
|
}
|
|
193
198
|
return `from '${relPath}'`
|
|
194
199
|
}
|
|
195
|
-
// Keep .js extension as-is (might be a real .js file)
|
|
196
200
|
return match
|
|
197
201
|
}
|
|
198
202
|
|
|
@@ -203,18 +207,24 @@ const __dirname = __dirname_fn(__filename);
|
|
|
203
207
|
if (transpiledFiles.has(tsPath)) {
|
|
204
208
|
const tempFile = transpiledFiles.get(tsPath)
|
|
205
209
|
const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
|
|
206
|
-
// Ensure the path starts with ./
|
|
207
210
|
if (!relPath.startsWith('.')) {
|
|
208
211
|
return `from './${relPath}'`
|
|
209
212
|
}
|
|
210
213
|
return `from '${relPath}'`
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
//
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
// Try index.ts for directory imports
|
|
217
|
+
const indexTsPath = path.join(resolvedPath, 'index.ts')
|
|
218
|
+
if (transpiledFiles.has(indexTsPath)) {
|
|
219
|
+
const tempFile = transpiledFiles.get(indexTsPath)
|
|
220
|
+
const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
|
|
221
|
+
if (!relPath.startsWith('.')) {
|
|
222
|
+
return `from './${relPath}'`
|
|
223
|
+
}
|
|
224
|
+
return `from '${relPath}'`
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// If the import doesn't have a standard module extension, add .js for ESM compatibility
|
|
218
228
|
const standardExtensions = ['.js', '.mjs', '.cjs', '.json', '.node']
|
|
219
229
|
const hasStandardExtension = standardExtensions.includes(originalExt.toLowerCase())
|
|
220
230
|
|
|
@@ -222,7 +232,6 @@ const __dirname = __dirname_fn(__filename);
|
|
|
222
232
|
return match.replace(importPath, importPath + '.js')
|
|
223
233
|
}
|
|
224
234
|
|
|
225
|
-
// Otherwise, keep the import as-is
|
|
226
235
|
return match
|
|
227
236
|
}
|
|
228
237
|
)
|
|
@@ -232,7 +241,6 @@ const __dirname = __dirname_fn(__filename);
|
|
|
232
241
|
/require\s*\(\s*['"](\.[^'"]+?)(?:\.ts)?['"]\s*\)/g,
|
|
233
242
|
(match, requirePath) => {
|
|
234
243
|
let resolvedPath = path.resolve(fileBaseDir, requirePath)
|
|
235
|
-
const originalExt = path.extname(requirePath)
|
|
236
244
|
|
|
237
245
|
// Handle .js extension that might be .ts
|
|
238
246
|
if (resolvedPath.endsWith('.js')) {
|