Skip to content

Commit

Permalink
refactor: drop support for versions below Node.js 8 (#125)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop support for Node.js < 8
  • Loading branch information
Siilwyn authored and satazor committed Aug 20, 2019
1 parent 48bee1d commit 16feb53
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 75 deletions.
16 changes: 6 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
language: node_js
node_js:
- '4.7'
- '4.8'
- '5.6'
- '5.7'
- '6'
- 'lts/*'
# nodejs 11.11.X was failing with this https://travis-ci.org/moxystudio/node-proper-lockfile/jobs/503161746#L469
# - 'node'
- 8
- 9
- 10
- 12
after_success:
- "npm i codecov"
- "node_modules/.bin/codecov"
- 'npm i codecov'
- 'node_modules/.bin/codecov'
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ A cross platform solution to node's spawn and spawnSync.

## Installation

Node.js version 8 and up:
`$ npm install cross-spawn`

Node.js version 7 and under:
`$ npm install cross-spawn@6`

## Why

Expand Down
13 changes: 2 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@
init:
- git config --global core.autocrlf input

# If we are running on Node <6, we must install npm v3 otherwise
# there will be intermitent errors when running `npm install`
environment:
matrix:
- nodejs_version: 4.7
npm_version: ^3.0.0
- nodejs_version: 4.8
npm_version: ^3.0.0
- nodejs_version: 5.6
npm_version: ^3.0.0
- nodejs_version: 5.7
npm_version: ^3.0.0
- nodejs_version: 6
- nodejs_version: 8
- nodejs_version: 9
- nodejs_version: 10
- nodejs_version: 12

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
36 changes: 1 addition & 35 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
'use strict';

const path = require('path');
const niceTry = require('nice-try');
const resolveCommand = require('./util/resolveCommand');
const escape = require('./util/escape');
const readShebang = require('./util/readShebang');
const semver = require('semver');

const isWin = process.platform === 'win32';
const isExecutableRegExp = /\.(?:com|exe)$/i;
const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;

// `options.shell` is supported in Node ^4.8.0, ^5.7.0 and >= 6.0.0
const supportsShellOption = niceTry(() => semver.satisfies(process.version, '^4.8.0 || ^5.7.0 || >= 6.0.0', true)) || false;

function detectShebang(parsed) {
parsed.file = resolveCommand(parsed);

Expand Down Expand Up @@ -67,35 +62,6 @@ function parseNonShell(parsed) {
return parsed;
}

function parseShell(parsed) {
// If node supports the shell option, there's no need to mimic its behavior
if (supportsShellOption) {
return parsed;
}

// Mimic node shell option
// See https://github.com/nodejs/node/blob/b9f6a2dc059a1062776133f3d4fd848c4da7d150/lib/child_process.js#L335
const shellCommand = [parsed.command].concat(parsed.args).join(' ');

if (isWin) {
parsed.command = typeof parsed.options.shell === 'string' ? parsed.options.shell : process.env.comspec || 'cmd.exe';
parsed.args = ['/d', '/s', '/c', `"${shellCommand}"`];
parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped
} else {
if (typeof parsed.options.shell === 'string') {
parsed.command = parsed.options.shell;
} else if (process.platform === 'android') {
parsed.command = '/system/bin/sh';
} else {
parsed.command = '/bin/sh';
}

parsed.args = ['-c', shellCommand];
}

return parsed;
}

function parse(command, args, options) {
// Normalize arguments, similar to nodejs
if (args && !Array.isArray(args)) {
Expand All @@ -119,7 +85,7 @@ function parse(command, args, options) {
};

// Delegate further parsing to shell or non-shell
return options.shell ? parseShell(parsed) : parseNonShell(parsed);
return options.shell ? parsed : parseNonShell(parsed);
}

module.exports = parse;
11 changes: 1 addition & 10 deletions lib/util/readShebang.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ const shebangCommand = require('shebang-command');
function readShebang(command) {
// Read the first 150 bytes from the file
const size = 150;
let buffer;

if (Buffer.alloc) {
// Node.js v4.5+ / v5.10+
buffer = Buffer.alloc(size);
} else {
// Old Node.js API
buffer = new Buffer(size);
buffer.fill(0); // zero-fill
}
const buffer = Buffer.alloc(size);

let fd;

Expand Down
8 changes: 2 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
]
},
"dependencies": {
"nice-try": "^1.0.4",
"path-key": "^2.0.1",
"semver": "^5.5.0",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
},
Expand All @@ -71,6 +69,6 @@
"standard-version": "^4.2.0"
},
"engines": {
"node": ">=4.8"
"node": ">= 8"
}
}

0 comments on commit 16feb53

Please sign in to comment.