diff --git a/packages/melos/lib/src/commands/analyze.dart b/packages/melos/lib/src/commands/analyze.dart index 2d6453e8..27629d90 100644 --- a/packages/melos/lib/src/commands/analyze.dart +++ b/packages/melos/lib/src/commands/analyze.dart @@ -37,13 +37,25 @@ mixin _AnalyzeMixin on _Melos { concurrency: concurrency, ).join(' '); final useGroupBuffer = concurrency != 1 && packages.length != 1; + final dartPackageCount = packages.where((e) => !e.isFlutterPackage).length; + final flutterPackageCount = + packages.where((e) => e.isFlutterPackage).length; logger.command('melos analyze', withDollarSign: true); - logger - .child(targetStyle(analyzeArgsString)) - .child('$runningLabel (in ${packages.length} packages)') - .newLine(); + if (dartPackageCount > 0) { + logger + .child(targetStyle(analyzeArgsString)) + .child('$runningLabel (in $dartPackageCount packages)') + .newLine(); + } + + if (flutterPackageCount > 0) { + logger + .child(targetStyle(analyzeArgsString.replaceFirst('dart', 'flutter'))) + .child('$runningLabel (in $flutterPackageCount packages)') + .newLine(); + } await pool.forEach(packages, (package) async { final group = useGroupBuffer ? package.name : null; @@ -55,6 +67,7 @@ mixin _AnalyzeMixin on _Melos { workspace, package, _getAnalyzeArgs( + package: package, workspace: workspace, fatalInfos: fatalInfos, fatalWarnings: fatalWarnings, @@ -101,6 +114,7 @@ mixin _AnalyzeMixin on _Melos { List _getAnalyzeArgs({ required MelosWorkspace workspace, required bool fatalInfos, + Package? package, bool? 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 @@ -110,7 +124,7 @@ mixin _AnalyzeMixin on _Melos { }) { final options = _getOptionsArgs(fatalInfos, fatalWarnings, concurrency); return [ - if (workspace.isFlutterWorkspace) + if (package?.isFlutterPackage ?? false) workspace.sdkTool('flutter') else workspace.sdkTool('dart'), diff --git a/packages/melos/test/commands/analyze_test.dart b/packages/melos/test/commands/analyze_test.dart index 9b7ae893..ac389b46 100644 --- a/packages/melos/test/commands/analyze_test.dart +++ b/packages/melos/test/commands/analyze_test.dart @@ -277,16 +277,59 @@ $ melos analyze expect(regex.hasMatch(logger.output.normalizeNewLines()), isTrue); }); - test('should run analysis with using flutter', () async { + test('should run analysis using flutter & dart', () async { final workspaceDir = await createTemporaryWorkspace(); + await createProject( + workspaceDir, + const PubSpec( + name: 'a', + dependencies: { + 'flutter': SdkReference('flutter'), + }, + ), + ); + await createProject( workspaceDir, PubSpec( + name: 'b', + dependencies: { + 'a': HostedReference(VersionConstraint.any), + }, + ), + ); + + final config = await MelosWorkspaceConfig.fromWorkspaceRoot(workspaceDir); + + final melos = Melos( + logger: logger, + config: config, + ); + await melos.analyze(concurrency: 2); + + expect( + logger.output + .normalizeNewLines() + .contains('flutter analyze --concurrency 2'), + isTrue, + ); + + final dartRegex = + RegExp(r'\$ melos analyze\s+└> dart analyze --concurrency 2'); + + expect(dartRegex.hasMatch(logger.output.normalizeNewLines()), isTrue); + }); + + test('should run analysis using flutter', () async { + final workspaceDir = await createTemporaryWorkspace(); + + await createProject( + workspaceDir, + const PubSpec( name: 'a', dependencies: { - 'c': HostedReference(VersionConstraint.any), - 'flutter': const SdkReference('flutter'), + 'flutter': SdkReference('flutter'), }, ), ); @@ -299,10 +342,40 @@ $ melos analyze ); await melos.analyze(concurrency: 2); - final regex = + final flutterRegex = RegExp(r'\$ melos analyze\s+└> flutter analyze --concurrency 2'); - expect(regex.hasMatch(logger.output.normalizeNewLines()), isTrue); + expect(flutterRegex.hasMatch(logger.output.normalizeNewLines()), isTrue); + }); + + test('should run analysis using dart', () async { + final workspaceDir = await createTemporaryWorkspace(); + + await createProject( + workspaceDir, + const PubSpec( + name: 'a', + ), + ); + + final config = await MelosWorkspaceConfig.fromWorkspaceRoot(workspaceDir); + + final melos = Melos( + logger: logger, + config: config, + ); + await melos.analyze(concurrency: 2); + + expect( + logger.output + .normalizeNewLines() + .contains('flutter analyze --concurrency 2'), + isFalse, + ); + + final dartRegex = + RegExp(r'\$ melos analyze\s+└> dart analyze --concurrency 2'); + expect(dartRegex.hasMatch(logger.output.normalizeNewLines()), isTrue); }); test('should run analysis with --concurrency 2 flag', () async {