|
1 | | -import execa from 'execa'; |
| 1 | +import execa, { ExecaError } from 'execa'; |
2 | 2 |
|
3 | | -export const listFilesOnly = async (): Promise<string> => { |
4 | | - const output = await execa('tsc', ['--listFilesOnly'], { |
| 3 | +export const showConfig = async (): Promise<string> => { |
| 4 | + const output = await execa('tsc', ['--showConfig'], { |
5 | 5 | all: true, |
6 | 6 | preferLocal: true, |
7 | 7 | }); |
8 | 8 |
|
9 | 9 | return output.stdout; |
10 | 10 | }; |
11 | 11 |
|
12 | | -export const showConfig = async (): Promise<string> => { |
13 | | - const output = await execa('tsc', ['--showConfig'], { |
14 | | - all: true, |
15 | | - preferLocal: true, |
16 | | - }); |
| 12 | +let compilerOutputCache = ''; |
| 13 | +export const compile = async (): Promise<string> => { |
| 14 | + if (compilerOutputCache) { |
| 15 | + return compilerOutputCache; |
| 16 | + } |
17 | 17 |
|
18 | | - return output.stdout; |
| 18 | + try { |
| 19 | + const compilerResult = await execa( |
| 20 | + 'tsc', |
| 21 | + [...process.argv.slice(2), '--strict', '--noEmit', '--pretty', 'false', '--listFiles'], |
| 22 | + { |
| 23 | + all: true, |
| 24 | + preferLocal: true, |
| 25 | + }, |
| 26 | + ); |
| 27 | + |
| 28 | + compilerOutputCache = compilerResult.stdout; |
| 29 | + } catch (error) { |
| 30 | + if (isExecaError(error) && error.all) { |
| 31 | + compilerOutputCache = error.all; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + return compilerOutputCache; |
19 | 36 | }; |
20 | 37 |
|
21 | | -export const compile = () => |
22 | | - execa('tsc', ['--strict', '--noEmit', ...process.argv.slice(2)], { |
23 | | - all: true, |
24 | | - preferLocal: true, |
25 | | - }); |
| 38 | +function isExecaError(error: unknown): error is ExecaError { |
| 39 | + return typeof (error as ExecaError)?.all === 'string'; |
| 40 | +} |
0 commit comments