Skip to content

Commit

Permalink
Run flutter analyze only for flutter packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mnayef95 committed Nov 15, 2024
1 parent adb6939 commit 2ab1af3
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 10 deletions.
24 changes: 19 additions & 5 deletions packages/melos/lib/src/commands/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Package, void>(packages, (package) async {
final group = useGroupBuffer ? package.name : null;
Expand All @@ -55,6 +67,7 @@ mixin _AnalyzeMixin on _Melos {
workspace,
package,
_getAnalyzeArgs(
package: package,
workspace: workspace,
fatalInfos: fatalInfos,
fatalWarnings: fatalWarnings,
Expand Down Expand Up @@ -101,6 +114,7 @@ mixin _AnalyzeMixin on _Melos {
List<String> _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
Expand All @@ -110,7 +124,7 @@ mixin _AnalyzeMixin on _Melos {
}) {
final options = _getOptionsArgs(fatalInfos, fatalWarnings, concurrency);
return <String>[
if (workspace.isFlutterWorkspace)
if (package?.isFlutterPackage ?? false)
workspace.sdkTool('flutter')
else
workspace.sdkTool('dart'),
Expand Down
83 changes: 78 additions & 5 deletions packages/melos/test/commands/analyze_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
},
),
);
Expand All @@ -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 {
Expand Down

0 comments on commit 2ab1af3

Please sign in to comment.