miaoda-expo-devkit 0.1.1-dev.development-build.6 → 0.1.1-dev.development-build.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/package.json +1 -1
- package/pnpm-patches/expo@55.0.6.patch +547 -23
- package/pnpm-patches/metro-runtime@0.83.3.patch +351 -3
- package/pnpm-patches/react-native@0.83.2.patch +205 -19
- package/pnpmfile.cjs +8 -1
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
diff --git a/src/modules/HMRClient.js b/src/modules/HMRClient.js
|
|
2
|
-
index 3e2652d..
|
|
2
|
+
index 3e2652d..111bf20 100644
|
|
3
3
|
--- a/src/modules/HMRClient.js
|
|
4
4
|
+++ b/src/modules/HMRClient.js
|
|
5
|
-
@@ -
|
|
5
|
+
@@ -15,12 +15,21 @@ const injectUpdate = (update) => {
|
|
6
|
+
class HMRClient extends EventEmitter {
|
|
7
|
+
_isEnabled = false;
|
|
8
|
+
_pendingUpdate = null;
|
|
9
|
+
+ _updateGate = null;
|
|
10
|
+
+ _updateGeneration = 0;
|
|
11
|
+
+ _gateEpoch = 0;
|
|
12
|
+
+ _gateRunning = false;
|
|
13
|
+
+ _gateRequested = false;
|
|
14
|
+
+ _isInvalid = false;
|
|
15
|
+
_queue = [];
|
|
16
|
+
_state = "opening";
|
|
17
|
+
constructor(url) {
|
|
18
|
+
super();
|
|
19
|
+
this._ws = new global.WebSocket(url);
|
|
20
|
+
this._ws.onopen = () => {
|
|
21
|
+
+ if (this._isInvalid) {
|
|
22
|
+
+ return;
|
|
23
|
+
+ }
|
|
24
|
+
this._state = "open";
|
|
25
|
+
this.emit("open");
|
|
26
|
+
this._flushQueue();
|
|
27
|
+
@@ -29,12 +38,20 @@ class HMRClient extends EventEmitter {
|
|
28
|
+
this.emit("connection-error", error);
|
|
29
|
+
};
|
|
30
|
+
this._ws.onclose = (closeEvent) => {
|
|
31
|
+
- this._state = "closed";
|
|
32
|
+
+ this._invalidate();
|
|
33
|
+
this.emit("close", closeEvent);
|
|
34
|
+
};
|
|
6
35
|
this._ws.onmessage = (message) => {
|
|
7
36
|
const data = JSON.parse(String(message.data));
|
|
8
37
|
switch (data.type) {
|
|
@@ -10,8 +39,327 @@ index 3e2652d..8225714 100644
|
|
|
10
39
|
+ // 控制消息。HMRClient 只做透传转发,具体处理在 expo 包的
|
|
11
40
|
+ // async-require/hmr.ts(该补丁同时加了版本协商,version !== 1 直接忽略)。
|
|
12
41
|
+ case "miaoda-hmr-control":
|
|
13
|
-
+ if (data.version === 1)
|
|
42
|
+
+ if (data.version === 1) {
|
|
43
|
+
+ this.emit("miaoda-hmr-control", data);
|
|
44
|
+
+ }
|
|
14
45
|
+ break;
|
|
15
46
|
case "bundle-registered":
|
|
16
47
|
this.emit("bundle-registered");
|
|
17
48
|
break;
|
|
49
|
+
@@ -58,16 +75,18 @@ class HMRClient extends EventEmitter {
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.on("update", (update) => {
|
|
53
|
+
- if (this._isEnabled) {
|
|
54
|
+
- injectUpdate(update);
|
|
55
|
+
- } else if (this._pendingUpdate == null) {
|
|
56
|
+
- this._pendingUpdate = update;
|
|
57
|
+
- } else {
|
|
58
|
+
- this._pendingUpdate = mergeUpdates(this._pendingUpdate, update);
|
|
59
|
+
+ if (this._isInvalid) {
|
|
60
|
+
+ return;
|
|
61
|
+
}
|
|
62
|
+
+ this._updateGeneration++;
|
|
63
|
+
+ this._pendingUpdate = this._pendingUpdate == null
|
|
64
|
+
+ ? update
|
|
65
|
+
+ : mergeUpdates(this._pendingUpdate, update);
|
|
66
|
+
+ this._requestPendingUpdate();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
close() {
|
|
70
|
+
+ this._invalidate();
|
|
71
|
+
this._ws.close();
|
|
72
|
+
}
|
|
73
|
+
send(message) {
|
|
74
|
+
@@ -89,15 +108,98 @@ class HMRClient extends EventEmitter {
|
|
75
|
+
this._queue.length = 0;
|
|
76
|
+
}
|
|
77
|
+
enable() {
|
|
78
|
+
+ if (this._isInvalid || this._isEnabled) {
|
|
79
|
+
+ return;
|
|
80
|
+
+ }
|
|
81
|
+
this._isEnabled = true;
|
|
82
|
+
+ this._requestPendingUpdate();
|
|
83
|
+
+ }
|
|
84
|
+
+ disable() {
|
|
85
|
+
+ this._isEnabled = false;
|
|
86
|
+
+ this._gateEpoch++;
|
|
87
|
+
+ }
|
|
88
|
+
+ setUpdateGate(gate) {
|
|
89
|
+
+ if (this._updateGate === gate) {
|
|
90
|
+
+ return;
|
|
91
|
+
+ }
|
|
92
|
+
+ this._updateGate = gate;
|
|
93
|
+
+ this._gateEpoch++;
|
|
94
|
+
+ this._requestPendingUpdate();
|
|
95
|
+
+ }
|
|
96
|
+
+ retryPendingUpdate() {
|
|
97
|
+
+ this._gateEpoch++;
|
|
98
|
+
+ this._requestPendingUpdate();
|
|
99
|
+
+ }
|
|
100
|
+
+ _invalidate() {
|
|
101
|
+
+ this._isInvalid = true;
|
|
102
|
+
+ this._isEnabled = false;
|
|
103
|
+
+ this._state = "closed";
|
|
104
|
+
+ this._gateEpoch++;
|
|
105
|
+
+ }
|
|
106
|
+
+ _requestPendingUpdate() {
|
|
107
|
+
+ this._gateRequested = true;
|
|
108
|
+
+ this._flushPendingUpdate();
|
|
109
|
+
+ }
|
|
110
|
+
+ _flushPendingUpdate() {
|
|
111
|
+
+ if (this._isInvalid || !this._isEnabled || this._gateRunning || !this._gateRequested) {
|
|
112
|
+
+ return;
|
|
113
|
+
+ }
|
|
114
|
+
+ this._gateRequested = false;
|
|
115
|
+
const update = this._pendingUpdate;
|
|
116
|
+
+ if (update == null) {
|
|
117
|
+
+ return;
|
|
118
|
+
+ }
|
|
119
|
+
+ const gate = this._updateGate;
|
|
120
|
+
+ if (gate == null || (update.added.length === 0 && update.modified.length === 0 && update.deleted.length === 0)) {
|
|
121
|
+
+ this._applyPendingUpdate(update);
|
|
122
|
+
+ return;
|
|
123
|
+
+ }
|
|
124
|
+
+ this._gateRunning = true;
|
|
125
|
+
+ this._runUpdateGate(update, this._updateGeneration, this._gateEpoch, gate).catch(error => {
|
|
126
|
+
+ // 异步路径不能把监听器或收尾异常变成未处理的 Promise 拒绝。
|
|
127
|
+
+ this._emitSafely("update-gate-error", error);
|
|
128
|
+
+ });
|
|
129
|
+
+ }
|
|
130
|
+
+ async _runUpdateGate(update, generation, epoch, gate) {
|
|
131
|
+
+ const isCurrent = () => !this._isInvalid && this._isEnabled &&
|
|
132
|
+
+ this._pendingUpdate === update && this._updateGeneration === generation && this._gateEpoch === epoch;
|
|
133
|
+
+ try {
|
|
134
|
+
+ let allowed;
|
|
135
|
+
+ try {
|
|
136
|
+
+ allowed = await gate(isCurrent);
|
|
137
|
+
+ } catch (error) {
|
|
138
|
+
+ this._emitSafely("update-gate-error", error);
|
|
139
|
+
+ return;
|
|
140
|
+
+ }
|
|
141
|
+
+ if (allowed && isCurrent()) {
|
|
142
|
+
+ this._applyPendingUpdate(update, true);
|
|
143
|
+
+ }
|
|
144
|
+
+ } finally {
|
|
145
|
+
+ // 旧检查完成后才处理新请求,避免同时出现多个兼容性弹窗。
|
|
146
|
+
+ this._gateRunning = false;
|
|
147
|
+
+ this._flushPendingUpdate();
|
|
148
|
+
+ }
|
|
149
|
+
+ }
|
|
150
|
+
+ _emitSafely(event, value) {
|
|
151
|
+
+ try {
|
|
152
|
+
+ this.emit(event, value);
|
|
153
|
+
+ } catch (error) {
|
|
154
|
+
+ // 事件监听器属于宿主代码,不能破坏 gate 的异步收尾。
|
|
155
|
+
+ }
|
|
156
|
+
+ }
|
|
157
|
+
+ _applyPendingUpdate(update, handleErrors = false) {
|
|
158
|
+
+ // 注入必须同步完成;提前移除整批,避免部分注入失败后被重放。
|
|
159
|
+
this._pendingUpdate = null;
|
|
160
|
+
- if (update != null) {
|
|
161
|
+
+ try {
|
|
162
|
+
injectUpdate(update);
|
|
163
|
+
+ } catch (error) {
|
|
164
|
+
+ if (!handleErrors) {
|
|
165
|
+
+ throw error;
|
|
166
|
+
+ }
|
|
167
|
+
+ this._emitSafely("update-apply-error", error);
|
|
168
|
+
+ return;
|
|
169
|
+
}
|
|
170
|
+
- }
|
|
171
|
+
- disable() {
|
|
172
|
+
- this._isEnabled = false;
|
|
173
|
+
+ this._emitSafely("update-applied", update);
|
|
174
|
+
}
|
|
175
|
+
isEnabled() {
|
|
176
|
+
return this._isEnabled;
|
|
177
|
+
diff --git a/src/modules/HMRClient.js.flow b/src/modules/HMRClient.js.flow
|
|
178
|
+
index 18040c4..62b7b20 100644
|
|
179
|
+
--- a/src/modules/HMRClient.js.flow
|
|
180
|
+
+++ b/src/modules/HMRClient.js.flow
|
|
181
|
+
@@ -15,6 +15,8 @@ import type {HmrMessage, HmrUpdate} from './types';
|
|
182
|
+
|
|
183
|
+
const EventEmitter = require('./vendor/eventemitter3');
|
|
184
|
+
|
|
185
|
+
+type UpdateGate = (isCurrent: () => boolean) => Promise<boolean>;
|
|
186
|
+
+
|
|
187
|
+
type SocketState = 'opening' | 'open' | 'closed';
|
|
188
|
+
|
|
189
|
+
const inject = ({module: [id, code], sourceURL}: HmrModule) => {
|
|
190
|
+
@@ -36,6 +38,12 @@ const injectUpdate = (update: HmrUpdate) => {
|
|
191
|
+
class HMRClient extends EventEmitter {
|
|
192
|
+
_isEnabled: boolean = false;
|
|
193
|
+
_pendingUpdate: HmrUpdate | null = null;
|
|
194
|
+
+ _updateGate: UpdateGate | null = null;
|
|
195
|
+
+ _updateGeneration: number = 0;
|
|
196
|
+
+ _gateEpoch: number = 0;
|
|
197
|
+
+ _gateRunning: boolean = false;
|
|
198
|
+
+ _gateRequested: boolean = false;
|
|
199
|
+
+ _isInvalid: boolean = false;
|
|
200
|
+
_queue: Array<string> = [];
|
|
201
|
+
_state: SocketState = 'opening';
|
|
202
|
+
_ws: WebSocket;
|
|
203
|
+
@@ -47,6 +55,9 @@ class HMRClient extends EventEmitter {
|
|
204
|
+
// since some polyfills do the initialization lazily.
|
|
205
|
+
this._ws = new global.WebSocket(url);
|
|
206
|
+
this._ws.onopen = () => {
|
|
207
|
+
+ if (this._isInvalid) {
|
|
208
|
+
+ return;
|
|
209
|
+
+ }
|
|
210
|
+
this._state = 'open';
|
|
211
|
+
this.emit('open');
|
|
212
|
+
this._flushQueue();
|
|
213
|
+
@@ -55,13 +66,20 @@ class HMRClient extends EventEmitter {
|
|
214
|
+
this.emit('connection-error', error);
|
|
215
|
+
};
|
|
216
|
+
this._ws.onclose = closeEvent => {
|
|
217
|
+
- this._state = 'closed';
|
|
218
|
+
+ this._invalidate();
|
|
219
|
+
this.emit('close', closeEvent);
|
|
220
|
+
};
|
|
221
|
+
this._ws.onmessage = message => {
|
|
222
|
+
- const data: HmrMessage = JSON.parse(String(message.data));
|
|
223
|
+
+ const data: HmrMessage | {type: 'miaoda-hmr-control', version: number, [string]: mixed} = JSON.parse(String(message.data));
|
|
224
|
+
|
|
225
|
+
switch (data.type) {
|
|
226
|
+
+ // 与运行代码对齐,只透传当前版本的批量编辑控制帧。
|
|
227
|
+
+ case 'miaoda-hmr-control':
|
|
228
|
+
+ if (data.version === 1) {
|
|
229
|
+
+ this.emit('miaoda-hmr-control', data);
|
|
230
|
+
+ }
|
|
231
|
+
+ break;
|
|
232
|
+
+
|
|
233
|
+
case 'bundle-registered':
|
|
234
|
+
this.emit('bundle-registered');
|
|
235
|
+
break;
|
|
236
|
+
@@ -88,17 +106,19 @@ class HMRClient extends EventEmitter {
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
this.on('update', (update: HmrUpdate) => {
|
|
240
|
+
- if (this._isEnabled) {
|
|
241
|
+
- injectUpdate(update);
|
|
242
|
+
- } else if (this._pendingUpdate == null) {
|
|
243
|
+
- this._pendingUpdate = update;
|
|
244
|
+
- } else {
|
|
245
|
+
- this._pendingUpdate = mergeUpdates(this._pendingUpdate, update);
|
|
246
|
+
+ if (this._isInvalid) {
|
|
247
|
+
+ return;
|
|
248
|
+
}
|
|
249
|
+
+ this._updateGeneration++;
|
|
250
|
+
+ this._pendingUpdate = this._pendingUpdate == null
|
|
251
|
+
+ ? update
|
|
252
|
+
+ : mergeUpdates(this._pendingUpdate, update);
|
|
253
|
+
+ this._requestPendingUpdate();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
close(): void {
|
|
258
|
+
+ this._invalidate();
|
|
259
|
+
this._ws.close();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@@ -124,16 +144,98 @@ class HMRClient extends EventEmitter {
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
enable() {
|
|
266
|
+
+ if (this._isInvalid || this._isEnabled) {
|
|
267
|
+
+ return;
|
|
268
|
+
+ }
|
|
269
|
+
this._isEnabled = true;
|
|
270
|
+
+ this._requestPendingUpdate();
|
|
271
|
+
+ }
|
|
272
|
+
+ disable() {
|
|
273
|
+
+ this._isEnabled = false;
|
|
274
|
+
+ this._gateEpoch++;
|
|
275
|
+
+ }
|
|
276
|
+
+ setUpdateGate(gate: UpdateGate | null) {
|
|
277
|
+
+ if (this._updateGate === gate) {
|
|
278
|
+
+ return;
|
|
279
|
+
+ }
|
|
280
|
+
+ this._updateGate = gate;
|
|
281
|
+
+ this._gateEpoch++;
|
|
282
|
+
+ this._requestPendingUpdate();
|
|
283
|
+
+ }
|
|
284
|
+
+ retryPendingUpdate() {
|
|
285
|
+
+ this._gateEpoch++;
|
|
286
|
+
+ this._requestPendingUpdate();
|
|
287
|
+
+ }
|
|
288
|
+
+ _invalidate() {
|
|
289
|
+
+ this._isInvalid = true;
|
|
290
|
+
+ this._isEnabled = false;
|
|
291
|
+
+ this._state = 'closed';
|
|
292
|
+
+ this._gateEpoch++;
|
|
293
|
+
+ }
|
|
294
|
+
+ _requestPendingUpdate() {
|
|
295
|
+
+ this._gateRequested = true;
|
|
296
|
+
+ this._flushPendingUpdate();
|
|
297
|
+
+ }
|
|
298
|
+
+ _flushPendingUpdate() {
|
|
299
|
+
+ if (this._isInvalid || !this._isEnabled || this._gateRunning || !this._gateRequested) {
|
|
300
|
+
+ return;
|
|
301
|
+
+ }
|
|
302
|
+
+ this._gateRequested = false;
|
|
303
|
+
const update = this._pendingUpdate;
|
|
304
|
+
+ if (update == null) {
|
|
305
|
+
+ return;
|
|
306
|
+
+ }
|
|
307
|
+
+ const gate = this._updateGate;
|
|
308
|
+
+ if (gate == null || (update.added.length === 0 && update.modified.length === 0 && update.deleted.length === 0)) {
|
|
309
|
+
+ this._applyPendingUpdate(update);
|
|
310
|
+
+ return;
|
|
311
|
+
+ }
|
|
312
|
+
+ this._gateRunning = true;
|
|
313
|
+
+ this._runUpdateGate(update, this._updateGeneration, this._gateEpoch, gate).catch(error => {
|
|
314
|
+
+ // 异步路径不能把监听器或收尾异常变成未处理的 Promise 拒绝。
|
|
315
|
+
+ this._emitSafely('update-gate-error', error);
|
|
316
|
+
+ });
|
|
317
|
+
+ }
|
|
318
|
+
+ async _runUpdateGate(update: HmrUpdate, generation: number, epoch: number, gate: UpdateGate): Promise<void> {
|
|
319
|
+
+ const isCurrent = () => !this._isInvalid && this._isEnabled &&
|
|
320
|
+
+ this._pendingUpdate === update && this._updateGeneration === generation && this._gateEpoch === epoch;
|
|
321
|
+
+ try {
|
|
322
|
+
+ let allowed;
|
|
323
|
+
+ try {
|
|
324
|
+
+ allowed = await gate(isCurrent);
|
|
325
|
+
+ } catch (error) {
|
|
326
|
+
+ this._emitSafely('update-gate-error', error);
|
|
327
|
+
+ return;
|
|
328
|
+
+ }
|
|
329
|
+
+ if (allowed && isCurrent()) {
|
|
330
|
+
+ this._applyPendingUpdate(update, true);
|
|
331
|
+
+ }
|
|
332
|
+
+ } finally {
|
|
333
|
+
+ // 旧检查完成后才处理新请求,避免同时出现多个兼容性弹窗。
|
|
334
|
+
+ this._gateRunning = false;
|
|
335
|
+
+ this._flushPendingUpdate();
|
|
336
|
+
+ }
|
|
337
|
+
+ }
|
|
338
|
+
+ _emitSafely(event: string, value: mixed): void {
|
|
339
|
+
+ try {
|
|
340
|
+
+ this.emit(event, value);
|
|
341
|
+
+ } catch (error) {
|
|
342
|
+
+ // 事件监听器属于宿主代码,不能破坏 gate 的异步收尾。
|
|
343
|
+
+ }
|
|
344
|
+
+ }
|
|
345
|
+
+ _applyPendingUpdate(update: HmrUpdate, handleErrors: boolean = false) {
|
|
346
|
+
+ // 注入必须同步完成;提前移除整批,避免部分注入失败后被重放。
|
|
347
|
+
this._pendingUpdate = null;
|
|
348
|
+
- if (update != null) {
|
|
349
|
+
+ try {
|
|
350
|
+
injectUpdate(update);
|
|
351
|
+
+ } catch (error) {
|
|
352
|
+
+ if (!handleErrors) {
|
|
353
|
+
+ throw error;
|
|
354
|
+
+ }
|
|
355
|
+
+ this._emitSafely('update-apply-error', error);
|
|
356
|
+
+ return;
|
|
357
|
+
}
|
|
358
|
+
- }
|
|
359
|
+
-
|
|
360
|
+
- disable() {
|
|
361
|
+
- this._isEnabled = false;
|
|
362
|
+
+ this._emitSafely('update-applied', update);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
isEnabled(): boolean {
|
|
@@ -28,20 +28,23 @@ index 2ce92e0..56eb4f8 100644
|
|
|
28
28
|
diff --git a/Libraries/LogBox/UI/LogBoxInspector.js b/Libraries/LogBox/UI/LogBoxInspector.js
|
|
29
29
|
--- a/Libraries/LogBox/UI/LogBoxInspector.js
|
|
30
30
|
+++ b/Libraries/LogBox/UI/LogBoxInspector.js
|
|
31
|
-
@@ -8,6 +8,
|
|
31
|
+
@@ -8,6 +8,10 @@
|
|
32
32
|
* @format
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
+import
|
|
35
|
+
+import type {CopyStatus} from '../Data/LogBoxCopy';
|
|
36
|
+
+
|
|
37
|
+
+import Alert from '../../Alert/Alert';
|
|
38
|
+
+import {createLogBoxCopyController} from '../Data/LogBoxCopy';
|
|
36
39
|
import Keyboard from '../../Components/Keyboard/Keyboard';
|
|
37
40
|
import View from '../../Components/View/View';
|
|
38
41
|
import StyleSheet from '../../StyleSheet/StyleSheet';
|
|
39
|
-
@@ -18,7 +
|
|
42
|
+
@@ -18,7 +22,97 @@
|
|
40
43
|
import LogBoxInspectorHeader from './LogBoxInspectorHeader';
|
|
41
44
|
import * as LogBoxStyle from './LogBoxStyle';
|
|
42
45
|
import * as React from 'react';
|
|
43
46
|
-import {useEffect} from 'react';
|
|
44
|
-
+import {useEffect, useState} from 'react';
|
|
47
|
+
+import {useEffect, useRef, useState} from 'react';
|
|
45
48
|
+
|
|
46
49
|
+const errorTitleMap = {
|
|
47
50
|
+ warn: '控制台警告',
|
|
@@ -135,22 +138,53 @@ diff --git a/Libraries/LogBox/UI/LogBoxInspector.js b/Libraries/LogBox/UI/LogBox
|
|
|
135
138
|
|
|
136
139
|
type Props = $ReadOnly<{
|
|
137
140
|
onDismiss: () => void,
|
|
138
|
-
@@ -32,6 +
|
|
141
|
+
@@ -32,6 +126,10 @@
|
|
139
142
|
export default function LogBoxInspector(props: Props): React.Node {
|
|
140
143
|
const {logs, selectedIndex} = props;
|
|
141
144
|
let log = logs[selectedIndex];
|
|
142
|
-
+ const [copyStatus, setCopyStatus] = useState<'idle'
|
|
143
|
-
+
|
|
144
|
-
+ );
|
|
145
|
+
+ const [copyStatus, setCopyStatus] = useState<CopyStatus>('idle');
|
|
146
|
+
+ const copyController = useRef(null);
|
|
147
|
+
+ const currentLog = useRef(log);
|
|
148
|
+
+ currentLog.current = log;
|
|
145
149
|
|
|
146
150
|
useEffect(() => {
|
|
147
151
|
if (log) {
|
|
148
|
-
@@ -55,8 +
|
|
152
|
+
@@ -55,8 +153,52 @@
|
|
149
153
|
Keyboard.dismiss();
|
|
150
154
|
}, []);
|
|
151
155
|
|
|
152
156
|
+ useEffect(() => {
|
|
153
157
|
+ setCopyStatus('idle');
|
|
158
|
+
+ const controller = createLogBoxCopyController(
|
|
159
|
+
+ status => {
|
|
160
|
+
+ if (currentLog.current === log) {
|
|
161
|
+
+ setCopyStatus(status);
|
|
162
|
+
+ }
|
|
163
|
+
+ },
|
|
164
|
+
+ message => {
|
|
165
|
+
+ if (currentLog.current === log) {
|
|
166
|
+
+ Alert.alert('复制失败', message);
|
|
167
|
+
+ }
|
|
168
|
+
+ },
|
|
169
|
+
+ reason => new Promise(resolve => {
|
|
170
|
+
+ if (currentLog.current !== log) {
|
|
171
|
+
+ resolve(false);
|
|
172
|
+
+ return;
|
|
173
|
+
+ }
|
|
174
|
+
+ Alert.alert('开发构建不适用', reason, [
|
|
175
|
+
+ {text: '取消', style: 'cancel', onPress: () => resolve(false)},
|
|
176
|
+
+ {text: '仍要复制错误', onPress: () => resolve(true)},
|
|
177
|
+
+ ], {cancelable: true, onDismiss: () => resolve(false)});
|
|
178
|
+
+ }),
|
|
179
|
+
+ () => currentLog.current === log,
|
|
180
|
+
+ );
|
|
181
|
+
+ copyController.current = controller;
|
|
182
|
+
+ return () => {
|
|
183
|
+
+ controller.cancel();
|
|
184
|
+
+ if (copyController.current === controller) {
|
|
185
|
+
+ copyController.current = null;
|
|
186
|
+
+ }
|
|
187
|
+
+ };
|
|
154
188
|
+ }, [log]);
|
|
155
189
|
+
|
|
156
190
|
function _handleRetry() {
|
|
@@ -159,16 +193,16 @@ diff --git a/Libraries/LogBox/UI/LogBoxInspector.js b/Libraries/LogBox/UI/LogBox
|
|
|
159
193
|
+
|
|
160
194
|
+ function _handleCopy() {
|
|
161
195
|
+ try {
|
|
162
|
-
+
|
|
163
|
-
+ setCopyStatus('copied');
|
|
196
|
+
+ void copyController.current?.copy(formatLogForClipboard(log));
|
|
164
197
|
+ } catch {
|
|
165
198
|
+ // 复制失败不能再次触发 LogBox,否则会遮盖原始错误。
|
|
166
|
-
+ setCopyStatus('failed');
|
|
199
|
+
+ setCopyStatus('copy-failed');
|
|
200
|
+
+ Alert.alert('复制失败', '无法整理错误内容,请重试。');
|
|
167
201
|
+ }
|
|
168
202
|
}
|
|
169
203
|
|
|
170
204
|
if (log == null) {
|
|
171
|
-
@@ -73,6 +
|
|
205
|
+
@@ -73,6 +215,8 @@
|
|
172
206
|
/>
|
|
173
207
|
<LogBoxInspectorBody log={log} onRetry={_handleRetry} />
|
|
174
208
|
<LogBoxInspectorFooter
|
|
@@ -228,11 +262,11 @@ diff --git a/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js b/Libraries/LogBox/
|
|
|
228
262
|
diff --git a/Libraries/LogBox/UI/LogBoxInspectorFooter.js b/Libraries/LogBox/UI/LogBoxInspectorFooter.js
|
|
229
263
|
--- a/Libraries/LogBox/UI/LogBoxInspectorFooter.js
|
|
230
264
|
+++ b/Libraries/LogBox/UI/LogBoxInspectorFooter.js
|
|
231
|
-
@@ -18,36 +18,
|
|
265
|
+
@@ -18,36 +18,58 @@
|
|
232
266
|
import * as React from 'react';
|
|
233
267
|
|
|
234
268
|
type Props = $ReadOnly<{
|
|
235
|
-
+ copyStatus: 'idle' | 'copied' | 'failed',
|
|
269
|
+
+ copyStatus: 'idle' | 'checking' | 'confirming' | 'copied' | 'check-failed' | 'copy-failed',
|
|
236
270
|
+ onCopy: () => void,
|
|
237
271
|
onDismiss: () => void,
|
|
238
272
|
onMinimize: () => void,
|
|
@@ -254,9 +288,15 @@ diff --git a/Libraries/LogBox/UI/LogBoxInspectorFooter.js b/Libraries/LogBox/UI/
|
|
|
254
288
|
+ const copyButtonText =
|
|
255
289
|
+ props.copyStatus === 'copied'
|
|
256
290
|
+ ? '已复制'
|
|
257
|
-
+ : props.copyStatus === '
|
|
258
|
-
+ ? '
|
|
259
|
-
+ : '
|
|
291
|
+
+ : props.copyStatus === 'checking'
|
|
292
|
+
+ ? '正在检查兼容性(最多 8 秒)'
|
|
293
|
+
+ : props.copyStatus === 'confirming'
|
|
294
|
+
+ ? '等待确认'
|
|
295
|
+
+ : props.copyStatus === 'check-failed'
|
|
296
|
+
+ ? '检查失败,点击重试'
|
|
297
|
+
+ : props.copyStatus === 'copy-failed'
|
|
298
|
+
+ ? '复制失败,点击重试'
|
|
299
|
+
+ : '复制错误给智能体修复';
|
|
260
300
|
|
|
261
301
|
return (
|
|
262
302
|
- <View style={styles.root}>
|
|
@@ -275,7 +315,7 @@ diff --git a/Libraries/LogBox/UI/LogBoxInspectorFooter.js b/Libraries/LogBox/UI/
|
|
|
275
315
|
+ <LogBoxInspectorFooterButton
|
|
276
316
|
+ id="logbox_footer_button_copy"
|
|
277
317
|
+ text={copyButtonText}
|
|
278
|
-
+ onPress={props.onCopy}
|
|
318
|
+
+ onPress={props.copyStatus === 'checking' || props.copyStatus === 'confirming' ? undefined : props.onCopy}
|
|
279
319
|
+ />
|
|
280
320
|
+ </View>
|
|
281
321
|
+ <View style={styles.root}>
|
|
@@ -409,3 +449,149 @@ diff --git a/Libraries/LogBox/UI/LogBoxInspectorReactFrames.js b/Libraries/LogBo
|
|
|
409
449
|
{getStackList().map((frame, index) => (
|
|
410
450
|
<View
|
|
411
451
|
// Unfortunately we don't have a unique identifier for stack traces.
|
|
452
|
+
diff --git a/Libraries/LogBox/Data/LogBoxCopy.js b/Libraries/LogBox/Data/LogBoxCopy.js
|
|
453
|
+
new file mode 100644
|
|
454
|
+
--- /dev/null
|
|
455
|
+
+++ b/Libraries/LogBox/Data/LogBoxCopy.js
|
|
456
|
+
@@ -0,0 +1,130 @@
|
|
457
|
+
+/**
|
|
458
|
+
+ * @flow strict-local
|
|
459
|
+
+ * @format
|
|
460
|
+
+ */
|
|
461
|
+
+
|
|
462
|
+
+export type CopyStatus =
|
|
463
|
+
+ | 'idle'
|
|
464
|
+
+ | 'checking'
|
|
465
|
+
+ | 'confirming'
|
|
466
|
+
+ | 'copied'
|
|
467
|
+
+ | 'check-failed'
|
|
468
|
+
+ | 'copy-failed';
|
|
469
|
+
+
|
|
470
|
+
+type CopyModule = {
|
|
471
|
+
+ checkCopyCompatibility: () => Promise<{status: string, reason?: string}>,
|
|
472
|
+
+ copyErrorToClipboard: (text: string) => Promise<void>,
|
|
473
|
+
+};
|
|
474
|
+
+
|
|
475
|
+
+function getCopyModule(): CopyModule {
|
|
476
|
+
+ // 延迟取桥接模块,避免 LogBox 初始化时引入 Expo 包或再次触发日志。
|
|
477
|
+
+ if (globalThis.expo == null) {
|
|
478
|
+
+ const registry = require('../../TurboModule/TurboModuleRegistry');
|
|
479
|
+
+ registry.get('ExpoModulesCore')?.installModules?.();
|
|
480
|
+
+ }
|
|
481
|
+
+ const module = globalThis.expo?.modules?.ExpoDevLauncher;
|
|
482
|
+
+ if (
|
|
483
|
+
+ typeof module?.checkCopyCompatibility !== 'function' ||
|
|
484
|
+
+ typeof module?.copyErrorToClipboard !== 'function'
|
|
485
|
+
+ ) {
|
|
486
|
+
+ throw new Error('请更新开发客户端后重试,当前客户端不支持复制兼容性检查。');
|
|
487
|
+
+ }
|
|
488
|
+
+ return module;
|
|
489
|
+
+}
|
|
490
|
+
+
|
|
491
|
+
+export function createLogBoxCopyController(
|
|
492
|
+
+ onStatus: (status: CopyStatus) => void,
|
|
493
|
+
+ onFailure: (message: string) => void,
|
|
494
|
+
+ confirmIncompatible: (reason: string) => Promise<boolean>,
|
|
495
|
+
+ isValid: () => boolean = () => true,
|
|
496
|
+
+): {copy: (text: string) => Promise<void>, cancel: () => void} {
|
|
497
|
+
+ let generation = 0;
|
|
498
|
+
+ let busy = false;
|
|
499
|
+
+ let stopWaiting: ?(() => void);
|
|
500
|
+
+ const stopped = {};
|
|
501
|
+
+
|
|
502
|
+
+ return {
|
|
503
|
+
+ cancel() {
|
|
504
|
+
+ // 页面退出或错误切换后,旧检查、确认框和写入回执均不能更新新页面。
|
|
505
|
+
+ generation += 1;
|
|
506
|
+
+ busy = false;
|
|
507
|
+
+ stopWaiting?.();
|
|
508
|
+
+ stopWaiting = null;
|
|
509
|
+
+ },
|
|
510
|
+
+ async copy(text: string): Promise<void> {
|
|
511
|
+
+ // 同步加锁,覆盖 React 尚未提交 checking 状态时的连续点击。
|
|
512
|
+
+ if (busy) {
|
|
513
|
+
+ return;
|
|
514
|
+
+ }
|
|
515
|
+
+ busy = true;
|
|
516
|
+
+ const request = ++generation;
|
|
517
|
+
+ const current = () => generation === request && isValid();
|
|
518
|
+
+ let timer;
|
|
519
|
+
+ let writing = false;
|
|
520
|
+
+ const cancelled = new Promise(resolve => {
|
|
521
|
+
+ stopWaiting = () => resolve(stopped);
|
|
522
|
+
+ });
|
|
523
|
+
+ onStatus('checking');
|
|
524
|
+
+ try {
|
|
525
|
+
+ const module = getCopyModule();
|
|
526
|
+
+ const timeout = new Promise((_, reject) => {
|
|
527
|
+
+ // 原生负责取消网络;JS 看门狗兼容异常桥接或迟到回调。
|
|
528
|
+
+ timer = setTimeout(
|
|
529
|
+
+ () => reject(new Error('兼容性检查超过 8 秒,请检查网络后重试。')),
|
|
530
|
+
+ 8000,
|
|
531
|
+
+ );
|
|
532
|
+
+ });
|
|
533
|
+
+ const result = await Promise.race([
|
|
534
|
+
+ module.checkCopyCompatibility(),
|
|
535
|
+
+ timeout,
|
|
536
|
+
+ cancelled,
|
|
537
|
+
+ ]);
|
|
538
|
+
+ clearTimeout(timer);
|
|
539
|
+
+ if (!current() || result === stopped) {
|
|
540
|
+
+ return;
|
|
541
|
+
+ }
|
|
542
|
+
+ if (result?.status === 'incompatible') {
|
|
543
|
+
+ onStatus('confirming');
|
|
544
|
+
+ const approved = await Promise.race([
|
|
545
|
+
+ confirmIncompatible(result.reason || '当前开发构建与项目原生能力不兼容。'),
|
|
546
|
+
+ cancelled,
|
|
547
|
+
+ ]);
|
|
548
|
+
+ if (!current() || approved !== true) {
|
|
549
|
+
+ if (current()) {
|
|
550
|
+
+ onStatus('idle');
|
|
551
|
+
+ }
|
|
552
|
+
+ return;
|
|
553
|
+
+ }
|
|
554
|
+
+ } else if (result?.status !== 'compatible') {
|
|
555
|
+
+ throw new Error(result?.reason || '无法完成兼容性检查,请检查网络后重试。');
|
|
556
|
+
+ }
|
|
557
|
+
+ if (!current()) {
|
|
558
|
+
+ return;
|
|
559
|
+
+ }
|
|
560
|
+
+ writing = true;
|
|
561
|
+
+ // 点击时传入的文本已固定,且仅在真实原生写入完成后显示成功。
|
|
562
|
+
+ await module.copyErrorToClipboard(text);
|
|
563
|
+
+ if (current()) {
|
|
564
|
+
+ onStatus('copied');
|
|
565
|
+
+ }
|
|
566
|
+
+ } catch (error) {
|
|
567
|
+
+ if (current()) {
|
|
568
|
+
+ onStatus(writing ? 'copy-failed' : 'check-failed');
|
|
569
|
+
+ onFailure(
|
|
570
|
+
+ writing
|
|
571
|
+
+ ? '剪贴板写入失败,请重试。'
|
|
572
|
+
+ : error instanceof Error
|
|
573
|
+
+ ? error.message
|
|
574
|
+
+ : '兼容性检查失败,请重试。',
|
|
575
|
+
+ );
|
|
576
|
+
+ }
|
|
577
|
+
+ } finally {
|
|
578
|
+
+ clearTimeout(timer);
|
|
579
|
+
+ if (current()) {
|
|
580
|
+
+ busy = false;
|
|
581
|
+
+ stopWaiting = null;
|
|
582
|
+
+ }
|
|
583
|
+
+ }
|
|
584
|
+
+ },
|
|
585
|
+
+ };
|
|
586
|
+
+}
|
|
587
|
+
diff --git a/Libraries/LogBox/UI/LogBoxInspectorFooterButton.js b/Libraries/LogBox/UI/LogBoxInspectorFooterButton.js
|
|
588
|
+
--- a/Libraries/LogBox/UI/LogBoxInspectorFooterButton.js
|
|
589
|
+
+++ b/Libraries/LogBox/UI/LogBoxInspectorFooterButton.js
|
|
590
|
+
@@ -18,6 +18,6 @@
|
|
591
|
+
|
|
592
|
+
type ButtonProps = $ReadOnly<{
|
|
593
|
+
id: string,
|
|
594
|
+
- onPress: () => void,
|
|
595
|
+
+ onPress?: () => void,
|
|
596
|
+
text: string,
|
|
597
|
+
}>;
|
package/pnpmfile.cjs
CHANGED
|
@@ -27,6 +27,7 @@ const managedPatches = {
|
|
|
27
27
|
'metro-runtime@0.83.3': {
|
|
28
28
|
filename: 'metro-runtime@0.83.3.patch',
|
|
29
29
|
legacyHashes: new Set([
|
|
30
|
+
'76aa02561be5343f25d60309a5a6fef13bd1d32f72203ac2e81352cef24e361f',
|
|
30
31
|
'bd14ae6037bcf49028607c01caf67d4bd03e543460609a62e72647664c27b242',
|
|
31
32
|
]),
|
|
32
33
|
},
|
|
@@ -51,6 +52,10 @@ const managedPatches = {
|
|
|
51
52
|
'expo@55.0.6': {
|
|
52
53
|
filename: 'expo@55.0.6.patch',
|
|
53
54
|
legacyHashes: new Set([
|
|
55
|
+
'4a8905eb936e57ba88f0492c12def4e6e402526cb93069cba54d2f1afe820f96',
|
|
56
|
+
'fd87f54739c416500b09153e6733f49f2ee64e31622a007ec868dbd7e308a558',
|
|
57
|
+
'7a7e7180540cbffd985d0e8cfa57ad6b87e0ae425c2a25b231e4b15463357992',
|
|
58
|
+
'912a9598dcce4a4803ad9f96079bd0f0dc71d3d0adea2c2e2f9784161faef381',
|
|
54
59
|
'3eca6fa71eb9640bccf2075dc37c5c8ed2fa060db77b36bb2c67fba902a9a9c5',
|
|
55
60
|
'1df9b522728e93daf64f9e2298ab835ce52d55b4aa2de92a68b947e7ed08f40a',
|
|
56
61
|
'8ac63998a9852ddafda7af96deb4d7ac4c3a5da5e65e865af32be9d4fd966e02',
|
|
@@ -73,7 +78,9 @@ const managedPatches = {
|
|
|
73
78
|
},
|
|
74
79
|
'react-native@0.83.2': {
|
|
75
80
|
filename: 'react-native@0.83.2.patch',
|
|
76
|
-
legacyHashes: new Set(
|
|
81
|
+
legacyHashes: new Set([
|
|
82
|
+
'4416d7456eece4b818b0798b04cc71a4f3273a70cf32458749c699d05c779729',
|
|
83
|
+
]),
|
|
77
84
|
},
|
|
78
85
|
'react-native-worklets@0.7.4': {
|
|
79
86
|
filename: 'react-native-worklets@0.7.4.patch',
|