diff --git a/src/context.ts b/src/context.ts index ac87e0d4c6..75fcb6f30d 100644 --- a/src/context.ts +++ b/src/context.ts @@ -13,6 +13,7 @@ // limitations under the License. import { AsyncLocalStorage } from 'node:async_hooks' +import { spawn } from 'node:child_process' export type Options = { verbose: boolean | number @@ -22,6 +23,7 @@ export type Options = { shell: string maxBuffer: number quote: (v: string) => string + spawn: typeof spawn logOutput?: 'stdout' | 'stderr' logFormat?: (...msg: any[]) => string | string[] logPrint?: (data: any, err?: any) => void diff --git a/src/core.ts b/src/core.ts index c18bbdff33..9ce7770e49 100644 --- a/src/core.ts +++ b/src/core.ts @@ -23,7 +23,7 @@ import { inspect, promisify } from 'node:util' import { spawn } from 'node:child_process' import { chalk, which } from './goods.js' -import { runInCtx, getCtx, setRootCtx, Context } from './context.js' +import { runInCtx, getCtx, setRootCtx, Context, Options } from './context.js' import { printCmd, log } from './print.js' import { quote, substitute } from './guards.js' @@ -31,7 +31,11 @@ import psTreeModule from 'ps-tree' const psTree = promisify(psTreeModule) -export function $(pieces: TemplateStringsArray, ...args: any[]) { +interface Zx extends Options { + (pieces: TemplateStringsArray, ...args: any[]): ProcessPromise +} + +export const $: Zx = function (pieces: TemplateStringsArray, ...args: any[]) { let resolve, reject let promise = new ProcessPromise((...args) => ([resolve, reject] = args))