ipc-input.js
This file
Path
lib/ipc/ipc-input.js
55 lines · 1.5 KiB · JavaScript
Last changed by
Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
History of this fileTake it
Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
line 1why, one step back1import {serialize} from 'node:v8';Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 2why, one step back2import {sendMessage} from './send.js';Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 3–13why, one step back34// Validate the `ipcInput` option5export const validateIpcInputOption = ({ipcInput, ipc, serialization}) => {6 if (ipcInput === undefined) {7 return;8 }910 if (!ipc) {11 throw new Error('The `ipcInput` option cannot be set unless the `ipc` option is `true`.');12 }13Harden some thingsSindre Sorhusbefore adoption4a0a121
lines 14–15why, one step back14 // An invalid `serialization` option is reported by `node:child_process` when spawning, like when `ipcInput` is not used15 validateIpcInput[serialization]?.(ipcInput);Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 16–21why, one step back16};1718const validateAdvancedInput = ipcInput => {19 try {20 serialize(ipcInput);21 } catch (error) {Improve IPC error messages (#1090)ehmickybefore adoptione6b012a
line 22why, one step back22 throw new Error('The `ipcInput` option is not serializable with a structured clone.', {cause: error});Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 23–27why, one step back23 }24};2526const validateJsonInput = ipcInput => {27 try {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 28–31why, one step back28 // `JSON.stringify()` returns `undefined` instead of throwing for values it cannot represent, such as functions and symbols29 if (JSON.stringify(ipcInput) === undefined) {30 throw new TypeError('The value cannot be represented as JSON.');31 }Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
line 32why, one step back32 } catch (error) {Improve IPC error messages (#1090)ehmickybefore adoptione6b012a
line 33why, one step back33 throw new Error('The `ipcInput` option is not serializable with JSON.', {cause: error});Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 34–37why, one step back34 }35};3637const validateIpcInput = {Harden some thingsSindre Sorhusbefore adoption4a0a121
line 38why, one step back38 __proto__: null,Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 39–43why, one step back39 advanced: validateAdvancedInput,40 json: validateJsonInput,41};4243// When the `ipcInput` option is set, it is sent as an initial IPC message to the subprocessAdd `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 44why, one step back44export const sendIpcInput = async (subprocess, ipcInput, ipc) => {Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 45–48why, one step back45 if (ipcInput === undefined) {46 return;47 }48Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
lines 49–54why, one step back49 await sendMessage({50 anyProcess: subprocess,51 channel: subprocess.channel,52 isSubprocess: false,53 ipc,54 }, ipcInput);Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
line 55why, one step back55};