Skip to content

Commit b175072

Browse files
authored
Start migration of WebDev to null-safety (#1756)
1 parent 7416956 commit b175072

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

webdev/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.7.12-dev.0
2+
- Migrate Webdev to null-safety.
3+
14
## 2.7.11
25

36
- Remove no longer used `ExpressionCompilerService.handler`.

webdev/lib/src/logging.dart

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
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-
75
import 'dart:async';
86
import 'dart:io';
97

108
import 'package:io/ansi.dart';
119
import 'package:logging/logging.dart';
1210

1311
typedef LogWriter = void Function(Level level, String message,
14-
{String error, String loggerName, String stackTrace});
12+
{String? error, String? loggerName, String? stackTrace});
1513

1614
var _verbose = false;
17-
StreamSubscription<LogRecord> _subscription;
15+
StreamSubscription<LogRecord>? _subscription;
1816

19-
void configureLogWriter(bool verbose, {LogWriter customLogWriter}) {
17+
void configureLogWriter(bool verbose, {LogWriter? customLogWriter}) {
2018
_verbose = verbose;
2119
_logWriter = customLogWriter ?? _logWriter;
2220
Logger.root.level = verbose ? Level.ALL : Level.INFO;
@@ -30,7 +28,7 @@ void configureLogWriter(bool verbose, {LogWriter customLogWriter}) {
3028

3129
// ignore: prefer_function_declarations_over_variables
3230
LogWriter _logWriter =
33-
(level, message, {String error, String loggerName, String stackTrace}) {
31+
(level, message, {String? error, String? loggerName, String? stackTrace}) {
3432
// Erases the previous line
3533
if (!_verbose) stdout.write('\x1b[2K\r');
3634
var log = formatLog(level, message,
@@ -54,7 +52,7 @@ LogWriter get logWriter => _logWriter;
5452

5553
/// Colors the message and writes it to stdout.
5654
String formatLog(Level level, String message,
57-
{bool withColors, String error, String loggerName, String stackTrace}) {
55+
{bool? withColors, String? error, String? loggerName, String? stackTrace}) {
5856
withColors ??= false;
5957
var buffer = StringBuffer(message);
6058
if (error != null) {
@@ -75,7 +73,7 @@ String formatLog(Level level, String message,
7573
} else {
7674
color = red;
7775
}
78-
formattedLevel = color.wrap(formattedLevel);
76+
formattedLevel = color.wrap(formattedLevel) ?? formattedLevel;
7977
}
8078

8179
var loggerNameOutput =

webdev/lib/src/pubspec.dart

+21-19
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
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-
75
import 'dart:async';
86
import 'dart:convert';
97
import 'dart:io';
108

119
import 'package:http/http.dart';
12-
import 'package:meta/meta.dart';
1310
import 'package:pub_semver/pub_semver.dart';
1411
import 'package:pubspec_parse/pubspec_parse.dart';
1512
import 'package:yaml/yaml.dart';
@@ -20,19 +17,19 @@ import 'version.dart';
2017
class 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

2825
class 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

7471
class 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.
170169
Future<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

193192
class _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
}

webdev/lib/src/util.dart

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
75
import 'dart:async';
86
import 'dart:io';
97

webdev/lib/src/version.dart

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webdev/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: webdev
22
# Every time this changes you need to run `dart run build_runner build`.
3-
version: 2.7.11
3+
version: 2.7.12-dev.0
44
# We should not depend on a dev SDK before publishing.
55
# publish_to: none
66
description: >-

0 commit comments

Comments
 (0)