Skip to content

Commit c350055

Browse files
authored
Migrate remaining webdev libraries (#1763)
Closes #1640 Migrate the last unmigrated libraries from `lib/` as well as the binary.
1 parent 81c5384 commit c350055

File tree

6 files changed

+30
-41
lines changed

6 files changed

+30
-41
lines changed

webdev/bin/webdev.dart

Lines changed: 1 addition & 3 deletions
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
import 'dart:isolate';
@@ -52,4 +50,4 @@ Future main(List<String> args) async {
5250
}
5351
}
5452

55-
String get _boldApp => styleBold.wrap(appName);
53+
String get _boldApp => styleBold.wrap(appName)!;

webdev/lib/src/command/daemon_command.dart

Lines changed: 4 additions & 5 deletions
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:convert';
97
import 'dart:io';
@@ -69,8 +67,8 @@ class DaemonCommand extends Command<int> {
6967
// Validate the pubspec first to ensure we are in a Dart project.
7068
var pubspecLock = await readPubspecLock(configuration);
7169

72-
Daemon daemon;
73-
DevWorkflow workflow;
70+
Daemon? daemon;
71+
DevWorkflow? workflow;
7472
var cancelCount = 0;
7573
var cancelSub = StreamGroup.merge([
7674
ProcessSignal.sigint.watch(),
@@ -100,8 +98,9 @@ class DaemonCommand extends Command<int> {
10098
});
10199
daemon.registerDomain(daemonDomain);
102100
var buildOptions = buildRunnerArgs(pubspecLock, configuration);
101+
var extraArgs = argResults?.rest ?? [];
103102
var directoryArgs =
104-
argResults.rest.where((arg) => !arg.startsWith('-')).toList();
103+
extraArgs.where((arg) => !arg.startsWith('-')).toList();
105104
var targetPorts =
106105
parseDirectoryArgs(directoryArgs, basePort: await findUnusedPort());
107106
validateLaunchApps(configuration.launchApps, targetPorts.keys);

webdev/lib/src/command/serve_command.dart

Lines changed: 3 additions & 5 deletions
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

97
import 'package:args/args.dart';
@@ -99,9 +97,9 @@ refresh: Performs a full page refresh.
9997
// Forward remaining arguments as Build Options to the Daemon.
10098
// This isn't documented. Should it be advertised?
10199
var buildOptions = buildRunnerArgs(pubspecLock, configuration)
102-
..addAll(argResults.rest.where((arg) => arg.startsWith('-')).toList());
103-
var directoryArgs =
104-
argResults.rest.where((arg) => !arg.startsWith('-')).toList();
100+
..addAll(argResults!.rest.where((arg) => arg.startsWith('-')).toList());
101+
var extraArgs = argResults?.rest ?? [];
102+
var directoryArgs = extraArgs.where((arg) => !arg.startsWith('-')).toList();
105103
var targetPorts = parseDirectoryArgs(directoryArgs);
106104
validateLaunchApps(configuration.launchApps, targetPorts.keys);
107105

webdev/lib/src/daemon/app_domain.dart

Lines changed: 13 additions & 15 deletions
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:convert';
97
import 'dart:io';
@@ -21,7 +19,7 @@ import 'utilites.dart';
2119
/// A collection of method and events relevant to the running application.
2220
class AppDomain extends Domain {
2321
bool _isShutdown = false;
24-
int _buildProgressEventId;
22+
int? _buildProgressEventId;
2523
var _progressEventId = 0;
2624

2725
final _appStates = <String, _AppState>{};
@@ -58,7 +56,7 @@ class AppDomain extends Domain {
5856
}
5957

6058
void _handleAppConnections(WebDevServer server) async {
61-
var dwds = server.dwds;
59+
var dwds = server.dwds!;
6260
// The connection is established right before `main()` is called.
6361
await for (var appConnection in dwds.connectedApps) {
6462
var debugConnection = await dwds.debugConnection(appConnection);
@@ -94,7 +92,7 @@ class AppDomain extends Domain {
9492
var stdOutSub = vmService.onStdoutEvent.listen((log) {
9593
sendEvent('app.log', {
9694
'appId': appId,
97-
'log': utf8.decode(base64.decode(log.bytes)),
95+
'log': utf8.decode(base64.decode(log.bytes!)),
9896
});
9997
});
10098
sendEvent('app.debugPort', {
@@ -129,19 +127,19 @@ class AppDomain extends Domain {
129127
_initialize(serverManager);
130128
}
131129

132-
Future<Map<String, dynamic>> _callServiceExtension(
130+
Future<Map<String, dynamic>?> _callServiceExtension(
133131
Map<String, dynamic> args) async {
134132
var appId = getStringArg(args, 'appId', required: true);
135133
var appState = _appStates[appId];
136134
if (appState == null) {
137135
throw ArgumentError.value(appId, 'appId', 'Not found');
138136
}
139-
var methodName = getStringArg(args, 'methodName', required: true);
137+
var methodName = getStringArg(args, 'methodName', required: true)!;
140138
var params = args['params'] != null
141139
? (args['params'] as Map<String, dynamic>)
142140
: <String, dynamic>{};
143-
var response =
144-
await appState.vmService.callServiceExtension(methodName, args: params);
141+
var response = await appState.vmService!
142+
.callServiceExtension(methodName, args: params);
145143
return response.json;
146144
}
147145

@@ -168,7 +166,7 @@ class AppDomain extends Domain {
168166
'message': 'Performing hot restart...',
169167
'progressId': 'hot.restart',
170168
});
171-
var response = await appState.vmService.callServiceExtension('hotRestart');
169+
var response = await appState.vmService!.callServiceExtension('hotRestart');
172170
sendEvent('app.progress', {
173171
'appId': appId,
174172
'id': '$_progressEventId',
@@ -193,7 +191,7 @@ class AppDomain extends Domain {
193191
}
194192
// Note that this triggers the daemon to shutdown as we listen for the
195193
// tabConnection to close to initiate a shutdown.
196-
await appState._debugConnection?.close();
194+
await appState._debugConnection.close();
197195
// Wait for the daemon to gracefully shutdown before sending success.
198196
await daemon.onExit;
199197
return true;
@@ -216,15 +214,15 @@ class _AppState {
216214

217215
bool _isDisposed = false;
218216

219-
VmService get vmService => _debugConnection?.vmService;
217+
VmService? get vmService => _debugConnection.vmService;
220218

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

223221
void dispose() {
224222
if (_isDisposed) return;
225223
_isDisposed = true;
226-
_stdOutSub?.cancel();
227-
_resultSub?.cancel();
228-
_debugConnection?.close();
224+
_stdOutSub.cancel();
225+
_resultSub.cancel();
226+
_debugConnection.close();
229227
}
230228
}

webdev/lib/src/serve/dev_workflow.dart

Lines changed: 8 additions & 10 deletions
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

@@ -57,7 +55,7 @@ String _uriForLaunchApp(String launchApp, ServerManager serverManager) {
5755
.toString();
5856
}
5957

60-
Future<Chrome> _startChrome(
58+
Future<Chrome?> _startChrome(
6159
Configuration configuration,
6260
ServerManager serverManager,
6361
BuildDaemonClient client,
@@ -99,7 +97,7 @@ Future<ServerManager> _startServerManager(
9997
for (var target in targetPorts.keys) {
10098
serverOptions.add(ServerOptions(
10199
configuration,
102-
targetPorts[target],
100+
targetPorts[target]!,
103101
target,
104102
assetPort,
105103
));
@@ -125,7 +123,7 @@ void _registerBuildTargets(
125123
) {
126124
// Register a target for each serve target.
127125
for (var target in targetPorts.keys) {
128-
OutputLocation outputLocation;
126+
OutputLocation? outputLocation;
129127
if (configuration.outputPath != null &&
130128
(configuration.outputInput == null ||
131129
target == configuration.outputInput)) {
@@ -147,7 +145,7 @@ void _registerBuildTargets(
147145
..hoist = false);
148146
client.registerBuildTarget(DefaultBuildTarget((b) => b
149147
..target = ''
150-
..outputLocation = outputLocation?.toBuilder()));
148+
..outputLocation = outputLocation.toBuilder()));
151149
}
152150
}
153151

@@ -158,10 +156,10 @@ void _registerBuildTargets(
158156
class DevWorkflow {
159157
final _doneCompleter = Completer();
160158
final BuildDaemonClient _client;
161-
final Chrome _chrome;
159+
final Chrome? _chrome;
162160

163161
final ServerManager serverManager;
164-
StreamSubscription _resultsSub;
162+
StreamSubscription? _resultsSub;
165163

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

@@ -208,8 +206,8 @@ class DevWorkflow {
208206
Future<void> shutDown() async {
209207
await _resultsSub?.cancel();
210208
await _chrome?.close();
211-
await _client?.close();
212-
await serverManager?.stop();
209+
await _client.close();
210+
await serverManager.stop();
213211
if (!_doneCompleter.isCompleted) _doneCompleter.complete();
214212
}
215213
}

webdev/lib/src/webdev_command_runner.dart

Lines changed: 1 addition & 3 deletions
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

97
import 'package:args/args.dart';
@@ -18,7 +16,7 @@ import 'version.dart';
1816
export 'pubspec.dart' show PackageException;
1917
export 'util.dart' show appName;
2018

21-
Future<int> run(List<String> args) => _CommandRunner().run(args);
19+
Future<int> run(List<String> args) async => (await _CommandRunner().run(args))!;
2220

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

0 commit comments

Comments
 (0)