Skip to content

Commit 39d5eb1

Browse files
authored
Remove built_value dependency from HotRestartResponse (#2732)
* updated HotReloadRequest to use JSON serialization * merge main and rebuilt client.js * updated version to 26.2.4-wip * Remove package:built_value dependency from HotReloadResponse * Remove package:built_value dependency from HotRestartRequest * fix merge issue * dart format hot_restart_request.dart * Remove built_value from HotRestartResponse * dart format
1 parent 99e445f commit 39d5eb1

File tree

8 files changed

+102
-404
lines changed

8 files changed

+102
-404
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 26.2.4-wip
22

3-
- Remove `package:built_value` dependency from `HotReloadRequest`, `HotReloadResponse`, and `HotRestartRequest` and use standard Dart JSON serialization instead.
3+
- Remove `package:built_value` dependency from `HotReloadRequest`, `HotReloadResponse`, `HotRestartRequest`, and `HotRestartResponse` and use standard Dart JSON serialization instead.
44

55
## 26.2.3
66

dwds/lib/data/hot_restart_response.dart

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
library hot_restart_response;
6-
7-
import 'package:built_value/built_value.dart';
8-
import 'package:built_value/serializer.dart';
9-
10-
part 'hot_restart_response.g.dart';
11-
125
/// A response to a hot restart request.
13-
abstract class HotRestartResponse
14-
implements Built<HotRestartResponse, HotRestartResponseBuilder> {
15-
static Serializer<HotRestartResponse> get serializer =>
16-
_$hotRestartResponseSerializer;
17-
6+
class HotRestartResponse {
187
/// The unique identifier matching the request.
19-
String get id;
8+
final String id;
209

2110
/// Whether the hot restart succeeded on the client.
22-
bool get success;
11+
final bool success;
2312

2413
/// An optional error message if success is false.
25-
@BuiltValueField(wireName: 'error')
26-
String? get errorMessage;
27-
28-
HotRestartResponse._();
29-
factory HotRestartResponse([
30-
void Function(HotRestartResponseBuilder) updates,
31-
]) = _$HotRestartResponse;
14+
final String? errorMessage;
15+
16+
HotRestartResponse({
17+
required this.id,
18+
required this.success,
19+
this.errorMessage,
20+
});
21+
22+
factory HotRestartResponse.fromJson(Map<String, dynamic> json) =>
23+
HotRestartResponse(
24+
id: json['id'] as String,
25+
success: json['success'] as bool,
26+
errorMessage: json['error'] as String?,
27+
);
28+
29+
Map<String, dynamic> toJson() => {
30+
'id': id,
31+
'success': success,
32+
if (errorMessage != null) 'error': errorMessage,
33+
};
3234
}

dwds/lib/data/hot_restart_response.g.dart

Lines changed: 0 additions & 209 deletions
This file was deleted.

dwds/lib/data/serializers.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'debug_info.dart';
1212
import 'devtools_request.dart';
1313
import 'error_response.dart';
1414
import 'extension_request.dart';
15-
import 'hot_restart_response.dart';
1615
import 'service_extension_request.dart';
1716
import 'service_extension_response.dart';
1817
import 'isolate_events.dart';
@@ -31,7 +30,6 @@ part 'serializers.g.dart';
3130
DebugInfo,
3231
DevToolsRequest,
3332
DevToolsResponse,
34-
HotRestartResponse,
3533
IsolateExit,
3634
IsolateStart,
3735
ExtensionRequest,

dwds/lib/data/serializers.g.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,32 @@ class DevHandler {
327327
}
328328
}
329329

330+
/// Deserializes a message from JSON, handling both built_value serializers
331+
/// and custom fromJson() implementations.
332+
Object? _deserializeMessage(dynamic decoded) {
333+
if (decoded is List && decoded.length == 2 && decoded[0] is String) {
334+
final typeName = decoded[0] as String;
335+
final jsonData = decoded[1] as Map<String, dynamic>;
336+
337+
switch (typeName) {
338+
case 'HotReloadResponse':
339+
return HotReloadResponse.fromJson(jsonData);
340+
case 'HotRestartResponse':
341+
return HotRestartResponse.fromJson(jsonData);
342+
default:
343+
// Fall through to serializers.deserialize
344+
break;
345+
}
346+
}
347+
return serializers.deserialize(decoded);
348+
}
349+
330350
void _handleConnection(SocketConnection injectedConnection) {
331351
_injectedConnections.add(injectedConnection);
332352
AppConnection? appConnection;
333353
injectedConnection.stream.listen((data) async {
334354
try {
335-
final message = serializers.deserialize(jsonDecode(data));
355+
final message = _deserializeMessage(jsonDecode(data));
336356
if (message is ConnectRequest) {
337357
if (appConnection != null) {
338358
throw StateError(

0 commit comments

Comments
 (0)