Skip to content
Myr

command.js

This file

Path

lib/command.js

25 lines · 866 bytes · JavaScript

Last changed by

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

History of this file

Take it

The walk stopped after 200 commits: lines older than 7122767 point at it.

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 1–2why, one step back
1export const mapCommandAsync = ({file, args}) => parseCommand(file, args);
2export const mapCommandSync = ({file, args}) => ({...parseCommand(file, args), isSync: true});

Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767

line 3why, one step back
3

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

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

Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6

lines 7–8why, one step back
7 }
8

Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767

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

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 21–22why, one step back
21 const [file, ...args] = tokens;
22 return {file, args};

Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767

line 23why, one step back
23};

Split files (#837)ehmickybefore adoption672c2d7

lines 24–25why, one step back
24
25const SPACES_REGEXP = / +/g;