Skip to content

Commit

Permalink
Avoid using NodeJS global type (#1032)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
ehmicky and sindresorhus committed May 9, 2024
1 parent fee011d commit 398d090
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions 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,
Expand Down Expand Up @@ -28,7 +29,7 @@ expectType<boolean>(unicornsResult.timedOut);
expectType<boolean>(unicornsResult.isCanceled);
expectType<boolean>(unicornsResult.isTerminated);
expectType<boolean>(unicornsResult.isMaxBuffer);
expectType<NodeJS.Signals | undefined>(unicornsResult.signal);
expectType<keyof SignalConstants | undefined>(unicornsResult.signal);
expectType<string | undefined>(unicornsResult.signalDescription);
expectType<string>(unicornsResult.cwd);
expectType<number>(unicornsResult.durationMs);
Expand All @@ -44,7 +45,7 @@ expectType<boolean>(unicornsResultSync.timedOut);
expectType<boolean>(unicornsResultSync.isCanceled);
expectType<boolean>(unicornsResultSync.isTerminated);
expectType<boolean>(unicornsResultSync.isMaxBuffer);
expectType<NodeJS.Signals | undefined>(unicornsResultSync.signal);
expectType<keyof SignalConstants | undefined>(unicornsResultSync.signal);
expectType<string | undefined>(unicornsResultSync.signalDescription);
expectType<string>(unicornsResultSync.cwd);
expectType<number>(unicornsResultSync.durationMs);
Expand All @@ -61,7 +62,7 @@ if (error instanceof ExecaError) {
expectType<boolean>(error.isCanceled);
expectType<boolean>(error.isTerminated);
expectType<boolean>(error.isMaxBuffer);
expectType<NodeJS.Signals | undefined>(error.signal);
expectType<keyof SignalConstants | undefined>(error.signal);
expectType<string | undefined>(error.signalDescription);
expectType<string>(error.cwd);
expectType<number>(error.durationMs);
Expand All @@ -83,7 +84,7 @@ if (errorSync instanceof ExecaSyncError) {
expectType<boolean>(errorSync.isCanceled);
expectType<boolean>(errorSync.isTerminated);
expectType<boolean>(errorSync.isMaxBuffer);
expectType<NodeJS.Signals | undefined>(errorSync.signal);
expectType<keyof SignalConstants | undefined>(errorSync.signal);
expectType<string | undefined>(errorSync.signalDescription);
expectType<string>(errorSync.cwd);
expectType<number>(errorSync.durationMs);
Expand Down
6 changes: 4 additions & 2 deletions 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';
Expand Down Expand Up @@ -73,7 +75,7 @@ export type CommonOptions<IsSync extends boolean = boolean> = {
@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)).
Expand Down Expand Up @@ -278,7 +280,7 @@ export type CommonOptions<IsSync extends boolean = boolean> = {
@default 'SIGTERM'
*/
readonly killSignal?: NodeJS.Signals | number;
readonly killSignal?: keyof SignalConstants | number;

/**
Run the subprocess independently from the current process.
Expand Down
3 changes: 2 additions & 1 deletion 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';
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion 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';
Expand Down Expand Up @@ -86,7 +87,7 @@ type ExecaCustomSubprocess<OptionsType extends Options = Options> = {
[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;

/**
Expand Down

0 comments on commit 398d090

Please sign in to comment.