Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes local package refs #161

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading