From 69be47ed84c3ced304047aaa885c8f8f48dad4e6 Mon Sep 17 00:00:00 2001 From: Bob Nystrom <robert@stuffwithstuff.com> Date: Fri, 7 Apr 2017 16:53:58 -0700 Subject: [PATCH] Allow publishing packages with SDK dependencies on Flutter. (#1562) Fix #1560. --- lib/src/validator/dependency.dart | 19 ++++++++++++++++++- test/validator/dependency_test.dart | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/src/validator/dependency.dart b/lib/src/validator/dependency.dart index e2f6c678..269a40f6 100644 --- a/lib/src/validator/dependency.dart +++ b/lib/src/validator/dependency.dart @@ -12,6 +12,7 @@ import '../log.dart' as log; import '../package.dart'; import '../source/hosted.dart'; import '../source/path.dart'; +import '../source/sdk.dart'; import '../validator.dart'; /// The range of all pub versions that don't support `^` version constraints. @@ -41,7 +42,9 @@ class DependencyValidator extends Validator { for (var dependency in entrypoint.root.pubspec.dependencies) { var constraint = dependency.constraint; - if (dependency.source is! HostedSource) { + if (dependency.name == "flutter") { + _warnAboutFlutterSdk(dependency); + } else if (dependency.source is! HostedSource) { await _warnAboutSource(dependency); } else if (constraint.isAny) { _warnAboutNoConstraint(dependency); @@ -65,6 +68,20 @@ class DependencyValidator extends Validator { } } + /// Warn about improper dependencies on Flutter. + void _warnAboutFlutterSdk(PackageDep dep) { + if (dep.source is SdkSource) return; + + errors.add('Don\'t depend on "${dep.name}" from the ${dep.source} ' + 'source. Use the SDK source instead. For example:\n' + '\n' + 'dependencies:\n' + ' ${dep.name}:\n' + ' sdk: ${dep.constraint}\n' + '\n' + 'The Flutter SDK is downloaded and managed outside of pub.'); + } + /// Warn that dependencies should use the hosted source. Future _warnAboutSource(PackageDep dep) async { List<Version> versions; diff --git a/test/validator/dependency_test.dart b/test/validator/dependency_test.dart index f66a1e24..c5292a9f 100644 --- a/test/validator/dependency_test.dart +++ b/test/validator/dependency_test.dart @@ -72,6 +72,16 @@ main() { ]).create(); expectNoValidationError(dependency); }); + + integration('depends on Flutter from an SDK source', () { + d.dir(appPath, [ + d.libPubspec("test_pkg", "1.0.0", deps: { + "flutter": {"sdk": ">=1.2.3 <2.0.0"} + }) + ]).create(); + + expectNoValidationError(dependency); + }); }); group('should consider a package invalid if it', () { @@ -418,5 +428,13 @@ main() { expectDependencyValidationError(' foo: ">=1.2.3 <2.0.0"'); }); }); + + integration('depends on Flutter from a non-SDK source', () { + d.dir(appPath, [ + d.libPubspec("test_pkg", "1.0.0", deps: {"flutter": ">=1.2.3 <2.0.0"}) + ]).create(); + + expectDependencyValidationError('sdk: >=1.2.3 <2.0.0'); + }); }); } -- GitLab