Skip to content

Commit

Permalink
Use package name when creating transforms instead of folder path.
Browse files Browse the repository at this point in the history
This fixes the issue of creating package uri's with version numbers in them like 'package:go_router-7.0.0/...', and so failing to match the transform.

fixes #52233

Change-Id: I49aaf28c2294264a5f592318d1d4050c449b386c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350685
Commit-Queue: Keerti Parthasarathy <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
keertip authored and Commit Queue committed Feb 7, 2024
1 parent d9797db commit 3b3abb2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TransformSetManager {
var packages = package.packagesAvailableTo(libraryPath);
for (var package in packages.packages) {
var folder = package.libFolder;
transformSets.addAll(fromFolder(folder));
transformSets.addAll(fromFolder(folder, packageName: package.name));
}
if (_sdkCache != null) {
transformSets.add(_sdkCache!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ class TransformSetManagerTest extends AbstractContextTest {
manager.clearCache();
}

Future<void> test_package_folder_with_version() async {
_addDataFile('p1-1.0');

writeTestPackageConfig(
config: PackageConfigFileBuilder()
..add(name: 'p1', rootPath: '$workspaceRootPath/p1-1.0'));

newFile('/home/test/pubspec.yaml', '');

var testFile = convertPath('$testPackageLibPath/test.dart');
newFile(testFile, '');
var result = await (await session).getResolvedLibraryValid(testFile);
var sets = manager.forLibrary(result.element);
expect(sets, hasLength(1));
var elementMatcher = ElementMatcher(
importedUris: [Uri.parse('package:p1/test.dart')],
components: ['A'],
kinds: [ElementKind.classKind]);

var set = sets.first.transformsFor(elementMatcher, applyingBulkFixes: true);
expect(set, isNotEmpty);
expect(
set.first.element.libraryUris.first.path,
equals('p1/test.dart'),
);
}

Future<void> test_twoFiles_onePackage() async {
var folder = '$workspaceRootPath/p1/lib/fix_data';

Expand Down

0 comments on commit 3b3abb2

Please sign in to comment.