findAssets method

  1. @override
Stream<AssetId> findAssets(
  1. Glob glob,
  2. {String? package}
)

Returns all readable assets matching glob under the current package.

Implementation

@override
Stream<AssetId> findAssets(Glob glob, {String? package}) {
  package ??= _rootPackage;
  if (package == null) {
    throw UnsupportedError(
        'Root package must be provided to use `findAssets` without an '
        'explicit `package`.');
  }
  var packageLibDir = _packageConfig[package]?.packageUriRoot;
  if (packageLibDir == null) return const Stream.empty();

  var packageFiles = Directory.fromUri(packageLibDir)
      .list(recursive: true)
      .whereType<File>()
      .map((f) =>
          p.join('lib', p.relative(f.path, from: p.fromUri(packageLibDir))));
  if (package == _rootPackage) {
    packageFiles = packageFiles.merge(Directory(_rootPackagePath)
        .list(recursive: true)
        .whereType<File>()
        .map((f) => p.relative(f.path, from: _rootPackagePath))
        .where((p) => !(p.startsWith('packages/') || p.startsWith('lib/'))));
  }
  return packageFiles.where(glob.matches).map((p) => AssetId(package!, p));
}