expandWorkspaceGlobs function
Expands glob patterns from dpk.yaml workspace field into actual directory paths. Only includes directories that contain a pubspec.yaml file.
Implementation
List<String>? expandWorkspaceGlobs(List<dynamic>? patterns, Directory root) {
if (patterns == null || patterns.isEmpty) {
return null;
}
final expandedPaths = <String>{};
for (final pattern in patterns) {
if (pattern == null || pattern is! String || pattern.isEmpty) {
continue;
}
final glob = Glob(pattern);
final matches = glob.listSync(root: root.path);
for (final match in matches) {
if (match is Directory) {
final pubspecFile = File(join(match.path, 'pubspec.yaml'));
if (pubspecFile.existsSync()) {
expandedPaths.add(relative(match.path, from: root.path));
}
}
}
}
if (expandedPaths.isEmpty) {
return null;
}
final sortedPaths = expandedPaths.toList()..sort();
return sortedPaths;
}