getWorkspacePackages function
Gets all workspace packages with their names and directories
Implementation
List<WorkspacePackage> getWorkspacePackages(WorkspaceInfo workspace) {
final packages = <WorkspacePackage>[];
for (final memberPath in workspace.memberPaths) {
// Resolve path relative to workspace root
final packageDir = path.isAbsolute(memberPath)
? Directory(memberPath)
: Directory(path.join(workspace.root.path, memberPath));
if (!packageDir.existsSync()) {
logger.warn('Workspace member path does not exist: ${packageDir.path}');
continue;
}
final pubspecFile = File(path.join(packageDir.path, 'pubspec.yaml'));
if (!pubspecFile.existsSync()) {
logger.warn('pubspec.yaml not found for workspace member: ${packageDir.path}');
continue;
}
try {
final pubspecContent = pubspecFile.readAsStringSync();
final packageName = PubspecUtils.getPackageName(pubspecContent);
final relativePath = path.relative(packageDir.path, from: workspace.root.path);
packages.add(WorkspacePackage(name: packageName, directory: packageDir, relativePath: relativePath));
} catch (e) {
logger.warn('Error reading package name from ${packageDir.path}: $e');
continue;
}
}
return packages;
}