miaoda-expo-devkit 0.1.1-dev.development-build.7 → 0.1.1-dev.development-build.9
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 +12 -3
- package/package.json +19 -19
- package/pnpm-patches/expo@55.0.6.patch +789 -25
- package/pnpm-patches/metro-runtime@0.83.3.patch +351 -3
- package/pnpm-patches/react-native@0.83.2.patch +291 -205
- package/pnpmfile.cjs +9 -0
|
@@ -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 {
|