Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

read-cmd-shim

Package Overview
Dependencies
Maintainers
7
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-cmd-shim - npm Package Compare versions

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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc