From e732a4dc2119b257d0ce970fe9423640227f9c9a Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Thu, 9 May 2019 10:09:25 -0700 Subject: [PATCH 1/2] handle org-dartlang-app library uris --- dwds/CHANGELOG.md | 5 +++++ dwds/lib/src/chrome_proxy_service.dart | 26 ++++++++++++++++++------ dwds/pubspec.yaml | 2 +- dwds/test/chrome_proxy_service_test.dart | 3 +-- webdev/pubspec.yaml | 4 ++++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index e277380dc..ade85d735 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.3.3-dev + +- Handle `org-dartlang-app` scheme library uris and convert them to match the + dart uris that we will see in the sourcemaps. + ## 0.3.2 - Add support for `scope` in `evaluate` calls. diff --git a/dwds/lib/src/chrome_proxy_service.dart b/dwds/lib/src/chrome_proxy_service.dart index 150722208..e4377abdd 100644 --- a/dwds/lib/src/chrome_proxy_service.dart +++ b/dwds/lib/src/chrome_proxy_service.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'package:path/path.dart' as p; import 'package:pedantic/pedantic.dart'; import 'package:pub_semver/pub_semver.dart' as semver; import 'package:vm_service_lib/vm_service_lib.dart'; @@ -119,11 +120,21 @@ class ChromeProxyService implements VmServiceInterface { ..kind = EventKind.kResume ..isolate = isolateRef; - for (var library in await _getLibraryNames()) { + for (var uri in await _getLibraryUris()) { + // The `org-dartlang-app` scheme is used to reference files that are not + // under the `lib` directory (and thus can't be referenced using a + // `package` scheme). + // + // We want to make these match the uris in the source map, which are + // relative to a top level directory in the package (such as `web` or + // `test`), so we strip the scheme and skip the first path segment. + var sourceMapUri = uri.scheme == 'org-dartlang-app' + ? p.url.joinAll(uri.pathSegments.skip(1)) + : '$uri'; isolate.libraries.add(LibraryRef() - ..id = library - ..name = library - ..uri = library); + ..id = sourceMapUri + ..name = sourceMapUri + ..uri = sourceMapUri); } // TODO: Something more robust here, right now we rely on the 2nd to last @@ -803,13 +814,16 @@ function($argsString) { } /// Runs an eval on the page to compute all the library names in the app. - Future> _getLibraryNames() async { + Future> _getLibraryUris() async { var expression = "require('dart_sdk').dart.getLibraries();"; var librariesResult = await tabConnection.runtime.sendCommand( 'Runtime.evaluate', params: {'expression': expression, 'returnByValue': true}); _handleErrorIfPresent(librariesResult, evalContents: expression); - return List.from(librariesResult.result['result']['value'] as List); + return (librariesResult.result['result']['value'] as List) + .cast() + .map(Uri.parse) + .toList(); } /// Listens for chrome console events and handles the ones we care about. diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index 372eb36e7..6feb439a6 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -1,5 +1,5 @@ name: dwds -version: 0.3.2 +version: 0.3.3-dev author: Dart Team homepage: https://github.com/dart-lang/webdev/tree/master/dwds description: >- diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index e63e71162..7d0cd7d84 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -242,8 +242,7 @@ void main() { expect(result, const TypeMatcher()); var isolate = result as Isolate; expect(isolate.name, contains(context.appUrl)); - // TODO: library names change with kernel dart-lang/sdk#36736 - expect(isolate.rootLib.uri, endsWith('main.dart')); + expect(isolate.rootLib.uri, equals('hello_world/main.dart')); expect( isolate.libraries, diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index 441007300..532dafe09 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -49,5 +49,9 @@ dev_dependencies: uuid: ^2.0.0 webdriver: ^2.0.0 +dependency_overrides: + dwds: + path: ../dwds + executables: webdev: From defaacce0bf5a367c29bcb4bd171b3877668ee9e Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Thu, 9 May 2019 13:32:16 -0700 Subject: [PATCH 2/2] revert tests for the current sdk --- dwds/lib/src/chrome_proxy_service.dart | 2 +- dwds/test/chrome_proxy_service_test.dart | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dwds/lib/src/chrome_proxy_service.dart b/dwds/lib/src/chrome_proxy_service.dart index e4377abdd..bca607669 100644 --- a/dwds/lib/src/chrome_proxy_service.dart +++ b/dwds/lib/src/chrome_proxy_service.dart @@ -129,7 +129,7 @@ class ChromeProxyService implements VmServiceInterface { // relative to a top level directory in the package (such as `web` or // `test`), so we strip the scheme and skip the first path segment. var sourceMapUri = uri.scheme == 'org-dartlang-app' - ? p.url.joinAll(uri.pathSegments.skip(1)) + ? p.url.joinAll(['/'].followedBy(uri.pathSegments.skip(1))) : '$uri'; isolate.libraries.add(LibraryRef() ..id = sourceMapUri diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index 7d0cd7d84..0915e4b16 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -242,7 +242,9 @@ void main() { expect(result, const TypeMatcher()); var isolate = result as Isolate; expect(isolate.name, contains(context.appUrl)); - expect(isolate.rootLib.uri, equals('hello_world/main.dart')); + // TODO(jakemac): Update to the full expected uri `/hello_world/main.dart` + // once the next dev sdk comes out. + expect(isolate.rootLib.uri, endsWith('main.dart')); expect( isolate.libraries,