vite-plugin-taro 0.7.1 → 0.7.3-beta.0
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.en.md +6 -0
- package/README.md +7 -0
- package/dist/index.js +84 -84
- package/dist/node/plugins/mini/dev/patch-journal.d.ts +3 -0
- package/dist/node/plugins/wx/create-wx-watch-plugin.d.ts +3 -0
- package/dist/runtime/mini/dev/hmr-protocol.d.ts +3 -0
- package/dist/runtime/mini/dev/mini-hmr-runtime.d.ts +5 -5
- package/dist/runtime/mini/dev/mini-hmr-runtime.js +34 -23
- package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.js +5 -2
- package/dist/runtime/zfb/dev/connect-zfb-socket.js +3 -0
- package/package.json +2 -2
|
@@ -18,6 +18,7 @@ export declare class PatchJournal {
|
|
|
18
18
|
private readonly publishPatches;
|
|
19
19
|
private buildId;
|
|
20
20
|
private readonly pendingPatches;
|
|
21
|
+
private hasPublishedPatches;
|
|
21
22
|
constructor(publishPatches: PublishPatches);
|
|
22
23
|
/** True when the buildId belongs to the current complete build. */
|
|
23
24
|
isCurrentBuild(buildId: string): boolean;
|
|
@@ -34,6 +35,8 @@ export declare class PatchJournal {
|
|
|
34
35
|
* failed publication therefore leaves the appended range intact, and a successful one remains until an explicit ACK.
|
|
35
36
|
*/
|
|
36
37
|
produce(patches: readonly PatchUpdate[]): Promise<void>;
|
|
38
|
+
/** A new App can use the disk baseline only while no patches have been published against it. */
|
|
39
|
+
isBaselineCurrent(): boolean;
|
|
37
40
|
/**
|
|
38
41
|
* Removes only the prefix covered by the runtime's successful application frontier.
|
|
39
42
|
*
|
|
@@ -43,6 +43,9 @@ export type MiniSocketTask = Readonly<{
|
|
|
43
43
|
code: number;
|
|
44
44
|
reason: string;
|
|
45
45
|
}>): void;
|
|
46
|
+
onOpen(listener: () => void): void;
|
|
47
|
+
onClose(listener: () => void): void;
|
|
48
|
+
onError(listener: () => void): void;
|
|
46
49
|
onMessage(listener: (result: Readonly<{
|
|
47
50
|
data: unknown;
|
|
48
51
|
}>) => void): void;
|
|
@@ -56,7 +59,6 @@ export declare class MiniHmrRuntime extends DevRuntime {
|
|
|
56
59
|
* stays fixed while appliedSeq records the committed frontier.
|
|
57
60
|
*/
|
|
58
61
|
private session;
|
|
59
|
-
/** The App heap's sole SocketTask, assigned once by initialize and retained for its lifetime. */
|
|
60
62
|
private socket;
|
|
61
63
|
/**
|
|
62
64
|
* Sparse current-generation accepting boundaries keyed by module id. Entries alone must
|
|
@@ -90,9 +92,7 @@ export declare class MiniHmrRuntime extends DevRuntime {
|
|
|
90
92
|
initialize(info: HmrInfo): void;
|
|
91
93
|
/** Receives mode-specific Vite custom events after shared control messages have been handled. */
|
|
92
94
|
protected onSocketEvent(_info: HmrInfo, _event: string, _data: unknown): void;
|
|
93
|
-
/**
|
|
94
|
-
protected sendSocketEvent(event: string, data: unknown): void;
|
|
95
|
-
/** Closes the sole socket after terminal host control or interpreter failure. */
|
|
95
|
+
/** Closes the sole socket after terminal host control or patch failure in either mode. */
|
|
96
96
|
protected stopSocket(reason: string): void;
|
|
97
97
|
/**
|
|
98
98
|
* Applies one mode-delivered cumulative payload through its mode-specific patch installer.
|
|
@@ -103,7 +103,7 @@ export declare class MiniHmrRuntime extends DevRuntime {
|
|
|
103
103
|
protected applyPatchPayload<Patch extends RuntimePatch>(payload: Readonly<{
|
|
104
104
|
buildId: string;
|
|
105
105
|
patches: readonly Patch[];
|
|
106
|
-
}>, installPatch: (patch: Patch) => void):
|
|
106
|
+
}>, installPatch: (patch: Patch) => void): void;
|
|
107
107
|
/**
|
|
108
108
|
* Folds one cumulative mode delivery into a single logical HMR update.
|
|
109
109
|
*
|
|
@@ -64,7 +64,7 @@ export class MiniHmrRuntime extends DevRuntime {
|
|
|
64
64
|
* stays fixed while appliedSeq records the committed frontier.
|
|
65
65
|
*/
|
|
66
66
|
session;
|
|
67
|
-
|
|
67
|
+
// Set only by native OPEN and cleared on close/error: this reference is the authority for whether reports can be sent.
|
|
68
68
|
socket;
|
|
69
69
|
/**
|
|
70
70
|
* Sparse current-generation accepting boundaries keyed by module id. Entries alone must
|
|
@@ -168,11 +168,20 @@ export class MiniHmrRuntime extends DevRuntime {
|
|
|
168
168
|
* either change could acknowledge factories against another host client or replay already committed application generations.
|
|
169
169
|
*/
|
|
170
170
|
initialize(info) {
|
|
171
|
-
if (this.session)
|
|
171
|
+
if (this.session) {
|
|
172
172
|
return;
|
|
173
|
+
}
|
|
173
174
|
this.session = { buildId: info.buildId, appliedSeq: 0 };
|
|
174
175
|
const socket = this.connectSocket(info.endpoint);
|
|
175
|
-
|
|
176
|
+
const clearSocket = () => {
|
|
177
|
+
this.socket = undefined;
|
|
178
|
+
};
|
|
179
|
+
socket.onClose(clearSocket);
|
|
180
|
+
socket.onError(clearSocket);
|
|
181
|
+
socket.onOpen(() => {
|
|
182
|
+
this.socket = socket;
|
|
183
|
+
this.sendReport({ kind: 'startup' });
|
|
184
|
+
});
|
|
176
185
|
socket.onMessage(({ data }) => {
|
|
177
186
|
if (typeof data !== 'string')
|
|
178
187
|
return;
|
|
@@ -189,21 +198,14 @@ export class MiniHmrRuntime extends DevRuntime {
|
|
|
189
198
|
}
|
|
190
199
|
/** Receives mode-specific Vite custom events after shared control messages have been handled. */
|
|
191
200
|
onSocketEvent(_info, _event, _data) { }
|
|
192
|
-
/**
|
|
193
|
-
sendSocketEvent(event, data) {
|
|
194
|
-
const socket = this.socket;
|
|
195
|
-
if (!socket) {
|
|
196
|
-
throw new Error('Mini Program HMR socket is not initialized');
|
|
197
|
-
}
|
|
198
|
-
socket.send({ data: JSON.stringify({ type: 'custom', event: event, data: data }) });
|
|
199
|
-
}
|
|
200
|
-
/** Closes the sole socket after terminal host control or interpreter failure. */
|
|
201
|
+
/** Closes the sole socket after terminal host control or patch failure in either mode. */
|
|
201
202
|
stopSocket(reason) {
|
|
202
|
-
|
|
203
|
-
if (!socket) {
|
|
203
|
+
if (!this.session) {
|
|
204
204
|
throw new Error('Mini Program HMR socket is not initialized');
|
|
205
205
|
}
|
|
206
|
-
socket
|
|
206
|
+
const socket = this.socket;
|
|
207
|
+
this.socket = undefined;
|
|
208
|
+
socket?.close({ code: 1000, reason: reason });
|
|
207
209
|
}
|
|
208
210
|
/**
|
|
209
211
|
* Applies one mode-delivered cumulative payload through its mode-specific patch installer.
|
|
@@ -215,15 +217,26 @@ export class MiniHmrRuntime extends DevRuntime {
|
|
|
215
217
|
const session = this.session;
|
|
216
218
|
if (!session || payload.buildId !== session.buildId) {
|
|
217
219
|
console.warn('[vpt] patches for a stale build');
|
|
218
|
-
return
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!this.socket) {
|
|
223
|
+
// Before OPEN the new heap uses only the disk baseline. Startup requests a rebuild if patches were published;
|
|
224
|
+
// do not replay their factories early or queue them for later. Closed connections likewise cannot acknowledge updates.
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (session.appliedSeq === 0 && payload.patches.length > 0 && payload.patches[0].seq > 1) {
|
|
228
|
+
// Compile starts from the original bundle, but the physical file can be an ACK-pruned suffix. Do not install it or
|
|
229
|
+
// classify an expected new-heap synchronization as patch corruption. OPEN reports startup automatically; if already
|
|
230
|
+
// connected, ask the host to rebuild the baseline now.
|
|
231
|
+
this.sendReport({ kind: 'startup' });
|
|
232
|
+
return;
|
|
219
233
|
}
|
|
220
234
|
const applied = this.applyPatchBatch(session, payload.patches, installPatch);
|
|
221
235
|
if (applied) {
|
|
222
236
|
// The host may publish later generations while synchronous application runs. Reporting only afterward makes this the
|
|
223
237
|
// application frontier: journal history is never pruned merely because a delivery became observable.
|
|
224
|
-
|
|
238
|
+
this.sendReport({ kind: 'applied', seq: session.appliedSeq });
|
|
225
239
|
}
|
|
226
|
-
return applied;
|
|
227
240
|
}
|
|
228
241
|
/**
|
|
229
242
|
* Folds one cumulative mode delivery into a single logical HMR update.
|
|
@@ -283,10 +296,8 @@ export class MiniHmrRuntime extends DevRuntime {
|
|
|
283
296
|
// An installer may already have replaced some factories and the module registry has no inverse operation. Keep the
|
|
284
297
|
// old application watermark unacknowledged and request a complete build, the only coherent rollback boundary.
|
|
285
298
|
console.warn('[vpt] patch batch failed; apply stopped', error);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
reason: error instanceof Error ? error.message : String(error)
|
|
289
|
-
});
|
|
299
|
+
this.sendReport({ kind: 'rebuild', reason: error instanceof Error ? error.message : String(error) });
|
|
300
|
+
this.stopSocket('patch application stopped');
|
|
290
301
|
return false;
|
|
291
302
|
}
|
|
292
303
|
}
|
|
@@ -299,6 +310,6 @@ export class MiniHmrRuntime extends DevRuntime {
|
|
|
299
310
|
throw new Error('Mini Program dev runtime is not initialized');
|
|
300
311
|
}
|
|
301
312
|
const report = { buildId: session.buildId, ...data };
|
|
302
|
-
this.
|
|
313
|
+
this.socket?.send({ data: JSON.stringify({ type: 'custom', event: runtimeReportEvent, data: report }) });
|
|
303
314
|
}
|
|
304
315
|
}
|
|
@@ -22,12 +22,15 @@ class InterpreterHmrRuntime extends MiniHmrRuntime {
|
|
|
22
22
|
this.installPatch = (patch) => interpreter.run(patch.code);
|
|
23
23
|
}
|
|
24
24
|
onSocketEvent(info, event, data) {
|
|
25
|
-
if (event !== interpreterServerEvent)
|
|
25
|
+
if (event !== interpreterServerEvent) {
|
|
26
26
|
return;
|
|
27
|
+
}
|
|
27
28
|
const message = data;
|
|
28
|
-
if (message.buildId !== info.buildId
|
|
29
|
+
if (message.buildId !== info.buildId) {
|
|
29
30
|
this.stopSocket('patch application stopped');
|
|
31
|
+
return;
|
|
30
32
|
}
|
|
33
|
+
this.applyPatchPayload(message, this.installPatch);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
/** Creates one platform-connected interpreter for installation by a thin target runtime entry. */
|
|
@@ -11,6 +11,9 @@ export const connectZfbSocket = (endpoint) => {
|
|
|
11
11
|
return {
|
|
12
12
|
send: (options) => socket.send(options),
|
|
13
13
|
close: (options) => socket.close(options),
|
|
14
|
+
onOpen: (listener) => socket.onOpen(listener),
|
|
15
|
+
onClose: (listener) => socket.onClose(listener),
|
|
16
|
+
onError: (listener) => socket.onError(listener),
|
|
14
17
|
onMessage: (listener) => {
|
|
15
18
|
socket.onMessage(({ message }) => listener({ data: message }));
|
|
16
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-taro",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3-beta.0",
|
|
4
4
|
"author": "sep2",
|
|
5
5
|
"description": "Vite 8 plugin for building one React/Taro codebase for WeChat, Alipay, and H5 targets.",
|
|
6
6
|
"type": "module",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"rolldown": "1.2.7",
|
|
64
64
|
"sval": "0.6.12",
|
|
65
65
|
"tailwindcss": "^4.3.3",
|
|
66
|
-
"vite-plugin-taro-runtime": "0.7.
|
|
66
|
+
"vite-plugin-taro-runtime": "0.7.3-beta.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react": "^19.0.0",
|