Skip to content

Commit 4435a92

Browse files
committed
DWDS Feature: Daemon Expression Compiler & FES Support
1 parent 84c2ac8 commit 4435a92

46 files changed

Lines changed: 3114 additions & 1274 deletions

Some content is hidden

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

dwds/lib/asset_reader.dart

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

55
export 'src/readers/asset_reader.dart'
6-
show AssetReader, PackageUriMapper, stripLeadingSlashes;
6+
show
7+
AssetReader,
8+
BuildRunnerPathResolver,
9+
FrontendServerPathResolver,
10+
PathResolver,
11+
stripLeadingSlashes;

dwds/lib/dwds.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export 'src/debugging/metadata/provider.dart'
1818
export 'src/events.dart' show DwdsEvent;
1919
export 'src/handlers/dev_handler.dart' show AppConnectionException;
2020
export 'src/handlers/socket_connections.dart';
21+
export 'src/loaders/asset_scheme.dart'
22+
show AssetScheme, BuildRunnerAssetScheme, FrontendServerAssetScheme;
2123
export 'src/loaders/build_runner_strategy_provider.dart'
2224
show
2325
BuildRunnerDdcLibraryBundleStrategyProvider,
2426
BuildRunnerRequireStrategyProvider;
2527
export 'src/loaders/ddc.dart' show DdcStrategy;
2628
export 'src/loaders/frontend_server_strategy_provider.dart'
2729
show
30+
FrontendServerBuildDaemonStrategyProvider,
2831
FrontendServerDdcLibraryBundleStrategyProvider,
2932
FrontendServerDdcStrategyProvider,
3033
FrontendServerRequireStrategyProvider;
@@ -35,13 +38,21 @@ export 'src/loaders/strategy.dart'
3538
LoadStrategy,
3639
ReloadConfiguration,
3740
ReloadableLoadStrategy;
38-
export 'src/readers/asset_reader.dart' show AssetReader, PackageUriMapper;
41+
export 'src/readers/asset_reader.dart'
42+
show
43+
AssetReader,
44+
BuildRunnerPathResolver,
45+
FlutterPathResolver,
46+
FrontendServerPathResolver,
47+
PathResolver;
3948
export 'src/readers/frontend_server_asset_reader.dart'
4049
show FrontendServerAssetReader;
4150
export 'src/readers/proxy_server_asset_reader.dart' show ProxyServerAssetReader;
4251
export 'src/servers/devtools.dart';
4352
export 'src/services/chrome/chrome_debug_exception.dart'
4453
show ChromeDebugException;
54+
export 'src/services/daemon_expression_compiler.dart'
55+
show DaemonExpressionCompiler;
4556
export 'src/services/expression_compiler.dart'
4657
show
4758
CompilerOptions,

dwds/lib/src/debugging/location.dart

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:dwds/src/debugging/metadata/provider.dart';
88
import 'package:dwds/src/debugging/modules.dart';
99
import 'package:dwds/src/readers/asset_reader.dart';
1010
import 'package:dwds/src/utilities/dart_uri.dart';
11+
import 'package:dwds/src/utilities/web_path_translator.dart';
1112
import 'package:logging/logging.dart';
1213
import 'package:path/path.dart' as p;
1314
import 'package:source_maps/parser.dart';
@@ -194,6 +195,8 @@ class Locations {
194195
return _sourceToLocation[serverPath] ?? {};
195196
}
196197

198+
Iterable<String> keys() => _sourceToLocation.keys;
199+
197200
/// Returns all [Location] data for a provided JS server path.
198201
Future<Set<Location>> locationsForUrl(String url) async {
199202
if (url.isEmpty) return {};
@@ -345,7 +348,13 @@ class Locations {
345348
'/${stripLeadingSlashes(modulePath)}',
346349
);
347350

348-
if (sourceMapContents == null) return result;
351+
if (sourceMapContents == null) {
352+
_logger.warning(
353+
'Failed to load source map for module $module at path '
354+
'$sourceMapPath',
355+
);
356+
return result;
357+
}
349358

350359
final runtimeScriptId = await _modules.getRuntimeScriptIdForModule(
351360
_entrypoint,
@@ -373,11 +382,9 @@ class Locations {
373382
}
374383
}
375384
for (final location in result) {
385+
final serverPath = location.dartLocation.uri.serverPath;
376386
_sourceToLocation
377-
.putIfAbsent(
378-
location.dartLocation.uri.serverPath,
379-
() => <Location>{},
380-
)
387+
.putIfAbsent(serverPath, () => <Location>{})
381388
.add(location);
382389
}
383390
return _moduleToLocations[module] = result;
@@ -395,15 +402,25 @@ class Locations {
395402
}) {
396403
final index = entry.sourceUrlId;
397404
if (index == null) return null;
398-
// Source map URLS are relative to the script. They may have platform
399-
// separators or they may use URL semantics. To be sure, we split and
400-
// re-join them.
401-
// This works on Windows because path treats both / and \ as separators.
402-
// It will fail if the path has both separators in it.
403-
final relativeSegments = p.split(sourceUrls[index]);
404-
final path = p.url.normalize(
405-
p.url.joinAll([scriptLocation, ...relativeSegments]),
406-
);
405+
final sourceUrl = sourceUrls[index];
406+
String path;
407+
if (Uri.tryParse(sourceUrl)?.isAbsolute == true) {
408+
path = sourceUrl;
409+
} else {
410+
// TODO(markzipan): Check if platform-specific separators can be handled
411+
// upstream in the SDK.
412+
// Source map URLS are relative to the script. They may have platform
413+
// separators or they may use URL semantics. To be sure, we split and
414+
// re-join them.
415+
// This works on Windows because path treats both / and \ as separators.
416+
// It will fail if the path has both separators in it.
417+
final relativeSegments = p.split(sourceUrl);
418+
path = p.url.normalize(
419+
p.url.joinAll([scriptLocation, ...relativeSegments]),
420+
);
421+
422+
path = WebPathTranslator.reconstructAppScheme(path, scriptLocation);
423+
}
407424

408425
try {
409426
final dartUri = DartUri(path, _root);

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4-
54
import 'dart:convert';
65

76
import 'package:async/async.dart';
@@ -13,7 +12,6 @@ import 'package:path/path.dart' as p;
1312
/// A provider of metadata in which data is collected through DDC outputs.
1413
class MetadataProvider {
1514
final AssetReader _assetReader;
16-
final _logger = Logger('MetadataProvider');
1715
final String entrypoint;
1816
final Set<String> _libraries = {};
1917
final Map<String, String> _scriptToModule = {};
@@ -165,13 +163,15 @@ class MetadataProvider {
165163
/// return a map from module names to their [ModuleMetadata].
166164
Future<Map<String, ModuleMetadata>> _processMetadata() async {
167165
final modules = <String, ModuleMetadata>{};
168-
// The merged metadata resides next to the entrypoint.
169-
// Assume that <name>.bootstrap.js has <name>.ddc_merged_metadata
170-
if (entrypoint.endsWith('.bootstrap.js')) {
171-
_logger.info('Loading debug metadata...');
166+
final logger = Logger('MetadataProvider');
167+
final assetScheme = _assetReader.assetScheme;
168+
final bootstrapSuffix = assetScheme.bootstrapSuffix;
169+
170+
if (entrypoint.endsWith(bootstrapSuffix)) {
171+
logger.info('Loading debug metadata...');
172172
final serverPath = entrypoint.replaceAll(
173-
'.bootstrap.js',
174-
'.ddc_merged_metadata',
173+
bootstrapSuffix,
174+
assetScheme.mergedMetadataSuffix,
175175
);
176176
final merged = await _assetReader.metadataContents(serverPath);
177177
if (merged != null) {
@@ -187,10 +187,9 @@ class MetadataProvider {
187187
);
188188
final moduleName = metadata.name;
189189
modules[moduleName] = metadata;
190-
_logger.fine('Loaded debug metadata for module: $moduleName');
190+
logger.fine('Loaded debug metadata for module: $moduleName');
191191
} catch (e) {
192-
_logger.warning('Failed to read metadata: $e');
193-
rethrow;
192+
logger.warning('Failed to parse metadata: $e');
194193
}
195194
}
196195
}
@@ -274,18 +273,19 @@ class MetadataProvider {
274273

275274
final moduleLibraries = <String>{};
276275
for (final library in metadata.libraries.values) {
277-
if (library.importUri.startsWith('file:/')) {
278-
throw AbsoluteImportUriException(library.importUri);
276+
final importUri = library.importUri;
277+
if (importUri.startsWith('file:/')) {
278+
throw AbsoluteImportUriException(importUri);
279279
}
280-
moduleLibraries.add(library.importUri);
281-
_libraries.add(library.importUri);
282-
_scripts[library.importUri] = [];
280+
moduleLibraries.add(importUri);
281+
_libraries.add(importUri);
282+
_scripts[importUri] = [];
283283

284-
_scriptToModule[library.importUri] = moduleName;
284+
_scriptToModule[importUri] = moduleName;
285285
for (final path in library.partUris) {
286286
// Parts in metadata are relative to the library Uri directory.
287-
final partPath = p.url.join(p.dirname(library.importUri), path);
288-
_scripts[library.importUri]!.add(partPath);
287+
final partPath = p.url.join(p.url.dirname(importUri), path);
288+
_scripts[importUri]!.add(partPath);
289289
_scriptToModule[partPath] = moduleName;
290290
}
291291
}

0 commit comments

Comments
 (0)