Skip to content

Commit

Permalink
fix: fixes local package refs by not adapting the relative path to th…
Browse files Browse the repository at this point in the history
…e main package
  • Loading branch information
devmil committed Sep 28, 2023
1 parent 147f657 commit 40416bf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 0.16.3
- adds more diff result reporting options (cli, json, markdown)
- fixes broken local packages refs

## Version 0.16.2
- fixes relative path handling in package config (leading to unresolvable types)
Expand Down
6 changes: 6 additions & 0 deletions lib/src/cli/commands/command_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ OBSOLETE: Has no effect anymore.
required String sourcePackageConfigPath,
}) async {
final sourcePackageConfigDirPath = p.dirname(sourcePackageConfigPath);
final sourcePackageDirPath =
Directory(sourcePackageConfigDirPath).parent.path;
final targetPackageConfigContent =
jsonDecode(await File(targetPackageConfigPath).readAsString());
// iterate through the package_config.json content and look for relative paths
Expand All @@ -211,6 +213,10 @@ OBSOLETE: Has no effect anymore.
// 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));
// if the relative path is the package path, then don't make it absolute
if (p.equals(sourcePackageDirPath, normalizedPackagePath)) {
continue;
}
// and write the new absolute path back to the json structure
packageConfig['rootUri'] = p.toUri(normalizedPackagePath).toString();
}
Expand Down
39 changes: 39 additions & 0 deletions test/integration_tests/cli/extract_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,45 @@ void main() {
timeout: integrationTestTimeout,
);

test(
'local packages don\'t break own package refs',
() async {
final tempDir = await Directory.systemTemp.createTemp();
final tempFilePath = path.join(tempDir.path, 'extract_paths_test.json');
final exitCode = await runner.run([
'extract',
'--input',
path.join(
'test',
'test_packages',
'path_references',
'cluster_a',
'package_a',
),
'--output',
tempFilePath,
]);
expect(exitCode, 0);

final jsonReportFile = File(tempFilePath);
expect(await jsonReportFile.exists(), isTrue);

final jsonReport = jsonDecode(await jsonReportFile.readAsString());
await tempDir.delete(recursive: true);

// check if the thisIsAMixinField in ClassA was extracted
final interfaceDeclarations =
jsonReport['packageApi']['interfaceDeclarations'] as List;
final classADeclaration =
interfaceDeclarations.singleWhere((id) => id['name'] == 'ClassA');
final thisIsAMixinFields =
(classADeclaration['fieldDeclarations'] as List)
.where((fd) => fd['name'] == 'thisIsAMixinField');
expect(thisIsAMixinFields.length, 1);
},
timeout: integrationTestTimeout,
);

test(
'Can handle pub ref',
() async {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:meta/meta.dart';
import 'package:package_b/package_b.dart';
import 'package:package_a/types/mixin_a.dart';

@experimental
class ClassA {
class ClassA with MixinA {
final ClassB classB;

ClassA({required this.classB});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mixin MixinA {
int thisIsAMixinField;
}

0 comments on commit 40416bf

Please sign in to comment.