Skip to content

Start migration of WebDev to null-safety #1756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.7.12-dev.0
- Migrate Webdev to null-safety.

## 2.7.11

- Remove no longer used `ExpressionCompilerService.handler`.
Expand Down
14 changes: 6 additions & 8 deletions webdev/lib/src/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:io';

import 'package:io/ansi.dart';
import 'package:logging/logging.dart';

typedef LogWriter = void Function(Level level, String message,
{String error, String loggerName, String stackTrace});
{String? error, String? loggerName, String? stackTrace});

var _verbose = false;
StreamSubscription<LogRecord> _subscription;
StreamSubscription<LogRecord>? _subscription;

void configureLogWriter(bool verbose, {LogWriter customLogWriter}) {
void configureLogWriter(bool verbose, {LogWriter? customLogWriter}) {
_verbose = verbose;
_logWriter = customLogWriter ?? _logWriter;
Logger.root.level = verbose ? Level.ALL : Level.INFO;
Expand All @@ -30,7 +28,7 @@ void configureLogWriter(bool verbose, {LogWriter customLogWriter}) {

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

/// Colors the message and writes it to stdout.
String formatLog(Level level, String message,
{bool withColors, String error, String loggerName, String stackTrace}) {
{bool? withColors, String? error, String? loggerName, String? stackTrace}) {
withColors ??= false;
var buffer = StringBuffer(message);
if (error != null) {
Expand All @@ -75,7 +73,7 @@ String formatLog(Level level, String message,
} else {
color = red;
}
formattedLevel = color.wrap(formattedLevel);
formattedLevel = color.wrap(formattedLevel) ?? formattedLevel;
}

var loggerNameOutput =
Expand Down
40 changes: 21 additions & 19 deletions webdev/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart';
import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:yaml/yaml.dart';
Expand All @@ -20,19 +17,19 @@ import 'version.dart';
class PackageException implements Exception {
final List<PackageExceptionDetails> details;

final String unsupportedArgument;
final String? unsupportedArgument;

PackageException(this.details, {this.unsupportedArgument});
}

class PackageExceptionDetails {
final String error;
final String description;
final String? description;
final bool _missingDependency;

const PackageExceptionDetails._(this.error,
{this.description, bool missingDependency})
: _missingDependency = missingDependency ?? false;
{this.description, bool missingDependency = false})
: _missingDependency = missingDependency;

static const noPubspecLock =
PackageExceptionDetails._('`pubspec.lock` does not exist.',
Expand Down Expand Up @@ -72,7 +69,7 @@ Future _runPubDeps() async {
}

class PubspecLock {
final YamlMap _packages;
final YamlMap? _packages;

PubspecLock(this._packages);

Expand All @@ -82,28 +79,30 @@ class PubspecLock {
var pubspecLock =
loadYaml(await File('pubspec.lock').readAsString()) as YamlMap;

var packages = pubspecLock['packages'] as YamlMap;
var packages = pubspecLock['packages'] as YamlMap?;
return PubspecLock(packages);
}

List<PackageExceptionDetails> checkPackage(
String pkgName, VersionConstraint constraint,
{String forArgument, bool requireDirect}) {
requireDirect ??= true;
{String? forArgument, bool requireDirect = true}) {
var issues = <PackageExceptionDetails>[];
var missingDetails =
PackageExceptionDetails.missingDep(pkgName, constraint);

var pkgDataMap = (_packages == null) ? null : _packages[pkgName] as YamlMap;
var pkgDataMap =
(_packages == null) ? null : _packages![pkgName] as YamlMap?;
if (pkgDataMap == null) {
issues.add(missingDetails);
} else {
var dependency = pkgDataMap['dependency'] as String;
if (requireDirect && !dependency.startsWith('direct ')) {
var dependency = pkgDataMap['dependency'] as String?;
if (requireDirect &&
dependency != null &&
!dependency.startsWith('direct ')) {
issues.add(missingDetails);
}

var source = pkgDataMap['source'] as String;
var source = pkgDataMap['source'] as String?;
if (source == 'hosted') {
// NOTE: pkgDataMap['description'] should be:
// `{url: https://pub.dartlang.org, name: [pkgName]}`
Expand Down Expand Up @@ -168,7 +167,7 @@ final buildWebCompilersConstraint = VersionConstraint.parse('>=2.12.0 <4.0.0');
// Note the minimum versions should never be dev versions as users will not
// get them by default.
Future<void> checkPubspecLock(PubspecLock pubspecLock,
{@required bool requireBuildWebCompilers}) async {
{required bool requireBuildWebCompilers}) async {
var issues = <PackageExceptionDetails>[];

var buildRunnerIssues =
Expand All @@ -191,7 +190,7 @@ Future<void> checkPubspecLock(PubspecLock pubspecLock,
}

class _PackageInfo {
final Version version;
final Version? version;
final VersionConstraint buildDaemonConstraint;
final bool isNewer;
_PackageInfo(this.version, this.buildDaemonConstraint, this.isNewer);
Expand All @@ -212,6 +211,9 @@ Future<_PackageInfo> _latestPackageInfo() async {
buildDaemonConstraint = buildDaemonDependency.version;
}
var currentVersion = Version.parse(packageVersion);
return _PackageInfo(pubspec.version, buildDaemonConstraint,
currentVersion.compareTo(pubspec.version) < 0);
var pubspecVersion = pubspec.version;
var isNewer = (pubspecVersion == null)
? true
: currentVersion.compareTo(pubspecVersion) < 0;
return _PackageInfo(pubspec.version, buildDaemonConstraint, isNewer);
}
2 changes: 0 additions & 2 deletions webdev/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:io';

Expand Down
2 changes: 1 addition & 1 deletion webdev/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: webdev
# Every time this changes you need to run `dart run build_runner build`.
version: 2.7.11
version: 2.7.12-dev.0
# We should not depend on a dev SDK before publishing.
# publish_to: none
description: >-
Expand Down Expand Up @@ -49,9 +49,9 @@ dev_dependencies:
webdriver: ^3.0.0

# Comment out before releasing webdev.
# dependency_overrides:
# dwds:
# path: ../dwds
dependency_overrides:
dwds:
path: ../dwds

executables:
webdev: