Unverified Commit 74dfc070 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Treat assets as variants only if they share the same filename (#112602)

parent 5c68452d
...@@ -1033,16 +1033,18 @@ class _AssetDirectoryCache { ...@@ -1033,16 +1033,18 @@ class _AssetDirectoryCache {
final List<FileSystemEntity> entitiesInDirectory = _fileSystem.directory(directory).listSync(); final List<FileSystemEntity> entitiesInDirectory = _fileSystem.directory(directory).listSync();
final File assetFile = _fileSystem.file(assetPath);
final List<String> pathsOfVariants = <String>[ final List<String> pathsOfVariants = <String>[
// It's possible that the user specifies only explicit variants (e.g. .../1x/asset.png), // It's possible that the user specifies only explicit variants (e.g. .../1x/asset.png),
// so there does not necessarily need to be a file at the given path. // so there does not necessarily need to be a file at the given path.
if (_fileSystem.file(assetPath).existsSync()) if (assetFile.existsSync())
assetPath, assetPath,
...entitiesInDirectory ...entitiesInDirectory
.whereType<Directory>() .whereType<Directory>()
.where((Directory dir) => _assetVariantDirectoryRegExp.hasMatch(dir.basename)) .where((Directory dir) => _assetVariantDirectoryRegExp.hasMatch(dir.basename))
.expand((Directory dir) => dir.listSync()) .expand((Directory dir) => dir.listSync())
.whereType<File>() .whereType<File>()
.where((File file) => file.basename == assetFile.basename)
.map((File file) => file.path), .map((File file) => file.path),
]; ];
......
...@@ -219,14 +219,18 @@ $assetsSection ...@@ -219,14 +219,18 @@ $assetsSection
writePubspecFile( writePubspecFile(
'p/p/pubspec.yaml', 'p/p/pubspec.yaml',
'test_package', 'test_package',
assets: <String>['a/foo'], assets: <String>['a/foo', 'a/bar'],
); );
final List<String> assets = <String>['a/foo', 'a/2x/foo']; final List<String> assets = <String>['a/foo', 'a/2x/foo', 'a/bar'];
writeAssets('p/p/', assets); writeAssets('p/p/', assets);
const String expectedManifest = '{"packages/test_package/a/foo":' const String expectedManifest = '{'
'["packages/test_package/a/foo","packages/test_package/a/2x/foo"]}'; '"packages/test_package/a/bar":'
'["packages/test_package/a/bar"],'
'"packages/test_package/a/foo":'
'["packages/test_package/a/foo","packages/test_package/a/2x/foo"]'
'}';
await buildAndVerifyAssets( await buildAndVerifyAssets(
assets, assets,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment