From 398d0908973a768de201e088214bba7af87ce3fd Mon Sep 17 00:00:00 2001 From: ehmicky Date: Thu, 9 May 2024 14:43:51 +0100 Subject: [PATCH] Avoid using NodeJS global type (#1032) Co-authored-by: Sindre Sorhus --- test-d/return/result-main.test-d.ts | 9 +++++---- types/arguments/options.d.ts | 6 ++++-- types/return/result.d.ts | 3 ++- types/subprocess/subprocess.d.ts | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test-d/return/result-main.test-d.ts b/test-d/return/result-main.test-d.ts index fcf6c1bf94..04649f21ae 100644 --- a/test-d/return/result-main.test-d.ts +++ b/test-d/return/result-main.test-d.ts @@ -1,3 +1,4 @@ +import type {SignalConstants} from 'node:os'; import {expectType, expectAssignable} from 'tsd'; import { execa, @@ -28,7 +29,7 @@ expectType(unicornsResult.timedOut); expectType(unicornsResult.isCanceled); expectType(unicornsResult.isTerminated); expectType(unicornsResult.isMaxBuffer); -expectType(unicornsResult.signal); +expectType(unicornsResult.signal); expectType(unicornsResult.signalDescription); expectType(unicornsResult.cwd); expectType(unicornsResult.durationMs); @@ -44,7 +45,7 @@ expectType(unicornsResultSync.timedOut); expectType(unicornsResultSync.isCanceled); expectType(unicornsResultSync.isTerminated); expectType(unicornsResultSync.isMaxBuffer); -expectType(unicornsResultSync.signal); +expectType(unicornsResultSync.signal); expectType(unicornsResultSync.signalDescription); expectType(unicornsResultSync.cwd); expectType(unicornsResultSync.durationMs); @@ -61,7 +62,7 @@ if (error instanceof ExecaError) { expectType(error.isCanceled); expectType(error.isTerminated); expectType(error.isMaxBuffer); - expectType(error.signal); + expectType(error.signal); expectType(error.signalDescription); expectType(error.cwd); expectType(error.durationMs); @@ -83,7 +84,7 @@ if (errorSync instanceof ExecaSyncError) { expectType(errorSync.isCanceled); expectType(errorSync.isTerminated); expectType(errorSync.isMaxBuffer); - expectType(errorSync.signal); + expectType(errorSync.signal); expectType(errorSync.signalDescription); expectType(errorSync.cwd); expectType(errorSync.durationMs); diff --git a/types/arguments/options.d.ts b/types/arguments/options.d.ts index 9d9b54e5bb..3a73c37bb5 100644 --- a/types/arguments/options.d.ts +++ b/types/arguments/options.d.ts @@ -1,3 +1,5 @@ +import type {SignalConstants} from 'node:os'; +import type {env} from 'node:process'; import type {Readable} from 'node:stream'; import type {Unless} from '../utils.js'; import type {StdinOptionCommon, StdoutStderrOptionCommon, StdioOptionsProperty} from '../stdio/type.js'; @@ -73,7 +75,7 @@ export type CommonOptions = { @default [process.env](https://nodejs.org/api/process.html#processenv) */ - readonly env?: NodeJS.ProcessEnv; + readonly env?: typeof env; /** If `true`, the subprocess uses both the `env` option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)). @@ -278,7 +280,7 @@ export type CommonOptions = { @default 'SIGTERM' */ - readonly killSignal?: NodeJS.Signals | number; + readonly killSignal?: keyof SignalConstants | number; /** Run the subprocess independently from the current process. diff --git a/types/return/result.d.ts b/types/return/result.d.ts index 1526430681..b4eb50a42a 100644 --- a/types/return/result.d.ts +++ b/types/return/result.d.ts @@ -1,3 +1,4 @@ +import type {SignalConstants} from 'node:os'; import type {Unless} from '../utils.js'; import type {CommonOptions, Options, SyncOptions} from '../arguments/options.js'; import type {ErrorProperties} from './final-error.js'; @@ -117,7 +118,7 @@ export declare abstract class CommonResult< If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`. */ - signal?: NodeJS.Signals; + signal?: keyof SignalConstants; /** A human-friendly description of the signal that was used to terminate the subprocess. diff --git a/types/subprocess/subprocess.d.ts b/types/subprocess/subprocess.d.ts index b5713f11ef..22bc6f2a3b 100644 --- a/types/subprocess/subprocess.d.ts +++ b/types/subprocess/subprocess.d.ts @@ -1,4 +1,5 @@ import type {ChildProcess} from 'node:child_process'; +import type {SignalConstants} from 'node:os'; import type {Readable, Writable, Duplex} from 'node:stream'; import type {StdioOptionsArray} from '../stdio/type.js'; import type {Options} from '../arguments/options.js'; @@ -86,7 +87,7 @@ type ExecaCustomSubprocess = { [More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal) */ - kill(signal?: NodeJS.Signals | number, error?: Error): boolean; + kill(signal?: keyof SignalConstants | number, error?: Error): boolean; kill(error?: Error): boolean; /**