@@ -13,15 +13,14 @@ export interface Options {
13
13
stdout ?: boolean
14
14
}
15
15
16
- const stdmockWrite = {
17
- stdout : process . stdout . write ,
18
- stderr : process . stderr . write ,
19
- }
20
-
21
16
export class ActionBase {
22
17
type ! : ActionType
23
18
std : 'stdout' | 'stderr' = 'stderr'
24
19
protected stdmocks ?: [ 'stdout' | 'stderr' , string [ ] ] [ ]
20
+ private stdmockOrigs = {
21
+ stdout : process . stdout . write ,
22
+ stderr : process . stderr . write ,
23
+ }
25
24
26
25
public start ( action : string , status ?: string , opts : Options = { } ) {
27
26
this . std = opts . stdout ? 'stdout' : 'stderr'
@@ -134,6 +133,11 @@ export class ActionBase {
134
133
const outputs : [ 'stdout' , 'stderr' ] = [ 'stdout' , 'stderr' ]
135
134
if ( toggle ) {
136
135
if ( this . stdmocks ) return
136
+ this . stdmockOrigs = {
137
+ stdout : process . stdout . write ,
138
+ stderr : process . stderr . write ,
139
+ }
140
+
137
141
this . stdmocks = [ ]
138
142
for ( let std of outputs ) {
139
143
( process [ std ] as any ) . write = ( ...args : any [ ] ) => {
@@ -144,7 +148,7 @@ export class ActionBase {
144
148
if ( ! this . stdmocks ) return
145
149
// this._write('stderr', '\nresetstdmock\n\n\n')
146
150
delete this . stdmocks
147
- for ( let std of outputs ) process [ std ] . write = stdmockWrite [ std ] as any
151
+ for ( let std of outputs ) process [ std ] . write = this . stdmockOrigs [ std ] as any
148
152
}
149
153
} catch ( err ) {
150
154
this . _write ( 'stderr' , inspect ( err ) )
@@ -178,6 +182,6 @@ export class ActionBase {
178
182
* write to the real stdout/stderr
179
183
*/
180
184
protected _write ( std : 'stdout' | 'stderr' , s : string | string [ ] ) {
181
- stdmockWrite [ std ] . apply ( process [ std ] , _ . castArray ( s ) )
185
+ this . stdmockOrigs [ std ] . apply ( process [ std ] , _ . castArray ( s ) )
182
186
}
183
187
}
0 commit comments