Skip to content

Commit

Permalink
Check if the workspace is flutter & run flutter analyze instead of da…
Browse files Browse the repository at this point in the history
…rt analyze
  • Loading branch information
mnayef95-tlb committed Nov 15, 2024
1 parent bc2da5f commit 906a0bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
22 changes: 7 additions & 15 deletions packages/melos/lib/src/commands/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ mixin _AnalyzeMixin on _Melos {
bool? fatalWarnings,
int concurrency = 1,
}) async {
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);
final workspace = await createWorkspace(global: global, packageFilters: packageFilters);
final packages = workspace.filteredPackages.values;

await _analyzeForAllPackages(
Expand Down Expand Up @@ -40,10 +39,7 @@ mixin _AnalyzeMixin on _Melos {

logger.command('melos analyze', withDollarSign: true);

logger
.child(targetStyle(analyzeArgsString))
.child('$runningLabel (in ${packages.length} packages)')
.newLine();
logger.child(targetStyle(analyzeArgsString)).child('$runningLabel (in ${packages.length} packages)').newLine();

await pool.forEach<Package, void>(packages, (package) async {
final group = useGroupBuffer ? package.name : null;
Expand All @@ -66,8 +62,7 @@ mixin _AnalyzeMixin on _Melos {
failures[package.name] = packageExitCode;
} else {
logger.log(
AnsiStyles.bgBlack.bold.italic('${package.name}: ') +
AnsiStyles.bgBlack(successLabel),
AnsiStyles.bgBlack.bold.italic('${package.name}: ') + AnsiStyles.bgBlack(successLabel),
group: group,
);
}
Expand All @@ -83,8 +78,7 @@ mixin _AnalyzeMixin on _Melos {
final resultLogger = logger.child(targetStyle(analyzeArgsString));

if (failures.isNotEmpty) {
final failuresLogger =
resultLogger.child('$failedLabel (in ${failures.length} packages)');
final failuresLogger = resultLogger.child('$failedLabel (in ${failures.length} packages)');
for (final packageName in failures.keys) {
failuresLogger.child(
'${errorPackageNameStyle(packageName)} '
Expand All @@ -110,7 +104,7 @@ mixin _AnalyzeMixin on _Melos {
}) {
final options = _getOptionsArgs(fatalInfos, fatalWarnings, concurrency);
return <String>[
workspace.sdkTool('dart'),
if (workspace.isFlutterWorkspace) workspace.sdkTool('flutter') else workspace.sdkTool('dart'),
'analyze',
options,
];
Expand Down Expand Up @@ -146,10 +140,8 @@ mixin _AnalyzeMixin on _Melos {
}) async {
final environment = {
EnvironmentVariableKey.melosRootPath: config.path,
if (workspace.sdkPath != null)
EnvironmentVariableKey.melosSdkPath: workspace.sdkPath!,
if (workspace.childProcessPath != null)
EnvironmentVariableKey.path: workspace.childProcessPath!,
if (workspace.sdkPath != null) EnvironmentVariableKey.melosSdkPath: workspace.sdkPath!,
if (workspace.childProcessPath != null) EnvironmentVariableKey.path: workspace.childProcessPath!,
};

return startCommand(
Expand Down
28 changes: 28 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,34 @@ $ melos analyze
expect(regex.hasMatch(logger.output.normalizeNewLines()), isTrue);
});

test('should run analysis with --concurrency flag', () async {
final workspaceDir = await createTemporaryWorkspace();

await createProject(
workspaceDir,
PubSpec(
name: 'a',
dependencies: {
'c': HostedReference(VersionConstraint.any),
'flutter': const SdkReference('flutter'),
},
),
);

final config = await MelosWorkspaceConfig.fromWorkspaceRoot(workspaceDir);

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

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

expect(regex.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 906a0bf

Please sign in to comment.