options.js
This file
Path
lib/arguments/options.js
123 lines · 3.7 KiB · JavaScript
Last changed by
Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
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';Improve input validation (#838)ehmickybefore adoption8ee137c
line 5why, one step back5import isPlainObject from 'is-plain-obj';Split files (#837)ehmickybefore adoption672c2d7
lines 6–7why, one step back6import {normalizeForceKillAfterDelay} from '../exit/kill.js';7import {validateTimeout} from '../exit/timeout.js';Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 8why, one step back8import {logCommand} from '../verbose/start.js';Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
line 9why, one step back9import {getVerboseInfo} from '../verbose/info.js';Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 10why, one step back10import {getStartTime} from '../return/duration.js';Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
line 11why, one step back11import {validateEncoding, BINARY_ENCODINGS} from './encoding.js';Split files (#837)ehmickybefore adoption672c2d7
lines 12–15why, one step back12import {handleNodeOption} from './node.js';13import {joinCommand} from './escape.js';14import {normalizeCwd, safeNormalizeFileUrl, normalizeFileUrl} from './cwd.js';15Improve input validation (#838)ehmickybefore adoption8ee137c
line 16why, one step back16export const normalizeArguments = (rawFile, rawArgs = [], rawOptions = {}) => {Split files (#837)ehmickybefore adoption672c2d7
line 17why, one step back17 const filePath = safeNormalizeFileUrl(rawFile, 'First argument');Improve input validation (#838)ehmickybefore adoption8ee137c
lines 18–25why, one step back18 const [args, options] = isPlainObject(rawArgs)19 ? [[], rawArgs]20 : [rawArgs, rawOptions];2122 if (!Array.isArray(args)) {23 throw new TypeError(`Second argument must be either an array of arguments or an options object: ${args}`);24 }25Improve process arguments validation (#873)ehmickybefore adoption54b5ea7
lines 26–35why, one step back26 if (args.some(arg => typeof arg === 'object' && arg !== null)) {27 throw new TypeError(`Second argument must be an array of strings: ${args}`);28 }2930 const normalizedArgs = args.map(String);31 const nullByteArg = normalizedArgs.find(arg => arg.includes('\0'));32 if (nullByteArg !== undefined) {33 throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${nullByteArg}`);34 }35Improve input validation (#838)ehmickybefore adoption8ee137c
lines 36–39why, one step back36 if (!isPlainObject(options)) {37 throw new TypeError(`Last argument must be an options object: ${options}`);38 }39Improve process arguments validation (#873)ehmickybefore adoption54b5ea7
line 40why, one step back40 return [filePath, normalizedArgs, options];Improve input validation (#838)ehmickybefore adoption8ee137c
lines 41–42why, one step back41};42Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 43why, one step back43export const handleCommand = (filePath, rawArgs, rawOptions) => {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 44why, one step back44 const startTime = getStartTime();Split files (#837)ehmickybefore adoption672c2d7
line 45why, one step back45 const {command, escapedCommand} = joinCommand(filePath, rawArgs);Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
lines 46–47why, one step back46 const verboseInfo = getVerboseInfo(rawOptions);47 logCommand(escapedCommand, verboseInfo, rawOptions);Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 48why, one step back48 return {command, escapedCommand, startTime, verboseInfo};Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 49why, one step back49};Split files (#837)ehmickybefore adoption672c2d7
line 50why, one step back50Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 51why, one step back51export const handleArguments = (filePath, rawArgs, rawOptions) => {Split files (#837)ehmickybefore adoption672c2d7
lines 52–58why, one step back52 rawOptions.cwd = normalizeCwd(rawOptions.cwd);53 const [processedFile, processedArgs, processedOptions] = handleNodeOption(filePath, rawArgs, rawOptions);5455 const {command: file, args, options: initialOptions} = crossSpawn._parse(processedFile, processedArgs, processedOptions);5657 const options = addDefaultOptions(initialOptions);58 validateTimeout(options);Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4
line 59why, one step back59 validateEncoding(options);Split files (#837)ehmickybefore adoption672c2d7
lines 60–62why, one step back60 options.shell = normalizeFileUrl(options.shell);61 options.env = getEnv(options);62 options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);Simplify `lines` option (#929)ehmickybefore adoptiond30fcbc
line 63why, one step back63 options.lines &&= !BINARY_ENCODINGS.has(options.encoding) && options.buffer;Split files (#837)ehmickybefore adoption672c2d7
lines 64–69why, one step back6465 if (process.platform === 'win32' && basename(file, '.exe') === 'cmd') {66 // #11667 args.unshift('/q');68 }69Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 70why, one step back70 return {file, args, options};Split files (#837)ehmickybefore adoption672c2d7
lines 71–89why, one step back71};7273const addDefaultOptions = ({74 maxBuffer = DEFAULT_MAX_BUFFER,75 buffer = true,76 stripFinalNewline = true,77 extendEnv = true,78 preferLocal = false,79 cwd,80 localDir = cwd,81 encoding = 'utf8',82 reject = true,83 cleanup = true,84 all = false,85 windowsHide = true,86 killSignal = 'SIGTERM',87 forceKillAfterDelay = true,88 lines = false,89 ipc = false,Change default value of `serialization` option to `advanced` (#905)ehmickybefore adoption4577582
line 90why, one step back90 serialization = 'advanced',Split files (#837)ehmickybefore adoption672c2d7
lines 91–109why, one step back91 ...options92}) => ({93 ...options,94 maxBuffer,95 buffer,96 stripFinalNewline,97 extendEnv,98 preferLocal,99 cwd,100 localDir,101 encoding,102 reject,103 cleanup,104 all,105 windowsHide,106 killSignal,107 forceKillAfterDelay,108 lines,109 ipc,Change default value of `serialization` option to `advanced` (#905)ehmickybefore adoption4577582
line 110why, one step back110 serialization,Split files (#837)ehmickybefore adoption672c2d7
lines 111–114why, one step back111});112113const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;114Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682
line 115why, one step back115const getEnv = ({env: envOption, extendEnv, preferLocal, node, localDir, nodePath}) => {Split files (#837)ehmickybefore adoption672c2d7
lines 116–117why, one step back116 const env = extendEnv ? {...process.env, ...envOption} : envOption;117Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682
lines 118–119why, one step back118 if (preferLocal || node) {119 return npmRunPathEnv({env, cwd: localDir, execPath: nodePath, preferLocal, addExecPath: node});Split files (#837)ehmickybefore adoption672c2d7
lines 120–123why, one step back120 }121122 return env;123};