command.js
This file
Path
lib/command.js
39 lines · 1.2 KiB · JavaScript
Last changed by
Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
History of this fileTake it
The walk stopped after 200 commits: lines older than e7dee28 point at it.
Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
line 1why, one step back1import isPlainObj from 'is-plain-obj';Split files (#837)ehmickybefore adoption672c2d7
lines 2–3why, one step back2import {execa} from './async.js';3import {execaSync} from './sync.js';8.0.0ehmickybefore adoptione7dee28
line 4why, one step back4Split files (#837)ehmickybefore adoption672c2d7
line 5why, one step back5export function execaCommand(command, options) {Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
line 6why, one step back6 const [file, ...args] = parseCommand(command, options);Split files (#837)ehmickybefore adoption672c2d7
lines 7–10why, one step back7 return execa(file, args, options);8}910export function execaCommandSync(command, options) {Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
line 11why, one step back11 const [file, ...args] = parseCommand(command, options);Split files (#837)ehmickybefore adoption672c2d7
lines 12–14why, one step back12 return execaSync(file, args, options);13}14Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
line 15why, one step back15const parseCommand = (command, options) => {Improve input validation (#838)ehmickybefore adoption8ee137c
lines 16–17why, one step back16 if (typeof command !== 'string') {17 throw new TypeError(`First argument must be a string: ${command}.`);Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
lines 18–21why, one step back18 }1920 if (options !== undefined && !isPlainObj(options)) {21 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${options}.`);Improve input validation (#838)ehmickybefore adoption8ee137c
lines 22–23why, one step back22 }238.0.0ehmickybefore adoptione7dee28
lines 24–37why, one step back24 const tokens = [];25 for (const token of command.trim().split(SPACES_REGEXP)) {26 // Allow spaces to be escaped by a backslash if not meant as a delimiter27 const previousToken = tokens.at(-1);28 if (previousToken && previousToken.endsWith('\\')) {29 // Merge previous token with current one30 tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;31 } else {32 tokens.push(token);33 }34 }3536 return tokens;37};Split files (#837)ehmickybefore adoption672c2d7
lines 38–39why, one step back3839const SPACES_REGEXP = / +/g;