Skip to content

Commit

Permalink
test: add setImmediate polyfill for deno
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Oct 17, 2024
1 parent b682547 commit d0bb97e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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',
Expand All @@ -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({
Expand Down
3 changes: 3 additions & 0 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
@@ -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 */ }

Expand Down
5 changes: 2 additions & 3 deletions src/main/ts/x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 || {}
Expand Down

0 comments on commit d0bb97e

Please sign in to comment.