codeceptjs 4.0.1-beta.10 → 4.0.1-beta.12
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 +22 -2
- package/package.json +1 -1
package/lib/utils/typescript.js
CHANGED
|
@@ -142,8 +142,13 @@ const __dirname = __dirname_fn(__filename);
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
//
|
|
146
|
-
|
|
145
|
+
// Check for standard module extensions to determine if we should try adding .ts
|
|
146
|
+
const ext = path.extname(importedPath)
|
|
147
|
+
const standardExtensions = ['.js', '.mjs', '.cjs', '.json', '.node']
|
|
148
|
+
const hasStandardExtension = standardExtensions.includes(ext.toLowerCase())
|
|
149
|
+
|
|
150
|
+
// If it doesn't end with .ts and doesn't have a standard extension, try adding .ts
|
|
151
|
+
if (!importedPath.endsWith('.ts') && !hasStandardExtension) {
|
|
147
152
|
const tsPath = importedPath + '.ts'
|
|
148
153
|
if (fs.existsSync(tsPath)) {
|
|
149
154
|
importedPath = tsPath
|
|
@@ -168,6 +173,7 @@ const __dirname = __dirname_fn(__filename);
|
|
|
168
173
|
/from\s+['"](\..+?)(?:\.ts)?['"]/g,
|
|
169
174
|
(match, importPath) => {
|
|
170
175
|
let resolvedPath = path.resolve(fileBaseDir, importPath)
|
|
176
|
+
const originalExt = path.extname(importPath)
|
|
171
177
|
|
|
172
178
|
// Handle .js extension that might be .ts
|
|
173
179
|
if (resolvedPath.endsWith('.js')) {
|
|
@@ -181,6 +187,8 @@ const __dirname = __dirname_fn(__filename);
|
|
|
181
187
|
}
|
|
182
188
|
return `from '${relPath}'`
|
|
183
189
|
}
|
|
190
|
+
// Keep .js extension as-is (might be a real .js file)
|
|
191
|
+
return match
|
|
184
192
|
}
|
|
185
193
|
|
|
186
194
|
// Try with .ts extension
|
|
@@ -197,6 +205,18 @@ const __dirname = __dirname_fn(__filename);
|
|
|
197
205
|
return `from '${relPath}'`
|
|
198
206
|
}
|
|
199
207
|
|
|
208
|
+
// If the import doesn't have a standard module extension (.js, .mjs, .cjs, .json)
|
|
209
|
+
// add .js for ESM compatibility
|
|
210
|
+
// This handles cases where:
|
|
211
|
+
// 1. Import has no real extension (e.g., "./utils" or "./helper")
|
|
212
|
+
// 2. Import has a non-standard extension that's part of the name (e.g., "./abstract.helper")
|
|
213
|
+
const standardExtensions = ['.js', '.mjs', '.cjs', '.json', '.node']
|
|
214
|
+
const hasStandardExtension = standardExtensions.includes(originalExt.toLowerCase())
|
|
215
|
+
|
|
216
|
+
if (!hasStandardExtension) {
|
|
217
|
+
return match.replace(importPath, importPath + '.js')
|
|
218
|
+
}
|
|
219
|
+
|
|
200
220
|
// Otherwise, keep the import as-is
|
|
201
221
|
return match
|
|
202
222
|
}
|