Skip to content
Myr

Move `onExit()` cleanup code next to `onExit()` (#337)

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 0241d6e · Browse files · 2 files+8 added−19 removed
This commit

State

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

Diff stats

2 files+8 added−19 removed

  • other:+8 added−19 removed

2 files+8 added−19 removed

modified:lib/kill.js+5 added-9 removed
modified:index.js+3 added-10 removed
2 unmodified lines
3const childProcess = require('child_process');4const crossSpawn = require('cross-spawn');5const stripFinalNewline = require('strip-final-newline');6const npmRunPath = require('npm-run-path');7const pFinally = require('p-finally');7const makeError = require('./lib/error');8const normalizeStdio = require('./lib/stdio');10const {spawnedKill, spawnedCancel, setupTimeout, setExitHandler, cleanup} = require('./lib/kill');9const {spawnedKill, spawnedCancel, setupTimeout, setExitHandler} = require('./lib/kill');10const {handleInput, getSpawnedResult, makeAllStream, validateInputSync} = require('./lib/stream.js');11const {mergePromise, getSpawnedPromise} = require('./lib/promise.js');12const {joinCommand, parseCommand} = require('./lib/command.js');13
79 unmodified lines
93 return mergePromise(dummySpawned, errorPromise);94 }9596 const spawnedPromise = getSpawnedPromise(spawned);97 const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);98 const processDone = setExitHandler(spawned, parsed.options, timedPromise);99100 const context = {isCanceled: false};101102 spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));103 spawned.cancel = spawnedCancel.bind(null, spawned, context);104104 const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);105 const removeExitHandler = setExitHandler(spawned, parsed.options);106107 // TODO: Use native "finally" syntax when targeting Node.js 10108 const processDone = pFinally(timedPromise, () => {109 cleanup(removeExitHandler);110 });111105 const handlePromise = async () => {106 const [{error, code, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);107 const stdout = handleOutput(parsed.options, stdoutResult);108 const stderr = handleOutput(parsed.options, stderrResult);
143 unmodified lines