Permalink
Browse files

Friendlier 'npm.install(foo)' for repl poking.

  • Loading branch information...
isaacs committed Aug 17, 2011
1 parent 10efacb commit d2e23deb9cdc7543a3d2d8d977f4fb157cc04367
Showing with 22 additions and 0 deletions.
  1. +22 −0 npm.js
View
22 npm.js
@@ -300,3 +300,25 @@ Object.defineProperty(npm, "tmp",
}
, enumerable : true
})
+
+// the better to repl you with
+Object.getOwnPropertyNames(npm.commands).forEach(function (n) {
+ if (npm.hasOwnProperty(n)) return
+
+ Object.defineProperty(npm, n, { get: function () {
+ return function () {
+ var args = Array.prototype.slice.call(arguments, 0)
+ , cb = defaultCb
+
+ if (args.length === 1 && Array.isArray(args[0])) {
+ args = args[0]
+ }
+
+ if (typeof args[args.length - 1] === "function") {
+ cb = args.pop()
+ }
+
+ npm.commands[n](args, cb)
@Raynos

Raynos Oct 1, 2012

Contributor

npm.commands["search"]([["search item"], true, 600], cb)

Clearly breaks. I required search directly from the lib folder but I don't know how I'm supposed to use through require("npm")

+ }
+ }, enumerable: false, configurable: true })
+})

0 comments on commit d2e23de

Please sign in to comment.