ensurePubspecResolved function

Future<void> ensurePubspecResolved(
  1. String dir, {
  2. bool isOffline = false,
  3. bool summaryOnly = true,
  4. bool onlyOutputWhenTerminal = true,
})

Makes sure that dir/pubspec.yaml is resolved such that pubspec.lock and .dart_tool/package_config.json are up-to-date and all packages are downloaded to the cache.

Will compare file timestamps to see if full resolution can be skipped.

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.

Throws a ResolutionFailedException if resolution fails.

Implementation

Future<void> ensurePubspecResolved(
  String dir, {
  bool isOffline = false,
  bool summaryOnly = true,
  bool onlyOutputWhenTerminal = true,
}) async {
  try {
    await Entrypoint.ensureUpToDate(
      dir,
      cache: SystemCache(isOffline: isOffline),
      summaryOnly: summaryOnly,
      onlyOutputWhenTerminal: onlyOutputWhenTerminal,
    );
  } on ApplicationException catch (e) {
    throw ResolutionFailedException._(e.toString());
  } finally {
    // TODO(https://github.com/dart-lang/pub/issues/4200)
    // This is a bit of a hack.
    // We should most likely take a client here.
    globalHttpClient.close();
  }
}