Skip to content
Myr

command.js

This file

Path

lib/command.js

30 lines · 843 bytes · JavaScript

Last changed by

Split files (#837)ehmickybefore adoption672c2d7

History of this file

Take it

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

Split files (#837)ehmickybefore adoption672c2d7

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

Meta tweaksSindre Sorhusbefore adoption09df476

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 => {

Meta tweaksSindre Sorhusbefore adoption09df476

lines 15–17why, one step back
15 const tokens = [];
16 for (const token of command.trim().split(SPACES_REGEXP)) {17 // Allow spaces to be escaped by a backslash if not meant as a delimiter

Require Node.js 16 (#569)ehmickybefore adoption65992b4

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

Meta tweaksSindre Sorhusbefore adoption09df476

lines 19–28why, one step back
19 if (previousToken && previousToken.endsWith('\\')) {
20 // Merge previous token with current one21 tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;22 } else {23 tokens.push(token);24 }25 }2627 return tokens;28};

Split files (#837)ehmickybefore adoption672c2d7

lines 29–30why, one step back
29
30const SPACES_REGEXP = / +/g;