Skip to content

Commit 627f9f9

Browse files
committed
fix: update pub_service to extract version using regex and refactor pubspec_service to use yaml package
1 parent 88e0ba0 commit 627f9f9

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

lib/src/services/pub_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PubService {
2020
final packages = await _processService.runPubGlobalList();
2121
for (var package in packages) {
2222
if (!package.contains(ksStackedCli)) continue;
23+
2324
final splitResults = package.split(' ');
2425
if (splitResults.length > 2) {
2526
version = splitResults[1];
@@ -28,7 +29,6 @@ class PubService {
2829
}
2930
break;
3031
}
31-
3232
return version;
3333
}
3434

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import 'dart:io';
2-
3-
import 'package:pubspec_yaml/pubspec_yaml.dart';
2+
import 'package:yaml/yaml.dart';
43

54
/// Provides functionality to interact with the pubspec in the current project
65
class PubspecService {
7-
late PubspecYaml pubspecYaml;
6+
late YamlMap pubspecYaml;
87

9-
/// Reads the pubpec and caches the value locally
8+
/// Reads the pubspec and caches the value locally
109
Future<void> initialise({String? workingDirectory}) async {
1110
final bool hasWorkingDirectory = workingDirectory != null;
12-
// stdout.writeln('PubspecService - initialise from pubspec.yaml');
13-
final pubspecYamlContent = await File(
14-
'${hasWorkingDirectory ? '$workingDirectory/' : ''}pubspec.yaml')
15-
.readAsString();
16-
pubspecYaml = pubspecYamlContent.toPubspecYaml();
17-
// stdout.writeln('PubspecService - initialise complete');
11+
12+
// Clean the working directory path from quotes and trim whitespace
13+
final cleanWorkingDirectory = workingDirectory?.replaceAll('"', '').trim();
14+
15+
final pubspecYamlContent =
16+
await File('${hasWorkingDirectory ? '$cleanWorkingDirectory/' : ''}pubspec.yaml').readAsString();
17+
18+
pubspecYaml = loadYaml(pubspecYamlContent) as YamlMap;
1819
}
1920

20-
String get getPackageName => pubspecYaml.name;
21+
String get getPackageName => pubspecYaml['name'];
2122
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
mockito: ^5.4.3
1515
mustache_template: ^2.0.0
1616
path: ^1.8.1
17-
pubspec_yaml: ^3.1.0
17+
yaml: ^3.1.3
1818
recase: ^4.0.0
1919
json_annotation: ^4.8.1
2020
ansicolor: ^2.0.2

0 commit comments

Comments
 (0)