Skip to content

Commit dce2267

Browse files
committedMar 7, 2019
Require Node.js 8
1 parent e897f44 commit dce2267

File tree

6 files changed

+123
-112
lines changed

6 files changed

+123
-112
lines changed
 

‎.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ language: node_js
55
node_js:
66
- '10'
77
- '8'
8-
- '6'
98
after_success:
109
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

‎index.js

+32-17
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@ function handleArgs(command, args, options) {
2020
args = parsed.args;
2121
options = parsed.options;
2222

23-
options = Object.assign({
23+
options = {
2424
maxBuffer: TEN_MEGABYTES,
2525
buffer: true,
2626
stripFinalNewline: true,
2727
preferLocal: true,
2828
localDir: options.cwd || process.cwd(),
2929
encoding: 'utf8',
3030
reject: true,
31-
cleanup: true
32-
}, options, {
31+
cleanup: true,
32+
...options,
3333
windowsHide: true
34-
});
34+
};
3535

3636
if (options.extendEnv !== false) {
37-
options.env = Object.assign({}, process.env, options.env);
37+
options.env = {
38+
...process.env,
39+
...options.env
40+
};
3841
}
3942

4043
if (options.preferLocal) {
41-
options.env = npmRunPath.env(Object.assign({}, options, {cwd: options.localDir}));
44+
options.env = npmRunPath.env({
45+
...options,
46+
cwd: options.localDir
47+
});
4248
}
4349

4450
// TODO: Remove in the next major release
@@ -82,7 +88,7 @@ function handleOutput(options, value) {
8288
}
8389

8490
function handleShell(fn, command, options) {
85-
return fn(command, Object.assign({}, options, {shell: true}));
91+
return fn(command, {...options, shell: true});
8692
}
8793

8894
function getStream(process, stream, {encoding, buffer, maxBuffer}) {
@@ -257,14 +263,15 @@ module.exports = (command, args, options) => {
257263
}
258264
}
259265

266+
// TODO: Use native "finally" syntax when targeting Node.js 10
260267
const handlePromise = () => pFinally(Promise.all([
261268
processDone,
262269
getStream(spawned, 'stdout', {encoding, buffer, maxBuffer}),
263270
getStream(spawned, 'stderr', {encoding, buffer, maxBuffer})
264-
]).then(arr => {
265-
const result = arr[0];
266-
result.stdout = arr[1];
267-
result.stderr = arr[2];
271+
]).then(results => { // eslint-disable-line promise/prefer-await-to-then
272+
const result = results[0];
273+
result.stdout = results[1];
274+
result.stderr = results[2];
268275

269276
if (result.error || result.code !== 0 || result.signal !== null) {
270277
const error = makeError(result, {
@@ -301,21 +308,29 @@ module.exports = (command, args, options) => {
301308

302309
handleInput(spawned, parsed.options.input);
303310

304-
spawned.then = (onfulfilled, onrejected) => handlePromise().then(onfulfilled, onrejected);
305-
spawned.catch = onrejected => handlePromise().catch(onrejected);
306-
// eslint-disable-next-line no-use-extend-native/no-use-extend-native
311+
// eslint-disable-next-line promise/prefer-await-to-then
312+
spawned.then = (onFulfilled, onRejected) => handlePromise().then(onFulfilled, onRejected);
313+
spawned.catch = onRejected => handlePromise().catch(onRejected);
314+
315+
// TOOD: Remove the `if`-guard when targeting Node.js 10
307316
if (Promise.prototype.finally) {
308-
spawned.finally = onfinally => handlePromise().finally(onfinally);
317+
spawned.finally = onFinally => handlePromise().finally(onFinally);
309318
}
310319

311320
return spawned;
312321
};
313322

314323
// TODO: set `stderr: 'ignore'` when that option is implemented
315-
module.exports.stdout = (...args) => module.exports(...args).then(x => x.stdout);
324+
module.exports.stdout = async (...args) => {
325+
const {stdout} = await module.exports(...args);
326+
return stdout;
327+
};
316328

317329
// TODO: set `stdout: 'ignore'` when that option is implemented
318-
module.exports.stderr = (...args) => module.exports(...args).then(x => x.stderr);
330+
module.exports.stderr = async (...args) => {
331+
const {stderr} = await module.exports(...args);
332+
return stderr;
333+
};
319334

320335
module.exports.shell = (command, options) => handleShell(module.exports, command, options);
321336

‎lib/errname.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (typeof util.getSystemErrorName === 'function') {
99
module.exports = util.getSystemErrorName;
1010
} else {
1111
try {
12-
uv = process.binding('uv');
12+
uv = process.binding('uv'); // eslint-disable-line node/no-deprecated-api
1313

1414
if (typeof uv.errname !== 'function') {
1515
throw new TypeError('uv.errname is not a function');

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=6"
13+
"node": ">=8"
1414
},
1515
"scripts": {
1616
"test": "xo && nyc ava"
@@ -46,14 +46,14 @@
4646
"strip-final-newline": "^2.0.0"
4747
},
4848
"devDependencies": {
49-
"ava": "^1.2.1",
50-
"cat-names": "^1.0.2",
51-
"coveralls": "^3.0.1",
52-
"delay": "^3.0.0",
49+
"ava": "^1.3.1",
50+
"cat-names": "^2.0.0",
51+
"coveralls": "^3.0.3",
52+
"delay": "^4.1.0",
5353
"is-running": "^2.0.0",
54-
"nyc": "^13.0.1",
54+
"nyc": "^13.3.0",
5555
"tempfile": "^2.0.0",
56-
"xo": "^0.23.0"
56+
"xo": "^0.24.0"
5757
},
5858
"nyc": {
5959
"exclude": [

‎test.js

+81-84
Large diffs are not rendered by default.

‎test/errname.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import errname from '../lib/errname';
33

4-
const isWin = process.platform === 'win32';
4+
const isWindows = process.platform === 'win32';
55

66
// Simulates failure to capture `process.binding('uv');`
77
const fallback = code => errname.__test__(null, code);
@@ -22,5 +22,5 @@ function makeTests(name, m, expected) {
2222

2323
const unknown = 'Unknown system error -2';
2424

25-
makeTests('native', errname, isWin ? unknown : 'ENOENT');
25+
makeTests('native', errname, isWindows ? unknown : 'ENOENT');
2626
makeTests('fallback', fallback, unknown);

0 commit comments

Comments
 (0)
Please sign in to comment.