read-cmd-shim
Advanced tools
Comparing version 1.0.5 to 2.0.0
54
index.js
@@ -1,5 +0,7 @@ | ||
'use strict' | ||
var fs = require('graceful-fs') | ||
const fs = require('fs') | ||
const {promisify} = require('util') | ||
const {readFileSync} = fs | ||
const readFile = promisify(fs.readFile) | ||
function extractPath (path, cmdshimContents) { | ||
const extractPath = (path, cmdshimContents) => { | ||
if (/[.]cmd$/.test(path)) { | ||
@@ -14,24 +16,25 @@ return extractPathFromCmd(cmdshimContents) | ||
function extractPathFromPowershell (cmdshimContents) { | ||
var matches = cmdshimContents.match(/"[$]basedir[/]([^"]+?)"\s+[$]args/) | ||
const extractPathFromPowershell = cmdshimContents => { | ||
const matches = cmdshimContents.match(/"[$]basedir[/]([^"]+?)"\s+[$]args/) | ||
return matches && matches[1] | ||
} | ||
function extractPathFromCmd (cmdshimContents) { | ||
var matches = cmdshimContents.match(/"%(?:~dp0|dp0%)\\([^"]+?)"\s+%[*]/) | ||
const extractPathFromCmd = cmdshimContents => { | ||
const matches = cmdshimContents.match(/"%(?:~dp0|dp0%)\\([^"]+?)"\s+%[*]/) | ||
return matches && matches[1] | ||
} | ||
function extractPathFromCygwin (cmdshimContents) { | ||
var matches = cmdshimContents.match(/"[$]basedir[/]([^"]+?)"\s+"[$]@"/) | ||
const extractPathFromCygwin = cmdshimContents => { | ||
const matches = cmdshimContents.match(/"[$]basedir[/]([^"]+?)"\s+"[$]@"/) | ||
return matches && matches[1] | ||
} | ||
function wrapError (thrown, newError) { | ||
const wrapError = (thrown, newError) => { | ||
newError.message = thrown.message | ||
newError.code = thrown.code | ||
newError.path = thrown.path | ||
return newError | ||
} | ||
function notaShim (path, er) { | ||
const notaShim = (path, er) => { | ||
if (!er) { | ||
@@ -42,22 +45,27 @@ er = new Error() | ||
er.code = 'ENOTASHIM' | ||
er.message = "Can't read shim path from '" + path + "', it doesn't appear to be a cmd-shim" | ||
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() | ||
const readCmdShim = path => { | ||
// create a new error to capture the stack trace from this point, | ||
// instead of getting some opaque stack into node's internals | ||
const 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)) | ||
}) | ||
return readFile(path).then(contents => { | ||
const destination = extractPath(path, contents.toString()) | ||
if (destination) return destination | ||
return Promise.reject(notaShim(path, er)) | ||
}, readFileEr => Promise.reject(wrapError(readFileEr, er))) | ||
} | ||
module.exports.sync = function (path) { | ||
var contents = fs.readFileSync(path) | ||
var destination = extractPath(path, contents.toString()) | ||
const readCmdShimSync = path => { | ||
const contents = readFileSync(path) | ||
const destination = extractPath(path, contents.toString()) | ||
if (!destination) throw notaShim(path) | ||
return destination | ||
} | ||
readCmdShim.sync = readCmdShimSync | ||
module.exports = readCmdShim |
{ | ||
"name": "read-cmd-shim", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"description": "Figure out what a cmd-shim is pointing at. This acts as the equivalent of fs.readlink.", | ||
"main": "index.js", | ||
"dependencies": { | ||
"graceful-fs": "^4.1.2" | ||
}, | ||
"devDependencies": { | ||
"cmd-shim": "^3.0.0", | ||
"rimraf": "^2.4.3", | ||
"standard": "^5.2.2", | ||
"tap": "^12.7.0" | ||
"cmd-shim": "^4.0.0", | ||
"rimraf": "^3.0.0", | ||
"tap": "^14.10.6" | ||
}, | ||
"scripts": { | ||
"pretest": "standard", | ||
"test": "tap test/*.js --100" | ||
"preversion": "npm t", | ||
"postversion": "npm publish", | ||
"prepublishOnly": "git push --follow-tags", | ||
"test": "tap" | ||
}, | ||
"tap": { | ||
"check-coverage": true | ||
}, | ||
"repository": { | ||
@@ -23,7 +24,3 @@ "type": "git", | ||
}, | ||
"author": "Rebecca Turner <me@re-becca.org> (http://re-becca.org/)", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/npm/read-cmd-shim/issues" | ||
}, | ||
"homepage": "https://github.com/npm/read-cmd-shim#readme", | ||
@@ -30,0 +27,0 @@ "files": [ |
@@ -10,14 +10,14 @@ # read-cmd-shim | ||
``` | ||
var readCmdShim = require('read-cmd-shim') | ||
const readCmdShim = require('read-cmd-shim') | ||
readCmdShim('/path/to/shim.cmd', function (er, destination) { | ||
readCmdShim('/path/to/shim.cmd').then(destination => { | ||
… | ||
}) | ||
var destination = readCmdShim.sync('/path/to/shim.cmd') | ||
const destination = readCmdShim.sync('/path/to/shim.cmd') | ||
``` | ||
### readCmdShim(path, callback) | ||
### readCmdShim(path) -> Promise | ||
Reads the `cmd-shim` located at `path` and calls back with the _relative_ | ||
Reads the `cmd-shim` located at `path` and resolves with the _relative_ | ||
path that the shim points at. Consider this as roughly the equivalent of | ||
@@ -35,5 +35,4 @@ `fs.readlink`. | ||
### readCmdShim.sync(path) | ||
Same as above but synchronous. Errors are thrown. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4635
0
3
60
2
37
1
- Removedgraceful-fs@^4.1.2
- Removedgraceful-fs@4.2.11(transitive)