-
Notifications
You must be signed in to change notification settings - Fork 239
[build_web_compilers] Standardize web app entrypoint selection #5095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Markzipan
merged 3 commits into
dart-lang:master
from
parlough:fix/web-entrypoint-priority
Sep 1, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
174 changes: 174 additions & 0 deletions
174
builder_pkgs/build_web_compilers/test/web_entrypoint_marker_builder_test.dart
This file contains hidden or 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,174 @@ | ||
| // Copyright (c) 2026, 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 'package:build/build.dart'; | ||
| import 'package:build_test/build_test.dart'; | ||
| import 'package:build_web_compilers/builders.dart'; | ||
| import 'package:build_web_compilers/src/build_modules/build_modules.dart'; | ||
| import 'package:build_web_compilers/src/web_entrypoint_marker_builder.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| setUp(_resetFrontendServerState); | ||
| tearDown(_resetFrontendServerState); | ||
|
|
||
| test('prefers a web entrypoint over a test entrypoint', () async { | ||
| final generateEntrypoint = TestBuilder( | ||
| buildExtensions: replaceExtension('.template', '.dart'), | ||
| ); | ||
|
|
||
| await testBuilders( | ||
| [generateEntrypoint, WebEntrypointMarkerBuilder(usesWebHotReload: true)], | ||
| { | ||
| 'a|web/\$web\$': '', | ||
| 'a|web/generated_main.template': 'void main() {}', | ||
| 'a|test/app_test.dart': 'void main() {}', | ||
| }, | ||
| outputs: { | ||
| 'a|web/generated_main.dart': 'void main() {}', | ||
| 'a|web/.web.entrypoint.json': decodedMatches( | ||
| contains('a|web/generated_main.dart'), | ||
| ), | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test( | ||
| 'falls back to a test entrypoint when there is no web entrypoint', | ||
| () async { | ||
| await testBuilders( | ||
| [WebEntrypointMarkerBuilder(usesWebHotReload: true)], | ||
| {'a|web/\$web\$': '', 'a|test/app_test.dart': 'void main() {}'}, | ||
| outputs: { | ||
| 'a|web/.web.entrypoint.json': decodedMatches( | ||
| contains('a|test/app_test.dart'), | ||
| ), | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| test('uses configured entrypoint directory order', () async { | ||
| await testBuilders( | ||
| [ | ||
| webEntrypointMarkerBuilder( | ||
| const BuilderOptions({ | ||
| 'web-hot-reload': true, | ||
| 'web-assets-path': 'test,web', | ||
| }), | ||
| ), | ||
| ], | ||
| { | ||
| 'a|web/\$web\$': '', | ||
| 'a|web/main.dart': 'void main() {}', | ||
| 'a|test/app_test.dart': 'void main() {}', | ||
| }, | ||
| outputs: { | ||
| 'a|web/.web.entrypoint.json': decodedMatches( | ||
| contains('a|test/app_test.dart'), | ||
| ), | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('prefers `main.dart` over an earlier alphabetical entrypoint', () async { | ||
| await testBuilders( | ||
| [WebEntrypointMarkerBuilder(usesWebHotReload: true)], | ||
| { | ||
| 'a|web/\$web\$': '', | ||
| 'a|web/a_main.dart': 'void main() {}', | ||
| 'a|web/main.dart': 'void main() {}', | ||
| }, | ||
| outputs: { | ||
| 'a|web/.web.entrypoint.json': decodedMatches( | ||
| contains('a|web/main.dart'), | ||
| ), | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('prefers an entrypoint closer to the searched directory', () async { | ||
| await testBuilders( | ||
| [WebEntrypointMarkerBuilder(usesWebHotReload: true)], | ||
| { | ||
| 'a|web/\$web\$': '', | ||
| 'a|web/debug/main.dart': 'void main() {}', | ||
| 'a|web/zzz.dart': 'void main() {}', | ||
| }, | ||
| outputs: { | ||
| 'a|web/.web.entrypoint.json': decodedMatches( | ||
| contains('a|web/zzz.dart'), | ||
| ), | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('ignores whitespace around configured entrypoint directories', () async { | ||
| await testBuilders( | ||
| [ | ||
| webEntrypointMarkerBuilder( | ||
| const BuilderOptions({ | ||
| 'web-hot-reload': true, | ||
| 'web-assets-path': ' test , web ', | ||
| }), | ||
| ), | ||
| ], | ||
| { | ||
| 'a|web/\$web\$': '', | ||
| 'a|web/main.dart': 'void main() {}', | ||
| 'a|test/app_test.dart': 'void main() {}', | ||
| }, | ||
| outputs: { | ||
| 'a|web/.web.entrypoint.json': decodedMatches( | ||
| contains('a|test/app_test.dart'), | ||
| ), | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('accepts entrypoint directories specified as a list', () async { | ||
| await testBuilders( | ||
| [ | ||
| webEntrypointMarkerBuilder( | ||
| const BuilderOptions({ | ||
| 'web-hot-reload': true, | ||
| 'web-assets-path': ['test', 'web'], | ||
| }), | ||
| ), | ||
| ], | ||
| { | ||
| 'a|web/\$web\$': '', | ||
| 'a|web/main.dart': 'void main() {}', | ||
| 'a|test/app_test.dart': 'void main() {}', | ||
| }, | ||
| outputs: { | ||
| 'a|web/.web.entrypoint.json': decodedMatches( | ||
| contains('a|test/app_test.dart'), | ||
| ), | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('rejects an unusable entrypoint directory configuration', () { | ||
| for (final invalidValue in [42, '', ' , ', <String>[]]) { | ||
| expect( | ||
| () => webEntrypointMarkerBuilder( | ||
| BuilderOptions({ | ||
| 'web-hot-reload': true, | ||
| 'web-assets-path': invalidValue, | ||
| }), | ||
| ), | ||
| throwsA(isA<ArgumentError>()), | ||
| reason: 'Expected `$invalidValue` to be rejected.', | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| void _resetFrontendServerState() { | ||
| frontendServerState | ||
| ..entrypointAssetId = null | ||
| ..needsRecompileRestart = false | ||
| ..fesScratchSpace = null; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.