@weapp-vite/web 1.3.36 → 1.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 (321) hide show
  1. package/README.md +144 -5
  2. package/dist/_virtual/_rolldown/runtime.mjs +19 -1
  3. package/dist/compiler/wxml/attributes.mjs +1 -1
  4. package/dist/compiler/wxml/attributes.mjs.map +1 -1
  5. package/dist/compiler/wxml/compile.mjs +6 -3
  6. package/dist/compiler/wxml/compile.mjs.map +1 -1
  7. package/dist/compiler/wxml/interpolation.mjs +1 -2
  8. package/dist/compiler/wxml/interpolation.mjs.map +1 -1
  9. package/dist/compiler/wxml/navigation.mjs +5 -7
  10. package/dist/compiler/wxml/navigation.mjs.map +1 -1
  11. package/dist/compiler/wxml/parser.mjs +5 -5
  12. package/dist/compiler/wxml/parser.mjs.map +1 -1
  13. package/dist/compiler/wxml/renderer.mjs +13 -12
  14. package/dist/compiler/wxml/renderer.mjs.map +1 -1
  15. package/dist/compiler/wxml/specialNodes.mjs +6 -1
  16. package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
  17. package/dist/compiler/wxml/types.d.mts +12 -0
  18. package/dist/compiler/wxs.mjs +5 -5
  19. package/dist/compiler/wxs.mjs.map +1 -1
  20. package/dist/css/wxss.d.mts +1 -0
  21. package/dist/css/wxss.mjs +110 -9
  22. package/dist/css/wxss.mjs.map +1 -1
  23. package/dist/index.d.mts +29 -6
  24. package/dist/index.mjs +197 -4
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/plugin/assets.d.mts +7 -0
  27. package/dist/plugin/assets.mjs +122 -0
  28. package/dist/plugin/assets.mjs.map +1 -0
  29. package/dist/plugin/constants.mjs +10 -1
  30. package/dist/plugin/constants.mjs.map +1 -1
  31. package/dist/plugin/dependencyScan.mjs +41 -0
  32. package/dist/plugin/dependencyScan.mjs.map +1 -0
  33. package/dist/plugin/entry.mjs +56 -7
  34. package/dist/plugin/entry.mjs.map +1 -1
  35. package/dist/plugin/files.mjs +1 -1
  36. package/dist/plugin/files.mjs.map +1 -1
  37. package/dist/plugin/index.d.mts +37 -3
  38. package/dist/plugin/index.mjs +245 -74
  39. package/dist/plugin/index.mjs.map +1 -1
  40. package/dist/plugin/layout.mjs +24 -0
  41. package/dist/plugin/layout.mjs.map +1 -0
  42. package/dist/plugin/path.mjs +4 -1
  43. package/dist/plugin/path.mjs.map +1 -1
  44. package/dist/plugin/register.mjs +48 -36
  45. package/dist/plugin/register.mjs.map +1 -1
  46. package/dist/plugin/scan.mjs +206 -94
  47. package/dist/plugin/scan.mjs.map +1 -1
  48. package/dist/plugin/scanSfc.mjs +65 -0
  49. package/dist/plugin/scanSfc.mjs.map +1 -0
  50. package/dist/plugin/state.mjs +3 -2
  51. package/dist/plugin/state.mjs.map +1 -1
  52. package/dist/plugin/styleModule.mjs +52 -0
  53. package/dist/plugin/styleModule.mjs.map +1 -0
  54. package/dist/plugin/types.d.mts +46 -1
  55. package/dist/plugin/vueSfc.mjs +149 -0
  56. package/dist/plugin/vueSfc.mjs.map +1 -0
  57. package/dist/runtime/appShell/container.mjs +25 -0
  58. package/dist/runtime/appShell/container.mjs.map +1 -0
  59. package/dist/runtime/appShell/tabBar/index.mjs +192 -0
  60. package/dist/runtime/appShell/tabBar/index.mjs.map +1 -0
  61. package/dist/runtime/appShell/tabBar/style.mjs +127 -0
  62. package/dist/runtime/appShell/tabBar/style.mjs.map +1 -0
  63. package/dist/runtime/button/helpers.mjs +1 -58
  64. package/dist/runtime/button/helpers.mjs.map +1 -1
  65. package/dist/runtime/button/index.d.mts +4 -5
  66. package/dist/runtime/button/index.mjs +6 -28
  67. package/dist/runtime/button/index.mjs.map +1 -1
  68. package/dist/runtime/button/style.mjs +53 -28
  69. package/dist/runtime/button/style.mjs.map +1 -1
  70. package/dist/runtime/component/behavior.mjs +26 -2
  71. package/dist/runtime/component/behavior.mjs.map +1 -1
  72. package/dist/runtime/component/element.mjs +107 -31
  73. package/dist/runtime/component/element.mjs.map +1 -1
  74. package/dist/runtime/component/observers.mjs +36 -0
  75. package/dist/runtime/component/observers.mjs.map +1 -0
  76. package/dist/runtime/component/publicInstance.mjs +48 -0
  77. package/dist/runtime/component/publicInstance.mjs.map +1 -0
  78. package/dist/runtime/component/relations.mjs +35 -0
  79. package/dist/runtime/component/relations.mjs.map +1 -0
  80. package/dist/runtime/component/slots.mjs +24 -0
  81. package/dist/runtime/component/slots.mjs.map +1 -0
  82. package/dist/runtime/component/state.mjs +13 -3
  83. package/dist/runtime/component/state.mjs.map +1 -1
  84. package/dist/runtime/component/types.d.mts +29 -4
  85. package/dist/runtime/component/virtualHost.mjs +83 -0
  86. package/dist/runtime/component/virtualHost.mjs.map +1 -0
  87. package/dist/runtime/host/index.d.mts +13 -0
  88. package/dist/runtime/host/index.mjs +47 -0
  89. package/dist/runtime/host/index.mjs.map +1 -0
  90. package/dist/runtime/host/types.d.mts +28 -0
  91. package/dist/runtime/hostGlobals.d.mts +9 -0
  92. package/dist/runtime/hostGlobals.mjs +39 -0
  93. package/dist/runtime/hostGlobals.mjs.map +1 -0
  94. package/dist/runtime/index.d.mts +21 -3
  95. package/dist/runtime/index.mjs +26 -4
  96. package/dist/runtime/index.mjs.map +1 -0
  97. package/dist/runtime/legacyTemplate/dom.mjs +3 -3
  98. package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
  99. package/dist/runtime/legacyTemplate/expression.mjs +9 -9
  100. package/dist/runtime/legacyTemplate/expression.mjs.map +1 -1
  101. package/dist/runtime/legacyTemplate/index.mjs +6 -6
  102. package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
  103. package/dist/runtime/nativeComponents/canvas/index.mjs +53 -0
  104. package/dist/runtime/nativeComponents/canvas/index.mjs.map +1 -0
  105. package/dist/runtime/nativeComponents/checkbox.mjs +137 -0
  106. package/dist/runtime/nativeComponents/checkbox.mjs.map +1 -0
  107. package/dist/runtime/nativeComponents/cover/index.mjs +23 -0
  108. package/dist/runtime/nativeComponents/cover/index.mjs.map +1 -0
  109. package/dist/runtime/nativeComponents/form.d.mts +7 -0
  110. package/dist/runtime/nativeComponents/form.mjs +50 -0
  111. package/dist/runtime/nativeComponents/form.mjs.map +1 -0
  112. package/dist/runtime/nativeComponents/formControl.mjs +61 -0
  113. package/dist/runtime/nativeComponents/formControl.mjs.map +1 -0
  114. package/dist/runtime/nativeComponents/helpers.mjs +25 -0
  115. package/dist/runtime/nativeComponents/helpers.mjs.map +1 -0
  116. package/dist/runtime/nativeComponents/icon/helpers.mjs +42 -0
  117. package/dist/runtime/nativeComponents/icon/helpers.mjs.map +1 -0
  118. package/dist/runtime/nativeComponents/icon/index.mjs +45 -0
  119. package/dist/runtime/nativeComponents/icon/index.mjs.map +1 -0
  120. package/dist/runtime/nativeComponents/icon/style.mjs +176 -0
  121. package/dist/runtime/nativeComponents/icon/style.mjs.map +1 -0
  122. package/dist/runtime/nativeComponents/image.d.mts +8 -0
  123. package/dist/runtime/nativeComponents/image.mjs +121 -0
  124. package/dist/runtime/nativeComponents/image.mjs.map +1 -0
  125. package/dist/runtime/nativeComponents/index.d.mts +11 -0
  126. package/dist/runtime/nativeComponents/index.mjs +83 -0
  127. package/dist/runtime/nativeComponents/index.mjs.map +1 -0
  128. package/dist/runtime/nativeComponents/input.d.mts +8 -0
  129. package/dist/runtime/nativeComponents/input.mjs +131 -0
  130. package/dist/runtime/nativeComponents/input.mjs.map +1 -0
  131. package/dist/runtime/nativeComponents/label.mjs +36 -0
  132. package/dist/runtime/nativeComponents/label.mjs.map +1 -0
  133. package/dist/runtime/nativeComponents/mediaRegistry.mjs +47 -0
  134. package/dist/runtime/nativeComponents/mediaRegistry.mjs.map +1 -0
  135. package/dist/runtime/nativeComponents/movable/helpers.mjs +23 -0
  136. package/dist/runtime/nativeComponents/movable/helpers.mjs.map +1 -0
  137. package/dist/runtime/nativeComponents/movable/index.mjs +117 -0
  138. package/dist/runtime/nativeComponents/movable/index.mjs.map +1 -0
  139. package/dist/runtime/nativeComponents/navigator.mjs +200 -0
  140. package/dist/runtime/nativeComponents/navigator.mjs.map +1 -0
  141. package/dist/runtime/nativeComponents/picker/editors.mjs +74 -0
  142. package/dist/runtime/nativeComponents/picker/editors.mjs.map +1 -0
  143. package/dist/runtime/nativeComponents/picker/helpers.mjs +57 -0
  144. package/dist/runtime/nativeComponents/picker/helpers.mjs.map +1 -0
  145. package/dist/runtime/nativeComponents/picker/index.mjs +210 -0
  146. package/dist/runtime/nativeComponents/picker/index.mjs.map +1 -0
  147. package/dist/runtime/nativeComponents/picker/style.mjs +71 -0
  148. package/dist/runtime/nativeComponents/picker/style.mjs.map +1 -0
  149. package/dist/runtime/nativeComponents/pickerView/column.mjs +134 -0
  150. package/dist/runtime/nativeComponents/pickerView/column.mjs.map +1 -0
  151. package/dist/runtime/nativeComponents/pickerView/helpers.mjs +17 -0
  152. package/dist/runtime/nativeComponents/pickerView/helpers.mjs.map +1 -0
  153. package/dist/runtime/nativeComponents/pickerView/index.mjs +128 -0
  154. package/dist/runtime/nativeComponents/pickerView/index.mjs.map +1 -0
  155. package/dist/runtime/nativeComponents/pickerView/style.mjs +58 -0
  156. package/dist/runtime/nativeComponents/pickerView/style.mjs.map +1 -0
  157. package/dist/runtime/nativeComponents/primitives.mjs +16 -0
  158. package/dist/runtime/nativeComponents/primitives.mjs.map +1 -0
  159. package/dist/runtime/nativeComponents/progress/helpers.mjs +29 -0
  160. package/dist/runtime/nativeComponents/progress/helpers.mjs.map +1 -0
  161. package/dist/runtime/nativeComponents/progress/index.mjs +130 -0
  162. package/dist/runtime/nativeComponents/progress/index.mjs.map +1 -0
  163. package/dist/runtime/nativeComponents/progress/style.mjs +40 -0
  164. package/dist/runtime/nativeComponents/progress/style.mjs.map +1 -0
  165. package/dist/runtime/nativeComponents/radio.mjs +147 -0
  166. package/dist/runtime/nativeComponents/radio.mjs.map +1 -0
  167. package/dist/runtime/nativeComponents/richText/helpers.mjs +230 -0
  168. package/dist/runtime/nativeComponents/richText/helpers.mjs.map +1 -0
  169. package/dist/runtime/nativeComponents/richText/index.mjs +74 -0
  170. package/dist/runtime/nativeComponents/richText/index.mjs.map +1 -0
  171. package/dist/runtime/nativeComponents/scrollView.d.mts +15 -0
  172. package/dist/runtime/nativeComponents/scrollView.mjs +79 -0
  173. package/dist/runtime/nativeComponents/scrollView.mjs.map +1 -0
  174. package/dist/runtime/nativeComponents/slider/helpers.mjs +28 -0
  175. package/dist/runtime/nativeComponents/slider/helpers.mjs.map +1 -0
  176. package/dist/runtime/nativeComponents/slider/index.mjs +120 -0
  177. package/dist/runtime/nativeComponents/slider/index.mjs.map +1 -0
  178. package/dist/runtime/nativeComponents/slider/style.mjs +60 -0
  179. package/dist/runtime/nativeComponents/slider/style.mjs.map +1 -0
  180. package/dist/runtime/nativeComponents/style.mjs +41 -0
  181. package/dist/runtime/nativeComponents/style.mjs.map +1 -0
  182. package/dist/runtime/nativeComponents/swiper/helpers.mjs +52 -0
  183. package/dist/runtime/nativeComponents/swiper/helpers.mjs.map +1 -0
  184. package/dist/runtime/nativeComponents/swiper/index.mjs +235 -0
  185. package/dist/runtime/nativeComponents/swiper/index.mjs.map +1 -0
  186. package/dist/runtime/nativeComponents/swiper/item.mjs +14 -0
  187. package/dist/runtime/nativeComponents/swiper/item.mjs.map +1 -0
  188. package/dist/runtime/nativeComponents/swiper/style.mjs +20 -0
  189. package/dist/runtime/nativeComponents/swiper/style.mjs.map +1 -0
  190. package/dist/runtime/nativeComponents/switch.d.mts +7 -0
  191. package/dist/runtime/nativeComponents/switch.mjs +132 -0
  192. package/dist/runtime/nativeComponents/switch.mjs.map +1 -0
  193. package/dist/runtime/nativeComponents/textarea.d.mts +9 -0
  194. package/dist/runtime/nativeComponents/textarea.mjs +144 -0
  195. package/dist/runtime/nativeComponents/textarea.mjs.map +1 -0
  196. package/dist/runtime/nativeComponents/video/helpers.d.mts +12 -0
  197. package/dist/runtime/nativeComponents/video/helpers.mjs +21 -0
  198. package/dist/runtime/nativeComponents/video/helpers.mjs.map +1 -0
  199. package/dist/runtime/nativeComponents/video/index.mjs +124 -0
  200. package/dist/runtime/nativeComponents/video/index.mjs.map +1 -0
  201. package/dist/runtime/nativeComponents/video/style.mjs +14 -0
  202. package/dist/runtime/nativeComponents/video/style.mjs.map +1 -0
  203. package/dist/runtime/navigationBar/index.mjs +1 -3
  204. package/dist/runtime/navigationBar/index.mjs.map +1 -1
  205. package/dist/runtime/pageLayout.d.mts +9 -0
  206. package/dist/runtime/pageLayout.mjs +16 -0
  207. package/dist/runtime/pageLayout.mjs.map +1 -0
  208. package/dist/runtime/polyfill/animation.mjs +120 -0
  209. package/dist/runtime/polyfill/animation.mjs.map +1 -0
  210. package/dist/runtime/polyfill/appState.mjs +1 -1
  211. package/dist/runtime/polyfill/appState.mjs.map +1 -1
  212. package/dist/runtime/polyfill/async.d.mts +7 -0
  213. package/dist/runtime/polyfill/async.mjs.map +1 -1
  214. package/dist/runtime/polyfill/canvasContext.mjs +41 -0
  215. package/dist/runtime/polyfill/canvasContext.mjs.map +1 -1
  216. package/dist/runtime/polyfill/device.mjs +1 -1
  217. package/dist/runtime/polyfill/device.mjs.map +1 -1
  218. package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +8 -2
  219. package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -1
  220. package/dist/runtime/polyfill/eventBus.mjs +56 -0
  221. package/dist/runtime/polyfill/eventBus.mjs.map +1 -0
  222. package/dist/runtime/polyfill/fileSystemManager.mjs +5 -2
  223. package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -1
  224. package/dist/runtime/polyfill/files.mjs +10 -10
  225. package/dist/runtime/polyfill/files.mjs.map +1 -1
  226. package/dist/runtime/polyfill/font.mjs +32 -0
  227. package/dist/runtime/polyfill/font.mjs.map +1 -0
  228. package/dist/runtime/polyfill/index.d.mts +2 -2
  229. package/dist/runtime/polyfill/index.mjs +49 -45
  230. package/dist/runtime/polyfill/index.mjs.map +1 -1
  231. package/dist/runtime/polyfill/interaction.mjs +7 -6
  232. package/dist/runtime/polyfill/interaction.mjs.map +1 -1
  233. package/dist/runtime/polyfill/interactionApi.mjs +3 -2
  234. package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
  235. package/dist/runtime/polyfill/intersectionObserver.mjs +106 -0
  236. package/dist/runtime/polyfill/intersectionObserver.mjs.map +1 -0
  237. package/dist/runtime/polyfill/locale.mjs +14 -0
  238. package/dist/runtime/polyfill/locale.mjs.map +1 -0
  239. package/dist/runtime/polyfill/locationApi.mjs +7 -4
  240. package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
  241. package/dist/runtime/polyfill/mediaActions.mjs +2 -2
  242. package/dist/runtime/polyfill/mediaActions.mjs.map +1 -1
  243. package/dist/runtime/polyfill/mediaApi/file.mjs +1 -1
  244. package/dist/runtime/polyfill/mediaApi/info.mjs +6 -4
  245. package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -1
  246. package/dist/runtime/polyfill/menuApi.mjs +38 -4
  247. package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
  248. package/dist/runtime/polyfill/navigationBarRuntime.mjs +6 -1
  249. package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -1
  250. package/dist/runtime/polyfill/network/request.mjs +2 -2
  251. package/dist/runtime/polyfill/network/request.mjs.map +1 -1
  252. package/dist/runtime/polyfill/platformApi.mjs +1 -1
  253. package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs +88 -0
  254. package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs.map +1 -0
  255. package/dist/runtime/polyfill/routeRuntime/dom.mjs +44 -15
  256. package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -1
  257. package/dist/runtime/polyfill/routeRuntime/history.d.mts +30 -0
  258. package/dist/runtime/polyfill/routeRuntime/history.mjs +148 -0
  259. package/dist/runtime/polyfill/routeRuntime/history.mjs.map +1 -0
  260. package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +39 -8
  261. package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -1
  262. package/dist/runtime/polyfill/routeRuntime/options.d.mts +11 -1
  263. package/dist/runtime/polyfill/routeRuntime/options.mjs +0 -1
  264. package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -1
  265. package/dist/runtime/polyfill/routeRuntime/result.mjs +12 -0
  266. package/dist/runtime/polyfill/routeRuntime/result.mjs.map +1 -0
  267. package/dist/runtime/polyfill/routeRuntime/scroll.mjs +39 -0
  268. package/dist/runtime/polyfill/routeRuntime/scroll.mjs.map +1 -0
  269. package/dist/runtime/polyfill/routeRuntime/stack.mjs +122 -0
  270. package/dist/runtime/polyfill/routeRuntime/stack.mjs.map +1 -0
  271. package/dist/runtime/polyfill/routeRuntime.d.mts +26 -17
  272. package/dist/runtime/polyfill/routeRuntime.mjs +121 -96
  273. package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
  274. package/dist/runtime/polyfill/runtimeDataApi.mjs +8 -3
  275. package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -1
  276. package/dist/runtime/polyfill/runtimeOps.mjs +10 -6
  277. package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -1
  278. package/dist/runtime/polyfill/selectorQuery.mjs +70 -14
  279. package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
  280. package/dist/runtime/polyfill/storage.mjs +5 -2
  281. package/dist/runtime/polyfill/storage.mjs.map +1 -1
  282. package/dist/runtime/polyfill/system.mjs +30 -3
  283. package/dist/runtime/polyfill/system.mjs.map +1 -1
  284. package/dist/runtime/polyfill/types/locationRuntime.d.mts +1 -4
  285. package/dist/runtime/polyfill/types/platformRuntime.d.mts +9 -0
  286. package/dist/runtime/polyfill/types/systemAuth.d.mts +20 -9
  287. package/dist/runtime/polyfill/types/tabBarRuntime.d.mts +25 -0
  288. package/dist/runtime/polyfill/ui.mjs +2 -6
  289. package/dist/runtime/polyfill/ui.mjs.map +1 -1
  290. package/dist/runtime/polyfill/uiMediaApi.d.mts +11 -10
  291. package/dist/runtime/polyfill/uiMediaApi.mjs +26 -2
  292. package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
  293. package/dist/runtime/polyfill/videoContext.mjs +4 -0
  294. package/dist/runtime/polyfill/videoContext.mjs.map +1 -1
  295. package/dist/runtime/polyfill/vkSession.mjs +4 -14
  296. package/dist/runtime/polyfill/vkSession.mjs.map +1 -1
  297. package/dist/runtime/polyfill.d.mts +2 -2
  298. package/dist/runtime/renderContext.mjs +1 -1
  299. package/dist/runtime/renderContext.mjs.map +1 -1
  300. package/dist/runtime/rpx.mjs +17 -8
  301. package/dist/runtime/rpx.mjs.map +1 -1
  302. package/dist/runtime/seo/index.d.mts +31 -0
  303. package/dist/runtime/seo/index.mjs +94 -0
  304. package/dist/runtime/seo/index.mjs.map +1 -0
  305. package/dist/runtime/viewport/index.d.mts +12 -0
  306. package/dist/runtime/viewport/index.mjs +44 -0
  307. package/dist/runtime/viewport/index.mjs.map +1 -0
  308. package/dist/runtime/viewport/style.mjs +62 -0
  309. package/dist/runtime/viewport/style.mjs.map +1 -0
  310. package/dist/runtime/viewport/types.d.mts +14 -0
  311. package/dist/runtime/wevu.d.mts +20 -0
  312. package/dist/runtime/wevu.mjs +73 -0
  313. package/dist/runtime/wevu.mjs.map +1 -0
  314. package/dist/shared/nativeComponents.mjs +401 -0
  315. package/dist/shared/nativeComponents.mjs.map +1 -0
  316. package/dist/shared/tabBar.d.mts +19 -0
  317. package/dist/shared/tabBar.mjs +37 -0
  318. package/dist/shared/tabBar.mjs.map +1 -0
  319. package/dist/shared/wxml.mjs +3 -20
  320. package/dist/shared/wxml.mjs.map +1 -1
  321. package/package.json +13 -5
@@ -1,44 +1,40 @@
1
- import { appendInlineQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from "./path.mjs";
1
+ import { STYLE_QUERY, TEMPLATE_QUERY } from "./constants.mjs";
2
+ import { appendQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from "./path.mjs";
2
3
  import { parse } from "@babel/parser";
3
4
  import _babelTraverse from "@babel/traverse";
4
5
  import * as t from "@babel/types";
5
6
  import MagicString from "magic-string";
6
7
 
7
8
  //#region src/plugin/register.ts
8
- const traverseCandidate = (() => {
9
- const mod = _babelTraverse;
9
+ function resolveBabelTraverse(mod) {
10
10
  if (typeof mod === "function") return mod;
11
11
  if (mod?.default && typeof mod.default === "function") return mod.default;
12
12
  if (mod?.traverse && typeof mod.traverse === "function") return mod.traverse;
13
- })();
14
- if (typeof traverseCandidate !== "function") throw new TypeError("[@weapp-vite/web] Failed to resolve @babel/traverse export.");
15
- const traverse = traverseCandidate;
16
- function mapRegisterIdentifier(kind) {
17
- if (kind === "page") return "Page";
18
- if (kind === "component") return "Component";
19
- if (kind === "app") return "App";
20
- return "";
13
+ throw new TypeError("[@weapp-vite/web] Failed to resolve @babel/traverse export.");
21
14
  }
22
- function getRegisterName(kind) {
23
- if (kind === "page") return "registerPage";
24
- if (kind === "component") return "registerComponent";
25
- if (kind === "app") return "registerApp";
15
+ const traverse = resolveBabelTraverse(_babelTraverse);
16
+ function getRegisterName(kind, callee) {
17
+ if (kind === "page" && (callee === "Page" || callee === "Component")) return "registerPage";
18
+ if (kind === "component" && callee === "Component") return "registerComponent";
19
+ if (kind === "app" && callee === "App") return "registerApp";
26
20
  }
27
- function overwriteCall(path, meta, registerName, templateIdent, styleIdent, s) {
28
- const node = path.node;
29
- const callee = node.callee;
30
- if (!t.isIdentifier(callee)) return;
31
- const insertPosition = node.end - 1;
21
+ function createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind = false) {
32
22
  const metaParts = [`id: ${JSON.stringify(meta.id)}`];
23
+ if (includeKind) metaParts.push(`kind: ${JSON.stringify(meta.kind)}`);
33
24
  if (templateIdent) metaParts.push(`template: ${templateIdent}`);
34
25
  if (styleIdent) metaParts.push(`style: ${styleIdent}`);
35
- const metaCode = `{ ${metaParts.join(", ")} }`;
36
- s.overwrite(callee.start, callee.end, registerName);
26
+ if (meta.navigationBar) metaParts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`);
27
+ return `{ ${metaParts.join(", ")} }`;
28
+ }
29
+ function overwriteCall(path, meta, registerName, templateIdent, styleIdent, s, includeKind = false) {
30
+ const node = path.node;
31
+ const identifier = node.callee;
32
+ const insertPosition = node.end - 1;
33
+ const metaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind);
34
+ s.overwrite(identifier.start, identifier.end, registerName);
37
35
  s.appendLeft(insertPosition, `, ${metaCode}`);
38
36
  }
39
- function transformScriptModule({ code, cleanId, meta, enableHmr }) {
40
- const registerName = getRegisterName(meta.kind);
41
- if (!registerName) return null;
37
+ function transformScriptModule({ code, cleanId, meta, enableHmr, runtimeModuleId, hmrAcceptCode }) {
42
38
  let ast;
43
39
  try {
44
40
  ast = parse(code, {
@@ -51,27 +47,43 @@ function transformScriptModule({ code, cleanId, meta, enableHmr }) {
51
47
  return null;
52
48
  }
53
49
  const s = new MagicString(code);
54
- let transformed = false;
50
+ const wevuDefineComponentNames = /* @__PURE__ */ new Set();
51
+ for (const statement of ast.program.body) {
52
+ if (!t.isImportDeclaration(statement) || statement.source.value !== "wevu") continue;
53
+ for (const specifier of statement.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, { name: "defineComponent" })) wevuDefineComponentNames.add(specifier.local.name);
54
+ }
55
55
  const imports = [];
56
- const runtimePolyfillId = toViteFsImport(resolveRuntimePolyfillPath());
56
+ const runtimePolyfillId = runtimeModuleId ?? toViteFsImport(resolveRuntimePolyfillPath());
57
57
  const templateIdent = meta.templatePath ? "__weapp_template__" : void 0;
58
58
  const styleIdent = meta.stylePath ? "__weapp_style__" : void 0;
59
- if (meta.templatePath && templateIdent) imports.push(`import ${templateIdent} from '${toRelativeImport(cleanId, meta.templatePath)}'`);
60
- if (meta.stylePath && styleIdent) imports.push(`import ${styleIdent} from '${appendInlineQuery(toRelativeImport(cleanId, meta.stylePath))}'`);
59
+ if (meta.templatePath && templateIdent) imports.push(`import ${templateIdent} from '${appendQuery(toRelativeImport(cleanId, meta.templatePath), TEMPLATE_QUERY)}'`);
60
+ if (meta.stylePath && styleIdent) {
61
+ const styleQuery = meta.stylePath.endsWith(".wxss") ? STYLE_QUERY : "inline";
62
+ imports.push(`import ${styleIdent} from '${appendQuery(toRelativeImport(cleanId, meta.stylePath), styleQuery)}'`);
63
+ }
61
64
  const registerImports = /* @__PURE__ */ new Set();
62
65
  traverse(ast, { CallExpression(path) {
63
66
  if (!t.isIdentifier(path.node.callee)) return;
64
- if (path.node.callee.name === mapRegisterIdentifier(meta.kind)) {
67
+ const name = path.node.callee.name;
68
+ if (wevuDefineComponentNames.has(name) && meta.kind !== "app") {
69
+ registerImports.add("registerWebWevuComponent");
70
+ overwriteCall(path, meta, "registerWebWevuComponent", templateIdent, styleIdent, s, true);
71
+ return;
72
+ }
73
+ const registerName = getRegisterName(meta.kind, name);
74
+ if (registerName) {
65
75
  registerImports.add(registerName);
66
76
  overwriteCall(path, meta, registerName, templateIdent, styleIdent, s);
67
- transformed = true;
68
77
  }
69
78
  } });
70
- if (!transformed) return null;
71
- if (registerImports.size > 0) imports.unshift(`import { ${Array.from(registerImports).join(", ")} } from '${runtimePolyfillId}'`);
72
- const prefix = `${imports.join("\n")}\n`;
79
+ registerImports.add("installWebModuleRegistration");
80
+ imports.unshift(`import { ${Array.from(registerImports).join(", ")} } from '${runtimePolyfillId}'`);
81
+ const moduleMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, true);
82
+ const restoreIdent = "__weapp_web_restore_registration__";
83
+ const prefix = `${imports.join("\n")}\nconst ${restoreIdent} = installWebModuleRegistration(${moduleMetaCode})\n`;
73
84
  s.prepend(prefix);
74
- if (enableHmr) s.append(`\nif (import.meta.hot) { import.meta.hot.accept() }\n`);
85
+ s.append(`\n${restoreIdent}()\n`);
86
+ if (enableHmr && hmrAcceptCode) s.append(`\n${hmrAcceptCode}\n`);
75
87
  return {
76
88
  code: s.toString(),
77
89
  map: s.generateMap({ hires: true })
@@ -79,5 +91,5 @@ function transformScriptModule({ code, cleanId, meta, enableHmr }) {
79
91
  }
80
92
 
81
93
  //#endregion
82
- export { transformScriptModule };
94
+ export { resolveBabelTraverse, transformScriptModule };
83
95
  //# sourceMappingURL=register.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport { appendInlineQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from './path'\n\ntype TraverseFunction = typeof _babelTraverse extends (...args: any[]) => any\n ? typeof _babelTraverse\n : typeof _babelTraverse extends { default: infer D }\n ? D\n : typeof _babelTraverse\n\nconst traverseCandidate: any = (() => {\n const mod: any = _babelTraverse\n if (typeof mod === 'function') {\n return mod\n }\n if (mod?.default && typeof mod.default === 'function') {\n return mod.default\n }\n if (mod?.traverse && typeof mod.traverse === 'function') {\n return mod.traverse\n }\n return undefined\n})()\n\nif (typeof traverseCandidate !== 'function') {\n throw new TypeError('[@weapp-vite/web] Failed to resolve @babel/traverse export.')\n}\n\nconst traverse: TraverseFunction = traverseCandidate\n\nfunction mapRegisterIdentifier(kind: ModuleMeta['kind']) {\n if (kind === 'page') {\n return 'Page'\n }\n if (kind === 'component') {\n return 'Component'\n }\n if (kind === 'app') {\n return 'App'\n }\n return ''\n}\n\nfunction getRegisterName(kind: ModuleMeta['kind']) {\n if (kind === 'page') {\n return 'registerPage'\n }\n if (kind === 'component') {\n return 'registerComponent'\n }\n if (kind === 'app') {\n return 'registerApp'\n }\n return undefined\n}\n\nfunction overwriteCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n registerName: string,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n) {\n const node = path.node\n const callee = node.callee\n if (!t.isIdentifier(callee)) {\n return\n }\n const end = node.end!\n const insertPosition = end - 1\n const metaParts: string[] = [`id: ${JSON.stringify(meta.id)}`]\n if (templateIdent) {\n metaParts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n metaParts.push(`style: ${styleIdent}`)\n }\n const metaCode = `{ ${metaParts.join(', ')} }`\n s.overwrite(callee.start!, callee.end!, registerName)\n s.appendLeft(insertPosition, `, ${metaCode}`)\n}\n\ninterface TransformScriptModuleOptions {\n code: string\n cleanId: string\n meta: ModuleMeta\n enableHmr: boolean\n}\n\nexport function transformScriptModule({\n code,\n cleanId,\n meta,\n enableHmr,\n}: TransformScriptModuleOptions): null | { code: string, map: SourceMap } {\n const registerName = getRegisterName(meta.kind)\n if (!registerName) {\n return null\n }\n\n let ast: ReturnType<typeof parse> | undefined\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n ranges: true,\n })\n }\n catch {\n return null\n }\n\n const s = new MagicString(code)\n let transformed = false\n\n const imports: string[] = []\n const runtimePolyfillId = toViteFsImport(resolveRuntimePolyfillPath())\n const templateIdent = meta.templatePath ? '__weapp_template__' : undefined\n const styleIdent = meta.stylePath ? '__weapp_style__' : undefined\n\n if (meta.templatePath && templateIdent) {\n imports.push(`import ${templateIdent} from '${toRelativeImport(cleanId, meta.templatePath)}'`)\n }\n\n if (meta.stylePath && styleIdent) {\n imports.push(`import ${styleIdent} from '${appendInlineQuery(toRelativeImport(cleanId, meta.stylePath))}'`)\n }\n\n const registerImports = new Set<string>()\n\n traverse(ast, {\n CallExpression(path: NodePath<CallExpression>) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n const name = path.node.callee.name\n if (name === mapRegisterIdentifier(meta.kind)) {\n registerImports.add(registerName)\n overwriteCall(path, meta, registerName, templateIdent, styleIdent, s)\n transformed = true\n }\n },\n })\n\n if (!transformed) {\n return null\n }\n\n if (registerImports.size > 0) {\n imports.unshift(`import { ${Array.from(registerImports).join(', ')} } from '${runtimePolyfillId}'`)\n }\n\n const prefix = `${imports.join('\\n')}\\n`\n s.prepend(prefix)\n\n if (enableHmr) {\n s.append(`\\nif (import.meta.hot) { import.meta.hot.accept() }\\n`)\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({\n hires: true,\n }),\n }\n}\n"],"mappings":";;;;;;;AAkBA,MAAM,2BAAgC;CACpC,MAAM,MAAW;CACjB,IAAI,OAAO,QAAQ,YACjB,OAAO;CAET,IAAI,KAAK,WAAW,OAAO,IAAI,YAAY,YACzC,OAAO,IAAI;CAEb,IAAI,KAAK,YAAY,OAAO,IAAI,aAAa,YAC3C,OAAO,IAAI;AAGf,EAAC,CAAE;AAEH,IAAI,OAAO,sBAAsB,YAC/B,MAAM,IAAI,UAAU,6DAA6D;AAGnF,MAAM,WAA6B;AAEnC,SAAS,sBAAsB,MAA0B;CACvD,IAAI,SAAS,QACX,OAAO;CAET,IAAI,SAAS,aACX,OAAO;CAET,IAAI,SAAS,OACX,OAAO;CAET,OAAO;AACT;AAEA,SAAS,gBAAgB,MAA0B;CACjD,IAAI,SAAS,QACX,OAAO;CAET,IAAI,SAAS,aACX,OAAO;CAET,IAAI,SAAS,OACX,OAAO;AAGX;AAEA,SAAS,cACP,MACA,MACA,cACA,eACA,YACA,GACA;CACA,MAAM,OAAO,KAAK;CAClB,MAAM,SAAS,KAAK;CACpB,IAAI,CAAC,EAAE,aAAa,MAAM,GACxB;CAGF,MAAM,iBADM,KAAK,MACY;CAC7B,MAAM,YAAsB,CAAC,OAAO,KAAK,UAAU,KAAK,EAAE,GAAG;CAC7D,IAAI,eACF,UAAU,KAAK,aAAa,eAAe;CAE7C,IAAI,YACF,UAAU,KAAK,UAAU,YAAY;CAEvC,MAAM,WAAW,KAAK,UAAU,KAAK,IAAI,EAAE;CAC3C,EAAE,UAAU,OAAO,OAAQ,OAAO,KAAM,YAAY;CACpD,EAAE,WAAW,gBAAgB,KAAK,UAAU;AA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EAAE,OAAO,uDAAuD;CAGlE,OAAO;EACL,MAAM,EAAE,SAAS;EACjB,KAAK,EAAE,YAAY,EACjB,OAAO,KACT,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport { STYLE_QUERY, TEMPLATE_QUERY } from './constants'\nimport { appendQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from './path'\n\ntype TraverseFunction = typeof _babelTraverse extends (...args: any[]) => any\n ? typeof _babelTraverse\n : typeof _babelTraverse extends { default: infer D }\n ? D\n : typeof _babelTraverse\n\nexport function resolveBabelTraverse(mod: any): TraverseFunction {\n if (typeof mod === 'function') {\n return mod\n }\n if (mod?.default && typeof mod.default === 'function') {\n return mod.default\n }\n if (mod?.traverse && typeof mod.traverse === 'function') {\n return mod.traverse\n }\n throw new TypeError('[@weapp-vite/web] Failed to resolve @babel/traverse export.')\n}\n\nconst traverse = resolveBabelTraverse(_babelTraverse)\n\nfunction getRegisterName(kind: ModuleMeta['kind'], callee: string) {\n if (kind === 'page' && (callee === 'Page' || callee === 'Component')) {\n return 'registerPage'\n }\n if (kind === 'component' && callee === 'Component') {\n return 'registerComponent'\n }\n if (kind === 'app' && callee === 'App') {\n return 'registerApp'\n }\n return undefined\n}\n\nfunction createRegisterMetaCode(\n meta: ModuleMeta,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n includeKind = false,\n) {\n const metaParts: string[] = [`id: ${JSON.stringify(meta.id)}`]\n if (includeKind) {\n metaParts.push(`kind: ${JSON.stringify(meta.kind)}`)\n }\n if (templateIdent) {\n metaParts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n metaParts.push(`style: ${styleIdent}`)\n }\n if (meta.navigationBar) {\n metaParts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`)\n }\n return `{ ${metaParts.join(', ')} }`\n}\n\nfunction overwriteCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n registerName: string,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n includeKind = false,\n) {\n const node = path.node\n const callee = node.callee\n const identifier = callee as t.Identifier\n const end = node.end!\n const insertPosition = end - 1\n const metaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind)\n s.overwrite(identifier.start!, identifier.end!, registerName)\n s.appendLeft(insertPosition, `, ${metaCode}`)\n}\n\ninterface TransformScriptModuleOptions {\n code: string\n cleanId: string\n meta: ModuleMeta\n enableHmr: boolean\n runtimeModuleId?: string\n hmrAcceptCode?: string\n}\n\nexport function transformScriptModule({\n code,\n cleanId,\n meta,\n enableHmr,\n runtimeModuleId,\n hmrAcceptCode,\n}: TransformScriptModuleOptions): null | { code: string, map: SourceMap } {\n let ast: ReturnType<typeof parse> | undefined\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n ranges: true,\n })\n }\n catch {\n return null\n }\n\n const s = new MagicString(code)\n const wevuDefineComponentNames = new Set<string>()\n for (const statement of ast.program.body) {\n if (!t.isImportDeclaration(statement) || statement.source.value !== 'wevu') {\n continue\n }\n for (const specifier of statement.specifiers) {\n if (t.isImportSpecifier(specifier)\n && t.isIdentifier(specifier.imported, { name: 'defineComponent' })) {\n wevuDefineComponentNames.add(specifier.local.name)\n }\n }\n }\n\n const imports: string[] = []\n const runtimePolyfillId = runtimeModuleId ?? toViteFsImport(resolveRuntimePolyfillPath())\n const templateIdent = meta.templatePath ? '__weapp_template__' : undefined\n const styleIdent = meta.stylePath ? '__weapp_style__' : undefined\n\n if (meta.templatePath && templateIdent) {\n imports.push(`import ${templateIdent} from '${appendQuery(toRelativeImport(cleanId, meta.templatePath), TEMPLATE_QUERY)}'`)\n }\n\n if (meta.stylePath && styleIdent) {\n const styleQuery = meta.stylePath.endsWith('.wxss') ? STYLE_QUERY : 'inline'\n imports.push(`import ${styleIdent} from '${appendQuery(toRelativeImport(cleanId, meta.stylePath), styleQuery)}'`)\n }\n\n const registerImports = new Set<string>()\n\n traverse(ast, {\n CallExpression(path: NodePath<CallExpression>) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n const name = path.node.callee.name\n if (wevuDefineComponentNames.has(name) && meta.kind !== 'app') {\n registerImports.add('registerWebWevuComponent')\n overwriteCall(path, meta, 'registerWebWevuComponent', templateIdent, styleIdent, s, true)\n return\n }\n const registerName = getRegisterName(meta.kind, name)\n if (registerName) {\n registerImports.add(registerName)\n overwriteCall(path, meta, registerName, templateIdent, styleIdent, s)\n }\n },\n })\n\n registerImports.add('installWebModuleRegistration')\n imports.unshift(`import { ${Array.from(registerImports).join(', ')} } from '${runtimePolyfillId}'`)\n\n const moduleMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, true)\n const restoreIdent = '__weapp_web_restore_registration__'\n const prefix = `${imports.join('\\n')}\\nconst ${restoreIdent} = installWebModuleRegistration(${moduleMetaCode})\\n`\n s.prepend(prefix)\n\n s.append(`\\n${restoreIdent}()\\n`)\n\n if (enableHmr && hmrAcceptCode) {\n s.append(`\\n${hmrAcceptCode}\\n`)\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({\n hires: true,\n }),\n }\n}\n"],"mappings":";;;;;;;;AAmBA,SAAgB,qBAAqB,KAA4B;CAC/D,IAAI,OAAO,QAAQ,YACjB,OAAO;CAET,IAAI,KAAK,WAAW,OAAO,IAAI,YAAY,YACzC,OAAO,IAAI;CAEb,IAAI,KAAK,YAAY,OAAO,IAAI,aAAa,YAC3C,OAAO,IAAI;CAEb,MAAM,IAAI,UAAU,6DAA6D;AACnF;AAEA,MAAM,WAAW,qBAAqB,cAAc;AAEpD,SAAS,gBAAgB,MAA0B,QAAgB;CACjE,IA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ACnF,MAAM,eAAe;CACrB,MAAM,SAAS,GAAG,QAAQ,KAAK,IAAI,EAAE,UAAU,aAAa,kCAAkC,eAAe;CAC7G,EAAE,QAAQ,MAAM;CAEhB,EAAE,OAAO,KAAK,aAAa,KAAK;CAEhC,IAAI,aAAa,eACf,EAAE,OAAO,KAAK,cAAc,GAAG;CAGjC,OAAO;EACL,MAAM,EAAE,SAAS;EACjB,KAAK,EAAE,YAAY,EACjB,OAAO,KACT,CAAC;CACH;AACF"}
@@ -1,77 +1,135 @@
1
- import { normalizePath, toPosixId } from "./path.mjs";
1
+ import { SCRIPT_EXTS } from "./constants.mjs";
2
+ import { isInsideDir, normalizePath, toPosixId } from "./path.mjs";
2
3
  import { slugify } from "../shared/slugify.mjs";
4
+ import { normalizeWebTabBarConfig } from "../shared/tabBar.mjs";
3
5
  import { isRecord, readJsonFile, resolveJsonPath, resolveScriptFile, resolveStyleFile, resolveTemplateFile } from "./files.mjs";
4
6
  import { mergeNavigationConfig, pickNavigationConfig } from "./navigation.mjs";
5
7
  import { collectComponentTagsFromConfig, collectComponentTagsFromJson, mergeComponentTags } from "./scanConfig.mjs";
8
+ import { compileScannedSfc, discoverWebPageIds } from "./scanSfc.mjs";
9
+ import { readdir } from "node:fs/promises";
6
10
  import process from "node:process";
7
11
  import { dirname, extname, join, posix, relative, resolve } from "pathe";
8
12
 
9
13
  //#region src/plugin/scan.ts
10
- async function scanProject({ srcRoot, warn, state }) {
14
+ function getStableWebComponentId(script, srcRoot) {
15
+ const normalized = script.replace(/\\/g, "/");
16
+ const nodeModulesIndex = normalized.lastIndexOf("/node_modules/");
17
+ const extension = extname(script);
18
+ if (nodeModulesIndex >= 0) return `__external__/${normalized.slice(nodeModulesIndex + 14).slice(0, -extension.length)}`;
19
+ return toPosixId(relative(srcRoot, script).slice(0, -extension.length));
20
+ }
21
+ function resolveComponentBase(raw, importerDir, srcRoot) {
22
+ if (!raw) return;
23
+ if (raw.startsWith(".")) return resolve(importerDir, raw);
24
+ if (raw.startsWith("/")) return resolve(srcRoot, raw.slice(1));
25
+ }
26
+ async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportTag, resolveAppConfig, uniApp }) {
11
27
  state.moduleMeta.clear();
12
28
  state.pageNavigationMap.clear();
13
29
  state.templateComponentMap.clear();
14
30
  state.templatePathSet.clear();
15
31
  state.componentTagMap.clear();
16
- state.componentIdMap.clear();
32
+ state.sfcResults.clear();
17
33
  let appNavigationDefaults = {};
18
34
  let appComponentTags = {};
35
+ let appTabBar;
19
36
  const pages = /* @__PURE__ */ new Map();
20
37
  const components = /* @__PURE__ */ new Map();
38
+ const layouts = /* @__PURE__ */ new Map();
39
+ async function walk(current, files) {
40
+ const entries = await readdir(current, { withFileTypes: true });
41
+ for (const entry of entries) {
42
+ const pathname = join(current, entry.name);
43
+ if (entry.isDirectory()) await walk(pathname, files);
44
+ else files.push(pathname);
45
+ }
46
+ }
21
47
  const reportWarning = (message) => {
22
48
  if (warn) {
23
49
  warn(message);
24
50
  return;
25
51
  }
26
- if (typeof process !== "undefined" && typeof process.emitWarning === "function") process.emitWarning(message);
52
+ process.emitWarning(message);
27
53
  };
28
54
  const appScript = await resolveScriptFile(join(srcRoot, "app"));
29
- if (appScript) state.moduleMeta.set(normalizePath(appScript), {
30
- kind: "app",
31
- id: "app",
32
- scriptPath: appScript,
33
- stylePath: await resolveStyleFile(appScript)
34
- });
55
+ if (appScript) {
56
+ const appMeta = {
57
+ kind: "app",
58
+ id: "app",
59
+ scriptPath: appScript,
60
+ stylePath: await resolveStyleFile(appScript),
61
+ sourceType: appScript.endsWith(".vue") ? "vue-sfc" : "native"
62
+ };
63
+ state.moduleMeta.set(normalizePath(appScript), appMeta);
64
+ }
35
65
  const resolveComponentScript = async (raw, importerDir) => {
36
66
  const base = resolveComponentBase(raw, importerDir, srcRoot);
37
- if (!base) return;
38
- return resolveScriptFile(base);
67
+ if (base) {
68
+ const resolved = await resolveScriptFile(base);
69
+ return resolved ? normalizePath(resolved) : void 0;
70
+ }
71
+ const importer = join(importerDir, "__weapp_web_using_components__.ts");
72
+ const resolved = await resolveId?.(raw, importer);
73
+ const script = resolved ? await resolveScriptFile(resolved) : void 0;
74
+ return script ? normalizePath(script) : void 0;
39
75
  };
40
- const getComponentId = (script) => {
41
- const cached = state.componentIdMap.get(script);
42
- if (cached) return cached;
43
- const componentIdPosix = toPosixId(relative(srcRoot, script).replace(new RegExp(`${extname(script)}$`), ""));
44
- state.componentIdMap.set(script, componentIdPosix);
45
- return componentIdPosix;
76
+ const getStableComponentId = (script) => {
77
+ return getStableWebComponentId(script, srcRoot);
46
78
  };
47
79
  const getComponentTag = (script) => {
48
80
  const cached = state.componentTagMap.get(script);
49
81
  if (cached) return cached;
50
- const tag = slugify(getComponentId(script), "wv-component");
82
+ const tag = slugify(getStableComponentId(script), "wv-component");
51
83
  state.componentTagMap.set(script, tag);
52
84
  return tag;
53
85
  };
54
86
  const collectComponent = async (componentId, importerDir) => {
55
- const base = resolveComponentBase(componentId, importerDir, srcRoot);
56
- const script = base ? await resolveScriptFile(base) : void 0;
57
- if (!script || components.has(script)) return;
58
- const componentIdPosix = toPosixId(relative(srcRoot, script).replace(new RegExp(`${extname(script)}$`), ""));
87
+ const script = await resolveComponentScript(componentId, importerDir);
88
+ if (!script) return;
89
+ const existing = components.get(script);
90
+ if (existing) {
91
+ existing.importId ??= resolveComponentBase(componentId, importerDir, srcRoot) ? void 0 : componentId;
92
+ return;
93
+ }
94
+ const componentIdPosix = getStableComponentId(script);
95
+ const importId = resolveComponentBase(componentId, importerDir, srcRoot) ? isInsideDir(script, srcRoot) ? void 0 : componentIdPosix : componentId;
59
96
  const template = await resolveTemplateFile(script);
60
97
  const style = await resolveStyleFile(script);
61
98
  if (template) state.templatePathSet.add(normalizePath(template));
62
- state.moduleMeta.set(normalizePath(script), {
99
+ const componentMeta = {
63
100
  kind: "component",
64
101
  id: componentIdPosix,
65
102
  scriptPath: script,
66
103
  templatePath: template,
67
- stylePath: style
68
- });
104
+ stylePath: style,
105
+ sourceType: script.endsWith(".vue") ? "vue-sfc" : "native"
106
+ };
107
+ state.moduleMeta.set(normalizePath(script), componentMeta);
69
108
  components.set(script, {
70
109
  script,
71
- id: componentIdPosix
110
+ id: componentIdPosix,
111
+ importId
72
112
  });
73
- const componentTags = await collectComponentTagsFromJson({
74
- jsonBasePath: `${script.replace(new RegExp(`${extname(script)}$`), "")}.json`,
113
+ const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), "")}.json`;
114
+ const sfcConfig = script.endsWith(".vue") ? (await compileScannedSfc({
115
+ filename: script,
116
+ meta: componentMeta,
117
+ srcRoot,
118
+ state,
119
+ resolveId,
120
+ resolveAutoImportTag,
121
+ uniApp
122
+ })).config : void 0;
123
+ const componentTags = sfcConfig ? await collectComponentTagsFromConfig({
124
+ json: sfcConfig,
125
+ importerDir: dirname(script),
126
+ jsonPath: script,
127
+ warn: reportWarning,
128
+ resolveComponentScript,
129
+ getComponentTag,
130
+ collectComponent
131
+ }) : await collectComponentTagsFromJson({
132
+ jsonBasePath: componentJsonBasePath,
75
133
  importerDir: dirname(script),
76
134
  warn: reportWarning,
77
135
  collectFromConfig: (json, nextImporterDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({
@@ -84,6 +142,7 @@ async function scanProject({ srcRoot, warn, state }) {
84
142
  collectComponent
85
143
  })
86
144
  });
145
+ componentMeta.componentTags = mergeComponentTags(appComponentTags, componentTags);
87
146
  if (!template) return;
88
147
  const mergedTags = mergeComponentTags(appComponentTags, componentTags);
89
148
  if (Object.keys(mergedTags).length > 0) {
@@ -92,41 +151,6 @@ async function scanProject({ srcRoot, warn, state }) {
92
151
  }
93
152
  state.templateComponentMap.delete(normalizePath(template));
94
153
  };
95
- const appJsonPath = await resolveJsonPath(join(srcRoot, "app.json"));
96
- if (appJsonPath) {
97
- const appJson = await readJsonFile(appJsonPath);
98
- if (appJson) appComponentTags = await collectComponentTagsFromConfig({
99
- json: appJson,
100
- importerDir: srcRoot,
101
- jsonPath: appJsonPath,
102
- warn: reportWarning,
103
- resolveComponentScript,
104
- getComponentTag,
105
- collectComponent,
106
- onResolved: (tags) => {
107
- appComponentTags = tags;
108
- }
109
- });
110
- if (appJson?.pages && Array.isArray(appJson.pages)) {
111
- for (const page of appJson.pages) if (typeof page === "string") await collectPage(page);
112
- }
113
- if (appJson?.subPackages && Array.isArray(appJson.subPackages)) for (const pkg of appJson.subPackages) {
114
- if (!pkg || typeof pkg !== "object" || !Array.isArray(pkg.pages)) continue;
115
- const root = typeof pkg.root === "string" ? pkg.root : "";
116
- for (const page of pkg.pages) {
117
- if (typeof page !== "string") continue;
118
- await collectPage(posix.join(root, page));
119
- }
120
- }
121
- appNavigationDefaults = pickNavigationConfig(isRecord(appJson?.window) ? appJson.window : void 0);
122
- }
123
- state.appNavigationDefaults = appNavigationDefaults;
124
- state.appComponentTags = appComponentTags;
125
- state.scanResult = {
126
- app: appScript,
127
- pages: Array.from(pages.values()),
128
- components: Array.from(components.values())
129
- };
130
154
  async function collectPage(pageId) {
131
155
  const base = join(srcRoot, pageId);
132
156
  const script = await resolveScriptFile(base);
@@ -134,62 +158,150 @@ async function scanProject({ srcRoot, warn, state }) {
134
158
  const template = await resolveTemplateFile(base);
135
159
  if (template) state.templatePathSet.add(normalizePath(template));
136
160
  const style = await resolveStyleFile(base);
137
- const pageJsonBasePath = join(srcRoot, `${pageId}.json`);
138
- const pageJsonPath = await resolveJsonPath(pageJsonBasePath);
161
+ const pageJsonPath = await resolveJsonPath(join(srcRoot, `${pageId}.json`));
139
162
  const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : void 0;
140
- state.moduleMeta.set(normalizePath(script), {
163
+ const pageMeta = {
141
164
  kind: "page",
142
165
  id: toPosixId(pageId),
143
166
  scriptPath: script,
144
167
  templatePath: template,
145
- stylePath: style
146
- });
168
+ stylePath: style,
169
+ sourceType: script.endsWith(".vue") ? "vue-sfc" : "native"
170
+ };
171
+ const sfcConfig = script.endsWith(".vue") ? (await compileScannedSfc({
172
+ filename: script,
173
+ meta: pageMeta,
174
+ srcRoot,
175
+ state,
176
+ resolveId,
177
+ resolveAutoImportTag,
178
+ uniApp
179
+ })).config : void 0;
180
+ const resolvedNavigationConfig = mergeNavigationConfig(appNavigationDefaults, sfcConfig ? pickNavigationConfig(sfcConfig) : pageJson ? pickNavigationConfig(pageJson) : {});
181
+ pageMeta.navigationBar = Object.keys(resolvedNavigationConfig).length > 0 ? resolvedNavigationConfig : void 0;
182
+ state.moduleMeta.set(normalizePath(script), pageMeta);
147
183
  pages.set(script, {
148
184
  script,
149
185
  id: toPosixId(pageId)
150
186
  });
151
- const pageComponentTags = pageJson && pageJsonPath ? await collectComponentTagsFromConfig({
152
- json: pageJson,
187
+ const pageComponentTags = sfcConfig ? await collectComponentTagsFromConfig({
188
+ json: sfcConfig,
153
189
  importerDir: dirname(script),
154
- jsonPath: pageJsonPath,
190
+ jsonPath: script,
155
191
  warn: reportWarning,
156
192
  resolveComponentScript,
157
193
  getComponentTag,
158
194
  collectComponent
159
- }) : await collectComponentTagsFromJson({
160
- jsonBasePath: pageJsonBasePath,
195
+ }) : pageJson && pageJsonPath ? await collectComponentTagsFromConfig({
196
+ json: pageJson,
161
197
  importerDir: dirname(script),
198
+ jsonPath: pageJsonPath,
162
199
  warn: reportWarning,
163
- collectFromConfig: (json, importerDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({
164
- json,
165
- importerDir,
166
- jsonPath,
167
- warn: nextWarn,
168
- resolveComponentScript,
169
- getComponentTag,
170
- collectComponent
171
- })
172
- });
200
+ resolveComponentScript,
201
+ getComponentTag,
202
+ collectComponent
203
+ }) : {};
173
204
  if (template) {
174
205
  const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags);
175
206
  if (Object.keys(mergedTags).length > 0) state.templateComponentMap.set(normalizePath(template), mergedTags);
176
207
  else state.templateComponentMap.delete(normalizePath(template));
177
208
  }
209
+ pageMeta.componentTags = mergeComponentTags(appComponentTags, pageComponentTags);
178
210
  if (!template) return;
179
- if (pageJson) {
180
- state.pageNavigationMap.set(normalizePath(template), mergeNavigationConfig(appNavigationDefaults, pickNavigationConfig(pageJson)));
211
+ state.pageNavigationMap.set(normalizePath(template), resolvedNavigationConfig);
212
+ }
213
+ async function collectLayouts() {
214
+ const layoutsRoot = join(srcRoot, "layouts");
215
+ const files = [];
216
+ try {
217
+ await walk(layoutsRoot, files);
218
+ } catch {
181
219
  return;
182
220
  }
183
- state.pageNavigationMap.set(normalizePath(template), { ...appNavigationDefaults });
221
+ for (const filename of files.sort()) {
222
+ const script = SCRIPT_EXTS.includes(extname(filename)) ? filename : void 0;
223
+ if (!script) continue;
224
+ const segments = relative(layoutsRoot, script).replace(/\\/g, "/").split("/");
225
+ segments.pop();
226
+ if (segments[segments.length - 1] === "index") segments.pop();
227
+ const name = segments.join("/");
228
+ if (!name) continue;
229
+ const id = `layouts/${name}`;
230
+ const template = await resolveTemplateFile(script);
231
+ const style = await resolveStyleFile(script);
232
+ const tag = slugify(id, "wv-component");
233
+ state.moduleMeta.set(normalizePath(script), {
234
+ kind: "component",
235
+ id,
236
+ scriptPath: script,
237
+ templatePath: template,
238
+ stylePath: style,
239
+ sourceType: "native"
240
+ });
241
+ layouts.set(script, {
242
+ script,
243
+ id,
244
+ name,
245
+ tag,
246
+ template,
247
+ style
248
+ });
249
+ if (template) state.templatePathSet.add(normalizePath(template));
250
+ }
184
251
  }
185
- }
186
- function resolveComponentBase(raw, importerDir, srcRoot) {
187
- if (!raw) return;
188
- if (raw.startsWith(".")) return resolve(importerDir, raw);
189
- if (raw.startsWith("/")) return resolve(srcRoot, raw.slice(1));
190
- return resolve(srcRoot, raw);
252
+ const appJsonPath = await resolveJsonPath(join(srcRoot, "app.json"));
253
+ let appJson = appJsonPath ? await (resolveAppConfig ? resolveAppConfig(appJsonPath) : readJsonFile(appJsonPath)) : void 0;
254
+ if (appScript?.endsWith(".vue")) appJson = {
255
+ ...(await compileScannedSfc({
256
+ filename: appScript,
257
+ meta: state.moduleMeta.get(normalizePath(appScript)),
258
+ srcRoot,
259
+ state,
260
+ resolveId,
261
+ resolveAutoImportTag,
262
+ uniApp
263
+ })).config ?? {},
264
+ ...appJson ?? {}
265
+ };
266
+ if (appJson) {
267
+ appComponentTags = await collectComponentTagsFromConfig({
268
+ json: appJson,
269
+ importerDir: srcRoot,
270
+ jsonPath: appJsonPath ?? appScript,
271
+ warn: reportWarning,
272
+ resolveComponentScript,
273
+ getComponentTag,
274
+ collectComponent,
275
+ onResolved: (tags) => {
276
+ appComponentTags = tags;
277
+ }
278
+ });
279
+ appNavigationDefaults = pickNavigationConfig(isRecord(appJson?.window) ? appJson.window : void 0);
280
+ const configuredPages = Array.isArray(appJson.pages) ? appJson.pages.filter((page) => typeof page === "string") : [];
281
+ for (const page of configuredPages.length > 0 ? configuredPages : await discoverWebPageIds(srcRoot)) await collectPage(page);
282
+ const subPackages = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
283
+ if (subPackages.length > 0) for (const pkg of subPackages) {
284
+ if (!pkg || typeof pkg !== "object" || !Array.isArray(pkg.pages)) continue;
285
+ const root = typeof pkg.root === "string" ? pkg.root : "";
286
+ for (const page of pkg.pages) {
287
+ if (typeof page !== "string") continue;
288
+ await collectPage(posix.join(root, page));
289
+ }
290
+ }
291
+ appTabBar = normalizeWebTabBarConfig(appJson?.tabBar);
292
+ } else for (const page of await discoverWebPageIds(srcRoot)) await collectPage(page);
293
+ await collectLayouts();
294
+ state.appNavigationDefaults = appNavigationDefaults;
295
+ state.appComponentTags = appComponentTags;
296
+ state.scanResult = {
297
+ app: appScript,
298
+ pages: Array.from(pages.values()),
299
+ components: Array.from(components.values()),
300
+ layouts: Array.from(layouts.values()),
301
+ tabBar: appTabBar
302
+ };
191
303
  }
192
304
 
193
305
  //#endregion
194
- export { scanProject };
306
+ export { getStableWebComponentId, scanProject };
195
307
  //# sourceMappingURL=scan.mjs.map