|
1 | 1 |
|
2 | | -import { join } from 'path' |
3 | | -import { readFile, writeFile } from 'fs/promises' |
| 2 | +import { join, dirname } from 'path' |
| 3 | +import { readFile, writeFile, access } from 'fs/promises' |
4 | 4 | import glob from 'fast-glob' |
5 | 5 | import chalk from 'chalk' |
6 | 6 |
|
@@ -135,6 +135,31 @@ export async function capsule({ |
135 | 135 | } |
136 | 136 | } |
137 | 137 | } |
| 138 | + |
| 139 | + // Clean up tsconfig.json extends paths that don't resolve in the published package |
| 140 | + console.log('[t44] Cleaning up tsconfig.json extends paths ...\n') |
| 141 | + for (const [repoName, repoSourceDir] of Object.entries(repos)) { |
| 142 | + await cleanupTsconfigExtends(join(repoSourceDir as string, 'tsconfig.json')) |
| 143 | + |
| 144 | + // Follow workspaces to find sub-workspace tsconfig.json files |
| 145 | + const pkgPath = join(repoSourceDir as string, 'package.json') |
| 146 | + try { |
| 147 | + const pkgContent = await readFile(pkgPath, 'utf-8') |
| 148 | + const pkg = JSON.parse(pkgContent) |
| 149 | + const workspaces: string[] = pkg.workspaces || [] |
| 150 | + if (workspaces.length > 0) { |
| 151 | + const tsconfigPatterns = workspaces.map(ws => join(ws, 'tsconfig.json')) |
| 152 | + const tsconfigPaths = await glob(tsconfigPatterns, { |
| 153 | + cwd: repoSourceDir as string, |
| 154 | + absolute: true, |
| 155 | + onlyFiles: true, |
| 156 | + }) |
| 157 | + for (const tsconfigPath of tsconfigPaths) { |
| 158 | + await cleanupTsconfigExtends(tsconfigPath) |
| 159 | + } |
| 160 | + } |
| 161 | + } catch { } |
| 162 | + } |
138 | 163 | } |
139 | 164 | } |
140 | 165 | }, |
@@ -337,3 +362,29 @@ async function updateWorkspaceDependencies( |
337 | 362 | } |
338 | 363 | } |
339 | 364 | } |
| 365 | + |
| 366 | +async function cleanupTsconfigExtends(tsconfigPath: string): Promise<void> { |
| 367 | + try { |
| 368 | + const content = await readFile(tsconfigPath, 'utf-8') |
| 369 | + const tsconfig = JSON.parse(content) |
| 370 | + |
| 371 | + if (!tsconfig.extends) return |
| 372 | + |
| 373 | + // Resolve the extends path relative to the tsconfig.json directory |
| 374 | + const tsconfigDir = dirname(tsconfigPath) |
| 375 | + const extendsPath = join(tsconfigDir, tsconfig.extends) |
| 376 | + |
| 377 | + try { |
| 378 | + await access(extendsPath) |
| 379 | + // Path exists — keep it |
| 380 | + } catch { |
| 381 | + // Path does not exist — remove the extends field |
| 382 | + delete tsconfig.extends |
| 383 | + const indent = detectIndent(content) |
| 384 | + await writeFile(tsconfigPath, JSON.stringify(tsconfig, null, indent) + '\n', 'utf-8') |
| 385 | + console.log(chalk.green(` ✓ Removed invalid extends from ${tsconfigPath}\n`)) |
| 386 | + } |
| 387 | + } catch { |
| 388 | + // tsconfig.json doesn't exist or isn't valid JSON — skip |
| 389 | + } |
| 390 | +} |
0 commit comments