Skip to content

Commit

Permalink
Merge branch 'main' into link-checker
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 5, 2024
2 parents 2b6ec0d + 8572eb1 commit f50a6d3
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 33 deletions.
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile
`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\
_Returns_: [`Promise<Result>`](#result)

Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](execution.md#template-string-syntax).
Like [`subprocess.pipe(file, arguments?, options?)`](#subprocesspipefile-arguments-options) but using a [`command` template string](execution.md#template-string-syntax) instead. This follows the same syntax as `execa` [template strings](execution.md#template-string-syntax).

[More info.](pipe.md#template-string-syntax)

Expand Down Expand Up @@ -1006,7 +1006,7 @@ By default, this applies to both `stdout` and `stderr`, but [different values ca
_Type:_ `boolean`\
_Default:_ `true` if the [`node`](#optionsnode), [`ipcInput`](#optionsipcinput) or [`gracefulCancel`](#optionsgracefulcancel) option is set, `false` otherwise

Enables exchanging messages with the subprocess using [`subprocess.sendMessage(message)`](#subprocesssendmessagemessage-sendmessageoptions), [`subprocess.getOneMessage()`](#subprocessgetonemessagegetonemessageoptions) and [`subprocess.getEachMessage()`](#subprocessgeteachmessage).
Enables exchanging messages with the subprocess using [`subprocess.sendMessage(message)`](#subprocesssendmessagemessage-sendmessageoptions), [`subprocess.getOneMessage()`](#subprocessgetonemessagegetonemessageoptions) and [`subprocess.getEachMessage()`](#subprocessgeteachmessagegeteachmessageoptions).

The subprocess must be a Node.js file.

Expand Down
2 changes: 1 addition & 1 deletion docs/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Synchronous execution is generally discouraged as it holds the CPU and prevents
- Signal termination: [`subprocess.kill()`](api.md#subprocesskillerror), [`subprocess.pid`](api.md#subprocesspid), [`cleanup`](api.md#optionscleanup) option, [`cancelSignal`](api.md#optionscancelsignal) option, [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option.
- Piping multiple subprocesses: [`subprocess.pipe()`](api.md#subprocesspipefile-arguments-options).
- [`subprocess.iterable()`](lines.md#progressive-splitting).
- [IPC](ipc.md): [`sendMessage()`](api.md#sendmessagemessage-sendmessageoptions), [`getOneMessage()`](api.md#getonemessagegetonemessageoptions), [`getEachMessage()`](api.md#geteachmessage), [`result.ipcOutput`](output.md#any-output-type), [`ipc`](api.md#optionsipc) option, [`serialization`](api.md#optionsserialization) option, [`ipcInput`](input.md#any-input-type) option.
- [IPC](ipc.md): [`sendMessage()`](api.md#sendmessagemessage-sendmessageoptions), [`getOneMessage()`](api.md#getonemessagegetonemessageoptions), [`getEachMessage()`](api.md#geteachmessagegeteachmessageoptions), [`result.ipcOutput`](output.md#any-output-type), [`ipc`](api.md#optionsipc) option, [`serialization`](api.md#optionsserialization) option, [`ipcInput`](input.md#any-input-type) option.
- [`result.all`](api.md#resultall) is not interleaved.
- [`detached`](api.md#optionsdetached) option.
- The [`maxBuffer`](api.md#optionsmaxbuffer) option is always measured in bytes, not in characters, [lines](api.md#optionslines) nor [objects](transform.md#object-mode). Also, it ignores transforms and the [`encoding`](api.md#optionsencoding) option.
Expand Down
6 changes: 3 additions & 3 deletions docs/ipc.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ await sendMessage(newMessage);

## Listening to messages

The methods described above read a single message. On the other hand, [`subprocess.getEachMessage()`](api.md#subprocessgeteachmessage) and [`getEachMessage()`](api.md#geteachmessage) return an [async iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols). This should be preferred when listening to multiple messages.
The methods described above read a single message. On the other hand, [`subprocess.getEachMessage()`](api.md#subprocessgeteachmessagegeteachmessageoptions) and [`getEachMessage()`](api.md#geteachmessagegeteachmessageoptions) return an [async iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols). This should be preferred when listening to multiple messages.

[`subprocess.getEachMessage()`](api.md#subprocessgeteachmessage) waits for the subprocess to end (even when using [`break`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) or [`return`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)). It throws if the subprocess [fails](api.md#result). This means you do not need to `await` the subprocess' [promise](execution.md#result).
[`subprocess.getEachMessage()`](api.md#subprocessgeteachmessagegeteachmessageoptions) waits for the subprocess to end (even when using [`break`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) or [`return`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)). It throws if the subprocess [fails](api.md#result). This means you do not need to `await` the subprocess' [promise](execution.md#result).

```js
// parent.js
Expand Down Expand Up @@ -128,7 +128,7 @@ await runTask(secondTask);

## Retrieve all messages

The [`result.ipcOutput`](api.md#resultipcoutput) array contains all the messages sent by the subprocess. In many situations, this is simpler than using [`subprocess.getOneMessage()`](api.md#subprocessgetonemessagegetonemessageoptions) and [`subprocess.getEachMessage()`](api.md#subprocessgeteachmessage).
The [`result.ipcOutput`](api.md#resultipcoutput) array contains all the messages sent by the subprocess. In many situations, this is simpler than using [`subprocess.getOneMessage()`](api.md#subprocessgetonemessagegetonemessageoptions) and [`subprocess.getEachMessage()`](api.md#subprocessgeteachmessagegeteachmessageoptions).

```js
// main.js
Expand Down
4 changes: 2 additions & 2 deletions types/return/ignore.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {NoStreamStdioOption, StdioOptionCommon} from '../stdio/type.js';
import type {NoStreamStdioOption} from '../stdio/type.js';
import type {IsInputFd} from '../stdio/direction.js';
import type {FdStdioOption} from '../stdio/option.js';
import type {FdSpecificOption} from '../arguments/specific.js';
Expand All @@ -22,5 +22,5 @@ export type IgnoresSubprocessOutput<

type IgnoresOutput<
FdNumber extends string,
StdioOptionType extends StdioOptionCommon,
StdioOptionType,
> = StdioOptionType extends NoStreamStdioOption<FdNumber> ? true : false;
2 changes: 1 addition & 1 deletion types/return/result-ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {Message, HasIpc} from '../ipc.js';
// This is empty unless the `ipc` option is `true`.
// Also, this is empty if the `buffer` option is `false`.
export type ResultIpcOutput<
IsSync extends boolean,
IsSync,
OptionsType extends CommonOptions,
> = IsSync extends true
? []
Expand Down
3 changes: 1 addition & 2 deletions types/return/result-stdio.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type {StdioOptionsArray} from '../stdio/type.js';
import type {StdioOptionNormalizedArray} from '../stdio/array.js';
import type {CommonOptions} from '../arguments/options.js';
import type {ResultStdioNotAll} from './result-stdout.js';
Expand All @@ -8,7 +7,7 @@ export type ResultStdioArray<OptionsType extends CommonOptions> =
MapResultStdio<StdioOptionNormalizedArray<OptionsType>, OptionsType>;

type MapResultStdio<
StdioOptionsArrayType extends StdioOptionsArray,
StdioOptionsArrayType,
OptionsType extends CommonOptions,
> = {
-readonly [FdNumber in keyof StdioOptionsArrayType]: ResultStdioNotAll<
Expand Down
4 changes: 2 additions & 2 deletions types/return/result-stdout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ OptionsType
type ResultStdioProperty<
ObjectFdNumber extends string,
LinesFdNumber extends string,
StreamOutputIgnored extends boolean,
StreamOutputIgnored,
OptionsType extends CommonOptions,
> = StreamOutputIgnored extends true
? undefined
Expand All @@ -37,7 +37,7 @@ type ResultStdioProperty<
>;

type ResultStdioItem<
IsObjectResult extends boolean,
IsObjectResult,
LinesOption extends boolean | undefined,
Encoding extends CommonOptions['encoding'],
> = IsObjectResult extends true ? unknown[]
Expand Down
13 changes: 4 additions & 9 deletions types/stdio/option.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import type {CommonOptions} from '../arguments/options.js';
import type {StdioOptionNormalizedArray} from './array.js';
import type {
StandardStreams,
StdioOptionCommon,
StdioOptionsArray,
StdioOptionsProperty,
} from './type.js';
import type {StandardStreams, StdioOptionCommon, StdioOptionsArray} from './type.js';

// `options.stdin|stdout|stderr|stdio` for a given file descriptor
export type FdStdioOption<
FdNumber extends string,
OptionsType extends CommonOptions,
> = Extract<FdStdioOptionProperty<FdNumber, OptionsType>, StdioOptionCommon>;
> = FdStdioOptionProperty<FdNumber, OptionsType>;

type FdStdioOptionProperty<
FdNumber extends string,
Expand All @@ -29,11 +24,11 @@ type FdStdioOptionProperty<
export type FdStdioArrayOption<
FdNumber extends string,
OptionsType extends CommonOptions,
> = Extract<FdStdioArrayOptionProperty<FdNumber, StdioOptionNormalizedArray<OptionsType>>, StdioOptionCommon>;
> = FdStdioArrayOptionProperty<FdNumber, StdioOptionNormalizedArray<OptionsType>>;

type FdStdioArrayOptionProperty<
FdNumber extends string,
StdioOptionsType extends StdioOptionsProperty,
StdioOptionsType,
> = string extends FdNumber
? StdioOptionCommon | undefined
: StdioOptionsType extends StdioOptionsArray
Expand Down
6 changes: 2 additions & 4 deletions types/stdio/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type StdioExtraOptionCommon<IsSync extends boolean> =
| StdoutStderrOptionCommon<IsSync, true>;

// `options.stdin|stdout|stderr|stdio` array items
export type StdioSingleOption<
type StdioSingleOption<
IsSync extends boolean = boolean,
IsExtra extends boolean = boolean,
IsArray extends boolean = boolean,
Expand All @@ -147,9 +147,7 @@ export type StdioSingleOption<
| StdoutStderrSingleOption<IsSync, IsExtra, IsArray>;

// Get `options.stdin|stdout|stderr|stdio` items if it is an array, else keep as is
export type StdioSingleOptionItems<
StdioOptionType extends StdioOptionCommon,
> = StdioOptionType extends readonly StdioSingleOption[]
export type StdioSingleOptionItems<StdioOptionType> = StdioOptionType extends readonly StdioSingleOption[]
? StdioOptionType[number]
: StdioOptionType;

Expand Down
2 changes: 1 addition & 1 deletion types/subprocess/all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type SubprocessAll<OptionsType extends Options> = AllStream<AllIgnored<Op
type AllStream<IsIgnored> = IsIgnored extends true ? undefined : Readable;

type AllIgnored<
AllOption extends Options['all'],
AllOption,
OptionsType extends Options,
> = AllOption extends true
? IgnoresSubprocessOutput<'1', OptionsType> extends true
Expand Down
3 changes: 1 addition & 2 deletions types/subprocess/stdio.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StdioOptionNormalizedArray} from '../stdio/array.js';
import type {StdioOptionsArray} from '../stdio/type.js';
import type {Options} from '../arguments/options.js';
import type {SubprocessStdioStream} from './stdout.js';

Expand All @@ -8,7 +7,7 @@ export type SubprocessStdioArray<OptionsType extends Options> = MapStdioStreams<

// We cannot use mapped types because it must be compatible with Node.js `ChildProcess["stdio"]` which uses a tuple with exactly 5 items
type MapStdioStreams<
StdioOptionsArrayType extends StdioOptionsArray,
StdioOptionsArrayType,
OptionsType extends Options,
> = [
SubprocessStdioStream<'0', OptionsType>,
Expand Down
2 changes: 1 addition & 1 deletion types/subprocess/stdout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type SubprocessStdioStream<

type SubprocessStream<
FdNumber extends string,
StreamResultIgnored extends boolean,
StreamResultIgnored,
OptionsType extends Options,
> = StreamResultIgnored extends true
? null
Expand Down
6 changes: 3 additions & 3 deletions types/transform/object-mode.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {StdioSingleOption, StdioOptionCommon, StdioSingleOptionItems} from '../stdio/type.js';
import type {StdioSingleOptionItems} from '../stdio/type.js';
import type {FdStdioOption} from '../stdio/option.js';
import type {CommonOptions} from '../arguments/options.js';
import type {DuplexTransform, TransformCommon} from './normalize.js';
Expand All @@ -10,9 +10,9 @@ export type IsObjectFd<
OptionsType extends CommonOptions,
> = IsObjectStdioOption<FdStdioOption<FdNumber, OptionsType>>;

type IsObjectStdioOption<StdioOptionType extends StdioOptionCommon> = IsObjectStdioSingleOption<StdioSingleOptionItems<StdioOptionType>>;
type IsObjectStdioOption<StdioOptionType> = IsObjectStdioSingleOption<StdioSingleOptionItems<StdioOptionType>>;

type IsObjectStdioSingleOption<StdioSingleOptionType extends StdioSingleOption> = StdioSingleOptionType extends TransformCommon
type IsObjectStdioSingleOption<StdioSingleOptionType> = StdioSingleOptionType extends TransformCommon
? BooleanObjectMode<StdioSingleOptionType['objectMode']>
: StdioSingleOptionType extends DuplexTransform
? StdioSingleOptionType['transform']['readableObjectMode']
Expand Down

0 comments on commit f50a6d3

Please sign in to comment.