diff --git a/dwds/lib/asset_reader.dart b/dwds/lib/asset_reader.dart index 9066a04b1..578849f30 100644 --- a/dwds/lib/asset_reader.dart +++ b/dwds/lib/asset_reader.dart @@ -3,4 +3,4 @@ // BSD-style license that can be found in the LICENSE file. export 'src/readers/asset_reader.dart' - show AssetReader, UrlEncoder, PackageUriMapper, stripLeadingSlashes; + show AssetReader, PackageUriMapper, stripLeadingSlashes; diff --git a/dwds/lib/config.dart b/dwds/lib/config.dart new file mode 100644 index 000000000..e21c7f494 --- /dev/null +++ b/dwds/lib/config.dart @@ -0,0 +1,7 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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. + +export 'src/config/app_metadata.dart' show AppMetadata; +export 'src/config/debug_settings.dart' + show UrlEncoder, DevToolsLauncher, DebugSettings; diff --git a/dwds/lib/dart_web_debug_service.dart b/dwds/lib/dart_web_debug_service.dart index b68e07416..4ff176e65 100644 --- a/dwds/lib/dart_web_debug_service.dart +++ b/dwds/lib/dart_web_debug_service.dart @@ -5,6 +5,8 @@ import 'dart:async'; import 'package:dwds/data/build_result.dart'; +import 'package:dwds/src/config/app_metadata.dart'; +import 'package:dwds/src/config/debug_settings.dart'; import 'package:dwds/src/connections/app_connection.dart'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/events.dart'; @@ -15,7 +17,6 @@ import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/readers/asset_reader.dart'; import 'package:dwds/src/servers/devtools.dart'; import 'package:dwds/src/servers/extension_backend.dart'; -import 'package:dwds/src/services/expression_compiler.dart'; import 'package:dwds/src/utilities/globals.dart'; import 'package:logging/logging.dart'; import 'package:shelf/shelf.dart'; @@ -67,35 +68,18 @@ class Dwds { required Stream buildResults, required ConnectionProvider chromeConnection, required LoadStrategy loadStrategy, - required bool enableDebugging, - // TODO(annagrin): make expressionCompiler argument required - // [issue 881](https://github.com/dart-lang/webdev/issues/881) - ExpressionCompiler? expressionCompiler, - bool enableDebugExtension = false, - String hostname = 'localhost', - bool useSseForDebugProxy = true, - bool useSseForDebugBackend = true, - bool useSseForInjectedClient = true, - UrlEncoder? urlEncoder, - bool spawnDds = true, - // TODO(elliette): DevTools is inconsistently capitalized throughout this - // file. Change all occurrences of devtools/Devtools to devTools/DevTools. - bool enableDevtoolsLaunch = true, - DevtoolsLauncher? devtoolsLauncher, - bool launchDevToolsInNewWindow = true, - bool emitDebugEvents = true, - bool isInternalBuild = false, - Future Function()? isFlutterApp, + required DebugSettings debugSettings, + required AppMetadata appMetadata, }) async { globalLoadStrategy = loadStrategy; - globalIsInternalBuild = isInternalBuild; - isFlutterApp ??= () => Future.value(true); + globalAppMetadata = appMetadata; + globalDebugSettings = debugSettings; DevTools? devTools; Future? extensionUri; ExtensionBackend? extensionBackend; - if (enableDebugExtension) { - final handler = useSseForDebugBackend + if (debugSettings.enableDebugExtension) { + final handler = debugSettings.useSseForDebugBackend ? SseSocketHandler( SseHandler( Uri.parse('/\$debug'), @@ -108,34 +92,32 @@ class Dwds { ) : WebSocketSocketHandler(); - extensionBackend = await ExtensionBackend.start(handler, hostname); + extensionBackend = + await ExtensionBackend.start(handler, appMetadata.hostname); extensionUri = Future.value( Uri( - scheme: useSseForDebugBackend ? 'http' : 'ws', + scheme: debugSettings.useSseForDebugBackend ? 'http' : 'ws', host: extensionBackend.hostname, port: extensionBackend.port, path: r'$debug', ).toString(), ); - if (urlEncoder != null) extensionUri = urlEncoder(await extensionUri); + final urlEncoder = debugSettings.urlEncoder; + if (urlEncoder != null) { + extensionUri = urlEncoder(await extensionUri); + } } - final serveDevTools = devtoolsLauncher != null; - if (serveDevTools) { - devTools = await devtoolsLauncher(hostname); + final devToolsLauncher = debugSettings.devToolsLauncher; + if (devToolsLauncher != null) { + devTools = await devToolsLauncher(appMetadata.hostname); final uri = Uri(scheme: 'http', host: devTools.hostname, port: devTools.port); _logger.info('Serving DevTools at $uri\n'); } final injected = DwdsInjector( - loadStrategy, - useSseForInjectedClient: useSseForInjectedClient, extensionUri: extensionUri, - enableDevtoolsLaunch: enableDevtoolsLaunch, - emitDebugEvents: emitDebugEvents, - isInternalBuild: isInternalBuild, - isFlutterApp: isFlutterApp, ); final devHandler = DevHandler( @@ -143,15 +125,15 @@ class Dwds { buildResults, devTools, assetReader, - hostname, + appMetadata.hostname, extensionBackend, - urlEncoder, - useSseForDebugProxy, - useSseForInjectedClient, - expressionCompiler, + debugSettings.urlEncoder, + debugSettings.useSseForDebugProxy, + debugSettings.useSseForInjectedClient, + debugSettings.expressionCompiler, injected, - spawnDds, - launchDevToolsInNewWindow, + debugSettings.spawnDds, + debugSettings.launchDevToolsInNewWindow, ); return Dwds._( @@ -159,7 +141,7 @@ class Dwds { devTools, devHandler, assetReader, - enableDebugging, + debugSettings.enableDebugging, ); } } diff --git a/dwds/lib/dwds.dart b/dwds/lib/dwds.dart index 3b67f1a14..66ac4e664 100644 --- a/dwds/lib/dwds.dart +++ b/dwds/lib/dwds.dart @@ -3,6 +3,9 @@ // BSD-style license that can be found in the LICENSE file. export 'dart_web_debug_service.dart' show Dwds, ConnectionProvider; +export 'src/config/app_metadata.dart' show AppMetadata; +export 'src/config/debug_settings.dart' + show UrlEncoder, DevToolsLauncher, DebugSettings; export 'src/connections/app_connection.dart' show AppConnection; export 'src/connections/debug_connection.dart' show DebugConnection; export 'src/debugging/metadata/provider.dart' @@ -17,8 +20,7 @@ export 'src/loaders/frontend_server_require.dart' export 'src/loaders/legacy.dart' show LegacyStrategy; export 'src/loaders/require.dart' show RequireStrategy; export 'src/loaders/strategy.dart' show LoadStrategy, ReloadConfiguration; -export 'src/readers/asset_reader.dart' - show AssetReader, UrlEncoder, PackageUriMapper; +export 'src/readers/asset_reader.dart' show AssetReader, PackageUriMapper; export 'src/readers/frontend_server_asset_reader.dart' show FrontendServerAssetReader; export 'src/readers/proxy_server_asset_reader.dart' show ProxyServerAssetReader; diff --git a/dwds/lib/src/config/app_metadata.dart b/dwds/lib/src/config/app_metadata.dart new file mode 100644 index 000000000..424e08b6a --- /dev/null +++ b/dwds/lib/src/config/app_metadata.dart @@ -0,0 +1,18 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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. + +/// Metadata for the connected app. +/// +/// These are set by the code runner and passed to DWDS on start up. +class AppMetadata { + final String hostname; + final bool isInternalBuild; + Future Function() isFlutterApp; + + AppMetadata({ + this.hostname = 'localhost', + this.isInternalBuild = false, + Future Function()? isFlutterApp, + }) : isFlutterApp = isFlutterApp ?? (() => Future.value(true)); +} diff --git a/dwds/lib/src/config/debug_settings.dart b/dwds/lib/src/config/debug_settings.dart new file mode 100644 index 000000000..d6f178224 --- /dev/null +++ b/dwds/lib/src/config/debug_settings.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:dwds/src/servers/devtools.dart'; +import 'package:dwds/src/services/expression_compiler.dart'; + +typedef UrlEncoder = Future Function(String url); + +typedef DevToolsLauncher = Future Function(String hostname); + +/// Debug settings for the connected app. +/// +/// These are set by the code runner and passed to DWDS on start up. +class DebugSettings { + final bool enableDebugging; + final bool enableDebugExtension; + final bool useSseForDebugProxy; + final bool useSseForDebugBackend; + final bool useSseForInjectedClient; + final bool spawnDds; + final bool enableDevToolsLaunch; + final bool launchDevToolsInNewWindow; + final bool emitDebugEvents; + final DevToolsLauncher? devToolsLauncher; + // TODO(annagrin): make expressionCompiler argument required + // [issue 881](https://github.com/dart-lang/webdev/issues/881) + final ExpressionCompiler? expressionCompiler; + final UrlEncoder? urlEncoder; + + DebugSettings({ + required this.enableDebugging, + this.enableDebugExtension = false, + this.useSseForDebugProxy = true, + this.useSseForDebugBackend = true, + this.useSseForInjectedClient = true, + this.spawnDds = true, + this.enableDevToolsLaunch = true, + this.launchDevToolsInNewWindow = true, + this.emitDebugEvents = true, + this.devToolsLauncher, + this.expressionCompiler, + this.urlEncoder, + }); +} diff --git a/dwds/lib/src/handlers/dev_handler.dart b/dwds/lib/src/handlers/dev_handler.dart index 51c634ac6..ff634da76 100644 --- a/dwds/lib/src/handlers/dev_handler.dart +++ b/dwds/lib/src/handlers/dev_handler.dart @@ -14,6 +14,7 @@ import 'package:dwds/data/error_response.dart'; import 'package:dwds/data/isolate_events.dart'; import 'package:dwds/data/register_event.dart'; import 'package:dwds/data/serializers.dart'; +import 'package:dwds/src/config/debug_settings.dart'; import 'package:dwds/src/connections/app_connection.dart'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/execution_context.dart'; diff --git a/dwds/lib/src/handlers/injector.dart b/dwds/lib/src/handlers/injector.dart index a8dc6b570..9b28d39a0 100644 --- a/dwds/lib/src/handlers/injector.dart +++ b/dwds/lib/src/handlers/injector.dart @@ -8,7 +8,7 @@ import 'dart:io'; import 'dart:isolate'; import 'package:crypto/crypto.dart'; -import 'package:dwds/src/loaders/strategy.dart'; +import 'package:dwds/src/utilities/globals.dart'; import 'package:dwds/src/version.dart'; import 'package:logging/logging.dart'; import 'package:shelf/shelf.dart'; @@ -28,30 +28,13 @@ const _clientScript = 'dwds/src/injected/client'; /// Handles injecting the DWDS client and embedding debugging related /// information. class DwdsInjector { - final LoadStrategy _loadStrategy; final Future? _extensionUri; final _devHandlerPaths = StreamController(); final _logger = Logger('DwdsInjector'); - final bool _enableDevtoolsLaunch; - final bool _useSseForInjectedClient; - final bool _emitDebugEvents; - final bool _isInternalBuild; - final Future Function() _isFlutterApp; - DwdsInjector( - this._loadStrategy, { - required bool enableDevtoolsLaunch, - required bool useSseForInjectedClient, - required bool emitDebugEvents, - required bool isInternalBuild, - required Future Function() isFlutterApp, + DwdsInjector({ Future? extensionUri, - }) : _extensionUri = extensionUri, - _enableDevtoolsLaunch = enableDevtoolsLaunch, - _useSseForInjectedClient = useSseForInjectedClient, - _emitDebugEvents = emitDebugEvents, - _isInternalBuild = isInternalBuild, - _isFlutterApp = isFlutterApp; + }) : _extensionUri = extensionUri; /// Returns the embedded dev handler paths. /// @@ -97,7 +80,7 @@ class DwdsInjector { final appId = base64 .encode(md5.convert(utf8.encode('$requestedUri')).bytes); var scheme = request.requestedUri.scheme; - if (!_useSseForInjectedClient) { + if (!globalDebugSettings.useSseForInjectedClient) { // Switch http->ws and https->wss. scheme = scheme.replaceFirst('http', 'ws'); } @@ -112,20 +95,15 @@ class DwdsInjector { devHandlerPath = '$requestedUriBase/$devHandlerPath'; _devHandlerPaths.add(devHandlerPath); final entrypoint = request.url.path; - _loadStrategy.trackEntrypoint(entrypoint); - body = _injectClientAndHoistMain( + globalLoadStrategy.trackEntrypoint(entrypoint); + body = await _injectClientAndHoistMain( body, appId, devHandlerPath, entrypoint, await _extensionUri, - _loadStrategy, - _enableDevtoolsLaunch, - _emitDebugEvents, - _isInternalBuild, - await _isFlutterApp(), ); - body += await _loadStrategy.bootstrapFor(entrypoint); + body += await globalLoadStrategy.bootstrapFor(entrypoint); _logger.info('Injected debugging metadata for ' 'entrypoint at $requestedUri'); etag = base64.encode(md5.convert(body.codeUnits).bytes); @@ -136,7 +114,7 @@ class DwdsInjector { } return response.change(body: body, headers: newHeaders); } else { - final loadResponse = await _loadStrategy.handler(request); + final loadResponse = await globalLoadStrategy.handler(request); if (loadResponse.statusCode != HttpStatus.notFound) { return loadResponse; } @@ -148,18 +126,13 @@ class DwdsInjector { /// Returns the provided body with the main function hoisted into a global /// variable and a snippet of JS that loads the injected client. -String _injectClientAndHoistMain( +Future _injectClientAndHoistMain( String body, String appId, String devHandlerPath, String entrypointPath, String? extensionUri, - LoadStrategy loadStrategy, - bool enableDevtoolsLaunch, - bool emitDebugEvents, - bool isInternalBuild, - bool isFlutterApp, -) { +) async { final bodyLines = body.split('\n'); final extensionIndex = bodyLines.indexWhere((line) => line.contains(mainExtensionMarker)); @@ -171,16 +144,11 @@ String _injectClientAndHoistMain( // We inject the client in the entry point module as the client expects the // application to be in a ready state, that is the main function is hoisted // and the Dart SDK is loaded. - final injectedClientSnippet = _injectedClientSnippet( + final injectedClientSnippet = await _injectedClientSnippet( appId, devHandlerPath, entrypointPath, extensionUri, - loadStrategy, - enableDevtoolsLaunch, - emitDebugEvents, - isInternalBuild, - isFlutterApp, ); result += ''' // Injected by dwds for debugging support. @@ -207,29 +175,25 @@ String _injectClientAndHoistMain( } /// JS snippet which includes global variables required for debugging. -String _injectedClientSnippet( +Future _injectedClientSnippet( String appId, String devHandlerPath, String entrypointPath, String? extensionUri, - LoadStrategy loadStrategy, - bool enableDevtoolsLaunch, - bool emitDebugEvents, - bool isInternalBuild, - bool isFlutterApp, -) { +) async { + final isFlutterApp = await globalAppMetadata.isFlutterApp(); var injectedBody = 'window.\$dartAppId = "$appId";\n' - 'window.\$dartReloadConfiguration = "${loadStrategy.reloadConfiguration}";\n' - 'window.\$dartModuleStrategy = "${loadStrategy.id}";\n' - 'window.\$loadModuleConfig = ${loadStrategy.loadModuleSnippet};\n' + 'window.\$dartReloadConfiguration = "${globalLoadStrategy.reloadConfiguration}";\n' + 'window.\$dartModuleStrategy = "${globalLoadStrategy.id}";\n' + 'window.\$loadModuleConfig = ${globalLoadStrategy.loadModuleSnippet};\n' 'window.\$dwdsVersion = "$packageVersion";\n' 'window.\$dwdsDevHandlerPath = "$devHandlerPath";\n' - 'window.\$dwdsEnableDevtoolsLaunch = $enableDevtoolsLaunch;\n' + 'window.\$dwdsEnableDevToolsLaunch = ${globalDebugSettings.enableDevToolsLaunch};\n' 'window.\$dartEntrypointPath = "$entrypointPath";\n' - 'window.\$dartEmitDebugEvents = $emitDebugEvents;\n' - 'window.\$isInternalBuild = $isInternalBuild;\n' + 'window.\$dartEmitDebugEvents = ${globalDebugSettings.emitDebugEvents};\n' + 'window.\$isInternalBuild = ${globalAppMetadata.isInternalBuild};\n' 'window.\$isFlutterApp = $isFlutterApp;\n' - '${loadStrategy.loadClientSnippet(_clientScript)}'; + '${globalLoadStrategy.loadClientSnippet(_clientScript)}'; if (extensionUri != null) { injectedBody += 'window.\$dartExtensionUri = "$extensionUri";\n'; } diff --git a/dwds/lib/src/readers/asset_reader.dart b/dwds/lib/src/readers/asset_reader.dart index 896eb527e..a6a6fa21e 100644 --- a/dwds/lib/src/readers/asset_reader.dart +++ b/dwds/lib/src/readers/asset_reader.dart @@ -7,8 +7,6 @@ import 'package:file/file.dart'; import 'package:logging/logging.dart'; import 'package:package_config/package_config.dart'; -typedef UrlEncoder = Future Function(String url); - /// A reader for Dart sources and related source maps. abstract class AssetReader { /// Base path of the application, for example, set up in the index file: diff --git a/dwds/lib/src/servers/devtools.dart b/dwds/lib/src/servers/devtools.dart index e1deb70e7..579957dff 100644 --- a/dwds/lib/src/servers/devtools.dart +++ b/dwds/lib/src/servers/devtools.dart @@ -4,8 +4,6 @@ import 'dart:io'; -typedef DevtoolsLauncher = Future Function(String hostname); - /// A server for Dart Devtools. class DevTools { final String hostname; diff --git a/dwds/lib/src/services/debug_service.dart b/dwds/lib/src/services/debug_service.dart index 5976e7e22..740e9ae3b 100644 --- a/dwds/lib/src/services/debug_service.dart +++ b/dwds/lib/src/services/debug_service.dart @@ -9,6 +9,7 @@ import 'dart:math'; import 'dart:typed_data'; import 'package:dds/dds.dart'; +import 'package:dwds/src/config/debug_settings.dart'; import 'package:dwds/src/connections/app_connection.dart'; import 'package:dwds/src/debugging/execution_context.dart'; import 'package:dwds/src/debugging/remote_debugger.dart'; diff --git a/dwds/lib/src/utilities/dart_uri.dart b/dwds/lib/src/utilities/dart_uri.dart index 5cdb44f43..d2ab99d1c 100644 --- a/dwds/lib/src/utilities/dart_uri.dart +++ b/dwds/lib/src/utilities/dart_uri.dart @@ -144,7 +144,7 @@ class DartUri { if (packageUri != null) return packageUri; // If this is an internal app, then the given uri might be g3-relative: - if (globalIsInternalBuild) { + if (globalAppMetadata.isInternalBuild) { // TODO(https://github.com/dart-lang/webdev/issues/2198): Verify if the // intermediary conversion to resolvedUri is causing performance issues. final resolvedUri = _g3RelativeUriToResolvedUri[uri]; @@ -185,7 +185,7 @@ class DartUri { static void recordAbsoluteUris(Iterable libraryUris) { for (var uri in libraryUris) { _recordAbsoluteUri(uri); - if (globalIsInternalBuild) { + if (globalAppMetadata.isInternalBuild) { _recordG3RelativeUri(uri); } } diff --git a/dwds/lib/src/utilities/globals.dart b/dwds/lib/src/utilities/globals.dart index d8881dfd2..6e81d1716 100644 --- a/dwds/lib/src/utilities/globals.dart +++ b/dwds/lib/src/utilities/globals.dart @@ -2,6 +2,8 @@ // 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. +import 'package:dwds/src/config/app_metadata.dart'; +import 'package:dwds/src/config/debug_settings.dart'; import 'package:dwds/src/loaders/strategy.dart'; /// The load strategy for the connected app. @@ -9,8 +11,13 @@ late LoadStrategy _globalLoadStrategy; set globalLoadStrategy(LoadStrategy strategy) => _globalLoadStrategy = strategy; LoadStrategy get globalLoadStrategy => _globalLoadStrategy; -/// Whether or not the connected app is an internal (e.g. google3) app. -bool get globalIsInternalBuild => _isInternalBuild ?? false; -bool? _isInternalBuild; -set globalIsInternalBuild(bool isInternalBuild) => - _isInternalBuild = isInternalBuild; +/// The debug settings for the connected app. +late DebugSettings _globalDebugSettings; +set globalDebugSettings(DebugSettings settings) => + _globalDebugSettings = settings; +DebugSettings get globalDebugSettings => _globalDebugSettings; + +/// Metadata for the connected app. +late AppMetadata _globalAppMetadata; +set globalAppMetadata(AppMetadata metadata) => _globalAppMetadata = metadata; +AppMetadata get globalAppMetadata => _globalAppMetadata; diff --git a/dwds/test/dart_uri_test.dart b/dwds/test/dart_uri_test.dart index 55978ba3b..eb645d44c 100644 --- a/dwds/test/dart_uri_test.dart +++ b/dwds/test/dart_uri_test.dart @@ -6,6 +6,7 @@ @Timeout(Duration(minutes: 2)) import 'package:dwds/asset_reader.dart'; +import 'package:dwds/src/config/app_metadata.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:dwds/src/utilities/globals.dart'; import 'package:path/path.dart' as p; @@ -206,13 +207,13 @@ void main() { setUpAll(() async { await DartUri.initialize(); - globalIsInternalBuild = true; + globalAppMetadata = AppMetadata(isInternalBuild: false); DartUri.recordAbsoluteUris(['package:path/path.dart']); }); tearDownAll(() { DartUri.clear(); - globalIsInternalBuild = false; + globalAppMetadata = AppMetadata(isInternalBuild: false); }); test( diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index c926ca082..76e3c9ba7 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -10,6 +10,7 @@ import 'package:build_daemon/data/build_status.dart'; import 'package:build_daemon/data/build_target.dart'; import 'package:dwds/asset_reader.dart'; import 'package:dwds/expression_compiler.dart'; +import 'package:dwds/src/config/debug_settings.dart'; import 'package:dwds/src/connections/app_connection.dart'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/webkit_debugger.dart'; diff --git a/dwds/test/fixtures/server.dart b/dwds/test/fixtures/server.dart index 6396e8566..f40d28bbf 100644 --- a/dwds/test/fixtures/server.dart +++ b/dwds/test/fixtures/server.dart @@ -10,6 +10,8 @@ import 'package:dwds/asset_reader.dart'; import 'package:dwds/dart_web_debug_service.dart'; import 'package:dwds/data/build_result.dart'; import 'package:dwds/expression_compiler.dart'; +import 'package:dwds/src/config/app_metadata.dart'; +import 'package:dwds/src/config/debug_settings.dart'; import 'package:dwds/src/loaders/require.dart'; import 'package:dwds/src/servers/devtools.dart'; import 'package:dwds/src/services/expression_compiler_service.dart'; @@ -108,30 +110,34 @@ class TestServer { buildResults: filteredBuildResults, chromeConnection: chromeConnection, loadStrategy: strategy, - spawnDds: spawnDds, - enableDebugExtension: enableDebugExtension, - enableDebugging: enableDebugging, - useSseForDebugProxy: useSse, - useSseForDebugBackend: useSse, - useSseForInjectedClient: useSse, - hostname: hostname, - urlEncoder: urlEncoder, - expressionCompiler: expressionCompiler, - isInternalBuild: isInternalBuild, - isFlutterApp: () => Future.value(isFlutterApp), - devtoolsLauncher: serveDevTools - ? (hostname) async { - final server = await DevToolsServer().serveDevTools( - hostname: hostname, - enableStdinCommands: false, - customDevToolsPath: sdkLayout.devToolsDirectory, - ); - if (server == null) { - throw StateError('DevTools server could not be started.'); + debugSettings: DebugSettings( + spawnDds: spawnDds, + enableDebugExtension: enableDebugExtension, + enableDebugging: enableDebugging, + useSseForDebugProxy: useSse, + useSseForDebugBackend: useSse, + useSseForInjectedClient: useSse, + urlEncoder: urlEncoder, + expressionCompiler: expressionCompiler, + devToolsLauncher: serveDevTools + ? (hostname) async { + final server = await DevToolsServer().serveDevTools( + hostname: hostname, + enableStdinCommands: false, + customDevToolsPath: sdkLayout.devToolsDirectory, + ); + if (server == null) { + throw StateError('DevTools server could not be started.'); + } + return DevTools(server.address.host, server.port, server); } - return DevTools(server.address.host, server.port, server); - } - : null, + : null, + ), + appMetadata: AppMetadata( + hostname: hostname, + isInternalBuild: isInternalBuild, + isFlutterApp: () => Future.value(isFlutterApp), + ), ); final server = await startHttpServer('localhost', port: port); diff --git a/dwds/test/handlers/injector_test.dart b/dwds/test/handlers/injector_test.dart index 073bffa61..238c4cfcf 100644 --- a/dwds/test/handlers/injector_test.dart +++ b/dwds/test/handlers/injector_test.dart @@ -6,32 +6,24 @@ import 'dart:io'; +import 'package:dwds/src/config/debug_settings.dart'; import 'package:dwds/src/handlers/injector.dart'; +import 'package:dwds/src/utilities/globals.dart'; import 'package:dwds/src/version.dart'; import 'package:http/http.dart' as http; import 'package:shelf/shelf.dart'; import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:test/test.dart'; -import '../fixtures/fakes.dart'; - void main() { late HttpServer server; const entryEtag = 'entry etag'; const nonEntryEtag = 'some etag'; - final loadStrategy = FakeStrategy(FakeAssetReader()); group('InjectedHandlerWithoutExtension', () { late DwdsInjector injector; setUp(() async { - injector = DwdsInjector( - loadStrategy, - useSseForInjectedClient: true, - enableDevtoolsLaunch: true, - emitDebugEvents: true, - isInternalBuild: false, - isFlutterApp: () => Future.value(true), - ); + injector = DwdsInjector(); final pipeline = const Pipeline().addMiddleware(injector.middleware); server = await shelf_io.serve( pipeline.addHandler((request) { @@ -237,7 +229,7 @@ void main() { 'http://localhost:${server.port}/entrypoint$bootstrapJsExtension', ), ); - expect(result.body.contains('dwdsEnableDevtoolsLaunch'), isTrue); + expect(result.body.contains('dwdsEnableDevToolsLaunch'), isTrue); }); test('Delegates to strategy handler', () async { @@ -304,14 +296,11 @@ void main() { group('InjectedHandlerWithoutExtension using WebSockets', () { late DwdsInjector injector; setUp(() async { - injector = DwdsInjector( - loadStrategy, + globalDebugSettings = DebugSettings( + enableDebugging: true, useSseForInjectedClient: false, - enableDevtoolsLaunch: true, - emitDebugEvents: true, - isInternalBuild: false, - isFlutterApp: () => Future.value(true), ); + injector = DwdsInjector(); final pipeline = const Pipeline().addMiddleware(injector.middleware); server = await shelf_io.serve( pipeline.addHandler((request) { @@ -378,13 +367,7 @@ void main() { final extensionUri = 'http://localhost:4000'; final pipeline = const Pipeline().addMiddleware( DwdsInjector( - loadStrategy, extensionUri: Future.value(extensionUri), - useSseForInjectedClient: true, - enableDevtoolsLaunch: true, - emitDebugEvents: true, - isInternalBuild: false, - isFlutterApp: () => Future.value(true), ).middleware, ); server = await shelf_io.serve( diff --git a/dwds/web/client.dart b/dwds/web/client.dart index 740688208..51a0a251f 100644 --- a/dwds/web/client.dart +++ b/dwds/web/client.dart @@ -169,7 +169,7 @@ Future? main() { }, ); - if (dwdsEnableDevtoolsLaunch) { + if (dwdsEnableDevToolsLaunch) { window.onKeyDown.listen((Event e) { if (e is KeyboardEvent && const [ @@ -337,8 +337,8 @@ external String get reloadConfiguration; @JS(r'$dartEntrypointPath') external String get dartEntrypointPath; -@JS(r'$dwdsEnableDevtoolsLaunch') -external bool get dwdsEnableDevtoolsLaunch; +@JS(r'$dwdsEnableDevToolsLaunch') +external bool get dwdsEnableDevToolsLaunch; @JS('window.top.document.dispatchEvent') external void dispatchEvent(CustomEvent event); diff --git a/frontend_server_common/lib/src/asset_server.dart b/frontend_server_common/lib/src/asset_server.dart index 784e634f9..b63b6e05e 100644 --- a/frontend_server_common/lib/src/asset_server.dart +++ b/frontend_server_common/lib/src/asset_server.dart @@ -10,6 +10,7 @@ import 'dart:io'; import 'dart:typed_data'; import 'package:dwds/asset_reader.dart'; +import 'package:dwds/config.dart'; import 'package:file/file.dart'; import 'package:logging/logging.dart'; import 'package:mime/mime.dart' as mime; diff --git a/frontend_server_common/lib/src/devfs.dart b/frontend_server_common/lib/src/devfs.dart index c0c7f371d..64e3e4512 100644 --- a/frontend_server_common/lib/src/devfs.dart +++ b/frontend_server_common/lib/src/devfs.dart @@ -5,6 +5,7 @@ // Note: this is a copy from flutter tools, updated to work with dwds tests import 'package:dwds/asset_reader.dart'; +import 'package:dwds/config.dart'; import 'package:file/file.dart'; import 'package:path/path.dart' as p; import 'package:test_common/test_sdk_layout.dart'; diff --git a/frontend_server_common/lib/src/resident_runner.dart b/frontend_server_common/lib/src/resident_runner.dart index fdf2e6b1c..e1931fdec 100644 --- a/frontend_server_common/lib/src/resident_runner.dart +++ b/frontend_server_common/lib/src/resident_runner.dart @@ -8,6 +8,7 @@ import 'dart:async'; import 'package:dwds/asset_reader.dart'; +import 'package:dwds/config.dart'; import 'package:dwds/expression_compiler.dart'; import 'package:file/file.dart'; import 'package:logging/logging.dart'; diff --git a/webdev/lib/src/serve/webdev_server.dart b/webdev/lib/src/serve/webdev_server.dart index b4ef287a1..bd956a0c4 100644 --- a/webdev/lib/src/serve/webdev_server.dart +++ b/webdev/lib/src/serve/webdev_server.dart @@ -145,17 +145,12 @@ class WebDevServer { var shouldServeDevTools = options.configuration.debug || options.configuration.debugExtension; dwds = await Dwds.start( - hostname: options.configuration.hostname, - assetReader: assetReader, - buildResults: filteredBuildResults, - chromeConnection: () async => - (await Chrome.connectedInstance).chromeConnection, - loadStrategy: loadStrategy, + debugSettings: DebugSettings( enableDebugExtension: options.configuration.debugExtension, enableDebugging: options.configuration.debug, spawnDds: !options.configuration.disableDds, expressionCompiler: ddcService, - devtoolsLauncher: shouldServeDevTools + devToolsLauncher: shouldServeDevTools ? (String hostname) async { var server = await DevToolsServer().serveDevTools( hostname: hostname, @@ -164,7 +159,17 @@ class WebDevServer { ); return DevTools(server!.address.host, server.port, server); } - : null); + : null, + ), + appMetadata: AppMetadata( + hostname: options.configuration.hostname, + ), + assetReader: assetReader, + buildResults: filteredBuildResults, + chromeConnection: () async => + (await Chrome.connectedInstance).chromeConnection, + loadStrategy: loadStrategy, + ); pipeline = pipeline.addMiddleware(dwds.middleware); cascade = cascade.add(dwds.handler); cascade = cascade.add(assetHandler);