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-
54import 'dart:convert' ;
65
76import '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.
1413class 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