(projectDir: string)
| 93 | } |
| 94 | |
| 95 | export function buildTsconfigAliases(projectDir: string): Array<{ find: RegExp; replacement: string }> { |
| 96 | const tsconfigPath = ts.findConfigFile(projectDir, ts.sys.fileExists); |
| 97 | if (!tsconfigPath) { |
| 98 | return []; |
| 99 | } |
| 100 | const { config, error } = ts.readConfigFile(tsconfigPath, ts.sys.readFile); |
| 101 | if (error || !config) { |
| 102 | return []; |
| 103 | } |
| 104 | const parsed = ts.parseJsonConfigFileContent(config, ts.sys, path.dirname(tsconfigPath)); |
| 105 | const aliases: Array<{ find: RegExp; replacement: string }> = []; |
| 106 | for (const [pattern, targets] of Object.entries(parsed.options.paths ?? {})) { |
| 107 | const target = targets?.[0]; |
| 108 | if (!target) { |
| 109 | continue; |
| 110 | } |
| 111 | if (pattern.endsWith('/*') && target.endsWith('/*')) { |
| 112 | aliases.push({ |
| 113 | find: new RegExp(`^${escapeRegExp(pattern.slice(0, -2))}/(.*)$`), |
| 114 | replacement: `${target.slice(0, -2)}/$1` |
| 115 | }); |
| 116 | } else { |
| 117 | aliases.push({ find: new RegExp(`^${escapeRegExp(pattern)}$`), replacement: target }); |
| 118 | } |
| 119 | } |
| 120 | return aliases; |
| 121 | } |
| 122 | |
| 123 | export function defaultBuildUserConfig(projectDir: string = process.cwd()): UserConfig { |
| 124 | return { |
no test coverage detected