diff options
author | isaacs <i@izs.me> | 2010-10-24 05:46:59 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-10-24 05:46:59 +0400 |
commit | 9c5da9dd23d39a1a91c98ba447bacc3b176cdf66 (patch) | |
tree | 11492f79c0635aaadce97930382a166b94886c4f /cli.js | |
parent | 3adf7987038c5f8545801a71a4d88bb0b9e81ce2 (diff) |
More "programmatic npm" updates.
Building more upon the patch from Charlie Robbins (d7c69821a01c8327f5468fe7a115f2537f908da9), these changes remove any way of npm actually triggering a program exit than by being called by the cli.
- Move the "exit" option off the opts object and onto a proper config setting. Why not?
- Use \r\n for most output, so that it'll look correct in the repl, or other places where \n may not be enough.
- Add a comment about loading npm programmatically.
Diffstat (limited to 'cli.js')
-rwxr-xr-x | cli.js | 29 |
1 files changed, 15 insertions, 14 deletions
@@ -51,7 +51,7 @@ var vindex = arglist.indexOf("-v") , printVersion = vindex !== -1 || conf.version if (printVersion) { sys.puts(npm.version) - if (vindex !== -1) arglist.splice(vindex, 1) + process.exit(0) } else log("npm@"+npm.version, "using") // make sure that this version of node works with this version of npm. @@ -59,22 +59,23 @@ var semver = require("./lib/utils/semver") , nodeVer = process.version , reqVer = npm.nodeVersionRequired if (reqVer && !semver.satisfies(nodeVer, reqVer)) { - var badNodeVersion = new Error( - "npm doesn't work with node " + nodeVer + "\nRequired: node@" + reqVer) - throw badNodeVersion + errorHandler(new Error( + "npm doesn't work with node " + nodeVer + "\nRequired: node@" + reqVer), true) } process.on("uncaughtException", errorHandler) -if (!command && !printVersion) conf.usage = true +if (!command) conf.usage = true -if (printVersion) itWorked = true -else { - if (conf.usage && command !== "help") { - arglist.unshift(command) - command = "help" - } - npm.load({ conf: conf, exit: true }, function (err, loaded) { - npm.commands[command](arglist, errorHandler) - }); +if (conf.usage && command !== "help") { + arglist.unshift(command) + command = "help" } + +// now actually fire up npm and run the command. +// this is how to use npm programmatically: +conf._exit = true +npm.load(conf, function (er) { + if (er) return errorHandler(er) + npm.commands[command](arglist, errorHandler) +}) |