refreshDependencies method

Future<void> refreshDependencies()

Implementation

Future<void> refreshDependencies() async {
  final packageConfig = _packageConfig;

  if (packageConfig == null) {
    return;
  }

  final dependencies = await _getDependencyFiles(
    packageConfig,
    lastModified: _retrievedDependenciesAt,
    pathDependenciesOnly: true,
  );
  _retrievedDependenciesAt = DateTime.now();

  for (final path in dependencies) {
    final normalizedPath = fs.path.normalize(path);
    final file = fs.file(normalizedPath);
    final bytes = switch (file.existsSync()) {
      true => await file.readAsBytes(),
      false => null,
    };

    if (bytes == null) {
      try {
        _memoryProvider.deleteFile(normalizedPath);
      } catch (_) {
        // Already absent from the overlay.
      }
    } else {
      _memoryProvider.newFileWithBytes(normalizedPath, bytes);
    }

    await _notifyFileChanged(normalizedPath);
  }
}