Skip to content

Fix breakpoints not hitting after changing a base in index.html. #1556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/injected/client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions dwds/lib/src/loaders/frontend_server_require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class FrontendServerRequireStrategyProvider {
final ReloadConfiguration _configuration;
final AssetReader _assetReader;
final Future<Map<String, String>> 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,
Expand All @@ -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<Map<String, String>> _moduleProvider(
MetadataProvider metadataProvider) async =>
(await metadataProvider.moduleToModulePath).map((key, value) =>
MapEntry(key, relativizePath(removeJsExtension(value))));

Future<String> _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<String> _serverPathForModule(
MetadataProvider metadataProvider, String module) async =>
(await metadataProvider.moduleToModulePath)[module] ?? '';
_addBasePath((await metadataProvider.moduleToModulePath)[module] ?? '');

Future<String> _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;
}
Expand Down
15 changes: 15 additions & 0 deletions dwds/lib/src/loaders/require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion dwds/lib/src/services/expression_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 20 additions & 12 deletions dwds/lib/src/utilities/dart_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -36,38 +37,48 @@ 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);
}

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');
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<void> _loadPackageConfig(Uri uri) async {
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dwds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
92 changes: 0 additions & 92 deletions dwds/test/build_daemon_nested_directory_breakpoint_test.dart

This file was deleted.

2 changes: 1 addition & 1 deletion dwds/test/dart_uri_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
3 changes: 2 additions & 1 deletion dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ class TestContext {
assetHandler = webRunner.devFS.assetServer.handleRequest;

requireStrategy = FrontendServerRequireStrategyProvider(
reloadConfiguration, assetReader, () async => {}).strategy;
reloadConfiguration, assetReader, () async => {}, '')
.strategy;

buildResults = const Stream<BuildResults>.empty();
}
Expand Down