mirror of
https://github.com/bower/bower.git
synced 2026-04-02 03:01:15 -04:00
Some changes to the resolver API, add more tests.
This commit is contained in:
@@ -39,25 +39,51 @@ Resolver.prototype.getTempDir = function () {
|
||||
};
|
||||
|
||||
Resolver.prototype.hasNew = function (canonicalPkg) {
|
||||
return Q.resolve(true);
|
||||
var that = this,
|
||||
promise,
|
||||
metaFile;
|
||||
|
||||
// If already working, error out
|
||||
if (this._working) {
|
||||
return Q.reject(createError('Already working', 'EWORKING'));
|
||||
}
|
||||
|
||||
this._working = true;
|
||||
|
||||
// Avoid reading the package meta if _hasNew was not rewritten
|
||||
if (this._hasNew === Resolver.prototype._hasNew) {
|
||||
promise = this._hasNew();
|
||||
// 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);
|
||||
}, function () {
|
||||
return true; // Simply resolve to true if there was an error reading the meta
|
||||
});
|
||||
}
|
||||
|
||||
return promise.fin(function () {
|
||||
that._working = false;
|
||||
});
|
||||
};
|
||||
|
||||
Resolver.prototype.resolve = function () {
|
||||
var that = this;
|
||||
|
||||
// If already resolving, throw an error
|
||||
// We don't actually reject a promise because this is a
|
||||
// serious logic error
|
||||
if (this._resolving) {
|
||||
throw new Error('Already resolving');
|
||||
// If already working, error out
|
||||
if (this._working) {
|
||||
return Q.reject(createError('Already working', 'EWORKING'));
|
||||
}
|
||||
|
||||
this._resolving = true;
|
||||
this._working = true;
|
||||
|
||||
// Create temporary dir
|
||||
return this._createTempDir()
|
||||
// Resolve self
|
||||
.then(this._resolveSelf.bind(this))
|
||||
.then(this._resolve.bind(this))
|
||||
// Read json, generating the package meta
|
||||
.then(function () {
|
||||
return that._readJson(that._tempDir);
|
||||
@@ -71,14 +97,15 @@ Resolver.prototype.resolve = function () {
|
||||
]);
|
||||
})
|
||||
.then(function () {
|
||||
that._resolving = false;
|
||||
// Resolve with the folder
|
||||
return that._tempDir;
|
||||
}, function (err) {
|
||||
that._resolving = false;
|
||||
// If something went wrong, unset the temporary dir
|
||||
that._tempDir = null;
|
||||
throw err;
|
||||
})
|
||||
.fin(function () {
|
||||
that._working = false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -93,12 +120,16 @@ Resolver.clearRuntimeCache = function () {};
|
||||
// -----------------
|
||||
|
||||
// Abstract function that should be implemented by concrete resolvers
|
||||
Resolver.prototype._resolveSelf = function () {
|
||||
throw new Error('_resolveSelf not implemented');
|
||||
Resolver.prototype._resolve = function () {
|
||||
throw new Error('_resolve not implemented');
|
||||
};
|
||||
|
||||
// -----------------
|
||||
|
||||
Resolver.prototype._hasNew = function (pkgMeta, canonicalPkg) {
|
||||
return Q.resolve(true);
|
||||
};
|
||||
|
||||
Resolver.prototype._createTempDir = function () {
|
||||
var baseDir = path.join(tmp.tmpdir, 'bower');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user