Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 18, 2019
1 parent df08cfb commit 5a9c76f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -7,6 +7,5 @@ node_js:
- '13'
- '12'
- '10'
- '8'
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
10 changes: 5 additions & 5 deletions lib/kill.js
@@ -1,7 +1,6 @@
'use strict';
const os = require('os');
const onExit = require('signal-exit');
const pFinally = require('p-finally');

const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;

Expand Down Expand Up @@ -80,15 +79,15 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise
}, timeout);
});

const safeSpawnedPromise = pFinally(spawnedPromise, () => {
const safeSpawnedPromise = spawnedPromise.finally(() => {
clearTimeout(timeoutId);
});

return Promise.race([timeoutPromise, safeSpawnedPromise]);
};

// `cleanup` option handling
const setExitHandler = (spawned, {cleanup, detached}, timedPromise) => {
const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => {
if (!cleanup || detached) {
return timedPromise;
}
Expand All @@ -97,8 +96,9 @@ const setExitHandler = (spawned, {cleanup, detached}, timedPromise) => {
spawned.kill();
});

// TODO: Use native "finally" syntax when targeting Node.js 10
return pFinally(timedPromise, removeExitHandler);
return timedPromise.finally(() => {
removeExitHandler();
});
};

module.exports = {
Expand Down
7 changes: 1 addition & 6 deletions lib/promise.js
Expand Up @@ -17,12 +17,7 @@ const mergePromiseProperty = (spawned, promise, property) => {
const mergePromise = (spawned, promise) => {
mergePromiseProperty(spawned, promise, 'then');
mergePromiseProperty(spawned, promise, 'catch');

// TODO: Remove the `if`-guard when targeting Node.js 10
if (Promise.prototype.finally) {
mergePromiseProperty(spawned, promise, 'finally');
}

mergePromiseProperty(spawned, promise, 'finally');
return spawned;
};

Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -11,7 +11,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": "^8.12.0 || >=9.7.0"
"node": ">=10"
},
"scripts": {
"test": "xo && nyc ava && tsd"
Expand Down Expand Up @@ -46,7 +46,6 @@
"merge-stream": "^2.0.0",
"npm-run-path": "^4.0.0",
"onetime": "^5.1.0",
"p-finally": "^2.0.0",
"signal-exit": "^3.0.2",
"strip-final-newline": "^2.0.0"
},
Expand Down

0 comments on commit 5a9c76f

Please sign in to comment.