diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 9792de8..7c787b4 100644 --- a/src/main/ts/spawn.ts +++ b/src/main/ts/spawn.ts @@ -2,7 +2,7 @@ import * as cp from 'node:child_process' import process from 'node:process' import EventEmitter from 'node:events' import { Readable, Writable, Stream, Transform } from 'node:stream' -import { assign, noop, randomId } from './util.js' +import { assign, noop, randomId, g } from './util.js' export * from './util.js' @@ -102,7 +102,7 @@ export const defaults: TSpawnCtxNormalized = { get stdout(){ return new VoidStream() }, get stderr(){ return new VoidStream() }, stdio: ['pipe', 'pipe', 'pipe'], - run: setImmediate, + run: g.setImmediate, } export const normalizeCtx = (...ctxs: TSpawnCtx[]): TSpawnCtxNormalized => assign({ diff --git a/src/main/ts/util.ts b/src/main/ts/util.ts index 20769e6..d5fc326 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -1,5 +1,7 @@ import { Stream } from 'node:stream' +export const g = global || globalThis + export const noop = () => { /* noop */ } export const randomId = () => Math.random().toString(36).slice(2) diff --git a/src/main/ts/x.ts b/src/main/ts/x.ts index fb5e81b..065f5f3 100644 --- a/src/main/ts/x.ts +++ b/src/main/ts/x.ts @@ -17,7 +17,8 @@ import { assign, quote, buildCmd, - parseInput + parseInput, + g } from './util.js' import { pipeMixin } from './mixin/pipe.js' import { killMixin } from './mixin/kill.js' @@ -85,8 +86,6 @@ export interface TShellSync { (opts: TShellOptions): TShellSync } -const g = global || globalThis - export const $: TShell = function(this: any, pieces?: any, ...args: any): any { const self = (this !== g) && this const preset = self || {} diff --git a/src/test/smoke/invoke.test.mjs b/src/test/smoke/invoke.test.mjs index 1fed14b..1f3ff57 100644 --- a/src/test/smoke/invoke.test.mjs +++ b/src/test/smoke/invoke.test.mjs @@ -1,6 +1,10 @@ import assert from 'node:assert' import { zurk, $ } from '../../../target/esm/index.mjs' +if (globalThis.Deno) { + globalThis.setImmediate = (cb) => setTimeout(cb, 0) + globalThis.global = globalThis +} const keepAlive = setInterval(() => {}, 1000 * 60 * 60) const r1 = zurk({ sync: true, cmd: 'echo', args: ['foo'] })