fromDirectory static method
Creates a package checker by checking the directory for a pubspec.yaml and a package_config.json file.
Implementation
static Future<PackageChecker> fromDirectory({
required Directory directory,
required Config config,
}) async {
File pubspecFile = File(join(directory.path, 'pubspec.yaml'));
if (!pubspecFile.existsSync()) {
return throw FileSystemException(
'pubspec.yaml file not found in current directory.',
);
}
Pubspec pubspec = Pubspec.parseYaml(await pubspecFile.readAsString());
PackageConfig? packageConfig =
await findPackageConfig(directory, recurse: false);
if (packageConfig == null) {
throw FileSystemException(
'No package_config.json found. Are you sure this is a Dart package directory?',
);
}
List<DependencyChecker> packageDependencies = [];
for (Package pkg in packageConfig.packages) {
if (pkg.name == pubspec.name) {
// Don't add or check self
continue;
}
packageDependencies.add(DependencyChecker(config: config, package: pkg));
}
return PackageChecker._(
pubspec: pubspec,
packages: packageDependencies,
config: config,
);
}