getLibraries method

Future<void> getLibraries(
  1. PackageGraph uninitializedPackageGraph
)

Implementation

Future<void> getLibraries(PackageGraph uninitializedPackageGraph) async {
  var findSpecialsSdk = sdk;
  if (embedderSdk != null && embedderSdk.urlMappings.isNotEmpty) {
    findSpecialsSdk = embedderSdk;
  }
  var files = await _getFiles();
  var specialFiles = specialLibraryFiles(findSpecialsSdk);

  /// Returns true if this library element should be included according
  /// to the configuration.
  bool isLibraryIncluded(LibraryElement libraryElement) {
    if (config.include.isNotEmpty &&
        !config.include.contains(libraryElement.name)) {
      return false;
    }
    return true;
  }

  var foundLibraries = <LibraryElement>{};
  await _parseLibraries(uninitializedPackageGraph.addLibraryToGraph,
      foundLibraries, files, isLibraryIncluded);
  if (config.include.isNotEmpty) {
    var knownLibraryNames = foundLibraries.map((l) => l.name);
    var notFound = Set<String>.from(config.include)
        .difference(Set.from(knownLibraryNames))
        .difference(Set.from(config.exclude));
    if (notFound.isNotEmpty) {
      throw 'Did not find: [${notFound.join(', ')}] in '
          'known libraries: [${knownLibraryNames.join(', ')}]';
    }
  }
  // Include directive does not apply to special libraries.
  await _parseLibraries(uninitializedPackageGraph.addSpecialLibraryToGraph,
      foundLibraries, specialFiles.difference(files));
}