Skip to content

Commit

Permalink
Fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Gringauze committed Jan 26, 2024
1 parent 1ecd353 commit 2fc1635
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 50 deletions.
2 changes: 1 addition & 1 deletion dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
/// traffic to disk.
///
/// Note: this should not be checked in enabled.
const _enableLogging = false;
const _enableLogging = true;

/// SSE handler to enable development features like hot reload and
/// opening DevTools.
Expand Down
52 changes: 13 additions & 39 deletions dwds/lib/src/handlers/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,21 @@ String _injectClientAndHoistMain(
String entrypointPath,
String? extensionUri,
) {
// TODO(annagrin): google3 already sets appName in the bootstrap file, so we need
// other build system to do the same before rolling this to google3, or figure a
// way to set appName here only if not defined already.
final bodyLines = body.split('\n');
final entrypointExtensionIndex =
bodyLines.indexWhere((line) => line.contains(entrypointExtensionMarker));
var result = bodyLines.sublist(0, entrypointExtensionIndex).join('\n');
result += '''
var appName = 'TestApp';
''';

final extensionIndex =
bodyLines.indexWhere((line) => line.contains(mainExtensionMarker));
var result = bodyLines.sublist(0, extensionIndex).join('\n');
result +=
bodyLines.sublist(entrypointExtensionIndex, extensionIndex).join('\n');
// The line after the marker calls `main`. We prevent `main` from
// being called and make it runnable through a global variable.
final mainFunction =
Expand All @@ -173,9 +184,7 @@ String _injectClientAndHoistMain(
}
$injectedClientSnippet
} else {
console.log("INJECTOR: registering entrypoint...");
if (typeof window.\$dartRegisterEntrypoint != "undefined") {
console.log("INJECTOR: registering entrypoint with dev handler");
window.\$dartRegisterEntrypoint(
/* app name */ appName,
/* entrypoint */ "$entrypointPath",
Expand Down Expand Up @@ -220,48 +229,13 @@ String _injectedClientSnippet(
workspaceName: appMetadata.workspaceName,
);

final injectedBody = '\n'
//' console.log("INJECTOR: registering app: " + appName);\n'
return '\n'
// Used by DDC runtime to detect if a debugger is attached.
' window.\$dwdsVersion = "$packageVersion";\n'
// Used by the injected client to communicate with the debugger.
' window.\$dartAppInfo = ${appInfo.toJs()};\n'
// Load the injected client.
' ${loadStrategy.loadClientSnippet(_clientScript)};\n';

Logger.root.warning(injectedBody);

// injectedBody += '\n'
// ' let appRecord = {};\n'
// ' appRecord.moduleStrategy = "${loadStrategy.id}";\n'
// ' appRecord.reloadConfiguration = "${loadStrategy.reloadConfiguration}";\n'
// ' appRecord.loadModuleConfig = ${loadStrategy.loadModuleSnippet};\n'
// ' appRecord.dwdsVersion = "$packageVersion";\n'
// ' appRecord.enableDevToolsLaunch = ${debugSettings.enableDevToolsLaunch};\n'
// ' appRecord.emitDebugEvents = ${debugSettings.emitDebugEvents};\n'
// ' appRecord.isInternalBuild = ${appMetadata.isInternalBuild};\n'
// ' appRecord.appName = appName;\n'
// ' appRecord.appId = "$appId";\n'
// ' appRecord.isFlutterApp = ${buildSettings.isFlutterApp};\n'
// ' appRecord.devHandlerPath = "$devHandlerPath";\n'
// ' appRecord.entrypoints = new Array();\n'
// ' appRecord.entrypoints.push("$entrypointPath");\n';

// if (extensionUri != null) {
// injectedBody += ' appRecord.extensionUrl = "$extensionUri";\n';
// }

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

// injectedBody += '\n'
// ' window.\$dartAppInfo = $appInfo;\n'
// ' console.log("INJECTOR: Loading injected client...");\n'
// ' ${loadStrategy.loadClientSnippet(_clientScript)};\n';

return injectedBody;
}

/// Generate JS app info object for the injected client.
Expand Down
2 changes: 0 additions & 2 deletions dwds/lib/src/loaders/require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ class RequireStrategy extends LoadStrategy {
/// Adds error handler code for require.js which requests a `.errors` file for
/// any failed module, and logs it to the console.
String get _requireJsConfig => '''
$_baseUrlScript;
require.config({
baseUrl: baseUrl,
waitSeconds: 0,
Expand Down Expand Up @@ -224,7 +223,6 @@ requirejs.onResourceLoad = function (context, map, depArray) {
final moduleNames =
modulePaths.map((key, value) => MapEntry<String, String>(value, key));
return '''
let appName = "TestApp"; // TODO: this needs to be set by the build's bootstrap.
$_baseUrlScript
let modulePaths = ${const JsonEncoder.withIndent(" ").convert(modulePaths)};
let moduleNames = ${const JsonEncoder.withIndent(" ").convert(moduleNames)};
Expand Down
3 changes: 0 additions & 3 deletions dwds/test/evaluate_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void testAll({
() {
setUpAll(() async {
setCurrentLogWriter(debug: debug);
print('SETUP1');
await context.setUp(
testSettings: TestSettings(
compilationMode: compilationMode,
Expand All @@ -79,7 +78,6 @@ void testAll({
verboseCompiler: debug,
),
);
print('SETUP2');
});

tearDownAll(() async {
Expand Down Expand Up @@ -113,7 +111,6 @@ void testAll({
}
},
);
print('SETUP3');
context.service.onEvent('Stdout').listen(Logger.root.info);
context.service.onEvent('Stderr').listen(Logger.root.warning);

Expand Down
2 changes: 1 addition & 1 deletion dwds/test/frontend_server_evaluate_sound_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'fixtures/project.dart';

void main() async {
// Enable verbose logging for debugging.
final debug = true;
final debug = false;

final provider = TestSdkConfigurationProvider(verbose: debug);
tearDownAll(provider.dispose);
Expand Down
3 changes: 0 additions & 3 deletions fixtures/_webdevSoundSmoke/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import 'dart:convert';
import 'dart:developer';
import 'dart:html';

int global = 3;

void main() {
print('Initial Print');
global = 4;

registerExtension('ext.print', (_, __) async {
print('Hello World');
Expand Down
2 changes: 1 addition & 1 deletion frontend_server_common/lib/src/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ String generateDDCMainModule(
return '''/* ENTRYPOINT_EXTENTION_MARKER */
(function() {
let appName = "$entrypoint";
//let appName = "$entrypoint";
// A uuid that identifies a subapp.
let uuid = "00000000-0000-0000-0000-000000000000";
Expand Down

0 comments on commit 2fc1635

Please sign in to comment.