projectPackageConfigUri property

FutureOr<Uri> get projectPackageConfigUri

The resolved project .dart_tool/package_config.json Uri.

For a pub workspace member this is the workspace root's .dart_tool/package_config.json (see projectResolutionDirectory). Falls back to the legacy .packages file in the projectDirectory.

Throws a StateError if none exists (dart pub get not run).

Implementation

FutureOr<Uri> get projectPackageConfigUri =>
    projectResolutionDirectory.resolveMapped((resolutionDir) {
      var fileJson = File.fromUri(
        resolutionDir.uri.resolve('.dart_tool/package_config.json'),
      );
      if (fileJson.existsSync()) {
        return fileJson.uri;
      }

      return projectSubFile('.packages').resolveMapped((filePack) {
        if (filePack.existsSync()) {
          return filePack.uri;
        }
        throw StateError(
          "Can't resolve project packageConfig: $fileJson ; $filePack",
        );
      });
    });