Skip to content

Commit

Permalink
Consolidate FrontendServerDdcStrategyProvider and FrontendServerRequi…
Browse files Browse the repository at this point in the history
…reStrategyProvider under a shared parent class. - [#2517](https://gith… (#2518)

* Consolidate  and  under a shared parent class. - [#2517](#2517)

* clean up lib/src/loaders/frontend_server_strategy_provider.dart

* updated copyright date, make T extend loadstrategy and define strategies as late

* code formatting

* combine load strategies into one file and make fields/methods private

* updated path to load strategy providers and added a throw statement when new module format (ddc library bundle) is requested
  • Loading branch information
jyameo authored Nov 12, 2024
1 parent 472511d commit 18ab1d5
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 149 deletions.
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 24.2.0-wip

- Consolidate `FrontendServerDdcStrategyProvider` and `FrontendServerRequireStrategyProvider` under a shared parent class. - [#2517](https://github.com/dart-lang/webdev/issues/2517)
- Remove `build_daemon_ddc_and_canary_evaluate_test`. - [2512](https://github.com/dart-lang/webdev/issues/2512)
- Replace deprecated JS code `this.__proto__` with `Object.getPrototypeOf(this)`. - [#2500](https://github.com/dart-lang/webdev/pull/2500)
- Migrate injected client code to `package:web`. - [#2491](https://github.com/dart-lang/webdev/pull/2491)
Expand Down
8 changes: 4 additions & 4 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export 'src/handlers/socket_connections.dart';
export 'src/loaders/build_runner_require.dart'
show BuildRunnerRequireStrategyProvider;
export 'src/loaders/ddc.dart' show DdcStrategy;
export 'src/loaders/frontend_server_ddc.dart'
show FrontendServerDdcStrategyProvider;
export 'src/loaders/frontend_server_require.dart'
show FrontendServerRequireStrategyProvider;
export 'src/loaders/frontend_server_strategy_provider.dart'
show
FrontendServerDdcStrategyProvider,
FrontendServerRequireStrategyProvider;
export 'src/loaders/require.dart' show RequireStrategy;
export 'src/loaders/strategy.dart'
show LoadStrategy, ReloadConfiguration, BuildSettings;
Expand Down
114 changes: 0 additions & 114 deletions dwds/lib/src/loaders/frontend_server_require.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,51 +1,35 @@
// Copyright 2023 The Dart Authors. All rights reserved.
// Copyright 2024 The Dart Authors. 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:dwds/src/debugging/metadata/provider.dart';
import 'package:dwds/src/loaders/ddc.dart';
import 'package:dwds/src/loaders/require.dart';
import 'package:dwds/src/loaders/strategy.dart';
import 'package:dwds/src/readers/asset_reader.dart';
import 'package:dwds/src/services/expression_compiler.dart';
import 'package:path/path.dart' as p;

/// Provides a [DdcStrategy] suitable for use with Frontend Server.
class FrontendServerDdcStrategyProvider {
abstract class FrontendServerStrategyProvider<T extends LoadStrategy> {
final ReloadConfiguration _configuration;
final AssetReader _assetReader;
final PackageUriMapper _packageUriMapper;
final Future<Map<String, String>> Function() _digestsProvider;
final String _basePath;
final BuildSettings _buildSettings;

late final DdcStrategy _ddcStrategy = DdcStrategy(
_configuration,
_moduleProvider,
(_) => _digestsProvider(),
_moduleForServerPath,
_serverPathForModule,
_sourceMapPathForModule,
_serverPathForAppUri,
_moduleInfoForProvider,
_assetReader,
_buildSettings,
(String _) => null,
null,
);

FrontendServerDdcStrategyProvider(
FrontendServerStrategyProvider(
this._configuration,
this._assetReader,
this._packageUriMapper,
this._digestsProvider,
this._buildSettings,
) : _basePath = _assetReader.basePath;

DdcStrategy get strategy => _ddcStrategy;
T get strategy;

String _removeBasePath(String path) {
if (_basePath.isEmpty) return path;

final stripped = stripLeadingSlashes(path);
return stripLeadingSlashes(stripped.substring(_basePath.length));
}
Expand All @@ -54,12 +38,15 @@ class FrontendServerDdcStrategyProvider {
? stripLeadingSlashes(serverPath)
: '$_basePath/${stripLeadingSlashes(serverPath)}';

String _removeJsExtension(String path) =>
path.endsWith('.js') ? p.withoutExtension(path) : path;

Future<Map<String, String>> _moduleProvider(
MetadataProvider metadataProvider,
) async =>
(await metadataProvider.moduleToModulePath).map(
(key, value) =>
MapEntry(key, stripLeadingSlashes(removeJsExtension(value))),
MapEntry(key, stripLeadingSlashes(_removeJsExtension(value))),
);

Future<String?> _moduleForServerPath(
Expand Down Expand Up @@ -114,3 +101,61 @@ class FrontendServerDdcStrategyProvider {
return result;
}
}

/// Provides a [DdcStrategy] suitable for use with Frontend Server.
class FrontendServerDdcStrategyProvider
extends FrontendServerStrategyProvider<DdcStrategy> {
late final DdcStrategy _ddcStrategy = DdcStrategy(
_configuration,
_moduleProvider,
(_) => _digestsProvider(),
_moduleForServerPath,
_serverPathForModule,
_sourceMapPathForModule,
_serverPathForAppUri,
_moduleInfoForProvider,
_assetReader,
_buildSettings,
(String _) => null,
null,
);

FrontendServerDdcStrategyProvider(
super._configuration,
super._assetReader,
super._packageUriMapper,
super._digestsProvider,
super._buildSettings,
);

@override
DdcStrategy get strategy => _ddcStrategy;
}

/// Provides a [RequireStrategy] suitable for use with Frontend Server.
class FrontendServerRequireStrategyProvider
extends FrontendServerStrategyProvider<RequireStrategy> {
late final RequireStrategy _requireStrategy = RequireStrategy(
_configuration,
_moduleProvider,
(_) => _digestsProvider(),
_moduleForServerPath,
_serverPathForModule,
_sourceMapPathForModule,
_serverPathForAppUri,
_moduleInfoForProvider,
_assetReader,
_buildSettings,
);

FrontendServerRequireStrategyProvider(
super._configuration,
super._assetReader,
super._packageUriMapper,
super._digestsProvider,
super._buildSettings,
);

@override
RequireStrategy get strategy => _requireStrategy;
}
22 changes: 13 additions & 9 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import 'package:dwds/src/connections/app_connection.dart';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/debugging/webkit_debugger.dart';
import 'package:dwds/src/loaders/build_runner_require.dart';
import 'package:dwds/src/loaders/frontend_server_ddc.dart';
import 'package:dwds/src/loaders/frontend_server_require.dart';
import 'package:dwds/src/loaders/frontend_server_strategy_provider.dart';
import 'package:dwds/src/loaders/strategy.dart';
import 'package:dwds/src/readers/proxy_server_asset_reader.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
Expand Down Expand Up @@ -348,13 +347,18 @@ class TestContext {
() async => {},
buildSettings,
).strategy,
ModuleFormat.ddc => FrontendServerDdcStrategyProvider(
testSettings.reloadConfiguration,
assetReader,
packageUriMapper,
() async => {},
buildSettings,
).strategy,
ModuleFormat.ddc => buildSettings.canaryFeatures
? throw Exception(
'''Unsupported DDC module format ${testSettings.moduleFormat.name}
with canaryFeatures set to ${buildSettings.canaryFeatures}.''',
)
: FrontendServerDdcStrategyProvider(
testSettings.reloadConfiguration,
assetReader,
packageUriMapper,
() async => {},
buildSettings,
).strategy,
_ => throw Exception(
'Unsupported DDC module format ${testSettings.moduleFormat.name}.',
)
Expand Down

0 comments on commit 18ab1d5

Please sign in to comment.