Skip to content

Commit

Permalink
fix: Run flutter analyze for flutter packages (#793)
Browse files Browse the repository at this point in the history
## Description
Current `melos analyze` command is running `dart analyze` instead of
`flutter analyze` on flutter projects
#792

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ] ✨ `feat` -- New feature (non-breaking change which adds
functionality)
- [x] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 `refactor` -- Code refactor
- [ ] ✅ `ci` -- Build configuration change
- [ ] 📝 `docs` -- Documentation
- [ ] 🗑️ `chore` -- Chore
  • Loading branch information
mnayef95 authored Nov 16, 2024
1 parent bc2da5f commit e804822
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 5 deletions.
27 changes: 22 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,10 @@ mixin _AnalyzeMixin on _Melos {
}) {
final options = _getOptionsArgs(fatalInfos, fatalWarnings, concurrency);
return <String>[
workspace.sdkTool('dart'),
if (package?.isFlutterPackage ?? false)
workspace.sdkTool('flutter')
else
workspace.sdkTool('dart'),
'analyze',
options,
];
Expand Down
100 changes: 100 additions & 0 deletions packages/melos/test/commands/analyze_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,106 @@ $ melos analyze
expect(regex.hasMatch(logger.output.normalizeNewLines()), isTrue);
});

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: {
'flutter': SdkReference('flutter'),
},
),
);

final config = await MelosWorkspaceConfig.fromWorkspaceRoot(workspaceDir);

final melos = Melos(
logger: logger,
config: config,
);
await melos.analyze(concurrency: 2);

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

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 {
await melos.analyze(concurrency: 2);

Expand Down

0 comments on commit e804822

Please sign in to comment.