Navigation Menu

Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 7, 2019
1 parent e897f44 commit dce2267
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 112 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -5,6 +5,5 @@ language: node_js
node_js:
- '10'
- '8'
- '6'
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
49 changes: 32 additions & 17 deletions index.js
Expand Up @@ -20,25 +20,31 @@ function handleArgs(command, args, options) {
args = parsed.args;
options = parsed.options;

options = Object.assign({
options = {
maxBuffer: TEN_MEGABYTES,
buffer: true,
stripFinalNewline: true,
preferLocal: true,
localDir: options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
cleanup: true
}, options, {
cleanup: true,
...options,
windowsHide: true
});
};

if (options.extendEnv !== false) {
options.env = Object.assign({}, process.env, options.env);
options.env = {
...process.env,
...options.env
};
}

if (options.preferLocal) {
options.env = npmRunPath.env(Object.assign({}, options, {cwd: options.localDir}));
options.env = npmRunPath.env({
...options,
cwd: options.localDir
});
}

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

function handleShell(fn, command, options) {
return fn(command, Object.assign({}, options, {shell: true}));
return fn(command, {...options, shell: true});
}

function getStream(process, stream, {encoding, buffer, maxBuffer}) {
Expand Down Expand Up @@ -257,14 +263,15 @@ module.exports = (command, args, options) => {
}
}

// TODO: Use native "finally" syntax when targeting Node.js 10
const handlePromise = () => pFinally(Promise.all([
processDone,
getStream(spawned, 'stdout', {encoding, buffer, maxBuffer}),
getStream(spawned, 'stderr', {encoding, buffer, maxBuffer})
]).then(arr => {
const result = arr[0];
result.stdout = arr[1];
result.stderr = arr[2];
]).then(results => { // eslint-disable-line promise/prefer-await-to-then
const result = results[0];
result.stdout = results[1];
result.stderr = results[2];

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

handleInput(spawned, parsed.options.input);

spawned.then = (onfulfilled, onrejected) => handlePromise().then(onfulfilled, onrejected);
spawned.catch = onrejected => handlePromise().catch(onrejected);
// eslint-disable-next-line no-use-extend-native/no-use-extend-native
// eslint-disable-next-line promise/prefer-await-to-then
spawned.then = (onFulfilled, onRejected) => handlePromise().then(onFulfilled, onRejected);
spawned.catch = onRejected => handlePromise().catch(onRejected);

// TOOD: Remove the `if`-guard when targeting Node.js 10
if (Promise.prototype.finally) {
spawned.finally = onfinally => handlePromise().finally(onfinally);
spawned.finally = onFinally => handlePromise().finally(onFinally);
}

return spawned;
};

// TODO: set `stderr: 'ignore'` when that option is implemented
module.exports.stdout = (...args) => module.exports(...args).then(x => x.stdout);
module.exports.stdout = async (...args) => {
const {stdout} = await module.exports(...args);
return stdout;
};

// TODO: set `stdout: 'ignore'` when that option is implemented
module.exports.stderr = (...args) => module.exports(...args).then(x => x.stderr);
module.exports.stderr = async (...args) => {
const {stderr} = await module.exports(...args);
return stderr;
};

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

Expand Down
2 changes: 1 addition & 1 deletion lib/errname.js
Expand Up @@ -9,7 +9,7 @@ if (typeof util.getSystemErrorName === 'function') {
module.exports = util.getSystemErrorName;
} else {
try {
uv = process.binding('uv');
uv = process.binding('uv'); // eslint-disable-line node/no-deprecated-api

if (typeof uv.errname !== 'function') {
throw new TypeError('uv.errname is not a function');
Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && nyc ava"
Expand Down Expand Up @@ -46,14 +46,14 @@
"strip-final-newline": "^2.0.0"
},
"devDependencies": {
"ava": "^1.2.1",
"cat-names": "^1.0.2",
"coveralls": "^3.0.1",
"delay": "^3.0.0",
"ava": "^1.3.1",
"cat-names": "^2.0.0",
"coveralls": "^3.0.3",
"delay": "^4.1.0",
"is-running": "^2.0.0",
"nyc": "^13.0.1",
"nyc": "^13.3.0",
"tempfile": "^2.0.0",
"xo": "^0.23.0"
"xo": "^0.24.0"
},
"nyc": {
"exclude": [
Expand Down

0 comments on commit dce2267

Please sign in to comment.