Skip to content

Commit 98a0e66

Browse files
committed
chore: linting
1 parent 7a7ca81 commit 98a0e66

File tree

2 files changed

+36
-79
lines changed

2 files changed

+36
-79
lines changed

src/core.ts

+36-77
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ 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'
20+
import { $ as zurk$, TShellResponse as TZurkShellResponse } from 'zurk'
2421
import {
2522
chalk,
2623
which,
@@ -87,7 +84,7 @@ try {
8784
defaults.prefix = 'set -euo pipefail;'
8885
defaults.quote = quote
8986
} catch (err) {
90-
if (process.platform == 'win32') {
87+
if (isWin) {
9188
try {
9289
defaults.shell = which.sync('powershell.exe')
9390
defaults.quote = quotePowerShell
@@ -120,7 +117,6 @@ export const $ = new Proxy<Shell & Options>(
120117
}
121118
cmd += s + pieces[++i]
122119
}
123-
isWin && console.log('cmd=', cmd)
124120
promise._bind(cmd, from, resolve!, reject!, getStore())
125121
// Postpone run to allow promise configuration.
126122
setImmediate(() => promise.isHalted || promise.run())
@@ -196,114 +192,71 @@ export class ProcessPromise extends Promise<ProcessOutput> {
196192

197193
this._zurk = zurk$({
198194
cmd: $.prefix + this._command,
199-
get cwd() { return $.cwd ?? $[processCwd] },
195+
get cwd() {
196+
return $.cwd ?? $[processCwd]
197+
},
200198
get shell() {
201-
isWin && console.log('$.shell=', $.shell)
202199
return typeof $.shell === 'string' ? $.shell : true
203200
},
204-
get env() { return $.env },
205-
get spawn() { return $.spawn },
201+
get env() {
202+
return $.env
203+
},
204+
get spawn() {
205+
return $.spawn
206+
},
206207
quote: <T>(v: T): T => v, // let zx handle quoting
207208
stdio: this._stdio as any,
208209
sync: false,
209210
nothrow: true,
210211
nohandle: true,
211212
detached: !isWin,
212-
onStdout(data: any) { $.log({ kind: 'stdout', data, verbose: $.verbose && !self._quiet }) },
213-
onStderr(data: any) { $.log({ kind: 'stderr', data, verbose: $.verbose && !self._quiet }) },
214-
run: cb => cb(),
213+
onStdout(data: any) {
214+
$.log({ kind: 'stdout', data, verbose: $.verbose && !self._quiet })
215+
},
216+
onStderr(data: any) {
217+
$.log({ kind: 'stderr', data, verbose: $.verbose && !self._quiet })
218+
},
219+
run: (cb) => cb(),
215220
timeout: self._timeout,
216221
timeoutSignal: self._timeoutSignal as NodeJS.Signals,
217222
})() as TZurkShellResponse
218223

219224
this.child = this._zurk._ctx.child as ChildProcess
220225

221-
this._zurk.finally(() => self._resolved = true)
222-
this._zurk.then(({
223-
error,
224-
stdout,
225-
stderr,
226-
stdall,
227-
status,
228-
signal
229-
}) => {
230-
isWin && console.log('ctx=', this._zurk?._ctx)
226+
this._zurk.finally(() => (self._resolved = true))
227+
this._zurk.then(({ error, stdout, stderr, stdall, status, signal }) => {
231228
if (error) {
232229
const message = ProcessOutput.getErrorMessage(error, self._from)
233230
self._reject(
234231
new ProcessOutput(null, null, stdout, stderr, stdall, message)
235232
)
236233
} else {
237-
const message = ProcessOutput.getMessage(status, signal, stderr, self._from)
234+
const message = ProcessOutput.getMessage(
235+
status,
236+
signal,
237+
stderr,
238+
self._from
239+
)
238240
const output = new ProcessOutput(
239241
status,
240242
signal,
241243
stdout,
242244
stderr,
243245
stdall,
244-
message,
246+
message
245247
)
246248
if (status === 0 || self._nothrow) {
247249
self._resolve(output)
248250
} else {
249251
self._reject(output)
250252
}
251253
}
252-
253254
})
254255

255-
// this.child = $.spawn($.prefix + this._command, {
256-
// cwd: $.cwd ?? $[processCwd],
257-
// shell: typeof $.shell === 'string' ? $.shell : true,
258-
// stdio: this._stdio,
259-
// windowsHide: true,
260-
// env: $.env,
261-
// })
262-
263-
// this.child.on('close', (code, signal) => {
264-
// // let message = ProcessOutput.getMessage(code, signal, stderr, this._from)
265-
// // let output = new ProcessOutput(
266-
// // code,
267-
// // signal,
268-
// // stdout,
269-
// // stderr,
270-
// // combined,
271-
// // message
272-
// // )
273-
// // if (code === 0 || this._nothrow) {
274-
// // this._resolve(output)
275-
// // } else {
276-
// // this._reject(output)
277-
// // }
278-
// // this._resolved = true
279-
// })
280-
// this.child.on('error', (err: NodeJS.ErrnoException) => {
281-
// // const message = ProcessOutput.getErrorMessage(err, this._from)
282-
// // this._reject(
283-
// // new ProcessOutput(null, null, stdout, stderr, combined, message)
284-
// // )
285-
// // this._resolved = true
286-
// })
287-
// let stdout = '',
288-
// stderr = '',
289-
// combined = ''
290-
// let onStdout = (data: any) => {
291-
// // $.log({ kind: 'stdout', data, verbose: $.verbose && !this._quiet })
292-
// stdout += data
293-
// combined += data
294-
// }
295-
// let onStderr = (data: any) => {
296-
// // $.log({ kind: 'stderr', data, verbose: $.verbose && !this._quiet })
297-
// stderr += data
298-
// combined += data
299-
// }
300256
// if (!this._piped) this.child.stdout?.on('data', onStdout) // If process is piped, don't collect or print output.
301257
// this.child.stderr?.on('data', onStderr) // Stderr should be printed regardless of piping.
302258
this._postrun() // In case $1.pipe($2), after both subprocesses are running, we can pipe $1.stdout to $2.stdin.
303-
// if (this._timeout && this._timeoutSignal) {
304-
// const t = setTimeout(() => this.kill(this._timeoutSignal), this._timeout)
305-
// this.finally(() => clearTimeout(t)).catch(noop)
306-
// }
259+
307260
return this
308261
}
309262

@@ -482,7 +435,12 @@ export class ProcessOutput extends Error {
482435
return this._signal
483436
}
484437

485-
static getMessage(code: number | null, signal: NodeJS.Signals | null, stderr: string, from: string) {
438+
static getMessage(
439+
code: number | null,
440+
signal: NodeJS.Signals | null,
441+
stderr: string,
442+
from: string
443+
) {
486444
let message = `exit code: ${code}`
487445
if (code != 0 || signal != null) {
488446
message = `${stderr || '\n'} at ${from}`
@@ -498,11 +456,12 @@ export class ProcessOutput extends Error {
498456
}
499457

500458
static getErrorMessage(err: NodeJS.ErrnoException, from: string) {
501-
return ``+
459+
return (
502460
`${err.message}\n` +
503461
` errno: ${err.errno} (${errnoMessage(err.errno)})\n` +
504462
` code: ${err.code}\n` +
505463
` at ${from}`
464+
)
506465
}
507466

508467
[inspect.custom]() {

test/win32.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ _describe('win32', () => {
2727
const p = await $`echo $0` // Bash is first by default.
2828
assert.match(p.stdout, /bash/)
2929
await within(async () => {
30-
$.prefix = ''
3130
$.shell = which.sync('powershell.exe')
3231
$.quote = quotePowerShell
3332
const p = await $`get-host`
@@ -37,7 +36,6 @@ _describe('win32', () => {
3736

3837
test('quotePowerShell works', async () => {
3938
await within(async () => {
40-
$.prefix = ''
4139
$.shell = which.sync('powershell.exe')
4240
$.quote = quotePowerShell
4341
const p = await $`echo ${`Windows 'rulez!'`}`

0 commit comments

Comments
 (0)