fromFile static method

PackageGraph fromFile(
  1. File file
)

Reads and parses a package graph file.

Throws PackageGraphFileNotFoundException if the file is not found. Throws FormatException if the file is not a valid package graph file.

Implementation

static PackageGraph fromFile(final File file) {
  final String contents;
  try {
    contents = file.readAsStringSync();
  } on PathNotFoundException {
    throw PackageGraphFileNotFoundException(file.path);
  } on FileSystemException catch (e) {
    throw FormatException(
      'Failed to read package_graph.json at `${file.path}`: ${e.message}',
    );
  }
  try {
    return fromJson(jsonDecode(contents));
  } on FormatException catch (e) {
    throw FormatException(
      'Failed to parse package_graph.json at `${file.path}`: ${e.message}',
    );
  }
}