Permalink
Browse files

Add github shorthands support (with tests), closes #121.

  • Loading branch information...
1 parent b23cbb8 commit 2948eae4484a1c31292032c085c42f9f7f885477 @satazor satazor committed Nov 11, 2012
Showing with 24 additions and 0 deletions.
  1. +12 −0 lib/core/package.js
  2. +12 −0 test/package.js
View
@@ -78,6 +78,18 @@ var Package = function (name, endpoint, manager) {
} else if (fileExists.sync(endpoint)) {
this.path = path.resolve(endpoint);
+ } else if (endpoint.split('/').length === 2) {
+ var shorthand;
+
+ if (/^(.*)#(.*)$/.exec(endpoint)) {
+ shorthand = RegExp.$1;
+ this.tag = RegExp.$2;
+ } else {
+ shorthand = endpoint;
+ this.tag = false;
+ }
+
+ this.gitUrl = 'git://github.com/' + shorthand + '.git';
} else {
this.tag = endpoint.split('#', 2)[1];
}
View
@@ -32,6 +32,17 @@ describe('package', function () {
assert.equal(pkg.gitUrl, 'git://github.com/jquery/jquery.git');
});
+ it('Should resolve git shorthands (username/project)', function () {
+ var pkg = new Package('jquery', 'jquery/jquery');
+ assert.equal(pkg.gitUrl, 'git://github.com/jquery/jquery.git');
+ });
+
+ it('Should resolve git shorthands (username/project) with specific tag', function () {
+ var pkg = new Package('jquery', 'jquery/jquery#1.0.0');
+ assert.equal(pkg.gitUrl, 'git://github.com/jquery/jquery.git');
+ assert.equal(pkg.tag, '1.0.0');
+ });
+
it('Should resolve git HTTP URLs properly', function () {
var pkg = new Package('jquery', 'git+http://example.com/project.git');
assert.equal(pkg.gitUrl, 'http://example.com/project.git');
@@ -53,6 +64,7 @@ describe('package', function () {
assert.equal(pkg.gitUrl, 'git@github.com:twitter/flight.git');
});
+
it('Should resolve normal HTTP URLs', function (next) {
var pkg = new Package('bootstrap', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js');

0 comments on commit 2948eae

Please sign in to comment.