Skip to content

Add an option to dwds to suppress emitting debug events #1467

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
merged 2 commits into from
Dec 16, 2021
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
2 changes: 2 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
**Breaking changes:**

- Add `sdkDir` argument to `Dwds.start` to help file resolution for sdk uris.
- Add `emitDebugEvents` argument to `Dwds.start` to suppress emitting debug
events from the injected client.

## 11.5.1

Expand Down
3 changes: 3 additions & 0 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Dwds {
bool enableDevtoolsLaunch,
DevtoolsLauncher devtoolsLauncher,
Uri sdkDir,
bool emitDebugEvents,
}) async {
hostname ??= 'localhost';
enableDebugging ??= true;
Expand All @@ -123,6 +124,7 @@ class Dwds {
enableDevtoolsLaunch ??= true;
spawnDds ??= true;
globalLoadStrategy = loadStrategy;
emitDebugEvents ??= true;

await DartUri.initialize(sdkDir: sdkDir);

Expand Down Expand Up @@ -162,6 +164,7 @@ class Dwds {
useSseForInjectedClient: useSseForInjectedClient,
extensionUri: extensionUri,
enableDevtoolsLaunch: enableDevtoolsLaunch,
emitDebugEvents: emitDebugEvents,
);

var devHandler = DevHandler(
Expand Down
10 changes: 9 additions & 1 deletion dwds/lib/src/handlers/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ class DwdsInjector {
final _logger = Logger('DwdsInjector');
final bool _enableDevtoolsLaunch;
final bool _useSseForInjectedClient;
final bool _emitDebugEvents;

DwdsInjector(
this._loadStrategy, {
Future<String> extensionUri,
bool enableDevtoolsLaunch,
bool useSseForInjectedClient,
bool emitDebugEvents,
}) : _extensionUri = extensionUri,
_enableDevtoolsLaunch = enableDevtoolsLaunch,
_useSseForInjectedClient = useSseForInjectedClient ?? true;
_useSseForInjectedClient = useSseForInjectedClient ?? true,
_emitDebugEvents = emitDebugEvents ?? true;

/// Returns the embedded dev handler paths.
///
Expand Down Expand Up @@ -107,6 +110,7 @@ class DwdsInjector {
await _extensionUri,
_loadStrategy,
_enableDevtoolsLaunch,
_emitDebugEvents,
);
body += await _loadStrategy.bootstrapFor(entrypoint);
_logger.info('Injected debugging metadata for '
Expand Down Expand Up @@ -137,6 +141,7 @@ String _injectClientAndHoistMain(
String extensionUri,
LoadStrategy loadStrategy,
bool enableDevtoolsLaunch,
bool emitDebugEvents,
) {
var bodyLines = body.split('\n');
var extensionIndex =
Expand All @@ -156,6 +161,7 @@ String _injectClientAndHoistMain(
extensionUri,
loadStrategy,
enableDevtoolsLaunch,
emitDebugEvents,
);
result += '''
// Injected by dwds for debugging support.
Expand Down Expand Up @@ -189,6 +195,7 @@ String _injectedClientSnippet(
String extensionUri,
LoadStrategy loadStrategy,
bool enableDevtoolsLaunch,
bool emitDebugEvents,
) {
var injectedBody = 'window.\$dartAppId = "$appId";\n'
'window.\$dartReloadConfiguration = "${loadStrategy.reloadConfiguration}";\n'
Expand All @@ -198,6 +205,7 @@ String _injectedClientSnippet(
'window.\$dwdsDevHandlerPath = "$devHandlerPath";\n'
'window.\$dwdsEnableDevtoolsLaunch = $enableDevtoolsLaunch;\n'
'window.\$dartEntrypointPath = "$entrypointPath";\n'
'window.\$dartEmitDebugEvents = "$emitDebugEvents";\n'
'${loadStrategy.loadClientSnippet(_clientScript)}';
if (extensionUri != null) {
injectedBody += 'window.\$dartExtensionUri = "$extensionUri";\n';
Expand Down
Loading