| 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 f9fb845837b83265316acc55491cc5b16ae49570..419326091c9712eba1acf2a2d2b9e2f5b5b87ee4 100644
|
| --- a/sdk/lib/_internal/pub_generated/lib/src/validator/dependency.dart
|
| +++ b/sdk/lib/_internal/pub_generated/lib/src/validator/dependency.dart
|
| @@ -1,17 +1,29 @@
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| library pub.validator.dependency;
|
| +
|
| import 'dart:async';
|
| +
|
| import 'package:pub_semver/pub_semver.dart';
|
| +
|
| import '../entrypoint.dart';
|
| import '../log.dart' as log;
|
| import '../package.dart';
|
| import '../validator.dart';
|
| +
|
| +/// A validator that validates a package's dependencies.
|
| class DependencyValidator extends Validator {
|
| - DependencyValidator(Entrypoint entrypoint) : super(entrypoint);
|
| + DependencyValidator(Entrypoint entrypoint)
|
| + : super(entrypoint);
|
| +
|
| Future validate() {
|
| return Future.forEach(entrypoint.root.pubspec.dependencies, (dependency) {
|
| if (dependency.source != "hosted") {
|
| return _warnAboutSource(dependency);
|
| }
|
| +
|
| if (dependency.constraint.isAny) {
|
| _warnAboutNoConstraint(dependency);
|
| } else if (dependency.constraint is Version) {
|
| @@ -23,9 +35,12 @@ class DependencyValidator extends Validator {
|
| _warnAboutNoConstraintUpperBound(dependency);
|
| }
|
| }
|
| +
|
| return new Future.value();
|
| });
|
| }
|
| +
|
| + /// Warn that dependencies should use the hosted source.
|
| Future _warnAboutSource(PackageDep dep) {
|
| return entrypoint.cache.sources['hosted'].getVersions(
|
| dep.name,
|
| @@ -40,10 +55,13 @@ class DependencyValidator extends Validator {
|
| constraint = '"$constraint"';
|
| }
|
| }
|
| +
|
| + // Path sources are errors. Other sources are just warnings.
|
| var messages = warnings;
|
| if (dep.source == "path") {
|
| messages = errors;
|
| }
|
| +
|
| messages.add(
|
| 'Don\'t depend on "${dep.name}" from the ${dep.source} '
|
| 'source. Use the hosted source instead. For example:\n' '\n' 'dependencies:\n'
|
| @@ -52,6 +70,8 @@ class DependencyValidator extends Validator {
|
| 'package\'s dependencies along with your package.');
|
| });
|
| }
|
| +
|
| + /// Warn that dependencies should have version constraints.
|
| void _warnAboutNoConstraint(PackageDep dep) {
|
| var message =
|
| 'Your dependency on "${dep.name}" should have a version ' 'constraint.';
|
| @@ -66,6 +86,8 @@ class DependencyValidator extends Validator {
|
| 'Without a constraint, you\'re promising to support ${log.bold("all")} '
|
| 'future versions of "${dep.name}".');
|
| }
|
| +
|
| + /// Warn that dependencies should allow more than a single version.
|
| void _warnAboutSingleVersionConstraint(PackageDep dep) {
|
| warnings.add(
|
| 'Your dependency on "${dep.name}" should allow more than one version. '
|
| @@ -75,6 +97,8 @@ class DependencyValidator extends Validator {
|
| 'use your package\n'
|
| 'along with other packages that also depend on "${dep.name}".');
|
| }
|
| +
|
| + /// Warn that dependencies should have lower bounds on their constraints.
|
| void _warnAboutNoConstraintLowerBound(PackageDep dep) {
|
| var message = 'Your dependency on "${dep.name}" should have a lower bound.';
|
| var locked = entrypoint.lockFile.packages[dep.name];
|
| @@ -85,6 +109,7 @@ class DependencyValidator extends Validator {
|
| } else {
|
| constraint = '">=${locked.version} ${dep.constraint}"';
|
| }
|
| +
|
| message =
|
| '$message For example:\n' '\n' 'dependencies:\n' ' ${dep.name}: $constraint\n';
|
| }
|
| @@ -93,6 +118,8 @@ class DependencyValidator extends Validator {
|
| 'Without a constraint, you\'re promising to support ${log.bold("all")} '
|
| 'previous versions of "${dep.name}".');
|
| }
|
| +
|
| + /// Warn that dependencies should have upper bounds on their constraints.
|
| void _warnAboutNoConstraintUpperBound(PackageDep dep) {
|
| warnings.add(
|
| 'Your dependency on "${dep.name}" should have an upper bound. For ' 'example:\n'
|
| @@ -101,8 +128,14 @@ class DependencyValidator extends Validator {
|
| 'Without an upper bound, you\'re promising to support '
|
| '${log.bold("all")} future versions of ${dep.name}.');
|
| }
|
| +
|
| + /// 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';
|
|
|