diff --git a/packages/melos/lib/src/commands/analyze.dart b/packages/melos/lib/src/commands/analyze.dart index 17507c5e0..fcfb895c5 100644 --- a/packages/melos/lib/src/commands/analyze.dart +++ b/packages/melos/lib/src/commands/analyze.dart @@ -30,12 +30,12 @@ mixin _AnalyzeMixin on _Melos { }) async { final failures = {}; 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); @@ -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); @@ -100,12 +104,17 @@ mixin _AnalyzeMixin on _Melos { } } - List _getAnalyzeArgs( - MelosWorkspace workspace, - bool fatalInfos, + List _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 [ ..._analyzeCommandExecArgs( useFlutter: workspace.isFlutterWorkspace, @@ -115,7 +124,11 @@ mixin _AnalyzeMixin on _Melos { ]; } - String _getOptionsArgs(bool fatalInfos, bool? fatalWarnings) { + String _getOptionsArgs( + bool fatalInfos, + bool? fatalWarnings, + int concurrency, + ) { final options = []; if (fatalInfos) { @@ -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(' '); } diff --git a/packages/melos/test/commands/analyze_test.dart b/packages/melos/test/commands/analyze_test.dart index ac990dab9..292074788 100644 --- a/packages/melos/test/commands/analyze_test.dart +++ b/packages/melos/test/commands/analyze_test.dart @@ -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); + }); }); }