mirror of
https://github.com/bower/bower.git
synced 2026-02-11 14:34:58 -05:00
Remove read of local rc to get the json name, small tweaks.
This commit is contained in:
@@ -15,9 +15,10 @@ var Package = function (endpoint, options) {
|
||||
|
||||
this._endpoint = endpoint;
|
||||
this._name = options.name;
|
||||
this._explicitName = !!this.name;
|
||||
this._guessedName = !this.name;
|
||||
this._range = options.range || '*';
|
||||
this._unitOfWork = options.unitOfWork || new UnitOfWork();
|
||||
this._config = options.config || config;
|
||||
};
|
||||
|
||||
util.inherits(Package, events.EventEmitter);
|
||||
@@ -53,13 +54,11 @@ Package.prototype.resolve = function () {
|
||||
return this._createTempDir()
|
||||
// 3nd - Resolve self
|
||||
.then(this._resolveSelf.bind(this))
|
||||
// 4th - Read local rc
|
||||
.then(this._readRc.bind(this))
|
||||
// 5th - Read json
|
||||
// 4th - Read json
|
||||
.then(this._readJson.bind(this))
|
||||
// 6th - Parse json
|
||||
// 5th - Parse json
|
||||
.then(this._parseJson.bind(this))
|
||||
// 7th - Mark as resolved & call done
|
||||
// 6th - Mark as resolved & call done
|
||||
// to inform the unit of work
|
||||
.then(function (dependencies) {
|
||||
this._resolved = true;
|
||||
@@ -70,7 +69,7 @@ Package.prototype.resolve = function () {
|
||||
done();
|
||||
throw err;
|
||||
}.bind(this))
|
||||
// 8th - Resolve dependencies
|
||||
// 7th - Resolve dependencies
|
||||
.then(this._resolveDependencies.bind(this));
|
||||
}.bind(this), function (err) {
|
||||
// If error is of a duplicate package,
|
||||
@@ -129,40 +128,7 @@ Package.prototype._createTempDir = function () {
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Package.prototype._readRc = function () {
|
||||
console.log('_readRc');
|
||||
|
||||
// Resolved if cached
|
||||
if (this._rc) {
|
||||
return Q.fcall(this._rc);
|
||||
}
|
||||
|
||||
var rcFile = path.join(this.getTempDir(), '.bowerrc');
|
||||
|
||||
// 1nd - Read rc as string
|
||||
return Q.nfcall(fs.readFile, rcFile)
|
||||
// 2nd - If successfull, parse it as json
|
||||
// - If the file does not exist, make it the global config
|
||||
.then(function (contents) {
|
||||
try {
|
||||
this._rc = JSON.parse(contents);
|
||||
return this._rc;
|
||||
} catch (e) {
|
||||
throw createError('Unable to parse local ".bowerrc" file', 'EINVJSON', {
|
||||
details: 'Unable to parse JSON file "' + rcFile + '": ' + e.message
|
||||
});
|
||||
}
|
||||
}.bind(this), function (err) {
|
||||
// If the file does not exist, return the global config
|
||||
if (err.code === 'ENOENT') {
|
||||
return config;
|
||||
}
|
||||
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
||||
Package.prototype._readJson = function (rc) {
|
||||
Package.prototype._readJson = function () {
|
||||
console.log('_readJson');
|
||||
|
||||
// Resolve if cached
|
||||
@@ -172,18 +138,18 @@ Package.prototype._readJson = function (rc) {
|
||||
|
||||
var jsonFile;
|
||||
|
||||
function read(file) {
|
||||
jsonFile = file;
|
||||
return Q.nfcall(fs.readFile, path.join(this.getTempDir(), file));
|
||||
}
|
||||
|
||||
// Try package rc.json
|
||||
return read.call(this, rc.json)
|
||||
// Try bower.json
|
||||
.then(null, read.bind(this, 'bower.json'))
|
||||
// Try component.json (deprecated, remove later)
|
||||
.then(null, function () {
|
||||
return read.call(this, 'component.json')
|
||||
jsonFile = path.join(this.getTempDir(), 'bower.json');
|
||||
return Q.nfcall(fs.readFile, jsonFile)
|
||||
// Try component.json
|
||||
.then(null, function (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
|
||||
jsonFile = path.join(this.getTempDir(), 'component.json');
|
||||
return Q.nfcall(fs.readFile, jsonFile)
|
||||
// Issue a deprecation message if it exists
|
||||
.then(function (contents) {
|
||||
this.emit('warn', 'Package "' + this.name + '" is using the deprecated component.json file');
|
||||
return contents;
|
||||
@@ -196,19 +162,19 @@ Package.prototype._readJson = function (rc) {
|
||||
this._json = JSON.parse(contents);
|
||||
return this._json;
|
||||
} catch (e) {
|
||||
throw createError('Unable to parse local "' + path.basename(jsonFile) + '" file', 'EINVJSON', {
|
||||
details: 'Unable to parse JSON file "' + jsonFile + '": ' + e.message
|
||||
throw createError('Unable to parse "' + jsonFile + '" file', e.code, {
|
||||
details: e.message
|
||||
});
|
||||
}
|
||||
// Otherwise there was an error
|
||||
}.bind(this), function (err) {
|
||||
// If no json file was found, return an empty one
|
||||
// If no json file was found, return one just with the name
|
||||
if (err.code === 'ENOENT') {
|
||||
this._json = { name: this.name };
|
||||
return {};
|
||||
return this._json;
|
||||
}
|
||||
|
||||
// If we got here, the error code is something else so we throw it
|
||||
// If we got here, the error code is something else so we re-throw it
|
||||
throw err;
|
||||
}.bind(this));
|
||||
};
|
||||
@@ -221,19 +187,19 @@ Package.prototype._parseJson = function (json) {
|
||||
return Q.fcall(this._dependencies);
|
||||
}
|
||||
|
||||
// 1st - Check if name defined in the json is different
|
||||
// Only handle it if the package name was not explicitly set
|
||||
if (!this._explicitName && json.name !== this.name) {
|
||||
// Check if name defined in the json is different
|
||||
// If so and if the name was "guessed", assume the json name
|
||||
if (this._guessedName && json.name !== this.name) {
|
||||
this.name = json.name;
|
||||
this.emit('name_change', this.name);
|
||||
}
|
||||
|
||||
// 2nd - Handle ignore property
|
||||
// Handle ignore property, deleting all files from the temporary directory
|
||||
return Q.fcall(function () {
|
||||
// Delete all the files specified in the ignore from the temporary directory
|
||||
// TODO:
|
||||
}.bind(this))
|
||||
// 3rd - Handle the dependencies property
|
||||
// Handle the dependencies property
|
||||
.then(function () {
|
||||
var key,
|
||||
promises = [];
|
||||
@@ -246,7 +212,7 @@ Package.prototype._parseJson = function (json) {
|
||||
}
|
||||
}
|
||||
|
||||
// Since the create package actually returns a promise, we must resolve them all
|
||||
// Resolve all the create packages promises
|
||||
return Q.all(promises).then(function (packages) {
|
||||
this._dependencies = packages;
|
||||
return packages;
|
||||
|
||||
Reference in New Issue
Block a user