fromWorkspaceRoot static method
Loads the MelosWorkspaceConfig for the workspace at workspaceRoot.
Implementation
static Future<MelosWorkspaceConfig> fromWorkspaceRoot(
Directory workspaceRoot,
) async {
final rootPubspecFile = File(pubspecPathForDirectory(workspaceRoot.path));
if (!rootPubspecFile.existsSync()) {
throw UnresolvedWorkspace(
multiLine([
'Found no pubspec.yaml file in "${workspaceRoot.path}".',
'',
'You must have a ${AnsiStyles.bold('pubspec.yaml')} file in the root '
'of your workspace.',
'',
'For more information, see: '
'https://melos.invertase.dev/configuration/overview',
]),
);
}
late final Object? rootPubspecContent;
try {
rootPubspecContent = loadYamlNode(
await rootPubspecFile.readAsString(),
sourceUrl: rootPubspecFile.uri,
).toPlainObject();
} on YamlException catch (error) {
throw MelosConfigException('Failed to parse root pubspec.yaml:\n$error');
}
if (rootPubspecContent is! Map<Object?, Object?>) {
throw MelosConfigException('pubspec.yaml must contain a valid YAML.');
}
if (rootPubspecContent['melos'] is! Map<Object?, Object?>?) {
throw MelosConfigException(
'If a melos section is present in the root pubspec.yaml file, it must '
'be a map.',
);
}
return MelosWorkspaceConfig.fromYaml(
rootPubspecContent,
path: workspaceRoot.path,
);
}