inPubCache method

bool inPubCache({
  1. Map<String, String>? environment,
})

Whether it lives in pub's shared cache: the default one, or the one PUB_CACHE names in environment (this process's by default).

Implementation

bool inPubCache({Map<String, String>? environment}) {
  final p = rootPath.toLowerCase();
  if (p.contains('/pub/cache/') || p.contains('/.pub-cache/')) return true;
  final set = (environment ?? Platform.environment)['PUB_CACHE']?.trim();
  if (set == null || set.isEmpty) return false;
  final cache = normalPath(Directory(set).absolute.path);
  final ignoreCase = Platform.isWindows || Platform.isMacOS;
  final root = ignoreCase ? p : rootPath;
  final prefix = ignoreCase ? '${cache.toLowerCase()}/' : '$cache/';
  return root.startsWith(prefix);
}