getPubPackageRoot function

Future<String> getPubPackageRoot(
  1. String resolverPath, {
  2. FilterDartProjectOptions? filterDartProjectOptions,
})

throws if no project found

Implementation

Future<String> getPubPackageRoot(
  String resolverPath, {
  FilterDartProjectOptions? filterDartProjectOptions,
}) async {
  var dirPath = normalize(absolute(resolverPath));

  while (true) {
    // Find the project root path
    if (await isPubPackageRoot(
      dirPath,
      filterDartProjectOptions: filterDartProjectOptions,
    )) {
      return dirPath;
    }
    var parentDirPath = dirname(dirPath);

    if (parentDirPath == dirPath) {
      throw Exception("No project found for path '$resolverPath");
    }
    dirPath = parentDirPath;
  }
}