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 9c33048
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
4 changes: 4 additions & 0 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
@@ -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 */ }

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 9c33048

Please sign in to comment.