Reorder properties of results and errors (#241)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 0d39fdf · Browse files · 4 files·+74 added−60 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+74 added−60 removed
- other:+74 added−60 removed
Provenance
- Commit
f488c42- Tree
f0bf69a- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
0d39fdf
4 files changed+74 added−60 removed
modified:index.d.ts+10 added-10 removed
193 unmodified lines194 }195 196 interface ExecaReturnBase<StdoutStderrType> {197 /**198+ The command that was run.199+ */200+ command: string;201+202+ /**203 The numeric exit code of the process that was run.204 */205 exitCode: number;206 17 unmodified lines224 */225 failed: boolean;226 227 /**223- The signal that was used to terminate the process.224- */225- signal?: string;226-227- /**228- The command that was run.229- */230- command: string;231-232- /**228 Whether the process timed out.229 */230 timedOut: boolean;231 232 /**233 Whether the process was killed.234 */235 killed: boolean;236+237+ /**238+ The signal that was used to terminate the process.239+ */240+ signal?: string;241 }242 243 interface ExecaSyncReturnValue<StdoutErrorType = string>244 extends ExecaReturnBase<StdoutErrorType> {138 unmodified linesmodified:index.js+22 added-21 removed
179 unmodified lines180 } else {181 error = new Error(message);182 }183 184- error.code = exitCode || exitCodeName;184+ error.command = joinedCommand;185 error.exitCode = exitCode;186 error.exitCodeName = exitCodeName;187+ error.code = exitCode || exitCodeName;188 error.stdout = stdout;189 error.stderr = stderr;189- error.failed = true;190- // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize191- // it to `undefined`192- error.signal = signal || undefined;193- error.command = joinedCommand;194- error.timedOut = timedOut;195- error.isCanceled = isCanceled;196- error.killed = killed && !timedOut;190 191 if ('all' in result) {192 error.all = result.all;193 }194 195+ error.failed = true;196+ error.timedOut = timedOut;197+ error.isCanceled = isCanceled;198+ error.killed = killed && !timedOut;199+ // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize200+ // it to `undefined`201+ error.signal = signal || undefined;202+203 return error;204 }205 206 function getCode({error = {}}, code) {165 unmodified lines372 throw error;373 }374 375 return {376+ command: joinedCommand,377+ exitCode: 0,378+ exitCodeName: 'SUCCESS',379+ code: 0,380 stdout: result.stdout,381 stderr: result.stderr,382 all: result.all,378- code: 0,379- exitCode: 0,380- exitCodeName: 'SUCCESS',383 failed: false,382- killed: false,383- command: joinedCommand,384 timedOut: false,385- isCanceled: false385+ isCanceled: false,386+ killed: false387 };388 };389 390 // TODO: Use native "finally" syntax when targeting Node.js 1053 unmodified lines444 throw error;445 }446 447 return {447- stdout: result.stdout,448- stderr: result.stderr,449- code: 0,448+ command: joinedCommand,449 exitCode: 0,450 exitCodeName: 'SUCCESS',451+ code: 0,452+ stdout: result.stdout,453+ stderr: result.stderr,454 failed: false,453- killed: false,454- command: joinedCommand,455 timedOut: false,456- isCanceled: false456+ isCanceled: false,457+ killed: false458 };459 };modified:index.test-d.ts+7 added-7 removed
13 unmodified lines141516171819201819202122232425262728295 unmodified lines353637383940413940444142434445464748495079 unmodified lines13 unmodified lines
const unicornsResult = await execaPromise; expectType<string>(unicornsResult.command); expectType<string | number>(unicornsResult.code); expectType<boolean>(unicornsResult.failed); expectType<boolean>(unicornsResult.killed); expectType<string | undefined>(unicornsResult.signal); expectType<string>(unicornsResult.stderr); expectType<string>(unicornsResult.stdout); expectType<string>(unicornsResult.all); expectType<boolean>(unicornsResult.failed); expectType<boolean>(unicornsResult.timedOut); expectType<boolean>(unicornsResult.isCanceled); expectType<boolean>(unicornsResult.killed); expectType<string | undefined>(unicornsResult.signal);} catch (error) { const execaError: ExecaError = error;
expectType<string>(execaError.message);5 unmodified linestry { const unicornsResult = execa.sync('unicorns'); expectType<string>(unicornsResult.command); expectType<string | number>(unicornsResult.code); expectType<boolean>(unicornsResult.failed); expectType<boolean>(unicornsResult.killed); expectType<string | undefined>(unicornsResult.signal); expectType<string>(unicornsResult.stderr); expectType<string>(unicornsResult.stdout); expectType<boolean>(unicornsResult.timedOut); expectError(unicornsResult.all); expectType<boolean>(unicornsResult.failed); expectType<boolean>(unicornsResult.timedOut); expectError(unicornsResult.isCanceled); expectType<boolean>(unicornsResult.killed); expectType<string | undefined>(unicornsResult.signal);} catch (error) { const execaError: ExecaSyncError = error;
expectType<string>(execaError.message);79 unmodified linesmodified:readme.md+35 added-22 removed
58 unmodified lines59 } catch (error) {60 console.log(error);61 /*62 {63- message: 'spawn wrong command ENOENT',63+ message: 'Command failed with exit code 2 (ENOENT): wrong command spawn wrong ENOENT',64 errno: 'ENOENT',65- code: 'ENOENT',66- syscall: 'spawn wrong command',67- path: 'wrong command',68- killed: false,65+ code: 2,66+ syscall: 'spawn wrong',67+ path: 'wrong',68+ spawnargs: ['command'],69+ command: 'wrong command',70+ exitCode: 2,71+ exitCodeName: 'ENOENT',72 stdout: '',73 stderr: '',74+ all: '',75 failed: true,72- signal: null,73- cmd: 'wrong command',74- timedOut: false76+ timedOut: false,77+ isCanceled: false,78+ killed: false79 }80 */81 }82 16 unmodified lines99 } catch (error) {100 console.log(error);101 /*102 {99- message: 'spawnSync wrong command ENOENT',103+ message: 'Command failed with exit code 2 (ENOENT): wrong command spawnSync wrong ENOENT',104 errno: 'ENOENT',101- code: 'ENOENT',102- syscall: 'spawnSync wrong command',103- path: 'wrong command',105+ code: 2,106+ syscall: 'spawnSync wrong',107+ path: 'wrong',108+ spawnargs: ['command'],109+ command: 'wrong command',110+ exitCode: 2,111+ exitCodeName: 'ENOENT',112+ stdout: null,113+ stderr: null,114+ failed: true,115+ timedOut: false,116+ isCanceled: false117 }118 */119 }120 ```38 unmodified lines159 Type: `object`160 161 Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.162 163+#### command164+165+Type: `string`166+167+The command that was run.168+169 #### exitCode170 171 Type: `number`172 22 unmodified lines195 Type: `string | Buffer`196 197 The output of the process on both stdout and stderr. `undefined` if `execa.sync()` was used.198 180-#### command181-182-Type: `string`183-184-The command that was run.185-199 #### failed200 201 Type: `boolean`202 4 unmodified lines207 Type: `boolean`208 209 Whether the process timed out.210 198-#### killed211+#### isCanceled212 213 Type: `boolean`214 202-Whether the process was killed.215+Whether the process was canceled.216 204-#### isCanceled217+#### killed218 219 Type: `boolean`220 208-Whether the process was canceled.221+Whether the process was killed.222 223 #### signal224 225 Type: `string | undefined`204 unmodified lines