mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
parseConstraint -> parsePackageConstraint
In the return value, `name` has been changed to `package`,
and `vConstraint` is now `versionConstraint`.
`constraint.package` is better than `constraint.name`, where
`constraint` is a PackageConstraint. It's also more consistent
with functions like parsePackageAtVersion which return an object
like `{package, version}`.
`vConstraint` was too cryptic.
Changes were discussed with Glasser in a code review.
Troposphere does not call parseConstraint or work with constraint
objects, so it doesn't need to change.
This is a breaking change to the package-version-parser API (or one
method of it, at least), but it is considered an internal API so we
are not worrying too much about it.
This commit is contained in:
@@ -22,7 +22,7 @@ CS.CatalogCache.prototype.hasPackageVersion = function (package, version) {
|
||||
CS.CatalogCache.prototype.addPackageVersion = function (p, v, deps) {
|
||||
check(p, String);
|
||||
check(v, String);
|
||||
// `deps` must not have any duplicate values of `.packageConstraint.name`
|
||||
// `deps` must not have any duplicate values of `.packageConstraint.package`
|
||||
check(deps, [CS.Dependency]);
|
||||
|
||||
var key = pvkey(p, v);
|
||||
@@ -38,7 +38,7 @@ CS.CatalogCache.prototype.addPackageVersion = function (p, v, deps) {
|
||||
var depsByPackage = {};
|
||||
this._dependencies[key] = depsByPackage;
|
||||
_.each(deps, function (d) {
|
||||
var p2 = d.packageConstraint.name;
|
||||
var p2 = d.packageConstraint.package;
|
||||
if (_.has(depsByPackage, p2)) {
|
||||
throw new Error("Can't have two dependencies on " + p2 +
|
||||
" in " + key);
|
||||
@@ -49,7 +49,7 @@ CS.CatalogCache.prototype.addPackageVersion = function (p, v, deps) {
|
||||
|
||||
// Returns the dependencies of a (package, version), stored in a map.
|
||||
// The values are Dependency objects; the key for `d` is
|
||||
// `d.packageConstraint.name`. (Don't mutate the map.)
|
||||
// `d.packageConstraint.package`. (Don't mutate the map.)
|
||||
CS.CatalogCache.prototype.getDependencyMap = function (p, v) {
|
||||
var key = pvkey(p, v);
|
||||
if (! _.has(this._dependencies, key)) {
|
||||
|
||||
@@ -32,7 +32,7 @@ CS.Input.prototype.loadFromCatalog = function (catalogLoader) {
|
||||
packagesToLoad[package] = true;
|
||||
});
|
||||
_.each(self.constraints, function (constraint) {
|
||||
packagesToLoad[constraint.name] = true;
|
||||
packagesToLoad[constraint.package] = true;
|
||||
});
|
||||
_.each(self.previousSolution, function (version, package) {
|
||||
packagesToLoad[package] = true;
|
||||
@@ -79,7 +79,7 @@ CS.Input.fromJSONable = function (obj) {
|
||||
return new CS.Input(
|
||||
obj.dependencies,
|
||||
_.map(obj.constraints, function (cstr) {
|
||||
return PV.parseConstraint(cstr);
|
||||
return PV.parsePackageConstraint(cstr);
|
||||
}),
|
||||
CS.CatalogCache.fromJSONable(obj.catalogCache),
|
||||
{
|
||||
@@ -109,8 +109,8 @@ var VersionConstraintType = Match.OneOf(
|
||||
var PackageConstraintType = Match.OneOf(
|
||||
PV.PackageConstraint,
|
||||
Match.Where(function (c) {
|
||||
check(c.name, String);
|
||||
check(c.package, String);
|
||||
check(c.constraintString, String);
|
||||
check(c.vConstraint, VersionConstraintType);
|
||||
check(c.versionConstraint, VersionConstraintType);
|
||||
return c.constructor !== Object;
|
||||
}));
|
||||
|
||||
@@ -70,7 +70,7 @@ splitArgs = function (deps) {
|
||||
dependencies.push(dep);
|
||||
}
|
||||
if (constr) {
|
||||
constraints.push(PV.parseConstraint(dep + "@" + constr));
|
||||
constraints.push(PV.parsePackageConstraint(dep + "@" + constr));
|
||||
}
|
||||
});
|
||||
return {dependencies: dependencies, constraints: constraints};
|
||||
@@ -298,7 +298,7 @@ Tinytest.add("constraint solver - no constraint dependency - anything", function
|
||||
Tinytest.add("constraint solver - no constraint dependency - transitive dep still picked right", function (test) {
|
||||
var versions = defaultResolver.resolve(
|
||||
["sparkle", "sparky-forms"],
|
||||
[PV.parseConstraint("sparky-forms@1.1.2")]).answer;
|
||||
[PV.parsePackageConstraint("sparky-forms@1.1.2")]).answer;
|
||||
test.equal(versions.sparkle, "2.1.1");
|
||||
});
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ CS.PackagesResolver._resolveWithInput = function (input, _nudge) {
|
||||
resolver.addUnitVersion(uv);
|
||||
_.each(cache.getDependencyMap(p, v), function (dep) {
|
||||
// `dep` is a CS.Dependency
|
||||
var p2 = dep.packageConstraint.name;
|
||||
var p2 = dep.packageConstraint.package;
|
||||
var constr = dep.packageConstraint.constraintString;
|
||||
if (! dep.isWeak) {
|
||||
uv.addDependency(p2);
|
||||
@@ -85,7 +85,7 @@ CS.PackagesResolver._resolveWithInput = function (input, _nudge) {
|
||||
});
|
||||
|
||||
var constraints = _.map(input.constraints, function (c) {
|
||||
return resolver.getConstraint(c.name, c.constraintString);
|
||||
return resolver.getConstraint(c.package, c.constraintString);
|
||||
});
|
||||
|
||||
var resolverOptions = {
|
||||
|
||||
@@ -3,7 +3,7 @@ var CS = ConstraintSolver;
|
||||
|
||||
Tinytest.add("constraint solver - datatypes - Dependency", function (test) {
|
||||
_.each(["foo", "foo@1.0.0"], function (foo) {
|
||||
var d1 = new CS.Dependency(PV.parseConstraint(foo));
|
||||
var d1 = new CS.Dependency(PV.parsePackageConstraint(foo));
|
||||
test.equal(d1.packageConstraint.toString(), foo);
|
||||
test.equal(d1.isWeak, false);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ CS.PackageAndVersion.fromString = function (str) {
|
||||
CS.Dependency = function (packageConstraint, flags) {
|
||||
check(packageConstraint, Match.OneOf(PV.PackageConstraint, String));
|
||||
if (typeof packageConstraint === 'string') {
|
||||
packageConstraint = PV.parseConstraint(packageConstraint);
|
||||
packageConstraint = PV.parsePackageConstraint(packageConstraint);
|
||||
}
|
||||
if (flags) {
|
||||
check(flags, Object);
|
||||
|
||||
@@ -295,14 +295,14 @@ _.extend(ConstraintSolver.UnitVersion.prototype, {
|
||||
ConstraintSolver.Constraint = function (name, constraintString) {
|
||||
var self = this;
|
||||
|
||||
var parsed = PackageVersion.parseConstraint(name, constraintString);
|
||||
var parsed = PackageVersion.parsePackageConstraint(name, constraintString);
|
||||
|
||||
self.name = parsed.name;
|
||||
self.name = parsed.package;
|
||||
self.constraintString = parsed.constraintString;
|
||||
// The results of parsing are `||`-separated alternatives, simple
|
||||
// constraints like `1.0.0` or `=1.0.1` which have been parsed into
|
||||
// objects with a `type` and `versionString` property.
|
||||
self.alternatives = parsed.vConstraint.alternatives;
|
||||
self.alternatives = parsed.versionConstraint.alternatives;
|
||||
};
|
||||
|
||||
ConstraintSolver.Constraint.prototype.toString = function (options) {
|
||||
|
||||
@@ -92,27 +92,27 @@ Tinytest.add("package-version-parser - parse", function (test) {
|
||||
throws("v1.0.0", /must look like semver/);
|
||||
});
|
||||
|
||||
Tinytest.add("package-version-parser - constraints - parseConstraint", function (test) {
|
||||
test.isTrue(PackageVersion.parseConstraint("foo") instanceof
|
||||
Tinytest.add("package-version-parser - constraints - parsePackageConstraint", function (test) {
|
||||
test.isTrue(PackageVersion.parsePackageConstraint("foo") instanceof
|
||||
PackageVersion.PackageConstraint);
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo@1.2.3"),
|
||||
{ name: "foo", constraintString: "1.2.3",
|
||||
vConstraint: {
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo@1.2.3"),
|
||||
{ package: "foo", constraintString: "1.2.3",
|
||||
versionConstraint: {
|
||||
raw: "1.2.3",
|
||||
alternatives: [{type: "compatible-with",
|
||||
versionString: "1.2.3"}] } });
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo"),
|
||||
{ name: "foo", constraintString: "",
|
||||
vConstraint: {
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo"),
|
||||
{ package: "foo", constraintString: "",
|
||||
versionConstraint: {
|
||||
raw: "",
|
||||
alternatives: [{type: "any-reasonable",
|
||||
versionString: null}] } });
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo@1.0.0 || =2.0.0"),
|
||||
{ name: "foo", constraintString: "1.0.0 || =2.0.0",
|
||||
vConstraint: {
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo@1.0.0 || =2.0.0"),
|
||||
{ package: "foo", constraintString: "1.0.0 || =2.0.0",
|
||||
versionConstraint: {
|
||||
raw: "1.0.0 || =2.0.0",
|
||||
alternatives: [{type: "compatible-with",
|
||||
versionString: "1.0.0"},
|
||||
@@ -120,57 +120,57 @@ Tinytest.add("package-version-parser - constraints - parseConstraint", function
|
||||
versionString: "2.0.0"}] } });
|
||||
|
||||
test.equal(new PackageVersion.PackageConstraint("foo@1.0.0 || =2.0.0"),
|
||||
PackageVersion.parseConstraint("foo@1.0.0 || =2.0.0"));
|
||||
PackageVersion.parsePackageConstraint("foo@1.0.0 || =2.0.0"));
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo", null),
|
||||
PackageVersion.parseConstraint("foo"));
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo", null),
|
||||
PackageVersion.parsePackageConstraint("foo"));
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo", ""),
|
||||
PackageVersion.parseConstraint("foo"));
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo", ""),
|
||||
PackageVersion.parsePackageConstraint("foo"));
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo", "1.0.0"),
|
||||
PackageVersion.parseConstraint("foo@1.0.0"));
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo", "1.0.0"),
|
||||
PackageVersion.parsePackageConstraint("foo@1.0.0"));
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo", "=1.0.0"),
|
||||
PackageVersion.parseConstraint("foo@=1.0.0"));
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo", "=1.0.0"),
|
||||
PackageVersion.parsePackageConstraint("foo@=1.0.0"));
|
||||
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("", "1.0.0");
|
||||
PackageVersion.parsePackageConstraint("", "1.0.0");
|
||||
});
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("foo@1.0.0", "1.0.0");
|
||||
PackageVersion.parsePackageConstraint("foo@1.0.0", "1.0.0");
|
||||
});
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("foo@", "1.0.0");
|
||||
PackageVersion.parsePackageConstraint("foo@", "1.0.0");
|
||||
});
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("foo@");
|
||||
PackageVersion.parsePackageConstraint("foo@");
|
||||
}, /leave off the @/);
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("foo@", "");
|
||||
PackageVersion.parsePackageConstraint("foo@", "");
|
||||
});
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("a@b@c");
|
||||
PackageVersion.parsePackageConstraint("a@b@c");
|
||||
});
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("foo@||");
|
||||
PackageVersion.parsePackageConstraint("foo@||");
|
||||
}, /Invalid constraint string: \|\|/);
|
||||
test.throws(function () {
|
||||
PackageVersion.parseConstraint("foo@=||=");
|
||||
PackageVersion.parsePackageConstraint("foo@=||=");
|
||||
}, /Empty string is not a valid version/);
|
||||
|
||||
test.equal(new PackageVersion.PackageConstraint(
|
||||
"foo", new PackageVersion.VersionConstraint(null)),
|
||||
{ name: "foo", constraintString: "",
|
||||
vConstraint: {
|
||||
{ package: "foo", constraintString: "",
|
||||
versionConstraint: {
|
||||
raw: "",
|
||||
alternatives: [{type: "any-reasonable",
|
||||
versionString: null}] } });
|
||||
|
||||
test.equal(PackageVersion.parseConstraint(
|
||||
test.equal(PackageVersion.parsePackageConstraint(
|
||||
"foo", PackageVersion.parseVersionConstraint("1.0.0 || =2.0.0")),
|
||||
{ name: "foo", constraintString: "1.0.0 || =2.0.0",
|
||||
vConstraint: {
|
||||
{ package: "foo", constraintString: "1.0.0 || =2.0.0",
|
||||
versionConstraint: {
|
||||
raw: "1.0.0 || =2.0.0",
|
||||
alternatives: [{type: "compatible-with",
|
||||
versionString: "1.0.0"},
|
||||
@@ -184,14 +184,14 @@ Tinytest.add("package-version-parser - constraints - parseConstraint", function
|
||||
{raw: "", alternatives: [{type: "any-reasonable",
|
||||
versionString: null}]});
|
||||
|
||||
test.equal(PackageVersion.parseConstraint("foo").toString(),
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo").toString(),
|
||||
"foo");
|
||||
test.equal(PackageVersion.parseConstraint("foo", null).toString(),
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo", null).toString(),
|
||||
"foo");
|
||||
test.equal(PackageVersion.parseConstraint("foo@1.0.0").toString(),
|
||||
test.equal(PackageVersion.parsePackageConstraint("foo@1.0.0").toString(),
|
||||
"foo@1.0.0");
|
||||
test.equal(PackageVersion.parseConstraint("foo@=1.0.0 || 2.0.0").toString(),
|
||||
"foo@=1.0.0 || 2.0.0");
|
||||
test.equal(PackageVersion.parsePackageConstraint(
|
||||
"foo@=1.0.0 || 2.0.0").toString(), "foo@=1.0.0 || 2.0.0");
|
||||
});
|
||||
|
||||
var t = function (pConstraintString, expected, descr) {
|
||||
@@ -201,11 +201,11 @@ var t = function (pConstraintString, expected, descr) {
|
||||
alternatives: expected.alternatives
|
||||
};
|
||||
currentTest.equal(
|
||||
PackageVersion.parseConstraint(pConstraintString),
|
||||
PackageVersion.parsePackageConstraint(pConstraintString),
|
||||
{
|
||||
name: expected.name,
|
||||
package: expected.package,
|
||||
constraintString: constraintString,
|
||||
vConstraint: {
|
||||
versionConstraint: {
|
||||
raw: constraintString,
|
||||
alternatives: expected.alternatives
|
||||
}
|
||||
@@ -215,16 +215,16 @@ var t = function (pConstraintString, expected, descr) {
|
||||
|
||||
var FAIL = function (versionString, errorExpect) {
|
||||
currentTest.throws(function () {
|
||||
PackageVersion.parseConstraint(versionString);
|
||||
PackageVersion.parsePackageConstraint(versionString);
|
||||
}, errorExpect);
|
||||
};
|
||||
|
||||
Tinytest.add("package-version-parser - constraints - any-reasonable", function (test) {
|
||||
currentTest = test;
|
||||
|
||||
t("foo", { name: "foo", alternatives: [{
|
||||
t("foo", { package: "foo", alternatives: [{
|
||||
versionString: null, type: "any-reasonable" } ]});
|
||||
t("foo-1234", { name: "foo-1234", alternatives: [{
|
||||
t("foo-1234", { package: "foo-1234", alternatives: [{
|
||||
versionString: null, type: "any-reasonable" } ]});
|
||||
FAIL("bad_name");
|
||||
});
|
||||
@@ -232,11 +232,11 @@ Tinytest.add("package-version-parser - constraints - any-reasonable", function (
|
||||
Tinytest.add("package-version-parser - constraints - compatible version, compatible-with", function (test) {
|
||||
currentTest = test;
|
||||
|
||||
t("foo@1.2.3", { name: "foo", alternatives: [{
|
||||
t("foo@1.2.3", { package: "foo", alternatives: [{
|
||||
versionString: "1.2.3", type: "compatible-with" } ]});
|
||||
t("foo-1233@1.2.3", { name: "foo-1233", alternatives: [{
|
||||
t("foo-1233@1.2.3", { package: "foo-1233", alternatives: [{
|
||||
versionString: "1.2.3", type: "compatible-with" } ]});
|
||||
t("foo-bar@3.2.1", { name: "foo-bar", alternatives: [{
|
||||
t("foo-bar@3.2.1", { package: "foo-bar", alternatives: [{
|
||||
versionString: "3.2.1", type: "compatible-with" } ]});
|
||||
FAIL("42@0.2.0");
|
||||
FAIL("foo@1.2.3.4");
|
||||
@@ -255,26 +255,26 @@ Tinytest.add("package-version-parser - constraints - compatible version, compati
|
||||
FAIL("foo-1233@1.2.3_", /wrap number must follow/);
|
||||
FAIL("foo-1233@1.2.3_0123");
|
||||
|
||||
t("foo@1.2.3_1", { name: "foo", alternatives: [{
|
||||
t("foo@1.2.3_1", { package: "foo", alternatives: [{
|
||||
versionString: "1.2.3_1", type: "compatible-with" } ]});
|
||||
t("foo-bar@3.2.1-rc0_123", { name: "foo-bar", alternatives: [{
|
||||
t("foo-bar@3.2.1-rc0_123", { package: "foo-bar", alternatives: [{
|
||||
versionString: "3.2.1-rc0_123", type: "compatible-with" } ]});
|
||||
t("foo-1233@1.2.3_5+1234", { name: "foo-1233", alternatives: [{
|
||||
t("foo-1233@1.2.3_5+1234", { package: "foo-1233", alternatives: [{
|
||||
versionString: "1.2.3_5+1234", type: "compatible-with" } ]});
|
||||
t("foo", { name: "foo", alternatives: [{
|
||||
t("foo", { package: "foo", alternatives: [{
|
||||
versionString: null, type: "any-reasonable" } ]});
|
||||
});
|
||||
|
||||
Tinytest.add("package-version-parser - constraints - compatible version, exactly", function (test) {
|
||||
currentTest = test;
|
||||
|
||||
t("foo@=1.2.3", { name: "foo", alternatives: [
|
||||
t("foo@=1.2.3", { package: "foo", alternatives: [
|
||||
{ versionString: "1.2.3", type: "exactly" } ]});
|
||||
t("foo-bar@=3.2.1", { name: "foo-bar", alternatives: [{
|
||||
t("foo-bar@=3.2.1", { package: "foo-bar", alternatives: [{
|
||||
versionString: "3.2.1", type: "exactly" } ]});
|
||||
t("foo@=1.2.3_1", { name: "foo", alternatives: [{
|
||||
t("foo@=1.2.3_1", { package: "foo", alternatives: [{
|
||||
versionString: "1.2.3_1", type: "exactly" } ]});
|
||||
t("foo-bar@=3.2.1_34", { name: "foo-bar", alternatives: [{
|
||||
t("foo-bar@=3.2.1_34", { package: "foo-bar", alternatives: [{
|
||||
versionString: "3.2.1_34", type: "exactly" } ]});
|
||||
|
||||
FAIL("42@=0.2.0");
|
||||
@@ -307,31 +307,31 @@ Tinytest.add("package-version-parser - constraints - or", function (test) {
|
||||
currentTest = test;
|
||||
|
||||
t("foo@1.0.0 || 2.0.0 || 3.0.0 || =4.0.0-rc1",
|
||||
{ name: "foo", alternatives:
|
||||
{ package: "foo", alternatives:
|
||||
[{ versionString: "1.0.0", type: "compatible-with"},
|
||||
{ versionString: "2.0.0", type: "compatible-with"},
|
||||
{ versionString: "3.0.0", type: "compatible-with"},
|
||||
{ versionString: "4.0.0-rc1", type: "exactly"}]
|
||||
});
|
||||
t("foo@1.0.0|| 2.0.0||3.0.0 || =4.0.0-rc1",
|
||||
{ name: "foo", alternatives:
|
||||
{ package: "foo", alternatives:
|
||||
[{ versionString: "1.0.0", type: "compatible-with"},
|
||||
{ versionString: "2.0.0", type: "compatible-with"},
|
||||
{ versionString: "3.0.0", type: "compatible-with"},
|
||||
{ versionString: "4.0.0-rc1", type: "exactly"}]
|
||||
});
|
||||
t("foo-bar@=3.2.1 || 1.0.0",
|
||||
{ name: "foo-bar", alternatives:
|
||||
{ package: "foo-bar", alternatives:
|
||||
[{ versionString: "3.2.1", type: "exactly"},
|
||||
{ versionString: "1.0.0", type: "compatible-with"}]
|
||||
});
|
||||
t("foo@=1.2.3_1 || 1.2.4",
|
||||
{ name: "foo", alternatives:
|
||||
{ package: "foo", alternatives:
|
||||
[{ versionString: "1.2.3_1", type: "exactly"},
|
||||
{ versionString: "1.2.4", type: "compatible-with"}]
|
||||
});
|
||||
t("foo-bar@=3.2.1_34 || =3.2.1-rc1",
|
||||
{ name: "foo-bar", alternatives:
|
||||
{ package: "foo-bar", alternatives:
|
||||
[{ versionString: "3.2.1_34", type: "exactly"},
|
||||
{ versionString: "3.2.1-rc1", type: "exactly"}]
|
||||
});
|
||||
|
||||
@@ -129,7 +129,7 @@ main.registerCommand({
|
||||
var addPackages = function (packageNames) {
|
||||
projectContext.projectConstraintsFile.addConstraints(
|
||||
_.map(packageNames, function (p) {
|
||||
return utils.parseConstraint(p);
|
||||
return utils.parsePackageConstraint(p);
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -395,7 +395,7 @@ main.registerCommand({
|
||||
if (projectContext.projectConstraintsFile.getConstraint(name))
|
||||
return;
|
||||
projectContext.projectConstraintsFile.addConstraints(
|
||||
[utils.parseConstraint(name)]);
|
||||
[utils.parsePackageConstraint(name)]);
|
||||
});
|
||||
|
||||
// Now resolve constraints and build packages.
|
||||
@@ -626,7 +626,7 @@ main.registerCommand({
|
||||
projectContext.initializeCatalog();
|
||||
});
|
||||
projectContext.projectConstraintsFile.addConstraints(
|
||||
[utils.parseConstraint(name + "@=" + versionString)]);
|
||||
[utils.parsePackageConstraint(name + "@=" + versionString)]);
|
||||
main.captureAndExit("=> Errors while initializing project:", function () {
|
||||
projectContext.prepareProjectForBuild();
|
||||
});
|
||||
@@ -833,7 +833,7 @@ main.registerCommand({
|
||||
var allPackages = projectContext.localCatalog.getAllNonTestPackageNames();
|
||||
projectContext.projectConstraintsFile.addConstraints(
|
||||
_.map(allPackagesWithTests, function (p) {
|
||||
return utils.parseConstraint(p);
|
||||
return utils.parsePackageConstraint(p);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -1095,7 +1095,7 @@ main.registerCommand({
|
||||
// Iterate over packages that are used directly by this app (not indirect
|
||||
// dependencies).
|
||||
projectContext.projectConstraintsFile.eachConstraint(function (constraint) {
|
||||
var packageName = constraint.name;
|
||||
var packageName = constraint.package;
|
||||
var mapInfo = projectContext.packageMap.getInfo(packageName);
|
||||
if (! mapInfo)
|
||||
throw Error("no version for used package " + packageName);
|
||||
@@ -1526,7 +1526,7 @@ main.registerCommand({
|
||||
var upgradePackageNames = [];
|
||||
if (options.args.length === 0) {
|
||||
projectContext.projectConstraintsFile.eachConstraint(function (constraint) {
|
||||
upgradePackageNames.push(constraint.name);
|
||||
upgradePackageNames.push(constraint.package);
|
||||
});
|
||||
} else {
|
||||
upgradePackageNames = options.args;
|
||||
@@ -1674,7 +1674,7 @@ main.registerCommand({
|
||||
var messages = buildmessage.capture(function () {
|
||||
_.each(args, function (packageReq) {
|
||||
buildmessage.enterJob("adding package " + packageReq, function () {
|
||||
var constraint = utils.parseConstraint(packageReq, {
|
||||
var constraint = utils.parsePackageConstraint(packageReq, {
|
||||
useBuildmessage: true
|
||||
});
|
||||
if (buildmessage.jobHasMessages())
|
||||
@@ -1683,37 +1683,37 @@ main.registerCommand({
|
||||
// It's OK to make errors based on looking at the catalog, because this
|
||||
// is a OnceAtStart command.
|
||||
var packageRecord = projectContext.projectCatalog.getPackage(
|
||||
constraint.name);
|
||||
constraint.package);
|
||||
if (! packageRecord) {
|
||||
buildmessage.error("no such package");
|
||||
return;
|
||||
}
|
||||
|
||||
_.each(constraint.vConstraint.alternatives, function (subConstraint) {
|
||||
if (subConstraint.versionString === null)
|
||||
_.each(constraint.versionConstraint.alternatives, function (subConstr) {
|
||||
if (subConstr.versionString === null)
|
||||
return;
|
||||
// Figure out if this version exists either in the official catalog or
|
||||
// the local catalog. (This isn't the same as using the combined
|
||||
// catalog, since it's OK to type "meteor add foo@1.0.0" if the local
|
||||
// package is 1.1.0 as long as 1.0.0 exists.)
|
||||
var versionRecord = projectContext.localCatalog.getVersion(
|
||||
constraint.name, subConstraint.versionString);
|
||||
constraint.package, subConstr.versionString);
|
||||
if (! versionRecord) {
|
||||
// XXX #2846 here's an example of something that might require a
|
||||
// refresh
|
||||
versionRecord = catalog.official.getVersion(
|
||||
constraint.name, subConstraint.versionString);
|
||||
constraint.package, subConstr.versionString);
|
||||
}
|
||||
if (! versionRecord) {
|
||||
buildmessage.error("no such version " + constraint.name + "@" +
|
||||
subConstraint.versionString);
|
||||
buildmessage.error("no such version " + constraint.package + "@" +
|
||||
subConstr.versionString);
|
||||
}
|
||||
});
|
||||
if (buildmessage.jobHasMessages())
|
||||
return;
|
||||
|
||||
var current = projectContext.projectConstraintsFile.getConstraint(
|
||||
constraint.name);
|
||||
constraint.package);
|
||||
|
||||
// Check that the constraint is new. If we are already using the package
|
||||
// at the same constraint in the app, we will log an info message later
|
||||
@@ -1724,21 +1724,21 @@ main.registerCommand({
|
||||
} else if (! current.constraintString &&
|
||||
! constraint.constraintString) {
|
||||
infoMessages.push(
|
||||
constraint.name +
|
||||
constraint.package +
|
||||
" without a version constraint has already been added.");
|
||||
} else if (current.constraintString === constraint.constraintString) {
|
||||
infoMessages.push(
|
||||
constraint.name + " with version constraint " +
|
||||
constraint.package + " with version constraint " +
|
||||
constraint.constraintString + " has already been added.");
|
||||
} else {
|
||||
// We are changing an existing constraint.
|
||||
if (current.constraintString) {
|
||||
infoMessages.push(
|
||||
"Currently using " + constraint.name +
|
||||
"Currently using " + constraint.package +
|
||||
" with version constraint " + current.constraintString + ".");
|
||||
} else {
|
||||
infoMessages.push(
|
||||
"Currently using " + constraint.name +
|
||||
"Currently using " + constraint.package +
|
||||
" without any version constraint.");
|
||||
}
|
||||
if (constraint.constraintString) {
|
||||
@@ -1780,11 +1780,11 @@ main.registerCommand({
|
||||
// Show descriptions of directly added packages.
|
||||
Console.info();
|
||||
_.each(constraintsToAdd, function (constraint) {
|
||||
var version = projectContext.packageMap.getInfo(constraint.name).version;
|
||||
var version = projectContext.packageMap.getInfo(constraint.package).version;
|
||||
var versionRecord = projectContext.projectCatalog.getVersion(
|
||||
constraint.name, version);
|
||||
constraint.package, version);
|
||||
Console.info(
|
||||
constraint.name +
|
||||
constraint.package +
|
||||
(versionRecord.description ? (": " + versionRecord.description) : ""));
|
||||
});
|
||||
|
||||
|
||||
@@ -1294,7 +1294,7 @@ main.registerCommand({
|
||||
// Use the driver package and meteor-platform as well.
|
||||
packagesToAdd.unshift('meteor-platform', options['driver-package']);
|
||||
var constraintsToAdd = _.map(packagesToAdd, function (p) {
|
||||
return utils.parseConstraint(p);
|
||||
return utils.parsePackageConstraint(p);
|
||||
});
|
||||
// Add the packages to our in-memory representation of .meteor/packages. (We
|
||||
// haven't yet resolved constraints, so this will affect constraint
|
||||
|
||||
@@ -94,8 +94,8 @@ var mapWhereToArch = function (where) {
|
||||
|
||||
var splitConstraint = function (c) {
|
||||
// XXX print error better (w/ buildmessage?)?
|
||||
var parsed = utils.parseConstraint(c);
|
||||
return { package: parsed.name,
|
||||
var parsed = utils.parsePackageConstraint(c);
|
||||
return { package: parsed.package,
|
||||
constraint: parsed.constraintString || null };
|
||||
};
|
||||
|
||||
@@ -1126,7 +1126,7 @@ _.extend(PackageSource.prototype, {
|
||||
for (var i = 0; i < names.length; ++i) {
|
||||
var name = names[i];
|
||||
try {
|
||||
var parsed = utils.parseConstraint(name);
|
||||
var parsed = utils.parsePackageConstraint(name);
|
||||
} catch (e) {
|
||||
if (!e.versionParserError)
|
||||
throw e;
|
||||
@@ -1137,7 +1137,7 @@ _.extend(PackageSource.prototype, {
|
||||
|
||||
forAllMatchingArchs(arch, function (a) {
|
||||
uses[a].push({
|
||||
package: parsed.name,
|
||||
package: parsed.package,
|
||||
constraint: parsed.constraintString,
|
||||
unordered: options.unordered || false,
|
||||
weak: options.weak || false
|
||||
@@ -1176,7 +1176,7 @@ _.extend(PackageSource.prototype, {
|
||||
for (var i = 0; i < names.length; ++i) {
|
||||
var name = names[i];
|
||||
try {
|
||||
var parsed = utils.parseConstraint(name);
|
||||
var parsed = utils.parsePackageConstraint(name);
|
||||
} catch (e) {
|
||||
if (!e.versionParserError)
|
||||
throw e;
|
||||
@@ -1189,7 +1189,7 @@ _.extend(PackageSource.prototype, {
|
||||
// We don't allow weak or unordered implies, since the main
|
||||
// purpose of imply is to provide imports and plugins.
|
||||
implies[a].push({
|
||||
package: parsed.name,
|
||||
package: parsed.package,
|
||||
constraint: parsed.constraintString
|
||||
});
|
||||
});
|
||||
@@ -1499,7 +1499,7 @@ _.extend(PackageSource.prototype, {
|
||||
// because there's no way to specify otherwise in .meteor/packages.
|
||||
var uses = [];
|
||||
projectContext.projectConstraintsFile.eachConstraint(function (constraint) {
|
||||
uses.push({ package: constraint.name,
|
||||
uses.push({ package: constraint.package,
|
||||
constraint: constraint.constraintString });
|
||||
});
|
||||
|
||||
|
||||
@@ -289,8 +289,8 @@ PV.parseVersionConstraint = function (constraintString) {
|
||||
};
|
||||
|
||||
// A PackageConstraint consists of a package name and a version constraint.
|
||||
// Call either with args (name, vConstraintString) or (pConstraintString),
|
||||
// or (name, vConstraint).
|
||||
// Call either with args (package, versionConstraintString) or
|
||||
// (packageConstraintString), or (package, versionConstraint).
|
||||
// That is, ("foo", "1.2.3") or ("foo@1.2.3"), or ("foo", vc) where vc
|
||||
// is instanceof PV.VersionConstraint.
|
||||
PV.PackageConstraint = function (part1, part2) {
|
||||
@@ -300,11 +300,11 @@ PV.PackageConstraint = function (part1, part2) {
|
||||
throw new Error("constraintString must be a string");
|
||||
}
|
||||
|
||||
var name, vConstraint, vConstraintString;
|
||||
var packageName, versionConstraint, vConstraintString;
|
||||
if (part2) {
|
||||
name = part1;
|
||||
packageName = part1;
|
||||
if (part2 instanceof PV.VersionConstraint) {
|
||||
vConstraint = part2;
|
||||
versionConstraint = part2;
|
||||
} else {
|
||||
vConstraintString = part2;
|
||||
}
|
||||
@@ -312,33 +312,33 @@ PV.PackageConstraint = function (part1, part2) {
|
||||
// Shave off last part after @, with "a@b@c" becoming ["a@b", "c"].
|
||||
// Validating the package name will catch extra @.
|
||||
var parts = part1.match(/^(.*)@([^@]*)$/).slice(1);
|
||||
name = parts[0];
|
||||
packageName = parts[0];
|
||||
vConstraintString = parts[1];
|
||||
if (! vConstraintString) {
|
||||
throwVersionParserError(
|
||||
"Version constraint for package '" + name +
|
||||
"Version constraint for package '" + packageName +
|
||||
"' cannot be empty; leave off the @ if you don't want to constrain " +
|
||||
"the version.");
|
||||
}
|
||||
} else {
|
||||
name = part1;
|
||||
packageName = part1;
|
||||
vConstraintString = "";
|
||||
}
|
||||
|
||||
PV.validatePackageName(name);
|
||||
if (vConstraint) {
|
||||
vConstraintString = vConstraint.raw;
|
||||
PV.validatePackageName(packageName);
|
||||
if (versionConstraint) {
|
||||
vConstraintString = versionConstraint.raw;
|
||||
} else {
|
||||
vConstraint = PV.parseVersionConstraint(vConstraintString);
|
||||
versionConstraint = PV.parseVersionConstraint(vConstraintString);
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
this.package = packageName;
|
||||
this.constraintString = vConstraintString;
|
||||
this.vConstraint = vConstraint;
|
||||
this.versionConstraint = versionConstraint;
|
||||
};
|
||||
|
||||
PV.PackageConstraint.prototype.toString = function () {
|
||||
var ret = this.name;
|
||||
var ret = this.package;
|
||||
if (this.constraintString) {
|
||||
ret += "@" + this.constraintString;
|
||||
}
|
||||
@@ -347,16 +347,14 @@ PV.PackageConstraint.prototype.toString = function () {
|
||||
|
||||
// Structure of a parsed constraint:
|
||||
//
|
||||
// { name: String,
|
||||
// /*PV.PackageConstraint*/
|
||||
// { package: String,
|
||||
// constraintString: String,
|
||||
// vConstraint: {
|
||||
// versionConstraint: /*PV.VersionConstraint*/ {
|
||||
// raw: String,
|
||||
// alternatives: [{versionString: String|null,
|
||||
// type: String}]}}
|
||||
//
|
||||
// The returned object is instanceof PackageConstraint, and
|
||||
// vConstraint is instanceof VersionConstraint.
|
||||
PV.parseConstraint = function (part1, part2) {
|
||||
PV.parsePackageConstraint = function (part1, part2) {
|
||||
return new PV.PackageConstraint(part1, part2);
|
||||
};
|
||||
|
||||
|
||||
@@ -507,7 +507,7 @@ _.extend(ProjectContext.prototype, {
|
||||
self.projectConstraintsFile.eachConstraint(function (constraint) {
|
||||
// Add a dependency ("this package must be used") and a constraint
|
||||
// ("... at this version (maybe 'any reasonable')").
|
||||
depsAndConstraints.deps.push(constraint.name);
|
||||
depsAndConstraints.deps.push(constraint.package);
|
||||
depsAndConstraints.constraints.push(constraint);
|
||||
});
|
||||
},
|
||||
@@ -516,8 +516,8 @@ _.extend(ProjectContext.prototype, {
|
||||
var self = this;
|
||||
_.each(self.localCatalog.getAllPackageNames(), function (packageName) {
|
||||
var versionRecord = self.localCatalog.getLatestVersion(packageName);
|
||||
var constraint =
|
||||
utils.parseConstraint(packageName + "@=" + versionRecord.version);
|
||||
var constraint = utils.parsePackageConstraint(
|
||||
packageName + "@=" + versionRecord.version);
|
||||
// Add a constraint ("this is the only version available") but no
|
||||
// dependency (we don't automatically use all local packages!)
|
||||
depsAndConstraints.constraints.push(constraint);
|
||||
@@ -529,7 +529,8 @@ _.extend(ProjectContext.prototype, {
|
||||
if (! self._releaseForConstraints)
|
||||
return;
|
||||
_.each(self._releaseForConstraints.packages, function (version, packageName) {
|
||||
var constraint = utils.parseConstraint(packageName + "@=" + version);
|
||||
var constraint = utils.parsePackageConstraint(
|
||||
packageName + "@=" + version);
|
||||
// Add a constraint ("this is the only version available") but no
|
||||
// dependency (we don't automatically use all local packages!)
|
||||
depsAndConstraints.constraints.push(constraint);
|
||||
@@ -553,9 +554,9 @@ _.extend(ProjectContext.prototype, {
|
||||
// Pre-release versions that are root constraints (in .meteor/packages, in
|
||||
// the release, or the version of a local package) are anticipated.
|
||||
_.each(rootConstraints, function (constraintObject) {
|
||||
_.each(constraintObject.vConstraint.alternatives, function (alternative) {
|
||||
var version = alternative.versionString;
|
||||
version && add(constraintObject.name, version);
|
||||
_.each(constraintObject.versionConstraint.alternatives, function (alt) {
|
||||
var version = alt.versionString;
|
||||
version && add(constraintObject.package, version);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -659,7 +660,7 @@ exports.ProjectConstraintsFile = function (options) {
|
||||
self._modified = null;
|
||||
// List of each line in the file; object with keys:
|
||||
// - leadingSpace (string of spaces before the constraint)
|
||||
// - constraint (as returned by utils.parseConstraint)
|
||||
// - constraint (as returned by utils.parsePackageConstraint)
|
||||
// - trailingSpaceAndComment (string of spaces/comments after the constraint)
|
||||
// This allows us to rewrite the file preserving comments.
|
||||
self._constraintLines = null;
|
||||
@@ -713,22 +714,22 @@ _.extend(exports.ProjectConstraintsFile.prototype, {
|
||||
// No constraint? Leave lineRecord.constraint null and continue.
|
||||
if (line === '')
|
||||
return;
|
||||
lineRecord.constraint = utils.parseConstraint(line, {
|
||||
lineRecord.constraint = utils.parsePackageConstraint(line, {
|
||||
useBuildmessage: true,
|
||||
buildmessageFile: self.filename
|
||||
});
|
||||
if (! lineRecord.constraint)
|
||||
return; // recover by ignoring
|
||||
|
||||
if (_.has(self._constraintMap, lineRecord.constraint.name)) {
|
||||
if (_.has(self._constraintMap, lineRecord.constraint.package)) {
|
||||
buildmessage.error(
|
||||
"Package name appears twice: " + lineRecord.constraint.name, {
|
||||
"Package name appears twice: " + lineRecord.constraint.package, {
|
||||
// XXX should this be relative?
|
||||
file: self.filename
|
||||
});
|
||||
return; // recover by ignoring
|
||||
}
|
||||
self._constraintMap[lineRecord.constraint.name] = lineRecord;
|
||||
self._constraintMap[lineRecord.constraint.package] = lineRecord;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -742,7 +743,7 @@ _.extend(exports.ProjectConstraintsFile.prototype, {
|
||||
var lines = _.map(self._constraintLines, function (lineRecord) {
|
||||
var lineParts = [lineRecord.leadingSpace];
|
||||
if (lineRecord.constraint) {
|
||||
lineParts.push(lineRecord.constraint.name);
|
||||
lineParts.push(lineRecord.constraint.package);
|
||||
if (lineRecord.constraint.constraintString) {
|
||||
lineParts.push('@', lineRecord.constraint.constraintString);
|
||||
}
|
||||
@@ -762,7 +763,7 @@ _.extend(exports.ProjectConstraintsFile.prototype, {
|
||||
},
|
||||
|
||||
// Iterates over all constraints, in the format returned by
|
||||
// utils.parseConstraint.
|
||||
// utils.parsePackageConstraint.
|
||||
eachConstraint: function (iterator) {
|
||||
var self = this;
|
||||
_.each(self._constraintLines, function (lineRecord) {
|
||||
@@ -771,8 +772,8 @@ _.extend(exports.ProjectConstraintsFile.prototype, {
|
||||
});
|
||||
},
|
||||
|
||||
// Returns the constraint in the format returned by utils.parseConstraint, or
|
||||
// null.
|
||||
// Returns the constraint in the format returned by
|
||||
// utils.parsePackageConstraint, or null.
|
||||
getConstraint: function (name) {
|
||||
var self = this;
|
||||
if (_.has(self._constraintMap, name))
|
||||
@@ -781,7 +782,7 @@ _.extend(exports.ProjectConstraintsFile.prototype, {
|
||||
},
|
||||
|
||||
// Adds constraints, an array of objects as returned from
|
||||
// utils.parseConstraint.
|
||||
// utils.parsePackageConstraint.
|
||||
// Does not write to disk immediately; changes are written to disk by
|
||||
// writeIfModified() which is called in the _saveChangedMetadata step
|
||||
// of project preparation.
|
||||
@@ -789,18 +790,18 @@ _.extend(exports.ProjectConstraintsFile.prototype, {
|
||||
var self = this;
|
||||
_.each(constraintsToAdd, function (constraintToAdd) {
|
||||
var lineRecord;
|
||||
if (! _.has(self._constraintMap, constraintToAdd.name)) {
|
||||
if (! _.has(self._constraintMap, constraintToAdd.package)) {
|
||||
lineRecord = {
|
||||
leadingSpace: '',
|
||||
constraint: constraintToAdd,
|
||||
trailingSpaceAndComment: ''
|
||||
};
|
||||
self._constraintLines.push(lineRecord);
|
||||
self._constraintMap[constraintToAdd.name] = lineRecord;
|
||||
self._constraintMap[constraintToAdd.package] = lineRecord;
|
||||
self._modified = true;
|
||||
return;
|
||||
}
|
||||
lineRecord = self._constraintMap[constraintToAdd.name];
|
||||
lineRecord = self._constraintMap[constraintToAdd.package];
|
||||
if (_.isEqual(constraintToAdd, lineRecord.constraint))
|
||||
return; // nothing changed
|
||||
lineRecord.constraint = constraintToAdd;
|
||||
@@ -819,7 +820,7 @@ _.extend(exports.ProjectConstraintsFile.prototype, {
|
||||
self._constraintLines = _.filter(
|
||||
self._constraintLines, function (lineRecord) {
|
||||
return ! (lineRecord.constraint &&
|
||||
_.contains(packagesToRemove, lineRecord.constraint.name));
|
||||
_.contains(packagesToRemove, lineRecord.constraint.package));
|
||||
});
|
||||
_.each(packagesToRemove, function (p) {
|
||||
delete self._constraintMap[p];
|
||||
@@ -1041,9 +1042,9 @@ _.extend(exports.CordovaPluginsFile.prototype, {
|
||||
if (line === '')
|
||||
return;
|
||||
|
||||
// We just do a standard split here, not utils.parseConstraint, since
|
||||
// cordova plugins don't necessary obey the same naming conventions as
|
||||
// Meteor packages.
|
||||
// We just do a standard split here, not utils.parsePackageConstraint,
|
||||
// since cordova plugins don't necessary obey the same naming conventions
|
||||
// as Meteor packages.
|
||||
var parts = line.split('@');
|
||||
if (parts.length !== 2) {
|
||||
buildmessage.error("Cordova plugin must specify version: " + line, {
|
||||
|
||||
@@ -9,10 +9,10 @@ var testVersions = function (cases) {
|
||||
|
||||
if (expectedOutput === null) {
|
||||
selftest.expectThrows(function () {
|
||||
utils.parseConstraint(input);
|
||||
utils.parsePackageConstraint(input);
|
||||
});
|
||||
} else {
|
||||
var actualOutput = utils.parseConstraint(input);
|
||||
var actualOutput = utils.parsePackageConstraint(input);
|
||||
selftest.expectEqual(actualOutput, expectedOutput);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -194,11 +194,11 @@ exports.randomPort = function () {
|
||||
return 20000 + Math.floor(Math.random() * 10000);
|
||||
};
|
||||
|
||||
// Like packageVersionParser.parseConstraint, but if called in a buildmessage
|
||||
// context uses buildmessage to raise errors.
|
||||
exports.parseConstraint = function (constraintString, options) {
|
||||
// Like packageVersionParser.parsePackageConstraint, but if called in a
|
||||
// buildmessage context uses buildmessage to raise errors.
|
||||
exports.parsePackageConstraint = function (constraintString, options) {
|
||||
try {
|
||||
return packageVersionParser.parseConstraint(constraintString);
|
||||
return packageVersionParser.parsePackageConstraint(constraintString);
|
||||
} catch (e) {
|
||||
if (! (e.versionParserError && options && options.useBuildmessage))
|
||||
throw e;
|
||||
@@ -223,16 +223,16 @@ exports.validatePackageName = function (name, options) {
|
||||
exports.parsePackageAtVersion = function (packageAtVersionString, options) {
|
||||
// A string that has to look like "package@version" isn't really a
|
||||
// constraint, it's just a string of the form (package + "@" + version).
|
||||
// However, using parseConstraint in the implementation is too convenient
|
||||
// to pass up (especially in terms of error-handling quality).
|
||||
var parsedConstraint = exports.parseConstraint(packageAtVersionString,
|
||||
options);
|
||||
// However, using parsePackageConstraint in the implementation is too
|
||||
// convenient to pass up (especially in terms of error-handling quality).
|
||||
var parsedConstraint = exports.parsePackageConstraint(packageAtVersionString,
|
||||
options);
|
||||
if (! parsedConstraint) {
|
||||
// It must be that options.useBuildmessage and an error has been
|
||||
// registered. Otherwise, parseConstraint would succeed or throw.
|
||||
// registered. Otherwise, parsePackageConstraint would succeed or throw.
|
||||
return null;
|
||||
}
|
||||
var alternatives = parsedConstraint.vConstraint.alternatives;
|
||||
var alternatives = parsedConstraint.versionConstraint.alternatives;
|
||||
if (! (alternatives.length === 1 &&
|
||||
alternatives[0].type === 'compatible-with')) {
|
||||
if (options && options.useBuildmessage) {
|
||||
@@ -243,7 +243,7 @@ exports.parsePackageAtVersion = function (packageAtVersionString, options) {
|
||||
throw new Error("Malformed package@version: " + packageAtVersionString);
|
||||
}
|
||||
}
|
||||
return { package: parsedConstraint.name,
|
||||
return { package: parsedConstraint.package,
|
||||
version: alternatives[0].versionString };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user