Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor 2024 10 11 #9

Merged
merged 28 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Static Analysis
on:
push:
branches:
- master
pull_request:

concurrency:
Expand All @@ -23,15 +25,20 @@ jobs:
echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
fvm install 3.10.0 --setup
fvm install stable --setup
fvm global 3.10.0
fvm flutter doctor
fvm global stable
fvm flutter doctor
- name: Pub get
run: dart pub get
- name: Format
run: dart format . --set-exit-if-changed
run: dart format --set-exit-if-changed .
- name: Analyze
run: dart analyze
run: dart analyze --fatal-infos
- name: custom_lint
run: dart run custom_lint
- name: Test
run: dart test --timeout 120s --concurrency 1
run: dart test
- name: Pana
run: |
dart pub global activate pana
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ build/
pubspec.lock

# macOS
.DS_Store
.DS_Store

*.log
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.36.0

- Improves exit codes
- Adds safety checks for FVM usage
- Skips `pub get` in all example projects
- Bumps Dart SDK constraint to `^3.0.0`

## 1.35.0
- `puby link` no longer runs `pub get --offline` in flutter example projects
- Fixes `--no-fvm` flag for `puby link`
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:rexios_lints/dart/package.yaml
include: package:rexios_lints/dart/package_extra.yaml
45 changes: 14 additions & 31 deletions bin/commands.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'dart:convert';
import 'dart:io';

import 'package:io/io.dart';
import 'package:puby/command.dart';
import 'package:io/ansi.dart';
import 'package:puby/engine.dart';
import 'package:puby/pens.dart';
import 'package:puby/project.dart';
import 'package:puby/time.dart';

Expand Down Expand Up @@ -65,7 +66,7 @@ abstract class Commands {
// hanging
if (!command.silent) {
print(
redPen(
red.wrap(
'Run `fvm install ${flutterVersionNotInstalledMatch[1]}` first',
),
);
Expand All @@ -87,15 +88,15 @@ extension ProjectCommandExtension on ProjectCommand {
if (resolved.exclude) return 0;

final finalArgs = [
if (!raw) ...resolved.engine.args,
if (!raw) ...resolved.engine.prefixArgs,
...args,
];

final argString = finalArgs.join(' ');
final pathString =
resolved.path == '.' ? 'current directory' : resolved.path;
if (!silent) {
print(greenPen('Running "$argString" in $pathString...'));
print(green.wrap('Running "$argString" in $pathString...'));
}

final process = await Process.start(
Expand Down Expand Up @@ -124,12 +125,12 @@ extension ProjectCommandExtension on ProjectCommand {
.map(_decoder.convert)
.listen((line) {
if (!silent) {
stderr.write(redPen(line));
stderr.write(red.wrap(line));
}
err.add(line);
}).asFuture();

final processExitCode = await process.exitCode;
final exitCode = await process.exitCode;

if (!killed) {
// If we do not wait for these streams to finish, output could end up
Expand All @@ -140,38 +141,20 @@ extension ProjectCommandExtension on ProjectCommand {
}

stopwatch.stop();

// Skip error handling if the command was successful or this is a raw command
if (raw || processExitCode == 0) {
if (raw || exitCode == ExitCode.success.code) {
print(
greenPen(
green.wrap(
'Ran "$argString" in $pathString (${stopwatch.prettyPrint()})',
),
);

return processExitCode;
}

if (err.any(
(e) => e.contains(
'Flutter users should run `flutter pub get` instead of `dart pub get`.',
),
)) {
// If a project doesn't explicitly depend on flutter, it is not possible
// to know if it's dependencies require flutter. So retry if that's the
// reason for failure.
print(yellowPen('Retrying with "flutter" engine'));
return runInProject(resolved.copyWith(engine: Engine.flutter));
}

final unknownSubcommandMatch =
RegExp(r'Could not find a subcommand named "(.+?)" for ".+? pub"\.')
.firstMatch(err.join('\n'));
if (unknownSubcommandMatch != null) {
} else if (exitCode == ExitCode.usage.code) {
// Do not attempt to run in other projects if the command is unknown
print(redPen('Unknown command: ${unknownSubcommandMatch[1]}'));
exit(1);
print(red.wrap('Unknown command. Exiting...'));
exit(exitCode);
}

return processExitCode;
return exitCode;
}
}
33 changes: 33 additions & 0 deletions bin/fvm.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'dart:io';

import 'package:pub_semver/pub_semver.dart';
import 'package:io/ansi.dart';

final minFvmVersion = Version.parse('3.0.0');

void fvmCheck() {
try {
final fvmVersionResult = Process.runSync('fvm', ['--version']);
final fvmVersion = Version.parse(fvmVersionResult.stdout.toString().trim());
if (fvmVersion < minFvmVersion) {
print(
yellow.wrap(
'''
This version of puby expects FVM version $minFvmVersion or higher
FVM version $fvmVersion is installed
Commands in projects configured with FVM may fail
''',
),
);
}
} catch (e) {
print(
red.wrap(
'''
FVM is not installed
Commands in projects configured with FVM will fail
''',
),
);
}
}
18 changes: 11 additions & 7 deletions bin/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:async';

import 'package:flutter_tools_task_queue/flutter_tools_task_queue.dart';
import 'package:puby/command.dart';
import 'package:puby/pens.dart';
import 'package:io/ansi.dart';
import 'package:puby/project.dart';
import 'package:puby/pub.dart';
import 'package:puby/time.dart';
Expand Down Expand Up @@ -42,15 +42,17 @@ Future<int> linkDependencies({
dependencies.addAll(result.packages);
print('Resolved dependencies for ${resolved.path}');
} catch (e) {
print(redPen('Failed to resolve dependencies for ${resolved.path}'));
print(redPen(e));
print(
red.wrap('Failed to resolve dependencies for ${resolved.path}'),
);
print(red.wrap(e.toString()));
}
}),
);
}
await resolutionQueue.tasksComplete;
print(
greenPen(
green.wrap(
'Resolved all dependencies in ${resolutionStopwatch.prettyPrint()}',
),
);
Expand All @@ -69,16 +71,18 @@ Future<int> linkDependencies({
}
} catch (e) {
print(
redPen('Failed to download ${package.name} ${package.version}'),
red.wrap('Failed to download ${package.name} ${package.version}'),
);
print(redPen(e));
print(red.wrap(e.toString()));
}
}),
);
}
await downloadQueue.tasksComplete;
print(
greenPen('Downloaded all packages in ${downloadStopwatch.prettyPrint()}\n'),
green.wrap(
'Downloaded all packages in ${downloadStopwatch.prettyPrint()}\n',
),
);

// Stop all stopwatches
Expand Down
27 changes: 13 additions & 14 deletions bin/projects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:puby/command.dart';
import 'package:puby/config.dart';
import 'package:puby/engine.dart';
import 'package:puby/pens.dart';
import 'package:io/ansi.dart';
import 'package:puby/project.dart';
import 'package:path/path.dart' as p;

Expand All @@ -31,18 +31,18 @@ List<Project> findProjects() {
final path = p.relative(absolutePath);
final config = PubyConfig.fromProjectPath(path);

late final Pubspec? pubspec;
final Pubspec pubspec;
try {
pubspec = Pubspec.parse(pubspecEntity.readAsStringSync());
} catch (e) {
print(redPen('Error parsing pubspec: $path'));
pubspec = null;
print(red.wrap('Error parsing pubspec: $path'));
continue;
}

final Engine engine;
if (fvmPaths.any(absolutePath.startsWith)) {
engine = Engine.fvm;
} else if (pubspec?.dependencies['flutter'] != null) {
} else if (pubspec.dependencies['flutter'] != null) {
engine = Engine.flutter;
} else {
engine = Engine.dart;
Expand Down Expand Up @@ -91,14 +91,13 @@ extension ProjectExtension on Project {
}

if (message != null && !command.silent) {
print(yellowPen(message));
print(yellow.wrap(message));
}
return newEngine;
}

bool _defaultExclude(Command command) {
final isPubGetInFlutterExample = engine.isFlutter &&
example &&
final isPubGetInExample = example &&
command.args.length >= 2 &&
command.args[0] == 'pub' &&
command.args[1] == 'get';
Expand All @@ -112,17 +111,17 @@ extension ProjectExtension on Project {
} else if (path.startsWith('build/') || path.contains('/build/')) {
message = 'Skipping project in build folder: $path';
skip = true;
} else if (isPubGetInFlutterExample) {
// Skip flutter pub get in example projects since flutter does it anyways
message = 'Skipping flutter example project: $path';
} else if (isPubGetInExample) {
// Skip pub get in example projects since it happens anyways
message = 'Skipping example project: $path';
skip = true;
} else {
message = null;
skip = false;
}

if (message != null && !command.silent) {
print(yellowPen(message));
print(yellow.wrap(message));
}
return skip;
}
Expand All @@ -132,7 +131,7 @@ extension ProjectExtension on Project {

final skip = config.excludes.any(argString.startsWith);
if (skip && !command.silent) {
print(yellowPen('Skipping project with exclusion: $path'));
print(yellow.wrap('Skipping project with exclusion: $path'));
}

return skip;
Expand Down Expand Up @@ -167,7 +166,7 @@ extension ProjectExtension on Project {
}
return Version.parse(versionString);
} catch (e) {
print(redPen('Unable to determine FVM Flutter version: $path'));
print(red.wrap('Unable to determine FVM Flutter version: $path'));
return null;
}
}
Expand Down
Loading