Permalink
Browse files

Support username/project as a shorthand for github urls

  • Loading branch information...
1 parent 6741bfe commit bfcd368e50b6aa00f30fec9987d44080a5467174 @isaacs isaacs committed Oct 12, 2012
Showing with 33 additions and 3 deletions.
  1. +29 −2 lib/cache.js
  2. +4 −1 test/packages/npm-test-url-dep/package.json
View
@@ -474,10 +474,20 @@ function addNameTag (name, tag, data, cb) {
if (!explicit && Object.keys(data.versions).length) {
return addNamed(name, "*", data, cb)
}
- return cb(installTargetsError(tag, data))
+
+ er = installTargetsError(tag, data)
+
+ // might be username/project
+ // in that case, try it as a github url.
+ if (tag.split("/").length === 2) {
+ return maybeGithub(tag, name, er, cb)
+ }
+
+ return cb(er)
})
}
+
function engineFilter (data) {
var npmv = npm.version
, nodev = npm.config.get("node-version")
@@ -639,13 +649,30 @@ function addLocal (p, name, cb_) {
if (er) return cb(er)
// figure out if this is a folder or file.
fs.stat(p, function (er, s) {
- if (er) return cb(er)
+ if (er) {
+ // might be username/project
+ // in that case, try it as a github url.
+ if (p.split("/").length === 2) {
+ return maybeGithub(p, name, er, cb)
+ }
+ return cb(er)
+ }
if (s.isDirectory()) addLocalDirectory(p, name, cb)
else addLocalTarball(p, name, cb)
})
})
}
+function maybeGithub (p, name, er, cb) {
+ var u = "git://github.com/" + p
+ , up = url.parse(u)
+ log.info("maybeGithub", "Attempting to fetch %s from %s", p, u)
+ return addRemoteGit(u, up, name, function (er2, data) {
+ if (er2) return cb(er)
+ return cb(null, data)
+ })
+}
+
function addLocalTarball (p, name, cb) {
if (typeof cb !== "function") cb = name, name = ""
// if it's a tar, and not in place,
@@ -1,4 +1,7 @@
{ "name":"npm-test-url-dep"
, "version" : "1.2.3"
, "dependencies" :
- { "dnode" : "https://github.com/substack/dnode/tarball/master" } }
+ { "dnode" : "https://github.com/substack/jsonify/tarball/master"
+ , "sax": "isaacs/sax-js"
+ , "canonical-host": "git://github.com/isaacs/canonical-host"
+ } }

7 comments on commit bfcd368

Contributor

Raynos replied Oct 13, 2012

winning

Now just need to add support for semver tags and the need for private npm registries dies :)

any way to make it work with github enterprise?

Owner

isaacs replied Oct 22, 2012

@cpsubrian You know that you can put any commit-ish in the hash portion of the url? So you can easily point it at a branch, tag, or specific commit.

@shanejonas Sure. Just prefix it with git://url-of-your-private-enterprise-github.host.name/ and it'll work. That's always worked.

People. Seriously. Please don't be so excited about this! There's nothing you can do with this that you couldn't do before. It's literally just removing the need for the "git://github.com/" prefix. That's it. I did this because it was incredibly easy, and I wanted to show how silly the request was. ;P

Never underestimate the laziness of a programmer and how excited they get when they have to type less characters :)

Also, this is what I was talkin about: cpsubrian/awesomesauce#>=0.1.3

Owner

isaacs replied Oct 30, 2012

You can't specify a range, no. But if you had a tag called 0.1, then you could reference that.

Contributor

guybrush replied Oct 30, 2012

now make it faster :D #2482

Please sign in to comment.