Comparing version 1.0.0 to 1.0.1
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.0.1", | ||
"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": "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. | ||
## Installation | ||
@@ -15,3 +18,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 +31,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 +43,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 |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
13927
2
8
363
1
2
1
41
3
2
+ Addedgraceful-fs@2.0.3(transitive)
- Removedgraceful-fs@~1.2.0
- Removednpmlog@0
- Removedrimraf@2
- Removedslide@1
- Removedansi@0.3.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedgraceful-fs@1.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednpmlog@0.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedslide@1.1.6(transitive)
- Removedwrappy@1.0.2(transitive)