Always use package name declared in component.json

This commit is contained in:
Joshua Peek
2013-02-22 15:35:06 -06:00
parent c3e130bdf0
commit 4da57cbcb6
2 changed files with 19 additions and 3 deletions

View File

@@ -369,9 +369,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

@@ -280,6 +280,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');