Skip to content

Commit 09df476

Browse files
committed
Meta tweaks
1 parent 30c7a7a commit 09df476

File tree

6 files changed

+51
-55
lines changed

6 files changed

+51
-55
lines changed

index.d.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Buffer} from 'node:buffer';
2-
import {ChildProcess} from 'node:child_process';
3-
import {Stream, Readable as ReadableStream} from 'node:stream';
1+
import {type Buffer} from 'node:buffer';
2+
import {type ChildProcess} from 'node:child_process';
3+
import {type Stream, type Readable as ReadableStream} from 'node:stream';
44

55
export type StdioOption =
66
| 'pipe'
@@ -12,7 +12,7 @@ export type StdioOption =
1212
| number
1313
| undefined;
1414

15-
export interface CommonOptions<EncodingType> {
15+
export type CommonOptions<EncodingType> = {
1616
/**
1717
Kill the spawned process when the parent process exits unless either:
1818
- the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)
@@ -244,23 +244,23 @@ export interface CommonOptions<EncodingType> {
244244
@default true
245245
*/
246246
readonly windowsHide?: boolean;
247-
}
247+
};
248248

249-
export interface Options<EncodingType = string> extends CommonOptions<EncodingType> {
249+
export type Options<EncodingType = string> = {
250250
/**
251251
Write some input to the `stdin` of your binary.
252252
*/
253253
readonly input?: string | Buffer | ReadableStream;
254-
}
254+
} & CommonOptions<EncodingType>;
255255

256-
export interface SyncOptions<EncodingType = string> extends CommonOptions<EncodingType> {
256+
export type SyncOptions<EncodingType = string> = {
257257
/**
258258
Write some input to the `stdin` of your binary.
259259
*/
260260
readonly input?: string | Buffer;
261-
}
261+
} & CommonOptions<EncodingType>;
262262

263-
export interface NodeOptions<EncodingType = string> extends Options<EncodingType> {
263+
export type NodeOptions<EncodingType = string> = {
264264
/**
265265
The Node.js executable to use.
266266
@@ -274,9 +274,9 @@ export interface NodeOptions<EncodingType = string> extends Options<EncodingType
274274
@default process.execArgv
275275
*/
276276
readonly nodeOptions?: string[];
277-
}
277+
} & Options<EncodingType>;
278278

279-
export interface ExecaReturnBase<StdoutStderrType> {
279+
export type ExecaReturnBase<StdoutStderrType> = {
280280
/**
281281
The file and arguments that were run, for logging purposes.
282282
@@ -335,11 +335,10 @@ export interface ExecaReturnBase<StdoutStderrType> {
335335
If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.
336336
*/
337337
signalDescription?: string;
338-
}
338+
};
339339

340-
export interface ExecaSyncReturnValue<StdoutErrorType = string>
341-
extends ExecaReturnBase<StdoutErrorType> {
342-
}
340+
export type ExecaSyncReturnValue<StdoutErrorType = string> = {
341+
} & ExecaReturnBase<StdoutErrorType>;
343342

344343
/**
345344
Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.
@@ -351,8 +350,7 @@ The child process fails when:
351350
- being canceled
352351
- there's not enough memory or there are already too many child processes
353352
*/
354-
export interface ExecaReturnValue<StdoutErrorType = string>
355-
extends ExecaSyncReturnValue<StdoutErrorType> {
353+
export type ExecaReturnValue<StdoutErrorType = string> = {
356354
/**
357355
The output of the process with `stdout` and `stderr` interleaved.
358356
@@ -368,11 +366,9 @@ export interface ExecaReturnValue<StdoutErrorType = string>
368366
You can cancel the spawned process using the [`signal`](https://github.com/sindresorhus/execa#signal-1) option.
369367
*/
370368
isCanceled: boolean;
371-
}
369+
} & ExecaSyncReturnValue<StdoutErrorType>;
372370

373-
export interface ExecaSyncError<StdoutErrorType = string>
374-
extends Error,
375-
ExecaReturnBase<StdoutErrorType> {
371+
export type ExecaSyncError<StdoutErrorType = string> = {
376372
/**
377373
Error message when the child process failed to run. In addition to the underlying error message, it also contains some information related to why the child process errored.
378374
@@ -391,10 +387,9 @@ export interface ExecaSyncError<StdoutErrorType = string>
391387
This is `undefined` unless the child process exited due to an `error` event or a timeout.
392388
*/
393389
originalMessage?: string;
394-
}
390+
} & Error & ExecaReturnBase<StdoutErrorType>;
395391

396-
export interface ExecaError<StdoutErrorType = string>
397-
extends ExecaSyncError<StdoutErrorType> {
392+
export type ExecaError<StdoutErrorType = string> = {
398393
/**
399394
The output of the process with `stdout` and `stderr` interleaved.
400395
@@ -408,9 +403,9 @@ export interface ExecaError<StdoutErrorType = string>
408403
Whether the process was canceled.
409404
*/
410405
isCanceled: boolean;
411-
}
406+
} & ExecaSyncError<StdoutErrorType>;
412407

413-
export interface KillOptions {
408+
export type KillOptions = {
414409
/**
415410
Milliseconds to wait for the child process to terminate before sending `SIGKILL`.
416411
@@ -419,9 +414,9 @@ export interface KillOptions {
419414
@default 5000
420415
*/
421416
forceKillAfterTimeout?: number | false;
422-
}
417+
};
423418

424-
export interface ExecaChildPromise<StdoutErrorType> {
419+
export type ExecaChildPromise<StdoutErrorType> = {
425420
/**
426421
Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).
427422
@@ -444,7 +439,7 @@ export interface ExecaChildPromise<StdoutErrorType> {
444439
Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This used to be preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. But now this is deprecated and you should either use `.kill()` or the `signal` option when creating the child process.
445440
*/
446441
cancel(): void;
447-
}
442+
};
448443

449444
export type ExecaChildProcess<StdoutErrorType = string> = ChildProcess &
450445
ExecaChildPromise<StdoutErrorType> &

index.test-d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import {Buffer} from 'node:buffer';
33
// `process.stdin`, `process.stderr`, and `process.stdout`
44
// to get treated as `any` by `@typescript-eslint/no-unsafe-assignment`.
55
import * as process from 'node:process';
6-
import {Readable as ReadableStream} from 'node:stream';
6+
import {type Readable as ReadableStream} from 'node:stream';
77
import {expectType, expectError} from 'tsd';
88
import {
99
execa,
1010
execaSync,
1111
execaCommand,
1212
execaCommandSync,
1313
execaNode,
14-
ExecaReturnValue,
15-
ExecaChildProcess,
16-
ExecaError,
17-
ExecaSyncReturnValue,
18-
ExecaSyncError,
14+
type ExecaReturnValue,
15+
type ExecaChildProcess,
16+
type ExecaError,
17+
type ExecaSyncReturnValue,
18+
type ExecaSyncError,
1919
} from './index.js';
2020

2121
try {

lib/promise.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// eslint-disable-next-line unicorn/prefer-top-level-await
12
const nativePromisePrototype = (async () => {})().constructor.prototype;
3+
24
const descriptors = ['then', 'catch', 'finally'].map(property => [
35
property,
46
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"dependencies": {
4444
"cross-spawn": "^7.0.3",
4545
"get-stream": "^6.0.1",
46-
"human-signals": "^4.1.0",
46+
"human-signals": "^4.3.0",
4747
"is-stream": "^3.0.0",
4848
"merge-stream": "^2.0.0",
4949
"npm-run-path": "^5.1.0",
@@ -52,16 +52,16 @@
5252
"strip-final-newline": "^3.0.0"
5353
},
5454
"devDependencies": {
55-
"@types/node": "^17.0.17",
56-
"ava": "^4.0.1",
57-
"c8": "^7.11.0",
58-
"get-node": "^12.0.0",
55+
"@types/node": "^18.13.0",
56+
"ava": "^5.2.0",
57+
"c8": "^7.12.0",
58+
"get-node": "^13.5.0",
5959
"is-running": "^2.1.0",
6060
"p-event": "^5.0.1",
6161
"path-key": "^4.0.0",
6262
"tempfile": "^4.0.0",
63-
"tsd": "^0.19.1",
64-
"xo": "^0.48.0"
63+
"tsd": "^0.25.0",
64+
"xo": "^0.53.1"
6565
},
6666
"c8": {
6767
"reporter": [
@@ -74,6 +74,9 @@
7474
"**/test/**"
7575
]
7676
},
77+
"ava": {
78+
"workerThreads": false
79+
},
7780
"xo": {
7881
"rules": {
7982
"unicorn/no-empty-file": "off",

test/fixtures/sub-process-exit.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ import {execa} from '../../index.js';
55
const cleanup = process.argv[2] === 'true';
66
const detached = process.argv[3] === 'true';
77

8-
const runChild = async () => {
9-
try {
10-
await execa('node', ['./test/fixtures/noop.js'], {cleanup, detached});
11-
} catch (error) {
12-
console.error(error);
13-
process.exit(1);
14-
}
15-
};
16-
17-
runChild();
8+
try {
9+
await execa('node', ['./test/fixtures/noop.js'], {cleanup, detached});
10+
} catch (error) {
11+
console.error(error);
12+
process.exit(1);
13+
}

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ test('localDir option', async t => {
104104
});
105105

106106
test('execPath option', async t => {
107-
const {path: execPath} = await getNode('6.0.0');
107+
const {path: execPath} = await getNode('16.0.0');
108108
const {stdout} = await execa('node', ['-p', 'process.env.Path || process.env.PATH'], {preferLocal: true, execPath});
109-
t.true(stdout.includes('6.0.0'));
109+
t.true(stdout.includes('16.0.0'));
110110
});
111111

112112
test('stdin errors are handled', async t => {

0 commit comments

Comments
 (0)