Skip to content
Myr

command.js

This file

Path

lib/methods/command.js

29 lines · 1.1 KiB · JavaScript

Last changed by

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

History of this file

Take it

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 1why, one step back
1// Main logic for `execaCommand()`

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 2why, one step back
2export const mapCommandAsync = ({file, commandArguments}) => parseCommand(file, commandArguments);

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

lines 3–4why, one step back
3
4// Main logic for `execaCommandSync()`

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 5why, one step back
5export const mapCommandSync = ({file, commandArguments}) => ({...parseCommand(file, commandArguments), isSync: true});

Rename files (#977)ehmickybefore adoption4b2e316

line 6why, one step back
6

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 7why, one step back
7// Convert `execaCommand(command)` into `execa(file, ...commandArguments)`

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 8–10why, one step back
8const parseCommand = (command, unusedArguments) => {
9 if (unusedArguments.length > 0) {10 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArguments}.`);

Rename files (#977)ehmickybefore adoption4b2e316

lines 11–24why, one step back
11 }
1213 const tokens = [];14 for (const token of command.trim().split(SPACES_REGEXP)) {15 // Allow spaces to be escaped by a backslash if not meant as a delimiter16 const previousToken = tokens.at(-1);17 if (previousToken && previousToken.endsWith('\\')) {18 // Merge previous token with current one19 tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;20 } else {21 tokens.push(token);22 }23 }24

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 25–26why, one step back
25 const [file, ...commandArguments] = tokens;
26 return {file, commandArguments};

Rename files (#977)ehmickybefore adoption4b2e316

lines 27–29why, one step back
27};
2829const SPACES_REGEXP = / +/g;