2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.9
6
-
7
5
import 'dart:async' ;
8
6
import 'dart:convert' ;
9
7
import 'dart:io' ;
10
8
11
9
import 'package:http/http.dart' ;
12
- import 'package:meta/meta.dart' ;
13
10
import 'package:pub_semver/pub_semver.dart' ;
14
11
import 'package:pubspec_parse/pubspec_parse.dart' ;
15
12
import 'package:yaml/yaml.dart' ;
@@ -20,19 +17,19 @@ import 'version.dart';
20
17
class PackageException implements Exception {
21
18
final List <PackageExceptionDetails > details;
22
19
23
- final String unsupportedArgument;
20
+ final String ? unsupportedArgument;
24
21
25
22
PackageException (this .details, {this .unsupportedArgument});
26
23
}
27
24
28
25
class PackageExceptionDetails {
29
26
final String error;
30
- final String description;
27
+ final String ? description;
31
28
final bool _missingDependency;
32
29
33
30
const PackageExceptionDetails ._(this .error,
34
- {this .description, bool missingDependency})
35
- : _missingDependency = missingDependency ?? false ;
31
+ {this .description, bool missingDependency = false })
32
+ : _missingDependency = missingDependency;
36
33
37
34
static const noPubspecLock =
38
35
PackageExceptionDetails ._('`pubspec.lock` does not exist.' ,
@@ -72,7 +69,7 @@ Future _runPubDeps() async {
72
69
}
73
70
74
71
class PubspecLock {
75
- final YamlMap _packages;
72
+ final YamlMap ? _packages;
76
73
77
74
PubspecLock (this ._packages);
78
75
@@ -82,28 +79,30 @@ class PubspecLock {
82
79
var pubspecLock =
83
80
loadYaml (await File ('pubspec.lock' ).readAsString ()) as YamlMap ;
84
81
85
- var packages = pubspecLock['packages' ] as YamlMap ;
82
+ var packages = pubspecLock['packages' ] as YamlMap ? ;
86
83
return PubspecLock (packages);
87
84
}
88
85
89
86
List <PackageExceptionDetails > checkPackage (
90
87
String pkgName, VersionConstraint constraint,
91
- {String forArgument, bool requireDirect}) {
92
- requireDirect ?? = true ;
88
+ {String ? forArgument, bool requireDirect = true }) {
93
89
var issues = < PackageExceptionDetails > [];
94
90
var missingDetails =
95
91
PackageExceptionDetails .missingDep (pkgName, constraint);
96
92
97
- var pkgDataMap = (_packages == null ) ? null : _packages[pkgName] as YamlMap ;
93
+ var pkgDataMap =
94
+ (_packages == null ) ? null : _packages! [pkgName] as YamlMap ? ;
98
95
if (pkgDataMap == null ) {
99
96
issues.add (missingDetails);
100
97
} 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 ' )) {
103
102
issues.add (missingDetails);
104
103
}
105
104
106
- var source = pkgDataMap['source' ] as String ;
105
+ var source = pkgDataMap['source' ] as String ? ;
107
106
if (source == 'hosted' ) {
108
107
// NOTE: pkgDataMap['description'] should be:
109
108
// `{url: https://pub.dartlang.org, name: [pkgName]}`
@@ -168,7 +167,7 @@ final buildWebCompilersConstraint = VersionConstraint.parse('>=2.12.0 <4.0.0');
168
167
// Note the minimum versions should never be dev versions as users will not
169
168
// get them by default.
170
169
Future <void > checkPubspecLock (PubspecLock pubspecLock,
171
- {@ required bool requireBuildWebCompilers}) async {
170
+ {required bool requireBuildWebCompilers}) async {
172
171
var issues = < PackageExceptionDetails > [];
173
172
174
173
var buildRunnerIssues =
@@ -191,7 +190,7 @@ Future<void> checkPubspecLock(PubspecLock pubspecLock,
191
190
}
192
191
193
192
class _PackageInfo {
194
- final Version version;
193
+ final Version ? version;
195
194
final VersionConstraint buildDaemonConstraint;
196
195
final bool isNewer;
197
196
_PackageInfo (this .version, this .buildDaemonConstraint, this .isNewer);
@@ -212,6 +211,9 @@ Future<_PackageInfo> _latestPackageInfo() async {
212
211
buildDaemonConstraint = buildDaemonDependency.version;
213
212
}
214
213
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);
217
219
}
0 commit comments