fix release web builds where the target file is not under lib (#46179)

This commit is contained in:
Jonah Williams
2019-12-05 15:57:12 -08:00
committed by GitHub
parent e3005e6962
commit e6fa5717d1
2 changed files with 15 additions and 5 deletions

View File

@@ -68,11 +68,10 @@ class WebEntrypointTarget extends Target {
);
// 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');
}
// have an entry for the user's application or if the main file is
// outside of the lib/ directory.
final String mainImport = packageUriMapper.map(importPath)?.toString()
?? fs.file(importPath).absolute.uri.toString();
String contents;
if (hasPlugins) {

View File

@@ -76,6 +76,17 @@ void main() {
expect(generated, contains("import 'package:foo/main.dart' as entrypoint;"));
}));
test('WebEntrypointTarget generates an entrypoint for a file outside of main', () => testbed.run(() async {
environment.defines[kTargetFile] = fs.path.join('other', 'lib', 'main.dart');
await const WebEntrypointTarget().build(environment);
final String generated = environment.buildDir.childFile('main.dart').readAsStringSync();
// Import.
expect(generated, contains("import 'file:///other/lib/main.dart' as entrypoint;"));
}));
test('WebEntrypointTarget generates an entrypoint with plugins and init platform on windows', () => testbed.run(() async {
environment.defines[kHasWebPlugins] = 'true';
environment.defines[kInitializePlatform] = 'true';