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>2013-04-03 20:12:10 +0400
committerisaacs <i@izs.me>2013-04-03 20:12:10 +0400
commit42964846bfa74b3a0222d67a6b3b5cb9287d993b (patch)
treed67a45e9bc1b7b020f80311f00f826dab6ab148d /node_modules/cmd-shim
parent5f3fb144595dd08e37c6ac734ad8fa7f368163cc (diff)
cmd-shim@1.1.0
Diffstat (limited to 'node_modules/cmd-shim')
-rw-r--r--node_modules/cmd-shim/.npmignore16
-rw-r--r--node_modules/cmd-shim/.travis.yml4
-rw-r--r--node_modules/cmd-shim/LICENSE27
-rw-r--r--node_modules/cmd-shim/README.md42
-rw-r--r--node_modules/cmd-shim/index.js180
-rw-r--r--node_modules/cmd-shim/package.json28
-rw-r--r--node_modules/cmd-shim/test/00-setup.js34
-rw-r--r--node_modules/cmd-shim/test/basic.js167
-rw-r--r--node_modules/cmd-shim/test/zz-cleanup.js13
9 files changed, 511 insertions, 0 deletions
diff --git a/node_modules/cmd-shim/.npmignore b/node_modules/cmd-shim/.npmignore
new file mode 100644
index 000000000..69f75d26c
--- /dev/null
+++ b/node_modules/cmd-shim/.npmignore
@@ -0,0 +1,16 @@
+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
new file mode 100644
index 000000000..97e451583
--- /dev/null
+++ b/node_modules/cmd-shim/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - "0.10"
+ - "0.8" \ No newline at end of file
diff --git a/node_modules/cmd-shim/LICENSE b/node_modules/cmd-shim/LICENSE
new file mode 100644
index 000000000..6e93978e0
--- /dev/null
+++ b/node_modules/cmd-shim/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) Isaac Z. Schlueter ("Author")
+All rights reserved.
+
+The BSD License
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+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.
diff --git a/node_modules/cmd-shim/README.md b/node_modules/cmd-shim/README.md
new file mode 100644
index 000000000..fb997d5db
--- /dev/null
+++ b/node_modules/cmd-shim/README.md
@@ -0,0 +1,42 @@
+# 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://travis-ci.org/ForbesLindesay/cmd-shim.png?branch=master)](https://travis-ci.org/ForbesLindesay/cmd-shim) [![Dependency Status](https://gemnasium.com/ForbesLindesay/cmd-shim.png)](https://gemnasium.com/ForbesLindesay/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/index.js b/node_modules/cmd-shim/index.js
new file mode 100644
index 000000000..1cfd24edc
--- /dev/null
+++ b/node_modules/cmd-shim/index.js
@@ -0,0 +1,180 @@
+// 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 <prog> <args...>"
+// or:
+// "#!<prog> <args...>"
+//
+// Write a binroot/pkg.bin + ".cmd" file that has this line in it:
+// @<prog> <args...> %~dp0<target> %*
+
+module.exports = cmdShim
+cmdShim.ifExists = cmdShimIfExists
+
+try {
+ var fs = require("graceful-fs")
+} catch (e) {
+ var fs = require("fs")
+}
+
+var mkdir = require("mkdirp")
+ , path = require("path")
+ , shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\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, cb)
+ var prog = shebang[1]
+ , args = shebang[2] || ""
+ return writeShim_(from, to, prog, args, cb)
+ })
+ })
+}
+
+function writeShim_ (from, to, prog, args, cb) {
+ var shTarget = path.relative(path.dirname(to), from)
+ , target = shTarget.split("/").join("\\")
+ , longProg
+ , shProg = prog && prog.split("\\").join("/")
+ , shLongProg
+ shTarget = shTarget.split("\\").join("/")
+ args = args || ""
+ if (!prog) {
+ prog = "\"%~dp0\\" + target + "\""
+ shProg = "\"$basedir/" + shTarget + "\""
+ args = ""
+ target = ""
+ shTarget = ""
+ } else {
+ longProg = "\"%~dp0\\" + prog + ".exe\""
+ shLongProg = "\"$basedir/" + prog + "\""
+ target = "\"%~dp0\\" + target + "\""
+ shTarget = "\"$basedir/" + shTarget + "\""
+ }
+
+ // @IF EXIST "%~dp0\node.exe" (
+ // "%~dp0\node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
+ // ) ELSE (
+ // node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
+ // )
+ var cmd
+ if (longProg) {
+ cmd = "@IF EXIST " + longProg + " (\r\n"
+ + " " + longProg + " " + args + " " + target + " %*\r\n"
+ + ") ELSE (\r\n"
+ + " " + prog + " " + args + " " + target + " %*\r\n"
+ + ")"
+ } else {
+ cmd = prog + " " + args + " " + target + " %*\r\n"
+ }
+
+ // #!/bin/sh
+ // basedir=`dirname "$0"`
+ //
+ // case `uname` in
+ // *CYGWIN*) 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"
+
+ if (shLongProg) {
+ sh = sh
+ + "basedir=`dirname \"$0\"`\n"
+ + "\n"
+ + "case `uname` in\n"
+ + " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n"
+ + "esac\n"
+ + "\n"
+
+ sh = sh
+ + "if [ -x "+shLongProg+" ]; then\n"
+ + " " + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
+ + " ret=$?\n"
+ + "else \n"
+ + " " + shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ + " ret=$?\n"
+ + "fi\n"
+ + "exit $ret\n"
+ } else {
+ sh = shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ + "exit $?\n"
+ }
+
+ var then = times(2, next, cb)
+ 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)
+}
+
+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/cmd-shim/package.json b/node_modules/cmd-shim/package.json
new file mode 100644
index 000000000..409094507
--- /dev/null
+++ b/node_modules/cmd-shim/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "cmd-shim",
+ "version": "1.1.0",
+ "description": "Used in npm for command line application support",
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/ForbesLindesay/cmd-shim.git"
+ },
+ "license": "BSD",
+ "optionalDependencies": {
+ "graceful-fs": "1.2"
+ },
+ "dependencies": {
+ "mkdirp": "~0.3.3",
+ "graceful-fs": "1.2"
+ },
+ "devDependencies": {
+ "tap": "~0.4.1",
+ "rimraf": "~2.1.4"
+ },
+ "readme": "# cmd-shim\r\n\r\nThe cmd-shim used in npm to create executable scripts on Windows,\r\nsince symlinks are not suitable for this purpose there.\r\n\r\nOn Unix systems, you should use a symbolic link instead.\r\n\r\n[![Build Status](https://travis-ci.org/ForbesLindesay/cmd-shim.png?branch=master)](https://travis-ci.org/ForbesLindesay/cmd-shim) [![Dependency Status](https://gemnasium.com/ForbesLindesay/cmd-shim.png)](https://gemnasium.com/ForbesLindesay/cmd-shim)\r\n\r\n## Installation\r\n\r\n```\r\nnpm install cmd-shim\r\n```\r\n\r\n## API\r\n\r\n### cmdShim(from, to, cb)\r\n\r\nCreate a cmd shim at `to` for the command line program at `from`.\r\ne.g.\r\n\r\n```javascript\r\nvar cmdShim = require('cmd-shim');\r\ncmdShim(__dirname + '/cli.js', '/usr/bin/command-name', function (err) {\r\n if (err) throw err;\r\n});\r\n```\r\n\r\n### cmdShim.ifExists(from, to, cb)\r\n\r\nThe same as above, but will just continue if the file does not exist.\r\nSource:\r\n\r\n```javascript\r\nfunction cmdShimIfExists (from, to, cb) {\r\n fs.stat(from, function (er) {\r\n if (er) return cb()\r\n cmdShim(from, to, cb)\r\n })\r\n}\r\n```\r\n",
+ "readmeFilename": "README.md",
+ "_id": "cmd-shim@1.1.0",
+ "_from": "cmd-shim@"
+}
diff --git a/node_modules/cmd-shim/test/00-setup.js b/node_modules/cmd-shim/test/00-setup.js
new file mode 100644
index 000000000..f2689e6f4
--- /dev/null
+++ b/node_modules/cmd-shim/test/00-setup.js
@@ -0,0 +1,34 @@
+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.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/cmd-shim/test/basic.js b/node_modules/cmd-shim/test/basic.js
new file mode 100644
index 000000000..93da5ea26
--- /dev/null
+++ b/node_modules/cmd-shim/test/basic.js
@@ -0,0 +1,167 @@
+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'),
+ "\"$basedir/from.exe\" \"$@\"\nexit $?\n")
+ t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
+ "\"%~dp0\\from.exe\" %*\r\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
+ 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 \"$0\"`"+
+ "\n"+
+ "\ncase `uname` in"+
+ "\n *CYGWIN*) 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'),
+ "@IF EXIST \"%~dp0\\node.exe\" (\r"+
+ "\n \"%~dp0\\node.exe\" \"%~dp0\\from.env\" %*\r"+
+ "\n) ELSE (\r"+
+ "\n node \"%~dp0\\from.env\" %*\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
+ 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 \"$0\"`"+
+ "\n"+
+ "\ncase `uname` in"+
+ "\n *CYGWIN*) 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'),
+ "@IF EXIST \"%~dp0\\node.exe\" (\r"+
+ "\n \"%~dp0\\node.exe\" --expose_gc \"%~dp0\\from.env.args\" %*\r"+
+ "\n) ELSE (\r"+
+ "\n node --expose_gc \"%~dp0\\from.env.args\" %*\r"+
+ "\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
+ 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 \"$0\"`" +
+ "\n" +
+ "\ncase `uname` in" +
+ "\n *CYGWIN*) 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'),
+ "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
+ "\n \"%~dp0\\/usr/bin/sh.exe\" \"%~dp0\\from.sh\" %*\r" +
+ "\n) ELSE (\r" +
+ "\n /usr/bin/sh \"%~dp0\\from.sh\" %*\r" +
+ "\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
+ 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 \"$0\"`" +
+ "\n" +
+ "\ncase `uname` in" +
+ "\n *CYGWIN*) 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'),
+ "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" +
+ "\n \"%~dp0\\/usr/bin/sh.exe\" -x \"%~dp0\\from.sh.args\" %*\r" +
+ "\n) ELSE (\r" +
+ "\n /usr/bin/sh -x \"%~dp0\\from.sh.args\" %*\r" +
+ "\n)")
+ t.end()
+ })
+})
diff --git a/node_modules/cmd-shim/test/zz-cleanup.js b/node_modules/cmd-shim/test/zz-cleanup.js
new file mode 100644
index 000000000..47b789961
--- /dev/null
+++ b/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()
+ })
+})