Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default value of serialization option to advanced #905

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ type CommonOptions<IsSync extends boolean = boolean> = {

[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization)

@default 'json'
@default 'advanced'
*/
readonly serialization?: IfAsync<IsSync, 'json' | 'advanced'>;

Expand Down
2 changes: 2 additions & 0 deletions lib/arguments/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const addDefaultOptions = ({
forceKillAfterDelay = true,
lines = false,
ipc = false,
serialization = 'advanced',
...options
}) => ({
...options,
Expand All @@ -103,6 +104,7 @@ const addDefaultOptions = ({
forceKillAfterDelay,
lines,
ipc,
serialization,
});

const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ Enables exchanging messages with the subprocess using [`subprocess.send(value)`]
#### serialization

Type: `string`\
Default: `'json'`
Default: `'advanced'`

Specify the kind of serialization used for sending messages between subprocesses when using the [`ipc`](#ipc) option:
- `json`: Uses `JSON.stringify()` and `JSON.parse()`.
Expand Down
20 changes: 20 additions & 0 deletions test/arguments/node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {once} from 'node:events';
import {dirname, relative} from 'node:path';
import process from 'node:process';
import {pathToFileURL} from 'node:url';
Expand Down Expand Up @@ -256,3 +257,22 @@ const testNoShell = async (t, execaMethod) => {
test('Cannot use "shell: true" - execaNode()', testNoShell, execaNode);
test('Cannot use "shell: true" - "node" option', testNoShell, runWithNodeOption);
test('Cannot use "shell: true" - "node" option sync', testNoShell, runWithNodeOptionSync);

test('The "serialization" option defaults to "advanced"', async t => {
const subprocess = execa('node', ['ipc-echo.js'], {ipc: true});
subprocess.send([0n]);
const [message] = await once(subprocess, 'message');
t.is(message[0], 0n);
await subprocess;
});

test('The "serialization" option can be set to "json"', async t => {
const subprocess = execa('node', ['ipc-echo.js'], {ipc: true, serialization: 'json'});
t.throws(() => {
subprocess.send([0n]);
}, {message: /serialize a BigInt/});
subprocess.send(0);
const [message] = await once(subprocess, 'message');
t.is(message, 0);
await subprocess;
});
6 changes: 6 additions & 0 deletions test/fixtures/ipc-echo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
import process from 'node:process';

process.once('message', message => {
process.send(message);
});