[flutter_tools] fix package config invalidation (#55420)
This commit is contained in:
@@ -1270,6 +1270,17 @@ class ProjectFileInvalidator {
|
||||
if (updatedAt != null && updatedAt.isAfter(lastCompiled)) {
|
||||
invalidatedFiles.add(packageUri);
|
||||
packageConfig = await _createPackageConfig(packagesPath);
|
||||
// The frontend_server might be monitoring the package_config.json file,
|
||||
// Pub should always produce both files.
|
||||
// TODO(jonahwilliams): remove after https://github.com/flutter/flutter/issues/55249
|
||||
if (_fileSystem.path.basename(packagesPath) == '.packages') {
|
||||
final File packageConfigFile = _fileSystem.file(packagesPath)
|
||||
.parent.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
if (packageConfigFile.existsSync()) {
|
||||
invalidatedFiles.add(packageConfigFile.uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.printTrace(
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/run_hot.dart';
|
||||
import 'package:package_config/package_config.dart';
|
||||
|
||||
@@ -80,6 +81,49 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('Picks up changes to the .packages file and updates package_config.json'
|
||||
', asyncScanning: $asyncScanning', () async {
|
||||
final DateTime past = DateTime.now().subtract(const Duration(seconds: 1));
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final PackageConfig packageConfig = PackageConfig.empty;
|
||||
final ProjectFileInvalidator projectFileInvalidator = ProjectFileInvalidator(
|
||||
fileSystem: fileSystem,
|
||||
platform: FakePlatform(),
|
||||
logger: BufferLogger.test(),
|
||||
);
|
||||
fileSystem.file('.packages')
|
||||
.writeAsStringSync('\n');
|
||||
fileSystem.file('.dart_tool/package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(json.encode(<String, Object>{
|
||||
'configVersion': 2,
|
||||
'packages': <Object>[],
|
||||
}));
|
||||
|
||||
final InvalidationResult invalidationResult = await projectFileInvalidator.findInvalidated(
|
||||
lastCompiled: null,
|
||||
urisToMonitor: <Uri>[],
|
||||
packagesPath: '.packages',
|
||||
asyncScanning: asyncScanning,
|
||||
packageConfig: packageConfig,
|
||||
);
|
||||
expect(invalidationResult.uris, isEmpty);
|
||||
fileSystem.file('.packages').setLastModifiedSync(DateTime.now());
|
||||
|
||||
final InvalidationResult secondInvalidation = await projectFileInvalidator.findInvalidated(
|
||||
lastCompiled: past,
|
||||
urisToMonitor: <Uri>[],
|
||||
packagesPath: '.packages',
|
||||
asyncScanning: asyncScanning,
|
||||
packageConfig: packageConfig,
|
||||
);
|
||||
expect(secondInvalidation.uris, unorderedEquals(<Uri>[
|
||||
Uri.parse('.packages'),
|
||||
Uri.parse('.dart_tool/package_config.json'),
|
||||
]));
|
||||
});
|
||||
|
||||
|
||||
testWithoutContext('Picks up changes to the .packages file and updates PackageConfig'
|
||||
', asyncScanning: $asyncScanning', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
Reference in New Issue
Block a user