in lib/src/package_config_impl.dart [158:178]
Uri? toPackageUri(Uri nonPackageUri) {
if (nonPackageUri.isScheme('package')) {
throw PackageConfigArgumentError(
nonPackageUri, 'nonPackageUri', 'Must not be a package URI');
}
if (nonPackageUri.hasQuery || nonPackageUri.hasFragment) {
throw PackageConfigArgumentError(nonPackageUri, 'nonPackageUri',
'Must not have query or fragment part');
}
// Find package that file belongs to.
var package = _packageTree.packageOf(nonPackageUri);
if (package == null) return null;
// Check if it is inside the package URI root.
var path = nonPackageUri.toString();
var root = package.packageUriRoot.toString();
if (_beginsWith(package.root.toString().length, root, path)) {
var rest = path.substring(root.length);
return Uri(scheme: 'package', path: '${package.name}/$rest');
}
return null;
}