findPackageConfig function

Future<PackageConfig?> findPackageConfig(
  1. Directory directory, {
  2. bool recurse = true,
  3. void onError(
    1. Object error
    )?,
})

Finds a package configuration relative to directory.

If directory contains a package configuration, either a .dart_tool/package_config.json file or, if not, a .packages, then that file is loaded.

If no file is found in the current directory, then the parent directories are checked recursively, all the way to the root directory, to check if those contains a package configuration. If recurse is set to false, this parent directory check is not performed.

If onError is provided, the configuration file parsing will report errors by calling that function, and then try to recover. The returned package configuration is a best effort attempt to create a valid configuration from the invalid configuration file. If no onError is provided, errors are thrown immediately.

Returns null if no configuration file is found.

Implementation

Future<PackageConfig?> findPackageConfig(Directory directory,
        {bool recurse = true, void Function(Object error)? onError}) =>
    discover.findPackageConfig(directory, recurse, onError ?? throwError);