Skip to content

Commit

Permalink
fix: melos analyze concurrency flag log output (#678)
Browse files Browse the repository at this point in the history
* chore: add concurrency flag as log output

* test: add analyze command concurrency flag support
  • Loading branch information
jessicatarra authored Mar 26, 2024
1 parent 09f2173 commit 2ee575e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
43 changes: 30 additions & 13 deletions packages/melos/lib/src/commands/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ mixin _AnalyzeMixin on _Melos {
}) async {
final failures = <String, int?>{};
final pool = Pool(concurrency);
final analyzeArgs = _getAnalyzeArgs(
workspace,
fatalInfos,
fatalWarnings,
);
final analyzeArgsString = analyzeArgs.join(' ');
final analyzeArgsString = _getAnalyzeArgs(
workspace: workspace,
fatalInfos: fatalInfos,
fatalWarnings: fatalWarnings,
concurrency: concurrency,
).join(' ');
final prefixLogs = concurrency != 1 && packages.length != 1;

logger.command('melos analyze', withDollarSign: true);
Expand All @@ -62,7 +62,11 @@ mixin _AnalyzeMixin on _Melos {
final packageExitCode = await _analyzeForPackage(
workspace,
package,
analyzeArgs,
_getAnalyzeArgs(
workspace: workspace,
fatalInfos: fatalInfos,
fatalWarnings: fatalWarnings,
),
);

packageResults[package.name]?.complete(packageExitCode);
Expand Down Expand Up @@ -100,12 +104,17 @@ mixin _AnalyzeMixin on _Melos {
}
}

List<String> _getAnalyzeArgs(
MelosWorkspace workspace,
bool fatalInfos,
List<String> _getAnalyzeArgs({
required MelosWorkspace workspace,
required bool fatalInfos,
bool? fatalWarnings,
) {
final options = _getOptionsArgs(fatalInfos, fatalWarnings);
// Note: The `concurrency` argument is intentionally set to a default value
// of 1 to prevent its direct use by the `startCommand` function. It is
// designed to be utilized only for logging purposes to indicate the level
// of concurrency being applied.
int concurrency = 1,
}) {
final options = _getOptionsArgs(fatalInfos, fatalWarnings, concurrency);
return <String>[
..._analyzeCommandExecArgs(
useFlutter: workspace.isFlutterWorkspace,
Expand All @@ -115,7 +124,11 @@ mixin _AnalyzeMixin on _Melos {
];
}

String _getOptionsArgs(bool fatalInfos, bool? fatalWarnings) {
String _getOptionsArgs(
bool fatalInfos,
bool? fatalWarnings,
int concurrency,
) {
final options = <String>[];

if (fatalInfos) {
Expand All @@ -126,6 +139,10 @@ mixin _AnalyzeMixin on _Melos {
options.add(fatalWarnings ? '--fatal-warnings' : '--no-fatal-warnings');
}

if (concurrency > 1) {
options.add('--concurrency $concurrency');
}

return options.join(' ');
}

Expand Down
11 changes: 11 additions & 0 deletions packages/melos/test/commands/analyze_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,16 @@ $ melos analyze
'''),
);
});

test('should run analysis with --concurrency flag', () async {
// when concurrency is set to a number bigger than 1 then
// the output should appears as the following
await melos.analyze(concurrency: 2);

final regex =
RegExp(r'\$ melos analyze\s+└> dart analyze --concurrency 2');

expect(regex.hasMatch(logger.output.normalizeNewLines()), isTrue);
});
});
}

0 comments on commit 2ee575e

Please sign in to comment.