* Resolve the tsc invocation. Order: * (a) typecheckConfig.tscPath or CITADEL_TSC_PATH (test hook) * (b) the project's typescript package, run via the current node binary * (c) PROJECT_ROOT/node_modules/.bin/tsc shim * (d) tsc on PATH * Returns { cmd, baseArgs } or { error } when nothin
(typecheckConfig)
| 358 | const args = t.length > 1 ? t.slice(1) : [...DEFAULT_TSC_ARGS]; |
| 359 | if (!args.includes('--pretty')) args.push('--pretty', 'false'); |
| 360 | return { kind: 'tsc', args }; |
| 361 | } |
| 362 | return { kind: 'custom', tokens: t }; |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Resolve the tsc invocation. Order: |
| 367 | * (a) typecheckConfig.tscPath or CITADEL_TSC_PATH (test hook) |
| 368 | * (b) the project's typescript package, run via the current node binary |
| 369 | * (c) PROJECT_ROOT/node_modules/.bin/tsc shim |
| 370 | * (d) tsc on PATH |
| 371 | * Returns { cmd, baseArgs } or { error } when nothing resolves. |
| 372 | */ |
| 373 | function resolveTscInvocation(typecheckConfig) { |
| 374 | const explicit = typecheckConfig.tscPath || process.env.CITADEL_TSC_PATH; |
| 375 | if (explicit) { |
| 376 | if (!fs.existsSync(explicit)) { |
| 377 | return { error: `configured tsc path not found: ${explicit}` }; |
| 378 | } |
| 379 | if (/\.(exe|cmd|bat|com)$/i.test(explicit)) return { cmd: explicit, baseArgs: [] }; |
| 380 | return { cmd: process.execPath, baseArgs: [explicit] }; |
| 381 | } |
| 382 | |
| 383 | try { |
| 384 | const tscJs = require.resolve('typescript/bin/tsc', { paths: [PROJECT_ROOT] }); |
| 385 | return { cmd: process.execPath, baseArgs: [tscJs] }; |
| 386 | } catch { |
| 387 | // Older/newer typescript packages may not export bin/tsc; derive it from the main entry |
| 388 | try { |
| 389 | const tsMain = require.resolve('typescript', { paths: [PROJECT_ROOT] }); |
| 390 | const tscJs = path.join(path.dirname(tsMain), '..', 'bin', 'tsc'); |
| 391 | if (fs.existsSync(tscJs)) return { cmd: process.execPath, baseArgs: [tscJs] }; |
| 392 | } catch { /* typescript not installed in the project */ } |
| 393 | } |
no test coverage detected