in lib/src/package_config_impl.dart [214:267]
static SimplePackage? validate(
String name,
Uri root,
Uri? packageUriRoot,
LanguageVersion? languageVersion,
Object? extraData,
bool relativeRoot,
void Function(Object error) onError) {
var fatalError = false;
var invalidIndex = checkPackageName(name);
if (invalidIndex >= 0) {
onError(PackageConfigFormatException(
'Not a valid package name', name, invalidIndex));
fatalError = true;
}
if (root.isScheme('package')) {
onError(PackageConfigArgumentError(
'$root', 'root', 'Must not be a package URI'));
fatalError = true;
} else if (!isAbsoluteDirectoryUri(root)) {
onError(PackageConfigArgumentError(
'$root',
'root',
'In package $name: Not an absolute URI with no query or fragment '
'with a path ending in /'));
// Try to recover. If the URI has a scheme,
// then ensure that the path ends with `/`.
if (!root.hasScheme) {
fatalError = true;
} else if (!root.path.endsWith('/')) {
root = root.replace(path: root.path + '/');
}
}
if (packageUriRoot == null) {
packageUriRoot = root;
} else if (!fatalError) {
packageUriRoot = root.resolveUri(packageUriRoot);
if (!isAbsoluteDirectoryUri(packageUriRoot)) {
onError(PackageConfigArgumentError(
packageUriRoot,
'packageUriRoot',
'In package $name: Not an absolute URI with no query or fragment '
'with a path ending in /'));
packageUriRoot = root;
} else if (!isUriPrefix(root, packageUriRoot)) {
onError(PackageConfigArgumentError(packageUriRoot, 'packageUriRoot',
'The package URI root is not below the package root'));
packageUriRoot = root;
}
}
if (fatalError) return null;
return SimplePackage._(
name, root, packageUriRoot, languageVersion, extraData, relativeRoot);
}