Skip to content

Commit

Permalink
Merge branch 'main' into feat/markdown-report
Browse files Browse the repository at this point in the history
  • Loading branch information
devmil authored Sep 26, 2023
2 parents 27dc3a3 + 7b8dc02 commit 9c1e598
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
38 changes: 35 additions & 3 deletions lib/src/cli/commands/command_mixin.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:dart_apitool/api_tool.dart';
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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');
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9c1e598

Please sign in to comment.