Reland "Stop recursively including assets from asset directories" (#120312)

* stop recursively including assets from asset directories

* remove unused imports

* lint
This commit is contained in:
Andrew Kolos
2023-02-08 21:41:19 +00:00
committed by GitHub
parent 2303f42250
commit 4a9660881e
3 changed files with 49 additions and 16 deletions

View File

@@ -909,22 +909,6 @@ class ManifestAssetBundle implements AssetBundle {
attributedPackage: attributedPackage,
);
}
final Iterable<Directory> nonVariantSubDirectories = entities
.whereType<Directory>()
.where((Directory directory) => !_assetVariantDirectoryRegExp.hasMatch(directory.basename));
for (final Directory dir in nonVariantSubDirectories) {
final String relativePath = _fileSystem.path.relative(dir.path, from: assetBase);
final Uri relativePathsUri = Uri.directory(relativePath, windows: _platform.isWindows);
_parseAssetsFromFolder(packageConfig,
flutterManifest,
assetBase,
cache,
result,
relativePathsUri
);
}
}
void _parseAssetFromFile(

View File

@@ -69,6 +69,51 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('wildcard directories do not include subdirectories', () async {
globals.fs.file('.packages').createSync();
globals.fs.file('pubspec.yaml').writeAsStringSync(
'''
name: test
dependencies:
flutter:
sdk: flutter
flutter:
assets:
- assets/foo/
- assets/bar/lizard.png
'''
);
final List<String> assets = <String>[
'assets/foo/dog.png',
'assets/foo/sub/cat.png',
'assets/bar/lizard.png',
'assets/bar/sheep.png'
];
for (final String asset in assets) {
final File assetFile = globals.fs.file(
globals.fs.path.joinAll(asset.split('/'))
);
assetFile.createSync(recursive: true);
}
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
expect(bundle.entries.keys, unorderedEquals(<String>[
'AssetManifest.json',
'AssetManifest.bin',
'FontManifest.json',
'NOTICES.Z',
'assets/foo/dog.png',
'assets/bar/lizard.png'
]));
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('wildcard directories are updated when filesystem changes', () async {
final File packageFile = globals.fs.file('.packages')..createSync();
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);

View File

@@ -54,6 +54,9 @@ dependencies:
flutter:
assets:
- assets/
- assets/notAVariant/
- assets/folder/
- assets/normalFolder/
'''
);
});
@@ -184,6 +187,7 @@ dependencies:
flutter:
assets:
- assets/
- assets/somewhereElse/
'''
);
});