stripDevDependenciesFromPubspecContent static method

String? stripDevDependenciesFromPubspecContent(
  1. String pubspecContent
)

Strips dev_dependencies from pubspec.yaml content in memory. Returns the modified content, or null if no changes were needed.

Implementation

static String? stripDevDependenciesFromPubspecContent(
  final String pubspecContent,
) {
  try {
    final pubspecYaml = yamlDecode(pubspecContent);
    if (pubspecYaml is! Map) {
      return null;
    }

    if (pubspecYaml.containsKey('dev_dependencies')) {
      final modifiedPubspec = Map.from(pubspecYaml);
      modifiedPubspec.remove('dev_dependencies');
      return yamlEncode(modifiedPubspec);
    }
    return null;
  } on Exception {
    return null;
  }
}