mirror of
https://github.com/bower/bower.git
synced 2026-02-13 07:24:55 -05:00
Sort of picks must be done by the Manager, otherwise indexes are messed up.
Little code simplification on the Project.
This commit is contained in:
@@ -472,47 +472,73 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
|
||||
picks.push.apply(picks, nonSemvers);
|
||||
}
|
||||
|
||||
// If there are picks, the user needs to choose between them
|
||||
if (picks.length) {
|
||||
// If interactive is disabled, error out
|
||||
if (!this._config.interactive) {
|
||||
throw createError('Unable to find suitable version for ' + name, 'ECONFLICT', {
|
||||
picks: picks
|
||||
});
|
||||
// If there are no picks, resolve to the suitable one
|
||||
if (!picks.length) {
|
||||
return Q.resolve(suitable);
|
||||
|
||||
}
|
||||
|
||||
// Sort picks by version/release
|
||||
picks.sort(function (pick1, pick2) {
|
||||
var version1 = pick1.pkgMeta.version;
|
||||
var version2 = pick2.pkgMeta.version;
|
||||
|
||||
// If both have versions, compare their versions using semver
|
||||
if (version1 && version2) {
|
||||
if (semver.gt(version1, version2)) {
|
||||
return 1;
|
||||
}
|
||||
if (semver.lt(version1, version2)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
dataPicks = picks.map(function (pick) {
|
||||
return {
|
||||
endpoint: mout.object.pick(pick, ['name', 'source', 'target']),
|
||||
pkgMeta: pick.pkgMeta,
|
||||
canonicalPkg: pick.canonicalPkg,
|
||||
dependants: pick.dependants.map(function (dependant) {
|
||||
return {
|
||||
endpoint: mout.object.pick(dependant, ['name', 'source', 'target']),
|
||||
pkgMeta: dependant.pkgMeta,
|
||||
canonicalPkg: dependant.canonicalPkg
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
// Give priority to the one that is a version
|
||||
if (version1) {
|
||||
return 1;
|
||||
}
|
||||
if (version2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
this._logger.conflict('incompatible', 'Unable to find suitable version for ' + name, {
|
||||
picks: dataPicks,
|
||||
name: name
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
|
||||
// Question the user
|
||||
choices = picks.map(function (pick, index) {
|
||||
return index + 1;
|
||||
});
|
||||
dataPicks = picks.map(function (pick) {
|
||||
return {
|
||||
endpoint: mout.object.pick(pick, ['name', 'source', 'target']),
|
||||
pkgMeta: pick.pkgMeta,
|
||||
canonicalPkg: pick.canonicalPkg,
|
||||
dependants: pick.dependants.map(function (dependant) {
|
||||
return {
|
||||
endpoint: mout.object.pick(dependant, ['name', 'source', 'target']),
|
||||
pkgMeta: dependant.pkgMeta,
|
||||
canonicalPkg: dependant.canonicalPkg
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
return Q.nfcall(promptly.choose, 'Choice:', choices)
|
||||
.then(function (choice) {
|
||||
return picks[choice - 1];
|
||||
// If interactive is disabled, error out
|
||||
if (!this._config.interactive) {
|
||||
throw createError('Unable to find suitable version for ' + name, 'ECONFLICT', {
|
||||
name: name,
|
||||
picks: dataPicks
|
||||
});
|
||||
}
|
||||
|
||||
return Q.resolve(suitable);
|
||||
// Otherwise, question the user
|
||||
this._logger.conflict('incompatible', 'Unable to find suitable version for ' + name, {
|
||||
name: name,
|
||||
picks: dataPicks
|
||||
});
|
||||
|
||||
choices = picks.map(function (pick, index) { return index + 1; });
|
||||
return Q.nfcall(promptly.choose, 'Choice:', choices)
|
||||
.then(function (choice) {
|
||||
return picks[choice - 1];
|
||||
});
|
||||
};
|
||||
|
||||
Manager.prototype._getCap = function (comparators, side) {
|
||||
|
||||
@@ -28,7 +28,6 @@ Project.prototype.install = function (endpoints, options) {
|
||||
var that = this;
|
||||
var targets = [];
|
||||
var resolved = {};
|
||||
var installed;
|
||||
|
||||
// If already working, error out
|
||||
if (this._working) {
|
||||
@@ -60,19 +59,12 @@ Project.prototype.install = function (endpoints, options) {
|
||||
// Add endpoints as targets
|
||||
if (endpoints) {
|
||||
endpoints.forEach(function (endpoint) {
|
||||
var decEndpoint = endpointParser.decompose(endpoint);
|
||||
targets[decEndpoint.name] = decEndpoint;
|
||||
targets.push(endpointParser.decompose(endpoint));
|
||||
});
|
||||
}
|
||||
|
||||
// Mark installed
|
||||
installed = mout.object.map(flattened, function (decEndpoint) {
|
||||
return decEndpoint.pkgMeta;
|
||||
});
|
||||
})
|
||||
// Bootstrap the process
|
||||
.then(function () {
|
||||
return that._bootstrap(mout.object.values(targets), resolved, installed);
|
||||
// Bootstrap the process
|
||||
return that._bootstrap(targets, resolved, flattened);
|
||||
})
|
||||
// Handle save and saveDev options
|
||||
.then(function (installed) {
|
||||
@@ -112,7 +104,6 @@ Project.prototype.update = function (names, options) {
|
||||
var that = this;
|
||||
var targets = [];
|
||||
var resolved = {};
|
||||
var installed;
|
||||
|
||||
// If already working, error out
|
||||
if (this._working) {
|
||||
@@ -162,8 +153,7 @@ Project.prototype.update = function (names, options) {
|
||||
node.walked = true;
|
||||
});
|
||||
|
||||
// Mark extraneous as targets only if
|
||||
// it's not already a target
|
||||
// Mark extraneous as targets only if it's not already a target
|
||||
mout.object.forOwn(flattened, function (decEndpoint) {
|
||||
var foundTarget;
|
||||
var name = decEndpoint.name;
|
||||
@@ -180,14 +170,8 @@ Project.prototype.update = function (names, options) {
|
||||
});
|
||||
}
|
||||
|
||||
// Mark installed
|
||||
installed = mout.object.map(flattened, function (decEndpoint) {
|
||||
return decEndpoint.pkgMeta;
|
||||
});
|
||||
})
|
||||
// Bootstrap the process
|
||||
.then(function () {
|
||||
return that._bootstrap(targets, resolved, installed);
|
||||
// Bootstrap the process
|
||||
return that._bootstrap(targets, resolved, flattened);
|
||||
})
|
||||
.fin(function () {
|
||||
that._working = false;
|
||||
@@ -338,7 +322,11 @@ Project.prototype.analyse = function () {
|
||||
|
||||
// -----------------
|
||||
|
||||
Project.prototype._bootstrap = function (targets, resolved, installed) {
|
||||
Project.prototype._bootstrap = function (targets, resolved, flattened) {
|
||||
var installed = mout.object.map(flattened, function (decEndpoint) {
|
||||
return decEndpoint.pkgMeta;
|
||||
});
|
||||
|
||||
// Configure the manager and kick in the resolve process
|
||||
return this._manager
|
||||
.setProduction(this._production)
|
||||
|
||||
@@ -126,40 +126,12 @@ StandardRenderer.prototype._incompatibleLog = function (log) {
|
||||
|
||||
// Generate dependants string for each pick
|
||||
log.data.picks.forEach(function (pick) {
|
||||
|
||||
pick.dependants = pick.dependants.map(function (dependant) {
|
||||
var release = dependant.pkgMeta._release;
|
||||
return dependant.endpoint.name + (release ? '#' + release : '');
|
||||
}).join(', ');
|
||||
});
|
||||
|
||||
// Sort picks by version/release
|
||||
log.data.picks.sort(function (pick1, pick2) {
|
||||
var version1 = pick1.pkgMeta.version;
|
||||
var version2 = pick2.pkgMeta.version;
|
||||
|
||||
// If both have versions, compare their versions using semver
|
||||
if (version1 && version2) {
|
||||
if (semver.gt(version1, version2)) {
|
||||
return 1;
|
||||
}
|
||||
if (semver.lt(version1, version2)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Give priority to the one that is a version
|
||||
if (version1) {
|
||||
return 1;
|
||||
}
|
||||
if (version2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
str = template.render('std/incompatible.std', log.data);
|
||||
|
||||
this._write(process.stdout, '\n');
|
||||
|
||||
Reference in New Issue
Block a user