From ffd1da2b5d64de946bb3c8aaaa38a34b45c88700 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 17 Oct 2024 23:43:39 +0300 Subject: [PATCH] feat: provide deno support --- .github/workflows/ci.yaml | 2 +- src/main/ts/spawn.ts | 4 ++-- src/main/ts/util.ts | 2 ++ src/main/ts/x.ts | 5 +++-- src/test/smoke/invoke.test.mjs | 1 + 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cd3d5f1..81ab21c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -142,7 +142,7 @@ jobs: uses: denoland/setup-deno@v2 with: deno-version: ${{ matrix.deno-version }} - - run: deno install + - run: deno install npm:types/node - uses: actions/download-artifact@v4 with: name: build diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 608848f..0448894 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, g } from './util.js' +import { assign, noop, randomId, g, immediate } 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: g.setImmediate, + run: immediate } export const normalizeCtx = (...ctxs: TSpawnCtx[]): TSpawnCtxNormalized => assign({ diff --git a/src/main/ts/util.ts b/src/main/ts/util.ts index 63745a3..977cf47 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -4,6 +4,8 @@ import { Buffer } from 'node:buffer' export const g = (!process.versions.deno && global) || globalThis +export const immediate = g.setImmediate || ((f: any) => g.setTimeout(f, 0)) + 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 065f5f3..33f2cae 100644 --- a/src/main/ts/x.ts +++ b/src/main/ts/x.ts @@ -18,7 +18,8 @@ import { quote, buildCmd, parseInput, - g + g, + immediate } from './util.js' import { pipeMixin } from './mixin/pipe.js' import { killMixin } from './mixin/kill.js' @@ -102,7 +103,7 @@ const ignite = (preset: any, pieces: TemplateStringsArray, ...args: any[]) => { const input = parseInput(preset.input) const run = cmd instanceof Promise ? (cb: TVoidCallback, ctx: TShellCtx) => cmd.then((cmd) => { ctx.cmd = cmd; cb() }) - : setImmediate + : immediate const opts = assign(preset, { cmd, run, input }) return applyMixins($, opts) diff --git a/src/test/smoke/invoke.test.mjs b/src/test/smoke/invoke.test.mjs index 1fed14b..6a35c04 100644 --- a/src/test/smoke/invoke.test.mjs +++ b/src/test/smoke/invoke.test.mjs @@ -1,4 +1,5 @@ import assert from 'node:assert' +import process from 'node:process' import { zurk, $ } from '../../../target/esm/index.mjs' const keepAlive = setInterval(() => {}, 1000 * 60 * 60)