From 9c330485817861792c95eeee35d16e265c04b60c 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 --- .github/workflows/ci.yaml | 1 + README.md | 1 + src/main/ts/spawn.ts | 6 +++--- src/main/ts/util.ts | 4 ++++ src/main/ts/x.ts | 5 ++--- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 87c3826..cd3d5f1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -142,6 +142,7 @@ jobs: uses: denoland/setup-deno@v2 with: deno-version: ${{ matrix.deno-version }} + - run: deno install - uses: actions/download-artifact@v4 with: name: build diff --git a/README.md b/README.md index dd8aea1..95473c1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Just a testing ground for verifying ideas and approaches aimed at improve the [z * Node.js >= 6 (CJS) * Node.js >= 12 (ESM) * Bun >= 1.0.0 + * Deno >= 1.7.0 ## Install ```bash 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..63745a3 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -1,4 +1,8 @@ import { Stream } from 'node:stream' +import process from 'node:process' +import { Buffer } from 'node:buffer' + +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 || {}