Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add "npm use" #1249

Closed
wants to merge 3 commits into from

2 participants

@thejh

Add npm use <package> <yes/no>. Only useful in combination with npm/npm-registry-couchapp#27 .

@isaacs
Owner

Merged into master. Changed the API around a little bit. See http://npmjs.org/doc/star.html

@isaacs isaacs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 16, 2011
  1. @thejh

    add "npm use"

    thejh authored
  2. @thejh

    call it "star", not "use"

    thejh authored
  3. @thejh
This page is out of date. Refresh to see the latest.
View
35 lib/star.js
@@ -0,0 +1,35 @@
+
+module.exports = star
+
+var npm = require("../npm")
+ , registry = require("./utils/npm-registry-client")
+ , log = require("./utils/log")
+ , tar = require("./utils/tar")
+ , sha = require("./utils/sha")
+ , path = require("path")
+ , readJson = require("./utils/read-json")
+ , fs = require("fs")
+ , lifecycle = require("./utils/lifecycle")
+ , chain = require("slide").chain
+
+star.usage = "npm star <package> <yes/no>"
+
+star.completion = function (opts, cb) {
+ // for now, not yet implemented.
+ return cb()
+}
+
+function star (args, cb) {
+ if (args.length !== 2) return cb(new Error("you must specify exactly two parameters: package and yes or no"))
+ var using
+ if (args[1] === "yes")
+ using = true
+ else if (args[1] === "no")
+ using = false
+ else
+ return cb(new Error("second parameter must be yes or no"))
+ log.verbose(args, "star")
+ registry.use(args[0], using, function (er) {
+ cb(er)
+ })
+}
View
2  lib/utils/npm-registry-client/index.js
@@ -12,5 +12,5 @@ function setLazyGet (p) {
, enumerable : true })
}
-; ["publish", "unpublish", "tag", "adduser", "get", "request"]
+; ["publish", "unpublish", "tag", "adduser", "get", "request", "use"]
.forEach(setLazyGet)
View
42 lib/utils/npm-registry-client/use.js
@@ -0,0 +1,42 @@
+
+module.exports = use
+
+var request = require("./request")
+ , GET = request.GET
+ , PUT = request.PUT
+ , DELETE = request.DELETE
+ , reg = request.reg
+ , upload = request.upload
+ , log = require("../log")
+ , path = require("path")
+ , npm = require("../../../npm")
+ , url = require("url")
+
+function use (package, usingValue, cb) {
+ var registry = reg()
+ if (registry instanceof Error) return cb(registry)
+
+ var users = {}
+ users[new Buffer(npm.config.get("_auth"), 'base64').toString().split(':')[0]] = usingValue
+
+ var fullData =
+ { _id : package
+ , name : package
+ , users: users
+ }
+
+ var dataURI = encodeURIComponent(package)
+
+ GET(package, function (er, fullData) {
+ if (er) return cb(er)
+
+ fullData = {
+ users: users
+ , _id: fullData._id
+ , _rev: fullData._rev
+ }
+ return PUT(dataURI, fullData, function (er) {
+ cb(er)
+ })
+ })
+}
View
1  npm.js
@@ -88,6 +88,7 @@ var commandCache = {}
, "link"
, "publish"
+ , "star"
, "tag"
, "adduser"
, "unpublish"
Something went wrong with that request. Please try again.