Skip to content
Myr

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 file

Take 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 back
1import {readFileSync} from 'node:fs';

Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9

line 2why, one step back
2import {isStream as isNodeStream} from 'is-stream';

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

line 3why, one step back
3import {bufferToUint8Array} from './uint-array.js';

Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b

lines 4–6why, one step back
4import {handleInput} from './handle.js';
5import {TYPE_TO_MESSAGE} from './type.js';6

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

line 7why, one step back
7// Normalize `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode

Print output with `verbose` option (#884)ehmickybefore adoption6fda30f

line 8why, one step back
8export const handleInputSync = (options, verboseInfo) => {

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 9why, one step back
9 const {fileDescriptors} = handleInput(addPropertiesSync, options, verboseInfo, true);

Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9

line 10why, one step back
10 validateStdioArraysSync(fileDescriptors);

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 11why, one step back
11 return fileDescriptors;

Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b

lines 12–14why, one step back
12};
1314const forbiddenIfSync = ({type, optionName}) => {

Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1

line 15why, one step back
15 throwInvalidSyncValue(optionName, TYPE_TO_MESSAGE[type]);

Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b

lines 16–17why, one step back
16};
17

Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1

line 18why, one step back
18const forbiddenNativeIfSync = ({optionName, value}) => {

Do not allow `overlapped` with `execaSync()` (#949)ehmickybefore adoption7c2f575

line 19why, one step back
19 if (value === 'ipc' || value === 'overlapped') {

Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1

lines 20–26why, one step back
20 throwInvalidSyncValue(optionName, `"${value}"`);
21 }2223 return {};24};2526const throwInvalidSyncValue = (optionName, value) => {

Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9

line 27why, one step back
27 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 back
28};
29

Refactor tests (#934)ehmickybefore adoption52c4bde

line 30why, one step back
30const addProperties = {

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 31–32why, one step back
31 generator() {},
32 asyncGenerator: forbiddenIfSync,

Refactor tests (#934)ehmickybefore adoption52c4bde

lines 33–34why, one step back
33 webStream: forbiddenIfSync,
34 nodeStream: forbiddenIfSync,

Add support for `std*: TransformStream` option (#938)ehmickybefore adoption45824d6

line 35why, one step back
35 webTransform: forbiddenIfSync,

Add support for `std*: duplex` option (#937)ehmickybefore adoption6ca44fb

line 36why, one step back
36 duplex: forbiddenIfSync,

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

line 37why, one step back
37 asyncIterable: forbiddenIfSync,

Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1

line 38why, one step back
38 native: forbiddenNativeIfSync,

Refactor tests (#934)ehmickybefore adoption52c4bde

lines 39–40why, one step back
39};
40

Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b

lines 41–42why, one step back
41const addPropertiesSync = {
42 input: {

Refactor tests (#934)ehmickybefore adoption52c4bde

line 43why, one step back
43 ...addProperties,

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 44–48why, one step back
44 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 back
49 },
50 output: {

Refactor tests (#934)ehmickybefore adoption52c4bde

line 51why, one step back
51 ...addProperties,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

lines 52–53why, one step back
52 fileUrl: ({value}) => ({path: value}),
53 filePath: ({value: {file}}) => ({path: file}),

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

line 54why, one step back
54 iterable: forbiddenIfSync,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 55why, one step back
55 string: forbiddenIfSync,

Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4

line 56why, one step back
56 uint8Array: forbiddenIfSync,

Refactor `timeout` option to use `async/await` (#650)ehmickybefore adoption76ff50b

lines 57–59why, one step back
57 },
58};59

Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9

lines 60–102why, one step back
60const 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']);