@@ -22,6 +22,8 @@ class MetadataProvider {
2222 final Map <String , String > _moduleToModulePath = {};
2323 final Map <String , List <String >> _scripts = {};
2424 final _metadataMemoizer = AsyncMemoizer ();
25+ // Whether to use the `name` provided in the module metadata.
26+ final bool _useModuleName;
2527
2628 /// Implicitly imported libraries in any DDC component.
2729 ///
@@ -64,7 +66,11 @@ class MetadataProvider {
6466 'dart:ui' ,
6567 ];
6668
67- MetadataProvider (this .entrypoint, this ._assetReader);
69+ MetadataProvider (
70+ this .entrypoint,
71+ this ._assetReader, {
72+ required bool useModuleName,
73+ }) : _useModuleName = useModuleName;
6874
6975 /// A sound null safety mode for the whole app.
7076 ///
@@ -113,6 +119,8 @@ class MetadataProvider {
113119 /// web/main
114120 /// }
115121 ///
122+ /// If [_useModuleName] is false, the values will be the module paths instead
123+ /// of the name except for 'dart_sdk'.
116124 Future <Map <String , String >> get scriptToModule async {
117125 await _initialize ();
118126 return _scriptToModule;
@@ -127,13 +135,14 @@ class MetadataProvider {
127135 /// web/main.ddc.js.map
128136 /// }
129137 ///
130- ///
138+ /// If [_useModuleName] is false, the keys will be the module paths instead of
139+ /// the name.
131140 Future <Map <String , String >> get moduleToSourceMap async {
132141 await _initialize ();
133142 return _moduleToSourceMap;
134143 }
135144
136- /// A map of module path to module name
145+ /// A map of module path to module name.
137146 ///
138147 /// Example:
139148 ///
@@ -142,12 +151,14 @@ class MetadataProvider {
142151 /// web/main
143152 /// }
144153 ///
154+ /// If [_useModuleName] is false, the values will be the module paths instead
155+ /// of the name, making this an identity map.
145156 Future <Map <String , String >> get modulePathToModule async {
146157 await _initialize ();
147158 return _modulePathToModule;
148159 }
149160
150- /// A map of module to module path
161+ /// A map of module to module path.
151162 ///
152163 /// Example:
153164 ///
@@ -156,12 +167,14 @@ class MetadataProvider {
156167 /// web/main.ddc.js :
157168 /// }
158169 ///
170+ /// If [_useModuleName] is false, the keys will be the module paths instead of
171+ /// the name, making this an identity map.
159172 Future <Map <String , String >> get moduleToModulePath async {
160173 await _initialize ();
161174 return _moduleToModulePath;
162175 }
163176
164- /// A list of module ids
177+ /// A list of module ids.
165178 ///
166179 /// Example:
167180 ///
@@ -170,6 +183,8 @@ class MetadataProvider {
170183 /// web/foo/bar
171184 /// ]
172185 ///
186+ /// If [_useModuleName] is false, this will be the set of module paths
187+ /// instead.
173188 Future <List <String >> get modules async {
174189 await _initialize ();
175190 return _moduleToModulePath.keys.toList ();
@@ -196,8 +211,9 @@ class MetadataProvider {
196211 final metadata =
197212 ModuleMetadata .fromJson (moduleJson as Map <String , dynamic >);
198213 _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 ' );
201217 } catch (e) {
202218 _logger.warning ('Failed to read metadata: $e ' );
203219 rethrow ;
@@ -211,10 +227,14 @@ class MetadataProvider {
211227 void _addMetadata (ModuleMetadata metadata) {
212228 final modulePath = stripLeadingSlashes (metadata.moduleUri);
213229 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;
214234
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;
218238
219239 for (final library in metadata.libraries.values) {
220240 if (library.importUri.startsWith ('file:/' )) {
@@ -223,12 +243,12 @@ class MetadataProvider {
223243 _libraries.add (library.importUri);
224244 _scripts[library.importUri] = [];
225245
226- _scriptToModule[library.importUri] = metadata.name ;
246+ _scriptToModule[library.importUri] = moduleName ;
227247 for (final path in library.partUris) {
228248 // Parts in metadata are relative to the library Uri directory.
229249 final partPath = p.url.join (p.dirname (library.importUri), path);
230250 _scripts[library.importUri]! .add (partPath);
231- _scriptToModule[partPath] = metadata.name ;
251+ _scriptToModule[partPath] = moduleName ;
232252 }
233253 }
234254 }
@@ -239,6 +259,9 @@ class MetadataProvider {
239259 for (final lib in sdkLibraries) {
240260 _libraries.add (lib);
241261 _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.
242265 _scriptToModule[lib] = moduleName;
243266 }
244267 }
0 commit comments