diff --git a/CHANGELOG.md b/CHANGELOG.md index 33abe9b..e7ded60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ # Changelog -## Version 0.16.2 +## Version 0.16.3 - adds more diff result reporting options (cli, json, markdown) +## Version 0.16.2 +- fixes relative path handling in package config (leading to unresolvable types) + ## Version 0.16.1 - fixes issues with pubspec_overrides.yaml that got published with a pub package diff --git a/lib/src/cli/commands/command_mixin.dart b/lib/src/cli/commands/command_mixin.dart index a7cbf8a..79a2184 100644 --- a/lib/src/cli/commands/command_mixin.dart +++ b/lib/src/cli/commands/command_mixin.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:io'; import 'package:dart_apitool/api_tool.dart'; @@ -79,6 +80,10 @@ OBSOLETE: Has no effect anymore. File(_getPackageConfigPathForPackage(tempDir.path)) ..createSync(recursive: true); await sourcePackageConfig.copy(targetPackageConfig.path); + await _adaptPackageConfigToAbsolutePaths( + targetPackageConfigPath: targetPackageConfig.absolute.path, + sourcePackageConfigPath: sourcePackageConfig.absolute.path, + ); } else { await stdoutSession.writeln('Cleaning up local copy of pub package'); // Check if we have a pub package that bundles a pubspec_overrides.yaml (as this most probably destroys pub get) @@ -190,7 +195,34 @@ OBSOLETE: Has no effect anymore. } } } -} -String _getPackageConfigPathForPackage(String packagePath) => - p.join(packagePath, '.dart_tool', 'package_config.json'); + Future _adaptPackageConfigToAbsolutePaths({ + required String targetPackageConfigPath, + required String sourcePackageConfigPath, + }) async { + final sourcePackageConfigDirPath = p.dirname(sourcePackageConfigPath); + final targetPackageConfigContent = + jsonDecode(await File(targetPackageConfigPath).readAsString()); + // iterate through the package_config.json content and look for relative paths + for (final packageConfig in targetPackageConfigContent['packages']) { + final rootUri = Uri.parse(packageConfig['rootUri']); + final packagePath = p.fromUri(rootUri); + if (p.isRelative(packagePath)) { + // we make the relative path absolute by using the origin of the source package config as a base + final normalizedPackagePath = + p.normalize(p.join(sourcePackageConfigDirPath, packagePath)); + // and write the new absolute path back to the json structure + packageConfig['rootUri'] = p.toUri(normalizedPackagePath).toString(); + } + } + final encoder = JsonEncoder.withIndent(' '); + // replace the package config with the new content + await File(targetPackageConfigPath).writeAsString( + encoder.convert(targetPackageConfigContent), + mode: FileMode.write, + ); + } + + String _getPackageConfigPathForPackage(String packagePath) => + p.join(packagePath, '.dart_tool', 'package_config.json'); +} diff --git a/pubspec.yaml b/pubspec.yaml index 4662409..0743117 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: dart_apitool description: A tool to analyze the public API of a package, create a model of it and diff it against another version to check semver. repository: https://github.com/bmw-tech/dart_apitool -version: 0.16.2-dev +version: 0.16.3-dev environment: sdk: ">=2.17.5 <3.0.0"