Skip to content
Myr

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 file

Take it

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

Split files (#837)ehmickybefore adoption672c2d7

lines 1–2why, one step back
1import {execa} from './async.js';
2import {execaSync} from './sync.js';

Improve documentation of the usage section (#541)ehmickybefore adoption5320fef

line 3why, one step back
3

Split files (#837)ehmickybefore adoption672c2d7

lines 4–14why, one step back
4export 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 back
15 if (typeof command !== 'string') {
16 throw new TypeError(`First argument must be a string: ${command}.`);17 }18

Improve documentation of the usage section (#541)ehmickybefore adoption5320fef

lines 19–21why, one step back
19 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 delimiter

Require Node.js 16 (#569)ehmickybefore adoption65992b4

line 22why, one step back
22 const previousToken = tokens.at(-1);

Improve documentation of the usage section (#541)ehmickybefore adoption5320fef

lines 23–32why, one step back
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 back
33
34const SPACES_REGEXP = / +/g;