Skip to content

Commit 90c23b4

Browse files
authored
Move debug related webdev handlers to package:dwds (#477)
1 parent 9cc802b commit 90c23b4

File tree

12 files changed

+55
-44
lines changed

12 files changed

+55
-44
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.4.0-dev
22

33
- Move `data` abstractions from `package:webdev` into `package:dwds`.
4+
- Move debugging related handlers from `package:webdev` into `package:dwds`.
45

56
## 0.3.3
67

webdev/lib/src/serve/debugger/app_debug_services.dart renamed to dwds/lib/src/app_debug_services.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'package:dwds/service.dart';
7-
// ignore: implementation_imports
8-
import 'package:dwds/src/chrome_proxy_service.dart' show ChromeProxyService;
96

10-
import '../../serve/chrome.dart';
11-
import '../debugger/webdev_vm_client.dart';
7+
import '../service.dart';
8+
import 'chrome_proxy_service.dart' show ChromeProxyService;
9+
import 'dwds_vm_client.dart';
1210

1311
/// A container for all the services required for debugging an application.
1412
class AppDebugServices {
15-
final Chrome chrome;
1613
final DebugService debugService;
17-
final WebdevVmClient webdevClient;
14+
final DwdsVmClient dwdsVmClient;
1815

1916
ChromeProxyService get chromeProxyService =>
2017
debugService.chromeProxyService as ChromeProxyService;
@@ -24,8 +21,8 @@ class AppDebugServices {
2421
/// We only allow a given app to be debugged in a single tab at a time.
2522
String connectedInstanceId;
2623

27-
AppDebugServices(this.chrome, this.debugService, this.webdevClient);
24+
AppDebugServices(this.debugService, this.dwdsVmClient);
2825

2926
Future<void> close() =>
30-
Future.wait([debugService.close(), webdevClient.close()]);
27+
Future.wait([debugService.close(), dwdsVmClient.close()]);
3128
}
File renamed without changes.

webdev/lib/src/serve/debugger/webdev_vm_client.dart renamed to dwds/lib/src/dwds_vm_client.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@ import 'dart:async';
66
import 'dart:convert';
77

88
import 'package:dwds/service.dart';
9-
// ignore: implementation_imports
10-
import 'package:dwds/src/chrome_proxy_service.dart' show ChromeProxyService;
119
import 'package:vm_service_lib/vm_service_lib.dart';
1210

11+
import 'chrome_proxy_service.dart' show ChromeProxyService;
12+
1313
// A client of the vm service that registers some custom extensions like
1414
// hotRestart.
15-
class WebdevVmClient {
15+
class DwdsVmClient {
1616
final VmService client;
1717
final StreamController<Map<String, Object>> _requestController;
1818
final StreamController<Map<String, Object>> _responseController;
1919

20-
WebdevVmClient(
21-
this.client, this._requestController, this._responseController);
20+
DwdsVmClient(this.client, this._requestController, this._responseController);
2221

2322
Future<void> close() async {
2423
await _requestController.close();
2524
await _responseController.close();
2625
client.dispose();
2726
}
2827

29-
static Future<WebdevVmClient> create(DebugService debugService) async {
28+
static Future<DwdsVmClient> create(DebugService debugService) async {
3029
// Set up hot restart as an extension.
3130
var requestController = StreamController<Map<String, Object>>();
3231
var responseController = StreamController<Map<String, Object>>();
@@ -76,7 +75,7 @@ class WebdevVmClient {
7675
});
7776
await client.registerService('ext.webdev.screenshot', 'WebDev');
7877

79-
return WebdevVmClient(client, requestController, responseController);
78+
return DwdsVmClient(client, requestController, responseController);
8079
}
8180
}
8281

File renamed without changes.

webdev/lib/src/serve/handlers/dev_handler.dart renamed to dwds/lib/src/handlers/dev_handler.dart

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ import 'dart:convert';
77

88
import 'package:build_daemon/data/build_status.dart';
99
import 'package:build_daemon/data/serializers.dart';
10-
import 'package:dwds/data/connect_request.dart';
11-
import 'package:dwds/data/devtools_request.dart';
12-
import 'package:dwds/data/isolate_events.dart';
13-
import 'package:dwds/data/run_request.dart';
14-
import 'package:dwds/data/serializers.dart' as dwds;
15-
import 'package:dwds/service.dart';
1610
import 'package:logging/logging.dart';
1711
import 'package:pedantic/pedantic.dart';
1812
import 'package:shelf/shelf.dart';
1913
import 'package:sse/server/sse_handler.dart';
2014
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
2115

22-
import '../../logging.dart';
23-
import '../chrome.dart';
24-
import '../debugger/app_debug_services.dart';
25-
import '../debugger/devtools.dart';
26-
import '../debugger/webdev_vm_client.dart';
16+
import '../../data/connect_request.dart';
17+
import '../../data/devtools_request.dart';
18+
import '../../data/isolate_events.dart';
19+
import '../../data/run_request.dart';
20+
import '../../data/serializers.dart' as dwds;
21+
import '../../service.dart';
22+
import '../app_debug_services.dart';
23+
import '../devtools.dart';
24+
import '../dwds_vm_client.dart';
2725
import '../handlers/asset_handler.dart';
2826

2927
/// SSE handler to enable development features like hot reload and
@@ -39,11 +37,20 @@ class DevHandler {
3937
final _servicesByAppId = <String, Future<AppDebugServices>>{};
4038
final Stream<BuildResult> buildResults;
4139
final bool _verbose;
40+
final void Function(Level, String) _logWriter;
41+
final Future<ChromeConnection> Function() _chromeConnection;
4242

4343
Stream<DevConnection> get connectedApps => _connectedApps.stream;
4444

45-
DevHandler(this.buildResults, this._devTools, this._assetHandler,
46-
this._hostname, this._verbose) {
45+
DevHandler(
46+
this._chromeConnection,
47+
this.buildResults,
48+
this._devTools,
49+
this._assetHandler,
50+
this._hostname,
51+
this._verbose,
52+
this._logWriter,
53+
) {
4754
_sub = buildResults.listen(_emitBuildResults);
4855
_listen();
4956
}
@@ -82,7 +89,7 @@ class DevHandler {
8289
onResponse: _verbose
8390
? (response) {
8491
if (response['error'] == null) return;
85-
logWriter(Level.WARNING,
92+
_logWriter(Level.WARNING,
8693
'VmService proxy responded with an error:\n$response');
8794
}
8895
: null,
@@ -219,22 +226,21 @@ class DevHandler {
219226

220227
Future<AppDebugServices> _createAppDebugServices(
221228
String appId, String instanceId) async {
222-
var chrome = await Chrome.connectedInstance;
223229
var debugService =
224-
await startDebugService(chrome.chromeConnection, instanceId);
225-
logWriter(
230+
await startDebugService(await _chromeConnection(), instanceId);
231+
_logWriter(
226232
Level.INFO,
227233
'Debug service listening on '
228234
'${debugService.wsUri}\n');
229235

230-
var webdevClient = await WebdevVmClient.create(debugService);
231-
var appServices = AppDebugServices(chrome, debugService, webdevClient);
236+
var webdevClient = await DwdsVmClient.create(debugService);
237+
var appServices = AppDebugServices(debugService, webdevClient);
232238

233239
unawaited(
234240
appServices.chromeProxyService.tabConnection.onClose.first.then((_) {
235241
appServices.close();
236242
_servicesByAppId.remove(appId);
237-
logWriter(
243+
_logWriter(
238244
Level.INFO,
239245
'Stopped debug service on '
240246
'ws://${debugService.hostname}:${debugService.port}\n');

dwds/pubspec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ environment:
1010
sdk: ">=2.3.2-dev.0.1 <3.0.0"
1111

1212
dependencies:
13+
devtools: ^0.1.0
1314
http: ^0.12.0
1415
http_multi_server: ^2.0.0
1516
path: ^1.6.0
@@ -30,3 +31,7 @@ dev_dependencies:
3031
test: ^1.6.0
3132
webdriver: ^2.0.0
3233
webdev: ^2.0.0
34+
35+
dependency_overrides:
36+
webdev:
37+
path: ../webdev

webdev/lib/src/daemon/app_domain.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import 'dart:io';
88

99
import 'package:build_daemon/data/build_status.dart';
1010
import 'package:dwds/service.dart';
11+
import 'package:dwds/src/app_debug_services.dart'; // ignore: implementation_imports
1112
import 'package:pedantic/pedantic.dart';
1213
import 'package:vm_service_lib/vm_service_lib.dart';
1314

14-
import '../serve/debugger/app_debug_services.dart';
1515
import '../serve/server_manager.dart';
1616
import 'daemon.dart';
1717
import 'domain.dart';
@@ -24,7 +24,7 @@ class AppDomain extends Domain {
2424

2525
DebugService get _debugService => _appDebugServices?.debugService;
2626

27-
VmService get _vmService => _appDebugServices?.webdevClient?.client;
27+
VmService get _vmService => _appDebugServices?.dwdsVmClient?.client;
2828
StreamSubscription<BuildResult> _resultSub;
2929
StreamSubscription<Event> _stdOutSub;
3030
bool _isShutdown = false;

webdev/lib/src/serve/dev_workflow.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import 'package:build_daemon/client.dart';
99
import 'package:build_daemon/data/build_status.dart';
1010
import 'package:build_daemon/data/build_target.dart';
1111
import 'package:build_daemon/data/server_log.dart';
12+
import 'package:dwds/src/devtools.dart'; // ignore: implementation_imports
1213
import 'package:logging/logging.dart' as logging;
1314

1415
import '../command/configuration.dart';
1516
import '../daemon_client.dart';
1617
import '../logging.dart';
1718
import 'chrome.dart';
18-
import 'debugger/devtools.dart';
1919
import 'server_manager.dart';
2020
import 'webdev_server.dart';
2121

webdev/lib/src/serve/server_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import 'dart:async';
66

77
import 'package:build_daemon/data/build_status.dart';
8+
import 'package:dwds/src/devtools.dart'; // ignore: implementation_imports
89

9-
import 'debugger/devtools.dart';
1010
import 'webdev_server.dart';
1111

1212
/// Manages a set of [WebDevServer]s.

0 commit comments

Comments
 (0)