Skip to content

Commit

Permalink
Use correct working dir after install puro plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Jul 16, 2024
1 parent 5ca47c0 commit 3ab32eb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
3 changes: 0 additions & 3 deletions lib/puro_sidekick_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ void _setupFlutterEnvironment(SdkInitializerContext context) {
packagePath: context.packageDir?.root ?? SidekickContext.projectRoot,
projectRoot: SidekickContext.projectRoot,
).getMaxFlutterSdkVersionFromPubspec();
if (sdkVersion == null) {
throw Exception('No Flutter SDK version found in pubspec.yaml');
}

final progress = Progress.capture();
puro(['ls'], progress: progress);
Expand Down
2 changes: 0 additions & 2 deletions lib/src/puro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Future<ProcessCompletion> puro(
throw PuroNotFoundException();
}

await initializeSdkForPackage(workingDirectory);

int exitCode = -1;
try {
final process = dcli.startFromArgs(
Expand Down
49 changes: 36 additions & 13 deletions lib/src/version_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class VersionParser {
/// If the flutter version is not available, it reads the dart sdk version
/// and returns the flutter version of the upper bound dart version constraint
/// Returns null if the version is not found
String? getMaxFlutterSdkVersionFromPubspec() {
String getMaxFlutterSdkVersionFromPubspec() {
try {
YamlMap? pubspec = _readPubspecFile(packagePath);
if (pubspec == null) {
return null;
throw VersionParserException(
msg: 'No pubspec.yaml found in the package directory: $packagePath',
);
}

// Check if the package is part of a workspace
Expand Down Expand Up @@ -62,33 +64,39 @@ class VersionParser {

if (flutterConstraint != null) {
final flutterVersion = VersionConstraint.parse(flutterConstraint);
print('Found flutter version constraint: $flutterVersion');
for (final version in availableVersions.values) {
if (flutterVersion.allows(version)) {
return version.toString();
}
}
} else if (dartConstraint != null) {
final dartVersion = VersionConstraint.parse(dartConstraint);
print('Found dart version constraint: $dartVersion');
for (final version in availableVersions.keys) {
if (dartVersion.allows(version)) {
return availableVersions[version].toString();
}
}
} else {
print('No flutter or dart version constraint found in pubspec.yaml');
return null;
}

return null;
throw VersionParserException(
msg:
'No valid flutter or dart version constraint found in pubspec.yaml',
);
} on FileSystemException catch (e) {
print('Error reading pubspec.yaml: $e');
return null;
throw VersionParserException(
msg: 'Error reading pubspec.yaml',
innerException: e,
);
} on YamlException catch (e) {
print('Error parsing pubspec.yaml: $e');
return null;
throw VersionParserException(
msg: 'Error parsing pubspec.yaml',
innerException: e,
);
} catch (e) {
print('Unexpected error: $e');
return null;
throw VersionParserException(
msg: 'Unexpected error: $e',
);
}
}

Expand Down Expand Up @@ -227,3 +235,18 @@ class VersionParser {
);
}
}

class VersionParserException implements Exception {
VersionParserException({
this.msg,
this.innerException,
});

String? msg;
Exception? innerException;

@override
String toString() {
return 'Error parsing SDK versions: $msg ${innerException != null ? '\n$innerException' : ''}';
}
}
6 changes: 5 additions & 1 deletion tool/install.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ Future<void> main() async {
);
}

puro(['flutter', '--version']);
final initialPackage =
DartPackage.fromDirectory(SidekickContext.projectRoot) ??
SidekickContext.sidekickPackage;
initializePuro(SdkInitializerContext(packageDir: initialPackage));
puro(['flutter', '--version'], workingDirectory: initialPackage.root);

print(green('Successfully installed sidekick Puro plugin'));
print('\nUsage: You can now execute the commands:\n'
Expand Down

0 comments on commit 3ab32eb

Please sign in to comment.