33// found in the LICENSE file.
44
55import 'package:dwds/src/debugging/metadata/provider.dart' ;
6+ import 'package:dwds/src/loaders/ddc.dart' ;
7+ import 'package:dwds/src/loaders/require.dart' ;
68import 'package:dwds/src/loaders/strategy.dart' ;
79import 'package:dwds/src/readers/asset_reader.dart' ;
810import 'package:dwds/src/services/expression_compiler.dart' ;
911import 'package:path/path.dart' as p;
1012
1113abstract class FrontendServerStrategyProvider <T extends LoadStrategy > {
12- final ReloadConfiguration configuration ;
13- final AssetReader assetReader ;
14- final PackageUriMapper packageUriMapper ;
15- final Future <Map <String , String >> Function () digestsProvider ;
16- final String basePath ;
17- final BuildSettings buildSettings ;
14+ final ReloadConfiguration _configuration ;
15+ final AssetReader _assetReader ;
16+ final PackageUriMapper _packageUriMapper ;
17+ final Future <Map <String , String >> Function () _digestsProvider ;
18+ final String _basePath ;
19+ final BuildSettings _buildSettings ;
1820
1921 FrontendServerStrategyProvider (
20- this .configuration ,
21- this .assetReader ,
22- this .packageUriMapper ,
23- this .digestsProvider ,
24- this .buildSettings ,
25- ) : basePath = assetReader .basePath;
22+ this ._configuration ,
23+ this ._assetReader ,
24+ this ._packageUriMapper ,
25+ this ._digestsProvider ,
26+ this ._buildSettings ,
27+ ) : _basePath = _assetReader .basePath;
2628
2729 T get strategy;
2830
29- String removeBasePath (String path) {
30- if (basePath .isEmpty) return path;
31+ String _removeBasePath (String path) {
32+ if (_basePath .isEmpty) return path;
3133 final stripped = stripLeadingSlashes (path);
32- return stripLeadingSlashes (stripped.substring (basePath .length));
34+ return stripLeadingSlashes (stripped.substring (_basePath .length));
3335 }
3436
35- String addBasePath (String serverPath) => basePath .isEmpty
37+ String _addBasePath (String serverPath) => _basePath .isEmpty
3638 ? stripLeadingSlashes (serverPath)
37- : '$basePath /${stripLeadingSlashes (serverPath )}' ;
39+ : '$_basePath /${stripLeadingSlashes (serverPath )}' ;
3840
39- String removeJsExtension (String path) =>
41+ String _removeJsExtension (String path) =>
4042 path.endsWith ('.js' ) ? p.withoutExtension (path) : path;
4143
42- Future <Map <String , String >> moduleProvider (
44+ Future <Map <String , String >> _moduleProvider (
4345 MetadataProvider metadataProvider,
4446 ) async =>
4547 (await metadataProvider.moduleToModulePath).map (
4648 (key, value) =>
47- MapEntry (key, stripLeadingSlashes (removeJsExtension (value))),
49+ MapEntry (key, stripLeadingSlashes (_removeJsExtension (value))),
4850 );
4951
50- Future <String ?> moduleForServerPath (
52+ Future <String ?> _moduleForServerPath (
5153 MetadataProvider metadataProvider,
5254 String serverPath,
5355 ) async {
5456 final modulePathToModule = await metadataProvider.modulePathToModule;
55- final relativeServerPath = removeBasePath (serverPath);
57+ final relativeServerPath = _removeBasePath (serverPath);
5658 return modulePathToModule[relativeServerPath];
5759 }
5860
59- Future <String > serverPathForModule (
61+ Future <String > _serverPathForModule (
6062 MetadataProvider metadataProvider,
6163 String module,
6264 ) async =>
63- addBasePath ((await metadataProvider.moduleToModulePath)[module] ?? '' );
65+ _addBasePath ((await metadataProvider.moduleToModulePath)[module] ?? '' );
6466
65- Future <String > sourceMapPathForModule (
67+ Future <String > _sourceMapPathForModule (
6668 MetadataProvider metadataProvider,
6769 String module,
6870 ) async =>
69- addBasePath ((await metadataProvider.moduleToSourceMap)[module] ?? '' );
71+ _addBasePath ((await metadataProvider.moduleToSourceMap)[module] ?? '' );
7072
71- String ? serverPathForAppUri (String appUrl) {
73+ String ? _serverPathForAppUri (String appUrl) {
7274 final appUri = Uri .parse (appUrl);
7375 if (appUri.isScheme ('org-dartlang-app' )) {
74- return addBasePath (appUri.path);
76+ return _addBasePath (appUri.path);
7577 }
7678 if (appUri.isScheme ('package' )) {
77- final resolved = packageUriMapper .packageUriToServerPath (appUri);
79+ final resolved = _packageUriMapper .packageUriToServerPath (appUri);
7880 if (resolved != null ) {
7981 return resolved;
8082 }
8183 }
8284 return null ;
8385 }
8486
85- Future <Map <String , ModuleInfo >> moduleInfoForProvider (
87+ Future <Map <String , ModuleInfo >> _moduleInfoForProvider (
8688 MetadataProvider metadataProvider,
8789 ) async {
8890 final modules = await metadataProvider.moduleToModulePath;
@@ -99,3 +101,61 @@ abstract class FrontendServerStrategyProvider<T extends LoadStrategy> {
99101 return result;
100102 }
101103}
104+
105+ /// Provides a [DdcStrategy] suitable for use with Frontend Server.
106+ class FrontendServerDdcStrategyProvider
107+ extends FrontendServerStrategyProvider <DdcStrategy > {
108+ late final DdcStrategy _ddcStrategy = DdcStrategy (
109+ _configuration,
110+ _moduleProvider,
111+ (_) => _digestsProvider (),
112+ _moduleForServerPath,
113+ _serverPathForModule,
114+ _sourceMapPathForModule,
115+ _serverPathForAppUri,
116+ _moduleInfoForProvider,
117+ _assetReader,
118+ _buildSettings,
119+ (String _) => null ,
120+ null ,
121+ );
122+
123+ FrontendServerDdcStrategyProvider (
124+ super ._configuration,
125+ super ._assetReader,
126+ super ._packageUriMapper,
127+ super ._digestsProvider,
128+ super ._buildSettings,
129+ );
130+
131+ @override
132+ DdcStrategy get strategy => _ddcStrategy;
133+ }
134+
135+ /// Provides a [RequireStrategy] suitable for use with Frontend Server.
136+ class FrontendServerRequireStrategyProvider
137+ extends FrontendServerStrategyProvider <RequireStrategy > {
138+ late final RequireStrategy _requireStrategy = RequireStrategy (
139+ _configuration,
140+ _moduleProvider,
141+ (_) => _digestsProvider (),
142+ _moduleForServerPath,
143+ _serverPathForModule,
144+ _sourceMapPathForModule,
145+ _serverPathForAppUri,
146+ _moduleInfoForProvider,
147+ _assetReader,
148+ _buildSettings,
149+ );
150+
151+ FrontendServerRequireStrategyProvider (
152+ super ._configuration,
153+ super ._assetReader,
154+ super ._packageUriMapper,
155+ super ._digestsProvider,
156+ super ._buildSettings,
157+ );
158+
159+ @override
160+ RequireStrategy get strategy => _requireStrategy;
161+ }
0 commit comments