findPubspec method

File? findPubspec([
  1. String? startDir
])

Find the nearest pubspec.yaml by walking up the directory tree

Implementation

File? findPubspec([String? startDir]) {
  Directory dir = Directory(startDir ?? Directory.current.path);

  while (true) {
    final File pubspec = File(p.join(dir.path, 'pubspec.yaml'));
    if (pubspec.existsSync()) return pubspec;

    final Directory parent = dir.parent;
    if (parent.path == dir.path) return null;
    dir = parent;
  }
}