Add static function to clear the internal resolvers cache, fix some issues.

This commit is contained in:
André Cruz
2013-04-28 12:53:44 +01:00
parent bf61ed6310
commit b5054a7a7f
7 changed files with 81 additions and 37 deletions

View File

@@ -17,7 +17,7 @@ var Resolver = function (source, options) {
this._source = source;
this._target = options.target || '*';
this._name = options.name || this._source;
this._name = options.name || path.basename(this._source);
this._guessedName = !options.name;
this._config = options.config || config;
};
@@ -79,6 +79,10 @@ Resolver.prototype.getPkgMeta = function () {
// -----------------
Resolver.clearRuntimeCache = function () {};
// -----------------
// Abstract function that should be implemented by concrete resolvers
Resolver.prototype._resolveSelf = function () {
throw new Error('_resolveSelf not implemented');
@@ -186,4 +190,5 @@ Resolver.prototype._createIgnoreFilter = function (ignore) {
return list.matches(filename);
};
};
module.exports = Resolver;

View File

@@ -6,6 +6,11 @@ var cmd = require('../../util/cmd');
var GitRemoteResolver = function (source, options) {
GitResolver.call(this, source, options);
// If the name was guessed, remove the trailing .git
if (this._guessedName && mout.string.endsWith(this._name, '.git')) {
this._name = this._name.slice(0, -4);
}
};
util.inherits(GitRemoteResolver, GitResolver);

View File

@@ -10,14 +10,10 @@ var createError = require('../../util/createError');
var GitResolver = function (source, options) {
Resolver.call(this, source, options);
// Guess the name
if (this._guessedName) {
this._name = path.basename(this._source, '.git');
}
};
util.inherits(GitResolver, Resolver);
mout.object.mixIn(GitResolver, Resolver);
// -----------------
@@ -275,4 +271,11 @@ GitResolver.fetchBranches = function (source) {
}.bind(this));
};
GitResolver.clearRuntimeCache = function () {
GitResolver._branches = null;
GitResolver._tags = null;
GitResolver._versions = null;
GitResolver._refs = null;
};
module.exports = GitResolver;