Skip to content

Commit 7e03357

Browse files
author
Anna Gringauze
authored
Match server paths to source maps paths (#1730)
* Try repro mixed mode ddc bug * Added logging * format * Make module uris match directory structure * Use debugger module names, add tests * Cleanup * Added package_uri_mapper_tests, fixed failures in dart_uri tests * Fix location test failures * Addressed CR comments, run dart uri tests with useDebuggerModuleNames flag * Run dart_uri_file_uri test with frontend server as well
1 parent 313bcb8 commit 7e03357

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+956
-243
lines changed

dwds/CHANGELOG.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
- Migrate `package:dwds` to null safety.
1212
- Make `ChromeProxyService.getStack` wait for the debugger to perform initial
1313
resume operation. This avoids race conditions on isolate start.
14+
- Make server paths match directory structure
15+
- Allows correct relative source map paths resolution.
16+
- Add `PackageUriMapper` class to allow mapping uris to server paths.
1417
- Update the min SDK constraint to 2.18.0.
1518

1619
**Breaking changes**
1720

1821
- Remove no longer used `ExpressionCompilerService.handler`.
1922
- Remove `assetHandler` parameter from `ExpressionCompilerService` constructor.
23+
- Add `packageUriMapper` parameter to the constructor of
24+
`FrontendServerRequireStrategyProvider`.
2025

2126
## 15.0.0
2227

@@ -141,7 +146,7 @@
141146

142147
## 11.5.1
143148

144-
- Update SDK contraint to `>=2.15.0 <3.0.0`.
149+
- Update SDK constraint to `>=2.15.0 <3.0.0`.
145150

146151
## 11.5.0
147152

@@ -235,7 +240,7 @@
235240
## 11.1.2
236241

237242
- Return empty library from `ChromeProxyService.getObject` for libraries present
238-
in medatata but not loaded at runtime.
243+
in metadata but not loaded at runtime.
239244
- Log failures to load kernel during expression evaluation.
240245
- Show lowered final fields using their original dart names.
241246
- Limit simultaneous connections to asset server to prevent broken sockets.
@@ -395,7 +400,7 @@
395400

396401
## 7.0.2
397402

398-
- Depend on the latest `pacakge:sse`.
403+
- Depend on the latest `package:sse`.
399404
- Add more verbose logging around `hotRestart`, `fullReload` and entrypoint
400405
injection.
401406

@@ -432,7 +437,7 @@
432437
- Change `ExpressionCompiler` to require a new `updateDependencies` method.
433438
- Update a number of `LoadStrategy` APIs to remove heuristics and rely on the
434439
`MetadataProvider`.
435-
- No longer require a `LogWriter` and corresponding `verbose` arguement but
440+
- No longer require a `LogWriter` and corresponding `verbose` argument but
436441
instead properly use `package:logger`.
437442
- `FrontendServerRequireStrategyProvider` now requires a `digestProvider`.
438443

@@ -503,7 +508,7 @@
503508
- Change the returned errors for the unimplemented `getClassList` and
504509
`reloadSources` methods to -32601 ('method does not exist / is not
505510
available').
506-
- Do not include native JavaScipt objects on stack returned from the debugger.
511+
- Do not include native JavaScript objects on stack returned from the debugger.
507512

508513
## 3.1.0
509514

@@ -596,7 +601,7 @@
596601
- Expose `middleware` and `handler`.
597602

598603
**Breaking Change:** The `AssetHandler` will not automatically be added the DWDS
599-
handler cascade. You must now also add the `middelware` to your server's
604+
handler cascade. You must now also add the `middleware` to your server's
600605
pipeline.
601606

602607
## 0.8.5

dwds/lib/asset_reader.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
export 'src/readers/asset_reader.dart' show AssetReader, UrlEncoder;
5+
export 'src/readers/asset_reader.dart'
6+
show AssetReader, UrlEncoder, PackageUriMapper, stripLeadingSlashes;

dwds/lib/dwds.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export 'src/loaders/frontend_server_require.dart'
1717
export 'src/loaders/legacy.dart' show LegacyStrategy;
1818
export 'src/loaders/require.dart' show RequireStrategy;
1919
export 'src/loaders/strategy.dart' show LoadStrategy, ReloadConfiguration;
20-
export 'src/readers/asset_reader.dart' show AssetReader, UrlEncoder;
20+
export 'src/readers/asset_reader.dart'
21+
show AssetReader, UrlEncoder, PackageUriMapper;
2122
export 'src/readers/frontend_server_asset_reader.dart'
2223
show FrontendServerAssetReader;
2324
export 'src/readers/proxy_server_asset_reader.dart' show ProxyServerAssetReader;

dwds/lib/src/debugging/debugger.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ class Debugger extends Domain {
546546
/// Handles pause events coming from the Chrome connection.
547547
Future<void> _pauseHandler(DebuggerPausedEvent e) async {
548548
final isolate = inspector.isolate;
549-
550549
Event event;
551550
final timestamp = DateTime.now().millisecondsSinceEpoch;
552551
final jsBreakpointIds = e.hitBreakpoints ?? [];
@@ -808,8 +807,9 @@ class _Breakpoints extends Domain {
808807
throw RPCError(
809808
'addBreakpoint',
810809
102,
811-
'The VM is unable to add a breakpoint '
812-
'at the specified line or function');
810+
'The VM is unable to add a breakpoint $id '
811+
'at the specified line or function: ($scriptId:$line:$column): '
812+
' cannot find Dart location.');
813813
}
814814

815815
try {
@@ -822,8 +822,9 @@ class _Breakpoints extends Domain {
822822
throw RPCError(
823823
'addBreakpoint',
824824
102,
825-
'The VM is unable to add a breakpoint '
826-
'at the specified line or function');
825+
'The VM is unable to add a breakpoint $id '
826+
'at the specified line or function: ($scriptId:$line:$column): '
827+
'cannot set JS breakpoint at $location');
827828
}
828829
_note(jsId: jsBreakpointId, bp: dartBreakpoint);
829830
return dartBreakpoint;

dwds/lib/src/debugging/location.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:async/async.dart';
6-
import 'package:dwds/src/loaders/require.dart';
76
import 'package:logging/logging.dart';
87
import 'package:path/path.dart' as p;
98
import 'package:source_maps/parser.dart';
@@ -162,8 +161,13 @@ class Locations {
162161

163162
/// Returns all [Location] data for a provided JS server path.
164163
Future<Set<Location>> locationsForUrl(String url) async {
165-
final module = await globalLoadStrategy.moduleForServerPath(
166-
_entrypoint, Uri.parse(url).path);
164+
if (url.isEmpty) return {};
165+
166+
final dartUri = DartUri(url, _root);
167+
final serverPath = dartUri.serverPath;
168+
final module =
169+
await globalLoadStrategy.moduleForServerPath(_entrypoint, serverPath);
170+
167171
final cache = _moduleToLocations[module];
168172
if (cache != null) return cache;
169173
if (module != null) {
@@ -286,7 +290,9 @@ class Locations {
286290
await globalLoadStrategy.sourceMapPathForModule(_entrypoint, module);
287291
final sourceMapContents =
288292
await _assetReader.sourceMapContents(sourceMapPath);
289-
final scriptLocation = p.url.dirname('/${relativizePath(modulePath)}');
293+
final scriptLocation =
294+
p.url.dirname('/${stripLeadingSlashes(modulePath)}');
295+
290296
if (sourceMapContents == null) return result;
291297
// This happens to be a [SingleMapping] today in DDC.
292298
final mapping = parse(sourceMapContents);
@@ -303,6 +309,7 @@ class Locations {
303309
final relativeSegments = p.split(mapping.urls[index]);
304310
final path = p.url.normalize(
305311
p.url.joinAll([scriptLocation, ...relativeSegments]));
312+
306313
final dartUri = DartUri(path, _root);
307314
result.add(Location.from(
308315
modulePath,

dwds/lib/src/debugging/metadata/provider.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,12 @@ class MetadataProvider {
219219
}
220220

221221
void _addMetadata(ModuleMetadata metadata) {
222-
_moduleToSourceMap[metadata.name] = metadata.sourceMapUri;
223-
_modulePathToModule[metadata.moduleUri] = metadata.name;
224-
_moduleToModulePath[metadata.name] = metadata.moduleUri;
222+
final modulePath = stripLeadingSlashes(metadata.moduleUri);
223+
final sourceMapPath = stripLeadingSlashes(metadata.sourceMapUri);
224+
225+
_moduleToSourceMap[metadata.name] = sourceMapPath;
226+
_modulePathToModule[modulePath] = metadata.name;
227+
_moduleToModulePath[metadata.name] = modulePath;
225228

226229
for (var library in metadata.libraries.values) {
227230
if (library.importUri.startsWith('file:/')) {

dwds/lib/src/debugging/modules.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Modules {
7878

7979
if (scriptToModule.containsKey(library)) {
8080
final module = scriptToModule[library]!;
81+
8182
_sourceToModule[libraryServerPath] = module;
8283
_sourceToLibrary[libraryServerPath] = Uri.parse(library);
8384
_libraryToModule[library] = module;

dwds/lib/src/loaders/build_runner_require.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class BuildRunnerRequireStrategyProvider {
7575
Future<String?> _moduleForServerPath(
7676
MetadataProvider metadataProvider, String serverPath) async {
7777
final modulePathToModule = await metadataProvider.modulePathToModule;
78-
final relativePath = relativizePath(serverPath);
78+
final relativePath = stripLeadingSlashes(serverPath);
7979
for (var e in modulePathToModule.entries) {
8080
if (stripTopLevelDirectory(e.key) == relativePath) {
8181
return e.value;
@@ -97,10 +97,14 @@ class BuildRunnerRequireStrategyProvider {
9797
return stripTopLevelDirectory(path);
9898
}
9999

100-
String? _serverPathForAppUri(String appUri) {
101-
if (appUri.startsWith('org-dartlang-app:')) {
100+
String? _serverPathForAppUri(String appUrl) {
101+
final appUri = Uri.parse(appUrl);
102+
if (appUri.isScheme('org-dartlang-app')) {
102103
// We skip the root from which we are serving.
103-
return Uri.parse(appUri).pathSegments.skip(1).join('/');
104+
return appUri.pathSegments.skip(1).join('/');
105+
}
106+
if (appUri.isScheme('package')) {
107+
return '/packages/${appUri.path}';
104108
}
105109
return null;
106110
}

dwds/lib/src/loaders/frontend_server_require.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'require.dart';
1414
class FrontendServerRequireStrategyProvider {
1515
final ReloadConfiguration _configuration;
1616
final AssetReader _assetReader;
17+
final PackageUriMapper _packageUriMapper;
1718
final Future<Map<String, String>> Function() _digestsProvider;
1819
final String _basePath;
1920

@@ -29,26 +30,31 @@ class FrontendServerRequireStrategyProvider {
2930
_assetReader,
3031
);
3132

32-
FrontendServerRequireStrategyProvider(this._configuration, this._assetReader,
33-
this._digestsProvider, this._basePath);
33+
FrontendServerRequireStrategyProvider(
34+
this._configuration,
35+
this._assetReader,
36+
this._packageUriMapper,
37+
this._digestsProvider,
38+
this._basePath,
39+
);
3440

3541
RequireStrategy get strategy => _requireStrategy;
3642

3743
String _removeBasePath(String path) {
3844
if (_basePath.isEmpty) return path;
39-
// If path is a server path it might start with a '/'.
40-
final base = path.startsWith('/') ? '/$_basePath' : _basePath;
41-
return path.startsWith(base) ? path.substring(base.length) : path;
45+
46+
final stripped = stripLeadingSlashes(path);
47+
return stripLeadingSlashes(stripped.substring(_basePath.length));
4248
}
4349

4450
String _addBasePath(String serverPath) => _basePath.isEmpty
45-
? relativizePath(serverPath)
46-
: '$_basePath/${relativizePath(serverPath)}';
51+
? stripLeadingSlashes(serverPath)
52+
: '$_basePath/${stripLeadingSlashes(serverPath)}';
4753

4854
Future<Map<String, String>> _moduleProvider(
4955
MetadataProvider metadataProvider) async =>
5056
(await metadataProvider.moduleToModulePath).map((key, value) =>
51-
MapEntry(key, relativizePath(removeJsExtension(value))));
57+
MapEntry(key, stripLeadingSlashes(removeJsExtension(value))));
5258

5359
Future<String?> _moduleForServerPath(
5460
MetadataProvider metadataProvider, String serverPath) async {
@@ -65,9 +71,16 @@ class FrontendServerRequireStrategyProvider {
6571
MetadataProvider metadataProvider, String module) async =>
6672
_addBasePath((await metadataProvider.moduleToSourceMap)[module] ?? '');
6773

68-
String? _serverPathForAppUri(String appUri) {
69-
if (appUri.startsWith('org-dartlang-app:')) {
70-
return _addBasePath(Uri.parse(appUri).path);
74+
String? _serverPathForAppUri(String appUrl) {
75+
final appUri = Uri.parse(appUrl);
76+
if (appUri.isScheme('org-dartlang-app')) {
77+
return _addBasePath(appUri.path);
78+
}
79+
if (appUri.isScheme('package')) {
80+
final resolved = _packageUriMapper.packageUriToServerPath(appUri);
81+
if (resolved != null) {
82+
return resolved;
83+
}
7184
}
7285
return null;
7386
}

dwds/lib/src/loaders/require.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ String basePathForServerUri(String url) {
2323
return base = base.startsWith('/') ? base.substring(1) : base;
2424
}
2525

26-
String relativizePath(String path) =>
27-
path.startsWith('/') ? path.substring(1) : path;
28-
2926
String removeJsExtension(String path) =>
3027
path.endsWith('.js') ? p.withoutExtension(path) : path;
3128

0 commit comments

Comments
 (0)