@@ -232,7 +232,7 @@ const runPatchCheck = files.some(
232232// Resolve without the lockfile in a temp copy to preserve the working tree and lockfile.
233233// Copy mobile modules too: they are file: dependencies, not workspace packages.
234234// Cached registry metadata limits this to patches stranded by local changes, not registry drift.
235- const checkPatches = ( ) : boolean => {
235+ const checkPatches = async ( ) => {
236236 const temp = NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-patch-check-" ) ) ;
237237 try {
238238 const copy = ( relative : string ) => {
@@ -253,24 +253,15 @@ const checkPatches = (): boolean => {
253253 for ( const extra of [ "apps/mobile/deps" , "patches" , ".pnpmfile.cjs" ] ) {
254254 if ( NodeFS . existsSync ( NodePath . join ( root , extra ) ) ) copy ( extra ) ;
255255 }
256- const { status, stdout, stderr, error } = NodeChildProcess . spawnSync (
257- "vp" ,
258- [ "install" , "--lockfile-only" , "--ignore-scripts" ] ,
259- { cwd : temp , encoding : "utf8" , maxBuffer : 64 * 1024 * 1024 , timeout : timeoutSeconds * 1000 } ,
260- ) ;
261- if ( status === 0 ) return true ;
262- if ( stdout ) console . log ( stdout ) ;
263- if ( stderr ) console . error ( stderr ) ;
264- if ( error ) console . error ( error . message ) ;
265- if ( `${ stdout ?? "" } ${ stderr ?? "" } ` . includes ( "ERR_PNPM_UNUSED_PATCH" ) ) {
266- console . error (
267- "Unused dependency patches: remove each patch named above from " +
268- "patchedDependencies in pnpm-workspace.yaml and from patches/, " +
269- "update it to the version the install resolves, " +
270- "or pin the dependency that pulls it in to the patched version." ,
271- ) ;
272- }
273- return false ;
256+ const result = await spawnStep ( [ "install" , "--lockfile-only" , "--ignore-scripts" ] , temp ) ;
257+ if ( result . outcome !== "FAIL" || ! result . output . includes ( "ERR_PNPM_UNUSED_PATCH" ) )
258+ return result ;
259+ const hint =
260+ "Unused dependency patches: remove each patch named above from " +
261+ "patchedDependencies in pnpm-workspace.yaml and from patches/, " +
262+ "update it to the version the install resolves, " +
263+ "or pin the dependency that pulls it in to the patched version.\n" ;
264+ return { ...result , output : Buffer . concat ( [ result . output , Buffer . from ( hint ) ] ) } ;
274265 } finally {
275266 NodeFS . rmSync ( temp , { recursive : true , force : true } ) ;
276267 }
@@ -284,18 +275,18 @@ const graphql = ["apps/server", "packages/source-control-github"].filter((dir) =
284275// oxlint-disable-next-line t3code/no-global-process-runtime -- Standalone script has no Effect runtime.
285276const platform = process . platform ;
286277// The typecheck step gets the same budget for its own package runs. macOS
287- // counts its file cache as used, so freemem() there would starve a large Mac.
278+ // counts its file cache as used, so available memory there would starve a large
279+ // Mac. Elsewhere availableMemory() also honors a container's cgroup limit.
288280const concurrency =
289281 positiveInteger ( process . env . CHECK_CHANGED_CONCURRENCY ) ??
290282 defaultConcurrency (
291283 NodeOS . availableParallelism ( ) ,
292- platform === "darwin" ? NodeOS . totalmem ( ) : NodeOS . freemem ( ) ,
284+ platform === "darwin" ? NodeOS . totalmem ( ) : process . availableMemory ( ) ,
293285 ) ;
294286const timeoutSeconds = positiveInteger ( process . env . CHECK_CHANGED_TIMEOUT ) ?? 900 ;
295287
296288const filters = ( names : ReadonlyArray < string > ) => names . flatMap ( ( name ) => [ "--filter" , name ] ) ;
297289const steps = [
298- // Runs first; it takes about a second.
299290 runPatchCheck && { name : "unused patches" , run : checkPatches } ,
300291 present . length > 0 && {
301292 name : "format" ,
@@ -354,6 +345,15 @@ for (const signal of ["SIGINT", "SIGTERM"] as const) {
354345 process . exit ( signal === "SIGINT" ? 130 : 143 ) ;
355346 } ) ;
356347}
348+ const spawnStep = async ( args : ReadonlyArray < string > , cwd = root ) => {
349+ const child = NodeChildProcess . spawn ( "vp" , args , { cwd, env, detached : ! windows } ) ;
350+ running . add ( child ) ;
351+ try {
352+ return await awaitStep ( child , timeoutSeconds * 1000 , ( ) => killTree ( child ) ) ;
353+ } finally {
354+ running . delete ( child ) ;
355+ }
356+ } ;
357357const runStep = async ( step : ( typeof steps ) [ number ] ) => {
358358 const started = performance . now ( ) ;
359359 const finish = ( outcome : StepOutcome , output ?: Buffer ) => {
@@ -365,13 +365,7 @@ const runStep = async (step: (typeof steps)[number]) => {
365365 if ( output ) process . stdout . write ( output ) ;
366366 return { name : step . name , outcome, time } ;
367367 } ;
368- // In-process steps print their own output. The patch check is first and
369- // takes about a second, so the commands start right after it.
370- if ( "run" in step ) return finish ( step . run ( ) ? "pass" : "FAIL" ) ;
371- const child = NodeChildProcess . spawn ( "vp" , step . args , { cwd : root , env, detached : ! windows } ) ;
372- running . add ( child ) ;
373- const { outcome, output } = await awaitStep ( child , timeoutSeconds * 1000 , ( ) => killTree ( child ) ) ;
374- running . delete ( child ) ;
368+ const { outcome, output } = await ( "run" in step ? step . run ( ) : spawnStep ( step . args ) ) ;
375369 return finish ( outcome , output ) ;
376370} ;
377371
0 commit comments