sync.js
This file
Path
lib/stdio/sync.js
102 lines · 3.0 KiB · JavaScript
Last changed by
Do not allow `overlapped` with `execaSync()` (#949)ehmickybefore adoption7c2f575
History of this fileTake it
The walk stopped after 200 commits: lines older than 76ff50b point at it.
Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
line 1why, one step back1import {readFileSync} from 'node:fs';Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 2why, one step back2import {isStream as isNodeStream} from 'is-stream';Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
line 3why, one step back3import {bufferToUint8Array} from './uint-array.js';Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b
lines 4–6why, one step back4import {handleInput} from './handle.js';5import {TYPE_TO_MESSAGE} from './type.js';6Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
line 7why, one step back7// Normalize `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync modePrint output with `verbose` option (#884)ehmickybefore adoption6fda30f
line 8why, one step back8export const handleInputSync = (options, verboseInfo) => {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 9why, one step back9 const {fileDescriptors} = handleInput(addPropertiesSync, options, verboseInfo, true);Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 10why, one step back10 validateStdioArraysSync(fileDescriptors);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 11why, one step back11 return fileDescriptors;Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b
lines 12–14why, one step back12};1314const forbiddenIfSync = ({type, optionName}) => {Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
line 15why, one step back15 throwInvalidSyncValue(optionName, TYPE_TO_MESSAGE[type]);Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b
lines 16–17why, one step back16};17Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
line 18why, one step back18const forbiddenNativeIfSync = ({optionName, value}) => {Do not allow `overlapped` with `execaSync()` (#949)ehmickybefore adoption7c2f575
line 19why, one step back19 if (value === 'ipc' || value === 'overlapped') {Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
lines 20–26why, one step back20 throwInvalidSyncValue(optionName, `"${value}"`);21 }2223 return {};24};2526const throwInvalidSyncValue = (optionName, value) => {Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 27why, one step back27 throw new TypeError(`The \`${optionName}\` option cannot be ${value} with synchronous methods.`);Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
lines 28–29why, one step back28};29Refactor tests (#934)ehmickybefore adoption52c4bde
line 30why, one step back30const addProperties = {Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 31–32why, one step back31 generator() {},32 asyncGenerator: forbiddenIfSync,Refactor tests (#934)ehmickybefore adoption52c4bde
lines 33–34why, one step back33 webStream: forbiddenIfSync,34 nodeStream: forbiddenIfSync,Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6
line 35why, one step back35 webTransform: forbiddenIfSync,Add support for `std*: duplex` option (#937)ehmickybefore adoption6ca44fb
line 36why, one step back36 duplex: forbiddenIfSync,Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
line 37why, one step back37 asyncIterable: forbiddenIfSync,Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
line 38why, one step back38 native: forbiddenNativeIfSync,Refactor tests (#934)ehmickybefore adoption52c4bde
lines 39–40why, one step back39};40Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b
lines 41–42why, one step back41const addPropertiesSync = {42 input: {Refactor tests (#934)ehmickybefore adoption52c4bde
line 43why, one step back43 ...addProperties,Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 44–48why, one step back44 fileUrl: ({value}) => ({contents: [bufferToUint8Array(readFileSync(value))]}),45 filePath: ({value: {file}}) => ({contents: [bufferToUint8Array(readFileSync(file))]}),46 iterable: ({value}) => ({contents: [...value]}),47 string: ({value}) => ({contents: [value]}),48 uint8Array: ({value}) => ({contents: [value]}),Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b
lines 49–50why, one step back49 },50 output: {Refactor tests (#934)ehmickybefore adoption52c4bde
line 51why, one step back51 ...addProperties,Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 52–53why, one step back52 fileUrl: ({value}) => ({path: value}),53 filePath: ({value: {file}}) => ({path: file}),Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
line 54why, one step back54 iterable: forbiddenIfSync,Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 55why, one step back55 string: forbiddenIfSync,Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4
line 56why, one step back56 uint8Array: forbiddenIfSync,Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b
lines 57–59why, one step back57 },58};59Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
lines 60–102why, one step back60const validateStdioArraysSync = fileDescriptors => {61 for (const {stdioItems} of fileDescriptors) {62 validateStdioArraySync(stdioItems);63 }64};6566const validateStdioArraySync = stdioItems => {67 if (stdioItems.length === 1) {68 return;69 }7071 const singleValueName = stdioItems.map(stdioItem => getSingleValueSync(stdioItem)).find(Boolean);72 if (singleValueName === undefined) {73 return;74 }7576 const inputOption = stdioItems.find(({optionName}) => OPTION_NAMES.has(optionName));77 if (inputOption !== undefined) {78 throw new TypeError(`The \`${singleValueName}\` and the \`${inputOption.optionName}\` options cannot be both set with synchronous methods.`);79 }8081 throw new TypeError(`The \`${singleValueName}\` option cannot be set as an array of values with synchronous methods.`);82};8384const getSingleValueSync = ({type, value, optionName}) => {85 if (type !== 'native') {86 return;87 }8889 if (value === 'inherit') {90 return `${optionName}: "inherit"`;91 }9293 if (typeof value === 'number') {94 return `${optionName}: ${value}`;95 }9697 if (isNodeStream(value, {checkOpen: false})) {98 return `${optionName}: Stream`;99 }100};101102const OPTION_NAMES = new Set(['input', 'inputFile']);