Skip to content

Commit 83c57de

Browse files
authored
👷 Check bootstrappable package as a prehook of melos and log checked packages (#2363)
Picked and updated from #2362
1 parent 779ccf0 commit 83c57de

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

‎melos.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ ide:
1616
command:
1717
bootstrap:
1818
runPubGetInParallel: false
19+
hooks:
20+
pre: |
21+
# Check bootstrappable packages.
22+
dart ./scripts/melos_packages.dart
1923
clean:
2024
hooks:
2125
post: |

‎scripts/melos_packages.dart

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:io';
22

33
import 'package:cli_util/cli_logging.dart' show Logger;
44
import 'package:melos/melos.dart'
5-
show MelosLogger, MelosWorkspace, MelosWorkspaceConfig;
5+
show MelosLogger, MelosWorkspace, MelosWorkspaceConfig, Package;
66
import 'package:path/path.dart' as p;
77
import 'package:pub_semver/pub_semver.dart';
88
import 'package:yaml/yaml.dart';
@@ -40,30 +40,42 @@ void main() async {
4040
}
4141
}
4242

43-
final current = Version.parse(
43+
final currentDart = Version.parse(
4444
RegExp(r'\d*\.\d*\.\d*').firstMatch(Platform.version)!.group(0)!,
4545
);
46-
final validPackages = packages.where((e) {
46+
final overridePackages = <Package>[];
47+
final ignoredPackages = <Package>[];
48+
for (final e in packages) {
4749
final dynamic package = e as dynamic;
4850
bool allows;
4951
try {
5052
// Compatible with melos v6.3.
51-
allows = package.pubspec.environment['sdk']!.allows(current);
53+
allows = package.pubspec.environment['sdk']!.allows(currentDart);
5254
} on NoSuchMethodError {
5355
// Fallback to previous melos.
54-
allows = package.pubSpec.environment!.sdkConstraint!.allows(current);
56+
allows = package.pubSpec.environment!.sdkConstraint!.allows(currentDart);
5557
}
56-
return allows;
57-
});
58+
if (allows) {
59+
overridePackages.add(e);
60+
} else {
61+
ignoredPackages.add(e);
62+
}
63+
}
5864

59-
// Create melos marker files
60-
for (final package in validPackages) {
65+
// Create melos marker files.
66+
for (final package in overridePackages) {
6167
File(p.join(package.path, '.melos_package')).createSync();
6268
}
6369

64-
final validPackagesString = validPackages.map((p) => p.name).join(',');
70+
final overridePackagesString = overridePackages.map((p) => p.name).join(',');
71+
final ignoredPackagesString = ignoredPackages.map((p) => p.name).join(',');
72+
print(
73+
'Checked valid packages: \n'
74+
' [override]: $overridePackagesString\n'
75+
' [ignored]: $ignoredPackagesString',
76+
);
6577
File('$root/.melos_packages')
66-
.writeAsStringSync('MELOS_PACKAGES=$validPackagesString');
78+
.writeAsStringSync('MELOS_PACKAGES=$overridePackagesString');
6779
}
6880

6981
extension YamlUtils on YamlNode {

0 commit comments

Comments
 (0)