Skip to content

Commit

Permalink
fix: update dependency handling in Firebase Performance script
Browse files Browse the repository at this point in the history
  • Loading branch information
sharjeelyunus committed Jan 1, 2025
1 parent 4002841 commit a339310
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions starter/scripts/firebase_performance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,27 @@ void addPod(String pod) {
}

void addDependency(String dependency, String version) {
final pubspec = File('pubspec.yaml');
final pubspec = File(pubspecFilePath);
if (!pubspec.existsSync()) {
throw 'pubspec.yaml not found';
}

// find dependencies section with regex, don't do it with lines
final content = pubspec.readAsStringSync();
final dependencies =
final dependenciesSection =
RegExp(r'dependencies:', multiLine: true).firstMatch(content);

if (dependencies == null) {
if (dependenciesSection == null) {
throw 'dependencies section not found in pubspec.yaml';
}

final newContent = content.replaceFirst(dependencies.group(0)!,
'${dependencies.group(0)}\n $dependency: $version\n');
final dependencyPattern = RegExp(r'\s+$dependency:\s+\S+');
if (dependencyPattern.hasMatch(content)) {
return;
}
final newContent = content.replaceFirst(
dependenciesSection.group(0)!,
'${dependenciesSection.group(0)}\n $dependency: $version\n',
);

pubspec.writeAsStringSync(newContent);
}

0 comments on commit a339310

Please sign in to comment.