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

cmd-shim

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmd-shim - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.travis.yml

105

index.js

@@ -1,2 +0,1 @@

// XXX Todo:
// On windows, create a .cmd file.

@@ -15,7 +14,9 @@ // Read the #! in the file to see what it uses. The vast majority

var fs = require("graceful-fs")
, chain = require("slide").chain
, mkdir = require("mkdirp")
, rm = require("rimraf")
, log = require("npmlog")
try {
var fs = require("graceful-fs")
} catch (e) {
var fs = require("fs")
}
var mkdir = require("mkdirp")
, path = require("path")

@@ -31,16 +32,29 @@ , shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/

// 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) {
if (process.platform !== "win32") {
return cb(new Error(".cmd shims only should be used on windows"))
}
fs.stat(from, function (er, stat) {
if (er)
return cb(er)
chain
( [ [fs, "stat", from]
, [rm, to + ".cmd"]
, [rm, to]
, [mkdir, path.dirname(to)]
, [writeShim, from, to] ]
, cb )
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) {

@@ -51,10 +65,14 @@ // make a cmd file and a sh script

// sort of script, and just call it directly.
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)
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)
})
})

@@ -100,4 +118,2 @@ }

cmd = ":: Created by npm, please don't edit manually.\r\n" + cmd
// #!/bin/sh

@@ -144,15 +160,26 @@ // basedir=`dirname "$0"`

fs.writeFile(to + ".cmd", cmd, "utf8", function (er) {
if (er) {
log.warn("cmdShim", "Could not write "+to+".cmd")
return cb(er)
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()
}
fs.writeFile(to, sh, "utf8", function (er) {
if (er) {
log.warn("shShim", "Could not write "+to)
return cb(er)
}
fs.chmod(to, 0755, cb)
})
})
}
}
}
{
"name": "cmd-shim",
"version": "1.0.0",
"version": "1.1.0",
"description": "Used in npm for command line application support",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "tap test/*.js"
},

@@ -12,10 +12,13 @@ "repository": {

},
"license": "MIT",
"license": "BSD",
"optionalDependencies": {
"graceful-fs": "1.2"
},
"dependencies": {
"graceful-fs": "~1.2.0",
"rimraf": "2",
"mkdirp": "~0.3.3",
"slide": "1",
"npmlog": "0"
"mkdirp": "~0.3.3"
},
"devDependencies": {
"tap": "~0.4.1",
"rimraf": "~2.1.4"
}
}
# cmd-shim
The cmd-shim used in npm. Currently npm has this code inlined. It wasn not originally written by me; I simply copied it from the npm repository.
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

@@ -15,3 +20,4 @@

Create a cmd shim at `to` for the command line program at `from`. e.g.
Create a cmd shim at `to` for the command line program at `from`.
e.g.

@@ -27,3 +33,4 @@ ```javascript

The same as above, but will just continue if the file does not exist. Source:
The same as above, but will just continue if the file does not exist.
Source:

@@ -38,13 +45,1 @@ ```javascript

```
## Logging
By default, [npmlog](https://npmjs.org/package/npmlog) is used for logging. Log messages are written by default if it fails to write to the output directory. You can disable the logging by calling:
```javascript
require('npmlog').level('silent');
```
## License
MIT
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