pathPackageConfigMapGetPackagePath function

String? pathPackageConfigMapGetPackagePath(
  1. String path,
  2. Map packageConfigMap,
  3. String package, {
  4. bool? windows,
})

Get a library path, you can get the project dir through its parent null if not found

Implementation

String? pathPackageConfigMapGetPackagePath(
    String path, Map packageConfigMap, String package,
    {bool? windows}) {
  var pkg = _cache.get(path);
  var packagesList = packageConfigMap['packages'] as Iterable;
  for (var packageMap in packagesList) {
    if (packageMap is Map) {
      var name = packageMap['name'];

      if (name is String && name == package) {
        var rootUri = packageMap['rootUri'];
        if (rootUri is String) {
          // rootUri if relative is relative to .dart_tool
          // we want it relative to the root project.
          // Replace .. with . to avoid going up twice
          if (rootUri.startsWith('..')) {
            rootUri = rootUri.substring(1);
          }
          var parent = pkg?.workspace ?? path;
          return _toFilePath(parent, rootUri, windows: windows);
        }
      }
    }
  }
  return null;
}