diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 8621e53dd..4e15311c8 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,4 +1,4 @@ -## 13.1.1-dev +## 14.0.0-dev - Add column information to breakpoints to allow precise breakpoint placement. - Split SDK validation methods to allow validation of separate components. - Remove dependency on `package:_fe_analyzer_shared`. @@ -8,6 +8,10 @@ used. - Fix crash when using flutter tools with web server device. - Remove clearing all scripts on page load for extension debugger. +- Fix breakpoints not hitting after changing a base in index.html. + +**Breaking changes:** +- Add `basePath` parameter to `FrontendServerRequireStrategy`. ## 13.1.0 - Update _fe_analyzer_shared to version ^38.0.0. diff --git a/dwds/lib/src/injected/client.js b/dwds/lib/src/injected/client.js index cc103b81f..94f9c6fd1 100644 --- a/dwds/lib/src/injected/client.js +++ b/dwds/lib/src/injected/client.js @@ -1,4 +1,4 @@ -// Generated by dart2js (NullSafetyMode.unsound, csp), the Dart to JavaScript compiler version: 2.18.0-9.0.dev. +// Generated by dart2js (NullSafetyMode.unsound, csp), the Dart to JavaScript compiler version: 2.18.0-29.0.dev. // The code supports the following hooks: // dartPrint(message): // if this function is defined it is called instead of the Dart [print] diff --git a/dwds/lib/src/loaders/frontend_server_require.dart b/dwds/lib/src/loaders/frontend_server_require.dart index ad5871cc0..b025749b3 100644 --- a/dwds/lib/src/loaders/frontend_server_require.dart +++ b/dwds/lib/src/loaders/frontend_server_require.dart @@ -14,11 +14,13 @@ class FrontendServerRequireStrategyProvider { final ReloadConfiguration _configuration; final AssetReader _assetReader; final Future> Function() _digestsProvider; + final String _basePath; RequireStrategy _requireStrategy; - FrontendServerRequireStrategyProvider( - this._configuration, this._assetReader, this._digestsProvider); + FrontendServerRequireStrategyProvider(this._configuration, this._assetReader, + this._digestsProvider, String basePath) + : _basePath = basePathForServerUri(basePath); RequireStrategy get strategy => _requireStrategy ??= RequireStrategy( _configuration, @@ -32,28 +34,35 @@ class FrontendServerRequireStrategyProvider { _assetReader, ); + String _removeBasePath(String path) => + path.startsWith(_basePath) ? path.substring(_basePath.length) : null; + + String _addBasePath(String serverPath) => p.join(_basePath, serverPath); + Future> _moduleProvider( MetadataProvider metadataProvider) async => (await metadataProvider.moduleToModulePath).map((key, value) => MapEntry(key, relativizePath(removeJsExtension(value)))); Future _moduleForServerPath( - MetadataProvider metadataProvider, String serverPath) async => - (await metadataProvider.modulePathToModule)[serverPath]; + MetadataProvider metadataProvider, String serverPath) async { + var modulePathToModule = await metadataProvider.modulePathToModule; + return modulePathToModule[_removeBasePath(serverPath)]; + } Future _serverPathForModule( MetadataProvider metadataProvider, String module) async => - (await metadataProvider.moduleToModulePath)[module] ?? ''; + _addBasePath((await metadataProvider.moduleToModulePath)[module] ?? ''); Future _sourceMapPathForModule( MetadataProvider metadataProvider, String module) async { var path = (await metadataProvider.moduleToSourceMap)[module] ?? ''; - return relativizePath(path); + return _addBasePath(relativizePath(path)); } String _serverPathForAppUri(String appUri) { if (appUri.startsWith('org-dartlang-app:')) { - return Uri.parse(appUri).path.substring(1); + return _addBasePath(Uri.parse(appUri).path.substring(1)); } return null; } diff --git a/dwds/lib/src/loaders/require.dart b/dwds/lib/src/loaders/require.dart index 56868e27d..15f134ec5 100644 --- a/dwds/lib/src/loaders/require.dart +++ b/dwds/lib/src/loaders/require.dart @@ -11,6 +11,21 @@ import 'package:shelf/shelf.dart'; import '../../dwds.dart'; +/// Find the path we are serving from the url. +/// +/// Example: +/// https://localhost/base/index.html => /base +/// https://localhost/base => /base +String basePathForServerUri(String url) { + if (url == null) return null; + var uri = Uri.parse(url); + var base = uri.path.endsWith('.html') ? p.dirname(uri.path) : uri.path; + if (base.isNotEmpty) { + base = base.startsWith('/') ? base : '/$base'; + } + return base; +} + String relativizePath(String path) => path.startsWith('/') ? path.substring(1) : path; diff --git a/dwds/lib/src/services/expression_evaluator.dart b/dwds/lib/src/services/expression_evaluator.dart index 8c1494eef..f86fd5ffe 100644 --- a/dwds/lib/src/services/expression_evaluator.dart +++ b/dwds/lib/src/services/expression_evaluator.dart @@ -179,7 +179,8 @@ class ExpressionEvaluator { 'Cannot find Dart location for JS location: ' 'url: $url, ' 'function: $functionName, ' - 'line: $jsLine'); + 'line: $jsLine, ' + 'column: $jsColumn'); } var dartLocation = locationMap.dartLocation; diff --git a/dwds/lib/src/utilities/dart_uri.dart b/dwds/lib/src/utilities/dart_uri.dart index 3cb614eb8..393a0a4dd 100644 --- a/dwds/lib/src/utilities/dart_uri.dart +++ b/dwds/lib/src/utilities/dart_uri.dart @@ -8,6 +8,7 @@ import 'package:logging/logging.dart'; import 'package:package_config/package_config.dart'; import 'package:path/path.dart' as p; +import '../loaders/require.dart'; import '../loaders/strategy.dart'; import 'sdk_configuration.dart'; @@ -36,17 +37,23 @@ class DartUri { /// 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 (serverPath != null) { + return DartUri._(serverPath); + } // TODO(annagrin): Support creating DartUris from `dart:` uris. // Issue: https://github.com/dart-lang/webdev/issues/1584 if (uri.startsWith('package:')) { return DartUri._fromPackageUri(uri, serverUri: serverUri); } - if (uri.startsWith('file:')) return DartUri._fromFileUri(uri); + if (uri.startsWith('file:')) { + return DartUri._fromFileUri(uri, serverUri: serverUri); + } if (uri.startsWith('/packages/')) { return DartUri._fromRelativePath(uri, serverUri: serverUri); } - if (uri.startsWith('/')) return DartUri._fromRelativePath(uri); + if (uri.startsWith('/')) { + return DartUri._fromRelativePath(uri); + } if (uri.startsWith('http:') || uri.startsWith('https:')) { return DartUri(Uri.parse(uri).path); } @@ -54,20 +61,24 @@ class DartUri { throw FormatException('Unsupported URI form', uri); } + @override + String toString() => 'DartUri: $serverPath'; + /// Construct from a package: URI factory DartUri._fromPackageUri(String uri, {String serverUri}) { + var basePath = basePathForServerUri(serverUri); var packagePath = 'packages/${uri.substring("package:".length)}'; if (serverUri != null) { - return DartUri._fromRelativePath( - p.url.join(_dirForServerUri(serverUri), packagePath)); + var relativePath = p.url.join(basePath, packagePath); + return DartUri._fromRelativePath(relativePath); } return DartUri._(packagePath); } /// Construct from a file: URI - factory DartUri._fromFileUri(String uri) { + factory DartUri._fromFileUri(String uri, {String serverUri}) { var libraryName = _resolvedUriToUri[uri]; - if (libraryName != null) return DartUri(libraryName); + if (libraryName != null) return DartUri(libraryName, serverUri); // This is not one of our recorded libraries. throw ArgumentError.value(uri, 'uri', 'Unknown library'); } @@ -78,8 +89,8 @@ class DartUri { uri = uri[0] == '/' ? uri.substring(1) : uri; if (serverUri != null) { - return DartUri._fromRelativePath( - p.url.join(_dirForServerUri(serverUri), uri)); + var basePath = basePathForServerUri(serverUri); + return DartUri._fromRelativePath(p.url.join(basePath, uri)); } return DartUri._(uri); } @@ -179,9 +190,6 @@ class DartUri { } } - /// Returns the dirname for the server URI. - static String _dirForServerUri(String uri) => p.dirname(Uri.parse(uri).path); - /// Load the .dart_tool/package_config.json file associated with the running /// application so we can resolve file URLs into package: URLs appropriately. static Future _loadPackageConfig(Uri uri) async { diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart index 06dc05173..8bbf0255b 100644 --- a/dwds/lib/src/version.dart +++ b/dwds/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '13.1.1-dev'; +const packageVersion = '14.0.0-dev'; diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index af8c37bdb..f313b46fc 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -1,6 +1,6 @@ name: dwds # Every time this changes you need to run `dart run build_runner build`. -version: 13.1.1-dev +version: 14.0.0-dev description: >- A service that proxies between the Chrome debug protocol and the Dart VM service protocol. diff --git a/dwds/test/build_daemon_nested_directory_breakpoint_test.dart b/dwds/test/build_daemon_nested_directory_breakpoint_test.dart deleted file mode 100644 index ec5cd7b59..000000000 --- a/dwds/test/build_daemon_nested_directory_breakpoint_test.dart +++ /dev/null @@ -1,92 +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. - -// @dart = 2.9 - -@TestOn('vm') -import 'dart:async'; - -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:test/test.dart'; -import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; - -import 'fixtures/context.dart'; - -final context = TestContext( - directory: '../fixtures/_test', - entry: '../fixtures/_test/example/hello_world/main.dart', - path: 'hello_world/index.html', - pathToServe: 'example'); - -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; - -void main() { - group('shared context with evaluation', () { - setUpAll(() async { - await context.setUp(); - }); - - tearDownAll(() async { - await context.tearDown(); - }); - - group('breakpoint', () { - VM vm; - Isolate isolate; - ScriptList scripts; - ScriptRef mainScript; - Stream stream; - - setUp(() async { - vm = await service.getVM(); - isolate = await service.getIsolate(vm.isolates.first.id); - scripts = await service.getScripts(isolate.id); - - await service.streamListen('Debug'); - stream = service.onEvent('Debug'); - - mainScript = scripts.scripts - .firstWhere((each) => each.uri.contains('main.dart')); - }); - - tearDown(() async { - await service.resume(isolate.id); - }); - - test('set breakpoint', () async { - var line = await context.findBreakpointLine( - 'printLocal', isolate.id, mainScript); - var bp = await service.addBreakpointWithScriptUri( - isolate.id, mainScript.uri, line); - - await stream.firstWhere( - (Event event) => event.kind == EventKind.kPauseBreakpoint); - - expect(bp, isNotNull); - - // Remove breakpoint so it doesn't impact other tests. - await service.removeBreakpoint(isolate.id, bp.id); - }); - - test('set breakpoint again', () async { - var line = await context.findBreakpointLine( - 'printLocal', isolate.id, mainScript); - var bp = await service.addBreakpointWithScriptUri( - isolate.id, mainScript.uri, line); - - await stream.firstWhere( - (Event event) => event.kind == EventKind.kPauseBreakpoint); - - expect(bp, isNotNull); - - // Remove breakpoint so it doesn't impact other tests. - await service.removeBreakpoint(isolate.id, bp.id); - }); - }); - }); -} diff --git a/dwds/test/dart_uri_test.dart b/dwds/test/dart_uri_test.dart index 212766b22..195434010 100644 --- a/dwds/test/dart_uri_test.dart +++ b/dwds/test/dart_uri_test.dart @@ -35,7 +35,7 @@ void main() { test('parses package : paths with root', () { var uri = DartUri( 'package:path/path.dart', 'http://localhost:8080/foo/bar/blah'); - expect(uri.serverPath, 'foo/bar/packages/path/path.dart'); + expect(uri.serverPath, 'foo/bar/blah/packages/path/path.dart'); }); test('parses org-dartlang-app paths', () { diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index b6395054a..61c38b2dd 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -270,7 +270,8 @@ class TestContext { assetHandler = webRunner.devFS.assetServer.handleRequest; requireStrategy = FrontendServerRequireStrategyProvider( - reloadConfiguration, assetReader, () async => {}).strategy; + reloadConfiguration, assetReader, () async => {}, '') + .strategy; buildResults = const Stream.empty(); }