Extensibility improvements to flutter_tools (#14299)
* Make the current command injected into the AppContext, allowing other classes to inject the current command. * Introduce `AssetBundleFactory`, an injected factory class for spawning instances of `AssetBundle`. This allows other run contexts to use custom asset bundling logic. * Clean up RunCommand by removing a 'packages' argument that duplicated a global argument by the same name (and for the same purpose). Duplicate arguments are confusing and error-prone.
This commit is contained in:
@@ -57,7 +57,7 @@ $fontsSection
|
||||
List<String> packages,
|
||||
String expectedAssetManifest,
|
||||
) async {
|
||||
final AssetBundle bundle = new AssetBundle();
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
|
||||
for (String packageName in packages) {
|
||||
@@ -121,7 +121,7 @@ $fontsSection
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
final AssetBundle bundle = new AssetBundle();
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
expect(bundle.entries.length, 2); // LICENSE, AssetManifest
|
||||
expect(bundle.entries.containsKey('FontManifest.json'), false);
|
||||
|
||||
@@ -64,7 +64,7 @@ $assetsSection
|
||||
List<String> packages,
|
||||
String expectedAssetManifest,
|
||||
) async {
|
||||
final AssetBundle bundle = new AssetBundle();
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
|
||||
for (String packageName in packages) {
|
||||
@@ -122,7 +122,7 @@ $assetsSection
|
||||
writePackagesFile('test_package:p/p/lib/');
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
final AssetBundle bundle = new AssetBundle();
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
expect(bundle.entries.length, 2); // LICENSE, AssetManifest
|
||||
final String expectedAssetManifest = '{}';
|
||||
@@ -142,7 +142,7 @@ $assetsSection
|
||||
final List<String> assets = <String>['a/foo'];
|
||||
writeAssets('p/p/', assets);
|
||||
|
||||
final AssetBundle bundle = new AssetBundle();
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
expect(bundle.entries.length, 2); // LICENSE, AssetManifest
|
||||
final String expectedAssetManifest = '{}';
|
||||
|
||||
@@ -97,8 +97,8 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('nonempty', () async {
|
||||
final AssetBundle ab = new AssetBundle();
|
||||
testUsingContext('nonempty', () async {
|
||||
final AssetBundle ab = AssetBundleFactory.instance.createBundle();
|
||||
expect(await ab.build(), 0);
|
||||
expect(ab.entries.length, greaterThan(0));
|
||||
});
|
||||
@@ -108,7 +108,7 @@ void main() {
|
||||
..createSync()
|
||||
..writeAsStringSync('');
|
||||
|
||||
final AssetBundle bundle = new AssetBundle();
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
expect(bundle.entries.length, 1);
|
||||
final String expectedAssetManifest = '{}';
|
||||
|
||||
@@ -71,7 +71,7 @@ flutter:
|
||||
..writeAsStringSync(asset);
|
||||
}
|
||||
|
||||
AssetBundle bundle = new AssetBundle();
|
||||
AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
|
||||
// The main asset file, /a/b/c/foo, and its variants exist.
|
||||
@@ -81,7 +81,7 @@ flutter:
|
||||
}
|
||||
|
||||
fs.file('a/b/c/foo').deleteSync();
|
||||
bundle = new AssetBundle();
|
||||
bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
|
||||
// Now the main asset file, /a/b/c/foo, does not exist. This is OK because
|
||||
|
||||
@@ -29,7 +29,7 @@ void main() {
|
||||
// This test intentionally does not use a memory file system to ensure
|
||||
// that AssetBundle with fonts also works on Windows.
|
||||
testUsingContext('app font uses local font file', () async {
|
||||
final AssetBundle asset = new AssetBundle();
|
||||
final AssetBundle asset = AssetBundleFactory.instance.createBundle();
|
||||
await asset.build(
|
||||
manifestPath : fs.path.join(dataPath, 'main', 'pubspec.yaml'),
|
||||
packagesPath: fs.path.join(dataPath, 'main', '.packages'),
|
||||
|
||||
@@ -27,7 +27,7 @@ void main() {
|
||||
Directory tempDir;
|
||||
String basePath;
|
||||
DevFS devFS;
|
||||
final AssetBundle assetBundle = new AssetBundle();
|
||||
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
|
||||
|
||||
setUpAll(() {
|
||||
fs = new MemoryFileSystem();
|
||||
|
||||
Reference in New Issue
Block a user