execa
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -255,3 +255,5 @@ /// <reference types="node"/> | ||
/** | ||
The file and arguments that were run. | ||
The file and arguments that were run, for logging purposes. | ||
This is not escaped and should not be executed directly as a process, including using `execa()` or `execa.command()`. | ||
*/ | ||
@@ -261,2 +263,10 @@ command: string; | ||
/** | ||
Same as `command` but escaped. | ||
This is meant to be copy and pasted into a shell, for debugging purposes. | ||
Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execa.command()`. | ||
*/ | ||
escapedCommand: string; | ||
/** | ||
The numeric exit code of the process that was run. | ||
@@ -263,0 +273,0 @@ */ |
10
index.js
@@ -13,3 +13,3 @@ 'use strict'; | ||
const {mergePromise, getSpawnedPromise} = require('./lib/promise'); | ||
const {joinCommand, parseCommand} = require('./lib/command'); | ||
const {joinCommand, parseCommand, getEscapedCommand} = require('./lib/command'); | ||
@@ -78,2 +78,3 @@ const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100; | ||
const command = joinCommand(file, args); | ||
const escapedCommand = getEscapedCommand(file, args); | ||
@@ -94,2 +95,3 @@ validateTimeout(parsed.options); | ||
command, | ||
escapedCommand, | ||
parsed, | ||
@@ -127,2 +129,3 @@ timedOut: false, | ||
command, | ||
escapedCommand, | ||
parsed, | ||
@@ -143,2 +146,3 @@ timedOut, | ||
command, | ||
escapedCommand, | ||
exitCode: 0, | ||
@@ -169,2 +173,3 @@ stdout, | ||
const command = joinCommand(file, args); | ||
const escapedCommand = getEscapedCommand(file, args); | ||
@@ -183,2 +188,3 @@ validateInputSync(parsed.options); | ||
command, | ||
escapedCommand, | ||
parsed, | ||
@@ -202,2 +208,3 @@ timedOut: false, | ||
command, | ||
escapedCommand, | ||
parsed, | ||
@@ -218,2 +225,3 @@ timedOut: result.error && result.error.code === 'ETIMEDOUT', | ||
command, | ||
escapedCommand, | ||
exitCode: 0, | ||
@@ -220,0 +228,0 @@ stdout, |
'use strict'; | ||
const SPACES_REGEXP = / +/g; | ||
const joinCommand = (file, args = []) => { | ||
const normalizeArgs = (file, args = []) => { | ||
if (!Array.isArray(args)) { | ||
return file; | ||
return [file]; | ||
} | ||
return [file, ...args].join(' '); | ||
return [file, ...args]; | ||
}; | ||
const NO_ESCAPE_REGEXP = /^[\w.-]+$/; | ||
const DOUBLE_QUOTES_REGEXP = /"/g; | ||
const escapeArg = arg => { | ||
if (NO_ESCAPE_REGEXP.test(arg)) { | ||
return arg; | ||
} | ||
return `"${arg.replace(DOUBLE_QUOTES_REGEXP, '\\"')}"`; | ||
}; | ||
const joinCommand = (file, args) => { | ||
return normalizeArgs(file, args).join(' '); | ||
}; | ||
const getEscapedCommand = (file, args) => { | ||
return normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' '); | ||
}; | ||
const SPACES_REGEXP = / +/g; | ||
// Handle `execa.command()` | ||
@@ -31,3 +50,4 @@ const parseCommand = command => { | ||
joinCommand, | ||
getEscapedCommand, | ||
parseCommand | ||
}; |
@@ -36,2 +36,3 @@ 'use strict'; | ||
command, | ||
escapedCommand, | ||
timedOut, | ||
@@ -65,2 +66,3 @@ isCanceled, | ||
error.command = command; | ||
error.escapedCommand = escapedCommand; | ||
error.exitCode = exitCode; | ||
@@ -67,0 +69,0 @@ error.signal = signal; |
{ | ||
"name": "execa", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "Process execution for humans", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -71,2 +71,3 @@ <img src="media/logo.svg" width="400"> | ||
command: 'unknown command', | ||
escapedCommand: 'unknown command', | ||
stdout: '', | ||
@@ -125,2 +126,3 @@ stderr: '', | ||
command: 'unknown command', | ||
escapedCommand: 'unknown command', | ||
stdout: '', | ||
@@ -239,4 +241,15 @@ stderr: '', | ||
The file and arguments that were run. | ||
The file and arguments that were run, for logging purposes. | ||
This is not escaped and should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execa.command()`](#execacommandcommand-options). | ||
#### escapedCommand | ||
Type: `string` | ||
Same as [`command`](#command) but escaped. | ||
This is meant to be copy and pasted into a shell, for debugging purposes. | ||
Since the escaping is fairly basic, this should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execa.command()`](#execacommandcommand-options). | ||
#### exitCode | ||
@@ -243,0 +256,0 @@ |
57498
1023
664