Skip to content
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

Restructure LoadStrategy to provide build arguments #2270

Merged
merged 22 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 22.2.0-wip
## 23.0.0-wip
- Restructure `LoadStrategy` to provide build settings. - [#2270](https://github.com/dart-lang/webdev/pull/2270)

## 22.1.0
- Update `package:vm_service` constraint to `^13.0.0`. - [#2235](https://github.com/dart-lang/webdev/pull/2265)
- Update `package:vm_service` constraint to `^13.0.0`. - [#2265](https://github.com/dart-lang/webdev/pull/2265)

## 22.0.0

Expand Down
3 changes: 2 additions & 1 deletion dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export 'src/loaders/frontend_server_require.dart'
show FrontendServerRequireStrategyProvider;
export 'src/loaders/legacy.dart' show LegacyStrategy;
export 'src/loaders/require.dart' show RequireStrategy;
export 'src/loaders/strategy.dart' show LoadStrategy, ReloadConfiguration;
export 'src/loaders/strategy.dart'
show LoadStrategy, ReloadConfiguration, BuildSettings;
export 'src/readers/asset_reader.dart' show AssetReader, PackageUriMapper;
export 'src/readers/frontend_server_asset_reader.dart'
show FrontendServerAssetReader;
Expand Down
6 changes: 5 additions & 1 deletion dwds/lib/expression_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
// BSD-style license that can be found in the LICENSE file.

export 'src/services/expression_compiler.dart'
show ExpressionCompilationResult, ExpressionCompiler, ModuleInfo;
show
ExpressionCompilationResult,
ExpressionCompiler,
CompilerOptions,
ModuleInfo;
10 changes: 4 additions & 6 deletions dwds/lib/src/config/tool_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ToolConfiguration {
final DebugSettings debugSettings;
final AppMetadata appMetadata;

ToolConfiguration({
const ToolConfiguration({
required this.loadStrategy,
required this.debugSettings,
required this.appMetadata,
Expand All @@ -37,14 +37,12 @@ class AppMetadata {
final String hostname;
final bool isInternalBuild;
final String? workspaceName;
Future<bool> Function() isFlutterApp;
annagrin marked this conversation as resolved.
Show resolved Hide resolved

AppMetadata({
const AppMetadata({
this.hostname = 'localhost',
this.isInternalBuild = false,
this.workspaceName,
Future<bool> Function()? isFlutterApp,
}) : isFlutterApp = isFlutterApp ?? (() => Future.value(true));
});
}

typedef UrlEncoder = Future<String> Function(String url);
Expand All @@ -68,7 +66,7 @@ class DebugSettings {
final ExpressionCompiler? expressionCompiler;
final UrlEncoder? urlEncoder;

DebugSettings({
const DebugSettings({
this.enableDebugging = true,
this.enableDebugExtension = false,
this.useSseForDebugProxy = true,
Expand Down
10 changes: 4 additions & 6 deletions dwds/lib/src/debugging/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ class LibraryHelper extends Domain {

Future<LibraryRef> get rootLib async {
if (_rootLib != null) return _rootLib!;
// TODO: read entrypoint from app metadata.
// Issue: https://github.com/dart-lang/webdev/issues/1290
final libraries = await libraryRefs;
if (globalToolConfiguration.loadStrategy.appEntrypoint != null) {
final mainLibrary =
globalToolConfiguration.loadStrategy.buildSettings.appEntrypoint;
if (mainLibrary != null) {
_rootLib = libraries.firstWhereOrNull(
(lib) =>
Uri.parse(lib.uri ?? '') ==
globalToolConfiguration.loadStrategy.appEntrypoint,
(lib) => Uri.parse(lib.uri ?? '') == mainLibrary,
);
}
_rootLib = _rootLib ??
Expand Down
4 changes: 3 additions & 1 deletion dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class Locations {
}
final result = <Location>{};
if (module.isEmpty) return _moduleToLocations[module] = result;
if (module.endsWith('dart_sdk') || module.endsWith('dart_library')) {
if (module.endsWith('dart_sdk') ||
(module.endsWith('dart_library') &&
!module.endsWith('.dart_library'))) {
return result;
}
final modulePath = await globalToolConfiguration.loadStrategy
Expand Down
30 changes: 19 additions & 11 deletions dwds/lib/src/handlers/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class DwdsInjector {
devHandlerPath = '$requestedUriBase/$devHandlerPath';
_devHandlerPaths.add(devHandlerPath);
final entrypoint = request.url.path;
globalToolConfiguration.loadStrategy.trackEntrypoint(entrypoint);
await globalToolConfiguration.loadStrategy
.trackEntrypoint(entrypoint);
body = await _injectClientAndHoistMain(
body,
appId,
Expand Down Expand Up @@ -184,25 +185,32 @@ Future<String> _injectedClientSnippet(
String entrypointPath,
String? extensionUri,
) async {
final isFlutterApp = await globalToolConfiguration.appMetadata.isFlutterApp();
final loadStrategy = globalToolConfiguration.loadStrategy;
final buildSettings = loadStrategy.buildSettings;
final appMetadata = globalToolConfiguration.appMetadata;
final debugSettings = globalToolConfiguration.debugSettings;

var injectedBody = 'window.\$dartAppId = "$appId";\n'
'window.\$dartReloadConfiguration = "${globalToolConfiguration.loadStrategy.reloadConfiguration}";\n'
'window.\$dartModuleStrategy = "${globalToolConfiguration.loadStrategy.id}";\n'
'window.\$loadModuleConfig = ${globalToolConfiguration.loadStrategy.loadModuleSnippet};\n'
'window.\$dartReloadConfiguration = "${loadStrategy.reloadConfiguration}";\n'
'window.\$dartModuleStrategy = "${loadStrategy.id}";\n'
'window.\$loadModuleConfig = ${loadStrategy.loadModuleSnippet};\n'
'window.\$dwdsVersion = "$packageVersion";\n'
'window.\$dwdsDevHandlerPath = "$devHandlerPath";\n'
'window.\$dwdsEnableDevToolsLaunch = ${globalToolConfiguration.debugSettings.enableDevToolsLaunch};\n'
'window.\$dwdsEnableDevToolsLaunch = ${debugSettings.enableDevToolsLaunch};\n'
'window.\$dartEntrypointPath = "$entrypointPath";\n'
'window.\$dartEmitDebugEvents = ${globalToolConfiguration.debugSettings.emitDebugEvents};\n'
'window.\$isInternalBuild = ${globalToolConfiguration.appMetadata.isInternalBuild};\n'
'window.\$isFlutterApp = $isFlutterApp;\n'
'${globalToolConfiguration.loadStrategy.loadClientSnippet(_clientScript)}';
'window.\$dartEmitDebugEvents = ${debugSettings.emitDebugEvents};\n'
'window.\$isInternalBuild = ${appMetadata.isInternalBuild};\n'
'window.\$isFlutterApp = ${buildSettings.isFlutterApp};\n'
'${loadStrategy.loadClientSnippet(_clientScript)}';

if (extensionUri != null) {
injectedBody += 'window.\$dartExtensionUri = "$extensionUri";\n';
}
final workspaceName = globalToolConfiguration.appMetadata.workspaceName;

final workspaceName = appMetadata.workspaceName;
if (workspaceName != null) {
injectedBody += 'window.\$dartWorkspaceName = "$workspaceName";\n';
}

return injectedBody;
}
Loading
Loading