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:
authorRebecca Turner <me@re-becca.org>2015-09-10 00:50:29 +0300
committerRebecca Turner <me@re-becca.org>2015-09-10 22:15:15 +0300
commite6db459deac9713b584092c80dd014066e3a1d24 (patch)
tree73590ac3f1872abaa2ba5a703e9cc752ca10cf7a /node_modules/read-cmd-shim
parent2fb60bfef323d8dcf8f8c972bcb8e4d167e5e25d (diff)
read-cmd-shim@1.0.1
Diffstat (limited to 'node_modules/read-cmd-shim')
-rw-r--r--node_modules/read-cmd-shim/.npmignore3
-rw-r--r--node_modules/read-cmd-shim/README.md36
-rw-r--r--node_modules/read-cmd-shim/index.js54
-rw-r--r--node_modules/read-cmd-shim/package.json78
-rw-r--r--node_modules/read-cmd-shim/test/integration.js139
5 files changed, 310 insertions, 0 deletions
diff --git a/node_modules/read-cmd-shim/.npmignore b/node_modules/read-cmd-shim/.npmignore
new file mode 100644
index 000000000..ac5054963
--- /dev/null
+++ b/node_modules/read-cmd-shim/.npmignore
@@ -0,0 +1,3 @@
+.#*
+*~
+node_modules
diff --git a/node_modules/read-cmd-shim/README.md b/node_modules/read-cmd-shim/README.md
new file mode 100644
index 000000000..2f0b5f6cc
--- /dev/null
+++ b/node_modules/read-cmd-shim/README.md
@@ -0,0 +1,36 @@
+# read-cmd-shim
+
+Figure out what a [`cmd-shim`](https://github.com/ForbesLindesay/cmd-shim)
+is pointing at. This acts as the equivalent of
+[`fs.readlink`](https://nodejs.org/api/fs.html#fs_fs_readlink_path_callback).
+
+### Usage
+
+```
+var readCmdShim = require('read-cmd-shim')
+
+readCmdShim('/path/to/shim.cmd', function (er, destination) {
+ …
+})
+
+var destination = readCmdShim.sync('/path/to/shim.cmd')
+
+### readCmdShim(path, callback)
+
+Reads the `cmd-shim` located at `path` and calls back with the _relative_
+path that the shim points at. Consider this as roughly the equivalent of
+`fs.readlink`.
+
+This can read both `.cmd` style that are run by the Windows Command Prompt
+and Powershell, and the kind without any extension that are used by Cygwin.
+
+This can return errors that `fs.readFile` returns, except that they'll
+include a stack trace from where `readCmdShim` was called. Plus it can
+return a special `ENOTASHIM` exception, when it can't find a cmd-shim in the
+file referenced by `path`. This should only happen if you pass in a
+non-command shim.
+
+
+### readCmdShim.sync(path)
+
+Same as above but synchronous. Errors are thrown.
diff --git a/node_modules/read-cmd-shim/index.js b/node_modules/read-cmd-shim/index.js
new file mode 100644
index 000000000..6a2265449
--- /dev/null
+++ b/node_modules/read-cmd-shim/index.js
@@ -0,0 +1,54 @@
+'use strict'
+var fs = require('graceful-fs')
+
+function extractPath (path, cmdshimContents) {
+ if (/[.]cmd$/.test(path)) {
+ return extractPathFromCmd(cmdshimContents)
+ } else {
+ return extractPathFromCygwin(cmdshimContents)
+ }
+}
+
+function extractPathFromCmd (cmdshimContents) {
+ var matches = cmdshimContents.match(/"%~dp0\\([^"]+?)"\s+%[*]/)
+ return matches && matches[1]
+}
+
+function extractPathFromCygwin (cmdshimContents) {
+ var matches = cmdshimContents.match(/"[$]basedir[/]([^"]+?)"\s+"[$]@"/)
+ return matches && matches[1]
+}
+
+function wrapError (thrown, newError) {
+ newError.message = thrown.message
+ newError.code = thrown.code
+ return newError
+}
+
+function notaShim (path, er) {
+ if (!er) {
+ er = new Error()
+ Error.captureStackTrace(er, notaShim)
+ }
+ er.code = 'ENOTASHIM'
+ er.message = "Can't read shim path from '" + path + "', it doesn't appear to be a cmd-shim"
+ return er
+}
+
+var readCmdShim = module.exports = function (path, cb) {
+ var er = new Error()
+ Error.captureStackTrace(er, readCmdShim)
+ fs.readFile(path, function (readFileEr, contents) {
+ if (readFileEr) return cb(wrapError(readFileEr, er))
+ var destination = extractPath(path, contents.toString())
+ if (destination) return cb(null, destination)
+ return cb(notaShim(path, er))
+ })
+}
+
+module.exports.sync = function (path) {
+ var contents = fs.readFileSync(path)
+ var destination = extractPath(path, contents.toString())
+ if (!destination) throw notaShim(path)
+ return destination
+}
diff --git a/node_modules/read-cmd-shim/package.json b/node_modules/read-cmd-shim/package.json
new file mode 100644
index 000000000..481119680
--- /dev/null
+++ b/node_modules/read-cmd-shim/package.json
@@ -0,0 +1,78 @@
+{
+ "_args": [
+ [
+ "read-cmd-shim",
+ "/Users/rebecca/code/npm"
+ ]
+ ],
+ "_from": "read-cmd-shim@*",
+ "_id": "read-cmd-shim@1.0.1",
+ "_inCache": true,
+ "_location": "/read-cmd-shim",
+ "_nodeVersion": "3.1.0",
+ "_npmUser": {
+ "email": "me@re-becca.org",
+ "name": "iarna"
+ },
+ "_npmVersion": "3.3.0",
+ "_phantomChildren": {},
+ "_requested": {
+ "name": "read-cmd-shim",
+ "raw": "read-cmd-shim",
+ "rawSpec": "",
+ "scope": null,
+ "spec": "*",
+ "type": "range"
+ },
+ "_requiredBy": [
+ "/"
+ ],
+ "_shasum": "2d5d157786a37c055d22077c32c53f8329e91c7b",
+ "_shrinkwrap": null,
+ "_spec": "read-cmd-shim",
+ "_where": "/Users/rebecca/code/npm",
+ "author": {
+ "email": "me@re-becca.org",
+ "name": "Rebecca Turner",
+ "url": "http://re-becca.org/"
+ },
+ "bugs": {
+ "url": "https://github.com/npm/read-cmd-shim/issues"
+ },
+ "dependencies": {
+ "graceful-fs": "^4.1.2"
+ },
+ "description": "Figure out what a cmd-shim is pointing at. This acts as the equivalent of fs.readlink.",
+ "devDependencies": {
+ "cmd-shim": "^2.0.1",
+ "rimraf": "^2.4.3",
+ "standard": "^5.2.2",
+ "tap": "^1.4.1"
+ },
+ "directories": {},
+ "dist": {
+ "shasum": "2d5d157786a37c055d22077c32c53f8329e91c7b",
+ "tarball": "http://registry.npmjs.org/read-cmd-shim/-/read-cmd-shim-1.0.1.tgz"
+ },
+ "gitHead": "7c50879bf49743a1c69f9d7f0ba1638fc46bb40c",
+ "homepage": "https://github.com/npm/read-cmd-shim#readme",
+ "installable": true,
+ "license": "ISC",
+ "main": "index.js",
+ "maintainers": [
+ {
+ "name": "iarna",
+ "email": "me@re-becca.org"
+ }
+ ],
+ "name": "read-cmd-shim",
+ "optionalDependencies": {},
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/npm/read-cmd-shim.git"
+ },
+ "scripts": {
+ "test": "standard && tap test/*.js"
+ },
+ "version": "1.0.1"
+}
diff --git a/node_modules/read-cmd-shim/test/integration.js b/node_modules/read-cmd-shim/test/integration.js
new file mode 100644
index 000000000..269f96472
--- /dev/null
+++ b/node_modules/read-cmd-shim/test/integration.js
@@ -0,0 +1,139 @@
+'use strict'
+var path = require('path')
+var fs = require('graceful-fs')
+var test = require('tap').test
+var rimraf = require('rimraf')
+var cmdShim = require('cmd-shim')
+var readCmdShim = require('../index.js')
+var workDir = path.join(__dirname, path.basename(__filename, '.js'))
+var testShbang = path.join(workDir, 'test-shbang')
+var testShbangCmd = testShbang + '.cmd'
+var testShim = path.join(workDir, 'test')
+var testShimCmd = testShim + '.cmd'
+
+test('setup', function (t) {
+ rimraf.sync(workDir)
+ fs.mkdirSync(workDir)
+ fs.writeFileSync(testShbang + '.js', '#!/usr/bin/env node\ntrue')
+ cmdShim(__filename, testShim, function (er) {
+ t.error(er)
+ cmdShim(testShbang + '.js', testShbang, function (er) {
+ t.error(er)
+ t.done()
+ })
+ })
+})
+
+test('async-read-no-shbang', function (t) {
+ t.plan(2)
+ readCmdShim(testShimCmd, function (er, dest) {
+ t.error(er)
+ t.is(dest, '..\\basic.js')
+ t.done()
+ })
+})
+
+test('sync-read-no-shbang', function (t) {
+ t.plan(1)
+ var dest = readCmdShim.sync(testShimCmd)
+ t.is(dest, '..\\basic.js')
+ t.done()
+})
+
+test('async-read-shbang', function (t) {
+ t.plan(2)
+ readCmdShim(testShbangCmd, function (er, dest) {
+ t.error(er)
+ t.is(dest, 'test-shbang.js')
+ t.done()
+ })
+})
+
+test('sync-read-shbang', function (t) {
+ t.plan(1)
+ var dest = readCmdShim.sync(testShbangCmd)
+ t.is(dest, 'test-shbang.js')
+ t.done()
+})
+
+test('async-read-no-shbang-cygwin', function (t) {
+ t.plan(2)
+ readCmdShim(testShim, function (er, dest) {
+ t.error(er)
+ t.is(dest, '../basic.js')
+ t.done()
+ })
+})
+
+test('sync-read-no-shbang-cygwin', function (t) {
+ t.plan(1)
+ var dest = readCmdShim.sync(testShim)
+ t.is(dest, '../basic.js')
+ t.done()
+})
+
+test('async-read-shbang-cygwin', function (t) {
+ t.plan(2)
+ readCmdShim(testShbang, function (er, dest) {
+ t.error(er)
+ t.is(dest, 'test-shbang.js')
+ t.done()
+ })
+})
+
+test('sync-read-shbang-cygwin', function (t) {
+ t.plan(1)
+ var dest = readCmdShim.sync(testShbang)
+ t.is(dest, 'test-shbang.js')
+ t.done()
+})
+
+test('async-read-dir', function (t) {
+ t.plan(2)
+ readCmdShim(workDir, function (er) {
+ t.ok(er)
+ t.is(er.code, 'EISDIR', "cmd-shims can't be directories")
+ t.done()
+ })
+})
+
+test('sync-read-dir', function (t) {
+ t.plan(1)
+ t.throws(function () { readCmdShim.sync(workDir) }, "cmd-shims can't be directories")
+ t.done()
+})
+
+test('async-read-not-there', function (t) {
+ t.plan(2)
+ readCmdShim('/path/to/nowhere', function (er, dest) {
+ t.ok(er, 'missing files throw errors')
+ t.is(er.code, 'ENOENT', "cmd-shim file doesn't exist")
+ t.done()
+ })
+})
+
+test('sync-read-not-there', function (t) {
+ t.plan(1)
+ t.throws(function () { readCmdShim.sync('/path/to/nowhere') }, "cmd-shim file doesn't exist")
+ t.done()
+})
+
+test('async-read-not-shim', function (t) {
+ t.plan(2)
+ readCmdShim(__filename, function (er, dest) {
+ t.ok(er)
+ t.is(er.code, 'ENOTASHIM', 'shim file specified is not a shim')
+ t.done()
+ })
+})
+
+test('sync-read-not-shim', function (t) {
+ t.plan(1)
+ t.throws(function () { readCmdShim.sync(__filename) }, 'shim file specified is not a shim')
+ t.done()
+})
+
+test('cleanup', function (t) {
+ rimraf.sync(workDir)
+ t.done()
+})