@@ -22,6 +22,8 @@ class MetadataProvider {
22
22
final Map <String , String > _moduleToModulePath = {};
23
23
final Map <String , List <String >> _scripts = {};
24
24
final _metadataMemoizer = AsyncMemoizer ();
25
+ // Whether to use the `name` provided in the module metadata.
26
+ final bool _useModuleName;
25
27
26
28
/// Implicitly imported libraries in any DDC component.
27
29
///
@@ -64,7 +66,11 @@ class MetadataProvider {
64
66
'dart:ui' ,
65
67
];
66
68
67
- MetadataProvider (this .entrypoint, this ._assetReader);
69
+ MetadataProvider (
70
+ this .entrypoint,
71
+ this ._assetReader, {
72
+ required bool useModuleName,
73
+ }) : _useModuleName = useModuleName;
68
74
69
75
/// A sound null safety mode for the whole app.
70
76
///
@@ -113,6 +119,8 @@ class MetadataProvider {
113
119
/// web/main
114
120
/// }
115
121
///
122
+ /// If [_useModuleName] is false, the values will be the module paths instead
123
+ /// of the name except for 'dart_sdk'.
116
124
Future <Map <String , String >> get scriptToModule async {
117
125
await _initialize ();
118
126
return _scriptToModule;
@@ -127,13 +135,14 @@ class MetadataProvider {
127
135
/// web/main.ddc.js.map
128
136
/// }
129
137
///
130
- ///
138
+ /// If [_useModuleName] is false, the keys will be the module paths instead of
139
+ /// the name.
131
140
Future <Map <String , String >> get moduleToSourceMap async {
132
141
await _initialize ();
133
142
return _moduleToSourceMap;
134
143
}
135
144
136
- /// A map of module path to module name
145
+ /// A map of module path to module name.
137
146
///
138
147
/// Example:
139
148
///
@@ -142,12 +151,14 @@ class MetadataProvider {
142
151
/// web/main
143
152
/// }
144
153
///
154
+ /// If [_useModuleName] is false, the values will be the module paths instead
155
+ /// of the name, making this an identity map.
145
156
Future <Map <String , String >> get modulePathToModule async {
146
157
await _initialize ();
147
158
return _modulePathToModule;
148
159
}
149
160
150
- /// A map of module to module path
161
+ /// A map of module to module path.
151
162
///
152
163
/// Example:
153
164
///
@@ -156,12 +167,14 @@ class MetadataProvider {
156
167
/// web/main.ddc.js :
157
168
/// }
158
169
///
170
+ /// If [_useModuleName] is false, the keys will be the module paths instead of
171
+ /// the name, making this an identity map.
159
172
Future <Map <String , String >> get moduleToModulePath async {
160
173
await _initialize ();
161
174
return _moduleToModulePath;
162
175
}
163
176
164
- /// A list of module ids
177
+ /// A list of module ids.
165
178
///
166
179
/// Example:
167
180
///
@@ -170,6 +183,8 @@ class MetadataProvider {
170
183
/// web/foo/bar
171
184
/// ]
172
185
///
186
+ /// If [_useModuleName] is false, this will be the set of module paths
187
+ /// instead.
173
188
Future <List <String >> get modules async {
174
189
await _initialize ();
175
190
return _moduleToModulePath.keys.toList ();
@@ -196,8 +211,9 @@ class MetadataProvider {
196
211
final metadata =
197
212
ModuleMetadata .fromJson (moduleJson as Map <String , dynamic >);
198
213
_addMetadata (metadata);
199
- _logger
200
- .fine ('Loaded debug metadata for module: ${metadata .name }' );
214
+ final moduleName =
215
+ _useModuleName ? metadata.name : metadata.moduleUri;
216
+ _logger.fine ('Loaded debug metadata for module: $moduleName ' );
201
217
} catch (e) {
202
218
_logger.warning ('Failed to read metadata: $e ' );
203
219
rethrow ;
@@ -211,10 +227,14 @@ class MetadataProvider {
211
227
void _addMetadata (ModuleMetadata metadata) {
212
228
final modulePath = stripLeadingSlashes (metadata.moduleUri);
213
229
final sourceMapPath = stripLeadingSlashes (metadata.sourceMapUri);
230
+ // DDC library bundle module format does not provide names for library
231
+ // bundles, and therefore we use the URI instead to represent a library
232
+ // bundle.
233
+ final moduleName = _useModuleName ? metadata.name : modulePath;
214
234
215
- _moduleToSourceMap[metadata.name ] = sourceMapPath;
216
- _modulePathToModule[modulePath] = metadata.name ;
217
- _moduleToModulePath[metadata.name ] = modulePath;
235
+ _moduleToSourceMap[moduleName ] = sourceMapPath;
236
+ _modulePathToModule[modulePath] = moduleName ;
237
+ _moduleToModulePath[moduleName ] = modulePath;
218
238
219
239
for (final library in metadata.libraries.values) {
220
240
if (library.importUri.startsWith ('file:/' )) {
@@ -223,12 +243,12 @@ class MetadataProvider {
223
243
_libraries.add (library.importUri);
224
244
_scripts[library.importUri] = [];
225
245
226
- _scriptToModule[library.importUri] = metadata.name ;
246
+ _scriptToModule[library.importUri] = moduleName ;
227
247
for (final path in library.partUris) {
228
248
// Parts in metadata are relative to the library Uri directory.
229
249
final partPath = p.url.join (p.dirname (library.importUri), path);
230
250
_scripts[library.importUri]! .add (partPath);
231
- _scriptToModule[partPath] = metadata.name ;
251
+ _scriptToModule[partPath] = moduleName ;
232
252
}
233
253
}
234
254
}
@@ -239,6 +259,9 @@ class MetadataProvider {
239
259
for (final lib in sdkLibraries) {
240
260
_libraries.add (lib);
241
261
_scripts[lib] = [];
262
+ // TODO(srujzs): It feels weird that we add this mapping to only this map
263
+ // and not any of the other module maps. We should maybe handle this
264
+ // differently.
242
265
_scriptToModule[lib] = moduleName;
243
266
}
244
267
}
0 commit comments