(filePath)
| 181 | |
| 182 | // Recursive function to transpile a file and all its TypeScript dependencies |
| 183 | const transpileFileAndDeps = (filePath) => { |
| 184 | // Already transpiled, skip |
| 185 | if (transpiledFiles.has(filePath)) { |
| 186 | return |
| 187 | } |
| 188 | |
| 189 | // Transpile this file |
| 190 | let jsContent = transpileTS(filePath) |
| 191 | |
| 192 | // Find all TypeScript imports in this file (both ESM imports and require() calls) |
| 193 | const importRegex = /from\s+['"]([^'"]+?)['"]/g |
| 194 | const requireRegex = /require\s*\(\s*['"]([^'"]+?)['"]\s*\)/g |
| 195 | let match |
| 196 | const imports = [] |
| 197 | |
| 198 | while ((match = importRegex.exec(jsContent)) !== null) { |
| 199 | imports.push({ path: match[1], type: 'import' }) |
| 200 | } |
| 201 | |
| 202 | while ((match = requireRegex.exec(jsContent)) !== null) { |
| 203 | imports.push({ path: match[1], type: 'require' }) |
| 204 | } |
| 205 | |
| 206 | // Get the base directory for this file |
| 207 | const fileBaseDir = path.dirname(filePath) |
| 208 | |
| 209 | // Recursively transpile each imported TypeScript file |
| 210 | for (const { path: importPath } of imports) { |
| 211 | let importedPath = importPath |
| 212 | |
| 213 | // Check if this is a path alias |
| 214 | const resolvedAlias = resolveTsPathAlias(importPath, tsConfig, configDir) |
| 215 | if (resolvedAlias) { |
| 216 | importedPath = resolvedAlias |
| 217 | } else if (importPath.startsWith('.')) { |
| 218 | importedPath = path.resolve(fileBaseDir, importPath) |
| 219 | } else { |
| 220 | continue |
| 221 | } |
| 222 | |
| 223 | // Handle .js extensions that might actually be .ts files |
| 224 | if (importedPath.endsWith('.js')) { |
| 225 | const tsVersion = importedPath.replace(/\.js$/, '.ts') |
| 226 | if (fs.existsSync(tsVersion)) { |
| 227 | importedPath = tsVersion |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // Check for standard module extensions to determine if we should try adding .ts |
| 232 | const ext = path.extname(importedPath) |
| 233 | const standardExtensions = ['.js', '.mjs', '.cjs', '.json', '.node'] |
| 234 | const hasStandardExtension = standardExtensions.includes(ext.toLowerCase()) |
| 235 | |
| 236 | // If it doesn't end with .ts and doesn't have a standard extension, try adding .ts |
| 237 | if (!importedPath.endsWith('.ts') && !hasStandardExtension) { |
| 238 | const tsPath = importedPath + '.ts' |
| 239 | if (fs.existsSync(tsPath)) { |
| 240 | importedPath = tsPath |
no test coverage detected