22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart = 2.9
6-
75import 'dart:async' ;
86import 'dart:convert' ;
97import 'dart:io' ;
108
119import 'package:http/http.dart' ;
12- import 'package:meta/meta.dart' ;
1310import 'package:pub_semver/pub_semver.dart' ;
1411import 'package:pubspec_parse/pubspec_parse.dart' ;
1512import 'package:yaml/yaml.dart' ;
@@ -20,19 +17,19 @@ import 'version.dart';
2017class PackageException implements Exception {
2118 final List <PackageExceptionDetails > details;
2219
23- final String unsupportedArgument;
20+ final String ? unsupportedArgument;
2421
2522 PackageException (this .details, {this .unsupportedArgument});
2623}
2724
2825class PackageExceptionDetails {
2926 final String error;
30- final String description;
27+ final String ? description;
3128 final bool _missingDependency;
3229
3330 const PackageExceptionDetails ._(this .error,
34- {this .description, bool missingDependency})
35- : _missingDependency = missingDependency ?? false ;
31+ {this .description, bool missingDependency = false })
32+ : _missingDependency = missingDependency;
3633
3734 static const noPubspecLock =
3835 PackageExceptionDetails ._('`pubspec.lock` does not exist.' ,
@@ -72,7 +69,7 @@ Future _runPubDeps() async {
7269}
7370
7471class PubspecLock {
75- final YamlMap _packages;
72+ final YamlMap ? _packages;
7673
7774 PubspecLock (this ._packages);
7875
@@ -82,28 +79,30 @@ class PubspecLock {
8279 var pubspecLock =
8380 loadYaml (await File ('pubspec.lock' ).readAsString ()) as YamlMap ;
8481
85- var packages = pubspecLock['packages' ] as YamlMap ;
82+ var packages = pubspecLock['packages' ] as YamlMap ? ;
8683 return PubspecLock (packages);
8784 }
8885
8986 List <PackageExceptionDetails > checkPackage (
9087 String pkgName, VersionConstraint constraint,
91- {String forArgument, bool requireDirect}) {
92- requireDirect ?? = true ;
88+ {String ? forArgument, bool requireDirect = true }) {
9389 var issues = < PackageExceptionDetails > [];
9490 var missingDetails =
9591 PackageExceptionDetails .missingDep (pkgName, constraint);
9692
97- var pkgDataMap = (_packages == null ) ? null : _packages[pkgName] as YamlMap ;
93+ var pkgDataMap =
94+ (_packages == null ) ? null : _packages! [pkgName] as YamlMap ? ;
9895 if (pkgDataMap == null ) {
9996 issues.add (missingDetails);
10097 } else {
101- var dependency = pkgDataMap['dependency' ] as String ;
102- if (requireDirect && ! dependency.startsWith ('direct ' )) {
98+ var dependency = pkgDataMap['dependency' ] as String ? ;
99+ if (requireDirect &&
100+ dependency != null &&
101+ ! dependency.startsWith ('direct ' )) {
103102 issues.add (missingDetails);
104103 }
105104
106- var source = pkgDataMap['source' ] as String ;
105+ var source = pkgDataMap['source' ] as String ? ;
107106 if (source == 'hosted' ) {
108107 // NOTE: pkgDataMap['description'] should be:
109108 // `{url: https://pub.dartlang.org, name: [pkgName]}`
@@ -168,7 +167,7 @@ final buildWebCompilersConstraint = VersionConstraint.parse('>=2.12.0 <4.0.0');
168167// Note the minimum versions should never be dev versions as users will not
169168// get them by default.
170169Future <void > checkPubspecLock (PubspecLock pubspecLock,
171- {@ required bool requireBuildWebCompilers}) async {
170+ {required bool requireBuildWebCompilers}) async {
172171 var issues = < PackageExceptionDetails > [];
173172
174173 var buildRunnerIssues =
@@ -191,7 +190,7 @@ Future<void> checkPubspecLock(PubspecLock pubspecLock,
191190}
192191
193192class _PackageInfo {
194- final Version version;
193+ final Version ? version;
195194 final VersionConstraint buildDaemonConstraint;
196195 final bool isNewer;
197196 _PackageInfo (this .version, this .buildDaemonConstraint, this .isNewer);
@@ -212,6 +211,9 @@ Future<_PackageInfo> _latestPackageInfo() async {
212211 buildDaemonConstraint = buildDaemonDependency.version;
213212 }
214213 var currentVersion = Version .parse (packageVersion);
215- return _PackageInfo (pubspec.version, buildDaemonConstraint,
216- currentVersion.compareTo (pubspec.version) < 0 );
214+ var pubspecVersion = pubspec.version;
215+ var isNewer = (pubspecVersion == null )
216+ ? true
217+ : currentVersion.compareTo (pubspecVersion) < 0 ;
218+ return _PackageInfo (pubspec.version, buildDaemonConstraint, isNewer);
217219}
0 commit comments