vite-plugin-taro 0.3.2 → 0.4.1
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 +44 -0
- package/README.md +22 -497
- package/client.d.ts +9 -0
- package/dist/node/plugins/client/client-taro.d.ts +4 -0
- package/dist/node/plugins/client/client-taro.js +19 -0
- package/dist/node/plugins/client/constant.d.ts +4 -0
- package/dist/node/plugins/client/constant.js +4 -0
- package/dist/node/plugins/conditional/conditional-directives.d.ts +4 -0
- package/dist/node/plugins/{conditional-directives.js → conditional/conditional-directives.js} +27 -11
- package/dist/node/plugins/css/plugins.d.ts +4 -0
- package/dist/node/plugins/css/plugins.js +84 -0
- package/dist/node/plugins/h5/constant.d.ts +2 -0
- package/dist/node/plugins/h5/constant.js +3 -0
- package/dist/node/plugins/h5/plugins.d.ts +4 -0
- package/dist/node/plugins/h5/plugins.js +161 -0
- package/dist/node/plugins/h5/resolver/module-resolver.d.ts +14 -0
- package/dist/node/plugins/h5/resolver/module-resolver.js +19 -0
- package/dist/node/plugins/h5/transform-app.d.ts +10 -0
- package/dist/node/plugins/h5/transform-app.js +48 -0
- package/dist/node/plugins/wx/dev/dev-host.d.ts +15 -0
- package/dist/node/plugins/wx/dev/dev-host.js +352 -0
- package/dist/node/plugins/wx/dev/hmr-files.d.ts +28 -0
- package/dist/node/plugins/wx/dev/hmr-files.js +34 -0
- package/dist/node/plugins/wx/dev/patch-publisher.d.ts +22 -0
- package/dist/node/plugins/wx/dev/patch-publisher.js +40 -0
- package/dist/node/plugins/wx/dev/plugin.d.ts +7 -0
- package/dist/node/plugins/wx/dev/plugin.js +73 -0
- package/dist/node/plugins/wx/dev/react-refresh.d.ts +20 -0
- package/dist/node/plugins/wx/dev/react-refresh.js +198 -0
- package/dist/node/plugins/wx/module.d.ts +45 -0
- package/dist/node/plugins/wx/module.js +67 -0
- package/dist/node/plugins/wx/native/compile-native-component-interface.d.ts +21 -0
- package/dist/node/plugins/wx/native/compile-native-component-interface.js +29 -0
- package/dist/node/plugins/wx/native/create-native-component-output.d.ts +15 -0
- package/dist/node/plugins/wx/native/create-native-component-output.js +39 -0
- package/dist/node/plugins/wx/native/native-component-assets.d.ts +26 -0
- package/dist/node/plugins/wx/native/native-component-assets.js +76 -0
- package/dist/node/plugins/wx/native/native-component-interface.d.ts +12 -0
- package/dist/node/plugins/wx/native/native-component-interface.js +201 -0
- package/dist/node/plugins/wx/output/files.d.ts +12 -0
- package/dist/node/plugins/wx/output/files.js +12 -0
- package/dist/node/plugins/wx/output/json.d.ts +14 -0
- package/dist/node/plugins/wx/output/json.js +52 -0
- package/dist/node/plugins/wx/output/relative-root.d.ts +2 -0
- package/dist/node/plugins/wx/output/relative-root.js +6 -0
- package/dist/node/plugins/wx/output/templates.d.ts +7 -0
- package/dist/node/plugins/wx/output/templates.js +100 -0
- package/dist/node/plugins/wx/placement/placer.d.ts +78 -0
- package/dist/node/plugins/wx/placement/placer.js +145 -0
- package/dist/node/plugins/wx/placement/plan.d.ts +46 -0
- package/dist/node/plugins/wx/placement/plan.js +210 -0
- package/dist/node/plugins/wx/plugins.d.ts +4 -0
- package/dist/node/plugins/wx/plugins.js +137 -0
- package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +3 -0
- package/dist/node/plugins/wx/render/capsule-wrapper.js +64 -0
- package/dist/node/plugins/wx/render/capsule.d.ts +4 -0
- package/dist/node/plugins/wx/render/capsule.js +13 -0
- package/dist/node/plugins/wx/render/native.d.ts +9 -0
- package/dist/node/plugins/wx/render/native.js +45 -0
- package/dist/node/plugins/wx/render/transport.d.ts +17 -0
- package/dist/node/plugins/wx/render/transport.js +94 -0
- package/dist/node/plugins/wx/resolve/resolver.d.ts +7 -0
- package/dist/node/plugins/wx/resolve/resolver.js +86 -0
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.d.ts +9 -0
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +9 -0
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.d.ts +9 -0
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +11 -0
- package/dist/node/utils/constant.d.ts +1 -0
- package/dist/node/utils/constant.js +1 -0
- package/dist/node/utils/memoize.d.ts +122 -0
- package/dist/node/utils/memoize.js +86 -0
- package/dist/node/utils/modules.d.ts +20 -24
- package/dist/node/utils/modules.js +21 -34
- package/dist/node/utils/once.d.ts +10 -0
- package/dist/node/utils/once.js +20 -0
- package/dist/node/utils/packages.d.ts +1 -0
- package/dist/node/utils/packages.js +3 -2
- package/dist/node/utils/project-config.d.ts +3 -0
- package/dist/node/utils/project-config.js +8 -0
- package/dist/node/utils/serialized-task-queue.d.ts +9 -0
- package/dist/node/utils/serialized-task-queue.js +17 -0
- package/dist/node/utils/transform.d.ts +11 -0
- package/dist/node/utils/transform.js +58 -0
- package/dist/node/vite-plugin.d.ts +1 -1
- package/dist/node/vite-plugin.js +11 -27
- package/dist/options.d.ts +3 -4
- package/dist/runtime/{taro → client/taro}/api.d.ts +0 -1
- package/dist/runtime/client/taro/api.js +9 -0
- package/dist/runtime/client/taro/component.d.ts +1 -0
- package/dist/runtime/client/taro/component.js +1 -0
- package/dist/runtime/client/taro/define-native-component.d.ts +7 -0
- package/dist/runtime/client/taro/define-native-component.js +4 -0
- package/dist/runtime/h5/app.d.ts +2 -0
- package/dist/runtime/h5/app.js +15 -0
- package/dist/runtime/h5/taro-runtime.d.ts +1 -1
- package/dist/runtime/h5/taro-runtime.js +1 -4
- package/dist/runtime/wx/amphibious/bootstrap.d.ts +4 -0
- package/dist/runtime/wx/amphibious/bootstrap.js +16 -0
- package/dist/runtime/wx/amphibious/transport.d.ts +2 -0
- package/dist/runtime/wx/amphibious/transport.js +4 -0
- package/dist/runtime/wx/capsule/app.d.ts +2 -0
- package/dist/runtime/wx/capsule/app.js +7 -0
- package/dist/runtime/wx/capsule/component.d.ts +3 -0
- package/dist/runtime/wx/capsule/component.js +4 -0
- package/dist/runtime/wx/capsule/page.d.ts +3 -0
- package/dist/runtime/wx/capsule/page.js +68 -0
- package/dist/runtime/wx/capsule/taro-runtime.d.ts +6 -0
- package/dist/runtime/wx/capsule/taro-runtime.js +6 -0
- package/dist/runtime/wx/dev/dev-runtime.d.ts +1 -0
- package/dist/runtime/wx/dev/dev-runtime.js +246 -0
- package/dist/runtime/wx/native/app.d.ts +1 -0
- package/dist/runtime/wx/native/app.js +3 -0
- package/dist/runtime/wx/native/component.d.ts +1 -0
- package/dist/runtime/wx/native/component.js +3 -0
- package/dist/runtime/wx/native/page.d.ts +1 -0
- package/dist/runtime/wx/native/page.js +4 -0
- package/dist/runtime/wx/systemjs/system-core.d.ts +4 -0
- package/dist/runtime/wx/systemjs/system-core.js +331 -0
- package/package.json +21 -14
- package/src/node/plugins/client/client-taro.ts +23 -0
- package/src/node/plugins/client/constant.ts +5 -0
- package/src/node/plugins/{conditional-directives.ts → conditional/conditional-directives.ts} +33 -13
- package/src/node/plugins/css/plugins.ts +96 -0
- package/src/node/plugins/h5/constant.ts +4 -0
- package/src/node/plugins/h5/plugins.ts +197 -0
- package/src/node/plugins/h5/resolver/module-resolver.ts +32 -0
- package/src/node/plugins/h5/transform-app.ts +90 -0
- package/src/node/plugins/wx/dev/dev-host.ts +448 -0
- package/src/node/plugins/wx/dev/hmr-files.ts +55 -0
- package/src/node/plugins/wx/dev/patch-publisher.ts +49 -0
- package/src/node/plugins/wx/dev/plugin.ts +82 -0
- package/src/node/plugins/wx/dev/react-refresh.ts +227 -0
- package/src/node/plugins/wx/module.ts +98 -0
- package/src/node/plugins/wx/native/compile-native-component-interface.ts +47 -0
- package/src/node/plugins/wx/native/create-native-component-output.ts +57 -0
- package/src/node/plugins/wx/native/native-component-assets.ts +114 -0
- package/src/node/plugins/wx/native/native-component-interface.ts +265 -0
- package/src/node/plugins/wx/output/files.ts +27 -0
- package/src/node/plugins/wx/output/json.ts +79 -0
- package/src/node/plugins/wx/output/relative-root.ts +7 -0
- package/src/node/plugins/wx/output/templates.ts +141 -0
- package/src/node/plugins/wx/placement/placer.ts +172 -0
- package/src/node/plugins/wx/placement/plan.ts +306 -0
- package/src/node/plugins/wx/plugins.ts +165 -0
- package/src/node/plugins/wx/render/capsule-wrapper.ts +86 -0
- package/src/node/plugins/wx/render/capsule.ts +21 -0
- package/src/node/plugins/wx/render/native.ts +84 -0
- package/src/node/plugins/wx/render/transport.ts +157 -0
- package/src/node/plugins/wx/resolve/resolver.ts +125 -0
- package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +27 -0
- package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +29 -0
- package/src/node/utils/constant.ts +1 -0
- package/src/node/utils/memoize.ts +149 -0
- package/src/node/utils/modules.ts +36 -38
- package/src/node/utils/once.ts +21 -0
- package/src/node/utils/packages.ts +3 -2
- package/src/node/utils/project-config.ts +10 -0
- package/src/node/utils/serialized-task-queue.ts +20 -0
- package/src/node/utils/transform.ts +82 -0
- package/src/node/vite-plugin.ts +12 -32
- package/src/options.ts +3 -4
- package/src/runtime/client/taro/api.ts +11 -0
- package/src/runtime/client/taro/component.ts +1 -0
- package/src/runtime/client/taro/define-native-component.ts +15 -0
- package/src/runtime/h5/app.ts +25 -0
- package/src/runtime/h5/taro-runtime.ts +1 -4
- package/src/runtime/wx/amphibious/bootstrap.ts +22 -0
- package/src/runtime/wx/amphibious/transport.ts +10 -0
- package/src/runtime/wx/capsule/app.ts +9 -0
- package/src/runtime/wx/capsule/component.ts +6 -0
- package/src/runtime/wx/capsule/page.ts +96 -0
- package/src/runtime/wx/capsule/taro-runtime.ts +14 -0
- package/src/runtime/wx/dev/dev-runtime.ts +317 -0
- package/src/runtime/wx/native/app.ts +4 -0
- package/src/runtime/wx/native/component.ts +4 -0
- package/src/runtime/wx/native/page.ts +6 -0
- package/src/runtime/wx/systemjs/LICENSE +10 -0
- package/src/runtime/wx/systemjs/system-core.js +370 -0
- package/src/runtime/wx/systemjs/system.d.ts +55 -0
- package/src/runtime/wx/wechat.d.ts +52 -0
- package/README.zh.md +0 -521
- package/dist/node/build-context.d.ts +0 -25
- package/dist/node/build-context.js +0 -47
- package/dist/node/css/css-pipeline.d.ts +0 -35
- package/dist/node/css/css-pipeline.js +0 -154
- package/dist/node/plugins/conditional-directives.d.ts +0 -3
- package/dist/node/plugins/taro-runtime.d.ts +0 -5
- package/dist/node/plugins/taro-runtime.js +0 -18
- package/dist/node/targets/h5/plugin.d.ts +0 -6
- package/dist/node/targets/h5/plugin.js +0 -117
- package/dist/node/targets/h5/virtual-modules.d.ts +0 -5
- package/dist/node/targets/h5/virtual-modules.js +0 -60
- package/dist/node/targets/wx/companion-assets.d.ts +0 -19
- package/dist/node/targets/wx/companion-assets.js +0 -129
- package/dist/node/targets/wx/dev-server/development-session.d.ts +0 -32
- package/dist/node/targets/wx/dev-server/development-session.js +0 -215
- package/dist/node/targets/wx/dev-server/full-build-scheduler.d.ts +0 -14
- package/dist/node/targets/wx/dev-server/full-build-scheduler.js +0 -60
- package/dist/node/targets/wx/dev-server/js-utils.d.ts +0 -5
- package/dist/node/targets/wx/dev-server/js-utils.js +0 -28
- package/dist/node/targets/wx/dev-server/output.d.ts +0 -19
- package/dist/node/targets/wx/dev-server/output.js +0 -44
- package/dist/node/targets/wx/dev-server/rolldown-runtime-source.d.ts +0 -8
- package/dist/node/targets/wx/dev-server/rolldown-runtime-source.js +0 -95
- package/dist/node/targets/wx/dev-server/update-server-state.d.ts +0 -65
- package/dist/node/targets/wx/dev-server/update-server-state.js +0 -116
- package/dist/node/targets/wx/dev-server/update-transport.d.ts +0 -28
- package/dist/node/targets/wx/dev-server/update-transport.js +0 -212
- package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.d.ts +0 -44
- package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.js +0 -145
- package/dist/node/targets/wx/development-files.d.ts +0 -8
- package/dist/node/targets/wx/development-files.js +0 -8
- package/dist/node/targets/wx/plugin.d.ts +0 -6
- package/dist/node/targets/wx/plugin.js +0 -144
- package/dist/node/targets/wx/react-refresh.d.ts +0 -4
- package/dist/node/targets/wx/react-refresh.js +0 -38
- package/dist/node/targets/wx/virtual-modules.d.ts +0 -16
- package/dist/node/targets/wx/virtual-modules.js +0 -120
- package/dist/node/utils/async.d.ts +0 -8
- package/dist/node/utils/async.js +0 -16
- package/dist/node/utils/filesystem.d.ts +0 -13
- package/dist/node/utils/filesystem.js +0 -43
- package/dist/runtime/taro/api.js +0 -11
- package/dist/runtime/taro/components.d.ts +0 -2
- package/dist/runtime/taro/components.js +0 -2
- package/dist/runtime/wx/page-update.d.ts +0 -6
- package/dist/runtime/wx/page-update.js +0 -157
- package/dist/runtime/wx/taro-runtime.d.ts +0 -5
- package/dist/runtime/wx/taro-runtime.js +0 -6
- package/dist/runtime/wx/update-client-state.d.ts +0 -68
- package/dist/runtime/wx/update-client-state.js +0 -84
- package/dist/runtime/wx/update-client.d.ts +0 -1
- package/dist/runtime/wx/update-client.js +0 -171
- package/src/node/build-context.ts +0 -62
- package/src/node/css/css-pipeline.ts +0 -171
- package/src/node/plugins/taro-runtime.ts +0 -22
- package/src/node/targets/h5/plugin.ts +0 -135
- package/src/node/targets/h5/virtual-modules.ts +0 -71
- package/src/node/targets/wx/companion-assets.ts +0 -174
- package/src/node/targets/wx/dev-server/development-session.ts +0 -271
- package/src/node/targets/wx/dev-server/full-build-scheduler.ts +0 -62
- package/src/node/targets/wx/dev-server/js-utils.ts +0 -33
- package/src/node/targets/wx/dev-server/output.ts +0 -56
- package/src/node/targets/wx/dev-server/rolldown-runtime-source.ts +0 -95
- package/src/node/targets/wx/dev-server/update-server-state.ts +0 -183
- package/src/node/targets/wx/dev-server/update-transport.ts +0 -261
- package/src/node/targets/wx/dev-server/vite-bundled-dev-adapter.ts +0 -203
- package/src/node/targets/wx/development-files.ts +0 -11
- package/src/node/targets/wx/plugin.ts +0 -164
- package/src/node/targets/wx/react-refresh.ts +0 -51
- package/src/node/targets/wx/virtual-modules.ts +0 -152
- package/src/node/utils/async.ts +0 -19
- package/src/node/utils/filesystem.ts +0 -45
- package/src/runtime/taro/api.ts +0 -13
- package/src/runtime/taro/components.ts +0 -2
- package/src/runtime/wx/page-update.ts +0 -230
- package/src/runtime/wx/react-refresh.d.ts +0 -20
- package/src/runtime/wx/taro-runtime.ts +0 -7
- package/src/runtime/wx/update-client-state.ts +0 -138
- package/src/runtime/wx/update-client.ts +0 -223
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coordinates page-side update execution after the Rolldown and Taro runtimes exist.
|
|
3
|
-
*
|
|
4
|
-
* This module is intentionally page-only: it suppresses DevTools' synthetic lifecycles, preserves the Taro root,
|
|
5
|
-
* commits React Refresh, and relaunches stale component families. HTTP transport remains in update-client.ts.
|
|
6
|
-
*/
|
|
7
|
-
import { document } from '@tarojs/runtime'
|
|
8
|
-
import { validateRefreshBoundaryAndEnqueueUpdate } from '/@react-refresh'
|
|
9
|
-
|
|
10
|
-
type WxPage = {
|
|
11
|
-
$taroPath?: string
|
|
12
|
-
$taroParams?: Record<string, unknown>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type WxPageConfig = Record<string, unknown>
|
|
16
|
-
type PageLifecycle = (this: WxPage, ...args: unknown[]) => unknown
|
|
17
|
-
|
|
18
|
-
type TaroRoot = {
|
|
19
|
-
ctx: WxPage | null
|
|
20
|
-
updateChildNodes(): void
|
|
21
|
-
performUpdate(initRender?: boolean): void
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type ReactRefreshResult = {
|
|
25
|
-
staleFamilies?: Set<unknown>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type WxRolldownRuntime = {
|
|
29
|
-
beginPatch?(): void
|
|
30
|
-
endPatch?(): void
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type WxPageUpdateCoordinator = {
|
|
34
|
-
ready: boolean
|
|
35
|
-
pendingUpdate?: () => void
|
|
36
|
-
blockRefreshRegistration?: boolean
|
|
37
|
-
enqueueRefresh?: () => void
|
|
38
|
-
beginUpdate?: () => void
|
|
39
|
-
endUpdate?: () => void
|
|
40
|
-
afterRefresh?: (update?: ReactRefreshResult) => void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type WxUpdateClient = {
|
|
44
|
-
refreshCompleted(stale: boolean): void
|
|
45
|
-
routeReady(): void
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type WxRuntimeGlobal = typeof globalThis & {
|
|
49
|
-
__rolldown_runtime__?: WxRolldownRuntime
|
|
50
|
-
__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__?: WxPageUpdateCoordinator
|
|
51
|
-
__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?: WxUpdateClient
|
|
52
|
-
getCurrentPages(): Array<{ route?: string }>
|
|
53
|
-
wx: {
|
|
54
|
-
reLaunch(options: { url: string }): void
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const wxRuntimeGlobal = globalThis as WxRuntimeGlobal
|
|
59
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__ ??= { ready: false }
|
|
60
|
-
const bridge = wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__
|
|
61
|
-
const refreshBoundary = { default: function WxRefreshBoundary() {} }
|
|
62
|
-
const registeredRoutes = new Set<string>()
|
|
63
|
-
const ignoredPages = new WeakSet<WxPage>()
|
|
64
|
-
|
|
65
|
-
type PageRuntimeState = Readonly<{
|
|
66
|
-
activePage?: WxPage
|
|
67
|
-
pendingUpdate?: { page?: WxPage; root?: TaroRoot }
|
|
68
|
-
suppressLifecycles: boolean
|
|
69
|
-
}>
|
|
70
|
-
|
|
71
|
-
type PageRuntimeEvent =
|
|
72
|
-
| { type: 'page-activated'; page: WxPage }
|
|
73
|
-
| { type: 'page-unloaded'; page: WxPage }
|
|
74
|
-
| { type: 'update-started'; root?: TaroRoot }
|
|
75
|
-
| { type: 'suppression-ended' }
|
|
76
|
-
| { type: 'refresh-finished' }
|
|
77
|
-
|
|
78
|
-
let pageRuntimeState: PageRuntimeState = { suppressLifecycles: false }
|
|
79
|
-
|
|
80
|
-
/** Registers a native route once per App Service runtime generation. */
|
|
81
|
-
export function registerWxPage(route: string, register: () => void): void {
|
|
82
|
-
if (registeredRoutes.has(route)) return
|
|
83
|
-
register()
|
|
84
|
-
registeredRoutes.add(route)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Retains Taro's live root while filtering DevTools' synthetic update lifecycles. */
|
|
88
|
-
export function decorateWxPageConfig(config: WxPageConfig): WxPageConfig {
|
|
89
|
-
const onLoad = getLifecycle(config, 'onLoad')
|
|
90
|
-
config.onLoad = function (this: WxPage, ...args: unknown[]) {
|
|
91
|
-
if (pageRuntimeState.suppressLifecycles) {
|
|
92
|
-
ignoredPages.add(this)
|
|
93
|
-
this.$taroPath = pageRuntimeState.activePage?.$taroPath
|
|
94
|
-
this.$taroParams = pageRuntimeState.activePage?.$taroParams
|
|
95
|
-
dispatchPageRuntime({ type: 'page-activated', page: this })
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
const result = onLoad?.apply(this, args)
|
|
99
|
-
dispatchPageRuntime({ type: 'page-activated', page: this })
|
|
100
|
-
return result
|
|
101
|
-
}
|
|
102
|
-
wrapLifecycle(config, 'onReady', applyPendingPageUpdate)
|
|
103
|
-
wrapLifecycle(config, 'onShow', function () {
|
|
104
|
-
dispatchPageRuntime({ type: 'page-activated', page: this })
|
|
105
|
-
})
|
|
106
|
-
wrapLifecycle(config, 'onHide')
|
|
107
|
-
wrapLifecycle(config, 'onUnload', function () {
|
|
108
|
-
dispatchPageRuntime({ type: 'page-unloaded', page: this })
|
|
109
|
-
})
|
|
110
|
-
return config
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function wrapLifecycle(config: WxPageConfig, name: string, after?: PageLifecycle): void {
|
|
114
|
-
const original = getLifecycle(config, name)
|
|
115
|
-
config[name] = function (this: WxPage, ...args: unknown[]) {
|
|
116
|
-
if (pageRuntimeState.suppressLifecycles) return
|
|
117
|
-
if (ignoredPages.has(this)) {
|
|
118
|
-
if (name === 'onUnload') ignoredPages.delete(this)
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
const result = original?.apply(this, args)
|
|
122
|
-
after?.apply(this, args)
|
|
123
|
-
return result
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function getLifecycle(config: WxPageConfig, name: string): PageLifecycle | undefined {
|
|
128
|
-
return typeof config[name] === 'function' ? (config[name] as PageLifecycle) : undefined
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function applyPendingPageUpdate(): void {
|
|
132
|
-
bridge.ready = true
|
|
133
|
-
const pendingUpdate = bridge.pendingUpdate
|
|
134
|
-
if (pendingUpdate) {
|
|
135
|
-
delete bridge.pendingUpdate
|
|
136
|
-
pendingUpdate()
|
|
137
|
-
}
|
|
138
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.routeReady()
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function getActiveTaroRoot(): TaroRoot | undefined {
|
|
142
|
-
const page = pageRuntimeState.activePage
|
|
143
|
-
if (!page?.$taroPath) return
|
|
144
|
-
return (document.getElementById(page.$taroPath) as TaroRoot | null) ?? undefined
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
bridge.enqueueRefresh = () => {
|
|
148
|
-
validateRefreshBoundaryAndEnqueueUpdate('vite-plugin-taro-wx', refreshBoundary, refreshBoundary)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
bridge.beginUpdate = () => {
|
|
152
|
-
bridge.blockRefreshRegistration = false
|
|
153
|
-
wxRuntimeGlobal.__rolldown_runtime__?.beginPatch?.()
|
|
154
|
-
dispatchPageRuntime({ type: 'update-started', root: getActiveTaroRoot() })
|
|
155
|
-
refreshTaroRoot(pageRuntimeState.pendingUpdate?.root, pageRuntimeState.pendingUpdate?.page)
|
|
156
|
-
runInNextNativeTask(() => dispatchPageRuntime({ type: 'suppression-ended' }))
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
bridge.endUpdate = () => {
|
|
160
|
-
wxRuntimeGlobal.__rolldown_runtime__?.endPatch?.()
|
|
161
|
-
bridge.blockRefreshRegistration = true
|
|
162
|
-
bridge.enqueueRefresh?.()
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
bridge.afterRefresh = (update) => {
|
|
166
|
-
bridge.blockRefreshRegistration = false
|
|
167
|
-
const pendingUpdate = pageRuntimeState.pendingUpdate
|
|
168
|
-
dispatchPageRuntime({ type: 'refresh-finished' })
|
|
169
|
-
const page = pendingUpdate?.page
|
|
170
|
-
const root = pendingUpdate?.root
|
|
171
|
-
|
|
172
|
-
const stale = Boolean(update?.staleFamilies?.size)
|
|
173
|
-
if (stale) {
|
|
174
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.refreshCompleted(true)
|
|
175
|
-
relaunchActiveRoute(page)
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
runInNextNativeTask(() => {
|
|
179
|
-
refreshTaroRoot(root, pageRuntimeState.activePage ?? page)
|
|
180
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.refreshCompleted(false)
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function dispatchPageRuntime(event: PageRuntimeEvent): void {
|
|
185
|
-
pageRuntimeState = transitionPageRuntime(pageRuntimeState, event)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function transitionPageRuntime(state: PageRuntimeState, event: PageRuntimeEvent): PageRuntimeState {
|
|
189
|
-
switch (event.type) {
|
|
190
|
-
case 'page-activated':
|
|
191
|
-
return { ...state, activePage: event.page }
|
|
192
|
-
case 'page-unloaded':
|
|
193
|
-
return state.activePage === event.page ? { ...state, activePage: undefined } : state
|
|
194
|
-
case 'update-started':
|
|
195
|
-
return {
|
|
196
|
-
...state,
|
|
197
|
-
pendingUpdate: { page: state.activePage, root: event.root },
|
|
198
|
-
suppressLifecycles: true
|
|
199
|
-
}
|
|
200
|
-
case 'suppression-ended':
|
|
201
|
-
return { ...state, suppressLifecycles: false }
|
|
202
|
-
case 'refresh-finished':
|
|
203
|
-
return { ...state, pendingUpdate: undefined }
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function refreshTaroRoot(root: TaroRoot | undefined, page: WxPage | undefined): void {
|
|
208
|
-
if (!root) return
|
|
209
|
-
root.ctx = page ?? null
|
|
210
|
-
root.updateChildNodes()
|
|
211
|
-
root.performUpdate(true)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function relaunchActiveRoute(page: WxPage | undefined): void {
|
|
215
|
-
const route = wxRuntimeGlobal.getCurrentPages().at(-1)?.route
|
|
216
|
-
if (!route) return
|
|
217
|
-
const query = Object.entries(page?.$taroParams ?? {})
|
|
218
|
-
.filter(([key, value]) => key !== '$taroTimestamp' && value !== undefined)
|
|
219
|
-
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
|
220
|
-
.join('&')
|
|
221
|
-
runInNextNativeTask(() => wxRuntimeGlobal.wx.reLaunch({ url: `/${route}${query ? `?${query}` : ''}` }))
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* DevTools dispatches synthetic page lifecycles after the changed module returns. A macrotask—not a microtask—runs
|
|
226
|
-
* after that native turn and also avoids navigation or Taro root mutation from inside React Refresh's callback.
|
|
227
|
-
*/
|
|
228
|
-
function runInNextNativeTask(task: () => void): void {
|
|
229
|
-
setTimeout(task)
|
|
230
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** Vite's development-only React Refresh virtual module used by the WX runtime. */
|
|
2
|
-
declare module '*/@react-refresh' {
|
|
3
|
-
export type RefreshResult = {
|
|
4
|
-
updatedFamilies: Set<unknown>
|
|
5
|
-
staleFamilies: Set<unknown>
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function register(type: unknown, id: string): void
|
|
9
|
-
export function registerExportsForReactRefresh(filename: string, moduleExports: Record<string, unknown>): void
|
|
10
|
-
export function validateRefreshBoundaryAndEnqueueUpdate(
|
|
11
|
-
id: string,
|
|
12
|
-
previousExports: Record<string, unknown>,
|
|
13
|
-
nextExports: Record<string, unknown>
|
|
14
|
-
): string | undefined
|
|
15
|
-
|
|
16
|
-
const runtime: {
|
|
17
|
-
injectIntoGlobalHook(globalObject: typeof globalThis): void
|
|
18
|
-
}
|
|
19
|
-
export default runtime
|
|
20
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** Runtime exports consumed by generated WX App, page, and recursive-component entries. */
|
|
2
|
-
import '@tarojs/plugin-platform-weapp/dist/runtime.js'
|
|
3
|
-
|
|
4
|
-
// @ts-expect-error Taro exposes createReactApp from this runtime-only deep entry without types.
|
|
5
|
-
export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime'
|
|
6
|
-
export { default as ReactDOM } from '@tarojs/react'
|
|
7
|
-
export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime'
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure App-side stop-and-wait protocol state machine.
|
|
3
|
-
*
|
|
4
|
-
* It knows build versions and sequencing only; wx.request, literal code execution, and page lifecycle effects live in
|
|
5
|
-
* update-client.ts and page-update.ts.
|
|
6
|
-
*/
|
|
7
|
-
type WxUpdateClientPhase = 'stopped' | 'registering' | 'polling' | 'applying' | 'refreshing' | 'relaunching'
|
|
8
|
-
|
|
9
|
-
type WxUpdateClientState = {
|
|
10
|
-
buildId: string
|
|
11
|
-
version: number
|
|
12
|
-
phase: WxUpdateClientPhase
|
|
13
|
-
targetVersion?: number
|
|
14
|
-
pendingBatch?: { fromVersion: number; targetVersion: number }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type WxUpdateClientEvent =
|
|
18
|
-
| { type: 'started' }
|
|
19
|
-
| { type: 'registration-completed' }
|
|
20
|
-
| { type: 'poll-completed' }
|
|
21
|
-
| { type: 'batch-observed'; buildId: string; fromVersion: number; targetVersion: number }
|
|
22
|
-
| { type: 'batch-executed'; targetVersion: number }
|
|
23
|
-
| { type: 'batch-failed' }
|
|
24
|
-
| { type: 'refresh-completed'; stale: boolean }
|
|
25
|
-
| { type: 'route-ready' }
|
|
26
|
-
| { type: 'transport-failed' }
|
|
27
|
-
|
|
28
|
-
export type WxUpdateClientCommand =
|
|
29
|
-
| { type: 'register'; version: number }
|
|
30
|
-
| { type: 'poll'; version: number }
|
|
31
|
-
| { type: 'apply-batch'; fromVersion: number; targetVersion: number }
|
|
32
|
-
| { type: 'report-version'; version: number; reason: 'applied' | 'batch-mismatch' }
|
|
33
|
-
| { type: 'request-full-build'; reason: 'batch-execution-failed' }
|
|
34
|
-
| { type: 'retry-transport' }
|
|
35
|
-
|
|
36
|
-
type WxUpdateClientTransition = {
|
|
37
|
-
state: WxUpdateClientState
|
|
38
|
-
commands: WxUpdateClientCommand[]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function createWxUpdateClientState(buildId: string): WxUpdateClientState {
|
|
42
|
-
return { buildId, version: 0, phase: 'stopped' }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function transitionWxUpdateClient(
|
|
46
|
-
state: WxUpdateClientState,
|
|
47
|
-
event: WxUpdateClientEvent
|
|
48
|
-
): WxUpdateClientTransition {
|
|
49
|
-
switch (event.type) {
|
|
50
|
-
case 'started':
|
|
51
|
-
if (state.phase !== 'stopped') return transition(state)
|
|
52
|
-
return command({ ...state, phase: 'registering' }, { type: 'register', version: state.version })
|
|
53
|
-
case 'registration-completed': {
|
|
54
|
-
if (state.phase !== 'registering') return transition(state)
|
|
55
|
-
const pending = state.pendingBatch
|
|
56
|
-
if (!pending) return command({ ...state, phase: 'polling' }, { type: 'poll', version: state.version })
|
|
57
|
-
return command(
|
|
58
|
-
{ ...state, phase: 'applying', targetVersion: pending.targetVersion, pendingBatch: undefined },
|
|
59
|
-
{ type: 'apply-batch', ...pending }
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
case 'poll-completed':
|
|
63
|
-
if (state.phase !== 'polling') return transition(state)
|
|
64
|
-
return command(state, { type: 'poll', version: state.version })
|
|
65
|
-
case 'batch-observed':
|
|
66
|
-
return observeBatch(state, event)
|
|
67
|
-
case 'batch-executed':
|
|
68
|
-
if (state.phase !== 'applying' || state.targetVersion !== event.targetVersion) {
|
|
69
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' })
|
|
70
|
-
}
|
|
71
|
-
return transition({ ...state, phase: 'refreshing', version: event.targetVersion })
|
|
72
|
-
case 'batch-failed':
|
|
73
|
-
return command(
|
|
74
|
-
{ ...state, phase: 'polling', targetVersion: undefined },
|
|
75
|
-
{ type: 'request-full-build', reason: 'batch-execution-failed' }
|
|
76
|
-
)
|
|
77
|
-
case 'refresh-completed':
|
|
78
|
-
if (state.phase !== 'refreshing') return transition(state)
|
|
79
|
-
if (event.stale) return transition({ ...state, phase: 'relaunching' })
|
|
80
|
-
return applied(state)
|
|
81
|
-
case 'route-ready':
|
|
82
|
-
if (state.phase !== 'relaunching') return transition(state)
|
|
83
|
-
return applied(state)
|
|
84
|
-
case 'transport-failed':
|
|
85
|
-
return command(state, { type: 'retry-transport' })
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function observeBatch(
|
|
90
|
-
state: WxUpdateClientState,
|
|
91
|
-
batch: { buildId: string; fromVersion: number; targetVersion: number }
|
|
92
|
-
): WxUpdateClientTransition {
|
|
93
|
-
const valid =
|
|
94
|
-
batch.buildId === state.buildId &&
|
|
95
|
-
Number.isInteger(batch.fromVersion) &&
|
|
96
|
-
Number.isInteger(batch.targetVersion) &&
|
|
97
|
-
batch.fromVersion >= 0 &&
|
|
98
|
-
batch.targetVersion > batch.fromVersion
|
|
99
|
-
if (state.phase === 'registering') {
|
|
100
|
-
if (!valid || batch.fromVersion !== state.version || batch.targetVersion <= state.version) {
|
|
101
|
-
return transition(state)
|
|
102
|
-
}
|
|
103
|
-
return transition({
|
|
104
|
-
...state,
|
|
105
|
-
pendingBatch: { fromVersion: batch.fromVersion, targetVersion: batch.targetVersion }
|
|
106
|
-
})
|
|
107
|
-
}
|
|
108
|
-
if (!valid) {
|
|
109
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' })
|
|
110
|
-
}
|
|
111
|
-
if (batch.targetVersion <= state.version) {
|
|
112
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'applied' })
|
|
113
|
-
}
|
|
114
|
-
if (state.phase !== 'polling' || batch.fromVersion !== state.version) {
|
|
115
|
-
return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' })
|
|
116
|
-
}
|
|
117
|
-
return command(
|
|
118
|
-
{ ...state, phase: 'applying', targetVersion: batch.targetVersion },
|
|
119
|
-
{
|
|
120
|
-
type: 'apply-batch',
|
|
121
|
-
fromVersion: batch.fromVersion,
|
|
122
|
-
targetVersion: batch.targetVersion
|
|
123
|
-
}
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function applied(state: WxUpdateClientState): WxUpdateClientTransition {
|
|
128
|
-
const appliedState = { ...state, phase: 'polling' as const, targetVersion: undefined }
|
|
129
|
-
return command(appliedState, { type: 'report-version', version: state.version, reason: 'applied' })
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function transition(state: WxUpdateClientState): WxUpdateClientTransition {
|
|
133
|
-
return { state, commands: [] }
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function command(state: WxUpdateClientState, value: WxUpdateClientCommand): WxUpdateClientTransition {
|
|
137
|
-
return { state, commands: [value] }
|
|
138
|
-
}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* App-owned adapter for the WX update protocol.
|
|
3
|
-
*
|
|
4
|
-
* It transports metadata with wx.request and executes literal batches delivered through update.js. React/Taro page
|
|
5
|
-
* preservation is delegated to page-update.ts so the App never depends on the mutable update file.
|
|
6
|
-
*/
|
|
7
|
-
import {
|
|
8
|
-
createWxUpdateClientState,
|
|
9
|
-
transitionWxUpdateClient,
|
|
10
|
-
type WxUpdateClientCommand,
|
|
11
|
-
type WxUpdateClientEvent
|
|
12
|
-
} from './update-client-state.ts'
|
|
13
|
-
|
|
14
|
-
type WxUpdateControl = {
|
|
15
|
-
url: string
|
|
16
|
-
token: string
|
|
17
|
-
buildId: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type WxUpdateBatchMetadata = {
|
|
21
|
-
buildId: string
|
|
22
|
-
fromVersion: number
|
|
23
|
-
targetVersion: number
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type WxRequestTask = {
|
|
27
|
-
abort(): void
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type WxRequestResult = {
|
|
31
|
-
data?: unknown
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type WxPageUpdateCoordinator = {
|
|
35
|
-
ready: boolean
|
|
36
|
-
pendingUpdate?: () => void
|
|
37
|
-
beginUpdate?: () => void
|
|
38
|
-
endUpdate?: () => void
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type WxUpdateClient = {
|
|
42
|
-
receiveBatch(metadata: WxUpdateBatchMetadata, apply: () => void): void
|
|
43
|
-
refreshCompleted(stale: boolean): void
|
|
44
|
-
routeReady(): void
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
type WxClientGlobal = typeof globalThis & {
|
|
48
|
-
__VITE_PLUGIN_TARO_WX_CONTROL__?: WxUpdateControl
|
|
49
|
-
__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?: WxUpdateClient
|
|
50
|
-
__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__?: WxPageUpdateCoordinator
|
|
51
|
-
wx: {
|
|
52
|
-
request(options: {
|
|
53
|
-
url: string
|
|
54
|
-
method: 'POST'
|
|
55
|
-
data: unknown
|
|
56
|
-
timeout: number
|
|
57
|
-
success(result: WxRequestResult): void
|
|
58
|
-
fail(error: { errMsg?: string }): void
|
|
59
|
-
}): WxRequestTask
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const wxClientGlobal = globalThis as WxClientGlobal
|
|
64
|
-
const transportRetryDelay = 500
|
|
65
|
-
const rebuildPollDelay = 1_000
|
|
66
|
-
const updateFileWatchdogDelay = 2_000
|
|
67
|
-
|
|
68
|
-
export function startWxUpdateClient(): void {
|
|
69
|
-
if (wxClientGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__) return
|
|
70
|
-
const control = wxClientGlobal.__VITE_PLUGIN_TARO_WX_CONTROL__
|
|
71
|
-
if (!control) throw new Error('vite-plugin-taro could not find its WX update control configuration.')
|
|
72
|
-
|
|
73
|
-
let state = createWxUpdateClientState(control.buildId)
|
|
74
|
-
const sessionId = createSessionId()
|
|
75
|
-
let requestGeneration = 0
|
|
76
|
-
let activeRequest: WxRequestTask | undefined
|
|
77
|
-
let scheduledRequest: ReturnType<typeof setTimeout> | undefined
|
|
78
|
-
let pendingBatchApply: (() => void) | undefined
|
|
79
|
-
|
|
80
|
-
const dispatch = (event: WxUpdateClientEvent, apply?: () => void): void => {
|
|
81
|
-
const transition = transitionWxUpdateClient(state, event)
|
|
82
|
-
state = transition.state
|
|
83
|
-
for (const command of transition.commands) execute(command, apply)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const send = (action: 'register' | 'poll' | 'rebuild', version: number): void => {
|
|
87
|
-
if (scheduledRequest) clearTimeout(scheduledRequest)
|
|
88
|
-
scheduledRequest = undefined
|
|
89
|
-
activeRequest?.abort()
|
|
90
|
-
const generation = ++requestGeneration
|
|
91
|
-
activeRequest = wxClientGlobal.wx.request({
|
|
92
|
-
url: control.url,
|
|
93
|
-
method: 'POST',
|
|
94
|
-
data: {
|
|
95
|
-
token: control.token,
|
|
96
|
-
action,
|
|
97
|
-
buildId: state.buildId,
|
|
98
|
-
sessionId,
|
|
99
|
-
version
|
|
100
|
-
},
|
|
101
|
-
timeout: 30_000,
|
|
102
|
-
success(result) {
|
|
103
|
-
if (generation !== requestGeneration) return
|
|
104
|
-
activeRequest = undefined
|
|
105
|
-
const response = parseResponse(result.data)
|
|
106
|
-
if (action === 'register' && response.type === 'registered') {
|
|
107
|
-
dispatch({ type: 'registration-completed' })
|
|
108
|
-
return
|
|
109
|
-
}
|
|
110
|
-
if (action === 'poll' && (response.type === 'idle' || response.type === 'changed')) {
|
|
111
|
-
dispatch({ type: 'poll-completed' })
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
if (response.type === 'batch-published') {
|
|
115
|
-
// If DevTools misses the update.js event, report the unchanged version and republish with a new nonce.
|
|
116
|
-
scheduleRequest(updateFileWatchdogDelay)
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
if (response.type === 'rebuilding') {
|
|
120
|
-
scheduleRequest(rebuildPollDelay)
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
dispatch({ type: 'transport-failed' })
|
|
124
|
-
},
|
|
125
|
-
fail() {
|
|
126
|
-
if (generation !== requestGeneration) return
|
|
127
|
-
activeRequest = undefined
|
|
128
|
-
dispatch({ type: 'transport-failed' })
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Keeps exactly one delayed metadata request and discards it when protocol state advances. */
|
|
134
|
-
const scheduleRequest = (delay: number): void => {
|
|
135
|
-
if (scheduledRequest) clearTimeout(scheduledRequest)
|
|
136
|
-
const expectedPhase = state.phase
|
|
137
|
-
const expectedVersion = state.version
|
|
138
|
-
scheduledRequest = setTimeout(() => {
|
|
139
|
-
scheduledRequest = undefined
|
|
140
|
-
if (state.phase !== expectedPhase || state.version !== expectedVersion) return
|
|
141
|
-
send(state.phase === 'registering' ? 'register' : 'poll', state.version)
|
|
142
|
-
}, delay)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const execute = (command: WxUpdateClientCommand, apply?: () => void): void => {
|
|
146
|
-
switch (command.type) {
|
|
147
|
-
case 'register':
|
|
148
|
-
send('register', command.version)
|
|
149
|
-
return
|
|
150
|
-
case 'poll':
|
|
151
|
-
case 'report-version':
|
|
152
|
-
send('poll', command.version)
|
|
153
|
-
return
|
|
154
|
-
case 'apply-batch': {
|
|
155
|
-
const batchApply = apply ?? pendingBatchApply
|
|
156
|
-
pendingBatchApply = undefined
|
|
157
|
-
if (!batchApply) {
|
|
158
|
-
dispatch({ type: 'batch-failed' })
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
const applyUpdate = () => {
|
|
162
|
-
const bridge = wxClientGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__
|
|
163
|
-
if (!bridge) {
|
|
164
|
-
dispatch({ type: 'batch-failed' })
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
bridge.beginUpdate?.()
|
|
168
|
-
try {
|
|
169
|
-
batchApply()
|
|
170
|
-
dispatch({ type: 'batch-executed', targetVersion: command.targetVersion })
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error('[vite-plugin-taro] WX update execution failed', error)
|
|
173
|
-
dispatch({ type: 'batch-failed' })
|
|
174
|
-
} finally {
|
|
175
|
-
bridge.endUpdate?.()
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const bridge = wxClientGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__
|
|
179
|
-
if (bridge?.ready) applyUpdate()
|
|
180
|
-
else if (bridge) bridge.pendingUpdate = applyUpdate
|
|
181
|
-
else dispatch({ type: 'batch-failed' })
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
case 'request-full-build':
|
|
185
|
-
send('rebuild', state.version)
|
|
186
|
-
return
|
|
187
|
-
case 'retry-transport':
|
|
188
|
-
scheduleRequest(transportRetryDelay)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
wxClientGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__ = {
|
|
193
|
-
receiveBatch(metadata, apply) {
|
|
194
|
-
dispatch({ type: 'batch-observed', ...metadata }, apply)
|
|
195
|
-
if (
|
|
196
|
-
state.pendingBatch?.fromVersion === metadata.fromVersion &&
|
|
197
|
-
state.pendingBatch.targetVersion === metadata.targetVersion
|
|
198
|
-
) {
|
|
199
|
-
pendingBatchApply = apply
|
|
200
|
-
} else if (!state.pendingBatch && state.phase !== 'applying') {
|
|
201
|
-
pendingBatchApply = undefined
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
refreshCompleted(stale) {
|
|
205
|
-
dispatch({ type: 'refresh-completed', stale })
|
|
206
|
-
},
|
|
207
|
-
routeReady() {
|
|
208
|
-
dispatch({ type: 'route-ready' })
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
dispatch({ type: 'started' })
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function createSessionId(): string {
|
|
215
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function parseResponse(value: unknown): { type: string } {
|
|
219
|
-
if (typeof value !== 'object' || value === null || !('type' in value) || typeof value.type !== 'string') {
|
|
220
|
-
return { type: 'invalid' }
|
|
221
|
-
}
|
|
222
|
-
return { type: value.type }
|
|
223
|
-
}
|