merge static method

Module merge(
  1. List<Module> modules
)

Merge the sources and dependencies from modules into a single module.

All modules must have the same platform. primarySource will be the earliest value from the combined sources if they were sorted. isMissing will be true if any input module is missing. isSupported will be true if all input modules are supported. directDependencies will be merged for all modules, but if any module depended on a source from any other they will be filtered out.

Implementation

static Module merge(List<Module> modules) {
  assert(modules.isNotEmpty);
  if (modules.length == 1) return modules.single;
  assert(modules.every((m) => m.platform == modules.first.platform));

  final allSources = HashSet.of(modules.expand((m) => m.sources));
  final allDependencies =
      HashSet.of(modules.expand((m) => m.directDependencies))
        ..removeAll(allSources);
  final primarySource =
      allSources.reduce((a, b) => a.compareTo(b) < 0 ? a : b);
  final isMissing = modules.any((m) => m.isMissing);
  final isSupported = modules.every((m) => m.isSupported);
  return Module(primarySource, allSources, allDependencies,
      modules.first.platform, isSupported,
      isMissing: isMissing);
}