diff --git a/node_modules/bin-links/node_modules/cmd-shim/.travis.yml b/node_modules/bin-links/node_modules/cmd-shim/.travis.yml new file mode 100644 index 0000000000000..1d38b470c67ed --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/.travis.yml @@ -0,0 +1,19 @@ +language: node_js + +node_js: + - node + - 12 + - 10 + - 8 + - 6 + +os: + - linux + - windows + +cache: + directories: + - $HOME/.npm + +notifications: + email: false diff --git a/node_modules/bin-links/node_modules/cmd-shim/LICENSE b/node_modules/bin-links/node_modules/cmd-shim/LICENSE new file mode 100644 index 0000000000000..20a4762540923 --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/LICENSE @@ -0,0 +1,15 @@ +The ISC License + +Copyright (c) npm, Inc. and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/bin-links/node_modules/cmd-shim/README.md b/node_modules/bin-links/node_modules/cmd-shim/README.md new file mode 100644 index 0000000000000..2b8b2f468f2c3 --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/README.md @@ -0,0 +1,44 @@ +# cmd-shim + +The cmd-shim used in npm to create executable scripts on Windows, +since symlinks are not suitable for this purpose there. + +On Unix systems, you should use a symbolic link instead. + +[![Build Status](https://img.shields.io/travis/npm/cmd-shim/master.svg)](https://travis-ci.org/npm/cmd-shim) +[![Dependency Status](https://img.shields.io/david/npm/cmd-shim.svg)](https://david-dm.org/npm/cmd-shim) +[![NPM version](https://img.shields.io/npm/v/cmd-shim.svg)](https://www.npmjs.com/package/cmd-shim) + +## Installation + +``` +npm install cmd-shim +``` + +## API + +### cmdShim(from, to, cb) + +Create a cmd shim at `to` for the command line program at `from`. +e.g. + +```javascript +var cmdShim = require('cmd-shim'); +cmdShim(__dirname + '/cli.js', '/usr/bin/command-name', function (err) { + if (err) throw err; +}); +``` + +### cmdShim.ifExists(from, to, cb) + +The same as above, but will just continue if the file does not exist. +Source: + +```javascript +function cmdShimIfExists (from, to, cb) { + fs.stat(from, function (er) { + if (er) return cb() + cmdShim(from, to, cb) + }) +} +``` diff --git a/node_modules/cmd-shim/cmd-shim-2.0.2.tgz b/node_modules/bin-links/node_modules/cmd-shim/cmd-shim-2.0.2.tgz similarity index 100% rename from node_modules/cmd-shim/cmd-shim-2.0.2.tgz rename to node_modules/bin-links/node_modules/cmd-shim/cmd-shim-2.0.2.tgz diff --git a/node_modules/bin-links/node_modules/cmd-shim/index.js b/node_modules/bin-links/node_modules/cmd-shim/index.js new file mode 100644 index 0000000000000..722ad9158b02e --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/index.js @@ -0,0 +1,247 @@ +// On windows, create a .cmd file. +// Read the #! in the file to see what it uses. The vast majority +// of the time, this will be either: +// "#!/usr/bin/env " +// or: +// "#! " +// +// Write a binroot/pkg.bin + ".cmd" file that has this line in it: +// @ %~dp0 %* + +module.exports = cmdShim +cmdShim.ifExists = cmdShimIfExists + +var fs = require("graceful-fs") + +var mkdir = require("mkdirp") + , path = require("path") + , toBatchSyntax = require("./lib/to-batch-syntax") + , shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+=[^ \t]+\s+)*\s*([^ \t]+)(.*)$/ + +function cmdShimIfExists (from, to, cb) { + fs.stat(from, function (er) { + if (er) return cb() + cmdShim(from, to, cb) + }) +} + +// Try to unlink, but ignore errors. +// Any problems will surface later. +function rm (path, cb) { + fs.unlink(path, function(er) { + cb() + }) +} + +function cmdShim (from, to, cb) { + fs.stat(from, function (er, stat) { + if (er) + return cb(er) + + cmdShim_(from, to, cb) + }) +} + +function cmdShim_ (from, to, cb) { + var then = times(2, next, cb) + rm(to, then) + rm(to + ".cmd", then) + + function next(er) { + writeShim(from, to, cb) + } +} + +function writeShim (from, to, cb) { + // make a cmd file and a sh script + // First, check if the bin is a #! of some sort. + // If not, then assume it's something that'll be compiled, or some other + // sort of script, and just call it directly. + mkdir(path.dirname(to), function (er) { + if (er) + return cb(er) + fs.readFile(from, "utf8", function (er, data) { + if (er) return writeShim_(from, to, null, null, cb) + var firstLine = data.trim().split(/\r*\n/)[0] + , shebang = firstLine.match(shebangExpr) + if (!shebang) return writeShim_(from, to, null, null, null, cb) + var vars = shebang[1] || "" + , prog = shebang[2] + , args = shebang[3] || "" + return writeShim_(from, to, prog, args, vars, cb) + }) + }) +} + + +function writeShim_ (from, to, prog, args, variables, cb) { + var shTarget = path.relative(path.dirname(to), from) + , target = shTarget.split("/").join("\\") + , longProg + , shProg = prog && prog.split("\\").join("/") + , shLongProg + , pwshProg = shProg && "\"" + shProg + "$exe\"" + , pwshLongProg + shTarget = shTarget.split("\\").join("/") + args = args || "" + variables = variables || "" + if (!prog) { + prog = "\"%~dp0\\" + target + "\"" + shProg = "\"$basedir/" + shTarget + "\"" + pwshProg = shProg + args = "" + target = "" + shTarget = "" + } else { + longProg = "\"%~dp0\\" + prog + ".exe\"" + shLongProg = "\"$basedir/" + prog + "\"" + pwshLongProg = "\"$basedir/" + prog + "$exe\"" + target = "\"%~dp0\\" + target + "\"" + shTarget = "\"$basedir/" + shTarget + "\"" + } + + // @SETLOCAL + // + // @IF EXIST "%~dp0\node.exe" ( + // @SET "_prog=%~dp0\node.exe" + // ) ELSE ( + // @SET "_prog=node" + // @SET PATHEXT=%PATHEXT:;.JS;=;% + // ) + // + // "%_prog%" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %* + // @ENDLOCAL + var cmd + if (longProg) { + shLongProg = shLongProg.trim(); + args = args.trim(); + var variableDeclarationsAsBatch = toBatchSyntax.convertToSetCommands(variables) + cmd = "@SETLOCAL\r\n" + + variableDeclarationsAsBatch + + "\r\n" + + "@IF EXIST " + longProg + " (\r\n" + + " @SET \"_prog=" + longProg.replace(/(^")|("$)/g, '') + "\"\r\n" + + ") ELSE (\r\n" + + " @SET \"_prog=" + prog.replace(/(^")|("$)/g, '') + "\"\r\n" + + " @SET PATHEXT=%PATHEXT:;.JS;=;%\r\n" + + ")\r\n" + + "\r\n" + + "\"%_prog%\" " + args + " " + target + " %*\r\n" + + '@ENDLOCAL\r\n' + } else { + cmd = "@" + prog + " " + args + " " + target + " %*\r\n" + } + + // #!/bin/sh + // basedir=`dirname "$0"` + // + // case `uname` in + // *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; + // esac + // + // if [ -x "$basedir/node.exe" ]; then + // "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@" + // ret=$? + // else + // node "$basedir/node_modules/npm/bin/npm-cli.js" "$@" + // ret=$? + // fi + // exit $ret + + var sh = "#!/bin/sh\n" + + sh = sh + + "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n" + + "\n" + + "case `uname` in\n" + + " *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;\n" + + "esac\n" + + "\n" + + if (shLongProg) { + sh = sh + + "if [ -x "+shLongProg+" ]; then\n" + + " " + variables + shLongProg + " " + args + " " + shTarget + " \"$@\"\n" + + " ret=$?\n" + + "else \n" + + " " + variables + shProg + " " + args + " " + shTarget + " \"$@\"\n" + + " ret=$?\n" + + "fi\n" + + "exit $ret\n" + } else { + sh = sh + + shProg + " " + args + " " + shTarget + " \"$@\"\n" + + "exit $?\n" + } + + // #!/usr/bin/env pwsh + // $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + // + // $ret=0 + // $exe = "" + // if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + // # Fix case when both the Windows and Linux builds of Node + // # are installed in the same directory + // $exe = ".exe" + // } + // if (Test-Path "$basedir/node") { + // & "$basedir/node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args + // $ret=$LASTEXITCODE + // } else { + // & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args + // $ret=$LASTEXITCODE + // } + // exit $ret + var pwsh = "#!/usr/bin/env pwsh\n" + + "$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n" + + "\n" + + "$exe=\"\"\n" + + "if ($PSVersionTable.PSVersion -lt \"6.0\" -or $IsWindows) {\n" + + " # Fix case when both the Windows and Linux builds of Node\n" + + " # are installed in the same directory\n" + + " $exe=\".exe\"\n" + + "}\n" + if (shLongProg) { + pwsh = pwsh + + "$ret=0\n" + + "if (Test-Path " + pwshLongProg + ") {\n" + + " & " + pwshLongProg + " " + args + " " + shTarget + " $args\n" + + " $ret=$LASTEXITCODE\n" + + "} else {\n" + + " & " + pwshProg + " " + args + " " + shTarget + " $args\n" + + " $ret=$LASTEXITCODE\n" + + "}\n" + + "exit $ret\n" + } else { + pwsh = pwsh + + "& " + pwshProg + " " + args + " " + shTarget + " $args\n" + + "exit $LASTEXITCODE\n" + } + + var then = times(3, next, cb) + fs.writeFile(to + ".ps1", pwsh, "utf8", then) + fs.writeFile(to + ".cmd", cmd, "utf8", then) + fs.writeFile(to, sh, "utf8", then) + function next () { + chmodShim(to, cb) + } +} + +function chmodShim (to, cb) { + var then = times(2, cb, cb) + fs.chmod(to, "0755", then) + fs.chmod(to + ".cmd", "0755", then) + fs.chmod(to + ".ps1", "0755", then) +} + +function times(n, ok, cb) { + var errState = null + return function(er) { + if (!errState) { + if (er) + cb(errState = er) + else if (--n === 0) + ok() + } + } +} diff --git a/node_modules/bin-links/node_modules/cmd-shim/lib/to-batch-syntax.js b/node_modules/bin-links/node_modules/cmd-shim/lib/to-batch-syntax.js new file mode 100644 index 0000000000000..d8bed1a634a01 --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/lib/to-batch-syntax.js @@ -0,0 +1,52 @@ +exports.replaceDollarWithPercentPair = replaceDollarWithPercentPair +exports.convertToSetCommand = convertToSetCommand +exports.convertToSetCommands = convertToSetCommands + +function convertToSetCommand(key, value) { + var line = "" + key = key || "" + key = key.trim() + value = value || "" + value = value.trim() + if(key && value && value.length > 0) { + line = "@SET " + key + "=" + replaceDollarWithPercentPair(value) + "\r\n" + } + return line +} + +function extractVariableValuePairs(declarations) { + var pairs = {} + declarations.map(function(declaration) { + var split = declaration.split("=") + pairs[split[0]]=split[1] + }) + return pairs +} + +function convertToSetCommands(variableString) { + var variableValuePairs = extractVariableValuePairs(variableString.split(" ")) + var variableDeclarationsAsBatch = "" + Object.keys(variableValuePairs).forEach(function (key) { + variableDeclarationsAsBatch += convertToSetCommand(key, variableValuePairs[key]) + }) + return variableDeclarationsAsBatch +} + +function replaceDollarWithPercentPair(value) { + var dollarExpressions = /\$\{?([^\$@#\?\- \t{}:]+)\}?/g + var result = "" + var startIndex = 0 + value = value || "" + do { + var match = dollarExpressions.exec(value) + if(match) { + var betweenMatches = value.substring(startIndex, match.index) || "" + result += betweenMatches + "%" + match[1] + "%" + startIndex = dollarExpressions.lastIndex + } + } while (dollarExpressions.lastIndex > 0) + result += value.substr(startIndex) + return result +} + + diff --git a/node_modules/bin-links/node_modules/cmd-shim/package.json b/node_modules/bin-links/node_modules/cmd-shim/package.json new file mode 100644 index 0000000000000..02ff407be2fbf --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/package.json @@ -0,0 +1,50 @@ +{ + "_from": "cmd-shim@^2.0.2", + "_id": "cmd-shim@2.1.0", + "_inBundle": false, + "_integrity": "sha512-A5C0Cyf2H8sKsHqX0tvIWRXw5/PK++3Dc0lDbsugr90nOECLLuSPahVQBG8pgmgiXgm/TzBWMqI2rWdZwHduAw==", + "_location": "/bin-links/cmd-shim", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "cmd-shim@^2.0.2", + "name": "cmd-shim", + "escapedName": "cmd-shim", + "rawSpec": "^2.0.2", + "saveSpec": null, + "fetchSpec": "^2.0.2" + }, + "_requiredBy": [ + "/bin-links" + ], + "_resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-2.1.0.tgz", + "_shasum": "e59a08d4248dda3bb502044083a4db4ac890579a", + "_spec": "cmd-shim@^2.0.2", + "_where": "/Users/isaacs/dev/npm/cli/node_modules/bin-links", + "bugs": { + "url": "https://github.com/npm/cmd-shim/issues" + }, + "bundleDependencies": false, + "dependencies": { + "graceful-fs": "^4.1.2", + "mkdirp": "~0.5.0" + }, + "deprecated": false, + "description": "Used in npm for command line application support", + "devDependencies": { + "rimraf": "~2.2.8", + "tap": "^1.2.0" + }, + "homepage": "https://github.com/npm/cmd-shim#readme", + "license": "ISC", + "name": "cmd-shim", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/cmd-shim.git" + }, + "scripts": { + "test": "tap test/*.js" + }, + "version": "2.1.0" +} diff --git a/node_modules/bin-links/node_modules/cmd-shim/test/00-setup.js b/node_modules/bin-links/node_modules/cmd-shim/test/00-setup.js new file mode 100644 index 0000000000000..c9a7d3920748a --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/test/00-setup.js @@ -0,0 +1,35 @@ +var test = require('tap').test +var mkdirp = require('mkdirp') +var fs = require('fs') +var path = require('path') +var fixtures = path.resolve(__dirname, 'fixtures') + +var froms = { + 'from.exe': 'exe', + 'from.env': '#!/usr/bin/env node\nconsole.log(/hi/)\n', + 'from.env.args': '#!/usr/bin/env node --expose_gc\ngc()\n', + 'from.env.variables': '#!/usr/bin/env NODE_PATH=./lib:$NODE_PATH node', + 'from.sh': '#!/usr/bin/sh\necho hi\n', + 'from.sh.args': '#!/usr/bin/sh -x\necho hi\n' +} + +var cmdShim = require('../') + +test('create fixture', function (t) { + mkdirp(fixtures, function (er) { + if (er) + throw er + t.pass('made dir') + Object.keys(froms).forEach(function (f) { + t.test('write ' + f, function (t) { + fs.writeFile(path.resolve(fixtures, f), froms[f], function (er) { + if (er) + throw er + t.pass('wrote ' + f) + t.end() + }) + }) + }) + t.end() + }) +}) diff --git a/node_modules/bin-links/node_modules/cmd-shim/test/basic.js b/node_modules/bin-links/node_modules/cmd-shim/test/basic.js new file mode 100755 index 0000000000000..4d92557f4e0f7 --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/test/basic.js @@ -0,0 +1,330 @@ +var test = require('tap').test +var mkdirp = require('mkdirp') +var fs = require('fs') +var path = require('path') +var fixtures = path.resolve(__dirname, 'fixtures') + +var cmdShim = require('../') + +test('no shebang', function (t) { + var from = path.resolve(fixtures, 'from.exe') + var to = path.resolve(fixtures, 'exe.shim') + cmdShim(from, to, function(er) { + if (er) + throw er + t.equal(fs.readFileSync(to, 'utf8'), + "#!/bin/sh"+ + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ + "\n"+ + "\ncase `uname` in"+ + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ + "\nesac"+ + "\n"+ + "\n\"$basedir/from.exe\" \"$@\"\nexit $?\n") + t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + "@\"%~dp0\\from.exe\" %*\r\n") + t.equal(fs.readFileSync(to + '.ps1', 'utf8'), + '#!/usr/bin/env pwsh'+ + '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ + '\n'+ + '\n$exe=""'+ + '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ + '\n # Fix case when both the Windows and Linux builds of Node'+ + '\n # are installed in the same directory'+ + '\n $exe=".exe"'+ + '\n}'+ + '\n& "$basedir/from.exe" $args'+ + '\nexit $LASTEXITCODE'+ + '\n') + t.end() + }) +}) + +test('env shebang', function (t) { + var from = path.resolve(fixtures, 'from.env') + var to = path.resolve(fixtures, 'env.shim') + cmdShim(from, to, function(er) { + if (er) + throw er + + t.equal(fs.readFileSync(to, 'utf8'), + "#!/bin/sh" + + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + + "\n" + + "\ncase `uname` in" + + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + + "\nesac" + + "\n" + + "\nif [ -x \"$basedir/node\" ]; then" + + "\n \"$basedir/node\" \"$basedir/from.env\" \"$@\"" + + "\n ret=$?" + + "\nelse " + + "\n node \"$basedir/from.env\" \"$@\"" + + "\n ret=$?" + + "\nfi" + + "\nexit $ret" + + "\n") + t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + "@SETLOCAL\r" + + "\n\r" + + "\n@IF EXIST \"%~dp0\\node.exe\" (\r" + + "\n @SET \"_prog=%~dp0\\node.exe\"\r" + + "\n) ELSE (\r" + + "\n @SET \"_prog=node\"\r" + + "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + + "\n)\r" + + "\n\r" + + "\n\"%_prog%\" \"%~dp0\\from.env\" %*\r" + + "\n@ENDLOCAL\r" + + "\n") + t.end() + }) +}) + +test('env shebang with args', function (t) { + var from = path.resolve(fixtures, 'from.env.args') + var to = path.resolve(fixtures, 'env.args.shim') + cmdShim(from, to, function(er) { + if (er) + throw er + + t.equal(fs.readFileSync(to, 'utf8'), + "#!/bin/sh"+ + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ + "\n"+ + "\ncase `uname` in"+ + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ + "\nesac"+ + "\n"+ + "\nif [ -x \"$basedir/node\" ]; then"+ + "\n \"$basedir/node\" --expose_gc \"$basedir/from.env.args\" \"$@\""+ + "\n ret=$?"+ + "\nelse "+ + "\n node --expose_gc \"$basedir/from.env.args\" \"$@\""+ + "\n ret=$?"+ + "\nfi"+ + "\nexit $ret"+ + "\n") + t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + "@SETLOCAL\r" + + "\n\r" + + "\n@IF EXIST \"%~dp0\\node.exe\" (\r" + + "\n @SET \"_prog=%~dp0\\node.exe\"\r" + + "\n) ELSE (\r" + + "\n @SET \"_prog=node\"\r" + + "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + + "\n)\r" + + "\n\r" + + "\n\"%_prog%\" --expose_gc \"%~dp0\\from.env.args\" %*\r" + + "\n@ENDLOCAL\r" + + "\n") + t.equal(fs.readFileSync(to + '.ps1', 'utf8'), + '#!/usr/bin/env pwsh'+ + '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ + '\n'+ + '\n$exe=""'+ + '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ + '\n # Fix case when both the Windows and Linux builds of Node'+ + '\n # are installed in the same directory'+ + '\n $exe=".exe"'+ + '\n}'+ + '\n$ret=0'+ + '\nif (Test-Path "$basedir/node$exe") {'+ + '\n & "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n} else {'+ + '\n & "node$exe" --expose_gc "$basedir/from.env.args" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n}'+ + '\nexit $ret'+ + '\n') + t.end() + }) +}) + +test('env shebang with variables', function (t) { + var from = path.resolve(fixtures, 'from.env.variables') + var to = path.resolve(fixtures, 'env.variables.shim') + cmdShim(from, to, function(er) { + if (er) + throw er + + t.equal(fs.readFileSync(to, 'utf8'), + "#!/bin/sh"+ + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + + "\n"+ + "\ncase `uname` in"+ + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ + "\nesac"+ + "\n"+ + "\nif [ -x \"$basedir/node\" ]; then"+ + "\n NODE_PATH=./lib:$NODE_PATH \"$basedir/node\" \"$basedir/from.env.variables\" \"$@\""+ + "\n ret=$?"+ + "\nelse "+ + "\n NODE_PATH=./lib:$NODE_PATH node \"$basedir/from.env.variables\" \"$@\""+ + "\n ret=$?"+ + "\nfi"+ + "\nexit $ret"+ + "\n") + t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + "@SETLOCAL\r"+ + "\n@SET NODE_PATH=./lib:%NODE_PATH%\r"+ + "\n\r" + + "\n@IF EXIST \"%~dp0\\node.exe\" (\r"+ + "\n @SET \"_prog=%~dp0\\node.exe\"\r" + + "\n) ELSE (\r"+ + "\n @SET \"_prog=node\"\r"+ + "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + + "\n)\r"+ + "\n\r"+ + "\n\"%_prog%\" \"%~dp0\\from.env.variables\" %*\r"+ + "\n@ENDLOCAL\r\n") + t.equal(fs.readFileSync(to + '.ps1', 'utf8'), + '#!/usr/bin/env pwsh'+ + '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ + '\n'+ + '\n$exe=""'+ + '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ + '\n # Fix case when both the Windows and Linux builds of Node'+ + '\n # are installed in the same directory'+ + '\n $exe=".exe"'+ + '\n}'+ + '\n$ret=0'+ + '\nif (Test-Path "$basedir/node$exe") {'+ + '\n & "$basedir/node$exe" "$basedir/from.env.variables" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n} else {'+ + '\n & "node$exe" "$basedir/from.env.variables" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n}'+ + '\nexit $ret'+ + '\n') + t.end() + }) +}) + +test('explicit shebang', function (t) { + var from = path.resolve(fixtures, 'from.sh') + var to = path.resolve(fixtures, 'sh.shim') + cmdShim(from, to, function(er) { + if (er) + throw er + + t.equal(fs.readFileSync(to, 'utf8'), + "#!/bin/sh" + + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + + "\n" + + "\ncase `uname` in" + + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + + "\nesac" + + "\n" + + "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" + + "\n \"$basedir//usr/bin/sh\" \"$basedir/from.sh\" \"$@\"" + + "\n ret=$?" + + "\nelse " + + "\n /usr/bin/sh \"$basedir/from.sh\" \"$@\"" + + "\n ret=$?" + + "\nfi" + + "\nexit $ret" + + "\n") + + t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + "@SETLOCAL\r" + + "\n\r" + + "\n@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + + "\n @SET \"_prog=%~dp0\\/usr/bin/sh.exe\"\r" + + "\n) ELSE (\r" + + "\n @SET \"_prog=/usr/bin/sh\"\r" + + "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + + "\n)\r" + + "\n\r" + + "\n\"%_prog%\" \"%~dp0\\from.sh\" %*\r" + + "\n@ENDLOCAL\r" + + "\n") + + t.equal(fs.readFileSync(to + '.ps1', 'utf8'), + '#!/usr/bin/env pwsh'+ + '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ + '\n'+ + '\n$exe=""'+ + '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ + '\n # Fix case when both the Windows and Linux builds of Node'+ + '\n # are installed in the same directory'+ + '\n $exe=".exe"'+ + '\n}'+ + '\n$ret=0'+ + '\nif (Test-Path "$basedir//usr/bin/sh$exe") {'+ + '\n & "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n} else {'+ + '\n & "/usr/bin/sh$exe" "$basedir/from.sh" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n}'+ + '\nexit $ret'+ + '\n') + t.end() + }) +}) + +test('explicit shebang with args', function (t) { + var from = path.resolve(fixtures, 'from.sh.args') + var to = path.resolve(fixtures, 'sh.args.shim') + cmdShim(from, to, function(er) { + if (er) + throw er + + t.equal(fs.readFileSync(to, 'utf8'), + "#!/bin/sh" + + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + + "\n" + + "\ncase `uname` in" + + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + + "\nesac" + + "\n" + + "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" + + "\n \"$basedir//usr/bin/sh\" -x \"$basedir/from.sh.args\" \"$@\"" + + "\n ret=$?" + + "\nelse " + + "\n /usr/bin/sh -x \"$basedir/from.sh.args\" \"$@\"" + + "\n ret=$?" + + "\nfi" + + "\nexit $ret" + + "\n") + + t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + "@SETLOCAL\r" + + "\n\r" + + "\n@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + + "\n @SET \"_prog=%~dp0\\/usr/bin/sh.exe\"\r" + + "\n) ELSE (\r" + + "\n @SET \"_prog=/usr/bin/sh\"\r" + + "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + + "\n)\r" + + "\n\r" + + "\n\"%_prog%\" -x \"%~dp0\\from.sh.args\" %*\r" + + "\n@ENDLOCAL\r" + + "\n") + + t.equal(fs.readFileSync(to + '.ps1', 'utf8'), + '#!/usr/bin/env pwsh'+ + '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ + '\n'+ + '\n$exe=""'+ + '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ + '\n # Fix case when both the Windows and Linux builds of Node'+ + '\n # are installed in the same directory'+ + '\n $exe=".exe"'+ + '\n}'+ + '\n$ret=0'+ + '\nif (Test-Path "$basedir//usr/bin/sh$exe") {'+ + '\n & "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n} else {'+ + '\n & "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args'+ + '\n $ret=$LASTEXITCODE'+ + '\n}'+ + '\nexit $ret'+ + '\n') + t.end() + }) +}) diff --git a/node_modules/bin-links/node_modules/cmd-shim/test/to-batch-syntax-tests.js b/node_modules/bin-links/node_modules/cmd-shim/test/to-batch-syntax-tests.js new file mode 100644 index 0000000000000..3645fd0a577a3 --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/test/to-batch-syntax-tests.js @@ -0,0 +1,25 @@ +var test = require('tap').test +var toBatchSyntax = require('../lib/to-batch-syntax') + +test('replace $ expressions with % pair', function (t) { + var assertReplacement = function(string, expected) { + t.equal(toBatchSyntax.replaceDollarWithPercentPair(string), expected) + } + assertReplacement("$A", "%A%") + assertReplacement("$A:$B", "%A%:%B%") + assertReplacement("$A bla", "%A% bla") + assertReplacement("${A}bla", "%A%bla") + assertReplacement("$A $bla bla", "%A% %bla% bla") + assertReplacement("${A}bla ${bla}bla", "%A%bla %bla%bla") + assertReplacement("./lib:$NODE_PATH", "./lib:%NODE_PATH%") + t.end() +}) + +test('convert variable declaration to set command', function(t) { + t.equal(toBatchSyntax.convertToSetCommand("A",".lib:$A "), "@SET A=.lib:%A%\r\n") + t.equal(toBatchSyntax.convertToSetCommand("", ""), "") + t.equal(toBatchSyntax.convertToSetCommand(" ", ""), "") + t.equal(toBatchSyntax.convertToSetCommand(" ", " "), "") + t.equal(toBatchSyntax.convertToSetCommand(" ou", " ou "), "@SET ou=ou\r\n") + t.end() +}) diff --git a/node_modules/bin-links/node_modules/cmd-shim/test/zz-cleanup.js b/node_modules/bin-links/node_modules/cmd-shim/test/zz-cleanup.js new file mode 100644 index 0000000000000..9425031001cb0 --- /dev/null +++ b/node_modules/bin-links/node_modules/cmd-shim/test/zz-cleanup.js @@ -0,0 +1,13 @@ +var test = require('tap').test +var path = require('path') +var fixtures = path.resolve(__dirname, 'fixtures') +var rimraf = require('rimraf') + +test('cleanup', function(t) { + rimraf(fixtures, function(er) { + if (er) + throw er + t.pass('cleaned up') + t.end() + }) +}) diff --git a/node_modules/cmd-shim/index.js b/node_modules/cmd-shim/index.js index 722ad9158b02e..63a9d5ad1633c 100644 --- a/node_modules/cmd-shim/index.js +++ b/node_modules/cmd-shim/index.js @@ -6,7 +6,7 @@ // "#! " // // Write a binroot/pkg.bin + ".cmd" file that has this line in it: -// @ %~dp0 %* +// @ %dp0% %* module.exports = cmdShim cmdShim.ifExists = cmdShimIfExists @@ -43,9 +43,10 @@ function cmdShim (from, to, cb) { } function cmdShim_ (from, to, cb) { - var then = times(2, next, cb) + var then = times(3, next, cb) rm(to, then) rm(to + ".cmd", then) + rm(to + ".ps1", then) function next(er) { writeShim(from, to, cb) @@ -61,7 +62,7 @@ function writeShim (from, to, cb) { if (er) return cb(er) fs.readFile(from, "utf8", function (er, data) { - if (er) return writeShim_(from, to, null, null, cb) + if (er) return writeShim_(from, to, null, null, null, cb) var firstLine = data.trim().split(/\r*\n/)[0] , shebang = firstLine.match(shebangExpr) if (!shebang) return writeShim_(from, to, null, null, null, cb) @@ -86,50 +87,67 @@ function writeShim_ (from, to, prog, args, variables, cb) { args = args || "" variables = variables || "" if (!prog) { - prog = "\"%~dp0\\" + target + "\"" + prog = "\"%dp0%\\" + target + "\"" shProg = "\"$basedir/" + shTarget + "\"" pwshProg = shProg args = "" target = "" shTarget = "" } else { - longProg = "\"%~dp0\\" + prog + ".exe\"" + longProg = "\"%dp0%\\" + prog + ".exe\"" shLongProg = "\"$basedir/" + prog + "\"" pwshLongProg = "\"$basedir/" + prog + "$exe\"" - target = "\"%~dp0\\" + target + "\"" + target = "\"%dp0%\\" + target + "\"" shTarget = "\"$basedir/" + shTarget + "\"" } // @SETLOCAL + // @CALL :find_dp0 // - // @IF EXIST "%~dp0\node.exe" ( - // @SET "_prog=%~dp0\node.exe" + // @IF EXIST "%dp0%\node.exe" ( + // @SET "_prog=%dp0%\node.exe" // ) ELSE ( // @SET "_prog=node" // @SET PATHEXT=%PATHEXT:;.JS;=;% // ) // - // "%_prog%" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %* + // "%_prog%" "%dp0%\.\node_modules\npm\bin\npm-cli.js" %* // @ENDLOCAL + // @EXIT /b + // + // :find_dp0 + // SET dp0=%~dp0 + // EXIT /b + // + // Subroutine trick to fix https://github.com/npm/cmd-shim/issues/10 + var head = '@ECHO off\r\n' + + 'SETLOCAL\r\n' + + 'CALL find_dp0\r\n' + var foot = 'ENDLOCAL\r\n' + + 'EXIT /b\r\n' + + 'find_dp0:\r\n' + + 'SET dp0=%~dp0\r\n' + + 'EXIT /b\r\n' + var cmd if (longProg) { shLongProg = shLongProg.trim(); args = args.trim(); var variableDeclarationsAsBatch = toBatchSyntax.convertToSetCommands(variables) - cmd = "@SETLOCAL\r\n" + cmd = head + variableDeclarationsAsBatch + "\r\n" - + "@IF EXIST " + longProg + " (\r\n" - + " @SET \"_prog=" + longProg.replace(/(^")|("$)/g, '') + "\"\r\n" + + "IF EXIST " + longProg + " (\r\n" + + " SET \"_prog=" + longProg.replace(/(^")|("$)/g, '') + "\"\r\n" + ") ELSE (\r\n" - + " @SET \"_prog=" + prog.replace(/(^")|("$)/g, '') + "\"\r\n" - + " @SET PATHEXT=%PATHEXT:;.JS;=;%\r\n" + + " SET \"_prog=" + prog.replace(/(^")|("$)/g, '') + "\"\r\n" + + " SET PATHEXT=%PATHEXT:;.JS;=;%\r\n" + ")\r\n" + "\r\n" + "\"%_prog%\" " + args + " " + target + " %*\r\n" - + '@ENDLOCAL\r\n' + + foot } else { - cmd = "@" + prog + " " + args + " " + target + " %*\r\n" + cmd = head + prog + " " + args + " " + target + " %*\r\n" + foot } // #!/bin/sh @@ -228,7 +246,7 @@ function writeShim_ (from, to, prog, args, variables, cb) { } function chmodShim (to, cb) { - var then = times(2, cb, cb) + var then = times(3, cb, cb) fs.chmod(to, "0755", then) fs.chmod(to + ".cmd", "0755", then) fs.chmod(to + ".ps1", "0755", then) diff --git a/node_modules/cmd-shim/lib/to-batch-syntax.js b/node_modules/cmd-shim/lib/to-batch-syntax.js index d8bed1a634a01..734be551d2568 100644 --- a/node_modules/cmd-shim/lib/to-batch-syntax.js +++ b/node_modules/cmd-shim/lib/to-batch-syntax.js @@ -36,7 +36,6 @@ function replaceDollarWithPercentPair(value) { var dollarExpressions = /\$\{?([^\$@#\?\- \t{}:]+)\}?/g var result = "" var startIndex = 0 - value = value || "" do { var match = dollarExpressions.exec(value) if(match) { diff --git a/node_modules/cmd-shim/package.json b/node_modules/cmd-shim/package.json index 4faeff6645a98..5b4faf9226060 100644 --- a/node_modules/cmd-shim/package.json +++ b/node_modules/cmd-shim/package.json @@ -1,28 +1,27 @@ { - "_from": "cmd-shim@2.1.0", - "_id": "cmd-shim@2.1.0", + "_from": "cmd-shim@3.0.0", + "_id": "cmd-shim@3.0.0", "_inBundle": false, - "_integrity": "sha512-A5C0Cyf2H8sKsHqX0tvIWRXw5/PK++3Dc0lDbsugr90nOECLLuSPahVQBG8pgmgiXgm/TzBWMqI2rWdZwHduAw==", + "_integrity": "sha512-9cl9KcmjzrOZhA/mLl2qwhFaPLr6HpbbuPjMWPdDQ7EVrIOQJsI1JvzMur87mgaeCAtwRb5WNS2SBnC9uZDWwg==", "_location": "/cmd-shim", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "cmd-shim@2.1.0", + "raw": "cmd-shim@3.0.0", "name": "cmd-shim", "escapedName": "cmd-shim", - "rawSpec": "2.1.0", + "rawSpec": "3.0.0", "saveSpec": null, - "fetchSpec": "2.1.0" + "fetchSpec": "3.0.0" }, "_requiredBy": [ "#USER", - "/", - "/bin-links" + "/" ], - "_resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-2.1.0.tgz", - "_shasum": "e59a08d4248dda3bb502044083a4db4ac890579a", - "_spec": "cmd-shim@2.1.0", + "_resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-3.0.0.tgz", + "_shasum": "738b3532187238c4b69682345c2ad930e99b7750", + "_spec": "cmd-shim@3.0.0", "_where": "/Users/isaacs/dev/npm/cli", "bugs": { "url": "https://github.com/npm/cmd-shim/issues" @@ -36,7 +35,7 @@ "description": "Used in npm for command line application support", "devDependencies": { "rimraf": "~2.2.8", - "tap": "^1.2.0" + "tap": "^12.7.0" }, "homepage": "https://github.com/npm/cmd-shim#readme", "license": "ISC", @@ -46,7 +45,11 @@ "url": "git+https://github.com/npm/cmd-shim.git" }, "scripts": { - "test": "tap test/*.js" + "postpublish": "git push origin --follow-tags", + "postversion": "npm publish", + "preversion": "npm test", + "snap": "TAP_SNAPSHOT=1 tap test/*.js --100", + "test": "tap test/*.js --100" }, - "version": "2.1.0" + "version": "3.0.0" } diff --git a/node_modules/cmd-shim/tap-snapshots/test-basic.js-TAP.test.js b/node_modules/cmd-shim/tap-snapshots/test-basic.js-TAP.test.js new file mode 100644 index 0000000000000..e0947c6c5a692 --- /dev/null +++ b/node_modules/cmd-shim/tap-snapshots/test-basic.js-TAP.test.js @@ -0,0 +1,440 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/basic.js TAP env shebang > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +\\r +IF EXIST "%dp0%\\node.exe" (\\r + SET "_prog=%dp0%\\node.exe"\\r +) ELSE (\\r + SET "_prog=node"\\r + SET PATHEXT=%PATHEXT:;.JS;=;%\\r +)\\r +\\r +"%_prog%" "%dp0%\\from.env" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP env shebang > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir/node$exe") { + & "$basedir/node$exe" "$basedir/from.env" $args + $ret=$LASTEXITCODE +} else { + & "node$exe" "$basedir/from.env" $args + $ret=$LASTEXITCODE +} +exit $ret + +` + +exports[`test/basic.js TAP env shebang > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/node" ]; then + "$basedir/node" "$basedir/from.env" "$@" + ret=$? +else + node "$basedir/from.env" "$@" + ret=$? +fi +exit $ret + +` + +exports[`test/basic.js TAP env shebang with args > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +\\r +IF EXIST "%dp0%\\node.exe" (\\r + SET "_prog=%dp0%\\node.exe"\\r +) ELSE (\\r + SET "_prog=node"\\r + SET PATHEXT=%PATHEXT:;.JS;=;%\\r +)\\r +\\r +"%_prog%" --expose_gc "%dp0%\\from.env.args" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP env shebang with args > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir/node$exe") { + & "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args + $ret=$LASTEXITCODE +} else { + & "node$exe" --expose_gc "$basedir/from.env.args" $args + $ret=$LASTEXITCODE +} +exit $ret + +` + +exports[`test/basic.js TAP env shebang with args > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/node" ]; then + "$basedir/node" --expose_gc "$basedir/from.env.args" "$@" + ret=$? +else + node --expose_gc "$basedir/from.env.args" "$@" + ret=$? +fi +exit $ret + +` + +exports[`test/basic.js TAP env shebang with variables > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +@SET NODE_PATH=./lib:%NODE_PATH%\\r +\\r +IF EXIST "%dp0%\\node.exe" (\\r + SET "_prog=%dp0%\\node.exe"\\r +) ELSE (\\r + SET "_prog=node"\\r + SET PATHEXT=%PATHEXT:;.JS;=;%\\r +)\\r +\\r +"%_prog%" "%dp0%\\from.env.variables" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP env shebang with variables > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir/node$exe") { + & "$basedir/node$exe" "$basedir/from.env.variables" $args + $ret=$LASTEXITCODE +} else { + & "node$exe" "$basedir/from.env.variables" $args + $ret=$LASTEXITCODE +} +exit $ret + +` + +exports[`test/basic.js TAP env shebang with variables > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/node" ]; then + NODE_PATH=./lib:$NODE_PATH "$basedir/node" "$basedir/from.env.variables" "$@" + ret=$? +else + NODE_PATH=./lib:$NODE_PATH node "$basedir/from.env.variables" "$@" + ret=$? +fi +exit $ret + +` + +exports[`test/basic.js TAP explicit shebang > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +\\r +IF EXIST "%dp0%\\/usr/bin/sh.exe" (\\r + SET "_prog=%dp0%\\/usr/bin/sh.exe"\\r +) ELSE (\\r + SET "_prog=/usr/bin/sh"\\r + SET PATHEXT=%PATHEXT:;.JS;=;%\\r +)\\r +\\r +"%_prog%" "%dp0%\\from.sh" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP explicit shebang > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir//usr/bin/sh$exe") { + & "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args + $ret=$LASTEXITCODE +} else { + & "/usr/bin/sh$exe" "$basedir/from.sh" $args + $ret=$LASTEXITCODE +} +exit $ret + +` + +exports[`test/basic.js TAP explicit shebang > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir//usr/bin/sh" ]; then + "$basedir//usr/bin/sh" "$basedir/from.sh" "$@" + ret=$? +else + /usr/bin/sh "$basedir/from.sh" "$@" + ret=$? +fi +exit $ret + +` + +exports[`test/basic.js TAP explicit shebang with args > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +\\r +IF EXIST "%dp0%\\/usr/bin/sh.exe" (\\r + SET "_prog=%dp0%\\/usr/bin/sh.exe"\\r +) ELSE (\\r + SET "_prog=/usr/bin/sh"\\r + SET PATHEXT=%PATHEXT:;.JS;=;%\\r +)\\r +\\r +"%_prog%" -x "%dp0%\\from.sh.args" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP explicit shebang with args > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir//usr/bin/sh$exe") { + & "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args + $ret=$LASTEXITCODE +} else { + & "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args + $ret=$LASTEXITCODE +} +exit $ret + +` + +exports[`test/basic.js TAP explicit shebang with args > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir//usr/bin/sh" ]; then + "$basedir//usr/bin/sh" -x "$basedir/from.sh.args" "$@" + ret=$? +else + /usr/bin/sh -x "$basedir/from.sh.args" "$@" + ret=$? +fi +exit $ret + +` + +exports[`test/basic.js TAP if exists (it does exist) > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +"%dp0%\\from.exe" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP if exists (it does exist) > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +& "$basedir/from.exe" $args +exit $LASTEXITCODE + +` + +exports[`test/basic.js TAP if exists (it does exist) > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +"$basedir/from.exe" "$@" +exit $? + +` + +exports[`test/basic.js TAP just proceed if reading fails > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +"%dp0%\\" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP just proceed if reading fails > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +& "$basedir/" $args +exit $LASTEXITCODE + +` + +exports[`test/basic.js TAP just proceed if reading fails > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +"$basedir/" "$@" +exit $? + +` + +exports[`test/basic.js TAP no shebang > cmd 1`] = ` +@ECHO off\\r +SETLOCAL\\r +CALL find_dp0\\r +"%dp0%\\from.exe" %*\\r +ENDLOCAL\\r +EXIT /b\\r +find_dp0:\\r +SET dp0=%~dp0\\r +EXIT /b\\r + +` + +exports[`test/basic.js TAP no shebang > ps1 1`] = ` +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +& "$basedir/from.exe" $args +exit $LASTEXITCODE + +` + +exports[`test/basic.js TAP no shebang > shell 1`] = ` +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; +esac + +"$basedir/from.exe" "$@" +exit $? + +` diff --git a/node_modules/cmd-shim/test.bat b/node_modules/cmd-shim/test.bat new file mode 100644 index 0000000000000..a37cd7719692c --- /dev/null +++ b/node_modules/cmd-shim/test.bat @@ -0,0 +1,20 @@ + +@echo off +ECHO.%0 | FINDSTR /C:\ /C:/ >NUL && ( + @echo st dir to dp0 + SET dir=%~dp0 +) || ( + FOR /F %%i IN ('where %0') DO @SET dir=%%~dpi +) + +echo 0 = %0 +echo dp0 = %~dp0 +echo dir = %dir% + +call :find_bin +echo dir after call = %dir% +exit /b + +:find_bin +set dir=%~dp0 +exit /b diff --git a/node_modules/cmd-shim/test/basic.js b/node_modules/cmd-shim/test/basic.js index 4d92557f4e0f7..98b207cfc7ffb 100755 --- a/node_modules/cmd-shim/test/basic.js +++ b/node_modules/cmd-shim/test/basic.js @@ -1,9 +1,13 @@ var test = require('tap').test var mkdirp = require('mkdirp') +var rimraf = require('rimraf') var fs = require('fs') var path = require('path') var fixtures = path.resolve(__dirname, 'fixtures') +const matchSnapshot = (t, found, name) => + t.matchSnapshot(found.replace(/\r/g, '\\r'), name) + var cmdShim = require('../') test('no shebang', function (t) { @@ -12,30 +16,78 @@ test('no shebang', function (t) { cmdShim(from, to, function(er) { if (er) throw er - t.equal(fs.readFileSync(to, 'utf8'), - "#!/bin/sh"+ - "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ - "\n"+ - "\ncase `uname` in"+ - "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ - "\nesac"+ - "\n"+ - "\n\"$basedir/from.exe\" \"$@\"\nexit $?\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), - "@\"%~dp0\\from.exe\" %*\r\n") - t.equal(fs.readFileSync(to + '.ps1', 'utf8'), - '#!/usr/bin/env pwsh'+ - '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ - '\n'+ - '\n$exe=""'+ - '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ - '\n # Fix case when both the Windows and Linux builds of Node'+ - '\n # are installed in the same directory'+ - '\n $exe=".exe"'+ - '\n}'+ - '\n& "$basedir/from.exe" $args'+ - '\nexit $LASTEXITCODE'+ - '\n') + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') + t.end() + }) +}) + +test('if exists (it does exist)', function (t) { + var from = path.resolve(fixtures, 'from.exe') + var to = path.resolve(fixtures, 'exe.shim') + cmdShim.ifExists(from, to, function(er) { + if (er) + throw er + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') + t.end() + }) +}) + +test('if exists (it does not exist)', function (t) { + var from = path.resolve(fixtures, 'argle bargle we like to sparkle') + var to = path.resolve(fixtures, 'argle-bargle-shim') + cmdShim.ifExists(from, to, function(er) { + if (er) + throw er + t.throws(() => fs.statSync(to)) + t.throws(() => fs.statSync(to + '.cmd')) + t.throws(() => fs.statSync(to + '.ps1')) + t.end() + }) +}) + +test('fails if from doesnt exist', t => { + var from = path.resolve(fixtures, 'argle bargle we like to sparkle') + var to = path.resolve(fixtures, 'argle-bargle-shim') + cmdShim(from, to, function(er) { + t.match(er, { code: 'ENOENT' }) + t.end() + }) +}) + +test('fails if mkdir fails', t => { + var from = path.resolve(fixtures, 'from.env') + var to = path.resolve(fixtures, 'from.env/a/b/c') + cmdShim(from, to, er => { + t.match(er, { code: 'ENOTDIR' }) + t.end() + }) +}) + +test('fails if to is a dir', t => { + var from = path.resolve(fixtures, 'from.env') + var to = path.resolve(fixtures) + cmdShim(from, to, er => { + t.match(er, { code: 'EISDIR' }) + rimraf.sync(to + '.cmd') + rimraf.sync(to + '.ps1') + t.end() + }) +}) + +test('just proceed if reading fails', t => { + var from = fixtures + var to = path.resolve(fixtures, 'env.shim') + cmdShim(from, to, er => { + if (er) + throw er + + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') t.end() }) }) @@ -47,36 +99,9 @@ test('env shebang', function (t) { if (er) throw er - t.equal(fs.readFileSync(to, 'utf8'), - "#!/bin/sh" + - "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + - "\n" + - "\ncase `uname` in" + - "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + - "\nesac" + - "\n" + - "\nif [ -x \"$basedir/node\" ]; then" + - "\n \"$basedir/node\" \"$basedir/from.env\" \"$@\"" + - "\n ret=$?" + - "\nelse " + - "\n node \"$basedir/from.env\" \"$@\"" + - "\n ret=$?" + - "\nfi" + - "\nexit $ret" + - "\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), - "@SETLOCAL\r" + - "\n\r" + - "\n@IF EXIST \"%~dp0\\node.exe\" (\r" + - "\n @SET \"_prog=%~dp0\\node.exe\"\r" + - "\n) ELSE (\r" + - "\n @SET \"_prog=node\"\r" + - "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + - "\n)\r" + - "\n\r" + - "\n\"%_prog%\" \"%~dp0\\from.env\" %*\r" + - "\n@ENDLOCAL\r" + - "\n") + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') t.end() }) }) @@ -88,56 +113,9 @@ test('env shebang with args', function (t) { if (er) throw er - t.equal(fs.readFileSync(to, 'utf8'), - "#!/bin/sh"+ - "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ - "\n"+ - "\ncase `uname` in"+ - "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ - "\nesac"+ - "\n"+ - "\nif [ -x \"$basedir/node\" ]; then"+ - "\n \"$basedir/node\" --expose_gc \"$basedir/from.env.args\" \"$@\""+ - "\n ret=$?"+ - "\nelse "+ - "\n node --expose_gc \"$basedir/from.env.args\" \"$@\""+ - "\n ret=$?"+ - "\nfi"+ - "\nexit $ret"+ - "\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), - "@SETLOCAL\r" + - "\n\r" + - "\n@IF EXIST \"%~dp0\\node.exe\" (\r" + - "\n @SET \"_prog=%~dp0\\node.exe\"\r" + - "\n) ELSE (\r" + - "\n @SET \"_prog=node\"\r" + - "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + - "\n)\r" + - "\n\r" + - "\n\"%_prog%\" --expose_gc \"%~dp0\\from.env.args\" %*\r" + - "\n@ENDLOCAL\r" + - "\n") - t.equal(fs.readFileSync(to + '.ps1', 'utf8'), - '#!/usr/bin/env pwsh'+ - '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ - '\n'+ - '\n$exe=""'+ - '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ - '\n # Fix case when both the Windows and Linux builds of Node'+ - '\n # are installed in the same directory'+ - '\n $exe=".exe"'+ - '\n}'+ - '\n$ret=0'+ - '\nif (Test-Path "$basedir/node$exe") {'+ - '\n & "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n} else {'+ - '\n & "node$exe" --expose_gc "$basedir/from.env.args" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n}'+ - '\nexit $ret'+ - '\n') + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') t.end() }) }) @@ -149,56 +127,9 @@ test('env shebang with variables', function (t) { if (er) throw er - t.equal(fs.readFileSync(to, 'utf8'), - "#!/bin/sh"+ - "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + - "\n"+ - "\ncase `uname` in"+ - "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ - "\nesac"+ - "\n"+ - "\nif [ -x \"$basedir/node\" ]; then"+ - "\n NODE_PATH=./lib:$NODE_PATH \"$basedir/node\" \"$basedir/from.env.variables\" \"$@\""+ - "\n ret=$?"+ - "\nelse "+ - "\n NODE_PATH=./lib:$NODE_PATH node \"$basedir/from.env.variables\" \"$@\""+ - "\n ret=$?"+ - "\nfi"+ - "\nexit $ret"+ - "\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), - "@SETLOCAL\r"+ - "\n@SET NODE_PATH=./lib:%NODE_PATH%\r"+ - "\n\r" + - "\n@IF EXIST \"%~dp0\\node.exe\" (\r"+ - "\n @SET \"_prog=%~dp0\\node.exe\"\r" + - "\n) ELSE (\r"+ - "\n @SET \"_prog=node\"\r"+ - "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + - "\n)\r"+ - "\n\r"+ - "\n\"%_prog%\" \"%~dp0\\from.env.variables\" %*\r"+ - "\n@ENDLOCAL\r\n") - t.equal(fs.readFileSync(to + '.ps1', 'utf8'), - '#!/usr/bin/env pwsh'+ - '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ - '\n'+ - '\n$exe=""'+ - '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ - '\n # Fix case when both the Windows and Linux builds of Node'+ - '\n # are installed in the same directory'+ - '\n $exe=".exe"'+ - '\n}'+ - '\n$ret=0'+ - '\nif (Test-Path "$basedir/node$exe") {'+ - '\n & "$basedir/node$exe" "$basedir/from.env.variables" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n} else {'+ - '\n & "node$exe" "$basedir/from.env.variables" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n}'+ - '\nexit $ret'+ - '\n') + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') t.end() }) }) @@ -210,58 +141,9 @@ test('explicit shebang', function (t) { if (er) throw er - t.equal(fs.readFileSync(to, 'utf8'), - "#!/bin/sh" + - "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + - "\n" + - "\ncase `uname` in" + - "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + - "\nesac" + - "\n" + - "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" + - "\n \"$basedir//usr/bin/sh\" \"$basedir/from.sh\" \"$@\"" + - "\n ret=$?" + - "\nelse " + - "\n /usr/bin/sh \"$basedir/from.sh\" \"$@\"" + - "\n ret=$?" + - "\nfi" + - "\nexit $ret" + - "\n") - - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), - "@SETLOCAL\r" + - "\n\r" + - "\n@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + - "\n @SET \"_prog=%~dp0\\/usr/bin/sh.exe\"\r" + - "\n) ELSE (\r" + - "\n @SET \"_prog=/usr/bin/sh\"\r" + - "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + - "\n)\r" + - "\n\r" + - "\n\"%_prog%\" \"%~dp0\\from.sh\" %*\r" + - "\n@ENDLOCAL\r" + - "\n") - - t.equal(fs.readFileSync(to + '.ps1', 'utf8'), - '#!/usr/bin/env pwsh'+ - '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ - '\n'+ - '\n$exe=""'+ - '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ - '\n # Fix case when both the Windows and Linux builds of Node'+ - '\n # are installed in the same directory'+ - '\n $exe=".exe"'+ - '\n}'+ - '\n$ret=0'+ - '\nif (Test-Path "$basedir//usr/bin/sh$exe") {'+ - '\n & "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n} else {'+ - '\n & "/usr/bin/sh$exe" "$basedir/from.sh" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n}'+ - '\nexit $ret'+ - '\n') + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') t.end() }) }) @@ -273,58 +155,9 @@ test('explicit shebang with args', function (t) { if (er) throw er - t.equal(fs.readFileSync(to, 'utf8'), - "#!/bin/sh" + - "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + - "\n" + - "\ncase `uname` in" + - "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + - "\nesac" + - "\n" + - "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" + - "\n \"$basedir//usr/bin/sh\" -x \"$basedir/from.sh.args\" \"$@\"" + - "\n ret=$?" + - "\nelse " + - "\n /usr/bin/sh -x \"$basedir/from.sh.args\" \"$@\"" + - "\n ret=$?" + - "\nfi" + - "\nexit $ret" + - "\n") - - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), - "@SETLOCAL\r" + - "\n\r" + - "\n@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + - "\n @SET \"_prog=%~dp0\\/usr/bin/sh.exe\"\r" + - "\n) ELSE (\r" + - "\n @SET \"_prog=/usr/bin/sh\"\r" + - "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r" + - "\n)\r" + - "\n\r" + - "\n\"%_prog%\" -x \"%~dp0\\from.sh.args\" %*\r" + - "\n@ENDLOCAL\r" + - "\n") - - t.equal(fs.readFileSync(to + '.ps1', 'utf8'), - '#!/usr/bin/env pwsh'+ - '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent'+ - '\n'+ - '\n$exe=""'+ - '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {'+ - '\n # Fix case when both the Windows and Linux builds of Node'+ - '\n # are installed in the same directory'+ - '\n $exe=".exe"'+ - '\n}'+ - '\n$ret=0'+ - '\nif (Test-Path "$basedir//usr/bin/sh$exe") {'+ - '\n & "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n} else {'+ - '\n & "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args'+ - '\n $ret=$LASTEXITCODE'+ - '\n}'+ - '\nexit $ret'+ - '\n') + matchSnapshot(t, fs.readFileSync(to, 'utf8'), 'shell') + matchSnapshot(t, fs.readFileSync(to + '.cmd', 'utf8'), 'cmd') + matchSnapshot(t, fs.readFileSync(to + '.ps1', 'utf8'), 'ps1') t.end() }) }) diff --git a/package-lock.json b/package-lock.json index bd95d426ae3ab..9e2429eb65d4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -472,6 +472,17 @@ "gentle-fs": "^2.0.0", "graceful-fs": "^4.1.11", "write-file-atomic": "^2.3.0" + }, + "dependencies": { + "cmd-shim": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-2.1.0.tgz", + "integrity": "sha512-A5C0Cyf2H8sKsHqX0tvIWRXw5/PK++3Dc0lDbsugr90nOECLLuSPahVQBG8pgmgiXgm/TzBWMqI2rWdZwHduAw==", + "requires": { + "graceful-fs": "^4.1.2", + "mkdirp": "~0.5.0" + } + } } }, "bind-obj-methods": { @@ -786,9 +797,9 @@ } }, "cmd-shim": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-2.1.0.tgz", - "integrity": "sha512-A5C0Cyf2H8sKsHqX0tvIWRXw5/PK++3Dc0lDbsugr90nOECLLuSPahVQBG8pgmgiXgm/TzBWMqI2rWdZwHduAw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-3.0.0.tgz", + "integrity": "sha512-9cl9KcmjzrOZhA/mLl2qwhFaPLr6HpbbuPjMWPdDQ7EVrIOQJsI1JvzMur87mgaeCAtwRb5WNS2SBnC9uZDWwg==", "requires": { "graceful-fs": "^4.1.2", "mkdirp": "~0.5.0" diff --git a/package.json b/package.json index fcb9e191b0434..968f1775ce1df 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "ci-info": "^2.0.0", "cli-columns": "^3.1.2", "cli-table3": "^0.5.1", - "cmd-shim": "^2.1.0", + "cmd-shim": "^3.0.0", "columnify": "~1.5.4", "config-chain": "^1.1.12", "detect-indent": "~5.0.0",