11import { AnsiParser } from 'ansi-parser/interfaces/ansi-parser' ;
22import { decodeAnsiBytes , defaultAnsiParser } from 'ansi-parser/src' ;
3- import type childProcess from 'child_process' ;
43import cp from 'cross-spawn' ;
5- import tty from 'tty' ;
4+ import ttyGlobal from 'tty' ;
65import { envVarNames } from '../constants/ipc' ;
7- import crossKill from './cross_kill' ;
6+ import crossKillGlobal from './cross_kill' ;
87import { applyActionToSty , defaultStyContext , restoreSty , StyContext } from './sty' ;
98
9+ interface CrossSpawnParams {
10+ command : string ;
11+ args : string [ ] ;
12+ cwd ?: string ;
13+ env ?: NodeJS . ProcessEnv | undefined ;
14+ }
15+ type CrossProcessReadable = {
16+ readonly on : ( name : 'data' , handler : ( buf : Buffer ) => void ) => void ;
17+ readonly off : ( name : 'data' , handler : ( buf : Buffer ) => void ) => void ;
18+ } ;
19+ type CrossProcess = {
20+ readonly pid ?: number | undefined ;
21+ readonly once : ( name : 'exit' , handler : ( exitCode : number | null ) => void ) => void ;
22+ readonly stdout : CrossProcessReadable ;
23+ readonly stderr : CrossProcessReadable ;
24+ } ;
25+ type CrossSpawn = ( params : CrossSpawnParams ) => CrossProcess ;
26+
1027export type ProcStatus = 'waiting' | 'running' | 'killed' | 'finished' ;
1128
1229export interface ProcOwn {
@@ -19,7 +36,8 @@ export interface ProcOwnInternal {
1936 command : string ;
2037 cwd : string ;
2138 npmPath : string ;
22- $raw ?: childProcess . ChildProcessWithoutNullStreams ;
39+ // $raw?: childProcess.ChildProcessWithoutNullStreams;
40+ $raw ?: CrossProcess ;
2341}
2442
2543export interface LogOwn {
@@ -173,13 +191,24 @@ export interface CreateProcManagerParams {
173191 enableUnreadMarker : boolean ;
174192 historyAlwaysKeepHeadSize : number ;
175193 historyCacheSize : number ;
194+
195+ // for test
196+ tty ?: typeof ttyGlobal ;
197+ crossSpawn ?: CrossSpawn ;
198+ crossKill ?: typeof crossKillGlobal ;
176199}
177200export const createProcManager = ( {
178201 forceNoColor,
179202 enableUnreadMarker,
180203 historyAlwaysKeepHeadSize,
181204 historyCacheSize,
205+ tty : tty0 ,
206+ crossKill : crossKill0 ,
207+ crossSpawn : crossSpawn0 ,
182208} : CreateProcManagerParams ) : ProcManager => {
209+ const tty = tty0 ?? ttyGlobal ;
210+ const crossSpawn : CrossSpawn = crossSpawn0 ?? cp . spawn ;
211+ const crossKill = crossKill0 ?? crossKillGlobal ;
183212 const isColorSupported =
184213 ! ( 'NO_COLOR' in process . env || forceNoColor ) &&
185214 ( 'FORCE_COLOR' in process . env ||
@@ -496,8 +525,10 @@ export const createProcManager = ({
496525 nodeStderr . parent = node ;
497526 $notifyUpdate ( ) ;
498527
499- const p = cp . spawn ( node . procOwn . npmPath , [ 'run' , node . name ] , {
500- stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
528+ const p = crossSpawn ( {
529+ command : node . procOwn . npmPath ,
530+ args : [ 'run' , node . name ] ,
531+ // stdio: ['pipe', 'pipe', 'pipe'],
501532 cwd : node . procOwn . cwd ,
502533 env : {
503534 ...process . env ,
0 commit comments