findPackageRoot function
Implementation
String? findPackageRoot(String path) {
if (path.startsWith('file:')) {
path = fromUri(path);
}
path = absolute(path);
while (path != dirname(path)) {
// We use the pubspec.yaml file as an indicator of being in the package
// root directory.
final pubspec = File(join(path, 'pubspec.yaml'));
if (pubspec.existsSync()) return path;
path = dirname(path);
}
return null;
}