Support @~ version constraints and use them for core packages. (#8991)

This commit is contained in:
Ben Newman
2017-08-08 18:01:30 -04:00
committed by GitHub
parent 6de5c25fed
commit cfdc69bf71
10 changed files with 207 additions and 10 deletions

View File

@@ -186,6 +186,10 @@ CS.isConstraintSatisfied = function (pkg, vConstraint, version) {
var cVersion = simpleConstraint.versionString;
return (cVersion === version);
} else if (type === 'compatible-with') {
if (typeof simpleConstraint.test === "function") {
return simpleConstraint.test(version);
}
var cv = PV.parse(simpleConstraint.versionString);
var v = PV.parse(version);

View File

@@ -244,20 +244,41 @@ var parseSimpleConstraint = function (constraintString) {
throw new Error("Non-empty string required");
}
var type, versionString;
var result = {};
var needToCheckValidity = true;
if (constraintString.charAt(0) === '=') {
type = "exactly";
versionString = constraintString.substr(1);
result.type = "exactly";
result.versionString = constraintString.slice(1);
} else {
type = "compatible-with";
versionString = constraintString;
result.type = "compatible-with";
if (constraintString.charAt(0) === "~") {
var semversion = PV.parse(
result.versionString = constraintString.slice(1)
).semver;
var range = new semver.Range("~" + semversion);
result.test = function (version) {
return range.test(PV.parse(version).semver);
};
// Already checked by calling PV.parse above.
needToCheckValidity = false;
} else {
result.versionString = constraintString;
}
}
// This will throw if the version string is invalid.
PV.getValidServerVersion(versionString);
if (needToCheckValidity) {
// This will throw if the version string is invalid.
PV.getValidServerVersion(result.versionString);
}
return { type: type, versionString: versionString };
return result;
};

View File

@@ -748,8 +748,9 @@ _.extend(ProjectContext.prototype, {
var constraint = utils.parsePackageConstraint(
// Note that this used to be an exact name@=version constraint,
// before #7084 eliminated these constraints completely. They
// were reinstated in Meteor 1.4.3 as name@version constraints.
packageName + "@" + version);
// were reinstated in Meteor 1.4.3 as name@version constraints,
// and further refined to name@~version constraints in 1.5.2.
packageName + "@~" + version);
// Add a constraint but no dependency (we don't automatically use
// all local packages!):
depsAndConstraints.constraints.push(constraint);

View File

@@ -0,0 +1,11 @@
Package.describe({
name: "tilde-constraints",
version: "0.4.2",
summary: "Package for testing @~ version constraints",
documentation: "README.md"
});
Package.onUse(function(api) {
api.use("ecmascript");
api.mainModule("tilde-constraints.js");
});

View File

@@ -0,0 +1 @@
console.log(module.id);

View File

@@ -0,0 +1,12 @@
Package.describe({
name: "tilde-dependent",
version: "0.1.0",
summary: "Package for testing inter-package @~ constraints",
documentation: "README.md"
});
Package.onUse(function(api) {
api.use("ecmascript");
api.use("tilde-constraints");
api.mainModule("tilde-dependent.js");
});

View File

@@ -0,0 +1 @@
console.log(module.id);

View File

@@ -955,3 +955,149 @@ selftest.define("show readme excerpt", function () {
run.matchErr("Documentation not found");
run.expectExit(1);
});
selftest.define("tilde version constraints", [], function () {
var s = new Sandbox();
s.set("METEOR_WATCH_PRIORITIZE_CHANGED", "false");
s.createApp("tilde-app", "package-tests");
s.cd("tilde-app");
var run = s.run();
run.match("tilde-app");
run.match("proxy");
run.waitSecs(10);
run.match("MongoDB");
run.waitSecs(10);
run.match("your app");
run.waitSecs(10);
run.match("running at");
run.waitSecs(60);
var packages = s.read(".meteor/packages")
.replace(/\n*$/m, "\n");
function setTopLevelConstraint(constraint) {
s.write(
".meteor/packages",
packages + "tilde-constraints" + (
constraint ? "@" + constraint : ""
) + "\n"
);
}
setTopLevelConstraint("");
run.match(/tilde-constraints.*added, version 0\.4\.2/);
run.match("tilde-constraints.js");
run.waitSecs(10);
setTopLevelConstraint("0.4.0");
run.match("tilde-constraints.js");
run.match("server restarted");
run.waitSecs(10);
setTopLevelConstraint("~0.4.0");
run.match("tilde-constraints.js");
run.match("server restarted");
run.waitSecs(10);
setTopLevelConstraint("0.4.3");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
setTopLevelConstraint("~0.4.3");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
setTopLevelConstraint("0.3.0");
run.match("tilde-constraints.js");
run.match("server restarted");
run.waitSecs(10);
setTopLevelConstraint("~0.3.0");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
setTopLevelConstraint("0.5.0");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
setTopLevelConstraint("~0.5.0");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
s.write(
".meteor/packages",
packages
);
run.match(/tilde-constraints.*removed/);
run.waitSecs(10);
s.write(
".meteor/packages",
packages + "tilde-dependent\n"
);
run.match(/tilde-constraints.*added, version 0\.4\.2/);
run.match(/tilde-dependent.*added, version 0\.1\.0/);
run.match("tilde-constraints.js");
run.match("tilde-dependent.js");
run.waitSecs(10);
var depPackageJsPath = "packages/tilde-dependent/package.js"
var depPackageJs = s.read(depPackageJsPath);
function setDepConstraint(constraint) {
s.write(
depPackageJsPath,
depPackageJs.replace(
/tilde-constraints[^"]*/g, // Syntax highlighting hack: "
"tilde-constraints" + (
constraint ? "@" + constraint : ""
)
)
);
}
setDepConstraint("0.4.0");
run.match("tilde-constraints.js");
run.match("tilde-dependent.js");
run.match("server restarted");
run.waitSecs(10);
setDepConstraint("~0.4.0");
run.match("tilde-constraints.js");
run.match("tilde-dependent.js");
run.match("server restarted");
run.waitSecs(10);
setDepConstraint("0.3.0");
run.match("tilde-constraints.js");
run.match("tilde-dependent.js");
run.match("server restarted");
run.waitSecs(10);
// TODO The rest of these tests should cause version conflicts, but it
// seems like version constraints between local packages are ignored,
// which is a larger (preexisting) problem we should investigate.
/*
setDepConstraint("=0.4.0");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
setDepConstraint("~0.3.0");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
setDepConstraint("0.4.3");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
setDepConstraint("~0.4.3");
run.match("error: No version of tilde-constraints satisfies all constraints");
run.waitSecs(10);
*/
run.stop();
});