Skip to content

Commit ebc64f7

Browse files
authored
require an upper bound on the sdk to publish (#1701)
1 parent 2515b9e commit ebc64f7

11 files changed

+55
-19
lines changed

lib/src/validator/sdk_constraint.dart

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ class SdkConstraintValidator extends Validator {
2020

2121
Future validate() async {
2222
var dartConstraint = entrypoint.root.pubspec.dartSdkConstraint;
23-
if (dartConstraint is VersionRange &&
24-
dartConstraint.toString().startsWith("^")) {
25-
errors
26-
.add("^ version constraints aren't allowed for SDK constraints since "
27-
"older versions of pub don't support them.\n"
28-
"Expand it manually instead:\n"
29-
"\n"
30-
"environment:\n"
31-
" sdk: \">=${dartConstraint.min} <${dartConstraint.max}\"");
23+
if (dartConstraint is VersionRange) {
24+
if (dartConstraint.toString().startsWith("^")) {
25+
errors.add(
26+
"^ version constraints aren't allowed for SDK constraints since "
27+
"older versions of pub don't support them.\n"
28+
"Expand it manually instead:\n"
29+
"\n"
30+
"environment:\n"
31+
" sdk: \">=${dartConstraint.min} <${dartConstraint.max}\"");
32+
}
33+
34+
if (dartConstraint.max == null) {
35+
errors.add(
36+
'Published packages should have an upper bound constraint on the '
37+
'Dart SDK (typically this should restrict to less than the next '
38+
'major version to guard against breaking changes).\n'
39+
'See https://www.dartlang.org/tools/pub/pubspec#sdk-constraints for '
40+
'instructions on setting an sdk version constraint.');
41+
}
3242
}
3343

3444
if (entrypoint.root.pubspec.flutterSdkConstraint != null &&

test/descriptor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ TarFileDescriptor tar(String name, [Iterable<Descriptor> contents]) =>
2828

2929
/// Describes a package that passes all validation.
3030
Descriptor get validPackage => dir(appPath, [
31-
libPubspec("test_pkg", "1.0.0"),
31+
libPubspec("test_pkg", "1.0.0", sdk: '>=1.8.0 <=2.0.0'),
3232
file("LICENSE", "Eh, do what you want."),
3333
dir("lib", [file("test_pkg.dart", "int i = 1;")])
3434
]);

test/lish/force_does_not_publish_if_there_are_errors_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main() {
2424
await pub.shouldExit(exit_codes.DATA);
2525
expect(
2626
pub.stderr,
27-
emitsThrough("Sorry, your package is missing a "
28-
"requirement and can't be published yet."));
27+
emitsThrough("Sorry, your package is missing some "
28+
"requirements and can't be published yet."));
2929
});
3030
}

test/lish/force_publishes_if_there_are_warnings_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ main() {
1818
setUp(d.validPackage.create);
1919

2020
test('--force publishes if there are warnings', () async {
21-
var pkg = packageMap("test_pkg", "1.0.0");
21+
var pkg =
22+
packageMap("test_pkg", "1.0.0", null, null, {'sdk': '>=1.8.0 <2.0.0'});
2223
pkg["author"] = "Natalie Weizenbaum";
2324
await d.dir(appPath, [d.pubspec(pkg)]).create();
2425

test/lish/package_validation_has_a_warning_and_continues_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ main() {
1818
setUp(d.validPackage.create);
1919

2020
test('package validation has a warning and continues', () async {
21-
var pkg = packageMap("test_pkg", "1.0.0");
21+
var pkg =
22+
packageMap("test_pkg", "1.0.0", null, null, {'sdk': '>=1.8.0 <2.0.0'});
2223
pkg["author"] = "Natalie Weizenbaum";
2324
await d.dir(appPath, [d.pubspec(pkg)]).create();
2425

test/lish/package_validation_has_a_warning_and_is_canceled_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ main() {
1414
setUp(d.validPackage.create);
1515

1616
test('package validation has a warning and is canceled', () async {
17-
var pkg = packageMap("test_pkg", "1.0.0");
17+
var pkg =
18+
packageMap("test_pkg", "1.0.0", null, null, {'sdk': '>=1.8.0 <2.0.0'});
1819
pkg["author"] = "Natalie Weizenbaum";
1920
await d.dir(appPath, [d.pubspec(pkg)]).create();
2021

test/lish/package_validation_has_an_error_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main() {
2424
await pub.shouldExit(exit_codes.DATA);
2525
expect(
2626
pub.stderr,
27-
emitsThrough("Sorry, your package is missing a "
28-
"requirement and can't be published yet."));
27+
emitsThrough("Sorry, your package is missing some "
28+
"requirements and can't be published yet."));
2929
});
3030
}

test/lish/preview_package_validation_has_a_warning_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ main() {
1414
setUp(d.validPackage.create);
1515

1616
test('preview package validation has a warning', () async {
17-
var pkg = packageMap("test_pkg", "1.0.0");
17+
var pkg =
18+
packageMap("test_pkg", "1.0.0", null, null, {'sdk': '>=1.8.0 <2.0.0'});
1819
pkg["author"] = "Natalie Weizenbaum";
1920
await d.dir(appPath, [d.pubspec(pkg)]).create();
2021

test/lish/preview_package_validation_has_no_warnings_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ main() {
1414
setUp(d.validPackage.create);
1515

1616
test('preview package validation has no warnings', () async {
17-
var pkg = packageMap("test_pkg", "1.0.0");
17+
var pkg =
18+
packageMap("test_pkg", "1.0.0", null, null, {'sdk': '>=1.8.0 <2.0.0'});
1819
pkg["author"] = "Natalie Weizenbaum <[email protected]>";
1920
await d.dir(appPath, [d.pubspec(pkg)]).create();
2021

test/test_pub.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ Map packageMap(
591591
String version, [
592592
Map dependencies,
593593
Map devDependencies,
594+
Map environment,
594595
]) {
595596
var package = <String, dynamic>{
596597
"name": name,
@@ -602,6 +603,7 @@ Map packageMap(
602603

603604
if (dependencies != null) package["dependencies"] = dependencies;
604605
if (devDependencies != null) package["dev_dependencies"] = devDependencies;
606+
if (environment != null) package["environment"] = environment;
605607
return package;
606608
}
607609

0 commit comments

Comments
 (0)