Skip to content
Myr

options.js

This file

Path

lib/arguments/options.js

86 lines · 2.6 KiB · JavaScript

Last changed by

Improve validation and typing of signals (#1025)ehmickybefore adoption7213287

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–4why, one step back
1import {basename} from 'node:path';
2import process from 'node:process';3import crossSpawn from 'cross-spawn';4import {npmRunPathEnv} from 'npm-run-path';

Rename files (#977)ehmickybefore adoption4b2e316

line 5why, one step back
5import {normalizeForceKillAfterDelay} from '../terminate/kill.js';

Improve validation and typing of signals (#1025)ehmickybefore adoption7213287

line 6why, one step back
6import {normalizeKillSignal} from '../terminate/signal.js';

Rename files (#977)ehmickybefore adoption4b2e316

lines 7–9why, one step back
7import {validateTimeout} from '../terminate/timeout.js';
8import {handleNodeOption} from '../methods/node.js';9import {validateEncoding, BINARY_ENCODINGS} from './encoding-option.js';

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 10–12why, one step back
10import {normalizeCwd} from './cwd.js';
11import {normalizeFileUrl} from './file-url.js';12import {normalizeFdSpecificOptions} from './specific.js';

Split files (#837)ehmickybefore adoption672c2d7

line 13why, one step back
13

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

lines 14–15why, one step back
14// Normalize the options object, and sometimes also the file paths and arguments.
15// Applies default values, validate allowed options, normalize them.

Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478

line 16why, one step back
16export const normalizeOptions = (filePath, rawArguments, rawOptions) => {

Split files (#837)ehmickybefore adoption672c2d7

line 17why, one step back
17 rawOptions.cwd = normalizeCwd(rawOptions.cwd);

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 18why, one step back
18 const [processedFile, processedArguments, processedOptions] = handleNodeOption(filePath, rawArguments, rawOptions);

Split files (#837)ehmickybefore adoption672c2d7

line 19why, one step back
19

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 20why, one step back
20 const {command: file, args: commandArguments, options: initialOptions} = crossSpawn._parse(processedFile, processedArguments, processedOptions);

Split files (#837)ehmickybefore adoption672c2d7

line 21why, one step back
21

Allow setting different `maxBuffer` values for `stdout`/`stderr` (#966)ehmickybefore adoptionfdffcb6

lines 22–23why, one step back
22 const fdOptions = normalizeFdSpecificOptions(initialOptions);
23 const options = addDefaultOptions(fdOptions);

Split files (#837)ehmickybefore adoption672c2d7

line 24why, one step back
24 validateTimeout(options);

Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4

line 25why, one step back
25 validateEncoding(options);

Split files (#837)ehmickybefore adoption672c2d7

lines 26–27why, one step back
26 options.shell = normalizeFileUrl(options.shell);
27 options.env = getEnv(options);

Improve validation and typing of signals (#1025)ehmickybefore adoption7213287

line 28why, one step back
28 options.killSignal = normalizeKillSignal(options.killSignal);

Split files (#837)ehmickybefore adoption672c2d7

line 29why, one step back
29 options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);

Allow setting different `buffer` values for `stdout`/`stderr` (#973)ehmickybefore adoptiona25a50d

line 30why, one step back
30 options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);

Split files (#837)ehmickybefore adoption672c2d7

lines 31–33why, one step back
31
32 if (process.platform === 'win32' && basename(file, '.exe') === 'cmd') {33 // #116

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 34why, one step back
34 commandArguments.unshift('/q');

Split files (#837)ehmickybefore adoption672c2d7

lines 35–36why, one step back
35 }
36

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 37why, one step back
37 return {file, commandArguments, options};

Split files (#837)ehmickybefore adoption672c2d7

lines 38–43why, one step back
38};
3940const addDefaultOptions = ({41 extendEnv = true,42 preferLocal = false,43 cwd,

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 44why, one step back
44 localDir: localDirectory = cwd,

Split files (#837)ehmickybefore adoption672c2d7

lines 45–52why, one step back
45 encoding = 'utf8',
46 reject = true,47 cleanup = true,48 all = false,49 windowsHide = true,50 killSignal = 'SIGTERM',51 forceKillAfterDelay = true,52 ipc = false,

Change default value of `serialization` option to `advanced` (#905)ehmickybefore adoption4577582

line 53why, one step back
53 serialization = 'advanced',

Split files (#837)ehmickybefore adoption672c2d7

lines 54–59why, one step back
54 ...options
55}) => ({56 ...options,57 extendEnv,58 preferLocal,59 cwd,

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 60why, one step back
60 localDirectory,

Split files (#837)ehmickybefore adoption672c2d7

lines 61–68why, one step back
61 encoding,
62 reject,63 cleanup,64 all,65 windowsHide,66 killSignal,67 forceKillAfterDelay,68 ipc,

Change default value of `serialization` option to `advanced` (#905)ehmickybefore adoption4577582

line 69why, one step back
69 serialization,

Split files (#837)ehmickybefore adoption672c2d7

lines 70–71why, one step back
70});
71

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 72why, one step back
72const getEnv = ({env: envOption, extendEnv, preferLocal, node, localDirectory, nodePath}) => {

Split files (#837)ehmickybefore adoption672c2d7

lines 73–74why, one step back
73 const env = extendEnv ? {...process.env, ...envOption} : envOption;
74

Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682

line 75why, one step back
75 if (preferLocal || node) {

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 76–82why, one step back
76 return npmRunPathEnv({
77 env,78 cwd: localDirectory,79 execPath: nodePath,80 preferLocal,81 addExecPath: node,82 });

Split files (#837)ehmickybefore adoption672c2d7

lines 83–86why, one step back
83 }
8485 return env;86};