-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix relative imports in wasm loader (#3752)
Currently, the loader script emitted by `build_web_compilers` resolves URLs against the base-URL of the active document. This breaks when the entrypoint script is not in the same directory as the page, e.g. in ``` web/ index.html src/ app.dart ``` To fix this, this PR changes the logic to resolve URLs against the loader script (which would be `/src/app.dart.js` in the example, properly resolving the other dart2wasm/dart2js components). I've also added an integration test using a `<script>` tag pointing to a subdirectory to make sure that this is working now. Closes #3751
- Loading branch information
Showing
12 changed files
with
86 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:js_interop'; | ||
import 'dart:js_interop_unsafe'; | ||
|
||
void main() { | ||
globalContext['otherScriptLoaded'] = true.toJS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
@TestOn('browser') | ||
library; | ||
|
||
import 'dart:js_interop'; | ||
import 'dart:js_interop_unsafe'; | ||
|
||
import 'package:test/test.dart'; | ||
import 'package:web/web.dart'; | ||
|
||
void main() { | ||
final wasCompiledWithDdc = globalContext.has('define'); | ||
|
||
test( | ||
'did load script from a subdirectory', | ||
() async { | ||
final scriptTag = document.createElement('script') as HTMLScriptElement; | ||
scriptTag | ||
..type = 'application/javascript' | ||
..src = 'sub-dir/subdir_source.dart.js'; | ||
document.head!.append(scriptTag); | ||
|
||
await Future.any([ | ||
scriptTag.onLoad.first, | ||
scriptTag.onError.first | ||
.then((_) => fail('Script from sub directory failed to load')) | ||
]); | ||
|
||
await pumpEventQueue(); | ||
|
||
// `sub-dir/subdir_source.dart.js` should have set the `otherScriptLoader` | ||
// propery. | ||
expect(globalContext.has('otherScriptLoaded'), isTrue); | ||
}, | ||
skip: wasCompiledWithDdc | ||
? 'This requires multiple Dart entrypoints, which appears to break DDC' | ||
: null, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters