@@ -74,6 +74,8 @@ interface Finished {
7474 signal : NodeJS . Signals | null
7575 stdout : string
7676 stderr : string
77+ /** Whether stdout passed {@link MAX_OUTPUT_BYTES} and the rest was left out. */
78+ stdoutCut : boolean
7779}
7880
7981/**
@@ -96,10 +98,11 @@ function run(
9698 killSignal : 'SIGKILL' ,
9799 windowsHide : true ,
98100 } )
99- const output = { stdout : '' , stderr : '' }
101+ const output = { stdout : '' , stderr : '' , stdoutCut : false }
100102 for ( const stream of [ 'stdout' , 'stderr' ] as const ) {
101103 child [ stream ] ?. setEncoding ( 'utf8' ) . on ( 'data' , ( chunk : string ) => {
102104 if ( output [ stream ] . length < MAX_OUTPUT_BYTES ) output [ stream ] += chunk
105+ else if ( stream === 'stdout' ) output . stdoutCut = true
103106 } )
104107 }
105108 child . once ( 'error' , ( error ) =>
@@ -136,6 +139,21 @@ async function installedTsc(): Promise<string> {
136139 const root = typescriptRoot ( )
137140 const tsc = tscPath ( root )
138141 if ( existsSync ( tsc ) ) return tsc
142+ try {
143+ await installTypescript ( root )
144+ } catch ( error ) {
145+ if ( error instanceof TypesUnavailable ) throw error
146+ // The cache folder could not be written (permissions, a full disk).
147+ throw new TypesUnavailable (
148+ `TypeScript could not be installed into ${ root } (${ getErrorMessage ( error ) } ).`
149+ )
150+ }
151+ return tsc
152+ }
153+
154+ /** Installs the pinned release into `root` (see {@link installedTsc}). */
155+ async function installTypescript ( root : string ) : Promise < void > {
156+ const tsc = tscPath ( root )
139157 const parent = dirname ( root )
140158 await mkdir ( parent , { recursive : true } )
141159 const staging = await mkdtemp ( join ( parent , `.${ SOURCE_TYPESCRIPT_VERSION } -` ) )
@@ -187,7 +205,6 @@ async function installedTsc(): Promise<string> {
187205 } finally {
188206 await rm ( staging , { recursive : true , force : true } )
189207 }
190- return tsc
191208}
192209
193210/** An error tsc printed at a file position. */
@@ -208,7 +225,7 @@ const PROJECT_ERROR = /^error (TS\d+): (.*)$/
208225 */
209226function parseTscOutput ( stdout : string ) : { located : LocatedTscError [ ] ; project : string [ ] } {
210227 const located : LocatedTscError [ ] = [ ]
211- const project : string [ ] = [ ]
228+ const project : Array < { message : string } > = [ ]
212229 let last : { message : string } | undefined
213230 for ( const line of stdout . split ( / \r ? \n / ) ) {
214231 const at = LOCATED_ERROR . exec ( line )
@@ -224,12 +241,12 @@ function parseTscOutput(stdout: string): { located: LocatedTscError[]; project:
224241 last = error
225242 } else if ( global ) {
226243 last = { message : `${ global [ 1 ] } : ${ global [ 2 ] } ` }
227- project . push ( last . message )
244+ project . push ( last )
228245 } else if ( last && / ^ \s / . test ( line ) && line . trim ( ) ) {
229246 last . message += ` ${ line . trim ( ) } `
230247 }
231248 }
232- return { located, project }
249+ return { located, project : project . map ( ( { message } ) => message ) }
233250}
234251
235252/** The type check's outcome: whether it ran, and its findings. */
@@ -252,7 +269,18 @@ async function tscErrors(root: string): Promise<ReturnType<typeof parseTscOutput
252269 cwd : root ,
253270 }
254271 )
255- const errors = parseTscOutput ( finished . stdout )
272+ // Output past the cap ends mid-line: parse whole lines only, and say what was left out, as an
273+ // error no filter drops, so a cut list never reads as a clean check.
274+ const errors = parseTscOutput (
275+ finished . stdoutCut
276+ ? finished . stdout . slice ( 0 , finished . stdout . lastIndexOf ( '\n' ) )
277+ : finished . stdout
278+ )
279+ if ( finished . stdoutCut ) {
280+ errors . project . push (
281+ 'TypeScript reported more errors than a check lists; fix these and check again to see the rest.'
282+ )
283+ }
256284 if ( finished . code !== 0 && errors . located . length === 0 && errors . project . length === 0 ) {
257285 const said = ( finished . stderr || finished . stdout ) . trim ( ) . split ( '\n' ) [ 0 ] ?? ''
258286 throw new TypesUnavailable (
0 commit comments