Skip to content

Commit

Permalink
Rename result.ipc to result.ipcOutput (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 19, 2024
1 parent 587b490 commit ae9b360
Show file tree
Hide file tree
Showing 26 changed files with 159 additions and 159 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ Items are arrays when their corresponding `stdio` option is a [transform in obje

[More info.](output.md#additional-file-descriptors)

### result.ipc
### result.ipcOutput

_Type_: [`Message[]`](ipc.md#message-type)

Expand Down
2 changes: 1 addition & 1 deletion docs/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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`](api.md#optionsipc) and [`serialization`](api.md#optionsserialization) options.
- [IPC](ipc.md): [`sendMessage()`](api.md#sendmessagemessage), [`getOneMessage()`](api.md#getonemessage), [`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.
- [`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
10 changes: 5 additions & 5 deletions docs/ipc.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ for await (const message of getEachMessage()) {

## Retrieve all messages

The [`result.ipc`](api.md#resultipc) array contains all the messages sent by the subprocess. In many situations, this is simpler than using [`subprocess.getOneMessage()`](api.md#subprocessgetonemessage) 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#subprocessgetonemessage) and [`subprocess.getEachMessage()`](api.md#subprocessgeteachmessage).

```js
// main.js
import {execaNode} from 'execa';

const {ipc} = await execaNode`build.js`;
console.log(ipc[0]); // {kind: 'start', timestamp: date}
console.log(ipc[1]); // {kind: 'stop', timestamp: date}
const {ipcOutput} = await execaNode`build.js`;
console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}
console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}
```

```js
Expand Down Expand Up @@ -125,7 +125,7 @@ const subprocess = execaNode({serialization: 'json'})`child.js`;

When the [`verbose`](api.md#optionsverbose) option is `'full'`, the IPC messages sent by the subprocess to the current process are [printed on the console](debugging.md#full-mode).

Also, when the subprocess [failed](errors.md#subprocess-failure), [`error.ipc`](api.md) contains all the messages sent by the subprocess. Those are also shown at the end of the [error message](errors.md#error-message).
Also, when the subprocess [failed](errors.md#subprocess-failure), [`error.ipcOutput`](api.md) contains all the messages sent by the subprocess. Those are also shown at the end of the [error message](errors.md#error-message).

<hr>

Expand Down
14 changes: 7 additions & 7 deletions docs/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ await execa({stdout: 1, stderr: 1})`npm run build`;

## Any output type

If the subprocess uses Node.js, [IPC](ipc.md) can be used to return [almost any type](ipc.md#message-type) from the subprocess. The [`result.ipc`](api.md#resultipc) array contains all the messages sent by the subprocess.
If the subprocess uses Node.js, [IPC](ipc.md) can be used to return [almost any type](ipc.md#message-type) from the subprocess. The [`result.ipcOutput`](api.md#resultipcoutput) array contains all the messages sent by the subprocess.

```js
// main.js
import {execaNode} from 'execa';

const {ipc} = await execaNode`build.js`;
console.log(ipc[0]); // {kind: 'start', timestamp: date}
console.log(ipc[1]); // {kind: 'stop', timestamp: date}
const {ipcOutput} = await execaNode`build.js`;
console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}
console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}
```

```js
Expand Down Expand Up @@ -162,14 +162,14 @@ await execa({stdin: 'ignore', stdout: 'ignore', stderr: 'ignore'})`npm run build

To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](api.md#optionsmaxbuffer) option. It defaults to 100MB.

When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#errorismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout), [`error.stderr`](api.md#resultstderr) and [`error.ipc`](api.md#resultipc).
When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#errorismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout), [`error.stderr`](api.md#resultstderr) and [`error.ipcOutput`](api.md#resultipcoutput).

This is measured:
- By default: in [characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).
- If the [`encoding`](binary.md#encoding) option is `'buffer'`: in bytes.
- If the [`lines`](lines.md#simple-splitting) option is `true`: in lines.
- If a [transform in object mode](transform.md#object-mode) is used: in objects.
- With [`error.ipc`](ipc.md#retrieve-all-messages): in messages.
- With [`error.ipcOutput`](ipc.md#retrieve-all-messages): in messages.

```js
try {
Expand All @@ -187,7 +187,7 @@ try {

## Low memory

When the [`buffer`](api.md#optionsbuffer) option is `false`, [`result.stdout`](api.md#resultstdout), [`result.stderr`](api.md#resultstderr), [`result.all`](api.md#resultall), [`result.stdio[*]`](api.md#resultstdio) and [`result.ipc`](api.md#resultipc) properties are empty.
When the [`buffer`](api.md#optionsbuffer) option is `false`, [`result.stdout`](api.md#resultstdout), [`result.stderr`](api.md#resultstderr), [`result.all`](api.md#resultall), [`result.stdio[*]`](api.md#resultstdio) and [`result.ipcOutput`](api.md#resultipcoutput) properties are empty.

This prevents high memory consumption when the output is big. However, the output must be either ignored, [redirected](#file-output), [streamed](streams.md) or [listened to](ipc.md#listening-to-messages). If streamed, this should be done right away to avoid missing any data.

Expand Down
6 changes: 3 additions & 3 deletions lib/io/max-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const getMaxBufferUnit = (readableObjectMode, lines, encoding) => {
return 'characters';
};

// Check the `maxBuffer` option with `result.ipc`
export const checkIpcMaxBuffer = (subprocess, ipcMessages, maxBuffer) => {
if (ipcMessages.length !== maxBuffer) {
// Check the `maxBuffer` option with `result.ipcOutput`
export const checkIpcMaxBuffer = (subprocess, ipcOutput, maxBuffer) => {
if (ipcOutput.length !== maxBuffer) {
return;
}

Expand Down
18 changes: 9 additions & 9 deletions lib/ipc/buffer-messages.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {checkIpcMaxBuffer} from '../io/max-buffer.js';
import {shouldLogIpc, logIpcMessage} from '../verbose/ipc.js';
import {shouldLogIpc, logIpcOutput} from '../verbose/ipc.js';
import {loopOnMessages} from './get-each.js';

// Iterate through IPC messages sent by the subprocess
export const waitForIpcMessages = async ({
export const waitForIpcOutput = async ({
subprocess,
buffer: bufferArray,
maxBuffer: maxBufferArray,
ipc,
ipcMessages,
ipcOutput,
verboseInfo,
}) => {
if (!ipc) {
return ipcMessages;
return ipcOutput;
}

const isVerbose = shouldLogIpc(verboseInfo);
const buffer = bufferArray.at(-1);
const maxBuffer = maxBufferArray.at(-1);

if (!isVerbose && !buffer) {
return ipcMessages;
return ipcOutput;
}

for await (const message of loopOnMessages({
Expand All @@ -30,14 +30,14 @@ export const waitForIpcMessages = async ({
shouldAwait: false,
})) {
if (buffer) {
checkIpcMaxBuffer(subprocess, ipcMessages, maxBuffer);
ipcMessages.push(message);
checkIpcMaxBuffer(subprocess, ipcOutput, maxBuffer);
ipcOutput.push(message);
}

if (isVerbose) {
logIpcMessage(message, verboseInfo);
logIpcOutput(message, verboseInfo);
}
}

return ipcMessages;
return ipcOutput;
};
10 changes: 5 additions & 5 deletions lib/methods/main-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const handlePromise = async ({subprocess, options, startTime, verboseInfo, fileD
[exitCode, signal],
stdioResults,
allResult,
ipcMessages,
ipcOutput,
] = await waitForSubprocessResult({
subprocess,
options,
Expand All @@ -159,7 +159,7 @@ const handlePromise = async ({subprocess, options, startTime, verboseInfo, fileD
signal,
stdio,
all,
ipcMessages,
ipcOutput,
context,
options,
command,
Expand All @@ -169,7 +169,7 @@ const handlePromise = async ({subprocess, options, startTime, verboseInfo, fileD
return handleResult(result, verboseInfo, options);
};

const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, ipcMessages, context, options, command, escapedCommand, startTime}) => 'error' in errorInfo
const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, ipcOutput, context, options, command, escapedCommand, startTime}) => 'error' in errorInfo
? makeError({
error: errorInfo.error,
command,
Expand All @@ -181,7 +181,7 @@ const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, ipcMessages, c
signal,
stdio,
all,
ipcMessages,
ipcOutput,
options,
startTime,
isSync: false,
Expand All @@ -191,7 +191,7 @@ const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, ipcMessages, c
escapedCommand,
stdio,
all,
ipcMessages,
ipcOutput,
options,
startTime,
});
4 changes: 2 additions & 2 deletions lib/methods/main-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const getSyncResult = ({error, exitCode, signal, timedOut, isMaxBuffer, stdio, a
escapedCommand,
stdio,
all,
ipcMessages: [],
ipcOutput: [],
options,
startTime,
})
Expand All @@ -160,7 +160,7 @@ const getSyncResult = ({error, exitCode, signal, timedOut, isMaxBuffer, stdio, a
signal,
stdio,
all,
ipcMessages: [],
ipcOutput: [],
options,
startTime,
isSync: true,
Expand Down
10 changes: 5 additions & 5 deletions lib/resolve/wait-subprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {throwOnTimeout} from '../terminate/timeout.js';
import {isStandardStream} from '../utils/standard-stream.js';
import {TRANSFORM_TYPES} from '../stdio/type.js';
import {getBufferedData} from '../io/contents.js';
import {waitForIpcMessages} from '../ipc/buffer-messages.js';
import {waitForIpcOutput} from '../ipc/buffer-messages.js';
import {sendIpcInput} from '../ipc/ipc-input.js';
import {waitForAllStream} from './all-async.js';
import {waitForStdioStreams} from './stdio.js';
Expand Down Expand Up @@ -60,7 +60,7 @@ export const waitForSubprocessResult = async ({
verboseInfo,
streamInfo,
});
const ipcMessages = [];
const ipcOutput = [];
const originalPromises = waitForOriginalStreams(originalStreams, subprocess, streamInfo);
const customStreamsEndPromises = waitForCustomStreamsEnd(fileDescriptors, streamInfo);

Expand All @@ -71,12 +71,12 @@ export const waitForSubprocessResult = async ({
waitForSuccessfulExit(exitPromise),
Promise.all(stdioPromises),
allPromise,
waitForIpcMessages({
waitForIpcOutput({
subprocess,
buffer,
maxBuffer,
ipc,
ipcMessages,
ipcOutput,
verboseInfo,
}),
sendIpcInput(subprocess, ipcInput),
Expand All @@ -93,7 +93,7 @@ export const waitForSubprocessResult = async ({
exitPromise,
Promise.all(stdioPromises.map(stdioPromise => getBufferedData(stdioPromise))),
getBufferedData(allPromise),
ipcMessages,
ipcOutput,
Promise.allSettled(originalPromises),
Promise.allSettled(customStreamsEndPromises),
]);
Expand Down
4 changes: 2 additions & 2 deletions lib/return/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {DiscardedError, isExecaError} from './final-error.js';
export const createMessages = ({
stdio,
all,
ipcMessages,
ipcOutput,
originalError,
signal,
signalDescription,
Expand Down Expand Up @@ -44,7 +44,7 @@ export const createMessages = ({
shortMessage,
...messageStdio,
...stdio.slice(3),
ipcMessages.map(ipcMessage => serializeIpcMessage(ipcMessage)).join('\n'),
ipcOutput.map(ipcMessage => serializeIpcMessage(ipcMessage)).join('\n'),
]
.map(messagePart => escapeLines(stripFinalNewline(serializeMessagePart(messagePart))))
.filter(Boolean)
Expand Down
16 changes: 8 additions & 8 deletions lib/return/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const makeSuccessResult = ({
escapedCommand,
stdio,
all,
ipcMessages,
ipcOutput,
options: {cwd},
startTime,
}) => omitUndefinedProperties({
Expand All @@ -27,7 +27,7 @@ export const makeSuccessResult = ({
stderr: stdio[2],
all,
stdio,
ipc: ipcMessages,
ipcOutput,
pipedFrom: [],
});

Expand All @@ -49,7 +49,7 @@ export const makeEarlyError = ({
isCanceled: false,
isMaxBuffer: false,
stdio: Array.from({length: fileDescriptors.length}),
ipcMessages: [],
ipcOutput: [],
options,
isSync,
});
Expand All @@ -67,15 +67,15 @@ export const makeError = ({
signal: rawSignal,
stdio,
all,
ipcMessages,
ipcOutput,
options: {timeoutDuration, timeout = timeoutDuration, cwd, maxBuffer},
isSync,
}) => {
const {exitCode, signal, signalDescription} = normalizeExitPayload(rawExitCode, rawSignal);
const {originalMessage, shortMessage, message} = createMessages({
stdio,
all,
ipcMessages,
ipcOutput,
originalError,
signal,
signalDescription,
Expand All @@ -102,7 +102,7 @@ export const makeError = ({
signalDescription,
stdio,
all,
ipcMessages,
ipcOutput,
cwd,
originalMessage,
shortMessage,
Expand All @@ -123,7 +123,7 @@ const getErrorProperties = ({
signalDescription,
stdio,
all,
ipcMessages,
ipcOutput,
cwd,
originalMessage,
shortMessage,
Expand All @@ -147,7 +147,7 @@ const getErrorProperties = ({
stderr: stdio[2],
all,
stdio,
ipc: ipcMessages,
ipcOutput,
pipedFrom: [],
});

Expand Down
2 changes: 1 addition & 1 deletion lib/verbose/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import {verboseLog, serializeLogMessage} from './log.js';
// When `verbose` is `'full'`, print IPC messages from the subprocess
export const shouldLogIpc = ({verbose}) => verbose.at(-1) === 'full';

export const logIpcMessage = (message, {verboseId}) => {
export const logIpcOutput = (message, {verboseId}) => {
verboseLog(serializeLogMessage(message), verboseId, 'ipc');
};
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ const ipcInput = await getOneMessage();
// main.js
import {execaNode} from 'execa';

const {ipc} = await execaNode`build.js`;
console.log(ipc[0]); // {kind: 'start', timestamp: date}
console.log(ipc[1]); // {kind: 'stop', timestamp: date}
const {ipcOutput} = await execaNode`build.js`;
console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}
console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}
```

```js
Expand Down
Loading

0 comments on commit ae9b360

Please sign in to comment.