//@dart=2.9 import 'dart:io'; import 'package:path/path.dart' as p; List findPubspecs(Directory root, {bool pubspecLock = false}) { return findPackages(root, 'pubspec${pubspecLock ? '.lock' : '.yaml'}'); } List findPackages(Directory root, String fileName) { return _findPubspecs(root, fileName); } List _findPubspecs(Directory root, String file) { var results = []; var entities = root.listSync(); var hasPubspec = false; for (var entity in entities.whereType()) { if (p.basename(entity.path) == file) { hasPubspec = true; results.add(entity); } } for (var dir in entities.whereType()) { var dirName = p.basename(dir.path); if (!dirName.startsWith('.') && !dirName.startsWith('_') && (!hasPubspec || !const ['web', 'lib', 'test'].contains(dirName))) { results.addAll(_findPubspecs(dir, file)); } } return results; }