PackageAssetReader.forPackageRoot constructor

PackageAssetReader.forPackageRoot(
  1. String packageRoot,
  2. [String? rootPackage]
)

A PackageAssetReader with a single packageRoot configured.

It is assumed that every directory in packageRoot is a package where the name of the package is the name of the directory. This is similar to the older "packages" folder paradigm for resolution.

Implementation

factory PackageAssetReader.forPackageRoot(String packageRoot,
    [String? rootPackage]) {
  final directory = Directory(packageRoot);
  final packages = <String, String>{};
  for (final entity in directory.listSync()) {
    if (entity is Directory) {
      final name = p.basename(entity.path);
      packages[name] = entity.uri.toFilePath(windows: false);
    }
  }
  return PackageAssetReader.forPackages(packages, rootPackage);
}