From fb0871d3a27dc2dae2ffe89f4b0f4010b1280a17 Mon Sep 17 00:00:00 2001 From: devmil Date: Fri, 6 Dec 2024 22:33:38 +0100 Subject: [PATCH 1/3] fix: remove dependency_overrides from temporary pubspec.yaml to make pub get not run into issues --- CHANGELOG.md | 3 +++ lib/src/cli/commands/command_mixin.dart | 15 +++++++++++++++ pubspec.yaml | 1 + 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8c0da3..712b83f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Version 0.20.1 +- fix: remove dependency overrides from the pubspec.yaml file of the package to analyze as those might point to relative paths that are not resolvable in the context of the package to analyze + ## Version 0.20.0 - update analyzer's lower boundary to avoid the 'withNullability' required param (it is required on lower versions) diff --git a/lib/src/cli/commands/command_mixin.dart b/lib/src/cli/commands/command_mixin.dart index ab4df17..cc96fe3 100644 --- a/lib/src/cli/commands/command_mixin.dart +++ b/lib/src/cli/commands/command_mixin.dart @@ -5,6 +5,7 @@ import 'package:args/args.dart'; import 'package:dart_apitool/api_tool.dart'; import 'package:dart_apitool/src/cli/source_item.dart'; import 'package:path/path.dart' as p; +import 'package:pubspec_manager/pubspec_manager.dart'; import '../package_ref.dart'; import '../prepared_package_ref.dart'; @@ -175,6 +176,20 @@ OBSOLETE: Has no effect anymore. await Directory(exampleDirPath).delete(recursive: true); } + // remove any dependency overrides from the pubspec.yaml + final pubspecFile = File(p.join(packagePath, 'pubspec.yaml')); + if (pubspecFile.existsSync()) { + final pubSpec = PubSpec.load(directory: packagePath); + // removeAll of dependencyOverrides has an issue in the current version of pubspec_manager + // as it doesn't remove the section part of the dependency overrides and therefore are not removed + // in the saved version of the pubspec.yaml file + // workaround: remove all dependency overrides manually + for (final depOverride in pubSpec.dependencyOverrides.list) { + pubSpec.dependencyOverrides.remove(depOverride.name); + } + pubSpec.save(); + } + // Check if the package_config.json is already present from the preparation step final packageConfig = File(_getPackageConfigPathForPackage(packagePath)); if (!packageConfig.existsSync()) { diff --git a/pubspec.yaml b/pubspec.yaml index e1e9d90..d4b7879 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,6 +20,7 @@ dependencies: path: ^1.9.0 plist_parser: ^0.0.9 pub_semver: ^2.1.4 + pubspec_manager: ^1.0.0 pubspec_parse: ^1.2.0 stack: ^0.2.1 tuple: ^2.0.0 From a09fd91f1ff50730a54308e2337b996d037df19e Mon Sep 17 00:00:00 2001 From: devmil Date: Fri, 6 Dec 2024 23:10:42 +0100 Subject: [PATCH 2/3] add try-catch to package manager as this package seems to be quite fragile add test for ffigen issue that gets fixed by this PR --- lib/src/cli/commands/command_mixin.dart | 22 ++++++++++++------- .../cli/extract_command_test.dart | 11 ++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/src/cli/commands/command_mixin.dart b/lib/src/cli/commands/command_mixin.dart index cc96fe3..26d872b 100644 --- a/lib/src/cli/commands/command_mixin.dart +++ b/lib/src/cli/commands/command_mixin.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:dart_apitool/api_tool.dart'; import 'package:dart_apitool/src/cli/source_item.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:path/path.dart' as p; import 'package:pubspec_manager/pubspec_manager.dart'; @@ -179,15 +180,20 @@ OBSOLETE: Has no effect anymore. // remove any dependency overrides from the pubspec.yaml final pubspecFile = File(p.join(packagePath, 'pubspec.yaml')); if (pubspecFile.existsSync()) { - final pubSpec = PubSpec.load(directory: packagePath); - // removeAll of dependencyOverrides has an issue in the current version of pubspec_manager - // as it doesn't remove the section part of the dependency overrides and therefore are not removed - // in the saved version of the pubspec.yaml file - // workaround: remove all dependency overrides manually - for (final depOverride in pubSpec.dependencyOverrides.list) { - pubSpec.dependencyOverrides.remove(depOverride.name); + try { + final pubSpec = PubSpec.load(directory: packagePath); + // removeAll of dependencyOverrides has an issue in the current version of pubspec_manager + // as it doesn't remove the section part of the dependency overrides and therefore are not removed + // in the saved version of the pubspec.yaml file + // workaround: remove all dependency overrides manually + for (final depOverride in pubSpec.dependencyOverrides.list) { + pubSpec.dependencyOverrides.remove(depOverride.name); + } + pubSpec.save(); + } catch (e) { + await stdoutSession.writeln( + 'Error removing dependency overrides from pubspec.yaml: $e'); } - pubSpec.save(); } // Check if the package_config.json is already present from the preparation step diff --git a/test/integration_tests/cli/extract_command_test.dart b/test/integration_tests/cli/extract_command_test.dart index 8119c97..454cb54 100644 --- a/test/integration_tests/cli/extract_command_test.dart +++ b/test/integration_tests/cli/extract_command_test.dart @@ -240,5 +240,16 @@ void main() { }, timeout: integrationTestTimeout, ); + test('Can handle ffigen dependency overrides correctly', () async { + final packageName = 'ffigen'; + final packageVersion = '16.0.0'; + + final exitCode = await runner.run([ + 'extract', + '--input', + 'pub://$packageName/$packageVersion', + ]); + expect(exitCode, 0); + }); }); } From 8efe7a4990a24c4a86bc3c88d70f9a5e32d29d8f Mon Sep 17 00:00:00 2001 From: devmil Date: Fri, 6 Dec 2024 23:23:34 +0100 Subject: [PATCH 3/3] fix analyzer issue --- lib/src/cli/commands/command_mixin.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/cli/commands/command_mixin.dart b/lib/src/cli/commands/command_mixin.dart index 26d872b..e59e982 100644 --- a/lib/src/cli/commands/command_mixin.dart +++ b/lib/src/cli/commands/command_mixin.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:dart_apitool/api_tool.dart'; import 'package:dart_apitool/src/cli/source_item.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:path/path.dart' as p; import 'package:pubspec_manager/pubspec_manager.dart';