ensureUpToDate static method

Future<({PackageConfig packageConfig, String rootDir})> ensureUpToDate(
  1. String dir, {
  2. required SystemCache cache,
  3. bool summaryOnly = true,
  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.

If summaryOnly is true (the default) only a short summary is shown of the solve.

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,
  bool summaryOnly = true,
  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 entrypoint = Entrypoint(
    dir,
    cache,
    // [ensureUpToDate] is also used for entries in 'global_packages/'
    checkInCache: false,
  );
  if (onlyOutputWhenTerminal) {
    await log.errorsOnlyUnlessTerminal(() async {
      await entrypoint.acquireDependencies(
        SolveType.get,
        summaryOnly: summaryOnly,
      );
    });
  } else {
    await entrypoint.acquireDependencies(
      SolveType.get,
      summaryOnly: summaryOnly,
    );
  }
  return (
    packageConfig: entrypoint.packageConfig,
    rootDir: relativeIfNeeded(
      p.normalize(p.absolute(entrypoint.workspaceRoot.dir)),
    ),
  );
}