Unverified Commit d3a41816 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] ensure all source maps load correctly for release and profile (#50702)

parent a833effb
......@@ -400,6 +400,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
urlTunneller: urlTunneller,
buildMode: debuggingOptions.buildInfo.mode,
enableDwds: _enableDwds,
entrypoint: globals.fs.file(target).uri,
);
final Uri url = await device.devFS.create();
if (debuggingOptions.buildInfo.isDebug) {
......
......@@ -53,6 +53,7 @@ class WebAssetServer implements AssetReader {
UrlTunneller urlTunneller,
BuildMode buildMode,
bool enableDwds,
Uri entrypoint,
) async {
try {
final InternetAddress address = (await InternetAddress.lookup(hostname)).first;
......@@ -63,7 +64,7 @@ class WebAssetServer implements AssetReader {
// In release builds deploy a simpler proxy server.
if (buildMode != BuildMode.debug) {
final ReleaseAssetServer releaseAssetServer = ReleaseAssetServer();
final ReleaseAssetServer releaseAssetServer = ReleaseAssetServer(entrypoint);
shelf.serveRequests(httpServer, releaseAssetServer.handle);
return server;
}
......@@ -318,8 +319,10 @@ class WebDevFS implements DevFS {
@required this.urlTunneller,
@required this.buildMode,
@required this.enableDwds,
@required this.entrypoint,
});
final Uri entrypoint;
final String hostname;
final int port;
final String packagesFilePath;
......@@ -385,6 +388,7 @@ class WebDevFS implements DevFS {
urlTunneller,
buildMode,
enableDwds,
entrypoint,
);
return Uri.parse('http://$hostname:$port');
}
......@@ -552,15 +556,22 @@ String _filePathToUriFragment(String path) {
}
class ReleaseAssetServer {
ReleaseAssetServer(this.entrypoint);
final Uri entrypoint;
// Locations where source files, assets, or source maps may be located.
final List<Uri> _searchPaths = <Uri>[
globals.fs.directory(getWebBuildDirectory()).uri,
globals.fs.directory(Cache.flutterRoot).parent.uri,
globals.fs.currentDirectory.childDirectory('lib').uri,
globals.fs.directory(Cache.flutterRoot).uri,
globals.fs.currentDirectory.uri,
];
Future<shelf.Response> handle(shelf.Request request) async {
Uri fileUri;
if (request.url.toString() == 'main.dart') {
fileUri = entrypoint;
} else {
for (final Uri uri in _searchPaths) {
final Uri potential = uri.resolve(request.url.path);
if (potential == null || !globals.fs.isFileSync(potential.toFilePath())) {
......@@ -569,7 +580,7 @@ class ReleaseAssetServer {
fileUri = potential;
break;
}
}
if (fileUri != null) {
final File file = globals.fs.file(fileUri);
final Uint8List bytes = file.readAsBytesSync();
......
......@@ -289,6 +289,7 @@ void main() {
urlTunneller: null,
buildMode: BuildMode.debug,
enableDwds: false,
entrypoint: Uri.base,
);
webDevFS.requireJS.createSync(recursive: true);
webDevFS.dartSdk.createSync(recursive: true);
......
......@@ -40,7 +40,7 @@ void main() {
});
test('release asset server serves correct mime type and content length for png', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer();
final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.png'))
..createSync(recursive: true)
..writeAsBytesSync(kTransparentImage);
......@@ -54,7 +54,7 @@ void main() {
}));
test('release asset server serves correct mime type and content length for JavaScript', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer();
final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.js'))
..createSync(recursive: true)
..writeAsStringSync('function main() {}');
......@@ -68,7 +68,7 @@ void main() {
}));
test('release asset server serves correct mime type and content length for html', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer();
final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.html'))
..createSync(recursive: true)
..writeAsStringSync('<!doctype html><html></html>');
......@@ -82,7 +82,7 @@ void main() {
}));
test('release asset server serves content from flutter root', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer();
final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('flutter', 'bar.dart'))
..createSync(recursive: true)
..writeAsStringSync('void main() { }');
......@@ -93,8 +93,8 @@ void main() {
}));
test('release asset server serves content from project directory', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer();
globals.fs.file(globals.fs.path.join('lib', 'bar.dart'))
final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('bar.dart'))
..createSync(recursive: true)
..writeAsStringSync('void main() { }');
final Response response = await assetServer
......
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