ensureUpToDate static method

Future<({PackageConfig packageConfig, String rootDir})> ensureUpToDate(
  1. String dir, {
  2. required SystemCache cache,
  3. SolveReportMode reportMode = SolveReportMode.none,
  4. bool onlyOutputWhenTerminal = true,
})

Does a fast-pass check to see if the resolution is up-to-date. If not, run a resolution with pub get semantics.

reportMode specifies the level of reporting output on success. Defaults to SolveReportMode.none (no output).

If onlyOutputWhenTerminal is true (the default) there will be no output if no terminal is attached.

When succesfull returns the found/created PackageConfig and the directory containing it.

Implementation

static Future<({PackageConfig packageConfig, String rootDir})> ensureUpToDate(
  String dir, {
  required SystemCache cache,
  SolveReportMode reportMode = SolveReportMode.none,
  bool onlyOutputWhenTerminal = true,
}) async {
  late final wasRelative = p.isRelative(dir);
  String relativeIfNeeded(String path) =>
      wasRelative ? p.relative(path) : path;

  if (isResolutionUpToDate(dir, cache) case (
    final PackageConfig packageConfig,
    final String rootDir,
  )) {
    log.fine('Package Config up to date.');
    return (packageConfig: packageConfig, rootDir: rootDir);
  }
  final rootPackageDir = _rootPackageDir(dir);
  final entrypoint = Entrypoint(
    rootPackageDir,
    cache,
    // [ensureUpToDate] is also used for entries in 'global_packages/'
    checkInCache: false,
  );
  if (onlyOutputWhenTerminal) {
    await log.errorsOnlyUnlessTerminal(() async {
      await entrypoint.acquireDependencies(
        SolveType.get,
        reportMode: reportMode,
      );
    });
  } else {
    await entrypoint.acquireDependencies(
      SolveType.get,
      reportMode: reportMode,
    );
  }
  return (
    packageConfig: entrypoint.packageConfig,
    rootDir: relativeIfNeeded(
      p.normalize(p.absolute(entrypoint.workspaceRoot.dir)),
    ),
  );
}