Skip to content
Myr

Refactoring: move inner function to outer scope (#654)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent d69fd23 · Browse files · 1 file+48 added−42 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+48 added−42 removed

  • other:+48 added−42 removed

1 file+48 added−42 removed

modified:index.js+48 added-42 removed
134 unmodified lines
135136 spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));137 spawned.cancel = spawnedCancel.bind(null, spawned, context);138139 const handlePromise = async () => {140 const [{error, exitCode, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, options, stdioStreams, processDone);141 const stdout = handleOutput(options, stdoutResult);142 const stderr = handleOutput(options, stderrResult);143 const all = handleOutput(options, allResult);139 const handlePromiseOnce = onetime(handlePromise.bind(undefined, {spawned, options, context, stdioStreams, command, escapedCommand, processDone}));140145 if (error || exitCode !== 0 || signal !== null) {146 const returnedError = makeError({147 error,148 exitCode,149 signal,150 stdout,151 stderr,152 all,153 command,154 escapedCommand,155 options,156 timedOut,157 isCanceled: context.isCanceled || (options.signal ? options.signal.aborted : false),158 });141 pipeOutputAsync(spawned, stdioStreams);142160 if (!options.reject) {161 return returnedError;162 }143 spawned.all = makeAllStream(spawned, options);144145 addPipeMethods(spawned);146 mergePromise(spawned, handlePromiseOnce);164 throw returnedError;165 }147 return spawned;148}149167 return {168 command,169 escapedCommand,170 exitCode: 0,150const handlePromise = async ({spawned, options, context, stdioStreams, command, escapedCommand, processDone}) => {151 const [152 {error, exitCode, signal, timedOut},153 stdoutResult,154 stderrResult,155 allResult,156 ] = await getSpawnedResult(spawned, options, stdioStreams, processDone);157 const stdout = handleOutput(options, stdoutResult);158 const stderr = handleOutput(options, stderrResult);159 const all = handleOutput(options, allResult);160161 if (error || exitCode !== 0 || signal !== null) {162 const isCanceled = context.isCanceled || Boolean(options.signal?.aborted);163 const returnedError = makeError({164 error,165 exitCode,166 signal,167 stdout,168 stderr,169 all,174 failed: false,175 timedOut: false,176 isCanceled: false,177 isTerminated: false,178 };179 };170 command,171 escapedCommand,172 options,173 timedOut,174 isCanceled,175 });176181 const handlePromiseOnce = onetime(handlePromise);177 if (!options.reject) {178 return returnedError;179 }180183 pipeOutputAsync(spawned, stdioStreams);181 throw returnedError;182 }183185 spawned.all = makeAllStream(spawned, options);184 return {185 command,186 escapedCommand,187 exitCode: 0,188 stdout,189 stderr,190 all,191 failed: false,192 timedOut: false,193 isCanceled: false,194 isTerminated: false,195 };196};197187 addPipeMethods(spawned);188 mergePromise(spawned, handlePromiseOnce);189 return spawned;190}191198export function execaSync(rawFile, rawArgs, rawOptions) {199 const {file, args, command, escapedCommand, options} = handleArguments(rawFile, rawArgs, rawOptions);200201 const stdioStreams = handleInputSync(options);
133 unmodified lines