mirror of
https://github.com/bower/bower.git
synced 2026-02-11 22:44:58 -05:00
Small performance improvement by accepting an optional package meta to avoid re-reading it.
Fix tests if previous run left dummy directories.
This commit is contained in:
@@ -17,7 +17,7 @@ mout.object.mixIn(GitResolver, Resolver);
|
||||
|
||||
// -----------------
|
||||
|
||||
GitResolver.prototype._hasNew = function (pkgMeta) {
|
||||
GitResolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
|
||||
var oldResolution = pkgMeta._resolution || {};
|
||||
|
||||
return this._findResolution()
|
||||
|
||||
@@ -38,15 +38,11 @@ Resolver.prototype.getTempDir = function () {
|
||||
return this._tempDir;
|
||||
};
|
||||
|
||||
Resolver.prototype.hasNew = function (canonicalPkg) {
|
||||
Resolver.prototype.hasNew = function (canonicalPkg, pkgMeta) {
|
||||
var promise;
|
||||
var metaFile;
|
||||
var that = this;
|
||||
|
||||
// TODO: Change arguments to canonicalPkg, pkgMeta
|
||||
// where pkgMeta is optional
|
||||
// Change _hasNew to the same
|
||||
|
||||
// If already working, error out
|
||||
if (this._working) {
|
||||
return Q.reject(createError('Already working', 'EWORKING'));
|
||||
@@ -54,18 +50,18 @@ Resolver.prototype.hasNew = function (canonicalPkg) {
|
||||
|
||||
this._working = true;
|
||||
|
||||
// Avoid reading the package meta if _hasNew was not rewritten
|
||||
if (this._hasNew === Resolver.prototype._hasNew) {
|
||||
promise = this._hasNew();
|
||||
// Avoid reading the package meta if already given
|
||||
if (pkgMeta) {
|
||||
promise = this._hasNew(canonicalPkg, pkgMeta);
|
||||
// Otherwise call _hasNew with both the package meta and the canonical package
|
||||
} else {
|
||||
metaFile = path.join(canonicalPkg, '.bower.json');
|
||||
promise = Q.nfcall(fs.readFile, metaFile)
|
||||
.then(function (contents) {
|
||||
var pkgMeta = JSON.parse(contents.toString());
|
||||
return that._hasNew(pkgMeta, canonicalPkg);
|
||||
return that._hasNew(canonicalPkg, pkgMeta);
|
||||
}, function () {
|
||||
return true; // Simply resolve to true if there was an error reading the meta
|
||||
return true; // Simply resolve to true if there was an error reading the file
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,7 +126,7 @@ Resolver.prototype._resolve = function () {
|
||||
|
||||
// -----------------
|
||||
|
||||
Resolver.prototype._hasNew = function (pkgMeta) {
|
||||
Resolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
|
||||
return Q.resolve(true);
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ util.inherits(UrlResolver, Resolver);
|
||||
|
||||
// -----------------
|
||||
|
||||
UrlResolver.prototype._hasNew = function (pkgMeta) {
|
||||
UrlResolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
|
||||
var oldCacheHeaders = pkgMeta._cacheHeaders || {};
|
||||
var reqHeaders = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user