From 4eb8f6b7bfced57ce8415e98a632af5c5317011c Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 14 Oct 2011 14:04:56 -0700 Subject: Avoid accidentally opening npm.js with WSH --- bin/npm-cli.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/npm.cmd | 1 - bin/npm.js | 65 ------------------------------------------------- 3 files changed, 77 insertions(+), 66 deletions(-) create mode 100755 bin/npm-cli.js delete mode 100644 bin/npm.cmd delete mode 100755 bin/npm.js (limited to 'bin') diff --git a/bin/npm-cli.js b/bin/npm-cli.js new file mode 100755 index 000000000..db6db2fbd --- /dev/null +++ b/bin/npm-cli.js @@ -0,0 +1,77 @@ +#!/usr/bin/env node +;(function () { // wrapper in case we're in module_context mode + +// windows: running "npm blah" in this folder will invoke WSH, not node. +if (typeof WScript !== "undefined") { + WScript.echo("npm does not work when run\n" + +"with the Windows Scripting Host\n\n" + +"'cd' to a different directory,\n" + +"or type 'npm.cmd ',\n" + +"or type 'node npm '.") + WScript.quit(1) + return +} + +var log = require("../lib/utils/log.js") +log.waitForConfig() +log.info("ok", "it worked if it ends with") + +var fs = require("graceful-fs") + , path = require("path") + , npm = require("../lib/npm.js") + , ini = require("../lib/utils/ini.js") + , errorHandler = require("../lib/utils/error-handler.js") + + , configDefs = require("../lib/utils/config-defs.js") + , shorthands = configDefs.shorthands + , types = configDefs.types + , nopt = require("nopt") + +// if npm is called as "npmg" or "npm_g", then +// run in global mode. +if (path.basename(process.argv[1]).slice(-1) === "g") { + process.argv.splice(1, 1, "npm", "-g") +} + +log.verbose(process.argv, "cli") + +var conf = nopt(types, shorthands) +npm.argv = conf.argv.remain +if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift() +else conf.usage = true + + +if (conf.version) { + console.log(npm.version) + return +} + +log.info("npm@"+npm.version, "using") +log.info("node@"+process.version, "using") + +// make sure that this version of node works with this version of npm. +var semver = require("semver") + , nodeVer = process.version + , reqVer = npm.nodeVersionRequired +if (reqVer && !semver.satisfies(nodeVer, reqVer)) { + return errorHandler(new Error( + "npm doesn't work with node " + nodeVer + + "\nRequired: node@" + reqVer), true) +} + +process.on("uncaughtException", errorHandler) + +if (conf.usage && npm.command !== "help") { + npm.argv.unshift(npm.command) + npm.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[npm.command](npm.argv, errorHandler) +}) + +})() diff --git a/bin/npm.cmd b/bin/npm.cmd deleted file mode 100644 index 387fc26fa..000000000 --- a/bin/npm.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\..\npm.js %* diff --git a/bin/npm.js b/bin/npm.js deleted file mode 100755 index 003c3f953..000000000 --- a/bin/npm.js +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env node -;(function () { // wrapper in case we're in module_context mode -var log = require("../lib/utils/log") -log.waitForConfig() -log.info("ok", "it worked if it ends with") - -var fs = require("graceful-fs") - , path = require("path") - , npm = require("../npm") - , ini = require("../lib/utils/ini") - , errorHandler = require("../lib/utils/error-handler") - - , configDefs = require("../lib/utils/config-defs") - , shorthands = configDefs.shorthands - , types = configDefs.types - , nopt = require("nopt") - -// if npm is called as "npmg" or "npm_g", then -// run in global mode. -if (path.basename(process.argv[1]).slice(-1) === "g") { - process.argv.splice(1, 1, "npm", "-g") -} - -log.verbose(process.argv, "cli") - -var conf = nopt(types, shorthands) -npm.argv = conf.argv.remain -if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift() -else conf.usage = true - - -if (conf.version) { - console.log(npm.version) - return -} - -log.info("npm@"+npm.version, "using") -log.info("node@"+process.version, "using") - -// make sure that this version of node works with this version of npm. -var semver = require("semver") - , nodeVer = process.version - , reqVer = npm.nodeVersionRequired -if (reqVer && !semver.satisfies(nodeVer, reqVer)) { - return errorHandler(new Error( - "npm doesn't work with node " + nodeVer - + "\nRequired: node@" + reqVer), true) -} - -process.on("uncaughtException", errorHandler) - -if (conf.usage && npm.command !== "help") { - npm.argv.unshift(npm.command) - npm.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[npm.command](npm.argv, errorHandler) -}) - -})() -- cgit v1.2.3