diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index c6888bcec..33a4e9bbe 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,3 +1,10 @@ +## 3.0.0-dev + +**Breaking Changes:** +- Delegate to the `LoadStrategy` for module information: + - moduleId -> serverPath + - serverPath -> moduleId + ## 2.0.1 - Fix an issue where we would return prematurely during a `hotRestart`. diff --git a/dwds/lib/src/debugging/location.dart b/dwds/lib/src/debugging/location.dart index 4dda704db..b4f96784d 100644 --- a/dwds/lib/src/debugging/location.dart +++ b/dwds/lib/src/debugging/location.dart @@ -8,6 +8,7 @@ import 'package:path/path.dart' as p; import 'package:source_maps/parser.dart'; import 'package:source_maps/source_maps.dart'; +import '../loaders/strategy.dart'; import '../readers/asset_reader.dart'; import '../utilities/dart_uri.dart'; import 'modules.dart'; @@ -227,20 +228,13 @@ class Locations { if (_moduleToLocations[module] != null) return _moduleToLocations[module]; var result = {}; if (module?.isEmpty ?? true) return _moduleToLocations[module] = result; - var moduleExtension = await _modules.moduleExtension; - var modulePath = '$module$moduleExtension'; - if (modulePath.endsWith('dart_sdk.js') || - modulePath.endsWith('dart_sdk.ddk.js') || - // .lib.js extensions come from frontend server - modulePath.endsWith('dart_sdk.lib.js')) { + if (module.endsWith('dart_sdk')) { return result; } - - modulePath = _modules.adjustForRoot(modulePath); - var scriptLocation = p.url.dirname(modulePath); - + var modulePath = globalLoadStrategy.serverPathForModule(module); var sourceMapContents = await _assetReader.sourceMapContents('$modulePath.map'); + var scriptLocation = p.url.dirname('/$modulePath'); if (sourceMapContents == null) return result; var scriptId = await _modules.scriptIdForModule(module); if (scriptId == null) return result; @@ -259,8 +253,7 @@ class Locations { var relativeSegments = p.split(mapping.urls[index]); var path = p.url .normalize(p.url.joinAll([scriptLocation, ...relativeSegments])); - var uri = _modules.adjustForRoot(path); - var dartUri = DartUri('/$uri', _root); + var dartUri = DartUri(path, _root); result.add(Location.from( scriptId, lineEntry, diff --git a/dwds/lib/src/debugging/modules.dart b/dwds/lib/src/debugging/modules.dart index c3300d17e..c15ebccb4 100644 --- a/dwds/lib/src/debugging/modules.dart +++ b/dwds/lib/src/debugging/modules.dart @@ -4,9 +4,7 @@ import 'dart:async'; -import 'package:dwds/src/debugging/execution_context.dart'; -import 'package:path/path.dart' as p; - +import '../debugging/execution_context.dart'; import '../loaders/strategy.dart'; import '../utilities/dart_uri.dart'; import '../utilities/shared.dart'; @@ -29,16 +27,11 @@ class Modules { // The module to corresponding Chrome script ID. final _moduleToScriptId = {}; - final _moduleExtensionCompleter = Completer(); - - Modules(this._remoteDebugger, String root, this._executionContext) - : _root = root == '' ? '/' : root; - - /// Completes with the module extension i.e. `.ddc.js` or `.ddk.js`. - /// - /// We use the script parsed events from Chrome to determine this information. - // TODO(grouma) - Do something better here. - Future get moduleExtension => _moduleExtensionCompleter.future; + Modules( + this._remoteDebugger, + String root, + this._executionContext, + ) : _root = root == '' ? '/' : root; /// Initializes the mapping from source to module. /// @@ -82,88 +75,18 @@ class Modules { /// Checks if the [url] correspond to a module and stores meta data. Future noteModule(String url, String scriptId) async { var path = Uri.parse(url).path; - if (path == null || - !(path.endsWith('.ddc.js') || - path.endsWith('.ddk.js') || - path.endsWith('.lib.js'))) { - return; - } - - // TODO(grouma) - This is wonky. Find a better way. - if (!_moduleExtensionCompleter.isCompleted) { - if (path.endsWith('.ddc.js')) { - _moduleExtensionCompleter.complete('.ddc.js'); - } else if (path.endsWith('.ddk.js')) { - _moduleExtensionCompleter.complete('.ddk.js'); - } else { - _moduleExtensionCompleter.complete('.lib.js'); - } - } - - // TODO(annagrin): redirect modulePath->moduleName query to load strategy - // - // The code below is trying to guess the module name from js module path - // by assuming we can find a dart server path with a matching name located - // at the same server directory. Then it uses source->moduleName map to get - // the module name. - // [issue #917](https://github.com/dart-lang/webdev/issues/917) - // [issue #910](https://github.com/dart-lang/webdev/issues/910) - var serverPath = _jsModulePathToServerPath(path); - var module = await moduleForSource(serverPath); - + if (path == null) return; + var module = globalLoadStrategy.moduleForServerPath(path); + if (module == null) return; _scriptIdToModule[scriptId] = module; _moduleToScriptId[module] = scriptId; } - String _jsModulePathToServerPath(String path) { - // remove extensions, such as '.ddc.js' - var serverPath = p.withoutExtension(p.withoutExtension(path)); - // server path does not contain leading '/' - serverPath = - serverPath.startsWith('/') ? serverPath.substring(1) : serverPath; - // server path has '.dart' extension - serverPath = serverPath.endsWith('.dart') ? serverPath : '$serverPath.dart'; - // server path should be relative to the asset server root - serverPath = adjustForRoot(serverPath); - return DartUri('/$serverPath', _root).serverPath; - } - - /// Make path relative to the asset server's serving root. - /// - /// Remove the asset server root directory for non-package files, if any, - /// but do not remove the _root, which is the directory off the - /// asset server root. This is needed to produce paths that will be used - /// in requests to the asset server, such as dart script paths, dart - /// locations, or source map paths. Asset server is serving from the asset - /// server root directory, so it expects the requests to be relative to it. - // Note: This is a temporary workaround until we solve inconsistencies in - // different configurations by introducing module name and path translation - // interfaces between compiler, asset server, and the debugger. - // TODO(annagrin): module interface - // [issue #910](https://github.com/dart-lang/webdev/issues/910) - String adjustForRoot(String path) { - // path == 'dir/main.dart' => pathRoot == 'dir' - // path == 'main.dart' => pathRoot == '.' - var segments = p.split(path); - var pathRoot = p.split(p.dirname(path))[0]; - - // _root == 'http:/localhost:port/dir/index.html' => indexRoot == 'dir' - // _root == 'http:/localhost:port/index.html' => indexRoot == '.' - var indexPath = Uri.parse(_root).path.substring(1); - var indexRoot = p.split(p.dirname(indexPath))[0]; - - // remove the root from path only if not equal to packages or indexRoot - var result = pathRoot == 'packages' || pathRoot == indexRoot - // Module paths are consistent across platforms so join with a - // forward slash. - ? p.url.joinAll(segments) - : p.url.joinAll(segments.skip(1)); - return result; - } - /// Initializes [_sourceToModule]. Future _initializeMapping() async { if (_moduleCompleter.isCompleted) return; + // TODO(grouma) - We should talk to the compiler directly to greatly + // improve the performance here. var expression = ''' (function() { var dart = ${globalLoadStrategy.loadModuleSnippet}('dart_sdk').dart; @@ -188,51 +111,9 @@ class Modules { for (var dartScript in value.keys) { if (!dartScript.endsWith('.dart')) continue; var serverPath = DartUri(dartScript, _root).serverPath; - - // get module name from module Uri - // Note: This is a temporary workaround until we solve inconsistencies - // in different configurations by introducing module name and path - // translation interfaces between compiler, asset server, and the - // debugger. - // TODO(annagrin): module interface - // [issue #910](https://github.com/dart-lang/webdev/issues/910) - var moduleUri = Uri.parse(value[dartScript] as String); - var module = _moduleFor(moduleUri.path); - _sourceToModule[serverPath] = module; + _sourceToModule[serverPath] = value[dartScript] as String; _sourceToLibrary[serverPath] = Uri.parse(dartScript); } _moduleCompleter.complete(); } - - /// Returns the module for the provided path. - /// - /// Module are of the following form: - /// - /// packages/foo/bar/module - /// some/root/bar/module - /// - String _moduleFor(String path, {bool skipRoot}) { - path = '/$path'; - skipRoot ??= false; - var result = ''; - if (path.contains('/packages/')) { - result = 'packages/${path.split('/packages/').last}'; - } else if (path.contains('/lib/')) { - var splitModule = path.split('/lib/').first.substring(1).split('/'); - // Special case third_party/dart for Google3. - if (path.startsWith('/third_party/dart/')) { - splitModule = splitModule.skip(2).toList(); - } - result = 'packages/${splitModule.join(".")}/${p.basename(path)}'; - } else if (path.contains('/google3/')) { - result = path.split('/google3/').last; - } else if (path.startsWith('/')) { - path = path.substring(1); - if (skipRoot) { - path = path.split('/').skip(1).join('/'); - } - result = path; - } - return result; - } } diff --git a/dwds/lib/src/dwds_vm_client.dart b/dwds/lib/src/dwds_vm_client.dart index e7de2261e..d1ea7b9a5 100644 --- a/dwds/lib/src/dwds_vm_client.dart +++ b/dwds/lib/src/dwds_vm_client.dart @@ -78,7 +78,7 @@ class DwdsVmClient { } } // Only return success after the isolate has fully started. - var stream = client.onEvent('Isolate'); + var stream = chromeProxyService.onEvent('Isolate'); await stream.firstWhere((event) => event.kind == EventKind.kIsolateStart); return {'result': Success().toJson()}; }); diff --git a/dwds/lib/src/loaders/build_runner_require.dart b/dwds/lib/src/loaders/build_runner_require.dart index 9c5bf2db4..1493a8b9c 100644 --- a/dwds/lib/src/loaders/build_runner_require.dart +++ b/dwds/lib/src/loaders/build_runner_require.dart @@ -5,6 +5,7 @@ import 'dart:convert'; import 'dart:io'; +import 'package:path/path.dart' as p; import 'package:shelf/shelf.dart'; import 'require.dart'; @@ -12,15 +13,24 @@ import 'strategy.dart'; /// Provides a [RequireStrategy] suitable for use with `package:build_runner`. class BuildRunnerRequireStrategyProvider { + final _extension = '.ddc'; final Handler _assetHandler; final ReloadConfiguration _configuration; + final _serverPathToModule = {}; RequireStrategy _requireStrategy; BuildRunnerRequireStrategyProvider(this._assetHandler, this._configuration); RequireStrategy get strategy => _requireStrategy ??= RequireStrategy( - _configuration, '.ddc', _moduleProvider, _digestsProvider); + _configuration, + _extension, + _moduleProvider, + _digestsProvider, + _moduleForServerPath, + _serverPathForModule, + _serverPathForAppUri, + ); Future> _digestsProvider(String entrypoint) async { var digestsPath = entrypoint.replaceAll('.dart.bootstrap.js', '.digests'); @@ -50,8 +60,32 @@ class BuildRunnerRequireStrategyProvider { Future> _moduleProvider(String entrypoint) async { var digests = await _digestsProvider(entrypoint); - return { - for (var moduleId in digests.keys) moduleId: _serverPath(moduleId), - }; + var result = {}; + _serverPathToModule.clear(); + for (var moduleId in digests.keys) { + var serverPath = _serverPath(moduleId); + _serverPathToModule[serverPath] = moduleId; + result[moduleId] = serverPath; + } + return result; + } + + String _moduleForServerPath(String serverPath) { + if (!serverPath.endsWith('$_extension.js')) return null; + serverPath = + serverPath.startsWith('/') ? serverPath.substring(1) : serverPath; + // Remove the .js from the path. + serverPath = p.withoutExtension(serverPath); + return _serverPathToModule[serverPath]; + } + + String _serverPathForModule(String module) => '${_serverPath(module)}.js'; + + String _serverPathForAppUri(String appUri) { + if (appUri.startsWith('org-dartlang-app:')) { + // We skip the root from which we are serving. + return Uri.parse(appUri).pathSegments.skip(1).join('/'); + } + return null; } } diff --git a/dwds/lib/src/loaders/frontend_server_require.dart b/dwds/lib/src/loaders/frontend_server_require.dart index e5bfcd6b9..40646c35b 100644 --- a/dwds/lib/src/loaders/frontend_server_require.dart +++ b/dwds/lib/src/loaders/frontend_server_require.dart @@ -8,32 +8,29 @@ import 'package:dwds/dwds.dart'; class FrontendServerRequireStrategyProvider { final ReloadConfiguration _configuration; final Iterable _modules; + final _extension = '.lib.js'; RequireStrategy _requireStrategy; FrontendServerRequireStrategyProvider(this._modules, this._configuration); RequireStrategy get strategy => _requireStrategy ??= RequireStrategy( - _configuration, '.lib.js', _moduleProvider, _digestsProvider); + _configuration, + _extension, + _moduleProvider, + _digestsProvider, + _moduleForServerPath, + _serverPathForModule, + _serverPathForAppUri, + ); Future> _digestsProvider(String entrypoint) async { + // TODO(grouma) - provide actual digests. return {}; } Future> _moduleProvider(String entrypoint) async { final modulePaths = {}; for (var module in _modules) { - // We are currently 'guessing' module names from js module paths, - // which is not reliable. - // example: - // module: /web/main.dart.lib.js' - // name: web/main.dart - // path: web/main.dart.lib - // Note: This is a temporary workaround until we solve inconsistencies - // in different configurations by introducing module name and path - // translation interfaces between compiler, asset server, and the - // debugger. - // TODO(annagrin): module interface - // [issue #910](https://github.com/dart-lang/webdev/issues/910) module = module.startsWith('/') ? module.substring(1) : module; var name = module.replaceAll('.lib.js', ''); var path = module.replaceAll('.js', ''); @@ -41,4 +38,22 @@ class FrontendServerRequireStrategyProvider { } return modulePaths; } + + String _moduleForServerPath(String serverPath) { + if (serverPath.endsWith('.lib.js')) { + serverPath = + serverPath.startsWith('/') ? serverPath.substring(1) : serverPath; + return serverPath.replaceAll('.lib.js', ''); + } + return null; + } + + String _serverPathForModule(String module) => '$module.lib.js'; + + String _serverPathForAppUri(String appUri) { + if (appUri.startsWith('org-dartlang-app:')) { + return Uri.parse(appUri).path.substring(1); + } + return null; + } } diff --git a/dwds/lib/src/loaders/legacy.dart b/dwds/lib/src/loaders/legacy.dart index 4ce0802f2..6831cea21 100644 --- a/dwds/lib/src/loaders/legacy.dart +++ b/dwds/lib/src/loaders/legacy.dart @@ -11,7 +11,38 @@ class LegacyStrategy extends LoadStrategy { @override final ReloadConfiguration reloadConfiguration; - LegacyStrategy(this.reloadConfiguration); + /// Returns the module for the corresponding server path. + /// + /// For example: + /// + /// /packages/path/path.ddc.js -> packages/path/path + /// + final String Function(String sourcePath) _moduleForServerPath; + + /// Returns the server path for the provided module. + /// + /// For example: + /// + /// web/main -> main.ddc.js + /// + final String Function(String module) _serverPathForModule; + + /// Returns the server path for the app uri. + /// + /// For example: + /// + /// org-dartlang-app://web/main.dart -> main.dart + /// + /// Will return `null` if the provided uri is not + /// an app URI. + final String Function(String appUri) _serverPathForAppUri; + + LegacyStrategy( + this.reloadConfiguration, + this._moduleForServerPath, + this._serverPathForModule, + this._serverPathForAppUri, + ); @override Handler get handler => (request) => null; @@ -35,4 +66,14 @@ class LegacyStrategy extends LoadStrategy { @override String loadClientSnippet(String clientScript) => 'window.\$dartLoader.forceLoadModule("$clientScript");\n'; + + @override + String moduleForServerPath(String serverPath) => + _moduleForServerPath(serverPath); + + @override + String serverPathForModule(String module) => _serverPathForModule(module); + + @override + String serverPathForAppUri(String appUri) => _serverPathForAppUri(appUri); } diff --git a/dwds/lib/src/loaders/require.dart b/dwds/lib/src/loaders/require.dart index d10fe2289..806ba02f2 100644 --- a/dwds/lib/src/loaders/require.dart +++ b/dwds/lib/src/loaders/require.dart @@ -39,7 +39,7 @@ class RequireStrategy extends LoadStrategy { @override final ReloadConfiguration reloadConfiguration; - /// The module extension, e.g. `.ddc`. + /// The module extension without .js, e.g. `.ddc`. final String _moduleExtension; final String _requireDigestsPath = r'$requireDigestsPath'; @@ -64,11 +64,40 @@ class RequireStrategy extends LoadStrategy { final Future> Function(String entrypoint) _digestsProvider; + /// Returns the module for the corresponding server path. + /// + /// For example: + /// + /// /packages/path/path.ddc.js -> packages/path/path + /// + final String Function(String sourcePath) _moduleForServerPath; + + /// Returns the server path for the provided module. + /// + /// For example: + /// + /// web/main -> main.ddc.js + /// + final String Function(String module) _serverPathForModule; + + /// Returns the server path for the app uri. + /// + /// For example: + /// + /// org-dartlang-app://web/main.dart -> main.dart + /// + /// Will return `null` if the provided uri is not + /// an app URI. + final String Function(String appUri) _serverPathForAppUri; + RequireStrategy( this.reloadConfiguration, this._moduleExtension, this._moduleProvider, this._digestsProvider, + this._moduleForServerPath, + this._serverPathForModule, + this._serverPathForAppUri, ); @override @@ -183,4 +212,14 @@ if(!window.\$requireLoader) { } '''; } + + @override + String moduleForServerPath(String serverPath) => + _moduleForServerPath(serverPath); + + @override + String serverPathForModule(String module) => _serverPathForModule(module); + + @override + String serverPathForAppUri(String appUri) => _serverPathForAppUri(appUri); } diff --git a/dwds/lib/src/loaders/strategy.dart b/dwds/lib/src/loaders/strategy.dart index c9b66ad46..312cbb9f9 100644 --- a/dwds/lib/src/loaders/strategy.dart +++ b/dwds/lib/src/loaders/strategy.dart @@ -63,6 +63,32 @@ abstract class LoadStrategy { /// JS code snippet for loading the injected client script. String loadClientSnippet(String clientScript); + + /// Returns the module for the corresponding server path. + /// + /// For example: + /// + /// /packages/path/path.ddc.js -> packages/path/path + /// + String moduleForServerPath(String serverPath); + + /// Returns the server path for the provided module. + /// + /// For example: + /// + /// web/main -> main.ddc.js + /// + String serverPathForModule(String module); + + /// Returns the server path for the app uri. + /// + /// For example: + /// + /// org-dartlang-app://web/main.dart -> main.dart + /// + /// Will return `null` if the provided uri is not + /// an app URI. + String serverPathForAppUri(String appUri); } enum ReloadConfiguration { none, hotReload, hotRestart, liveReload } diff --git a/dwds/lib/src/utilities/dart_uri.dart b/dwds/lib/src/utilities/dart_uri.dart index b93805eab..24196ddf5 100644 --- a/dwds/lib/src/utilities/dart_uri.dart +++ b/dwds/lib/src/utilities/dart_uri.dart @@ -7,6 +7,8 @@ import 'dart:io'; import 'package:package_resolver/package_resolver.dart'; import 'package:path/path.dart' as p; +import '../loaders/strategy.dart'; + /// The URI for a particular Dart file, able to canonicalize from various /// different representations. class DartUri { @@ -104,11 +106,11 @@ class DartUri { /// packages/path/src/path.dart. The optional [serverUri] is the full URI of the /// JS script. The dirname of that path should give us the missing prefix. factory DartUri(String uri, [String serverUri]) { + var serverPath = globalLoadStrategy.serverPathForAppUri(uri); + if (serverPath != null) return DartUri._(serverPath); if (uri.startsWith('package:')) { return DartUri._fromPackageUri(uri, serverUri: serverUri); } - if (uri.startsWith('org-dartlang-app:')) return DartUri._fromAppUri(uri); - if (uri.startsWith('google3:')) return DartUri._fromGoogleUri(uri); if (uri.startsWith('file:')) return DartUri._fromFileUri(uri); if (uri.startsWith('/packages/')) { return DartUri._fromRelativePath(uri, serverUri: serverUri); @@ -142,19 +144,6 @@ class DartUri { throw ArgumentError.value(uri, 'uri', 'Unknown library'); } - /// Construct from an google3: URI. - factory DartUri._fromGoogleUri(String uri) { - return DartUri._(Uri.parse(uri).path.substring(1)); - } - - /// Construct from an org-dartlang-app: URI. - factory DartUri._fromAppUri(String uri) { - // We ignore the first segment of the path, which is the root - // from which we're serving. - var path = Uri.parse(uri).pathSegments.skip(1).join('/').toString(); - return DartUri._(path); - } - DartUri._(this.serverPath); /// Construct from a path, relative to the directory being served. diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart index 6884ff883..5dce1c231 100644 --- a/dwds/lib/src/version.dart +++ b/dwds/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '2.0.1'; +const packageVersion = '3.0.0-dev'; diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index 818e47806..0396a0038 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -1,5 +1,5 @@ name: dwds -version: 2.0.1 +version: 3.0.0-dev homepage: https://github.com/dart-lang/webdev/tree/master/dwds description: >- A service that proxies between the Chrome debug protocol and the Dart VM diff --git a/dwds/test/dart_uri_test.dart b/dwds/test/dart_uri_test.dart index b16c150d2..075d52a13 100644 --- a/dwds/test/dart_uri_test.dart +++ b/dwds/test/dart_uri_test.dart @@ -2,11 +2,23 @@ // 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/loaders/strategy.dart'; @TestOn('vm') import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:test/test.dart'; +import 'handlers/injected_handler_test.dart'; + +class TestStrategy extends FakeStrategy { + @override + String serverPathForAppUri(String appUri) { + if (appUri.startsWith('org-dartlang-app:')) return 'foo'; + return null; + } +} + void main() { + globalLoadStrategy = TestStrategy(); group('DartUri', () { test('parses package : paths', () { var uri = DartUri('package:path/path.dart'); @@ -21,7 +33,7 @@ void main() { test('parses org-dartlang-app paths', () { var uri = DartUri('org-dartlang-app:////blah/main.dart'); - expect(uri.serverPath, 'blah/main.dart'); + expect(uri.serverPath, 'foo'); }); test('parses packages paths', () { @@ -33,10 +45,5 @@ void main() { var uri = DartUri('http://localhost:8080/web/main.dart'); expect(uri.serverPath, 'web/main.dart'); }); - - test('parses google3 paths', () { - var uri = DartUri('google3:///some/path/foo.dart'); - expect(uri.serverPath, 'some/path/foo.dart'); - }); }); } diff --git a/dwds/test/debugging/modules_test.dart b/dwds/test/debugging/modules_test.dart deleted file mode 100644 index f75d6318d..000000000 --- a/dwds/test/debugging/modules_test.dart +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2019, 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/debugging/modules.dart'; - -import 'package:test/test.dart'; - -import '../fixtures/fakes.dart'; - -void main() { - group('noteModule', () { - var webkitDebugger = FakeWebkitDebugger(); - var executionContext = FakeExecutionContext(); - - test('handles Google3 URLs', () async { - var modules = Modules(webkitDebugger, '', executionContext)..initialize(); - await modules.noteModule('foo/google3/bar/blah.ddc.js', '10'); - expect(await modules.scriptIdForModule('bar/blah'), equals('10')); - }, skip: '[issue #917](https://github.com/dart-lang/webdev/issues/917)'); - - test('ignores non-module paths', () async { - var modules = Modules(webkitDebugger, '', executionContext)..initialize(); - await modules.noteModule('foo/bar', '10'); - expect(await modules.scriptIdForModule('foo/bar'), isNull); - }); - - test('rewrites third_party Google3 paths', () async { - var modules = Modules(webkitDebugger, '', executionContext)..initialize(); - await modules.noteModule('/third_party/dart/test/lib/test.ddc.js', '10'); - expect( - await modules.scriptIdForModule('packages/test/test'), equals('10')); - }, skip: '[issue #917](https://github.com/dart-lang/webdev/issues/917)'); - - test('handles package paths', () async { - var modules = Modules(webkitDebugger, '', executionContext)..initialize(); - await modules.noteModule('/packages/shelf/shelf.ddc.js', '10'); - expect(await modules.scriptIdForModule('packages/shelf/shelf'), - equals('10')); - }); - - test('handles absolute paths', () async { - var modules = Modules(webkitDebugger, '', executionContext)..initialize(); - await modules.noteModule('/foo/bar.ddc.js', '10'); - expect(await modules.scriptIdForModule('foo/bar'), equals('10')); - }, skip: '[issue #917](https://github.com/dart-lang/webdev/issues/917)'); - }); -} diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 01c0f139b..b93786760 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -11,10 +11,10 @@ import 'package:build_daemon/data/build_status.dart'; import 'package:build_daemon/data/build_target.dart'; import 'package:dwds/dwds.dart'; import 'package:dwds/src/debugging/webkit_debugger.dart'; +import 'package:dwds/src/loaders/frontend_server_require.dart'; import 'package:dwds/src/services/expression_compiler.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:dwds/src/utilities/shared.dart'; -import 'package:dwds/src/loaders/frontend_server_require.dart'; import 'package:frontend_server_common/src/resident_runner.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as p; diff --git a/dwds/test/fixtures/fakes.dart b/dwds/test/fixtures/fakes.dart index b97ff76e4..0cd989e56 100644 --- a/dwds/test/fixtures/fakes.dart +++ b/dwds/test/fixtures/fakes.dart @@ -133,7 +133,14 @@ class FakeWebkitDebugger implements WebkitDebugger { FakeWebkitDebugger() { globalLoadStrategy = RequireStrategy( - ReloadConfiguration.none, '.ddc', (_) async => {}, (_) async => {}); + ReloadConfiguration.none, + '.ddc', + (_) async => {}, + (_) async => {}, + (_) => null, + (_) => null, + (_) => null, + ); } @override @@ -193,7 +200,7 @@ class FakeWebkitDebugger implements WebkitDebugger { 'value': { // dart source Uri : js module name 'dart:io': 'dart_sdk', - 'google3:///dart/tools/iblaze/web/hello_world.dart': + 'org-dartlang-app:///dart/tools/iblaze/web/hello_world.dart': 'dart/tools/iblaze/web/hello_world_angular_library', 'package:ads.acx2.rpc.proto_mixin/ess_proto_mixin.dart': 'ads/acx2/rpc/proto_mixin/lib/proto_mixin', diff --git a/dwds/test/handlers/injected_handler_test.dart b/dwds/test/handlers/injected_handler_test.dart index 72f173cf6..f819fe2d3 100644 --- a/dwds/test/handlers/injected_handler_test.dart +++ b/dwds/test/handlers/injected_handler_test.dart @@ -39,6 +39,15 @@ class FakeStrategy implements LoadStrategy { @override String loadClientSnippet(String clientScript) => 'dummy-load-client-snippet'; + + @override + String moduleForServerPath(String serverPath) => null; + + @override + String serverPathForModule(String module) => null; + + @override + String serverPathForAppUri(String appUri) => null; } void main() { diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index 6fa279dbb..e988301d2 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -150,10 +150,7 @@ void main() { .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); await context.changeInput(); - await client.streamListen('Isolate'); - stream = client.onEvent('Isolate'); await client.callServiceExtension('hotRestart'); - await stream.firstWhere((event) => event.kind == EventKind.kIsolateStart); var source = await context.webDriver.pageSource; // Main is re-invoked which shouldn't clear the state. diff --git a/frontend_server_common/lib/src/asset_server.dart b/frontend_server_common/lib/src/asset_server.dart index 5fab1cca1..7b0b98d66 100644 --- a/frontend_server_common/lib/src/asset_server.dart +++ b/frontend_server_common/lib/src/asset_server.dart @@ -11,15 +11,13 @@ import 'dart:typed_data'; import 'package:dwds/dwds.dart'; import 'package:file/file.dart'; +import 'package:logging/logging.dart'; import 'package:mime/mime.dart' as mime; -// ignore: deprecated_member_use -import 'package:package_config/discovery.dart'; -// ignore: deprecated_member_use -import 'package:package_config/packages.dart'; +import 'package:package_config/discovery.dart'; // ignore: deprecated_member_use +import 'package:package_config/packages.dart'; // ignore: deprecated_member_use import 'package:path/path.dart' as p; import 'package:shelf/shelf.dart' as shelf; import 'package:shelf/shelf_io.dart' as shelf; -import 'package:logging/logging.dart'; import 'utilities.dart'; @@ -105,8 +103,7 @@ class TestAssetServer implements AssetReader { } // If this is a sourcemap file, then it might be in the in-memory cache. // Attempt to lookup the file by URI. - var sourceMapPath = _resolvePath(requestPath); - if (_sourcemaps.containsKey(sourceMapPath)) { + if (_sourcemaps.containsKey(requestPath)) { final List bytes = getSourceMap(requestPath); headers[HttpHeaders.contentLengthHeader] = bytes.length.toString(); headers[HttpHeaders.contentTypeHeader] = 'application/json'; @@ -201,8 +198,6 @@ class TestAssetServer implements AssetReader { // Attempt to resolve `path` to a dart file. File _resolveDartFile(String path) { - path = _resolvePath(path); - // If this is a dart file, it must be on the local file system and is // likely coming from a source map request. The tool doesn't currently // consider the case of Dart files as assets. @@ -234,25 +229,6 @@ class TestAssetServer implements AssetReader { return dartSdkFile; } - // Mimick build_daemon by serving from the root (web) - // if the path does not belong to a package - // Note: This is a temporary workaround until we solve inconsistencies - // in different configurations by introducing module name and path - // translation interfaces between compiler, asset server, and the - // debugger. - // TODO(annagrin): module interface - // [issue #910](https://github.com/dart-lang/webdev/issues/910) - String _resolvePath(String path) { - var segments = p.split(path); - if (segments.first.isEmpty) { - segments.removeAt(0); - } - - return path = segments.first == 'packages' - ? p.joinAll(segments) - : p.joinAll([_root, ...segments]); - } - @override Future dartSourceContents(String serverPath) { var result = _resolveDartFile(serverPath); @@ -264,8 +240,7 @@ class TestAssetServer implements AssetReader { @override Future sourceMapContents(String serverPath) async { - var path = _resolvePath(serverPath); - path = '/$path'; + var path = '/$serverPath'; if (_sourcemaps.containsKey(path)) { return utf8.decode(_sourcemaps[path]); } diff --git a/frontend_server_common/lib/src/frontend_server_client.dart b/frontend_server_common/lib/src/frontend_server_client.dart index cd2182e81..7da54926c 100644 --- a/frontend_server_common/lib/src/frontend_server_client.dart +++ b/frontend_server_common/lib/src/frontend_server_client.dart @@ -9,11 +9,11 @@ import 'dart:convert'; import 'dart:io'; import 'package:dwds/dwds.dart'; -import 'package:path/path.dart' as p; +import 'package:logging/logging.dart'; import 'package:meta/meta.dart'; +import 'package:path/path.dart' as p; import 'package:pedantic/pedantic.dart'; import 'package:usage/uuid/uuid.dart'; -import 'package:logging/logging.dart'; import 'package_map.dart'; import 'utilities.dart'; diff --git a/frontend_server_common/lib/src/resident_runner.dart b/frontend_server_common/lib/src/resident_runner.dart index 979bb1e1c..fb1232807 100644 --- a/frontend_server_common/lib/src/resident_runner.dart +++ b/frontend_server_common/lib/src/resident_runner.dart @@ -16,7 +16,8 @@ import 'devfs_content.dart'; import 'frontend_server_client.dart'; import 'utilities.dart'; -final String platformDill = p.join(dartSdkPath, '..', 'ddc_sdk.dill'); +final String platformDill = + p.join(dartSdkPath, '..', 'libexec', 'lib', '_internal', 'ddc_sdk.dill'); class ResidentWebRunner { ResidentWebRunner( diff --git a/webdev/README.md b/webdev/README.md index 95c9f10a1..5bc1e2ecd 100644 --- a/webdev/README.md +++ b/webdev/README.md @@ -53,14 +53,11 @@ Usage: webdev serve [arguments] [[:]]... (loses current state) refresh: Performs a full page refresh. [restart, refresh] - --[no-]debug Enable the launching of DevTools (Alt + D / Option + D). This also enables --launch-in-chrome. - --[no-]debug-extension Enable the backend for the Dart Debug Extension. - --[no-]injected-client Whether or not to inject the client.js script in web apps. This is required for all debugging related features, but may interact @@ -73,23 +70,18 @@ Advanced: listening on. If used with launch-in-chrome Chrome will be started with the debugger listening on this port. - --hostname Specify the hostname to serve on. (defaults to "localhost") - --[no-]launch-in-chrome Automatically launches your application in Chrome with the debug port open. Use chrome-debug-port to specify a specific port to attach to an already running chrome instance instead. - --log-requests Enables logging for each request to the server. - --tls-cert-chain The file location to a TLS Certificate to create an HTTPs server. Must be used with tls-cert-key. - --tls-cert-key The file location to a TLS Key to create an HTTPs server. Must be used with tls-cert-chain. @@ -103,12 +95,10 @@ Common: A value of "NONE" indicates that no "--output" value should be passed to `build_runner`. (defaults to "NONE") - -r, --[no-]release Build with release mode defaults for builders. --[no-]build-web-compilers If a dependency on `build_web_compilers` is required to run. (defaults to on) - -v, --verbose Enables verbose logging. Run "webdev help" to see global options. @@ -128,14 +118,11 @@ Usage: webdev build [arguments] A value of "NONE" indicates that no "--output" value should be passed to `build_runner`. (defaults to "web:build") - -r, --[no-]release Build with release mode defaults for builders. (defaults to on) - --[no-]build-web-compilers If a dependency on `build_web_compilers` is required to run. (defaults to on) - -v, --verbose Enables verbose logging. Run "webdev help" to see global options.