readPubspec static method

Map<String, dynamic> readPubspec(
  1. String pubspecPath
)

Reads both dependencies and dev_dependencies from a pubspec.yaml Converts YamlMap to regular Map<String, dynamic> to preserve nested values

Implementation

static Map<String, dynamic> readPubspec(String pubspecPath) {
  final file = File(pubspecPath);
  if (!file.existsSync()) {
    throw Exception('pubspec.yaml not found at $pubspecPath');
  }

  final content = file.readAsStringSync();
  final yamlMap = loadYaml(content);

  Map<String, dynamic> convertMap(dynamic map) {
    if (map == null) return {};
    return Map<String, dynamic>.from(map);
  }

  final dependencies = convertMap(yamlMap['dependencies']);
  final devDependencies = convertMap(yamlMap['dev_dependencies']);

  return {
    'dependencies': dependencies,
    'dev_dependencies': devDependencies,
  };
}