@@ -593,6 +593,47 @@ export function resolveTsdownBuildInvocation(params = {}) {
593593 } ;
594594}
595595
596+ function signalWindowsProcessTree ( pid , signal , runTaskkill = spawnSync ) {
597+ const args = [ "/PID" , String ( pid ) , "/T" ] ;
598+ if ( signal === "SIGKILL" ) {
599+ args . push ( "/F" ) ;
600+ }
601+ const result = runTaskkill ( "taskkill" , args , { stdio : "ignore" } ) ;
602+ return ! result ?. error && result ?. status === 0 ;
603+ }
604+
605+ function signalWindowsProcessTreeOrForce ( pid , signal , runTaskkill = spawnSync ) {
606+ if ( signalWindowsProcessTree ( pid , signal , runTaskkill ) ) {
607+ return true ;
608+ }
609+ return signal !== "SIGKILL" && signalWindowsProcessTree ( pid , "SIGKILL" , runTaskkill ) ;
610+ }
611+
612+ export function signalTsdownBuildProcessTree (
613+ child ,
614+ signal ,
615+ {
616+ platform = process . platform ,
617+ runTaskkill = spawnSync ,
618+ useProcessGroup = platform !== "win32" ,
619+ } = { } ,
620+ ) {
621+ if ( useProcessGroup && child . pid ) {
622+ try {
623+ process . kill ( - child . pid , signal ) ;
624+ return ;
625+ } catch {
626+ // The group may already be gone; fall back to the direct child handle.
627+ }
628+ }
629+ if ( platform === "win32" && child . pid ) {
630+ if ( signalWindowsProcessTreeOrForce ( child . pid , signal , runTaskkill ) ) {
631+ return ;
632+ }
633+ }
634+ child . kill ( signal ) ;
635+ }
636+
596637export async function runTsdownBuildInvocation ( invocation , params = { } ) {
597638 const stdout = params . stdout ?? process . stdout ;
598639 const stderr = params . stderr ?? process . stderr ;
@@ -610,7 +651,9 @@ export async function runTsdownBuildInvocation(invocation, params = {}) {
610651 let lastOutputAt = Date . now ( ) ;
611652 let forceKillAt = null ;
612653
613- const useProcessGroup = process . platform !== "win32" ;
654+ const platform = params . platform ?? process . platform ;
655+ const runTaskkill = params . runTaskkill ?? spawnSync ;
656+ const useProcessGroup = platform !== "win32" ;
614657 const child = spawn ( invocation . command , invocation . args , {
615658 ...invocation . options ,
616659 detached : useProcessGroup ,
@@ -622,15 +665,11 @@ export async function runTsdownBuildInvocation(invocation, params = {}) {
622665 }
623666
624667 function signalChild ( signal ) {
625- if ( useProcessGroup && child . pid ) {
626- try {
627- process . kill ( - child . pid , signal ) ;
628- return ;
629- } catch {
630- // The group may already be gone; fall back to the direct child handle.
631- }
632- }
633- child . kill ( signal ) ;
668+ signalTsdownBuildProcessTree ( child , signal , {
669+ platform,
670+ runTaskkill,
671+ useProcessGroup,
672+ } ) ;
634673 }
635674
636675 const parentSignalHandlers = [ ] ;
0 commit comments