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
This commit is contained in:
Jason Simmons 2025-01-16 16:40:52 -08:00 committed by GitHub
parent a6045c9985
commit 747f5fff1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 7 deletions

View File

@ -32,8 +32,8 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
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: '<unknown>',
@ -43,8 +43,8 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
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: '<unknown>',
@ -54,8 +54,8 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
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: '<unknown>',

View File

@ -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

View File

@ -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;
}

View File

@ -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',