resolveImport method
Resolves an import of a generated Dart file.
Both source
and target
are .proto files, where source
imports
target
.
The returned URI can be used within one of the source's dart files to import the target's generated file with the given extension.
Implementation
@override
Uri resolveImport(Uri target, Uri source, String extension) {
var targetBase = p.withoutExtension(target.path);
var targetUri = _packageUriFor('$targetBase$extension');
var sourceUri = _packageUriFor(source.path);
if (targetUri == null && sourceUri != null) {
// We can't reach outside of the lib/ directory of a package without
// using a package: import. Using a relative import for [target] could
// break anyone who uses a package: import to load [source].
throw 'ERROR: cannot generate import for $target from $source.';
}
if (targetUri != null && sourceUri?.packageName != targetUri.packageName) {
return targetUri.uri;
}
return super.resolveImport(target, source, extension);
}