From d0bb97ee1d0a630da6a957fef28b8f38c7112911 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 17 Oct 2024 22:34:15 +0300 Subject: [PATCH] test: add `setImmediate` polyfill for deno --- src/main/ts/spawn.ts | 6 +++--- src/main/ts/util.ts | 3 +++ src/main/ts/x.ts | 5 ++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 9792de8..608848f 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' @@ -88,7 +88,7 @@ export const defaults: TSpawnCtxNormalized = { input: null, env: process.env, get ee() { return new EventEmitter() }, - get ac() { return global.AbortController && new AbortController() }, + get ac() { return g.AbortController && new AbortController() }, get signal() { return this.ac?.signal }, on: {}, detached: process.platform !== 'win32', @@ -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..eb62038 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -1,4 +1,7 @@ import { Stream } from 'node:stream' +import process from 'node:process' + +export const g = (!process.versions.deno && global) || globalThis export const noop = () => { /* noop */ } 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 || {}