Skip to content

Commit 8ea13f1

Browse files
Merge pull request #140 from adaptlearning/feature/pre-releases
Add logic for compatible newer (pre-release) tags
2 parents d68d1e7 + cd73d35 commit 8ea13f1

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

lib/commands/install.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ module.exports = function (dependencies) {
266266
var compatibleWithOldIncompatibleConstraint = present.filter(isCompatibleWithOldIncompatibleConstraint);
267267
// a compatible version exists but the user requested an older version that is compatible (prompt for (r)equested, (l)atest compatible or (s)kip)
268268
var compatibleWithOldCompatibleConstraint = present.filter(isCompatibleWithOldCompatibleConstraint);
269+
// a compatible version exists but the user requested a newer version that is compatible (prompt for (r)equested, (l)atest compatible or (s)kip)
270+
var compatibleWithNewCompatibleConstraint = present.filter(isCompatibleWithNewCompatibleConstraint);
269271
// a compatible version exists but the user gave a bad constraint (prompt for (c)ompatible or (s)kip)
270272
var compatibleWithBadConstraint = present.filter(isCompatibleWithBadConstraint);
271273
// a compatible version exists but user has requested a valid version that is later than the latest compatible version (prompt for (r)equested, (l)atest compatible or (s)kip)
@@ -299,6 +301,10 @@ module.exports = function (dependencies) {
299301
p.markRequestedForInstallation();
300302
});
301303

304+
compatibleWithNewCompatibleConstraint.forEach(function(p) {
305+
p.markRequestedForInstallation();
306+
});
307+
302308
return Q.resolve();
303309
}
304310

@@ -315,6 +321,8 @@ module.exports = function (dependencies) {
315321
add(compatibleWithOldIncompatibleConstraint, 'An older incompatible version has been requested for the following plugins:', getPrompt_compatibleWithOldIncompatibleConstraint);
316322

317323
add(compatibleWithOldCompatibleConstraint, 'A compatible but older version has been requested for the following plugins:', getPrompt_compatibleWithOldCompatibleConstraint);
324+
325+
add(compatibleWithNewCompatibleConstraint, 'A compatible but newer version has been requested for the following plugins:', getPrompt_compatibleWithNewCompatibleConstraint);
318326

319327
add(compatibleWithBadConstraint, 'An invalid constraint was given but a compatible version exists for the following plugins:', getPrompt_compatibleWithBadConstraint);
320328

@@ -471,6 +479,38 @@ module.exports = function (dependencies) {
471479
});
472480
}
473481

482+
function getPrompt_compatibleWithNewCompatibleConstraint(p) {
483+
return createPromptTask({
484+
message: chalk.white(p.packageName),
485+
choices: [
486+
{
487+
name: `requested version [${p._resolvedConstraint}]`,
488+
value: 'r'
489+
},
490+
{
491+
name: `latest compatible version [${p._latestCompatibleVersion}]`,
492+
value: 'l'
493+
},
494+
{
495+
name: 'skip',
496+
value: 's'
497+
}
498+
],
499+
type: 'list',
500+
default: 's',
501+
onlyRejectOnError: true
502+
})
503+
.then(function (result) {
504+
var installRequested = result === 'r';
505+
var installLatestCompatible = result === 'l';
506+
507+
if (installRequested) p.markRequestedForInstallation();
508+
if (installLatestCompatible) p.markLatestCompatibleForInstallation();
509+
510+
return Q.resolve();
511+
});
512+
}
513+
474514
function getPrompt_compatibleWithBadConstraint(p) {
475515
return createPromptTask({
476516
message: chalk.white(p.packageName),
@@ -772,6 +812,10 @@ module.exports = function (dependencies) {
772812
return isCompatible(p) && isConstrained(p) && isGoodConstraint(p) && !isConstraintCompatible(p) && semver.gt(semver.maxSatisfying(p._versions, p.version), p._latestCompatibleVersion);
773813
}
774814

815+
function isCompatibleWithNewCompatibleConstraint(p) {
816+
return isCompatible(p) && isConstrained(p) && isGoodConstraint(p) && isConstraintCompatible(p) && semver.gt(semver.maxSatisfying(p._versions, p.version), p._latestCompatibleVersion);
817+
}
818+
775819
// simple filters
776820

777821
function isConstraintCompatible(p) {

0 commit comments

Comments
 (0)