From 0595f9fbc6b43a5c5dbff388bf8124297d3f40ef Mon Sep 17 00:00:00 2001 From: ehmicky Date: Mon, 13 May 2019 14:15:38 +0200 Subject: [PATCH 1/2] Reorder properties of results and errors --- index.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 3e96202fb..c0c1dd606 100644 --- a/index.js +++ b/index.js @@ -181,24 +181,25 @@ function makeError(result, options) { error = new Error(message); } - error.code = exitCode || exitCodeName; + error.command = joinedCommand; error.exitCode = exitCode; error.exitCodeName = exitCodeName; + error.code = exitCode || exitCodeName; error.stdout = stdout; error.stderr = stderr; - error.failed = true; - // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize - // it to `undefined` - error.signal = signal || undefined; - error.command = joinedCommand; - error.timedOut = timedOut; - error.isCanceled = isCanceled; - error.killed = killed && !timedOut; if ('all' in result) { error.all = result.all; } + error.failed = true; + error.timedOut = timedOut; + error.isCanceled = isCanceled; + error.killed = killed && !timedOut; + // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize + // it to `undefined` + error.signal = signal || undefined; + return error; } @@ -372,17 +373,17 @@ const execa = (command, args, options) => { } return { + command: joinedCommand, + exitCode: 0, + exitCodeName: 'SUCCESS', + code: 0, stdout: result.stdout, stderr: result.stderr, all: result.all, - code: 0, - exitCode: 0, - exitCodeName: 'SUCCESS', failed: false, - killed: false, - command: joinedCommand, timedOut: false, - isCanceled: false + isCanceled: false, + killed: false }; }; @@ -444,15 +445,15 @@ module.exports.sync = (command, args, options) => { } return { - stdout: result.stdout, - stderr: result.stderr, - code: 0, + command: joinedCommand, exitCode: 0, exitCodeName: 'SUCCESS', + code: 0, + stdout: result.stdout, + stderr: result.stderr, failed: false, - killed: false, - command: joinedCommand, timedOut: false, - isCanceled: false + isCanceled: false, + killed: false }; }; From e5681a18a68468dcf3e0f4f1f0a2c520f89d3544 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 15:47:43 +0200 Subject: [PATCH 2/2] Reorder properties in documentation too --- index.d.ts | 20 ++++++++--------- index.test-d.ts | 14 ++++++------ readme.md | 57 ++++++++++++++++++++++++++++++------------------- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/index.d.ts b/index.d.ts index a6a1976cb..054c097d8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -194,6 +194,11 @@ declare namespace execa { } interface ExecaReturnBase { + /** + The command that was run. + */ + command: string; + /** The numeric exit code of the process that was run. */ @@ -219,16 +224,6 @@ declare namespace execa { */ failed: boolean; - /** - The signal that was used to terminate the process. - */ - signal?: string; - - /** - The command that was run. - */ - command: string; - /** Whether the process timed out. */ @@ -238,6 +233,11 @@ declare namespace execa { Whether the process was killed. */ killed: boolean; + + /** + The signal that was used to terminate the process. + */ + signal?: string; } interface ExecaSyncReturnValue diff --git a/index.test-d.ts b/index.test-d.ts index 4f9453660..a6c95f654 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -15,14 +15,14 @@ try { const unicornsResult = await execaPromise; expectType(unicornsResult.command); expectType(unicornsResult.code); - expectType(unicornsResult.failed); - expectType(unicornsResult.killed); - expectType(unicornsResult.signal); expectType(unicornsResult.stderr); expectType(unicornsResult.stdout); expectType(unicornsResult.all); + expectType(unicornsResult.failed); expectType(unicornsResult.timedOut); expectType(unicornsResult.isCanceled); + expectType(unicornsResult.killed); + expectType(unicornsResult.signal); } catch (error) { const execaError: ExecaError = error; @@ -36,14 +36,14 @@ try { const unicornsResult = execa.sync('unicorns'); expectType(unicornsResult.command); expectType(unicornsResult.code); - expectType(unicornsResult.failed); - expectType(unicornsResult.killed); - expectType(unicornsResult.signal); expectType(unicornsResult.stderr); expectType(unicornsResult.stdout); - expectType(unicornsResult.timedOut); expectError(unicornsResult.all); + expectType(unicornsResult.failed); + expectType(unicornsResult.timedOut); expectError(unicornsResult.isCanceled); + expectType(unicornsResult.killed); + expectType(unicornsResult.signal); } catch (error) { const execaError: ExecaSyncError = error; diff --git a/readme.md b/readme.md index f7be04537..d735f0143 100644 --- a/readme.md +++ b/readme.md @@ -60,18 +60,22 @@ const execa = require('execa'); console.log(error); /* { - message: 'spawn wrong command ENOENT', + message: 'Command failed with exit code 2 (ENOENT): wrong command spawn wrong ENOENT', errno: 'ENOENT', - code: 'ENOENT', - syscall: 'spawn wrong command', - path: 'wrong command', - killed: false, + code: 2, + syscall: 'spawn wrong', + path: 'wrong', + spawnargs: ['command'], + command: 'wrong command', + exitCode: 2, + exitCodeName: 'ENOENT', stdout: '', stderr: '', + all: '', failed: true, - signal: null, - cmd: 'wrong command', - timedOut: false + timedOut: false, + isCanceled: false, + killed: false } */ } @@ -96,11 +100,20 @@ try { console.log(error); /* { - message: 'spawnSync wrong command ENOENT', + message: 'Command failed with exit code 2 (ENOENT): wrong command spawnSync wrong ENOENT', errno: 'ENOENT', - code: 'ENOENT', - syscall: 'spawnSync wrong command', - path: 'wrong command', + code: 2, + syscall: 'spawnSync wrong', + path: 'wrong', + spawnargs: ['command'], + command: 'wrong command', + exitCode: 2, + exitCodeName: 'ENOENT', + stdout: null, + stderr: null, + failed: true, + timedOut: false, + isCanceled: false } */ } @@ -147,6 +160,12 @@ Type: `object` Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance. +#### command + +Type: `string` + +The command that was run. + #### exitCode Type: `number` @@ -177,12 +196,6 @@ Type: `string | Buffer` The output of the process on both stdout and stderr. `undefined` if `execa.sync()` was used. -#### command - -Type: `string` - -The command that was run. - #### failed Type: `boolean` @@ -195,17 +208,17 @@ Type: `boolean` Whether the process timed out. -#### killed +#### isCanceled Type: `boolean` -Whether the process was killed. +Whether the process was canceled. -#### isCanceled +#### killed Type: `boolean` -Whether the process was canceled. +Whether the process was killed. #### signal