Skip to content
Snippets Groups Projects
Commit 69be47ed authored by Bob Nystrom's avatar Bob Nystrom Committed by GitHub
Browse files

Allow publishing packages with SDK dependencies on Flutter. (#1562)

Fix #1560.
parent f81cb51c
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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');
});
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment