Merge pull request #268 from twitter/package-json-name-is-authoritative

component.json package name should be authoritative
This commit is contained in:
Joshua Peek
2013-03-13 14:07:50 -07:00
2 changed files with 19 additions and 3 deletions

View File

@@ -367,9 +367,7 @@ Package.prototype.loadJSON = function () {
this.json = json;
this.version = this.commit || json.commit || json.version;
this.commit = this.commit || json.commit;
// Only overwrite the name if not already set
// This is because some packages have different names declared in the registry and the json
if (!this.name) this.name = json.name;
this.name = json.name;
// Read the endpoint from the json to ensure it is set correctly
this.readEndpoint();

View File

@@ -311,6 +311,24 @@ describe('package', function () {
pkg.loadJSON();
});
it('Should correct guessed name with configured json file package-wise', function (next) {
var pkg = new Package(null, __dirname + '/assets/package-jquery');
pkg.on('loadJSON', function () {
assert(pkg.json);
assert.equal(pkg.name, 'jquery');
assert.equal(pkg.json.name, 'jquery');
assert.equal(pkg.json.version, '1.8.1');
next();
});
pkg.on('error', function (err) {
throw err;
});
pkg.loadJSON();
});
it('Should give an error on an invalid components.json', function (next) {
var pkg = new Package('jquery', __dirname + '/assets/package-invalid-json');