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..e59e982 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,25 @@ 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()) { + 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'); + } + } + // 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 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); + }); }); }