Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcli.js2
-rwxr-xr-xnpm.js18
2 files changed, 14 insertions, 6 deletions
diff --git a/cli.js b/cli.js
index b1016ff16..db7bcb13c 100755
--- a/cli.js
+++ b/cli.js
@@ -24,7 +24,7 @@ var fs = require("fs")
log(sys.inspect(argv), "cli")
while (arg = argv.shift()) {
- if (!command && (arg in npm.commands)) {
+ if (!command && (npm.commands.hasOwnProperty(arg))) {
if (key) {
conf[key] = true
key = null
diff --git a/npm.js b/npm.js
index 37e0b3c2d..d236a2cc9 100755
--- a/npm.js
+++ b/npm.js
@@ -25,11 +25,11 @@ try {
npm.version = ex
}
+var commandCache = {}
; [ "install"
, "activate"
, "deactivate"
, "uninstall"
- , "ls"
, "build"
, "link"
, "publish"
@@ -43,10 +43,18 @@ try {
, "start"
, "restart"
, "unpublish"
- ].forEach(function (c) { npm.commands[c] = require("./lib/"+c) })
-
-npm.commands.list = npm.commands.ls
-npm.commands.rm = npm.commands.uninstall
+ , "list"
+ , "ls"
+ , "rm"
+ ].forEach(function (c) {
+ Object.defineProperty(npm.commands, c, { get : function () {
+ c = c === "list" ? "ls"
+ : c === "rm" ? "uninstall"
+ : c
+ if (c in commandCache) return commandCache[c]
+ return commandCache[c] = require("./lib/"+c)
+ }})
+ })
// Local store for package data, so it won't have to be fetched/read more than
// once in a single pass. TODO: cache this to disk somewhere when we're using