@@ -17,6 +17,10 @@ import { ChildProcess, spawn, StdioNull, StdioPipe } from 'node:child_process'
17
17
import { AsyncLocalStorage , createHook } from 'node:async_hooks'
18
18
import { Readable , Writable } from 'node:stream'
19
19
import { inspect } from 'node:util'
20
+ import {
21
+ $ as zurk$ ,
22
+ TShellResponse as TZurkShellResponse
23
+ } from 'zurk'
20
24
import {
21
25
chalk ,
22
26
which ,
@@ -159,6 +163,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
159
163
private _resolved = false
160
164
private _halted = false
161
165
private _piped = false
166
+ private _zurk : TZurkShellResponse | null = null
162
167
_prerun = noop
163
168
_postrun = noop
164
169
@@ -180,29 +185,41 @@ export class ProcessPromise extends Promise<ProcessOutput> {
180
185
const $ = this . _snapshot
181
186
if ( this . child ) return this // The _run() can be called from a few places.
182
187
this . _prerun ( ) // In case $1.pipe($2), the $2 returned, and on $2._run() invoke $1._run().
188
+
183
189
$ . log ( {
184
190
kind : 'cmd' ,
185
191
cmd : this . _command ,
186
192
verbose : $ . verbose && ! this . _quiet ,
187
193
} )
188
- this . child = $ . spawn ( $ . prefix + this . _command , {
189
- cwd : $ . cwd ?? $ [ processCwd ] ,
190
- shell : typeof $ . shell === 'string' ? $ . shell : true ,
191
- stdio : this . _stdio ,
192
- windowsHide : true ,
193
- env : $ . env ,
194
- } )
194
+
195
+ this . _zurk = zurk$ ( {
196
+ get cwd ( ) { return $ . cwd ?? $ [ processCwd ] } ,
197
+ cmd : $ . prefix + this . _command ,
198
+ get shell ( ) { return typeof $ . shell === 'string' ? $ . shell : true } ,
199
+ get env ( ) { return $ . env } ,
200
+ stdio : this . _stdio as any ,
201
+ get spawn ( ) { return $ . spawn } ,
202
+ run : cb => cb ( ) ,
203
+ sync : false ,
204
+ nothrow : true
205
+ } ) ( ) as TZurkShellResponse
206
+
207
+ this . child = this . _zurk . _ctx . child as ChildProcess
208
+
209
+ // this._zurk.then(({}) => {
210
+ //
211
+ // })
212
+
213
+ // this.child = $.spawn($.prefix + this._command, {
214
+ // cwd: $.cwd ?? $[processCwd],
215
+ // shell: typeof $.shell === 'string' ? $.shell : true,
216
+ // stdio: this._stdio,
217
+ // windowsHide: true,
218
+ // env: $.env,
219
+ // })
220
+
195
221
this . child . on ( 'close' , ( code , signal ) => {
196
- let message = `exit code: ${ code } `
197
- if ( code != 0 || signal != null ) {
198
- message = `${ stderr || '\n' } at ${ this . _from } `
199
- message += `\n exit code: ${ code } ${
200
- exitCodeInfo ( code ) ? ' (' + exitCodeInfo ( code ) + ')' : ''
201
- } `
202
- if ( signal != null ) {
203
- message += `\n signal: ${ signal } `
204
- }
205
- }
222
+ let message = ProcessOutput . getMessage ( code , signal , stderr , this . _from )
206
223
let output = new ProcessOutput (
207
224
code ,
208
225
signal ,
@@ -425,6 +442,21 @@ export class ProcessOutput extends Error {
425
442
return this . _signal
426
443
}
427
444
445
+ static getMessage ( code : number | null , signal : NodeJS . Signals | null , stderr : string , from : string ) {
446
+ let message = `exit code: ${ code } `
447
+ if ( code != 0 || signal != null ) {
448
+ message = `${ stderr || '\n' } at ${ from } `
449
+ message += `\n exit code: ${ code } ${
450
+ exitCodeInfo ( code ) ? ' (' + exitCodeInfo ( code ) + ')' : ''
451
+ } `
452
+ if ( signal != null ) {
453
+ message += `\n signal: ${ signal } `
454
+ }
455
+ }
456
+
457
+ return message
458
+ }
459
+
428
460
[ inspect . custom ] ( ) {
429
461
let stringify = ( s : string , c : ChalkInstance ) =>
430
462
s . length === 0 ? "''" : c ( inspect ( s ) )
0 commit comments