Skip to content
Myr

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 file

Take it

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

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

line 1why, one step back
1import isPlainObj from 'is-plain-obj';

Split files (#837)ehmickybefore adoption672c2d7

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

Fix `stdio` option (#634)ehmickybefore adoption640ae39

line 4why, one step back
4

Split files (#837)ehmickybefore adoption672c2d7

line 5why, one step back
5export function execaCommand(command, options) {

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

line 6why, one step back
6 const [file, ...args] = parseCommand(command, options);

Split files (#837)ehmickybefore adoption672c2d7

lines 7–10why, one step back
7 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 back
11 const [file, ...args] = parseCommand(command, options);

Split files (#837)ehmickybefore adoption672c2d7

lines 12–14why, one step back
12 return execaSync(file, args, options);
13}14

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

line 15why, one step back
15const parseCommand = (command, options) => {

Improve input validation (#838)ehmickybefore adoption8ee137c

lines 16–17why, one step back
16 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 back
18 }
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 back
22 }
23

Fix `stdio` option (#634)ehmickybefore adoption640ae39

lines 24–37why, one step back
24 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 back
38
39const SPACES_REGEXP = / +/g;