getProjectRoot static method

String getProjectRoot(
  1. FileSystem fs
)

Get the project root directory. The fs is the file system to use to search for the project root.

The project root is the directory that contains a pubspec.yaml file. If no project root is found, the current directory is used.

Implementation

static String getProjectRoot(FileSystem fs) {
  var dir = fs.currentDirectory;
  while (true) {
    if (dir.childFile('pubspec.yaml').existsSync()) {
      return dir.path;
    }
    if (dir.parent.path == dir.path) {
      return fs.currentDirectory.path;
    }
    dir = dir.parent;
  }
}