Permalink
Browse files

Avoid accidentally opening npm.js with WSH

  • Loading branch information...
1 parent f2b9b5d commit 4eb8f6b7bfced57ce8415e98a632af5c5317011c @isaacs isaacs committed Oct 14, 2011
Showing with 107 additions and 94 deletions.
  1. +1 −1 README.md
  2. +17 −5 bin/{npm.js → npm-cli.js}
  3. +0 −1 bin/npm.cmd
  4. +1 −1 cli.js
  5. +1 −1 lib/adduser.js
  6. +1 −1 lib/bin.js
  7. +1 −1 lib/bugs.js
  8. +1 −1 lib/build.js
  9. +1 −1 lib/cache.js
  10. +1 −1 lib/completion.js
  11. +1 −1 lib/config.js
  12. +1 −1 lib/deprecate.js
  13. +1 −1 lib/docs.js
  14. +1 −1 lib/edit.js
  15. +1 −1 lib/explore.js
  16. +1 −1 lib/faq.js
  17. +1 −1 lib/get.js
  18. +1 −1 lib/help-search.js
  19. +1 −1 lib/help.js
  20. +1 −1 lib/init.js
  21. +1 −1 lib/install.js
  22. +1 −1 lib/link.js
  23. +1 −1 lib/ls.js
  24. +13 −12 { → lib}/npm.js
  25. +1 −1 lib/outdated.js
  26. +1 −1 lib/owner.js
  27. +1 −1 lib/pack.js
  28. +1 −1 lib/prefix.js
  29. +1 −1 lib/prune.js
  30. +1 −1 lib/publish.js
  31. +1 −1 lib/rebuild.js
  32. +1 −1 lib/root.js
  33. +1 −1 lib/run-script.js
  34. +1 −1 lib/search.js
  35. +1 −1 lib/set.js
  36. +1 −1 lib/star.js
  37. +1 −1 lib/submodule.js
  38. +1 −1 lib/tag.js
  39. +1 −1 lib/unbuild.js
  40. +1 −1 lib/uninstall.js
  41. +1 −1 lib/unpublish.js
  42. +1 −1 lib/update.js
  43. +1 −1 lib/utils/cmd-shim.js
  44. +1 −1 lib/utils/completion/installed-deep.js
  45. +1 −1 lib/utils/completion/installed-shallow.js
  46. +1 −1 lib/utils/error-handler.js
  47. +1 −1 lib/utils/exec.js
  48. +1 −1 lib/utils/fetch.js
  49. +1 −1 lib/utils/find-prefix.js
  50. +1 −1 lib/utils/get-agent.js
  51. +1 −1 lib/utils/lifecycle.js
  52. +1 −1 lib/utils/link.js
  53. +1 −1 lib/utils/load-package-defaults.js
  54. +1 −1 lib/utils/log.js
  55. +1 −1 lib/utils/mkdir-p.js
  56. +1 −1 lib/utils/npm-registry-client/adduser.js
  57. +1 −1 lib/utils/npm-registry-client/get.js
  58. +1 −1 lib/utils/npm-registry-client/publish.js
  59. +1 −1 lib/utils/npm-registry-client/request.js
  60. +1 −1 lib/utils/npm-registry-client/star.js
  61. +1 −1 lib/utils/output.js
  62. +1 −1 lib/utils/read-installed.js
  63. +1 −1 lib/utils/read-json.js
  64. +1 −1 lib/utils/tar.js
  65. +1 −1 lib/utils/uid-number.js
  66. +1 −1 lib/version.js
  67. +1 −1 lib/view.js
  68. +1 −1 lib/whoami.js
  69. +8 −7 lib/xmas.js
  70. +4 −4 package.json
View
@@ -206,7 +206,7 @@ You cannot set configs individually for any single npm function at this
time. Since `npm` is a singleton, any call to `npm.config.set` will
change the value for *all* npm commands in that process.
-See `./bin/npm.js` for an example of pulling config values off of the
+See `./bin/npm-cli.js` for an example of pulling config values off of the
command line arguments using nopt. You may also want to check out `npm
help config` to learn about all the options you can set there.
@@ -1,16 +1,28 @@
#!/usr/bin/env node
;(function () { // wrapper in case we're in module_context mode
-var log = require("../lib/utils/log")
+
+// 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 <args>',\n"
+ +"or type 'node npm <args>'.")
+ 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("../npm")
- , ini = require("../lib/utils/ini")
- , errorHandler = require("../lib/utils/error-handler")
+ , npm = require("../lib/npm.js")
+ , ini = require("../lib/utils/ini.js")
+ , errorHandler = require("../lib/utils/error-handler.js")
- , configDefs = require("../lib/utils/config-defs")
+ , configDefs = require("../lib/utils/config-defs.js")
, shorthands = configDefs.shorthands
, types = configDefs.types
, nopt = require("nopt")
View
@@ -1 +0,0 @@
-@node %~dp0\..\npm.js %*
View
2 cli.js
@@ -1,2 +1,2 @@
#!/usr/bin/env node
-require("./bin/npm.js")
+require("./bin/npm-cli.js")
View
@@ -4,7 +4,7 @@ module.exports = adduser
var registry = require("./utils/npm-registry-client/index.js")
, ini = require("./utils/ini.js")
, log = require("./utils/log.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, prompt = require("./utils/prompt.js")
, promiseChain = require("./utils/promise-chain.js")
, crypto
View
@@ -1,6 +1,6 @@
module.exports = bin
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, output = require("./utils/output.js")
bin.usage = "npm bin\nnpm bin -g\n(just prints the bin folder)"
View
@@ -12,7 +12,7 @@ bugs.completion = function (opts, cb) {
var exec = require("./utils/exec.js")
, registry = require("./utils/npm-registry-client/index.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, log = require("./utils/log.js")
function bugs (args, cb) {
View
@@ -8,7 +8,7 @@
// This runs AFTER install or link are completed.
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, log = require("./utils/log.js")
, chain = require("slide").chain
, fs = require("graceful-fs")
View
@@ -34,7 +34,7 @@ exports.unpack = unpack
var mkdir = require("./utils/mkdir-p.js")
, exec = require("./utils/exec.js")
, fetch = require("./utils/fetch.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, fs = require("graceful-fs")
, rm = require("rimraf")
, readJson = require("./utils/read-json.js")
View
@@ -15,7 +15,7 @@ var output = require("./utils/output.js")
})
, shorthandNames = Object.keys(shorthands)
, allConfs = configNames.concat(shorthandNames)
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
completion.completion = function (opts, cb) {
if (opts.w > 3) return cb()
View
@@ -9,7 +9,7 @@ config.usage = "npm config set <key> <value>"
var ini = require("./utils/ini.js")
, log = require("./utils/log.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, exec = require("./utils/exec.js")
, fs = require("graceful-fs")
, dc
View
@@ -21,7 +21,7 @@ deprecate.completion = function (opts, cb) {
var registry = require("./utils/npm-registry-client/index.js")
, semver = require("semver")
, log = require("./utils/log.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
function deprecate (args, cb) {
var pkg = args[0]
View
@@ -12,7 +12,7 @@ docs.completion = function (opts, cb) {
var exec = require("./utils/exec.js")
, registry = require("./utils/npm-registry-client/index.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, log = require("./utils/log.js")
function docs (args, cb) {
View
@@ -6,7 +6,7 @@ edit.usage = "npm edit <pkg>"
edit.completion = require("./utils/completion/installed-shallow.js")
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, exec = require("./utils/exec.js")
, path = require("path")
, fs = require("graceful-fs")
View
@@ -5,7 +5,7 @@ module.exports = explore
explore.usage = "npm explore <pkg> [ -- <cmd>]"
explore.completion = require("./utils/completion/installed-shallow.js")
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, exec = require("./utils/exec.js")
, path = require("path")
, fs = require("graceful-fs")
View
@@ -3,6 +3,6 @@ module.exports = faq
faq.usage = "npm faq"
-var npm = require("../npm.js")
+var npm = require("./npm.js")
function faq (args, cb) { npm.commands.help(["faq"], cb) }
View
@@ -3,7 +3,7 @@ module.exports = get
get.usage = "npm get <key> <value> (See `npm config`)"
-var npm = require("../npm.js")
+var npm = require("./npm.js")
get.completion = npm.commands.config.completion
View
@@ -8,7 +8,7 @@ var fs = require("graceful-fs")
, cliDocsPath = path.join(__dirname, "..", "doc", "cli")
, apiDocsPath = path.join(__dirname, "..", "doc", "api")
, log = require("./utils/log.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
helpSearch.usage = "npm help-search <text>"
View
@@ -11,7 +11,7 @@ help.completion = function (opts, cb) {
var fs = require("graceful-fs")
, path = require("path")
, exec = require("./utils/exec.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, output = require("./utils/output.js")
, log = require("./utils/log.js")
View
@@ -11,7 +11,7 @@ var prompt = require("./utils/prompt.js")
, exec = require("./utils/exec.js")
, semver = require("semver")
, log = require("./utils/log.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, output = require("./utils/output.js")
init.usage = "npm init [folder]"
View
@@ -52,7 +52,7 @@ install.completion = function (opts, cb) {
})
}
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, semver = require("semver")
, readJson = require("./utils/read-json.js")
, log = require("./utils/log.js")
View
@@ -2,7 +2,7 @@
// link with no args: symlink the folder to the global location
// link with package arg: symlink the global to the local
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, symlink = require("./utils/link.js")
, fs = require("graceful-fs")
, log = require("./utils/log.js")
View
@@ -7,7 +7,7 @@
module.exports = exports = ls
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, readInstalled = require("./utils/read-installed.js")
, output = require("./utils/output.js")
, log = require("./utils/log.js")
View
@@ -19,19 +19,19 @@ require("path").SPLIT_CHAR = process.platform === "win32" ? "\\" : "/"
var EventEmitter = require("events").EventEmitter
, npm = module.exports = new EventEmitter
- , config = require("./lib/config.js")
- , set = require("./lib/utils/set.js")
- , get = require("./lib/utils/get.js")
- , ini = require("./lib/utils/ini.js")
- , log = require("./lib/utils/log.js")
+ , config = require("./config.js")
+ , set = require("./utils/set.js")
+ , get = require("./utils/get.js")
+ , ini = require("./utils/ini.js")
+ , log = require("./utils/log.js")
, fs = require("graceful-fs")
, path = require("path")
, abbrev = require("abbrev")
, which = require("which")
, semver = require("semver")
- , findPrefix = require("./lib/utils/find-prefix.js")
- , getUid = require("./lib/utils/uid-number.js")
- , mkdir = require("./lib/utils/mkdir-p.js")
+ , findPrefix = require("./utils/find-prefix.js")
+ , getUid = require("./utils/uid-number.js")
+ , mkdir = require("./utils/mkdir-p.js")
npm.commands = {}
npm.ELIFECYCLE = {}
@@ -68,7 +68,8 @@ if (process.platform === "win32") {
try {
// startup, ok to do this synchronously
- var j = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))+"")
+ var j = JSON.parse(fs.readFileSync(
+ path.join(__dirname, "../package.json"))+"")
npm.version = j.version
npm.nodeVersionRequired = j.engines.node
if (!semver.satisfies(process.version, j.engines.node)) {
@@ -114,7 +115,7 @@ var commandCache = {}
}
, aliasNames = Object.keys(aliases)
- // these are filenames in ./lib
+ // these are filenames in .
, cmdList = [ "install"
, "uninstall"
, "cache"
@@ -182,7 +183,7 @@ Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) {
}
npm.command = c
if (commandCache[a]) return commandCache[a]
- var cmd = require(__dirname+"/lib/"+a+".js")
+ var cmd = require(__dirname+"/"+a+".js")
commandCache[a] = function () {
var args = Array.prototype.slice.call(arguments, 0)
if (typeof args[args.length - 1] !== "function") {
@@ -391,6 +392,6 @@ Object.getOwnPropertyNames(npm.commands).forEach(function (n) {
})
if (require.main === module) {
- require("./bin/npm.js")
+ require("../bin/npm-cli.js")
}
})()
View
@@ -23,7 +23,7 @@ var path = require("path")
, readJson = require("./utils/read-json.js")
, cache = require("./cache.js")
, asyncMap = require("slide").asyncMap
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, log = require("./utils/log.js")
, semver = require("semver")
, relativize = require("./utils/relativize.js")
View
@@ -69,7 +69,7 @@ var registry = require("./utils/npm-registry-client/index.js")
, put = registry.request.PUT
, log = require("./utils/log.js")
, output
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
function owner (args, cb) {
var action = args.shift()
View
@@ -4,7 +4,7 @@
module.exports = pack
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, install = require("./install.js")
, cache = require("./cache.js")
, output = require("./utils/output.js")
View
@@ -1,6 +1,6 @@
module.exports = prefix
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, output = require("./utils/output.js")
prefix.usage = "npm prefix\nnpm prefix -g\n(just prints the prefix folder)"
View
@@ -5,7 +5,7 @@ module.exports = prune
prune.usage = "npm prune"
var readInstalled = require("./utils/read-installed.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
prune.completion = require("./utils/completion/installed-deep.js")
View
@@ -1,7 +1,7 @@
module.exports = publish
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, registry = require("./utils/npm-registry-client/index.js")
, log = require("./utils/log.js")
, tar = require("./utils/tar.js")
View
@@ -5,7 +5,7 @@ var readInstalled = require("./utils/read-installed.js")
, semver = require("semver")
, log = require("./utils/log.js")
, path = require("path")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, output = require("./utils/output.js")
rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]"
View
@@ -1,6 +1,6 @@
module.exports = root
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, output = require("./utils/output.js")
, log = require("./utils/log.js")
View
@@ -2,7 +2,7 @@
module.exports = runScript
var lifecycle = require("./utils/lifecycle.js")
- , npm = require("../npm.js")
+ , npm = require("./npm.js")
, path = require("path")
, readJson = require("./utils/read-json.js")
, log = require("./utils/log.js")
View
@@ -1,7 +1,7 @@
module.exports = exports = search
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, registry = require("./utils/npm-registry-client/index.js")
, semver = require("semver")
, output
View
@@ -3,7 +3,7 @@ module.exports = set
set.usage = "npm set <key> <value> (See `npm config`)"
-var npm = require("../npm.js")
+var npm = require("./npm.js")
set.completion = npm.commands.config.completion
View
@@ -1,7 +1,7 @@
module.exports = star
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, registry = require("./utils/npm-registry-client/index.js")
, log = require("./utils/log.js")
, asyncMap = require("slide").asyncMap
View
@@ -4,7 +4,7 @@
module.exports = submodule
-var npm = require("../npm.js")
+var npm = require("./npm.js")
, readJson = require("./utils/read-json.js")
, exec = require("./utils/exec.js")
, output = require("./utils/output.js")
Oops, something went wrong.

0 comments on commit 4eb8f6b

Please sign in to comment.