Add comments to package scheme fix (#45997)

This commit is contained in:
Jonah Williams
2019-12-03 09:55:50 -08:00
committed by GitHub
parent 0b2bf99491
commit 0dace48932

View File

@@ -53,12 +53,22 @@ class WebEntrypointTarget extends Target {
final bool shouldInitializePlatform = environment.defines[kInitializePlatform] == 'true';
final bool hasPlugins = environment.defines[kHasWebPlugins] == 'true';
final String importPath = fs.path.absolute(targetFile);
// Use the package uri mapper to find the correct package-scheme import path
// for the user application. If the application has a mix of package-scheme
// and relative imports for a library, then importing the entrypoint as a
// file-scheme will cause said library to be recognized as two distinct
// libraries. This can cause surprising behavior as types from that library
// will be considered distinct from each other.
final PackageUriMapper packageUriMapper = PackageUriMapper(
importPath,
PackageMap.globalPackagesPath,
null,
null,
);
// By construction, this will only be null if the .packages file does not
// have an entry for the user's application.
final Uri mainImport = packageUriMapper.map(importPath);
if (mainImport == null) {
throw Exception('Missing package definition for $mainImport');