vite-plugin-taro 0.3.1 → 0.4.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.
Files changed (260) hide show
  1. package/README.en.md +44 -0
  2. package/README.md +22 -497
  3. package/client.d.ts +9 -0
  4. package/dist/node/plugins/client/client-taro.d.ts +4 -0
  5. package/dist/node/plugins/client/client-taro.js +19 -0
  6. package/dist/node/plugins/client/constant.d.ts +4 -0
  7. package/dist/node/plugins/client/constant.js +4 -0
  8. package/dist/node/plugins/conditional/conditional-directives.d.ts +4 -0
  9. package/dist/node/plugins/{conditional-directives.js → conditional/conditional-directives.js} +27 -11
  10. package/dist/node/plugins/css/plugins.d.ts +4 -0
  11. package/dist/node/plugins/css/plugins.js +84 -0
  12. package/dist/node/plugins/h5/constant.d.ts +2 -0
  13. package/dist/node/plugins/h5/constant.js +3 -0
  14. package/dist/node/plugins/h5/plugins.d.ts +4 -0
  15. package/dist/node/plugins/h5/plugins.js +161 -0
  16. package/dist/node/plugins/h5/resolver/module-resolver.d.ts +14 -0
  17. package/dist/node/plugins/h5/resolver/module-resolver.js +19 -0
  18. package/dist/node/plugins/h5/transform-app.d.ts +10 -0
  19. package/dist/node/plugins/h5/transform-app.js +48 -0
  20. package/dist/node/plugins/wx/dev/dev-host.d.ts +15 -0
  21. package/dist/node/plugins/wx/dev/dev-host.js +352 -0
  22. package/dist/node/plugins/wx/dev/hmr-files.d.ts +28 -0
  23. package/dist/node/plugins/wx/dev/hmr-files.js +34 -0
  24. package/dist/node/plugins/wx/dev/patch-publisher.d.ts +22 -0
  25. package/dist/node/plugins/wx/dev/patch-publisher.js +40 -0
  26. package/dist/node/plugins/wx/dev/plugin.d.ts +7 -0
  27. package/dist/node/plugins/wx/dev/plugin.js +73 -0
  28. package/dist/node/plugins/wx/dev/react-refresh.d.ts +20 -0
  29. package/dist/node/plugins/wx/dev/react-refresh.js +198 -0
  30. package/dist/node/plugins/wx/module.d.ts +45 -0
  31. package/dist/node/plugins/wx/module.js +66 -0
  32. package/dist/node/plugins/wx/native/compile-native-component-interface.d.ts +21 -0
  33. package/dist/node/plugins/wx/native/compile-native-component-interface.js +29 -0
  34. package/dist/node/plugins/wx/native/create-native-component-output.d.ts +15 -0
  35. package/dist/node/plugins/wx/native/create-native-component-output.js +39 -0
  36. package/dist/node/plugins/wx/native/native-component-assets.d.ts +26 -0
  37. package/dist/node/plugins/wx/native/native-component-assets.js +76 -0
  38. package/dist/node/plugins/wx/native/native-component-interface.d.ts +12 -0
  39. package/dist/node/plugins/wx/native/native-component-interface.js +201 -0
  40. package/dist/node/plugins/wx/output/files.d.ts +12 -0
  41. package/dist/node/plugins/wx/output/files.js +12 -0
  42. package/dist/node/plugins/wx/output/json.d.ts +14 -0
  43. package/dist/node/plugins/wx/output/json.js +52 -0
  44. package/dist/node/plugins/wx/output/relative-root.d.ts +2 -0
  45. package/dist/node/plugins/wx/output/relative-root.js +6 -0
  46. package/dist/node/plugins/wx/output/templates.d.ts +7 -0
  47. package/dist/node/plugins/wx/output/templates.js +100 -0
  48. package/dist/node/plugins/wx/placement/placer.d.ts +78 -0
  49. package/dist/node/plugins/wx/placement/placer.js +145 -0
  50. package/dist/node/plugins/wx/placement/plan.d.ts +46 -0
  51. package/dist/node/plugins/wx/placement/plan.js +210 -0
  52. package/dist/node/plugins/wx/plugins.d.ts +4 -0
  53. package/dist/node/plugins/wx/plugins.js +137 -0
  54. package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +3 -0
  55. package/dist/node/plugins/wx/render/capsule-wrapper.js +64 -0
  56. package/dist/node/plugins/wx/render/capsule.d.ts +4 -0
  57. package/dist/node/plugins/wx/render/capsule.js +13 -0
  58. package/dist/node/plugins/wx/render/native.d.ts +9 -0
  59. package/dist/node/plugins/wx/render/native.js +45 -0
  60. package/dist/node/plugins/wx/render/transport.d.ts +17 -0
  61. package/dist/node/plugins/wx/render/transport.js +94 -0
  62. package/dist/node/plugins/wx/resolve/resolver.d.ts +7 -0
  63. package/dist/node/plugins/wx/resolve/resolver.js +86 -0
  64. package/dist/node/plugins/wx/resolve/specialize-bootstrap.d.ts +9 -0
  65. package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +9 -0
  66. package/dist/node/plugins/wx/resolve/specialize-page-capsule.d.ts +9 -0
  67. package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +11 -0
  68. package/dist/node/utils/constant.d.ts +1 -0
  69. package/dist/node/utils/constant.js +1 -0
  70. package/dist/node/utils/memoize.d.ts +122 -0
  71. package/dist/node/utils/memoize.js +86 -0
  72. package/dist/node/utils/modules.d.ts +20 -24
  73. package/dist/node/utils/modules.js +21 -34
  74. package/dist/node/utils/once.d.ts +10 -0
  75. package/dist/node/utils/once.js +20 -0
  76. package/dist/node/utils/packages.d.ts +1 -0
  77. package/dist/node/utils/packages.js +1 -1
  78. package/dist/node/utils/project-config.d.ts +3 -0
  79. package/dist/node/utils/project-config.js +8 -0
  80. package/dist/node/utils/serialized-task-queue.d.ts +9 -0
  81. package/dist/node/utils/serialized-task-queue.js +17 -0
  82. package/dist/node/utils/transform.d.ts +11 -0
  83. package/dist/node/utils/transform.js +58 -0
  84. package/dist/node/vite-plugin.d.ts +1 -1
  85. package/dist/node/vite-plugin.js +11 -27
  86. package/dist/options.d.ts +3 -4
  87. package/dist/runtime/{taro → client/taro}/api.d.ts +0 -1
  88. package/dist/runtime/client/taro/api.js +9 -0
  89. package/dist/runtime/client/taro/component.d.ts +1 -0
  90. package/dist/runtime/client/taro/component.js +1 -0
  91. package/dist/runtime/client/taro/define-native-component.d.ts +7 -0
  92. package/dist/runtime/client/taro/define-native-component.js +4 -0
  93. package/dist/runtime/h5/app.d.ts +2 -0
  94. package/dist/runtime/h5/app.js +15 -0
  95. package/dist/runtime/h5/taro-runtime.d.ts +1 -1
  96. package/dist/runtime/h5/taro-runtime.js +1 -4
  97. package/dist/runtime/wx/amphibious/bootstrap.d.ts +4 -0
  98. package/dist/runtime/wx/amphibious/bootstrap.js +16 -0
  99. package/dist/runtime/wx/amphibious/transport.d.ts +2 -0
  100. package/dist/runtime/wx/amphibious/transport.js +4 -0
  101. package/dist/runtime/wx/capsule/app.d.ts +2 -0
  102. package/dist/runtime/wx/capsule/app.js +7 -0
  103. package/dist/runtime/wx/capsule/component.d.ts +3 -0
  104. package/dist/runtime/wx/capsule/component.js +4 -0
  105. package/dist/runtime/wx/capsule/page.d.ts +3 -0
  106. package/dist/runtime/wx/capsule/page.js +68 -0
  107. package/dist/runtime/wx/capsule/taro-runtime.d.ts +6 -0
  108. package/dist/runtime/wx/capsule/taro-runtime.js +6 -0
  109. package/dist/runtime/wx/dev/dev-runtime.d.ts +1 -0
  110. package/dist/runtime/wx/dev/dev-runtime.js +246 -0
  111. package/dist/runtime/wx/native/app.d.ts +1 -0
  112. package/dist/runtime/wx/native/app.js +3 -0
  113. package/dist/runtime/wx/native/component.d.ts +1 -0
  114. package/dist/runtime/wx/native/component.js +3 -0
  115. package/dist/runtime/wx/native/page.d.ts +1 -0
  116. package/dist/runtime/wx/native/page.js +4 -0
  117. package/dist/runtime/wx/systemjs/system-core.d.ts +4 -0
  118. package/dist/runtime/wx/systemjs/system-core.js +331 -0
  119. package/package.json +21 -13
  120. package/src/node/plugins/client/client-taro.ts +23 -0
  121. package/src/node/plugins/client/constant.ts +5 -0
  122. package/src/node/plugins/{conditional-directives.ts → conditional/conditional-directives.ts} +33 -13
  123. package/src/node/plugins/css/plugins.ts +96 -0
  124. package/src/node/plugins/h5/constant.ts +4 -0
  125. package/src/node/plugins/h5/plugins.ts +197 -0
  126. package/src/node/plugins/h5/resolver/module-resolver.ts +32 -0
  127. package/src/node/plugins/h5/transform-app.ts +90 -0
  128. package/src/node/plugins/wx/dev/dev-host.ts +448 -0
  129. package/src/node/plugins/wx/dev/hmr-files.ts +55 -0
  130. package/src/node/plugins/wx/dev/patch-publisher.ts +49 -0
  131. package/src/node/plugins/wx/dev/plugin.ts +82 -0
  132. package/src/node/plugins/wx/dev/react-refresh.ts +227 -0
  133. package/src/node/plugins/wx/module.ts +97 -0
  134. package/src/node/plugins/wx/native/compile-native-component-interface.ts +47 -0
  135. package/src/node/plugins/wx/native/create-native-component-output.ts +57 -0
  136. package/src/node/plugins/wx/native/native-component-assets.ts +114 -0
  137. package/src/node/plugins/wx/native/native-component-interface.ts +265 -0
  138. package/src/node/plugins/wx/output/files.ts +27 -0
  139. package/src/node/plugins/wx/output/json.ts +79 -0
  140. package/src/node/plugins/wx/output/relative-root.ts +7 -0
  141. package/src/node/plugins/wx/output/templates.ts +141 -0
  142. package/src/node/plugins/wx/placement/placer.ts +172 -0
  143. package/src/node/plugins/wx/placement/plan.ts +306 -0
  144. package/src/node/plugins/wx/plugins.ts +165 -0
  145. package/src/node/plugins/wx/render/capsule-wrapper.ts +86 -0
  146. package/src/node/plugins/wx/render/capsule.ts +21 -0
  147. package/src/node/plugins/wx/render/native.ts +84 -0
  148. package/src/node/plugins/wx/render/transport.ts +157 -0
  149. package/src/node/plugins/wx/resolve/resolver.ts +125 -0
  150. package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +27 -0
  151. package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +29 -0
  152. package/src/node/utils/constant.ts +1 -0
  153. package/src/node/utils/memoize.ts +149 -0
  154. package/src/node/utils/modules.ts +36 -38
  155. package/src/node/utils/once.ts +21 -0
  156. package/src/node/utils/packages.ts +1 -1
  157. package/src/node/utils/project-config.ts +10 -0
  158. package/src/node/utils/serialized-task-queue.ts +20 -0
  159. package/src/node/utils/transform.ts +82 -0
  160. package/src/node/vite-plugin.ts +12 -33
  161. package/src/options.ts +3 -4
  162. package/src/runtime/client/taro/api.ts +11 -0
  163. package/src/runtime/client/taro/component.ts +1 -0
  164. package/src/runtime/client/taro/define-native-component.ts +15 -0
  165. package/src/runtime/h5/app.ts +25 -0
  166. package/src/runtime/h5/taro-runtime.ts +1 -4
  167. package/src/runtime/wx/amphibious/bootstrap.ts +22 -0
  168. package/src/runtime/wx/amphibious/transport.ts +10 -0
  169. package/src/runtime/wx/capsule/app.ts +9 -0
  170. package/src/runtime/wx/capsule/component.ts +6 -0
  171. package/src/runtime/wx/capsule/page.ts +96 -0
  172. package/src/runtime/wx/capsule/taro-runtime.ts +14 -0
  173. package/src/runtime/wx/dev/dev-runtime.ts +317 -0
  174. package/src/runtime/wx/native/app.ts +4 -0
  175. package/src/runtime/wx/native/component.ts +4 -0
  176. package/src/runtime/wx/native/page.ts +6 -0
  177. package/src/runtime/wx/systemjs/LICENSE +10 -0
  178. package/src/runtime/wx/systemjs/system-core.js +370 -0
  179. package/src/runtime/wx/systemjs/system.d.ts +55 -0
  180. package/src/runtime/wx/wechat.d.ts +52 -0
  181. package/README.zh.md +0 -521
  182. package/dist/node/build-context.d.ts +0 -25
  183. package/dist/node/build-context.js +0 -48
  184. package/dist/node/css/css-pipeline.d.ts +0 -21
  185. package/dist/node/css/css-pipeline.js +0 -129
  186. package/dist/node/plugins/conditional-directives.d.ts +0 -3
  187. package/dist/node/plugins/taro-runtime.d.ts +0 -5
  188. package/dist/node/plugins/taro-runtime.js +0 -18
  189. package/dist/node/targets/h5/plugin.d.ts +0 -6
  190. package/dist/node/targets/h5/plugin.js +0 -117
  191. package/dist/node/targets/h5/virtual-modules.d.ts +0 -5
  192. package/dist/node/targets/h5/virtual-modules.js +0 -60
  193. package/dist/node/targets/wx/companion-assets.d.ts +0 -19
  194. package/dist/node/targets/wx/companion-assets.js +0 -129
  195. package/dist/node/targets/wx/dev-server/development-session.d.ts +0 -31
  196. package/dist/node/targets/wx/dev-server/development-session.js +0 -202
  197. package/dist/node/targets/wx/dev-server/full-build-scheduler.d.ts +0 -14
  198. package/dist/node/targets/wx/dev-server/full-build-scheduler.js +0 -60
  199. package/dist/node/targets/wx/dev-server/js-utils.d.ts +0 -5
  200. package/dist/node/targets/wx/dev-server/js-utils.js +0 -28
  201. package/dist/node/targets/wx/dev-server/output.d.ts +0 -19
  202. package/dist/node/targets/wx/dev-server/output.js +0 -44
  203. package/dist/node/targets/wx/dev-server/rolldown-runtime-source.d.ts +0 -8
  204. package/dist/node/targets/wx/dev-server/rolldown-runtime-source.js +0 -95
  205. package/dist/node/targets/wx/dev-server/update-server-state.d.ts +0 -65
  206. package/dist/node/targets/wx/dev-server/update-server-state.js +0 -116
  207. package/dist/node/targets/wx/dev-server/update-transport.d.ts +0 -28
  208. package/dist/node/targets/wx/dev-server/update-transport.js +0 -212
  209. package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.d.ts +0 -44
  210. package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.js +0 -145
  211. package/dist/node/targets/wx/development-files.d.ts +0 -8
  212. package/dist/node/targets/wx/development-files.js +0 -8
  213. package/dist/node/targets/wx/plugin.d.ts +0 -6
  214. package/dist/node/targets/wx/plugin.js +0 -143
  215. package/dist/node/targets/wx/react-refresh.d.ts +0 -4
  216. package/dist/node/targets/wx/react-refresh.js +0 -38
  217. package/dist/node/targets/wx/virtual-modules.d.ts +0 -16
  218. package/dist/node/targets/wx/virtual-modules.js +0 -120
  219. package/dist/node/utils/async.d.ts +0 -8
  220. package/dist/node/utils/async.js +0 -16
  221. package/dist/node/utils/filesystem.d.ts +0 -13
  222. package/dist/node/utils/filesystem.js +0 -43
  223. package/dist/runtime/taro/api.js +0 -11
  224. package/dist/runtime/taro/components.d.ts +0 -2
  225. package/dist/runtime/taro/components.js +0 -2
  226. package/dist/runtime/wx/page-update.d.ts +0 -6
  227. package/dist/runtime/wx/page-update.js +0 -157
  228. package/dist/runtime/wx/taro-runtime.d.ts +0 -5
  229. package/dist/runtime/wx/taro-runtime.js +0 -6
  230. package/dist/runtime/wx/update-client-state.d.ts +0 -68
  231. package/dist/runtime/wx/update-client-state.js +0 -84
  232. package/dist/runtime/wx/update-client.d.ts +0 -1
  233. package/dist/runtime/wx/update-client.js +0 -170
  234. package/src/node/build-context.ts +0 -63
  235. package/src/node/css/css-pipeline.ts +0 -147
  236. package/src/node/plugins/taro-runtime.ts +0 -22
  237. package/src/node/targets/h5/plugin.ts +0 -135
  238. package/src/node/targets/h5/virtual-modules.ts +0 -71
  239. package/src/node/targets/wx/companion-assets.ts +0 -170
  240. package/src/node/targets/wx/dev-server/development-session.ts +0 -253
  241. package/src/node/targets/wx/dev-server/full-build-scheduler.ts +0 -62
  242. package/src/node/targets/wx/dev-server/js-utils.ts +0 -33
  243. package/src/node/targets/wx/dev-server/output.ts +0 -56
  244. package/src/node/targets/wx/dev-server/rolldown-runtime-source.ts +0 -95
  245. package/src/node/targets/wx/dev-server/update-server-state.ts +0 -183
  246. package/src/node/targets/wx/dev-server/update-transport.ts +0 -261
  247. package/src/node/targets/wx/dev-server/vite-bundled-dev-adapter.ts +0 -203
  248. package/src/node/targets/wx/development-files.ts +0 -11
  249. package/src/node/targets/wx/plugin.ts +0 -163
  250. package/src/node/targets/wx/react-refresh.ts +0 -51
  251. package/src/node/targets/wx/virtual-modules.ts +0 -152
  252. package/src/node/utils/async.ts +0 -19
  253. package/src/node/utils/filesystem.ts +0 -45
  254. package/src/runtime/taro/api.ts +0 -13
  255. package/src/runtime/taro/components.ts +0 -2
  256. package/src/runtime/wx/page-update.ts +0 -230
  257. package/src/runtime/wx/react-refresh.d.ts +0 -20
  258. package/src/runtime/wx/taro-runtime.ts +0 -7
  259. package/src/runtime/wx/update-client-state.ts +0 -138
  260. package/src/runtime/wx/update-client.ts +0 -222
@@ -1,120 +0,0 @@
1
- import { createPageComponentImportPath, toViteFileImportPath } from '../../utils/modules.js';
2
- import { resolvePackageFile } from '../../utils/packages.js';
3
- import { wxPagePreloadFile } from './development-files.js';
4
- import { createWxReactRefreshPreambleSource } from './react-refresh.js';
5
- const wxTaroRuntimeImportPath = runtimeImportPath('taro-runtime.js');
6
- const wxPageUpdateImportPath = runtimeImportPath('page-update.js');
7
- const wxUpdateClientImportPath = runtimeImportPath('update-client.js');
8
- /** Generated native App entry. */
9
- export const virtualWxAppId = 'virtual:vite-plugin-taro/wx/app';
10
- /** Generated recursive Taro component entry. */
11
- const virtualWxComponentId = 'virtual:vite-plugin-taro/wx/component';
12
- /** Prefix for one generated native entry per configured page route. */
13
- const virtualWxPageIdPrefix = 'virtual:vite-plugin-taro/wx/page/';
14
- /** App bootstrap module that installs React Refresh globals before application modules execute. */
15
- const virtualWxRefreshPreambleId = 'virtual:vite-plugin-taro/wx/refresh-preamble';
16
- /** Development-only entry that initializes all configured page components before update replay. */
17
- const virtualWxPagePreloadId = 'virtual:vite-plugin-taro/wx/page-preload';
18
- export function isWxVirtualModuleId(id) {
19
- return (id === virtualWxAppId ||
20
- id === virtualWxComponentId ||
21
- id === virtualWxRefreshPreambleId ||
22
- id === virtualWxPagePreloadId ||
23
- id.startsWith(virtualWxPageIdPrefix));
24
- }
25
- export function loadWxVirtualModule(id, context) {
26
- if (id === virtualWxRefreshPreambleId) {
27
- return createWxReactRefreshPreambleSource();
28
- }
29
- if (id === virtualWxAppId) {
30
- return createWxAppEntrySource(context);
31
- }
32
- if (id === virtualWxComponentId) {
33
- return createWxComponentEntrySource();
34
- }
35
- if (id === virtualWxPagePreloadId) {
36
- return createWxPagePreloadSource(context);
37
- }
38
- if (id.startsWith(virtualWxPageIdPrefix)) {
39
- const pagePath = id.slice(virtualWxPageIdPrefix.length);
40
- const page = context.project.pages.find((candidate) => candidate.path === pagePath);
41
- if (page) {
42
- return createWxPageEntrySource(page, context);
43
- }
44
- }
45
- }
46
- /** Registers every configured page and the shared recursive component as eager WX entry chunks. */
47
- export function emitWxEntryChunks(emitter, context, id) {
48
- if (id !== virtualWxAppId)
49
- return;
50
- for (const page of context.project.pages) {
51
- emitter.emitFile({
52
- type: 'chunk',
53
- id: `${virtualWxPageIdPrefix}${page.path}`,
54
- fileName: `${page.path}.js`,
55
- implicitlyLoadedAfterOneOf: [id]
56
- });
57
- }
58
- emitter.emitFile({
59
- type: 'chunk',
60
- id: virtualWxComponentId,
61
- fileName: 'comp.js',
62
- implicitlyLoadedAfterOneOf: [id]
63
- });
64
- if (context.development) {
65
- emitter.emitFile({
66
- type: 'chunk',
67
- id: virtualWxPagePreloadId,
68
- fileName: wxPagePreloadFile,
69
- implicitlyLoadedAfterOneOf: [id]
70
- });
71
- }
72
- }
73
- function createWxAppEntrySource(context) {
74
- const refreshPreamble = context.development ? `import ${JSON.stringify(virtualWxRefreshPreambleId)}\n` : '';
75
- const updateClient = context.development
76
- ? `import { startWxUpdateClient } from ${JSON.stringify(wxUpdateClientImportPath)}\n`
77
- : '';
78
- return `${refreshPreamble}${updateClient}import { createReactApp, ReactDOM } from ${JSON.stringify(wxTaroRuntimeImportPath)}
79
- import React from 'react'
80
- import AppComponent from ${JSON.stringify(toViteFileImportPath(context.project.appComponentFile))}
81
-
82
- const appConfig = ${JSON.stringify(context.project.appConfig)}
83
- App(createReactApp(AppComponent, React, ReactDOM, appConfig))
84
- ${context.development ? 'startWxUpdateClient()' : ''}
85
- `;
86
- }
87
- function createWxPageEntrySource(page, context) {
88
- const hotUpdateImport = context.development
89
- ? `import { decorateWxPageConfig, registerWxPage } from ${JSON.stringify(wxPageUpdateImportPath)}\n`
90
- : '';
91
- const createConfig = `createPageConfig(PageComponent, '${page.path}', { root: { cn: [] } }, pageConfig)`;
92
- const pageRegistration = context.development
93
- ? `registerWxPage(${JSON.stringify(page.path)}, () => Page(taroPageConfig))`
94
- : 'Page(taroPageConfig)';
95
- return `${hotUpdateImport}import { createPageConfig } from ${JSON.stringify(wxTaroRuntimeImportPath)}
96
- import PageComponent from ${JSON.stringify(createPageComponentImportPath(page.path))}
97
-
98
- const pageConfig = ${JSON.stringify(page.config)}
99
- const taroPageConfig = ${context.development ? `decorateWxPageConfig(${createConfig})` : createConfig}
100
- if (PageComponent && PageComponent.behaviors) {
101
- taroPageConfig.behaviors = (taroPageConfig.behaviors || []).concat(PageComponent.behaviors)
102
- }
103
- ${pageRegistration}
104
- `;
105
- }
106
- function createWxPagePreloadSource(context) {
107
- const imports = context.project.pages.map((page, index) => {
108
- return `import Page${index} from ${JSON.stringify(createPageComponentImportPath(page.path))}`;
109
- });
110
- return `${imports.join('\n')}\nvoid [${context.project.pages.map((_, index) => `Page${index}`).join(', ')}]\n`;
111
- }
112
- function runtimeImportPath(fileName) {
113
- return toViteFileImportPath(resolvePackageFile('dist/runtime/wx', fileName));
114
- }
115
- function createWxComponentEntrySource() {
116
- return `import { createRecursiveComponentConfig } from ${JSON.stringify(wxTaroRuntimeImportPath)}
117
-
118
- Component(createRecursiveComponentConfig())
119
- `;
120
- }
@@ -1,8 +0,0 @@
1
- /** Generic asynchronous coordination helpers for Node-side plugin services. */
2
- export declare class SerializedTaskQueue {
3
- private readonly reportError;
4
- private tail;
5
- constructor(reportError: (error: unknown) => void);
6
- enqueue(task: () => Promise<void>): Promise<void>;
7
- waitForIdle(): Promise<void>;
8
- }
@@ -1,16 +0,0 @@
1
- /** Generic asynchronous coordination helpers for Node-side plugin services. */
2
- export class SerializedTaskQueue {
3
- reportError;
4
- tail = Promise.resolve();
5
- constructor(reportError) {
6
- this.reportError = reportError;
7
- }
8
- enqueue(task) {
9
- const work = this.tail.then(task);
10
- this.tail = work.catch(this.reportError);
11
- return work;
12
- }
13
- async waitForIdle() {
14
- await this.tail;
15
- }
16
- }
@@ -1,13 +0,0 @@
1
- type FileSource = string | Uint8Array;
2
- type FileWrite = {
3
- file: string;
4
- source: FileSource;
5
- };
6
- /** Writes through a sibling temporary file so observers never read partial contents. */
7
- export declare function writeFileAtomically(file: string, source: FileSource): Promise<void>;
8
- export declare function writeFilesAtomically(files: FileWrite[]): Promise<void>;
9
- /** Copies a directory when present and treats a missing optional source as empty. */
10
- export declare function copyDirectoryIfExists(source: string, destination: string): Promise<void>;
11
- /** Mirrors one optional file: copy existing files, ignore directories, and remove a missing source's destination. */
12
- export declare function copyFileOrRemove(source: string, destination: string): Promise<void>;
13
- export {};
@@ -1,43 +0,0 @@
1
- /** Node-only filesystem helpers shared by build targets and development services. */
2
- import fs from 'node:fs/promises';
3
- import path from 'node:path';
4
- /** Writes through a sibling temporary file so observers never read partial contents. */
5
- export async function writeFileAtomically(file, source) {
6
- await fs.mkdir(path.dirname(file), { recursive: true });
7
- const temporaryFile = `${file}.tmp`;
8
- await fs.writeFile(temporaryFile, source);
9
- await fs.rename(temporaryFile, file);
10
- }
11
- export async function writeFilesAtomically(files) {
12
- await Promise.all(files.map(({ file, source }) => writeFileAtomically(file, source)));
13
- }
14
- /** Copies a directory when present and treats a missing optional source as empty. */
15
- export async function copyDirectoryIfExists(source, destination) {
16
- if (!source)
17
- return;
18
- try {
19
- await fs.cp(source, destination, { recursive: true, force: true });
20
- }
21
- catch (error) {
22
- if (!isMissingFileError(error))
23
- throw error;
24
- }
25
- }
26
- /** Mirrors one optional file: copy existing files, ignore directories, and remove a missing source's destination. */
27
- export async function copyFileOrRemove(source, destination) {
28
- try {
29
- const stat = await fs.stat(source);
30
- if (stat.isDirectory())
31
- return;
32
- await fs.mkdir(path.dirname(destination), { recursive: true });
33
- await fs.copyFile(source, destination);
34
- }
35
- catch (error) {
36
- if (!isMissingFileError(error))
37
- throw error;
38
- await fs.rm(destination, { recursive: true, force: true });
39
- }
40
- }
41
- function isMissingFileError(error) {
42
- return error instanceof Error && 'code' in error && error.code === 'ENOENT';
43
- }
@@ -1,11 +0,0 @@
1
- /** Physical runtime module backing the public `virtual:taro/api` facade. */
2
- // Ensure Taro's React runtime registers its `initNativeApi` hook before @tarojs/taro is initialized.
3
- import '@tarojs/plugin-framework-react/dist/runtime';
4
- import { hooks } from '@tarojs/runtime';
5
- import Taro from '@tarojs/taro';
6
- if (hooks.isExist('initNativeApi')) {
7
- hooks.call('initNativeApi', Taro);
8
- }
9
- // @ts-expect-error @tarojs/taro declares export= types, but vite-plugin-taro target aliases expose runtime named exports.
10
- export * from '@tarojs/taro';
11
- export default Taro;
@@ -1,2 +0,0 @@
1
- /** Physical runtime module backing the public `virtual:taro/components` facade. */
2
- export * from '@tarojs/components';
@@ -1,2 +0,0 @@
1
- /** Physical runtime module backing the public `virtual:taro/components` facade. */
2
- export * from '@tarojs/components';
@@ -1,6 +0,0 @@
1
- type WxPageConfig = Record<string, unknown>;
2
- /** Registers a native route once per App Service runtime generation. */
3
- export declare function registerWxPage(route: string, register: () => void): void;
4
- /** Retains Taro's live root while filtering DevTools' synthetic update lifecycles. */
5
- export declare function decorateWxPageConfig(config: WxPageConfig): WxPageConfig;
6
- export {};
@@ -1,157 +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
- const wxRuntimeGlobal = globalThis;
10
- wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__ ??= { ready: false };
11
- const bridge = wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__;
12
- const refreshBoundary = { default: function WxRefreshBoundary() { } };
13
- const registeredRoutes = new Set();
14
- const ignoredPages = new WeakSet();
15
- let pageRuntimeState = { suppressLifecycles: false };
16
- /** Registers a native route once per App Service runtime generation. */
17
- export function registerWxPage(route, register) {
18
- if (registeredRoutes.has(route))
19
- return;
20
- register();
21
- registeredRoutes.add(route);
22
- }
23
- /** Retains Taro's live root while filtering DevTools' synthetic update lifecycles. */
24
- export function decorateWxPageConfig(config) {
25
- const onLoad = getLifecycle(config, 'onLoad');
26
- config.onLoad = function (...args) {
27
- if (pageRuntimeState.suppressLifecycles) {
28
- ignoredPages.add(this);
29
- this.$taroPath = pageRuntimeState.activePage?.$taroPath;
30
- this.$taroParams = pageRuntimeState.activePage?.$taroParams;
31
- dispatchPageRuntime({ type: 'page-activated', page: this });
32
- return;
33
- }
34
- const result = onLoad?.apply(this, args);
35
- dispatchPageRuntime({ type: 'page-activated', page: this });
36
- return result;
37
- };
38
- wrapLifecycle(config, 'onReady', applyPendingPageUpdate);
39
- wrapLifecycle(config, 'onShow', function () {
40
- dispatchPageRuntime({ type: 'page-activated', page: this });
41
- });
42
- wrapLifecycle(config, 'onHide');
43
- wrapLifecycle(config, 'onUnload', function () {
44
- dispatchPageRuntime({ type: 'page-unloaded', page: this });
45
- });
46
- return config;
47
- }
48
- function wrapLifecycle(config, name, after) {
49
- const original = getLifecycle(config, name);
50
- config[name] = function (...args) {
51
- if (pageRuntimeState.suppressLifecycles)
52
- return;
53
- if (ignoredPages.has(this)) {
54
- if (name === 'onUnload')
55
- ignoredPages.delete(this);
56
- return;
57
- }
58
- const result = original?.apply(this, args);
59
- after?.apply(this, args);
60
- return result;
61
- };
62
- }
63
- function getLifecycle(config, name) {
64
- return typeof config[name] === 'function' ? config[name] : undefined;
65
- }
66
- function applyPendingPageUpdate() {
67
- bridge.ready = true;
68
- const pendingUpdate = bridge.pendingUpdate;
69
- if (pendingUpdate) {
70
- delete bridge.pendingUpdate;
71
- pendingUpdate();
72
- }
73
- wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.routeReady();
74
- }
75
- function getActiveTaroRoot() {
76
- const page = pageRuntimeState.activePage;
77
- if (!page?.$taroPath)
78
- return;
79
- return document.getElementById(page.$taroPath) ?? undefined;
80
- }
81
- bridge.enqueueRefresh = () => {
82
- validateRefreshBoundaryAndEnqueueUpdate('vite-plugin-taro-wx', refreshBoundary, refreshBoundary);
83
- };
84
- bridge.beginUpdate = () => {
85
- bridge.blockRefreshRegistration = false;
86
- wxRuntimeGlobal.__rolldown_runtime__?.beginPatch?.();
87
- dispatchPageRuntime({ type: 'update-started', root: getActiveTaroRoot() });
88
- refreshTaroRoot(pageRuntimeState.pendingUpdate?.root, pageRuntimeState.pendingUpdate?.page);
89
- runInNextNativeTask(() => dispatchPageRuntime({ type: 'suppression-ended' }));
90
- };
91
- bridge.endUpdate = () => {
92
- wxRuntimeGlobal.__rolldown_runtime__?.endPatch?.();
93
- bridge.blockRefreshRegistration = true;
94
- bridge.enqueueRefresh?.();
95
- };
96
- bridge.afterRefresh = (update) => {
97
- bridge.blockRefreshRegistration = false;
98
- const pendingUpdate = pageRuntimeState.pendingUpdate;
99
- dispatchPageRuntime({ type: 'refresh-finished' });
100
- const page = pendingUpdate?.page;
101
- const root = pendingUpdate?.root;
102
- const stale = Boolean(update?.staleFamilies?.size);
103
- if (stale) {
104
- wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.refreshCompleted(true);
105
- relaunchActiveRoute(page);
106
- return;
107
- }
108
- runInNextNativeTask(() => {
109
- refreshTaroRoot(root, pageRuntimeState.activePage ?? page);
110
- wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.refreshCompleted(false);
111
- });
112
- };
113
- function dispatchPageRuntime(event) {
114
- pageRuntimeState = transitionPageRuntime(pageRuntimeState, event);
115
- }
116
- function transitionPageRuntime(state, event) {
117
- switch (event.type) {
118
- case 'page-activated':
119
- return { ...state, activePage: event.page };
120
- case 'page-unloaded':
121
- return state.activePage === event.page ? { ...state, activePage: undefined } : state;
122
- case 'update-started':
123
- return {
124
- ...state,
125
- pendingUpdate: { page: state.activePage, root: event.root },
126
- suppressLifecycles: true
127
- };
128
- case 'suppression-ended':
129
- return { ...state, suppressLifecycles: false };
130
- case 'refresh-finished':
131
- return { ...state, pendingUpdate: undefined };
132
- }
133
- }
134
- function refreshTaroRoot(root, page) {
135
- if (!root)
136
- return;
137
- root.ctx = page ?? null;
138
- root.updateChildNodes();
139
- root.performUpdate(true);
140
- }
141
- function relaunchActiveRoute(page) {
142
- const route = wxRuntimeGlobal.getCurrentPages().at(-1)?.route;
143
- if (!route)
144
- return;
145
- const query = Object.entries(page?.$taroParams ?? {})
146
- .filter(([key, value]) => key !== '$taroTimestamp' && value !== undefined)
147
- .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
148
- .join('&');
149
- runInNextNativeTask(() => wxRuntimeGlobal.wx.reLaunch({ url: `/${route}${query ? `?${query}` : ''}` }));
150
- }
151
- /**
152
- * DevTools dispatches synthetic page lifecycles after the changed module returns. A macrotask—not a microtask—runs
153
- * after that native turn and also avoids navigation or Taro root mutation from inside React Refresh's callback.
154
- */
155
- function runInNextNativeTask(task) {
156
- setTimeout(task);
157
- }
@@ -1,5 +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
- export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
4
- export { default as ReactDOM } from '@tarojs/react';
5
- export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime';
@@ -1,6 +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
- // @ts-expect-error Taro exposes createReactApp from this runtime-only deep entry without types.
4
- export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
5
- export { default as ReactDOM } from '@tarojs/react';
6
- export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime';
@@ -1,68 +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
- type WxUpdateClientState = {
9
- buildId: string;
10
- version: number;
11
- phase: WxUpdateClientPhase;
12
- targetVersion?: number;
13
- pendingBatch?: {
14
- fromVersion: number;
15
- targetVersion: number;
16
- };
17
- };
18
- export type WxUpdateClientEvent = {
19
- type: 'started';
20
- } | {
21
- type: 'registration-completed';
22
- } | {
23
- type: 'poll-completed';
24
- } | {
25
- type: 'batch-observed';
26
- buildId: string;
27
- fromVersion: number;
28
- targetVersion: number;
29
- } | {
30
- type: 'batch-executed';
31
- targetVersion: number;
32
- } | {
33
- type: 'batch-failed';
34
- } | {
35
- type: 'refresh-completed';
36
- stale: boolean;
37
- } | {
38
- type: 'route-ready';
39
- } | {
40
- type: 'transport-failed';
41
- };
42
- export type WxUpdateClientCommand = {
43
- type: 'register';
44
- version: number;
45
- } | {
46
- type: 'poll';
47
- version: number;
48
- } | {
49
- type: 'apply-batch';
50
- fromVersion: number;
51
- targetVersion: number;
52
- } | {
53
- type: 'report-version';
54
- version: number;
55
- reason: 'applied' | 'batch-mismatch';
56
- } | {
57
- type: 'request-full-build';
58
- reason: 'batch-execution-failed';
59
- } | {
60
- type: 'retry-transport';
61
- };
62
- type WxUpdateClientTransition = {
63
- state: WxUpdateClientState;
64
- commands: WxUpdateClientCommand[];
65
- };
66
- export declare function createWxUpdateClientState(buildId: string): WxUpdateClientState;
67
- export declare function transitionWxUpdateClient(state: WxUpdateClientState, event: WxUpdateClientEvent): WxUpdateClientTransition;
68
- export {};
@@ -1,84 +0,0 @@
1
- export function createWxUpdateClientState(buildId) {
2
- return { buildId, version: 0, phase: 'stopped' };
3
- }
4
- export function transitionWxUpdateClient(state, event) {
5
- switch (event.type) {
6
- case 'started':
7
- if (state.phase !== 'stopped')
8
- return transition(state);
9
- return command({ ...state, phase: 'registering' }, { type: 'register', version: state.version });
10
- case 'registration-completed': {
11
- if (state.phase !== 'registering')
12
- return transition(state);
13
- const pending = state.pendingBatch;
14
- if (!pending)
15
- return command({ ...state, phase: 'polling' }, { type: 'poll', version: state.version });
16
- return command({ ...state, phase: 'applying', targetVersion: pending.targetVersion, pendingBatch: undefined }, { type: 'apply-batch', ...pending });
17
- }
18
- case 'poll-completed':
19
- if (state.phase !== 'polling')
20
- return transition(state);
21
- return command(state, { type: 'poll', version: state.version });
22
- case 'batch-observed':
23
- return observeBatch(state, event);
24
- case 'batch-executed':
25
- if (state.phase !== 'applying' || state.targetVersion !== event.targetVersion) {
26
- return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' });
27
- }
28
- return transition({ ...state, phase: 'refreshing', version: event.targetVersion });
29
- case 'batch-failed':
30
- return command({ ...state, phase: 'polling', targetVersion: undefined }, { type: 'request-full-build', reason: 'batch-execution-failed' });
31
- case 'refresh-completed':
32
- if (state.phase !== 'refreshing')
33
- return transition(state);
34
- if (event.stale)
35
- return transition({ ...state, phase: 'relaunching' });
36
- return applied(state);
37
- case 'route-ready':
38
- if (state.phase !== 'relaunching')
39
- return transition(state);
40
- return applied(state);
41
- case 'transport-failed':
42
- return command(state, { type: 'retry-transport' });
43
- }
44
- }
45
- function observeBatch(state, batch) {
46
- const valid = batch.buildId === state.buildId &&
47
- Number.isInteger(batch.fromVersion) &&
48
- Number.isInteger(batch.targetVersion) &&
49
- batch.fromVersion >= 0 &&
50
- batch.targetVersion > batch.fromVersion;
51
- if (state.phase === 'registering') {
52
- if (!valid || batch.fromVersion !== state.version || batch.targetVersion <= state.version) {
53
- return transition(state);
54
- }
55
- return transition({
56
- ...state,
57
- pendingBatch: { fromVersion: batch.fromVersion, targetVersion: batch.targetVersion }
58
- });
59
- }
60
- if (!valid) {
61
- return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' });
62
- }
63
- if (batch.targetVersion <= state.version) {
64
- return command(state, { type: 'report-version', version: state.version, reason: 'applied' });
65
- }
66
- if (state.phase !== 'polling' || batch.fromVersion !== state.version) {
67
- return command(state, { type: 'report-version', version: state.version, reason: 'batch-mismatch' });
68
- }
69
- return command({ ...state, phase: 'applying', targetVersion: batch.targetVersion }, {
70
- type: 'apply-batch',
71
- fromVersion: batch.fromVersion,
72
- targetVersion: batch.targetVersion
73
- });
74
- }
75
- function applied(state) {
76
- const appliedState = { ...state, phase: 'polling', targetVersion: undefined };
77
- return command(appliedState, { type: 'report-version', version: state.version, reason: 'applied' });
78
- }
79
- function transition(state) {
80
- return { state, commands: [] };
81
- }
82
- function command(state, value) {
83
- return { state, commands: [value] };
84
- }
@@ -1 +0,0 @@
1
- export declare function startWxUpdateClient(): void;