Unverified Commit 84ce3f60 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Serve web source maps in release runner (#45318)

parent 46632f9e
......@@ -353,11 +353,27 @@ abstract class AssetServer {
}
class ReleaseAssetServer extends AssetServer {
// Locations where source files, assets, or source maps may be located.
final List<Uri> _searchPaths = <Uri>[
fs.directory(getWebBuildDirectory()).uri,
fs.directory(Cache.flutterRoot).parent.uri,
fs.currentDirectory.childDirectory('lib').uri,
];
@override
Future<Response> handle(Request request) async {
final Uri artifactUri = fs.directory(getWebBuildDirectory()).uri.resolveUri(request.url);
final File file = fs.file(artifactUri);
if (file.existsSync()) {
Uri fileUri;
for (Uri uri in _searchPaths) {
final Uri potential = uri.resolve(request.url.path);
if (potential == null || !fs.isFileSync(potential.toFilePath())) {
continue;
}
fileUri = potential;
break;
}
if (fileUri != null) {
final File file = fs.file(fileUri);
final Uint8List bytes = file.readAsBytesSync();
// Fallback to "application/octet-stream" on null which
// makes no claims as to the structure of the data.
......
......@@ -4,6 +4,7 @@
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/build_runner/web_fs.dart';
import 'package:flutter_tools/src/globals.dart';
import 'package:flutter_tools/src/project.dart';
......@@ -151,4 +152,26 @@ void main() {
'content-length': '28',
});
}));
test('release asset server serves content from flutter root', () => testbed.run(() async {
assetServer = ReleaseAssetServer();
fs.file(fs.path.join('flutter', 'bar.dart'))
..createSync(recursive: true)
..writeAsStringSync('void main() { }');
final Response response = await assetServer
.handle(Request('GET', Uri.parse('http://localhost:8080/flutter/bar.dart')));
expect(response.statusCode, HttpStatus.ok);
}));
test('release asset server serves content from project directory', () => testbed.run(() async {
assetServer = ReleaseAssetServer();
fs.file(fs.path.join('lib', 'bar.dart'))
..createSync(recursive: true)
..writeAsStringSync('void main() { }');
final Response response = await assetServer
.handle(Request('GET', Uri.parse('http://localhost:8080/bar.dart')));
expect(response.statusCode, HttpStatus.ok);
}));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment