[flutter_tools] set test directory base as additional root, allow running without index.html (#55531)

This commit is contained in:
Jonah Williams
2020-04-24 09:09:53 -07:00
committed by GitHub
parent 873b21ec04
commit 2f0d41b2a6
5 changed files with 46 additions and 35 deletions

View File

@@ -48,6 +48,15 @@ typedef DwdsLauncher = Future<Dwds> Function({
ExpressionCompiler expressionCompiler,
});
// A minimal index for projects that do not yet support web.
const String _kDefaultIndex = '''
<html>
<body>
<script src="main.dart.js"></script>
</body>
</html>
''';
/// An expression compiler connecting to FrontendServer
///
/// This is only used in development mode
@@ -277,8 +286,11 @@ class WebAssetServer implements AssetReader {
headers[HttpHeaders.contentTypeHeader] = 'text/html';
headers[HttpHeaders.contentLengthHeader] = indexFile.lengthSync().toString();
return shelf.Response.ok(indexFile.openRead(), headers: headers);
} else {
headers[HttpHeaders.contentTypeHeader] = 'text/html';
headers[HttpHeaders.contentLengthHeader] = _kDefaultIndex.length.toString();
return shelf.Response.ok(_kDefaultIndex, headers: headers);
}
return shelf.Response.notFound('');
}
// Track etag headers for better caching of resources.

View File

@@ -368,9 +368,8 @@ class _ResidentWebRunner extends ResidentWebRunner {
applicationBinary: null,
);
if (package == null) {
globals.printError('This application is not configured to build on the web.');
globals.printError('To add web support to a project, run `flutter create .`.');
return 1;
globals.printStatus('This application is not configured to build on the web.');
globals.printStatus('To add web support to a project, run `flutter create .`.');
}
if (!globals.fs.isFileSync(mainPath)) {
String message = 'Tried to run $mainPath, but that file does not exist.';
@@ -569,6 +568,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
if (importedEntrypoint == null) {
final String parent = globals.fs.file(mainUri).parent.path;
flutterDevices.first.generator.addFileSystemRoot(parent);
flutterDevices.first.generator.addFileSystemRoot(globals.fs.directory('test').absolute.path);
importedEntrypoint = Uri(
scheme: 'org-dartlang-app',
path: '/' + mainUri.pathSegments.last,