@@ -26,11 +26,10 @@ import 'utils.dart';
26
26
final _packageName = new RegExp (
27
27
"^${identifierRegExp .pattern }(\\ .${identifierRegExp .pattern })*\$ " );
28
28
29
- /// The default SDK constraint for packages that don't declare one.
29
+ /// The default SDK upper bound constraint for packages that don't declare one.
30
30
///
31
- /// This allows 2.0.0 dev versions to make the migration proecss smoother.
32
- final _defaultSdkConstraint =
33
- new VersionConstraint .parse ("<2.0.0-dev.infinity" );
31
+ /// This provides a sane default for packages that don't have an upper bound.
32
+ final _defaultUpperBoundSdkConstraint = new VersionConstraint .parse ("<2.0.0" );
34
33
35
34
/// Whether or not `features` are enabled.
36
35
///
@@ -67,6 +66,10 @@ class Pubspec {
67
66
/// This includes the fields from which other properties are derived.
68
67
final YamlMap fields;
69
68
69
+ /// Whether or not to apply the [_defaultUpperBoundsSdkConstraint] to this
70
+ /// pubspec.
71
+ bool _includeDefaultSdkConstraint;
72
+
70
73
/// The package's name.
71
74
String get name {
72
75
if (_name != null ) return _name;
@@ -295,8 +298,8 @@ class Pubspec {
295
298
});
296
299
}
297
300
298
- /// The constraint on the Dart SDK, or [_defaultSdkConstraint ] if none is
299
- /// specified.
301
+ /// The constraint on the Dart SDK, with [_defaultUpperBoundSdkConstraint ] if
302
+ /// none is specified.
300
303
VersionConstraint get dartSdkConstraint {
301
304
_ensureEnvironment ();
302
305
return _dartSdkConstraint;
@@ -327,7 +330,11 @@ class Pubspec {
327
330
Pair <VersionConstraint , VersionConstraint > _parseEnvironment (YamlMap parent) {
328
331
var yaml = parent['environment' ];
329
332
if (yaml == null ) {
330
- return new Pair (_defaultSdkConstraint, null );
333
+ return new Pair (
334
+ _includeDefaultSdkConstraint
335
+ ? _defaultUpperBoundSdkConstraint
336
+ : VersionConstraint .any,
337
+ null );
331
338
}
332
339
333
340
if (yaml is ! Map ) {
@@ -337,7 +344,9 @@ class Pubspec {
337
344
338
345
return new Pair (
339
346
_parseVersionConstraint (yaml.nodes['sdk' ],
340
- defaultConstraint: _defaultSdkConstraint),
347
+ defaultUpperBoundConstraint: _includeDefaultSdkConstraint
348
+ ? _defaultUpperBoundSdkConstraint
349
+ : null ),
341
350
yaml.containsKey ('flutter' )
342
351
? _parseVersionConstraint (yaml.nodes['flutter' ])
343
352
: null );
@@ -485,7 +494,7 @@ class Pubspec {
485
494
/// If [expectedName] is passed and the pubspec doesn't have a matching name
486
495
/// field, this will throw a [PubspecError] .
487
496
factory Pubspec .load (String packageDir, SourceRegistry sources,
488
- {String expectedName}) {
497
+ {String expectedName, bool includeDefaultSdkConstraint }) {
489
498
var pubspecPath = path.join (packageDir, 'pubspec.yaml' );
490
499
var pubspecUri = path.toUri (pubspecPath);
491
500
if (! fileExists (pubspecPath)) {
@@ -498,7 +507,9 @@ class Pubspec {
498
507
}
499
508
500
509
return new Pubspec .parse (readTextFile (pubspecPath), sources,
501
- expectedName: expectedName, location: pubspecUri);
510
+ expectedName: expectedName,
511
+ includeDefaultSdkConstraint: includeDefaultSdkConstraint,
512
+ location: pubspecUri);
502
513
}
503
514
504
515
Pubspec (this ._name,
@@ -507,6 +518,7 @@ class Pubspec {
507
518
Iterable <PackageRange > devDependencies,
508
519
Iterable <PackageRange > dependencyOverrides,
509
520
VersionConstraint dartSdkConstraint,
521
+ bool includeDefaultSdkConstraint,
510
522
VersionConstraint flutterSdkConstraint,
511
523
Iterable <Iterable <TransformerConfig >> transformers,
512
524
Map fields,
@@ -517,8 +529,12 @@ class Pubspec {
517
529
devDependencies == null ? null : devDependencies.toList (),
518
530
_dependencyOverrides =
519
531
dependencyOverrides == null ? null : dependencyOverrides.toList (),
520
- _dartSdkConstraint = dartSdkConstraint ?? _defaultSdkConstraint,
532
+ _dartSdkConstraint =
533
+ dartSdkConstraint ?? includeDefaultSdkConstraint == true
534
+ ? _defaultUpperBoundSdkConstraint
535
+ : VersionConstraint .any,
521
536
_flutterSdkConstraint = flutterSdkConstraint,
537
+ _includeDefaultSdkConstraint = includeDefaultSdkConstraint,
522
538
_transformers = transformers == null
523
539
? []
524
540
: transformers.map ((phase) => phase.toSet ()).toList (),
@@ -531,8 +547,9 @@ class Pubspec {
531
547
_version = Version .none,
532
548
_dependencies = < PackageRange > [],
533
549
_devDependencies = < PackageRange > [],
534
- _dartSdkConstraint = _defaultSdkConstraint ,
550
+ _dartSdkConstraint = VersionConstraint .any ,
535
551
_flutterSdkConstraint = null ,
552
+ _includeDefaultSdkConstraint = false ,
536
553
_transformers = < Set <TransformerConfig >> [],
537
554
fields = new YamlMap ();
538
555
@@ -544,10 +561,11 @@ class Pubspec {
544
561
///
545
562
/// [location] is the location from which this pubspec was loaded.
546
563
Pubspec .fromMap (Map fields, this ._sources,
547
- {String expectedName, Uri location})
564
+ {String expectedName, bool includeDefaultSdkConstraint, Uri location})
548
565
: fields = fields is YamlMap
549
566
? fields
550
- : new YamlMap .wrap (fields, sourceUrl: location) {
567
+ : new YamlMap .wrap (fields, sourceUrl: location),
568
+ _includeDefaultSdkConstraint = includeDefaultSdkConstraint ?? true {
551
569
// If [expectedName] is passed, ensure that the actual 'name' field exists
552
570
// and matches the expectation.
553
571
if (expectedName == null ) return ;
@@ -564,7 +582,7 @@ class Pubspec {
564
582
/// If the pubspec doesn't define a version for itself, it defaults to
565
583
/// [Version.none] .
566
584
factory Pubspec .parse (String contents, SourceRegistry sources,
567
- {String expectedName, Uri location}) {
585
+ {String expectedName, bool includeDefaultSdkConstraint, Uri location}) {
568
586
YamlNode pubspecNode;
569
587
try {
570
588
pubspecNode = loadYamlNode (contents, sourceUrl: location);
@@ -583,7 +601,9 @@ class Pubspec {
583
601
}
584
602
585
603
return new Pubspec .fromMap (pubspecMap, sources,
586
- expectedName: expectedName, location: location);
604
+ expectedName: expectedName,
605
+ includeDefaultSdkConstraint: includeDefaultSdkConstraint,
606
+ location: location);
587
607
}
588
608
589
609
/// Returns a list of most errors in this pubspec.
@@ -702,17 +722,31 @@ class Pubspec {
702
722
return dependencies;
703
723
}
704
724
705
- /// Parses [node] to a [VersionConstraint] , or [defaultConstraint] if no
706
- /// constraint is specified..
725
+ /// Parses [node] to a [VersionConstraint] .
726
+ ///
727
+ /// If or [defaultUpperBoundConstraint] is specified then it will be set as
728
+ /// the max constraint if the original constraint doesn't have an upper
729
+ /// bound and it is compatible with [defaultUpperBoundConstraint] .
707
730
VersionConstraint _parseVersionConstraint (YamlNode node,
708
- {VersionConstraint defaultConstraint}) {
709
- if (node? .value == null ) return defaultConstraint;
731
+ {VersionConstraint defaultUpperBoundConstraint}) {
732
+ if (node? .value == null ) {
733
+ return defaultUpperBoundConstraint ?? VersionConstraint .any;
734
+ }
710
735
if (node.value is ! String ) {
711
736
_error ('A version constraint must be a string.' , node.span);
712
737
}
713
738
714
- return _wrapFormatException ('version constraint' , node.span,
715
- () => new VersionConstraint .parse (node.value));
739
+ return _wrapFormatException ('version constraint' , node.span, () {
740
+ var constraint = new VersionConstraint .parse (node.value);
741
+ if (defaultUpperBoundConstraint != null &&
742
+ constraint is VersionRange &&
743
+ constraint.max == null &&
744
+ defaultUpperBoundConstraint.allowsAny (constraint)) {
745
+ constraint = new VersionConstraint .intersection (
746
+ [constraint, defaultUpperBoundConstraint]);
747
+ }
748
+ return constraint;
749
+ });
716
750
}
717
751
718
752
/// Parses [node] to a map from feature names to whether those features are
0 commit comments