* Resolve TypeScript path alias to actual file path * @param {string} importPath - Import path with alias (e.g., '#config/urls') * @param {object} tsConfig - Parsed tsconfig.json * @param {string} configDir - Directory containing tsconfig.json * @returns {string|null} - Resolved file path or nul
(importPath, tsConfig, configDir)
| 28 | * @returns {string|null} - Resolved file path or null if not an alias |
| 29 | */ |
| 30 | function resolveTsPathAlias(importPath, tsConfig, configDir) { |
| 31 | if (!tsConfig || !tsConfig.compilerOptions || !tsConfig.compilerOptions.paths) { |
| 32 | return null |
| 33 | } |
| 34 | |
| 35 | const paths = tsConfig.compilerOptions.paths |
| 36 | |
| 37 | for (const [pattern, targets] of Object.entries(paths)) { |
| 38 | if (!targets || targets.length === 0) { |
| 39 | continue |
| 40 | } |
| 41 | |
| 42 | const patternRegex = new RegExp( |
| 43 | '^' + pattern.replace(/\*/g, '(.*)') + '$' |
| 44 | ) |
| 45 | const match = importPath.match(patternRegex) |
| 46 | |
| 47 | if (match) { |
| 48 | const wildcard = match[1] || '' |
| 49 | const target = targets[0] |
| 50 | const resolvedTarget = target.replace(/\*/g, wildcard) |
| 51 | |
| 52 | return path.resolve(configDir, resolvedTarget) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return null |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Transpile TypeScript files to ES modules with CommonJS shim support |
no test coverage detected