[flutter_tools] ensure package_config is re-created if pub get is run (#57184)
This commit is contained in:
@@ -249,14 +249,19 @@ Future<Directory> _templateImageDirectory(String name, FileSystem fileSystem) as
|
||||
if (!fileSystem.file(packageFilePath).existsSync()) {
|
||||
await _ensurePackageDependencies(toolPackagePath);
|
||||
}
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
fileSystem.file(packageFilePath),
|
||||
logger: globals.logger,
|
||||
);
|
||||
final Uri imagePackageLibDir = packageConfig['flutter_template_images']?.packageUriRoot;
|
||||
Uri imagePackageLibDir = packageConfig['flutter_template_images']?.packageUriRoot;
|
||||
// Ensure that the template image package is present.
|
||||
if (imagePackageLibDir == null || !fileSystem.directory(imagePackageLibDir).existsSync()) {
|
||||
await _ensurePackageDependencies(toolPackagePath);
|
||||
packageConfig = await loadPackageConfigWithLogging(
|
||||
fileSystem.file(packageFilePath),
|
||||
logger: globals.logger,
|
||||
);
|
||||
imagePackageLibDir = packageConfig['flutter_template_images']?.packageUriRoot;
|
||||
}
|
||||
return fileSystem.directory(imagePackageLibDir)
|
||||
.parent
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/dart/pub.dart';
|
||||
import 'package:flutter_tools/src/template.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -77,12 +78,21 @@ void main() {
|
||||
.childDirectory('flutter_tools')
|
||||
.childFile('.packages');
|
||||
packagesFile.createSync(recursive: true);
|
||||
packagesFile.writeAsStringSync('flutter_template_images:file:///flutter_template_images');
|
||||
packagesFile.writeAsStringSync('\n');
|
||||
|
||||
// Attempting to run pub in a test throws.
|
||||
await expectLater(Template.fromName('app', fileSystem: fileSystem),
|
||||
throwsUnsupportedError);
|
||||
when(pub.get(
|
||||
context: PubContext.pubGet,
|
||||
directory: anyNamed('directory'),
|
||||
)).thenAnswer((Invocation invocation) async {
|
||||
// Create valid package entry.
|
||||
packagesFile.writeAsStringSync('flutter_template_images:file:///flutter_template_images');
|
||||
});
|
||||
|
||||
await Template.fromName('app', fileSystem: fileSystem);
|
||||
}, overrides: <Type, Generator>{
|
||||
Pub: () => MockPub(),
|
||||
}));
|
||||
}
|
||||
|
||||
class MockPub extends Mock implements Pub {}
|
||||
class MockDirectory extends Mock implements Directory {}
|
||||
|
||||
Reference in New Issue
Block a user