mirror of
https://github.com/bower/bower.git
synced 2026-02-12 06:55:04 -05:00
Initial take on the commands + renderers + cli.
This commit is contained in:
@@ -100,8 +100,10 @@ Manager.prototype.install = function () {
|
||||
var release = decEndpoint.pkgMeta._release;
|
||||
|
||||
deferred.notify({
|
||||
type: 'action',
|
||||
data: 'Installing' + (release ? ' "' + release + '"' : ''),
|
||||
level: 'action',
|
||||
tag: 'install',
|
||||
data: name + (release ? '#' + release : ''),
|
||||
pkgMeta: decEndpoint.pkgMeta,
|
||||
origin: name,
|
||||
endpoint: decEndpoint
|
||||
});
|
||||
@@ -181,6 +183,8 @@ Manager.prototype.areCompatible = function (first, second) {
|
||||
|
||||
Manager.prototype._fetch = function (decEndpoint) {
|
||||
var name = decEndpoint.name;
|
||||
var deferred = this._deferred;
|
||||
var that = this;
|
||||
|
||||
// Mark as being fetched
|
||||
this._fetching[name] = this._fetching[name] || [];
|
||||
@@ -192,24 +196,36 @@ Manager.prototype._fetch = function (decEndpoint) {
|
||||
// because it might be reused if a similar endpoint needs to be resolved
|
||||
decEndpoint.promise = this._repository.fetch(decEndpoint)
|
||||
// When done, call onFetch
|
||||
.spread(this._onFetch.bind(this, decEndpoint))
|
||||
.spread(this._onFetch.bind(this, deferred, decEndpoint))
|
||||
// If it fails, we make the whole process to error out
|
||||
.fail(function (err) {
|
||||
err.origin = that._getOrigin(decEndpoint);
|
||||
err.endpoint = decEndpoint;
|
||||
deferred.reject(err);
|
||||
})
|
||||
// Listen to progress to proxy them to the resolve deferred
|
||||
// Note that we also mark where the notification is coming from
|
||||
.progress(function (notification) {
|
||||
notification.origin = that._getOrigin(decEndpoint);
|
||||
notification.endpoint = decEndpoint;
|
||||
notification.origin = name || decEndpoint.registryName || decEndpoint.resolverName;
|
||||
this._deferred.notify(notification);
|
||||
}.bind(this));
|
||||
deferred.notify(notification);
|
||||
});
|
||||
|
||||
return decEndpoint.promise;
|
||||
};
|
||||
|
||||
Manager.prototype._onFetch = function (decEndpoint, canonicalPkg, pkgMeta) {
|
||||
Manager.prototype._onFetch = function (deferred, decEndpoint, canonicalPkg, pkgMeta) {
|
||||
var name;
|
||||
var resolved;
|
||||
var index;
|
||||
var initialName = decEndpoint.name;
|
||||
|
||||
// If the deferred associated with the process is already rejected,
|
||||
// do not proceed.
|
||||
if (deferred.promise.isRejected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove from being fetched list
|
||||
mout.array.remove(this._fetching[initialName], decEndpoint);
|
||||
this._nrFetching--;
|
||||
@@ -373,6 +389,10 @@ Manager.prototype._dissect = function () {
|
||||
this._deferred.resolve(pkgMetas);
|
||||
};
|
||||
|
||||
Manager.prototype._getOrigin = function (decEndpoint) {
|
||||
return decEndpoint.name || decEndpoint.registryName || decEndpoint.resolverName;
|
||||
};
|
||||
|
||||
Manager.prototype._findHighestVersion = function (comparators) {
|
||||
var highest;
|
||||
var matches;
|
||||
@@ -403,4 +423,4 @@ Manager.prototype._findHighestVersion = function (comparators) {
|
||||
return highest;
|
||||
};
|
||||
|
||||
module.exports = Manager;
|
||||
module.exports = Manager;
|
||||
|
||||
@@ -25,7 +25,7 @@ var PackageRepository = function (options) {
|
||||
// -----------------
|
||||
|
||||
PackageRepository.prototype.fetch = function (decEndpoint) {
|
||||
var resolver;
|
||||
var res;
|
||||
var deferred = Q.defer();
|
||||
var that = this;
|
||||
|
||||
@@ -33,15 +33,20 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
|
||||
resolverFactory(decEndpoint, this._options)
|
||||
// Decide if we retrieve from the cache or not
|
||||
// Also decide we if validate the cached entry or not
|
||||
.then(function (res) {
|
||||
resolver = res;
|
||||
.then(function (resolver) {
|
||||
res = resolver;
|
||||
|
||||
// Set the resolver name in the decEndpoint
|
||||
decEndpoint.resolverName = res.getName();
|
||||
decEndpoint.resolverName = resolver.getName();
|
||||
|
||||
// If force flag is used, bypass cache
|
||||
if (that._options.force) {
|
||||
deferred.notify({ type: 'action', data: 'Resolving' });
|
||||
deferred.notify({
|
||||
level: 'action',
|
||||
tag: 'resolve',
|
||||
resolver: resolver,
|
||||
data: 'Resolving ' + resolver.getSource(),
|
||||
});
|
||||
return that._resolve(resolver);
|
||||
}
|
||||
|
||||
@@ -54,23 +59,50 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
|
||||
if (!canonicalPkg) {
|
||||
// And the offline flag is passed, error out
|
||||
if (that._options.offline) {
|
||||
throw createError('No cached version for ' + resolver.getTarget(), 'ENOCACHE');
|
||||
throw createError('No cached version for ' + resolver.getSource() + '#' + resolver.getTarget(), 'ENOCACHE', {
|
||||
resolver: resolver
|
||||
});
|
||||
}
|
||||
|
||||
// Otherwise, we have to resolve it
|
||||
deferred.notify({ type: 'action', data: 'No cached version, resolving..' });
|
||||
deferred.notify({
|
||||
level: 'info',
|
||||
tag: 'not-cached',
|
||||
data: 'No cached version for ' + resolver.getSource() + '#' + resolver.getTarget(),
|
||||
});
|
||||
deferred.notify({
|
||||
level: 'action',
|
||||
tag: 'resolve',
|
||||
resolver: resolver,
|
||||
data: 'Resolving ' + resolver.getSource() + '#' + resolver.getTarget(),
|
||||
});
|
||||
|
||||
return that._resolve(resolver);
|
||||
}
|
||||
|
||||
deferred.notify({
|
||||
level: 'info',
|
||||
tag: 'cached',
|
||||
data: 'Got cached ' + resolver.getSource() + (pkgMeta._release ? '#' + pkgMeta._release: '') + ' entry',
|
||||
canonicalPkg: canonicalPkg,
|
||||
pkgMeta: pkgMeta
|
||||
});
|
||||
|
||||
// If offline flag is used, use directly the cached one
|
||||
if (that._options.offline) {
|
||||
deferred.notify({ type: 'action', data: 'Got cached version' });
|
||||
return [canonicalPkg, pkgMeta];
|
||||
}
|
||||
|
||||
// Otherwise check for new contents
|
||||
process.nextTick(function () {
|
||||
deferred.notify({ type: 'action', data: 'Got cached version, validating..' });
|
||||
deferred.notify({
|
||||
level: 'action',
|
||||
tag: 'check',
|
||||
data: 'Checking ' + resolver.getSource() + '#' + resolver.getTarget() + ' for newer version',
|
||||
canonicalPkg: canonicalPkg,
|
||||
pkgMeta: pkgMeta,
|
||||
resolver: resolver
|
||||
});
|
||||
});
|
||||
|
||||
return resolver.hasNew(canonicalPkg, pkgMeta)
|
||||
@@ -82,13 +114,28 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
|
||||
}
|
||||
|
||||
// Otherwise resolve to the newest one
|
||||
deferred.notify({ type: 'action', data: 'There\'s a new version, resolving..' });
|
||||
deferred.notify({
|
||||
type: 'info',
|
||||
data: 'There\'s a new version for ' + resolver.getSource() + '#' + resolver.getTarget(),
|
||||
canonicalPkg: canonicalPkg,
|
||||
pkgMeta: pkgMeta,
|
||||
resolver: resolver
|
||||
});
|
||||
deferred.notify({
|
||||
type: 'resolve',
|
||||
resolver: resolver,
|
||||
data: 'Resolving ' + resolver.getSource() + '#' + resolver.getTarget()
|
||||
});
|
||||
|
||||
return that._resolve(resolver);
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(deferred.resolve, deferred.reject, deferred.notify);
|
||||
.then(deferred.resolve, deferred.reject, function (notification) {
|
||||
// Store the resolver for each notification
|
||||
notification.resolver = res;
|
||||
deferred.notify(notification);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
@@ -115,4 +162,4 @@ PackageRepository.prototype._resolve = function (resolver) {
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
module.exports = PackageRepository;
|
||||
module.exports = PackageRepository;
|
||||
|
||||
@@ -184,7 +184,9 @@ Project.prototype._readJson = function () {
|
||||
if (path.basename(filename) === 'component.json') {
|
||||
process.nextTick(function () {
|
||||
deferred.notify({
|
||||
type: 'warn',
|
||||
level: 'warn',
|
||||
tag: 'deprecated',
|
||||
json: filename,
|
||||
data: 'You are using the deprecated component.json file'
|
||||
});
|
||||
});
|
||||
@@ -285,4 +287,4 @@ Project.prototype._restoreNode = function (node, flattened, jsonKey) {
|
||||
}, this);
|
||||
};
|
||||
|
||||
module.exports = Project;
|
||||
module.exports = Project;
|
||||
|
||||
@@ -208,4 +208,4 @@ ResolveCache.prototype._sortVersions = function (versions) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = ResolveCache;
|
||||
module.exports = ResolveCache;
|
||||
|
||||
@@ -103,7 +103,7 @@ function createResolver(decEndpoint, options) {
|
||||
});
|
||||
};
|
||||
})
|
||||
// If we got the func, simply call and return
|
||||
// If we got the function, simply call and return
|
||||
.then(function (func) {
|
||||
return func();
|
||||
// Finally throw a meaningful error
|
||||
|
||||
@@ -40,18 +40,30 @@ GitResolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
|
||||
GitResolver.prototype._resolve = function () {
|
||||
var deferred = Q.defer();
|
||||
|
||||
deferred.notify({ type: 'action', data: 'Finding resolution' });
|
||||
deferred.notify({
|
||||
level: 'action',
|
||||
tag: 'versions',
|
||||
data: 'Finding resolution'
|
||||
});
|
||||
|
||||
this._findResolution()
|
||||
.then(function (resolution) {
|
||||
deferred.notify({ type: 'action', data: 'Checking out "' + (resolution.tag || resolution.branch || resolution.commit) + '"' });
|
||||
deferred.notify({
|
||||
level: 'action',
|
||||
tag: 'checkout',
|
||||
data: 'Checking out "' + (resolution.tag || resolution.branch || resolution.commit) + '"'
|
||||
});
|
||||
|
||||
return this._checkout()
|
||||
// Always run cleanup after checkout to ensure that .git is removed!
|
||||
// If it's not removed, problems might arise when the "tmp" module attempts
|
||||
// to delete the temporary folder
|
||||
.fin(function () {
|
||||
deferred.notify({ type: 'action', data: 'Cleaning up' });
|
||||
deferred.notify({
|
||||
level: 'action',
|
||||
tag: 'cleanup',
|
||||
data: 'Cleaning up git artifacts'
|
||||
});
|
||||
return this._cleanup();
|
||||
}.bind(this));
|
||||
}.bind(this))
|
||||
@@ -179,7 +191,8 @@ GitResolver.prototype._savePkgMeta = function (meta) {
|
||||
if (typeof meta.version === 'string' && semver.neq(meta.version, version)) {
|
||||
process.nextTick(function (metaVersion) {
|
||||
deferred.notify({
|
||||
type: 'warn',
|
||||
level: 'warn',
|
||||
tag: 'mismatch',
|
||||
data: 'Version declared in the json (' + metaVersion + ') is different than the resolved one (' + version + ')'
|
||||
});
|
||||
}.bind(this, meta.version));
|
||||
@@ -194,7 +207,7 @@ GitResolver.prototype._savePkgMeta = function (meta) {
|
||||
}
|
||||
|
||||
// Save version/commit/branch/tag in the release
|
||||
meta._release = version || this._resolution.tag || this._resolution.commit;
|
||||
meta._release = version || this._resolution.tag || this._resolution.commit.substr(0, 10);
|
||||
|
||||
// Save resolution to be used in hasNew later
|
||||
meta._resolution = this._resolution;
|
||||
|
||||
@@ -155,7 +155,9 @@ Resolver.prototype._readJson = function (dir) {
|
||||
// If it is a component.json, warn about the deprecation
|
||||
if (path.basename(filename) === 'component.json') {
|
||||
deferred.notify({
|
||||
type: 'warn',
|
||||
level: 'warn',
|
||||
tag: 'deprecated',
|
||||
json: filename,
|
||||
data: 'Package "' + this._name + '" is using the deprecated component.json file'
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ UrlResolver.prototype._savePkgMeta = function (meta) {
|
||||
|
||||
// Store ETAG under _release
|
||||
if (meta._cacheHeaders.ETag) {
|
||||
meta._release = 'e-tag: ' + mout.string.trim(meta._cacheHeaders.ETag, '"');
|
||||
meta._release = 'e-tag:' + mout.string.trim(meta._cacheHeaders.ETag.substr(0, 10), '"');
|
||||
}
|
||||
|
||||
// Store main if is a single file
|
||||
|
||||
Reference in New Issue
Block a user