getPubPackageRootSync function

String getPubPackageRootSync(
  1. String resolverPath
)

throws if no project found, returns the nearest pub package root from a given path (could be current dir using '.')

Implementation

String getPubPackageRootSync(String resolverPath) {
  var dirPath = normalize(absolute(resolverPath));

  while (true) {
    // Find the project root path
    if (isPubPackageRootSync(dirPath)) {
      return dirPath;
    }
    var parentDirPath = dirname(dirPath);

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