Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2019-08-12 22:09:50 +0300
committerisaacs <i@izs.me>2019-08-12 22:09:51 +0300
commitaa22ff6ea28dcb17e9f2b1bc87f2a4b5b868bf8a (patch)
tree24afe4935bbddb9268b937ff079204a41f1b7e39 /node_modules
parentaaf98e88c78fd6c850d0a3d3ee2f61c02f63bc8c (diff)
cmd-shim@2.1.0
- [`9c93ac3`](https://github.com/npm/cmd-shim/commit/9c93ac39e95b0d6ae852e842e4c5dba5e19687c2) [#2](https://github.com/npm/cmd-shim/pull/2) [npm#3380](https://github.com/npm/npm/issues/3380) Handle environment variables properly ([@basbossink](https://github.com/basbossink)) - [`2d277f8`](https://github.com/npm/cmd-shim/commit/2d277f8e84d45401747b0b9470058f168b974ad5) [#25](https://github.com/npm/cmd-shim/pull/25) [#36](https://github.com/npm/cmd-shim/pull/36) [#35](https://github.com/npm/cmd-shim/pull/35) Fix 'no shebang' case by always providing `$basedir` in shell script ([@igorklopov](https://github.com/igorklopov)) - [`adaf20b`](https://github.com/npm/cmd-shim/commit/adaf20b7fa2c09c2111a2506c6a3e53ed0831f88) [#26](https://github.com/npm/cmd-shim/pull/26) Fix `$*` causing an error when arguments contain parentheses ([@satazor](https://github.com/satazor)) - [`49f0c13`](https://github.com/npm/cmd-shim/commit/49f0c1318fd384e0031c3fd43801f0e22e1e555f) [#30](https://github.com/npm/cmd-shim/pull/30) Fix paths for MSYS/MINGW bash ([@dscho](https://github.com/dscho)) - [`51a8af3`](https://github.com/npm/cmd-shim/commit/51a8af30990cb072cb30d67fc1b564b14746bba9) [#34](https://github.com/npm/cmd-shim/pull/34) Add proper support for PowerShell ([@ExE-Boss](https://github.com/ExE-Boss))
Diffstat (limited to 'node_modules')
-rw-r--r--node_modules/cmd-shim/.npmignore16
-rw-r--r--node_modules/cmd-shim/.travis.yml19
-rw-r--r--node_modules/cmd-shim/LICENSE36
-rw-r--r--node_modules/cmd-shim/README.md4
-rw-r--r--node_modules/cmd-shim/cmd-shim-2.0.2.tgzbin0 -> 5643 bytes
-rw-r--r--node_modules/cmd-shim/index.js127
-rw-r--r--node_modules/cmd-shim/lib/to-batch-syntax.js52
-rw-r--r--node_modules/cmd-shim/package.json40
-rw-r--r--node_modules/cmd-shim/test/00-setup.js1
-rwxr-xr-xnode_modules/cmd-shim/test/basic.js251
-rw-r--r--node_modules/cmd-shim/test/to-batch-syntax-tests.js25
11 files changed, 428 insertions, 143 deletions
diff --git a/node_modules/cmd-shim/.npmignore b/node_modules/cmd-shim/.npmignore
deleted file mode 100644
index 699b5d4f1..000000000
--- a/node_modules/cmd-shim/.npmignore
+++ /dev/null
@@ -1,16 +0,0 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
-npm-debug.log
-
-node_modules
diff --git a/node_modules/cmd-shim/.travis.yml b/node_modules/cmd-shim/.travis.yml
index 2ca91f289..1d38b470c 100644
--- a/node_modules/cmd-shim/.travis.yml
+++ b/node_modules/cmd-shim/.travis.yml
@@ -1,4 +1,19 @@
language: node_js
+
node_js:
- - "0.10"
- - "0.8" \ No newline at end of file
+ - node
+ - 12
+ - 10
+ - 8
+ - 6
+
+os:
+ - linux
+ - windows
+
+cache:
+ directories:
+ - $HOME/.npm
+
+notifications:
+ email: false
diff --git a/node_modules/cmd-shim/LICENSE b/node_modules/cmd-shim/LICENSE
index 0c44ae716..20a476254 100644
--- a/node_modules/cmd-shim/LICENSE
+++ b/node_modules/cmd-shim/LICENSE
@@ -1,27 +1,15 @@
-Copyright (c) Isaac Z. Schlueter ("Author")
-All rights reserved.
+The ISC License
-The BSD License
+Copyright (c) npm, Inc. and Contributors
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
+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.
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+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/cmd-shim/README.md b/node_modules/cmd-shim/README.md
index ff6745f8e..2b8b2f468 100644
--- a/node_modules/cmd-shim/README.md
+++ b/node_modules/cmd-shim/README.md
@@ -5,8 +5,8 @@ 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/ForbesLindesay/cmd-shim/master.svg)](https://travis-ci.org/ForbesLindesay/cmd-shim)
-[![Dependency Status](https://img.shields.io/david/ForbesLindesay/cmd-shim.svg)](https://david-dm.org/ForbesLindesay/cmd-shim)
+[![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
diff --git a/node_modules/cmd-shim/cmd-shim-2.0.2.tgz b/node_modules/cmd-shim/cmd-shim-2.0.2.tgz
new file mode 100644
index 000000000..2d4a97075
--- /dev/null
+++ b/node_modules/cmd-shim/cmd-shim-2.0.2.tgz
Binary files differ
diff --git a/node_modules/cmd-shim/index.js b/node_modules/cmd-shim/index.js
index 9f22e103a..722ad9158 100644
--- a/node_modules/cmd-shim/index.js
+++ b/node_modules/cmd-shim/index.js
@@ -15,7 +15,8 @@ var fs = require("graceful-fs")
var mkdir = require("mkdirp")
, path = require("path")
- , shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/
+ , 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) {
@@ -63,51 +64,70 @@ function writeShim (from, to, cb) {
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, cb)
- var prog = shebang[1]
- , args = shebang[2] || ""
- return writeShim_(from, to, prog, args, cb)
+ 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, 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" (
- // "%~dp0\node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
+ // @SET "_prog=%~dp0\node.exe"
// ) ELSE (
- // SETLOCAL
- // SET PATHEXT=%PATHEXT:;.JS;=;%
- // node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
+ // @SET "_prog=node"
+ // @SET PATHEXT=%PATHEXT:;.JS;=;%
// )
+ //
+ // "%_prog%" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
+ // @ENDLOCAL
var cmd
if (longProg) {
- cmd = "@IF EXIST " + longProg + " (\r\n"
- + " " + longProg + " " + args + " " + target + " %*\r\n"
+ 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"
- + " @SETLOCAL\r\n"
+ + " @SET \"_prog=" + prog.replace(/(^")|("$)/g, '') + "\"\r\n"
+ " @SET PATHEXT=%PATHEXT:;.JS;=;%\r\n"
- + " " + prog + " " + args + " " + target + " %*\r\n"
- + ")"
+ + ")\r\n"
+ + "\r\n"
+ + "\"%_prog%\" " + args + " " + target + " %*\r\n"
+ + '@ENDLOCAL\r\n'
} else {
cmd = "@" + prog + " " + args + " " + target + " %*\r\n"
}
@@ -116,7 +136,7 @@ function writeShim_ (from, to, prog, args, cb) {
// basedir=`dirname "$0"`
//
// case `uname` in
- // *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+ // *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
// esac
//
// if [ -x "$basedir/node.exe" ]; then
@@ -130,30 +150,76 @@ function writeShim_ (from, to, prog, args, cb) {
var sh = "#!/bin/sh\n"
- if (shLongProg) {
- sh = sh
- + "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n"
- + "\n"
- + "case `uname` in\n"
- + " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n"
- + "esac\n"
- + "\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"
- + " " + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
+ + " " + variables + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
+ " ret=$?\n"
+ "else \n"
- + " " + shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ + " " + variables + shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ " ret=$?\n"
+ "fi\n"
+ "exit $ret\n"
} else {
- sh = shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ sh = sh
+ + shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ "exit $?\n"
}
- var then = times(2, next, cb)
+ // #!/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 () {
@@ -163,8 +229,9 @@ function writeShim_ (from, to, prog, args, 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, "0755", then)
+ fs.chmod(to + ".cmd", "0755", then)
+ fs.chmod(to + ".ps1", "0755", then)
}
function times(n, ok, cb) {
diff --git a/node_modules/cmd-shim/lib/to-batch-syntax.js b/node_modules/cmd-shim/lib/to-batch-syntax.js
new file mode 100644
index 000000000..d8bed1a63
--- /dev/null
+++ b/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/cmd-shim/package.json b/node_modules/cmd-shim/package.json
index 97e73e46f..4faeff664 100644
--- a/node_modules/cmd-shim/package.json
+++ b/node_modules/cmd-shim/package.json
@@ -1,54 +1,52 @@
{
- "_args": [
- [
- "cmd-shim@2.0.2",
- "/Users/rebecca/code/npm"
- ]
- ],
- "_from": "cmd-shim@2.0.2",
- "_id": "cmd-shim@2.0.2",
+ "_from": "cmd-shim@2.1.0",
+ "_id": "cmd-shim@2.1.0",
"_inBundle": false,
- "_integrity": "sha1-b8vamUg6j9FdfTChlspp1oii79s=",
+ "_integrity": "sha512-A5C0Cyf2H8sKsHqX0tvIWRXw5/PK++3Dc0lDbsugr90nOECLLuSPahVQBG8pgmgiXgm/TzBWMqI2rWdZwHduAw==",
"_location": "/cmd-shim",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
- "raw": "cmd-shim@2.0.2",
+ "raw": "cmd-shim@2.1.0",
"name": "cmd-shim",
"escapedName": "cmd-shim",
- "rawSpec": "2.0.2",
+ "rawSpec": "2.1.0",
"saveSpec": null,
- "fetchSpec": "2.0.2"
+ "fetchSpec": "2.1.0"
},
"_requiredBy": [
+ "#USER",
"/",
"/bin-links"
],
- "_resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-2.0.2.tgz",
- "_spec": "2.0.2",
- "_where": "/Users/rebecca/code/npm",
+ "_resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-2.1.0.tgz",
+ "_shasum": "e59a08d4248dda3bb502044083a4db4ac890579a",
+ "_spec": "cmd-shim@2.1.0",
+ "_where": "/Users/isaacs/dev/npm/cli",
"bugs": {
- "url": "https://github.com/ForbesLindesay/cmd-shim/issues"
+ "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": "~0.4.11"
+ "tap": "^1.2.0"
},
- "homepage": "https://github.com/ForbesLindesay/cmd-shim#readme",
- "license": "BSD-2-Clause",
+ "homepage": "https://github.com/npm/cmd-shim#readme",
+ "license": "ISC",
"name": "cmd-shim",
"repository": {
"type": "git",
- "url": "git+https://github.com/ForbesLindesay/cmd-shim.git"
+ "url": "git+https://github.com/npm/cmd-shim.git"
},
"scripts": {
"test": "tap test/*.js"
},
- "version": "2.0.2"
+ "version": "2.1.0"
}
diff --git a/node_modules/cmd-shim/test/00-setup.js b/node_modules/cmd-shim/test/00-setup.js
index 04ec2b256..c9a7d3920 100644
--- a/node_modules/cmd-shim/test/00-setup.js
+++ b/node_modules/cmd-shim/test/00-setup.js
@@ -8,6 +8,7 @@ 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'
}
diff --git a/node_modules/cmd-shim/test/basic.js b/node_modules/cmd-shim/test/basic.js
index 09823158b..4d92557f4 100755
--- a/node_modules/cmd-shim/test/basic.js
+++ b/node_modules/cmd-shim/test/basic.js
@@ -13,9 +13,29 @@ test('no shebang', function (t) {
if (er)
throw er
t.equal(fs.readFileSync(to, 'utf8'),
- "\"$basedir/from.exe\" \"$@\"\nexit $?\n")
+ "#!/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()
})
})
@@ -26,72 +46,159 @@ test('env shebang', function (t) {
cmdShim(from, to, function(er) {
if (er)
throw er
- console.error('%j', fs.readFileSync(to, 'utf8'))
- console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
+
+ 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*) basedir=`cygpath -w \"$basedir\"`;;"+
+ "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+
"\nesac"+
"\n"+
"\nif [ -x \"$basedir/node\" ]; then"+
- "\n \"$basedir/node\" \"$basedir/from.env\" \"$@\""+
+ "\n \"$basedir/node\" --expose_gc \"$basedir/from.env.args\" \"$@\""+
"\n ret=$?"+
"\nelse "+
- "\n node \"$basedir/from.env\" \"$@\""+
+ "\n node --expose_gc \"$basedir/from.env.args\" \"$@\""+
"\n ret=$?"+
"\nfi"+
"\nexit $ret"+
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
- "@IF EXIST \"%~dp0\\node.exe\" (\r"+
- "\n \"%~dp0\\node.exe\" \"%~dp0\\from.env\" %*\r"+
- "\n) ELSE (\r"+
- "\n @SETLOCAL\r"+
- "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
- "\n node \"%~dp0\\from.env\" %*\r"+
- "\n)")
+ "@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 args', function (t) {
- var from = path.resolve(fixtures, 'from.env.args')
- var to = path.resolve(fixtures, 'env.args.shim')
+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
- console.error('%j', fs.readFileSync(to, 'utf8'))
- console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh"+
- "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
+ "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
"\n"+
"\ncase `uname` in"+
- "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
+ "\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 NODE_PATH=./lib:$NODE_PATH \"$basedir/node\" \"$basedir/from.env.variables\" \"$@\""+
"\n ret=$?"+
"\nelse "+
- "\n node --expose_gc \"$basedir/from.env.args\" \"$@\""+
+ "\n NODE_PATH=./lib:$NODE_PATH node \"$basedir/from.env.variables\" \"$@\""+
"\n ret=$?"+
"\nfi"+
"\nexit $ret"+
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
- "@IF EXIST \"%~dp0\\node.exe\" (\r"+
- "\n \"%~dp0\\node.exe\" --expose_gc \"%~dp0\\from.env.args\" %*\r"+
+ "@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 @SETLOCAL\r"+
- "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
- "\n node --expose_gc \"%~dp0\\from.env.args\" %*\r"+
- "\n)")
+ "\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()
})
})
@@ -102,15 +209,13 @@ test('explicit shebang', function (t) {
cmdShim(from, to, function(er) {
if (er)
throw er
- console.error('%j', fs.readFileSync(to, 'utf8'))
- console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh" +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
"\n" +
"\ncase `uname` in" +
- "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" +
+ "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" +
"\nesac" +
"\n" +
"\nif [ -x \"$basedir//usr/bin/sh\" ]; then" +
@@ -124,13 +229,39 @@ test('explicit shebang', function (t) {
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
- "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
- "\n \"%~dp0\\/usr/bin/sh.exe\" \"%~dp0\\from.sh\" %*\r" +
+ "@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 @SETLOCAL\r"+
- "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
- "\n /usr/bin/sh \"%~dp0\\from.sh\" %*\r" +
- "\n)")
+ "\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()
})
})
@@ -141,35 +272,59 @@ test('explicit shebang with args', function (t) {
cmdShim(from, to, function(er) {
if (er)
throw er
- console.error('%j', fs.readFileSync(to, 'utf8'))
- console.error('%j', fs.readFileSync(to + '.cmd', 'utf8'))
t.equal(fs.readFileSync(to, 'utf8'),
"#!/bin/sh" +
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" +
"\n" +
"\ncase `uname` in" +
- "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" +
+ "\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 \"$basedir//usr/bin/sh\" -x \"$basedir/from.sh.args\" \"$@\"" +
"\n ret=$?" +
"\nelse " +
- "\n /usr/bin/sh -x \"$basedir/from.sh.args\" \"$@\"" +
+ "\n /usr/bin/sh -x \"$basedir/from.sh.args\" \"$@\"" +
"\n ret=$?" +
"\nfi" +
"\nexit $ret" +
"\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
- "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
- "\n \"%~dp0\\/usr/bin/sh.exe\" -x \"%~dp0\\from.sh.args\" %*\r" +
+ "@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 @SETLOCAL\r"+
- "\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r"+
- "\n /usr/bin/sh -x \"%~dp0\\from.sh.args\" %*\r" +
- "\n)")
+ "\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/cmd-shim/test/to-batch-syntax-tests.js b/node_modules/cmd-shim/test/to-batch-syntax-tests.js
new file mode 100644
index 000000000..3645fd0a5
--- /dev/null
+++ b/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()
+})