Skip to content

Commit de60d52

Browse files
committed
Remove offline package resolution
1 parent 1e34b21 commit de60d52

File tree

3 files changed

+6
-1437
lines changed

3 files changed

+6
-1437
lines changed

packages/custom_lint/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased patch
2+
3+
- Removed offline package resolution for the analyzer plugin.
4+
The logic seemed broken at times, so removing it should make custom_lint more stable.
5+
16
## 0.6.6 - 2024-09-08
27

38
- Fixed an error in the CLI when Flutter generates code under `.dart_tool/` or has dependencies on iOS libraries (thanks to @Kurogoma4D)

packages/custom_lint/lib/src/workspace.dart

+1-99
Original file line numberDiff line numberDiff line change
@@ -749,83 +749,6 @@ publish_to: 'none'
749749
return buffer.toString();
750750
}
751751

752-
/// Generate a package_config.json combining all the dependencies from all
753-
/// the contextRoots.
754-
///
755-
/// This also changes relative paths into absolute paths.
756-
Map<String, Package> _computeDependencies() {
757-
final conflictingPackagesChecker = _ConflictingPackagesChecker();
758-
759-
// A cache object to avoid parsing the same pubspec multiple times,
760-
// as two plugins might depend on the same package.
761-
// We still want to visit the dependencies of the package multiple times,
762-
// as the resolved package in the project's package_config.json might be different.
763-
final pubspecCache = PubspecCache();
764-
final visitedPackages = <String>{};
765-
766-
Iterable<Package> visitPluginsAndDependencies() sync* {
767-
for (final project in projects) {
768-
for (final plugin in project.plugins) {
769-
final packages = plugin._visitSelfAndTransitiveDependencies(
770-
pubspecCache,
771-
);
772-
773-
for (final package in packages) {
774-
conflictingPackagesChecker.addPluginPackage(
775-
project,
776-
plugin,
777-
package,
778-
workingDirectory: workingDirectory,
779-
);
780-
781-
/// Only add a package in the package_config.json if it was not already added.
782-
/// We do not care about version conflicts here and assume that the
783-
/// previously added package is the correct one.
784-
/// Version conflicts will be checked later with
785-
/// [ConflictingPackagesChecker.throwErrorIfConflictingPackages].
786-
if (visitedPackages.add(package.package.name)) {
787-
yield package.package;
788-
}
789-
}
790-
}
791-
}
792-
}
793-
794-
final result = <String, Package>{
795-
for (final package in visitPluginsAndDependencies())
796-
package.name: package,
797-
};
798-
799-
// Check if there are conflicting packages.
800-
// We do so after computing the result to avoid allocating a temporary
801-
// list of packages, by visiting dependencies using an Iterable instead of List.
802-
conflictingPackagesChecker.throwErrorIfConflictingPackages();
803-
804-
return result;
805-
}
806-
807-
String _computePackageConfig(Map<String, Package> dependencies) {
808-
return jsonEncode(<String, Object?>{
809-
'configVersion': 2,
810-
'generated': DateTime.now().toIso8601String(),
811-
'generator': 'custom_lint',
812-
'generatorVersion': '0.0.1',
813-
'packages': <Object?>[
814-
for (final dependency in dependencies.values)
815-
{
816-
'name': dependency.name,
817-
// This is somehow enough to change relative paths into absolute ones.
818-
// It seems that PackageConfig.parse already converts the paths into
819-
// absolute ones.
820-
'rootUri': dependency.root.toString(),
821-
'packageUri': dependency.packageUriRoot.toString(),
822-
'languageVersion': dependency.languageVersion.toString(),
823-
'extraData': dependency.extraData.toString(),
824-
},
825-
],
826-
});
827-
}
828-
829752
/// First attempts at creating the plugin host locally. And if it fails,
830753
/// it will fallback to resolving packages using "pub get".
831754
Future<void> resolvePluginHost(
@@ -839,28 +762,7 @@ publish_to: 'none'
839762
tempDir.pubspecOverrides.writeAsStringSync(pubspecOverride);
840763
}
841764

842-
try {
843-
await resolvePackageConfigOffline(tempDir);
844-
} catch (_) {
845-
await runPubGet(tempDir);
846-
}
847-
}
848-
849-
/// Attempts at creating the plugin host without having to run "pub get".
850-
///
851-
/// This works by combining all the `package_config.json` of the various
852-
/// plugins.
853-
///
854-
/// May throw if failed to create the plugin host.
855-
/// Will throw a [PackageVersionConflictException] if there are conflicting
856-
/// versions of the same package.
857-
Future<void> resolvePackageConfigOffline(Directory tempDir) async {
858-
final dependencies = _computeDependencies();
859-
final packageConfigContent = _computePackageConfig(dependencies);
860-
final packageConfigFile = tempDir.packageConfig;
861-
862-
await packageConfigFile.create(recursive: true);
863-
await packageConfigFile.writeAsString(packageConfigContent);
765+
await runPubGet(tempDir);
864766
}
865767

866768
/// Run "pub get" in the client project.

0 commit comments

Comments
 (0)