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

Use 'compile js-dev' instead of invoking DDC directly #2579

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
@@ -1,5 +1,7 @@
## 24.3.4-wip

- Use 'compile js-dev' for compilation instead of invoking DDC directly using knowledge of internals of the dart sdk

## 24.3.3

- Added support for some debugging APIs with the DDC library bundle format. - [#2563](https://github.com/dart-lang/webdev/issues/2563)
Expand Down
38 changes: 19 additions & 19 deletions dwds/debug_extension/tool/build_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,38 @@ import 'package:path/path.dart' as p;
const _prodFlag = 'prod';

void main(List<String> arguments) async {
final parser = ArgParser()
..addFlag(_prodFlag, negatable: true, defaultsTo: false);
final parser =
ArgParser()..addFlag(_prodFlag, negatable: true, defaultsTo: false);
final argResults = parser.parse(arguments);

exitCode = await run(
isProd: argResults[_prodFlag] as bool,
);
exitCode = await run(isProd: argResults[_prodFlag] as bool);
if (exitCode != 0) {
_logWarning('Run terminated unexpectedly with exit code: $exitCode');
}
}

Future<int> run({required bool isProd}) async {
_logInfo(
'Building extension for ${isProd ? 'prod' : 'dev'}',
);
_logInfo('Building extension for ${isProd ? 'prod' : 'dev'}');
_logInfo('Compiling extension with dart2js to /compiled directory');
final compileStep = await Process.start(
'dart',
['run', 'build_runner', 'build', 'web', '--output', 'build', '--release'],
);
final compileStep = await Process.start('dart', [
'run',
'build_runner',
'build',
'web',
'--output',
'build',
'--release',
]);
final compileExitCode = await _handleProcess(compileStep);
// Terminate early if compilation failed:
if (compileExitCode != 0) {
return compileExitCode;
}
_logInfo('Copying manifest.json to /compiled directory');
try {
File(p.join('web', 'manifest.json')).copySync(
p.join('compiled', 'manifest.json'),
);
File(
p.join('web', 'manifest.json'),
).copySync(p.join('compiled', 'manifest.json'));
} catch (error) {
_logWarning('Copying manifest file failed: $error');
// Return non-zero exit code to indicate failure:
Expand All @@ -60,10 +61,9 @@ Future<int> run({required bool isProd}) async {
if (isProd) return 0;
// Update manifest.json for dev:
_logInfo('Updating manifest.json in /compiled directory.');
final updateStep = await Process.start(
'dart',
[p.join('tool', 'update_dev_files.dart')],
);
final updateStep = await Process.start('dart', [
p.join('tool', 'update_dev_files.dart'),
]);
final updateExitCode = await _handleProcess(updateStep);
// Return exit code (0 indicates success):
return updateExitCode;
Expand Down
12 changes: 6 additions & 6 deletions dwds/debug_extension/tool/copy_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Builder copyBuilder(_) => _CopyBuilder();
class _CopyBuilder extends Builder {
@override
Map<String, List<String>> get buildExtensions => {
'web/{{}}.dart.js': ['compiled/{{}}.dart.js'],
'web/static_assets/{{}}.png': ['compiled/static_assets/{{}}.png'],
'web/static_assets/{{}}.html': ['compiled/static_assets/{{}}.html'],
'web/static_assets/{{}}.css': ['compiled/static_assets/{{}}.css'],
'web/manifest.json': ['compiled/manifest.json'],
};
'web/{{}}.dart.js': ['compiled/{{}}.dart.js'],
'web/static_assets/{{}}.png': ['compiled/static_assets/{{}}.png'],
'web/static_assets/{{}}.html': ['compiled/static_assets/{{}}.html'],
'web/static_assets/{{}}.css': ['compiled/static_assets/{{}}.css'],
'web/manifest.json': ['compiled/manifest.json'],
};

@override
Future<void> build(BuildStep buildStep) async {
Expand Down
13 changes: 5 additions & 8 deletions dwds/debug_extension/tool/update_dev_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ void main() async {
Future<void> _updateManifestJson() async {
final manifestJson = File('compiled/manifest.json');
final extensionKeyTxt = File('extension_key.txt');
final extensionKey = await extensionKeyTxt.exists()
? await extensionKeyTxt.readAsString()
: null;
final extensionKey =
await extensionKeyTxt.exists()
? await extensionKeyTxt.readAsString()
: null;
return _transformDevFile(manifestJson, (line) {
if (_matchesKey(line: line, key: 'name')) {
return [
Expand All @@ -24,11 +25,7 @@ Future<void> _updateManifestJson() async {
newValue: '[DEV] Dart Debug Extension',
),
if (extensionKey != null)
_newKeyValue(
oldLine: line,
newKey: 'key',
newValue: extensionKey,
),
_newKeyValue(oldLine: line, newKey: 'key', newValue: extensionKey),
];
} else if (_matchesKey(line: line, key: 'default_icon')) {
return [
Expand Down
50 changes: 25 additions & 25 deletions dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ void main() {
}

void _registerListeners() {
chrome.runtime.onMessage.addListener(
allowInterop(_handleRuntimeMessages),
);
chrome.runtime.onMessage.addListener(allowInterop(_handleRuntimeMessages));
// The only extension allowed to send messages to this extension is the
// AngularDart DevTools extension. Its permission is set in the manifest.json
// externally_connectable field.
Expand All @@ -34,8 +32,9 @@ void _registerListeners() {
);
// The only external service that sends messages to the Dart Debug Extension
// is Cider.
chrome.runtime.onConnectExternal
.addListener(allowInterop(handleCiderConnectRequest));
chrome.runtime.onConnectExternal.addListener(
allowInterop(handleCiderConnectRequest),
);
// Update the extension icon on tab navigation:
chrome.tabs.onActivated.addListener(
allowInterop((ActiveInfo info) async {
Expand All @@ -50,11 +49,13 @@ void _registerListeners() {
}
}),
);
chrome.webNavigation.onCommitted
.addListener(allowInterop(_detectNavigationAwayFromDartApp));
chrome.webNavigation.onCommitted.addListener(
allowInterop(_detectNavigationAwayFromDartApp),
);

chrome.commands.onCommand
.addListener(allowInterop(_maybeSendCopyAppIdRequest));
chrome.commands.onCommand.addListener(
allowInterop(_maybeSendCopyAppIdRequest),
);
}

Future<void> _handleRuntimeMessages(
Expand Down Expand Up @@ -214,19 +215,20 @@ bool _isInternalNavigation(NavigationInfo navigationInfo) {

DebugInfo _addTabInfo(DebugInfo debugInfo, {required Tab tab}) {
return DebugInfo(
(b) => b
..appEntrypointPath = debugInfo.appEntrypointPath
..appId = debugInfo.appId
..appInstanceId = debugInfo.appInstanceId
..appOrigin = debugInfo.appOrigin
..appUrl = debugInfo.appUrl
..authUrl = debugInfo.authUrl
..extensionUrl = debugInfo.extensionUrl
..isInternalBuild = debugInfo.isInternalBuild
..isFlutterApp = debugInfo.isFlutterApp
..workspaceName = debugInfo.workspaceName
..tabUrl = tab.url
..tabId = tab.id,
(b) =>
b
..appEntrypointPath = debugInfo.appEntrypointPath
..appId = debugInfo.appId
..appInstanceId = debugInfo.appInstanceId
..appOrigin = debugInfo.appOrigin
..appUrl = debugInfo.appUrl
..authUrl = debugInfo.authUrl
..extensionUrl = debugInfo.extensionUrl
..isInternalBuild = debugInfo.isInternalBuild
..isFlutterApp = debugInfo.isFlutterApp
..workspaceName = debugInfo.workspaceName
..tabUrl = tab.url
..tabId = tab.id,
);
}

Expand Down Expand Up @@ -279,9 +281,7 @@ void _setDefaultIcon(int tabId) {
final iconPath =
isDevMode ? 'static_assets/dart_dev.png' : 'static_assets/dart_grey.png';
setExtensionIcon(IconInfo(path: iconPath));
setExtensionPopup(
PopupDetails(popup: '', tabId: tabId),
);
setExtensionPopup(PopupDetails(popup: '', tabId: tabId));
}

Future<DebugInfo?> _fetchDebugInfo(int tabId) {
Expand Down
8 changes: 2 additions & 6 deletions dwds/debug_extension/web/chrome_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ class Notifications {
@JS()
@anonymous
class OnClickedHandler {
external void addListener(
void Function(String) callback,
);
external void addListener(void Function(String) callback);
}

@JS()
Expand Down Expand Up @@ -233,9 +231,7 @@ class Port {
@JS()
@anonymous
class OnPortMessageHandler {
external void addListener(
void Function(dynamic, Port) callback,
);
external void addListener(void Function(dynamic, Port) callback);
}

@JS()
Expand Down
23 changes: 6 additions & 17 deletions dwds/debug_extension/web/cider_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ enum CiderMessageType {
///
/// The types must match those defined by ChromeExtensionErrorType in the
/// Cider extension.
enum CiderErrorType {
internalError,
invalidRequest,
noAppId,
}
enum CiderErrorType { internalError, invalidRequest, noAppId }

const _ciderPortName = 'cider';
Port? _ciderPort;
Expand All @@ -62,9 +58,7 @@ void handleCiderConnectRequest(Port port) {
debugLog('Received connect request from Cider', verbose: true);
_ciderPort = port;

port.onMessage.addListener(
allowInterop(_handleMessageFromCider),
);
port.onMessage.addListener(allowInterop(_handleMessageFromCider));

sendMessageToCider(messageType: CiderMessageType.connected);
}
Expand Down Expand Up @@ -99,10 +93,7 @@ void sendErrorMessageToCider({
}

void _sendMessageToCider(String json) {
final message = {
'key': _ciderDartMessageKey,
'json': json,
};
final message = {'key': _ciderDartMessageKey, 'json': json};
_ciderPort!.postMessage(jsify(message));
}

Expand Down Expand Up @@ -177,7 +168,8 @@ Future<void> _sendInspectorUrl({String? appId}) async {
if (!alreadyDebugging) {
sendErrorMessageToCider(
errorType: CiderErrorType.invalidRequest,
errorDetails: 'Cannot send the inspector URL before '
errorDetails:
'Cannot send the inspector URL before '
'the debugger has been attached.',
);
return;
Expand All @@ -195,10 +187,7 @@ Future<void> _sendInspectorUrl({String? appId}) async {
}
final inspectorUrl = addQueryParameters(
devToolsUri,
queryParameters: {
'embed': 'true',
'page': 'inspector',
},
queryParameters: {'embed': 'true', 'page': 'inspector'},
);
sendMessageToCider(
messageType: CiderMessageType.inspectorUrlResponse,
Expand Down
14 changes: 6 additions & 8 deletions dwds/debug_extension/web/copier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ void main() {
}

void _registerListeners() {
chrome.runtime.onMessage.addListener(
allowInterop(_handleRuntimeMessages),
);
chrome.runtime.onMessage.addListener(allowInterop(_handleRuntimeMessages));
}

void _handleRuntimeMessages(
Expand Down Expand Up @@ -49,8 +47,8 @@ void _copyAppId(String appId) {
}

Future<bool> _notifyCopiedSuccess(String appId) => sendRuntimeMessage(
type: MessageType.appId,
body: appId,
sender: Script.copier,
recipient: Script.background,
);
type: MessageType.appId,
body: appId,
sender: Script.copier,
recipient: Script.background,
);
29 changes: 11 additions & 18 deletions dwds/debug_extension/web/cross_extension_communication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ void maybeForwardMessageToAngularDartDevTools({
}) {
if (!_eventsForAngularDartDevTools.contains(method)) return;

final message = method.startsWith('dwds')
? _dwdsEventMessage(method: method, params: params, tabId: tabId)
: _debugEventMessage(method: method, params: params, tabId: tabId);
final message =
method.startsWith('dwds')
? _dwdsEventMessage(method: method, params: params, tabId: tabId)
: _debugEventMessage(method: method, params: params, tabId: tabId);

_forwardMessageToAngularDartDevTools(message);
}
Expand Down Expand Up @@ -87,9 +88,7 @@ void _respondWithChromeResult(Object? chromeResult, Function sendResponse) {
if (chromeResult == null) {
sendResponse(
ErrorResponse()
..error = JSON.stringify(
chrome.runtime.lastError ?? 'Unknown error.',
),
..error = JSON.stringify(chrome.runtime.lastError ?? 'Unknown error.'),
);
} else {
sendResponse(chromeResult);
Expand Down Expand Up @@ -126,23 +125,17 @@ ExternalExtensionMessage _debugEventMessage({
required String method,
required dynamic params,
required int tabId,
}) =>
ExternalExtensionMessage(
name: 'chrome.debugger.event',
tabId: tabId,
options: DebugEvent(method: method, params: params),
);
}) => ExternalExtensionMessage(
name: 'chrome.debugger.event',
tabId: tabId,
options: DebugEvent(method: method, params: params),
);

ExternalExtensionMessage _dwdsEventMessage({
required String method,
required dynamic params,
required int tabId,
}) =>
ExternalExtensionMessage(
name: method,
tabId: tabId,
options: params,
);
}) => ExternalExtensionMessage(name: method, tabId: tabId, options: params);

// This message is used for cross-extension communication between this extension
// and the AngularDart DevTools extension.
Expand Down
Loading
Loading