From 747f5fff1e4dbab3f1aab16d0ec7e16ef7eb70e1 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 16 Jan 2025 16:40:52 -0800 Subject: [PATCH] Initialize dartLoader.rootDirectories so the Web stack trace mapper can convert package source paths (#160383) See https://dart.googlesource.com/sdk/+/refs/heads/main/pkg/dev_compiler/web/stack_trace_mapper.dart Fixes https://github.com/flutter/flutter/issues/158109 --- dev/integration_tests/web/lib/stack_trace.dart | 12 ++++++------ .../flutter_tools/lib/src/isolated/devfs_web.dart | 1 + packages/flutter_tools/lib/src/web/bootstrap.dart | 3 ++- .../test/general.shard/web/bootstrap_test.dart | 12 ++++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/dev/integration_tests/web/lib/stack_trace.dart b/dev/integration_tests/web/lib/stack_trace.dart index 66ccf36d99..ac429d6c8d 100644 --- a/dev/integration_tests/web/lib/stack_trace.dart +++ b/dev/integration_tests/web/lib/stack_trace.dart @@ -32,8 +32,8 @@ const List expectedDebugStackFrames = [ StackFrame( number: -1, packageScheme: 'package', - package: 'packages', - packagePath: 'web_integration/stack_trace.dart', + package: 'web_integration', + packagePath: 'stack_trace.dart', line: 119, column: 3, className: '', @@ -43,8 +43,8 @@ const List expectedDebugStackFrames = [ StackFrame( number: -1, packageScheme: 'package', - package: 'packages', - packagePath: 'web_integration/stack_trace.dart', + package: 'web_integration', + packagePath: 'stack_trace.dart', line: 114, column: 3, className: '', @@ -54,8 +54,8 @@ const List expectedDebugStackFrames = [ StackFrame( number: -1, packageScheme: 'package', - package: 'packages', - packagePath: 'web_integration/stack_trace.dart', + package: 'web_integration', + packagePath: 'stack_trace.dart', line: 109, column: 3, className: '', diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index 89487edcc3..0ba4d51530 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -1033,6 +1033,7 @@ class WebDevFS implements DevFS { entrypoint: entrypoint, nullAssertions: nullAssertions, nativeNullAssertions: nativeNullAssertions, + loaderRootDirectory: _baseUri.toString(), ), ); // TODO(zanderso): refactor the asset code in this and the regular devfs to diff --git a/packages/flutter_tools/lib/src/web/bootstrap.dart b/packages/flutter_tools/lib/src/web/bootstrap.dart index eb1877942b..4de9cf9031 100644 --- a/packages/flutter_tools/lib/src/web/bootstrap.dart +++ b/packages/flutter_tools/lib/src/web/bootstrap.dart @@ -458,6 +458,7 @@ String generateMainModule({ required bool nullAssertions, required bool nativeNullAssertions, String bootstrapModule = 'main_module.bootstrap', + String loaderRootDirectory = '', }) { // The typo below in "EXTENTION" is load-bearing, package:build depends on it. return ''' @@ -481,7 +482,7 @@ define("$bootstrapModule", ["$entrypoint", "dart_sdk"], function(app, dart_sdk) child.main(); window.\$dartLoader = {}; - window.\$dartLoader.rootDirectories = []; + window.\$dartLoader.rootDirectories = ["$loaderRootDirectory"]; if (window.\$requireLoader) { window.\$requireLoader.getModuleLibraries = dart_sdk.dart.getModuleLibraries; } diff --git a/packages/flutter_tools/test/general.shard/web/bootstrap_test.dart b/packages/flutter_tools/test/general.shard/web/bootstrap_test.dart index 6b31f0b720..53b9957b32 100644 --- a/packages/flutter_tools/test/general.shard/web/bootstrap_test.dart +++ b/packages/flutter_tools/test/general.shard/web/bootstrap_test.dart @@ -153,6 +153,18 @@ void main() { expect(result, contains('''dart_sdk.dart.nativeNonNullAsserts(false);''')); }); + test('generateMainModule sets rootDirectories', () { + const String root = 'http://localhost:12345'; + final String result = generateMainModule( + entrypoint: 'foo/bar/main.js', + nullAssertions: false, + nativeNullAssertions: false, + loaderRootDirectory: root, + ); + + expect(result, contains('''window.\$dartLoader.rootDirectories = ["$root"];''')); + }); + test('generateTestBootstrapFileContents embeds urls correctly', () { final String result = generateTestBootstrapFileContents( 'foo.dart.js',