| Index: sdk/lib/_internal/pub_generated/lib/src/validator/dependency.dart
|
| diff --git a/sdk/lib/_internal/pub_generated/lib/src/validator/dependency.dart b/sdk/lib/_internal/pub_generated/lib/src/validator/dependency.dart
|
| index 419326091c9712eba1acf2a2d2b9e2f5b5b87ee4..68ea7e20b54e468d794c697edbf9c14b0b35684e 100644
|
| --- a/sdk/lib/_internal/pub_generated/lib/src/validator/dependency.dart
|
| +++ b/sdk/lib/_internal/pub_generated/lib/src/validator/dependency.dart
|
| @@ -11,33 +11,127 @@ import 'package:pub_semver/pub_semver.dart';
|
| import '../entrypoint.dart';
|
| import '../log.dart' as log;
|
| import '../package.dart';
|
| +import '../utils.dart';
|
| import '../validator.dart';
|
|
|
| +/// The range of all pub versions that don't support `^` version constraints.
|
| +final _preCaretPubVersions = new VersionConstraint.parse("<1.8.0-dev.2.0");
|
| +
|
| +// TODO(nweiz): replace this with "^1.8.0" for the 1.8 release.
|
| +/// The range of all pub versions that do support `^` version constraints.
|
| +///
|
| +/// This is intersected with the user's SDK constraint to provide a suggested
|
| +/// constraint.
|
| +final _postCaretPubVersions = new VersionConstraint.parse("^1.8.0-dev.2.0");
|
| +
|
| /// A validator that validates a package's dependencies.
|
| class DependencyValidator extends Validator {
|
| + /// Whether the SDK constraint guarantees that `^` version constraints are
|
| + /// safe.
|
| + bool get _caretSafe =>
|
| + entrypoint.root.pubspec.environment.sdkVersion.intersect(
|
| + _preCaretPubVersions).isEmpty;
|
| +
|
| DependencyValidator(Entrypoint entrypoint)
|
| : super(entrypoint);
|
|
|
| Future validate() {
|
| - return Future.forEach(entrypoint.root.pubspec.dependencies, (dependency) {
|
| - if (dependency.source != "hosted") {
|
| - return _warnAboutSource(dependency);
|
| + final completer0 = new Completer();
|
| + scheduleMicrotask(() {
|
| + try {
|
| + var caretDeps = [];
|
| + Future.forEach(entrypoint.root.pubspec.dependencies, ((dependency) {
|
| + final completer0 = new Completer();
|
| + scheduleMicrotask(() {
|
| + try {
|
| + join0() {
|
| + completer0.complete();
|
| + }
|
| + if (dependency.source != "hosted") {
|
| + _warnAboutSource(dependency).then((x0) {
|
| + try {
|
| + x0;
|
| + join0();
|
| + } catch (e0, s0) {
|
| + completer0.completeError(e0, s0);
|
| + }
|
| + }, onError: completer0.completeError);
|
| + } else {
|
| + join1() {
|
| + join0();
|
| + }
|
| + if (dependency.constraint.isAny) {
|
| + _warnAboutNoConstraint(dependency);
|
| + join1();
|
| + } else {
|
| + join2() {
|
| + join1();
|
| + }
|
| + if (dependency.constraint is Version) {
|
| + _warnAboutSingleVersionConstraint(dependency);
|
| + join2();
|
| + } else {
|
| + join3() {
|
| + join2();
|
| + }
|
| + if (dependency.constraint is VersionRange) {
|
| + join4() {
|
| + join5() {
|
| + join3();
|
| + }
|
| + if (dependency.constraint.toString().startsWith("^")) {
|
| + caretDeps.add(dependency);
|
| + join5();
|
| + } else {
|
| + join5();
|
| + }
|
| + }
|
| + if (dependency.constraint.min == null) {
|
| + _warnAboutNoConstraintLowerBound(dependency);
|
| + join4();
|
| + } else {
|
| + join6() {
|
| + join4();
|
| + }
|
| + if (dependency.constraint.max == null) {
|
| + _warnAboutNoConstraintUpperBound(dependency);
|
| + join6();
|
| + } else {
|
| + join6();
|
| + }
|
| + }
|
| + } else {
|
| + join3();
|
| + }
|
| + }
|
| + }
|
| + }
|
| + } catch (e, s) {
|
| + completer0.completeError(e, s);
|
| + }
|
| + });
|
| + return completer0.future;
|
| + })).then((x0) {
|
| + try {
|
| + x0;
|
| + join0() {
|
| + completer0.complete();
|
| + }
|
| + if (caretDeps.isNotEmpty && !_caretSafe) {
|
| + _errorAboutCaretConstraints(caretDeps);
|
| + join0();
|
| + } else {
|
| + join0();
|
| + }
|
| + } catch (e0, s0) {
|
| + completer0.completeError(e0, s0);
|
| + }
|
| + }, onError: completer0.completeError);
|
| + } catch (e, s) {
|
| + completer0.completeError(e, s);
|
| }
|
| -
|
| - if (dependency.constraint.isAny) {
|
| - _warnAboutNoConstraint(dependency);
|
| - } else if (dependency.constraint is Version) {
|
| - _warnAboutSingleVersionConstraint(dependency);
|
| - } else if (dependency.constraint is VersionRange) {
|
| - if (dependency.constraint.min == null) {
|
| - _warnAboutNoConstraintLowerBound(dependency);
|
| - } else if (dependency.constraint.max == null) {
|
| - _warnAboutNoConstraintUpperBound(dependency);
|
| - }
|
| - }
|
| -
|
| - return new Future.value();
|
| });
|
| + return completer0.future;
|
| }
|
|
|
| /// Warn that dependencies should use the hosted source.
|
| @@ -121,23 +215,54 @@ class DependencyValidator extends Validator {
|
|
|
| /// Warn that dependencies should have upper bounds on their constraints.
|
| void _warnAboutNoConstraintUpperBound(PackageDep dep) {
|
| + var constraint;
|
| + if ((dep.constraint as VersionRange).includeMin) {
|
| + constraint = _constraintForVersion(dep.constraint.min);
|
| + } else {
|
| + constraint =
|
| + '"${dep.constraint} ' '<${(dep.constraint as VersionRange).min.nextBreaking}"';
|
| + }
|
| +
|
| warnings.add(
|
| 'Your dependency on "${dep.name}" should have an upper bound. For ' 'example:\n'
|
| - '\n' 'dependencies:\n' ' ${dep.name}: "${dep.constraint} '
|
| - '${_upperBoundForVersion((dep.constraint as VersionRange).min)}"\n' '\n'
|
| + '\n' 'dependencies:\n' ' ${dep.name}: $constraint\n' '\n'
|
| 'Without an upper bound, you\'re promising to support '
|
| '${log.bold("all")} future versions of ${dep.name}.');
|
| }
|
|
|
| + /// Emits an error for any version constraints that use `^` without an
|
| + /// appropriate SDK constraint.
|
| + void _errorAboutCaretConstraints(List<PackageDeps> caretDeps) {
|
| + var newSdkConstraint =
|
| + entrypoint.root.pubspec.environment.sdkVersion.intersect(_postCaretPubVersions);
|
| +
|
| + var buffer = new StringBuffer(
|
| + "Older versions of pub don't support ^ version constraints.\n"
|
| + "Make sure your SDK constraint excludes those old versions:\n" "\n"
|
| + "environment:\n" " sdk: \"$newSdkConstraint\"\n" "\n");
|
| +
|
| + if (caretDeps.length == 1) {
|
| + buffer.writeln("Or use a fully-expanded constraint:");
|
| + } else {
|
| + buffer.writeln("Or use fully-expanded constraints:");
|
| + }
|
| +
|
| + buffer.writeln();
|
| + buffer.writeln("dependencies:");
|
| +
|
| + caretDeps.forEach((dep) {
|
| + VersionRange constraint = dep.constraint;
|
| + buffer.writeln(
|
| + " ${dep.name}: \">=${constraint.min} <${constraint.max}\"");
|
| + });
|
| +
|
| + errors.add(buffer.toString().trim());
|
| + }
|
| +
|
| /// Returns the suggested version constraint for a dependency that was tested
|
| /// against [version].
|
| - String _constraintForVersion(Version version) =>
|
| - '">=$version ${_upperBoundForVersion(version)}"';
|
| -
|
| - /// Returns the suggested upper bound for a dependency that was tested against
|
| - /// [version].
|
| - String _upperBoundForVersion(Version version) {
|
| - if (version.major != 0) return '<${version.major + 1}.0.0';
|
| - return '<${version.major}.${version.minor + 1}.0';
|
| + String _constraintForVersion(Version version) {
|
| + if (_caretSafe) return "^$version";
|
| + return '">=$version <${version.nextBreaking}"';
|
| }
|
| }
|
|
|