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 fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–4why, one step back1import {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 back5import {normalizeForceKillAfterDelay} from '../terminate/kill.js';Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 6why, one step back6import {normalizeKillSignal} from '../terminate/signal.js';Rename files (#977)ehmickybefore adoption4b2e316
lines 7–9why, one step back7import {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 back10import {normalizeCwd} from './cwd.js';11import {normalizeFileUrl} from './file-url.js';12import {normalizeFdSpecificOptions} from './specific.js';Split files (#837)ehmickybefore adoption672c2d7
line 13why, one step back13Add more code comments (#984)ehmickybefore adoptionfdd8a9f
lines 14–15why, one step back14// 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 back16export const normalizeOptions = (filePath, rawArguments, rawOptions) => {Split files (#837)ehmickybefore adoption672c2d7
line 17why, one step back17 rawOptions.cwd = normalizeCwd(rawOptions.cwd);Upgrade xo (#980)ehmickybefore adoptionccfa412
line 18why, one step back18 const [processedFile, processedArguments, processedOptions] = handleNodeOption(filePath, rawArguments, rawOptions);Split files (#837)ehmickybefore adoption672c2d7
line 19why, one step back19Upgrade xo (#980)ehmickybefore adoptionccfa412
line 20why, one step back20 const {command: file, args: commandArguments, options: initialOptions} = crossSpawn._parse(processedFile, processedArguments, processedOptions);Split files (#837)ehmickybefore adoption672c2d7
line 21why, one step back21Allow setting different `maxBuffer` values for `stdout`/`stderr` (#966)ehmickybefore adoptionfdffcb6
lines 22–23why, one step back22 const fdOptions = normalizeFdSpecificOptions(initialOptions);23 const options = addDefaultOptions(fdOptions);Split files (#837)ehmickybefore adoption672c2d7
line 24why, one step back24 validateTimeout(options);Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4
line 25why, one step back25 validateEncoding(options);Split files (#837)ehmickybefore adoption672c2d7
lines 26–27why, one step back26 options.shell = normalizeFileUrl(options.shell);27 options.env = getEnv(options);Improve validation and typing of signals (#1025)ehmickybefore adoption7213287
line 28why, one step back28 options.killSignal = normalizeKillSignal(options.killSignal);Split files (#837)ehmickybefore adoption672c2d7
line 29why, one step back29 options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);Allow setting different `buffer` values for `stdout`/`stderr` (#973)ehmickybefore adoptiona25a50d
line 30why, one step back30 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 back3132 if (process.platform === 'win32' && basename(file, '.exe') === 'cmd') {33 // #116Upgrade xo (#980)ehmickybefore adoptionccfa412
line 34why, one step back34 commandArguments.unshift('/q');Split files (#837)ehmickybefore adoption672c2d7
lines 35–36why, one step back35 }36Upgrade xo (#980)ehmickybefore adoptionccfa412
line 37why, one step back37 return {file, commandArguments, options};Split files (#837)ehmickybefore adoption672c2d7
lines 38–43why, one step back38};3940const addDefaultOptions = ({41 extendEnv = true,42 preferLocal = false,43 cwd,Upgrade xo (#980)ehmickybefore adoptionccfa412
line 44why, one step back44 localDir: localDirectory = cwd,Split files (#837)ehmickybefore adoption672c2d7
lines 45–52why, one step back45 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 back53 serialization = 'advanced',Split files (#837)ehmickybefore adoption672c2d7
lines 54–59why, one step back54 ...options55}) => ({56 ...options,57 extendEnv,58 preferLocal,59 cwd,Upgrade xo (#980)ehmickybefore adoptionccfa412
line 60why, one step back60 localDirectory,Split files (#837)ehmickybefore adoption672c2d7
lines 61–68why, one step back61 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 back69 serialization,Split files (#837)ehmickybefore adoption672c2d7
lines 70–71why, one step back70});71Upgrade xo (#980)ehmickybefore adoptionccfa412
line 72why, one step back72const getEnv = ({env: envOption, extendEnv, preferLocal, node, localDirectory, nodePath}) => {Split files (#837)ehmickybefore adoption672c2d7
lines 73–74why, one step back73 const env = extendEnv ? {...process.env, ...envOption} : envOption;74Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682
line 75why, one step back75 if (preferLocal || node) {Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 76–82why, one step back76 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 back83 }8485 return env;86};