From 9cec2a73cdbf951785fd7302afa111e06a781805 Mon Sep 17 00:00:00 2001 From: Selwyn Date: Mon, 19 Aug 2019 20:36:11 +0200 Subject: [PATCH] refactor: drop support for versions below Node.js 8 --- .travis.yml | 16 ++++++---------- README.md | 3 +++ appveyor.yml | 13 ++----------- lib/parse.js | 36 +----------------------------------- lib/util/readShebang.js | 11 +---------- package-lock.json | 8 ++------ package.json | 4 +--- 7 files changed, 16 insertions(+), 75 deletions(-) diff --git a/.travis.yml b/.travis.yml index e5dc3c0..1417847 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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' diff --git a/README.md b/README.md index b12037d..0f95781 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/appveyor.yml b/appveyor.yml index 3d91a26..77acd10 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/lib/parse.js b/lib/parse.js index 962827a..0129d74 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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); @@ -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)) { @@ -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; diff --git a/lib/util/readShebang.js b/lib/util/readShebang.js index bd4f128..5e83733 100644 --- a/lib/util/readShebang.js +++ b/lib/util/readShebang.js @@ -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; diff --git a/package-lock.json b/package-lock.json index 3a53d5b..25ce629 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7064,11 +7064,6 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, - "nice-try": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.4.tgz", - "integrity": "sha512-2NpiFHqC87y/zFke0fC0spBXL3bBsoh/p5H1EFhshxjCR5+0g2d6BiXbUFz9v1sAcxsk2htp2eQnNIci2dIYcA==" - }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -8071,7 +8066,8 @@ "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", + "dev": true }, "semver-compare": { "version": "1.0.0", diff --git a/package.json b/package.json index 1c04713..8620166 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -71,6 +69,6 @@ "standard-version": "^4.2.0" }, "engines": { - "node": ">=4.8" + "node": ">= 8" } }