command.js
This file
Path
lib/command.js
34 lines · 954 bytes · JavaScript
Last changed by
Improve input validation (#838)ehmickybefore adoption8ee137c
History of this fileTake it
The walk stopped after 200 commits: lines older than e7dee28 point at it.
Split files (#837)ehmickybefore adoption672c2d7
lines 1–2why, one step back1import {execa} from './async.js';2import {execaSync} from './sync.js';8.0.0ehmickybefore adoptione7dee28
line 3why, one step back3Split files (#837)ehmickybefore adoption672c2d7
lines 4–14why, one step back4export function execaCommand(command, options) {5 const [file, ...args] = parseCommand(command);6 return execa(file, args, options);7}89export function execaCommandSync(command, options) {10 const [file, ...args] = parseCommand(command);11 return execaSync(file, args, options);12}1314const parseCommand = command => {Improve input validation (#838)ehmickybefore adoption8ee137c
lines 15–18why, one step back15 if (typeof command !== 'string') {16 throw new TypeError(`First argument must be a string: ${command}.`);17 }188.0.0ehmickybefore adoptione7dee28
lines 19–32why, one step back19 const tokens = [];20 for (const token of command.trim().split(SPACES_REGEXP)) {21 // Allow spaces to be escaped by a backslash if not meant as a delimiter22 const previousToken = tokens.at(-1);23 if (previousToken && previousToken.endsWith('\\')) {24 // Merge previous token with current one25 tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;26 } else {27 tokens.push(token);28 }29 }3031 return tokens;32};Split files (#837)ehmickybefore adoption672c2d7
lines 33–34why, one step back3334const SPACES_REGEXP = / +/g;