Skip to content

Migrate remaining webdev libraries #1763

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 3 commits into from
Oct 21, 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
4 changes: 1 addition & 3 deletions webdev/bin/webdev.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';
import 'dart:isolate';
Expand Down Expand Up @@ -52,4 +50,4 @@ Future main(List<String> args) async {
}
}

String get _boldApp => styleBold.wrap(appName);
String get _boldApp => styleBold.wrap(appName)!;
9 changes: 4 additions & 5 deletions webdev/lib/src/command/daemon_command.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:convert';
import 'dart:io';
Expand Down Expand Up @@ -69,8 +67,8 @@ class DaemonCommand extends Command<int> {
// Validate the pubspec first to ensure we are in a Dart project.
var pubspecLock = await readPubspecLock(configuration);

Daemon daemon;
DevWorkflow workflow;
Daemon? daemon;
DevWorkflow? workflow;
var cancelCount = 0;
var cancelSub = StreamGroup.merge([
ProcessSignal.sigint.watch(),
Expand Down Expand Up @@ -100,8 +98,9 @@ class DaemonCommand extends Command<int> {
});
daemon.registerDomain(daemonDomain);
var buildOptions = buildRunnerArgs(pubspecLock, configuration);
var extraArgs = argResults?.rest ?? [];
var directoryArgs =
argResults.rest.where((arg) => !arg.startsWith('-')).toList();
extraArgs.where((arg) => !arg.startsWith('-')).toList();
var targetPorts =
parseDirectoryArgs(directoryArgs, basePort: await findUnusedPort());
validateLaunchApps(configuration.launchApps, targetPorts.keys);
Expand Down
8 changes: 3 additions & 5 deletions webdev/lib/src/command/serve_command.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 'package:args/args.dart';
Expand Down Expand Up @@ -99,9 +97,9 @@ refresh: Performs a full page refresh.
// Forward remaining arguments as Build Options to the Daemon.
// This isn't documented. Should it be advertised?
var buildOptions = buildRunnerArgs(pubspecLock, configuration)
..addAll(argResults.rest.where((arg) => arg.startsWith('-')).toList());
var directoryArgs =
argResults.rest.where((arg) => !arg.startsWith('-')).toList();
..addAll(argResults!.rest.where((arg) => arg.startsWith('-')).toList());
var extraArgs = argResults?.rest ?? [];
var directoryArgs = extraArgs.where((arg) => !arg.startsWith('-')).toList();
var targetPorts = parseDirectoryArgs(directoryArgs);
validateLaunchApps(configuration.launchApps, targetPorts.keys);

Expand Down
28 changes: 13 additions & 15 deletions webdev/lib/src/daemon/app_domain.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:convert';
import 'dart:io';
Expand All @@ -21,7 +19,7 @@ import 'utilites.dart';
/// A collection of method and events relevant to the running application.
class AppDomain extends Domain {
bool _isShutdown = false;
int _buildProgressEventId;
int? _buildProgressEventId;
var _progressEventId = 0;

final _appStates = <String, _AppState>{};
Expand Down Expand Up @@ -58,7 +56,7 @@ class AppDomain extends Domain {
}

void _handleAppConnections(WebDevServer server) async {
var dwds = server.dwds;
var dwds = server.dwds!;
// The connection is established right before `main()` is called.
await for (var appConnection in dwds.connectedApps) {
var debugConnection = await dwds.debugConnection(appConnection);
Expand Down Expand Up @@ -94,7 +92,7 @@ class AppDomain extends Domain {
var stdOutSub = vmService.onStdoutEvent.listen((log) {
sendEvent('app.log', {
'appId': appId,
'log': utf8.decode(base64.decode(log.bytes)),
'log': utf8.decode(base64.decode(log.bytes!)),
});
});
sendEvent('app.debugPort', {
Expand Down Expand Up @@ -129,19 +127,19 @@ class AppDomain extends Domain {
_initialize(serverManager);
}

Future<Map<String, dynamic>> _callServiceExtension(
Future<Map<String, dynamic>?> _callServiceExtension(
Map<String, dynamic> args) async {
var appId = getStringArg(args, 'appId', required: true);
var appState = _appStates[appId];
if (appState == null) {
throw ArgumentError.value(appId, 'appId', 'Not found');
}
var methodName = getStringArg(args, 'methodName', required: true);
var methodName = getStringArg(args, 'methodName', required: true)!;
var params = args['params'] != null
? (args['params'] as Map<String, dynamic>)
: <String, dynamic>{};
var response =
await appState.vmService.callServiceExtension(methodName, args: params);
var response = await appState.vmService!
.callServiceExtension(methodName, args: params);
return response.json;
}

Expand All @@ -168,7 +166,7 @@ class AppDomain extends Domain {
'message': 'Performing hot restart...',
'progressId': 'hot.restart',
});
var response = await appState.vmService.callServiceExtension('hotRestart');
var response = await appState.vmService!.callServiceExtension('hotRestart');
sendEvent('app.progress', {
'appId': appId,
'id': '$_progressEventId',
Expand All @@ -193,7 +191,7 @@ class AppDomain extends Domain {
}
// Note that this triggers the daemon to shutdown as we listen for the
// tabConnection to close to initiate a shutdown.
await appState._debugConnection?.close();
await appState._debugConnection.close();
// Wait for the daemon to gracefully shutdown before sending success.
await daemon.onExit;
return true;
Expand All @@ -216,15 +214,15 @@ class _AppState {

bool _isDisposed = false;

VmService get vmService => _debugConnection?.vmService;
VmService? get vmService => _debugConnection.vmService;

_AppState(this._debugConnection, this._resultSub, this._stdOutSub);

void dispose() {
if (_isDisposed) return;
_isDisposed = true;
_stdOutSub?.cancel();
_resultSub?.cancel();
_debugConnection?.close();
_stdOutSub.cancel();
_resultSub.cancel();
_debugConnection.close();
}
}
18 changes: 8 additions & 10 deletions webdev/lib/src/serve/dev_workflow.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 Expand Up @@ -57,7 +55,7 @@ String _uriForLaunchApp(String launchApp, ServerManager serverManager) {
.toString();
}

Future<Chrome> _startChrome(
Future<Chrome?> _startChrome(
Configuration configuration,
ServerManager serverManager,
BuildDaemonClient client,
Expand Down Expand Up @@ -99,7 +97,7 @@ Future<ServerManager> _startServerManager(
for (var target in targetPorts.keys) {
serverOptions.add(ServerOptions(
configuration,
targetPorts[target],
targetPorts[target]!,
target,
assetPort,
));
Expand All @@ -125,7 +123,7 @@ void _registerBuildTargets(
) {
// Register a target for each serve target.
for (var target in targetPorts.keys) {
OutputLocation outputLocation;
OutputLocation? outputLocation;
if (configuration.outputPath != null &&
(configuration.outputInput == null ||
target == configuration.outputInput)) {
Expand All @@ -147,7 +145,7 @@ void _registerBuildTargets(
..hoist = false);
client.registerBuildTarget(DefaultBuildTarget((b) => b
..target = ''
..outputLocation = outputLocation?.toBuilder()));
..outputLocation = outputLocation.toBuilder()));
}
}

Expand All @@ -158,10 +156,10 @@ void _registerBuildTargets(
class DevWorkflow {
final _doneCompleter = Completer();
final BuildDaemonClient _client;
final Chrome _chrome;
final Chrome? _chrome;

final ServerManager serverManager;
StreamSubscription _resultsSub;
StreamSubscription? _resultsSub;

final _wrapWidth = stdout.hasTerminal ? stdout.terminalColumns - 8 : 72;

Expand Down Expand Up @@ -208,8 +206,8 @@ class DevWorkflow {
Future<void> shutDown() async {
await _resultsSub?.cancel();
await _chrome?.close();
await _client?.close();
await serverManager?.stop();
await _client.close();
await serverManager.stop();
if (!_doneCompleter.isCompleted) _doneCompleter.complete();
}
}
4 changes: 1 addition & 3 deletions webdev/lib/src/webdev_command_runner.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 'package:args/args.dart';
Expand All @@ -18,7 +16,7 @@ import 'version.dart';
export 'pubspec.dart' show PackageException;
export 'util.dart' show appName;

Future<int> run(List<String> args) => _CommandRunner().run(args);
Future<int> run(List<String> args) async => (await _CommandRunner().run(args))!;

class _CommandRunner extends CommandRunner<int> {
_CommandRunner() : super(appName, 'A tool to develop Dart web projects.') {
Expand Down