Skip to content

Commit 80dff3b

Browse files
committed
chore: inject zurk
1 parent be0d674 commit 80dff3b

File tree

3 files changed

+66
-157
lines changed

3 files changed

+66
-157
lines changed

package-lock.json

+13-139
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,8 @@
9898
},
9999
"repository": "google/zx",
100100
"author": "Anton Medvedev <anton@medv.io>",
101-
"license": "Apache-2.0"
101+
"license": "Apache-2.0",
102+
"dependencies": {
103+
"zurk": "^0.0.3"
104+
}
102105
}

src/core.ts

+49-17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import { ChildProcess, spawn, StdioNull, StdioPipe } from 'node:child_process'
1717
import { AsyncLocalStorage, createHook } from 'node:async_hooks'
1818
import { Readable, Writable } from 'node:stream'
1919
import { inspect } from 'node:util'
20+
import {
21+
$ as zurk$,
22+
TShellResponse as TZurkShellResponse
23+
} from 'zurk'
2024
import {
2125
chalk,
2226
which,
@@ -159,6 +163,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
159163
private _resolved = false
160164
private _halted = false
161165
private _piped = false
166+
private _zurk: TZurkShellResponse | null = null
162167
_prerun = noop
163168
_postrun = noop
164169

@@ -180,29 +185,41 @@ export class ProcessPromise extends Promise<ProcessOutput> {
180185
const $ = this._snapshot
181186
if (this.child) return this // The _run() can be called from a few places.
182187
this._prerun() // In case $1.pipe($2), the $2 returned, and on $2._run() invoke $1._run().
188+
183189
$.log({
184190
kind: 'cmd',
185191
cmd: this._command,
186192
verbose: $.verbose && !this._quiet,
187193
})
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+
195221
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)
206223
let output = new ProcessOutput(
207224
code,
208225
signal,
@@ -425,6 +442,21 @@ export class ProcessOutput extends Error {
425442
return this._signal
426443
}
427444

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+
428460
[inspect.custom]() {
429461
let stringify = (s: string, c: ChalkInstance) =>
430462
s.length === 0 ? "''" : c(inspect(s))

0 commit comments

Comments
 (0)