@nativescript/vite 0.0.1-alpha.7 → 0.0.2

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 (265) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +44 -0
  3. package/{dist/configuration → configuration}/angular.d.ts +1 -1
  4. package/configuration/angular.js +480 -0
  5. package/configuration/angular.js.map +1 -0
  6. package/configuration/base.d.ts +5 -0
  7. package/configuration/base.js +494 -0
  8. package/configuration/base.js.map +1 -0
  9. package/configuration/javascript.d.ts +4 -0
  10. package/configuration/javascript.js +151 -0
  11. package/configuration/javascript.js.map +1 -0
  12. package/{dist/configuration → configuration}/react.d.ts +1 -1
  13. package/{dist/configuration → configuration}/react.js +18 -17
  14. package/configuration/react.js.map +1 -0
  15. package/{dist/configuration → configuration}/solid.d.ts +1 -1
  16. package/{dist/configuration → configuration}/solid.js +17 -16
  17. package/configuration/solid.js.map +1 -0
  18. package/configuration/typescript.d.ts +4 -0
  19. package/configuration/typescript.js +175 -0
  20. package/configuration/typescript.js.map +1 -0
  21. package/{dist/configuration → configuration}/vue.d.ts +1 -1
  22. package/configuration/vue.js +163 -0
  23. package/configuration/vue.js.map +1 -0
  24. package/helpers/angular-linker.d.ts +13 -0
  25. package/helpers/angular-linker.js +181 -0
  26. package/helpers/angular-linker.js.map +1 -0
  27. package/helpers/cli-flags.d.ts +1 -0
  28. package/helpers/cli-flags.js +15 -0
  29. package/helpers/cli-flags.js.map +1 -0
  30. package/{dist/helpers → helpers}/commonjs-plugins.js +14 -13
  31. package/helpers/commonjs-plugins.js.map +1 -0
  32. package/{dist/helpers → helpers}/config-as-json.d.ts +1 -1
  33. package/{dist/helpers → helpers}/config-as-json.js +7 -6
  34. package/helpers/config-as-json.js.map +1 -0
  35. package/helpers/css-platform-plugin.d.ts +10 -0
  36. package/helpers/css-platform-plugin.js +76 -0
  37. package/helpers/css-platform-plugin.js.map +1 -0
  38. package/helpers/css-tree.js +22 -0
  39. package/helpers/css-tree.js.map +1 -0
  40. package/{dist/helpers → helpers}/dynamic-import-plugin.js +8 -7
  41. package/helpers/dynamic-import-plugin.js.map +1 -0
  42. package/helpers/esbuild-platform-resolver.d.ts +14 -0
  43. package/helpers/esbuild-platform-resolver.js +93 -0
  44. package/helpers/esbuild-platform-resolver.js.map +1 -0
  45. package/{dist/helpers → helpers}/external-configs.js +2 -1
  46. package/helpers/external-configs.js.map +1 -0
  47. package/{dist/helpers → helpers}/flavor.d.ts +1 -0
  48. package/helpers/flavor.js +51 -0
  49. package/helpers/flavor.js.map +1 -0
  50. package/{dist/helpers → helpers}/global-defines.d.ts +11 -3
  51. package/helpers/global-defines.js +24 -0
  52. package/helpers/global-defines.js.map +1 -0
  53. package/helpers/logging.d.ts +13 -0
  54. package/helpers/logging.js +111 -0
  55. package/helpers/logging.js.map +1 -0
  56. package/helpers/main-entry.d.ts +10 -0
  57. package/helpers/main-entry.js +215 -0
  58. package/helpers/main-entry.js.map +1 -0
  59. package/{dist/helpers → helpers}/module-resolution.js +4 -3
  60. package/helpers/module-resolution.js.map +1 -0
  61. package/{dist/helpers → helpers}/module-runner-patch.d.ts +1 -1
  62. package/{dist/helpers → helpers}/module-runner-patch.js +10 -12
  63. package/helpers/module-runner-patch.js.map +1 -0
  64. package/helpers/nativeclass-transform.d.ts +7 -0
  65. package/helpers/nativeclass-transform.js +158 -0
  66. package/helpers/nativeclass-transform.js.map +1 -0
  67. package/helpers/nativeclass-transformer-plugin.d.ts +5 -0
  68. package/helpers/nativeclass-transformer-plugin.js +23 -0
  69. package/helpers/nativeclass-transformer-plugin.js.map +1 -0
  70. package/{dist/helpers → helpers}/nativescript-package-resolver.js +18 -17
  71. package/helpers/nativescript-package-resolver.js.map +1 -0
  72. package/{dist/helpers → helpers}/ns-cli-plugins.d.ts +6 -1
  73. package/{dist/helpers → helpers}/ns-cli-plugins.js +31 -51
  74. package/helpers/ns-cli-plugins.js.map +1 -0
  75. package/helpers/package-platform-aliases.d.ts +10 -0
  76. package/{dist/helpers → helpers}/package-platform-aliases.js +18 -22
  77. package/helpers/package-platform-aliases.js.map +1 -0
  78. package/helpers/postcss-platform-config.d.ts +13 -0
  79. package/helpers/postcss-platform-config.js +97 -0
  80. package/helpers/postcss-platform-config.js.map +1 -0
  81. package/helpers/prelink-angular.d.ts +2 -0
  82. package/helpers/prelink-angular.js +117 -0
  83. package/helpers/prelink-angular.js.map +1 -0
  84. package/helpers/preserve-imports.js +38 -0
  85. package/helpers/preserve-imports.js.map +1 -0
  86. package/{dist/helpers → helpers}/project.js +2 -4
  87. package/helpers/project.js.map +1 -0
  88. package/helpers/resolver.d.ts +4 -0
  89. package/{dist/helpers → helpers}/resolver.js +7 -6
  90. package/helpers/resolver.js.map +1 -0
  91. package/helpers/theme-core-plugins.d.ts +14 -0
  92. package/helpers/theme-core-plugins.js +121 -0
  93. package/helpers/theme-core-plugins.js.map +1 -0
  94. package/helpers/ts-config-paths.d.ts +10 -0
  95. package/{dist/helpers → helpers}/ts-config-paths.js +70 -71
  96. package/helpers/ts-config-paths.js.map +1 -0
  97. package/{dist/helpers → helpers}/utils.js +14 -27
  98. package/helpers/utils.js.map +1 -0
  99. package/{dist/helpers → helpers}/workers.js +15 -16
  100. package/helpers/workers.js.map +1 -0
  101. package/{dist/hmr → hmr/client}/css-handler.js +18 -17
  102. package/hmr/client/css-handler.js.map +1 -0
  103. package/hmr/client/index.d.ts +13 -0
  104. package/hmr/client/index.js +1550 -0
  105. package/hmr/client/index.js.map +1 -0
  106. package/hmr/client/utils.d.ts +38 -0
  107. package/hmr/client/utils.js +426 -0
  108. package/hmr/client/utils.js.map +1 -0
  109. package/hmr/entry-runtime.d.ts +8 -0
  110. package/hmr/entry-runtime.js +135 -0
  111. package/hmr/entry-runtime.js.map +1 -0
  112. package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
  113. package/hmr/frameworks/angular/server/strategy.js +101 -0
  114. package/hmr/frameworks/angular/server/strategy.js.map +1 -0
  115. package/hmr/frameworks/vue/client/index.d.ts +22 -0
  116. package/hmr/frameworks/vue/client/index.js +1537 -0
  117. package/hmr/frameworks/vue/client/index.js.map +1 -0
  118. package/hmr/frameworks/vue/server/compiler.d.ts +11 -0
  119. package/hmr/frameworks/vue/server/compiler.js +26 -0
  120. package/hmr/frameworks/vue/server/compiler.js.map +1 -0
  121. package/hmr/frameworks/vue/server/sfc-transforms.d.ts +14 -0
  122. package/hmr/frameworks/vue/server/sfc-transforms.js +282 -0
  123. package/hmr/frameworks/vue/server/sfc-transforms.js.map +1 -0
  124. package/hmr/frameworks/vue/server/strategy.d.ts +2 -0
  125. package/hmr/frameworks/vue/server/strategy.js +273 -0
  126. package/hmr/frameworks/vue/server/strategy.js.map +1 -0
  127. package/hmr/helpers/ast-extract.d.ts +6 -0
  128. package/hmr/helpers/ast-extract.js +72 -0
  129. package/hmr/helpers/ast-extract.js.map +1 -0
  130. package/hmr/helpers/ast-normalizer.d.ts +7 -0
  131. package/hmr/helpers/ast-normalizer.js +772 -0
  132. package/hmr/helpers/ast-normalizer.js.map +1 -0
  133. package/hmr/helpers/babel.d.ts +3 -0
  134. package/hmr/helpers/babel.js +17 -0
  135. package/hmr/helpers/babel.js.map +1 -0
  136. package/hmr/helpers/sanitize.d.ts +6 -0
  137. package/hmr/helpers/sanitize.js +55 -0
  138. package/hmr/helpers/sanitize.js.map +1 -0
  139. package/hmr/helpers/vendor-rewrite.d.ts +1 -0
  140. package/hmr/helpers/vendor-rewrite.js +35 -0
  141. package/hmr/helpers/vendor-rewrite.js.map +1 -0
  142. package/hmr/server/compiler.d.ts +2 -0
  143. package/hmr/server/compiler.js +75 -0
  144. package/hmr/server/compiler.js.map +1 -0
  145. package/hmr/server/constants.d.ts +14 -0
  146. package/hmr/server/constants.js +23 -0
  147. package/hmr/server/constants.js.map +1 -0
  148. package/hmr/server/core-sanitize.d.ts +32 -0
  149. package/hmr/server/core-sanitize.js +134 -0
  150. package/hmr/server/core-sanitize.js.map +1 -0
  151. package/hmr/server/framework-strategy.d.ts +68 -0
  152. package/hmr/server/framework-strategy.js +2 -0
  153. package/hmr/server/framework-strategy.js.map +1 -0
  154. package/hmr/server/index.d.ts +5 -0
  155. package/hmr/server/index.js +19 -0
  156. package/hmr/server/index.js.map +1 -0
  157. package/hmr/server/vite-plugin.d.ts +5 -0
  158. package/{dist/hmr/plugins/plugin-vue.js → hmr/server/vite-plugin.js} +13 -15
  159. package/hmr/server/vite-plugin.js.map +1 -0
  160. package/hmr/server/websocket.d.ts +15 -0
  161. package/hmr/server/websocket.js +5528 -0
  162. package/hmr/server/websocket.js.map +1 -0
  163. package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
  164. package/hmr/shared/runtime/http-only-boot.js +107 -0
  165. package/hmr/shared/runtime/http-only-boot.js.map +1 -0
  166. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  167. package/hmr/shared/runtime/root-placeholder.js +142 -0
  168. package/hmr/shared/runtime/root-placeholder.js.map +1 -0
  169. package/hmr/shared/runtime/vendor-bootstrap.d.ts +1 -0
  170. package/hmr/shared/runtime/vendor-bootstrap.js +134 -0
  171. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -0
  172. package/hmr/shared/vendor/manifest-loader.d.ts +9 -0
  173. package/hmr/shared/vendor/manifest-loader.js +38 -0
  174. package/hmr/shared/vendor/manifest-loader.js.map +1 -0
  175. package/hmr/shared/vendor/manifest.d.ts +34 -0
  176. package/hmr/shared/vendor/manifest.js +787 -0
  177. package/hmr/shared/vendor/manifest.js.map +1 -0
  178. package/hmr/shared/vendor/registry.d.ts +9 -0
  179. package/hmr/shared/vendor/registry.js +62 -0
  180. package/hmr/shared/vendor/registry.js.map +1 -0
  181. package/hmr/vendor-bootstrap.d.ts +3 -0
  182. package/hmr/vendor-bootstrap.js +32 -0
  183. package/hmr/vendor-bootstrap.js.map +1 -0
  184. package/{dist/index.d.ts → index.d.ts} +2 -0
  185. package/{dist/index.js → index.js} +3 -0
  186. package/index.js.map +1 -0
  187. package/package.json +39 -31
  188. package/{dist/polyfills → polyfills}/mdn-data-at-rules.js +1 -0
  189. package/polyfills/mdn-data-at-rules.js.map +1 -0
  190. package/{dist/polyfills → polyfills}/mdn-data-properties.js +1 -0
  191. package/polyfills/mdn-data-properties.js.map +1 -0
  192. package/{dist/polyfills → polyfills}/mdn-data-syntaxes.js +1 -0
  193. package/polyfills/mdn-data-syntaxes.js.map +1 -0
  194. package/{dist/polyfills → polyfills}/module.js +1 -0
  195. package/polyfills/module.js.map +1 -0
  196. package/runtime/core-aliases-early.d.ts +1 -0
  197. package/runtime/core-aliases-early.js +334 -0
  198. package/runtime/core-aliases-early.js.map +1 -0
  199. package/shims/angular-animations-stub.d.ts +8 -0
  200. package/shims/angular-animations-stub.js +14 -0
  201. package/shims/angular-animations-stub.js.map +1 -0
  202. package/{dist/shims → shims}/node-module.js +3 -2
  203. package/shims/node-module.js.map +1 -0
  204. package/{dist/shims → shims}/react-reconciler-constants.js +2 -1
  205. package/shims/react-reconciler-constants.js.map +1 -0
  206. package/{dist/shims → shims}/react-reconciler.js +1 -0
  207. package/shims/react-reconciler.js.map +1 -0
  208. package/{dist/shims → shims}/set-value.js +5 -1
  209. package/shims/set-value.js.map +1 -0
  210. package/transformers/NativeClass/index.d.ts +2 -0
  211. package/transformers/NativeClass/index.js +222 -0
  212. package/transformers/NativeClass/index.js.map +1 -0
  213. package/dist/configuration/angular.js +0 -30
  214. package/dist/configuration/base.d.ts +0 -4
  215. package/dist/configuration/base.js +0 -386
  216. package/dist/configuration/vue.js +0 -45
  217. package/dist/helpers/css-tree.js +0 -21
  218. package/dist/helpers/flavor.js +0 -40
  219. package/dist/helpers/global-defines.js +0 -20
  220. package/dist/helpers/main-entry-hmr-includes.d.ts +0 -1
  221. package/dist/helpers/main-entry-hmr-includes.js +0 -18
  222. package/dist/helpers/main-entry.d.ts +0 -5
  223. package/dist/helpers/main-entry.js +0 -82
  224. package/dist/helpers/package-platform-aliases.d.ts +0 -4
  225. package/dist/helpers/preserve-imports.js +0 -19
  226. package/dist/helpers/resolver.d.ts +0 -4
  227. package/dist/helpers/ts-config-paths.d.ts +0 -4
  228. package/dist/hmr/client-vue.d.ts +0 -6
  229. package/dist/hmr/client-vue.js +0 -585
  230. package/dist/hmr/component-tracker.d.ts +0 -23
  231. package/dist/hmr/component-tracker.js +0 -193
  232. package/dist/hmr/message-handler.d.ts +0 -1
  233. package/dist/hmr/message-handler.js +0 -590
  234. package/dist/hmr/nsv-hooks.d.ts +0 -2
  235. package/dist/hmr/nsv-hooks.js +0 -481
  236. package/dist/hmr/plugins/index.d.ts +0 -1
  237. package/dist/hmr/plugins/index.js +0 -16
  238. package/dist/hmr/plugins/plugin-vue.d.ts +0 -2
  239. package/dist/hmr/plugins/websocket-vue.d.ts +0 -2
  240. package/dist/hmr/plugins/websocket-vue.js +0 -911
  241. package/dist/hmr/runtime-vue.d.ts +0 -13
  242. package/dist/hmr/runtime-vue.js +0 -2306
  243. package/dist/hmr/types.d.ts +0 -24
  244. package/dist/hmr/types.js +0 -2
  245. package/dist/transformers/NativeClass/index.d.ts +0 -5
  246. package/dist/transformers/NativeClass/index.js +0 -46
  247. /package/{dist/helpers → helpers}/commonjs-plugins.d.ts +0 -0
  248. /package/{dist/helpers → helpers}/css-tree.d.ts +0 -0
  249. /package/{dist/helpers → helpers}/dynamic-import-plugin.d.ts +0 -0
  250. /package/{dist/helpers → helpers}/external-configs.d.ts +0 -0
  251. /package/{dist/helpers → helpers}/module-resolution.d.ts +0 -0
  252. /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
  253. /package/{dist/helpers → helpers}/preserve-imports.d.ts +0 -0
  254. /package/{dist/helpers → helpers}/project.d.ts +0 -0
  255. /package/{dist/helpers → helpers}/utils.d.ts +0 -0
  256. /package/{dist/helpers → helpers}/workers.d.ts +0 -0
  257. /package/{dist/hmr → hmr/client}/css-handler.d.ts +0 -0
  258. /package/{dist/polyfills → polyfills}/mdn-data-at-rules.d.ts +0 -0
  259. /package/{dist/polyfills → polyfills}/mdn-data-properties.d.ts +0 -0
  260. /package/{dist/polyfills → polyfills}/mdn-data-syntaxes.d.ts +0 -0
  261. /package/{dist/polyfills → polyfills}/module.d.ts +0 -0
  262. /package/{dist/shims → shims}/node-module.d.ts +0 -0
  263. /package/{dist/shims → shims}/react-reconciler-constants.d.ts +0 -0
  264. /package/{dist/shims → shims}/react-reconciler.d.ts +0 -0
  265. /package/{dist/shims → shims}/set-value.d.ts +0 -0
@@ -1,6 +0,0 @@
1
- export declare function initHmrClient(opts?: {
2
- wsUrl?: string;
3
- }): void;
4
- export default function startViteHMR(opts?: {
5
- wsUrl?: string;
6
- }): void;
@@ -1,585 +0,0 @@
1
- import { knownFolders, File, Page, Application, Label, Folder, Frame, } from "@nativescript/core";
2
- import { NSVRoot, createVNode, createApp, resolveComponent, createBlock, createTextVNode, createElementVNode, createElementBlock, ref, computed, onMounted, onUnmounted, $navigateTo, $navigateBack, } from "nativescript-vue";
3
- // Import the core Vue functions for the ones not wrapped
4
- import { openBlock, withCtx, renderList, renderSlot, toDisplayString, createCommentVNode, Fragment, unref } from "@vue/runtime-core";
5
- // Wire in standard Vite 'update' handling (CSS etc.)
6
- import { handleCssUpdates } from "./css-handler";
7
- // Simple, robust HMR client for NativeScript + Vue 3.
8
- // Single-path behavior: always rebuild a fresh Page with the updated component and
9
- // replace the current root using appRoot.resetRoot. No Vue runtime HMR reload/rerender.
10
- const VERBOSE = !!globalThis.__NS_ENV_VERBOSE__;
11
- const DEDUP_WINDOW_MS = 250;
12
- let hmrSocket = null;
13
- let hmrWsUrl = undefined;
14
- const recentHmr = new Map();
15
- let httpOriginForVite;
16
- function deriveHttpOrigin(wsUrl) {
17
- try {
18
- const url = new URL(wsUrl || "ws://10.0.2.2:5173/ns-hmr");
19
- const http = url.protocol === "wss:" ? "https:" : "http:";
20
- return `${http}//${url.host}`;
21
- }
22
- catch {
23
- return "http://10.0.2.2:5173";
24
- }
25
- }
26
- function connectHmr() {
27
- if (hmrSocket?.readyState === WebSocket.OPEN)
28
- return;
29
- if (hmrSocket?.readyState === WebSocket.CONNECTING) {
30
- if (VERBOSE)
31
- console.log("[hmr-client-vue] Already connecting to HMR WebSocket, skipping");
32
- return;
33
- }
34
- try {
35
- const wsUrl = hmrWsUrl || "ws://10.0.2.2:5173/ns-hmr";
36
- if (VERBOSE)
37
- console.log("[hmr-client-vue] Connecting to HMR WebSocket:", wsUrl);
38
- hmrSocket = new WebSocket(wsUrl);
39
- hmrSocket.onopen = () => VERBOSE && console.log("[hmr-client-vue] Connected to HMR WebSocket");
40
- hmrSocket.onmessage = handleHmrMessage;
41
- hmrSocket.onerror = (error) => console.warn("[hmr-client-vue] WebSocket error:", error);
42
- hmrSocket.onclose = () => {
43
- if (VERBOSE)
44
- console.log("[hmr-client-vue] WebSocket closed, will reconnect...");
45
- setTimeout(connectHmr, 1000);
46
- };
47
- httpOriginForVite = deriveHttpOrigin(wsUrl);
48
- }
49
- catch (e) {
50
- console.warn("[hmr-client-vue] Failed to connect WebSocket:", e?.message);
51
- setTimeout(connectHmr, 2000);
52
- }
53
- }
54
- async function handleHmrMessage(ev) {
55
- let msg;
56
- try {
57
- msg = JSON.parse(ev.data);
58
- }
59
- catch {
60
- return;
61
- }
62
- if (VERBOSE)
63
- console.log("[hmr-client-vue] msg", msg);
64
- // Single-socket CSS updates from plugin
65
- if (msg.type === "ns:css-updates" && Array.isArray(msg.updates)) {
66
- try {
67
- const origin = msg.origin || httpOriginForVite || deriveHttpOrigin(hmrWsUrl);
68
- await handleCssUpdates(msg.updates, origin);
69
- }
70
- catch (e) {
71
- console.warn("[hmr-client-vue] CSS updates handling failed:", e);
72
- }
73
- return;
74
- }
75
- // Handle SFC registry bootstrap
76
- if (msg.type === "ns:vue-sfc-registry") {
77
- try {
78
- await installSfcRegistry(msg.entries || []);
79
- }
80
- catch (e) {
81
- console.warn("[hmr-client-vue] Failed installing SFC registry:", e);
82
- }
83
- return;
84
- }
85
- // Handle individual SFC registry updates
86
- if (msg.type === "ns:vue-sfc-registry-update") {
87
- try {
88
- await updateSfcModule(msg.fileName, msg.code);
89
- }
90
- catch (e) {
91
- console.warn("[hmr-client-vue] Failed updating SFC module:", e);
92
- }
93
- return;
94
- }
95
- if (msg.type !== "ns:vue-dynamic-module") {
96
- if (VERBOSE)
97
- console.log(`[hmr-client-vue] Ignoring message type: ${msg.type}`);
98
- return;
99
- }
100
- const key = msg.moduleId || msg.hmrId || msg.id || JSON.stringify(msg);
101
- const now = Date.now();
102
- const last = recentHmr.get(key) || 0;
103
- if (now - last < DEDUP_WINDOW_MS) {
104
- if (VERBOSE)
105
- console.log("[hmr-client-vue] Skipping duplicate dynamic-module within window:", key);
106
- return;
107
- }
108
- recentHmr.set(key, now);
109
- handleDynamicModule(msg);
110
- }
111
- async function handleDynamicModule(msg) {
112
- try {
113
- let moduleContent = msg.moduleCode;
114
- if (!moduleContent) {
115
- console.warn("[hmr-client-vue] No moduleCode in dynamic module message");
116
- return;
117
- }
118
- if (VERBOSE)
119
- console.log("[hmr-client-vue] Using moduleCode from message", {
120
- id: msg.id,
121
- hmrId: msg.hmrId,
122
- moduleId: msg.moduleId,
123
- bytes: moduleContent.length,
124
- });
125
- const newComponent = await importModuleFromContent(moduleContent, msg);
126
- if (!newComponent) {
127
- console.warn("[hmr-client-vue] Failed to load new component");
128
- return;
129
- }
130
- // Component debug: full keys and selected internals
131
- try {
132
- const describe = (c) => ({
133
- typeof: typeof c,
134
- keys: Object.keys(c || {}),
135
- __name: c?.__name,
136
- __file: c?.__file,
137
- __hmrId: c?.__hmrId,
138
- hasRender: !!c?.render,
139
- hasSetup: !!c?.setup,
140
- isFunction: typeof c === "function",
141
- });
142
- if (VERBOSE)
143
- console.log("[hmr-client-vue] Got new component (describe):", describe(newComponent));
144
- }
145
- catch { }
146
- // Single-path HMR: always replace current root with a pre-mounted Page
147
- await performResetRoot(newComponent);
148
- return;
149
- }
150
- catch (error) {
151
- console.error("[hmr-client-vue] Failed to handle dynamic module:", error);
152
- }
153
- }
154
- async function importModuleFromContent(content, msg) {
155
- try {
156
- // CRITICAL: Set up proper Vue runtime functions globally BEFORE importing the component
157
- // The generated component relies on these being available as globals
158
- // Define global references to required Vue functions for HMR chunks
159
- globalThis._resolveComponent = resolveComponent;
160
- globalThis._openBlock = openBlock;
161
- globalThis._createBlock = createBlock;
162
- globalThis._withCtx = withCtx;
163
- globalThis._createVNode = createVNode;
164
- globalThis._createTextVNode = createTextVNode;
165
- globalThis._createElementVNode = createElementVNode || createVNode;
166
- globalThis._createElementBlock = createElementBlock || createBlock;
167
- // Additional helpers (underscore + plain) used by compiled templates
168
- globalThis._renderList = globalThis._renderList || renderList;
169
- globalThis._renderSlot = globalThis._renderSlot || renderSlot;
170
- globalThis._toDisplayString = globalThis._toDisplayString || toDisplayString;
171
- globalThis._createCommentVNode = globalThis._createCommentVNode || createCommentVNode;
172
- globalThis._Fragment = globalThis._Fragment || Fragment;
173
- globalThis.renderList = globalThis.renderList || renderList;
174
- globalThis.renderSlot = globalThis.renderSlot || renderSlot;
175
- globalThis.toDisplayString = globalThis.toDisplayString || toDisplayString;
176
- globalThis.createCommentVNode = globalThis.createCommentVNode || createCommentVNode;
177
- globalThis.Fragment = globalThis.Fragment || Fragment;
178
- // Provide normalizeClass/normalizeStyle fallbacks (no-ops if not present)
179
- if (!globalThis.normalizeClass) {
180
- globalThis.normalizeClass = (v) => v;
181
- }
182
- if (!globalThis.normalizeStyle) {
183
- globalThis.normalizeStyle = (v) => v;
184
- }
185
- // Provide unref using ref utilities if not already available (avoid direct import to limit surface)
186
- if (!globalThis.unref) {
187
- globalThis.unref = unref || ((r) => (r && typeof r === 'object' && 'value' in r ? r.value : r));
188
- }
189
- // Set up Vue reactivity functions - CRITICAL for reactive bindings
190
- globalThis.ref = ref;
191
- globalThis.computed = computed;
192
- globalThis.onMounted = onMounted;
193
- globalThis.onUnmounted = onUnmounted;
194
- // Add navigation functions
195
- globalThis.$navigateTo = $navigateTo;
196
- // Wrap $navigateBack to gracefully handle missing Frame after HMR reset
197
- if (!globalThis.__NS_HMR_BACK_WRAPPED__) {
198
- const originalBack = $navigateBack;
199
- globalThis.__NS_HMR_BACK_WRAPPED__ = true;
200
- globalThis.$navigateBack = (...args) => {
201
- try {
202
- const top = Frame.topmost?.();
203
- if (top && top.canGoBack?.()) {
204
- return originalBack(...args);
205
- }
206
- }
207
- catch (e) {
208
- // fall through to fallback
209
- }
210
- // Fallback: reset to original root component if available
211
- const orig = globalThis.__NS_HMR_ORIG_ROOT_COMPONENT__;
212
- if (orig) {
213
- try {
214
- const app = createApp(orig);
215
- const root = new NSVRoot();
216
- const vm = app.mount(root);
217
- Application.resetRootView({ create: () => vm.$el.nativeView });
218
- return;
219
- }
220
- catch (e) {
221
- console.warn("[hmr-client-vue] Fallback back nav failed:", e);
222
- }
223
- }
224
- console.warn("[hmr-client-vue] No usable Frame and no original root component available; cannot navigate back.");
225
- };
226
- }
227
- // Also set the non-underscore versions
228
- globalThis.resolveComponent = resolveComponent;
229
- globalThis.openBlock = openBlock;
230
- globalThis.createBlock = createBlock;
231
- globalThis.withCtx = withCtx;
232
- globalThis.createVNode = createVNode;
233
- globalThis.createTextVNode = createTextVNode;
234
- // Set up component registry for HMR resolution
235
- // if (!globalThis.__NS_BUNDLE_COMPONENTS__) {
236
- // globalThis.__NS_BUNDLE_COMPONENTS__ = {};
237
- // // Try to extract components from the existing Vue app context
238
- // const existingApp = (globalThis as any).__NS_VUE_APP__;
239
- // if (existingApp?._context?.components) {
240
- // console.log("[hmr-client-vue] Registering existing app components for HMR resolution");
241
- // Object.assign(globalThis.__NS_BUNDLE_COMPONENTS__, existingApp._context.components);
242
- // console.log("[hmr-client-vue] Registered components:", Object.keys(existingApp._context.components));
243
- // }
244
- // }
245
- // First clean out any older HMR chunks to avoid filesystem clutter
246
- await removeHmrChunks();
247
- if (VERBOSE)
248
- console.log("[hmr-client-vue] Set up real Vue runtime and reactivity functions globally");
249
- const fileName = `hmr-${msg.id}-${Date.now()}.mjs`;
250
- if (VERBOSE)
251
- console.log("[hmr-client-vue] writing embedded-runtime module to filesystem for native import");
252
- const filePath = await writeDocumentsFile(fileName, content);
253
- if (VERBOSE)
254
- console.log("[hmr-client-vue] importing dynamic module from:", filePath);
255
- const moduleExports = await import(filePath);
256
- return moduleExports.default || moduleExports;
257
- }
258
- catch (error) {
259
- console.error("[hmr-client-vue] Failed to import module:", error);
260
- return null;
261
- }
262
- }
263
- async function removeHmrChunks() {
264
- const docs = knownFolders.documents();
265
- const entities = await docs.getEntities();
266
- const regex = /^hmr-.*\.mjs$/;
267
- const matches = [];
268
- for (const e of entities) {
269
- // keep it robust across bundlers:
270
- const isFile = e.remove !== undefined && !e.getEntities;
271
- if (isFile && regex.test(e.name)) {
272
- matches.push(e);
273
- }
274
- }
275
- // delete in parallel
276
- await Promise.all(matches.map((f) => f.remove()));
277
- return matches.map((f) => f.name);
278
- }
279
- async function removeSfcRegistryFiles() {
280
- const docs = knownFolders.documents();
281
- const entities = await docs.getEntities();
282
- const regex = /^sfc-.*\.mjs$/;
283
- const matches = [];
284
- for (const e of entities) {
285
- const isFile = e.remove !== undefined && !e.getEntities;
286
- if (isFile && regex.test(e.name)) {
287
- matches.push(e);
288
- }
289
- }
290
- await Promise.all(matches.map((f) => f.remove()));
291
- return matches.length;
292
- }
293
- async function writeDocumentsFile(fileName, content) {
294
- const docs = knownFolders.documents();
295
- const filePath = docs.path + "/" + fileName;
296
- const file = File.fromPath(filePath);
297
- await file.writeText(content);
298
- return filePath;
299
- }
300
- async function installSfcRegistry(entries) {
301
- if (VERBOSE)
302
- console.log("[hmr-client-vue] Installing SFC registry with", entries?.length || 0, "entries");
303
- try {
304
- const removed = await removeSfcRegistryFiles();
305
- if (removed) {
306
- if (VERBOSE)
307
- console.log("[hmr-client-vue] Removed", removed, "existing SFC files");
308
- }
309
- }
310
- catch (e) {
311
- console.warn("[hmr-client-vue] Could not clean SFC files:", e);
312
- }
313
- if (!entries || !entries.length)
314
- return;
315
- const writes = entries.map(async (e) => {
316
- try {
317
- const p = await writeDocumentsFile(e.fileName, e.code);
318
- return p;
319
- }
320
- catch (err) {
321
- console.warn("[hmr-client-vue] Failed writing SFC file", e.fileName, err);
322
- return null;
323
- }
324
- });
325
- const results = await Promise.all(writes);
326
- const ok = results.filter(Boolean).length;
327
- if (VERBOSE)
328
- console.log("[hmr-client-vue] Wrote", ok, "SFC files");
329
- }
330
- async function updateSfcModule(fileName, code) {
331
- if (!fileName || typeof code !== "string")
332
- return;
333
- try {
334
- const p = await writeDocumentsFile(fileName, code);
335
- if (VERBOSE)
336
- console.log("[hmr-client-vue] Updated SFC module:", fileName, "->", p);
337
- }
338
- catch (e) {
339
- console.warn("[hmr-client-vue] Failed to update SFC module", fileName, e);
340
- }
341
- }
342
- async function performResetRoot(newComponent) {
343
- if (VERBOSE)
344
- console.log("[hmr-client-vue] Single-path: replace current root Page");
345
- if (VERBOSE)
346
- console.log("[hmr-client-vue] Component details:", {
347
- componentName: newComponent.__name,
348
- componentFile: newComponent.__file,
349
- hasRender: !!newComponent.render,
350
- hasSetup: !!newComponent.setup,
351
- componentKeys: Object.keys(newComponent),
352
- });
353
- function mountRoot() {
354
- try {
355
- if (VERBOSE)
356
- console.log("[hmr-client-vue] Starting mountRoot process...");
357
- // First, let's test the component functions directly
358
- if (VERBOSE)
359
- console.log("[hmr-client-vue] Component analysis:", {
360
- hasSetup: !!newComponent.setup,
361
- hasRender: !!newComponent.render,
362
- setupType: typeof newComponent.setup,
363
- renderType: typeof newComponent.render,
364
- componentName: newComponent.__name,
365
- hmrId: newComponent.__hmrId,
366
- });
367
- // Skip direct setup function testing to avoid lifecycle warnings
368
- // The setup function will be called properly by Vue during mounting
369
- // Check if we have an existing Vue app instance we can reuse
370
- const existingApp = globalThis.__NS_VUE_APP__;
371
- if (VERBOSE)
372
- console.log("[hmr-client-vue] Existing app context:", {
373
- hasApp: !!existingApp,
374
- appKeys: existingApp ? Object.keys(existingApp) : [],
375
- contextComponents: existingApp?._context?.components
376
- ? Object.keys(existingApp._context.components)
377
- : [],
378
- });
379
- if (existingApp) {
380
- // Capture original root component once for back-navigation fallback
381
- try {
382
- if (!globalThis.__NS_HMR_ORIG_ROOT_COMPONENT__) {
383
- const orig = existingApp._component;
384
- if (orig) {
385
- globalThis.__NS_HMR_ORIG_ROOT_COMPONENT__ = orig;
386
- if (VERBOSE)
387
- console.log("[hmr-client-vue] Saved original root component for back fallback");
388
- }
389
- }
390
- }
391
- catch { }
392
- if (VERBOSE)
393
- console.log("[hmr-client-vue] Attempting to reuse existing app context...");
394
- try {
395
- // Create a new root container
396
- const newRoot = new NSVRoot();
397
- // Try to mount the new component using the existing app context
398
- // But first, we need to create a new app with the updated component
399
- const newApp = createApp(newComponent);
400
- // Copy the existing app's context (components, plugins, etc.)
401
- if (existingApp._context) {
402
- // Copy global properties and components from the existing app
403
- Object.assign(newApp._context.components, existingApp._context.components);
404
- Object.assign(newApp._context.config.globalProperties, existingApp._context.config.globalProperties);
405
- if (VERBOSE)
406
- console.log("[hmr-client-vue] Copied existing app context");
407
- }
408
- // Mount the component
409
- const vm = newApp.mount(newRoot);
410
- if (VERBOSE)
411
- console.log("[hmr-client-vue] Mounted with existing context. Result:", {
412
- hasEl: !!vm.$el,
413
- elType: vm.$el?.constructor?.name,
414
- hasNativeView: !!vm.$el?.nativeView,
415
- nativeViewType: vm.$el?.nativeView?.constructor?.name,
416
- });
417
- if (vm.$el?.nativeView) {
418
- return ensureFrameForNativeView(vm.$el.nativeView);
419
- }
420
- // Fall through to alternative approaches
421
- if (VERBOSE)
422
- console.log("[hmr-client-vue] Existing context approach didn't work, trying alternative...");
423
- }
424
- catch (contextError) {
425
- console.error("[hmr-client-vue] Error using existing context:", contextError);
426
- }
427
- }
428
- // Alternative approach: Direct component instantiation
429
- if (VERBOSE)
430
- console.log("[hmr-client-vue] Trying direct component instantiation...");
431
- try {
432
- // Create fresh app using imported functions
433
- const app = createApp(newComponent);
434
- // Mount to a new root
435
- const root = new NSVRoot();
436
- const vm = app.mount(root);
437
- if (VERBOSE)
438
- console.log("[hmr-client-vue] Direct mount result:", {
439
- hasEl: !!vm.$el,
440
- elType: vm.$el?.constructor?.name,
441
- hasNativeView: !!vm.$el?.nativeView,
442
- nativeViewType: vm.$el?.nativeView?.constructor?.name,
443
- elChildren: vm.$el?.childNodes?.length || 0,
444
- });
445
- // Try to find any valid nativeView in the component tree
446
- const findNativeView = (element) => {
447
- if (element?.nativeView) {
448
- return element.nativeView;
449
- }
450
- const children = element?.childNodes || element?.children || [];
451
- for (const child of children) {
452
- const result = findNativeView(child);
453
- if (result)
454
- return result;
455
- }
456
- return null;
457
- };
458
- const nativeView = findNativeView(vm.$el);
459
- if (nativeView) {
460
- if (VERBOSE)
461
- console.log("[hmr-client-vue] Found nativeView in tree:", nativeView.constructor.name);
462
- return ensureFrameForNativeView(nativeView);
463
- }
464
- }
465
- catch (directError) {
466
- console.error("[hmr-client-vue] Direct instantiation failed:", directError);
467
- }
468
- // Now try Vue rendering with proper runtime functions
469
- if (VERBOSE)
470
- console.log("[hmr-client-vue] Attempting Vue component rendering with real runtime...");
471
- try {
472
- // Create a fresh Vue app with the component
473
- const app = createApp(newComponent);
474
- // Mount to NSVRoot
475
- const root = new NSVRoot();
476
- const vm = app.mount(root);
477
- if (VERBOSE)
478
- console.log("[hmr-client-vue] Vue mount result with real runtime:", {
479
- hasEl: !!vm.$el,
480
- elType: vm.$el?.constructor?.name,
481
- hasNativeView: !!vm.$el?.nativeView,
482
- nativeViewType: vm.$el?.nativeView?.constructor?.name,
483
- elChildren: vm.$el?.childNodes?.length || 0,
484
- });
485
- // Search for the actual NativeScript view in the component tree
486
- const findNativeView = (element) => {
487
- // Check if this element has a nativeView
488
- if (element?.nativeView) {
489
- if (VERBOSE)
490
- console.log("[hmr-client-vue] Found nativeView:", element.nativeView.constructor.name);
491
- return element.nativeView;
492
- }
493
- // Search children recursively
494
- const children = element?.childNodes || element?.children || [];
495
- for (const child of children) {
496
- const result = findNativeView(child);
497
- if (result)
498
- return result;
499
- }
500
- return null;
501
- };
502
- const nativeView = findNativeView(vm.$el);
503
- if (nativeView) {
504
- if (VERBOSE)
505
- console.log("[hmr-client-vue] SUCCESS! Found Vue-rendered NativeScript view:", nativeView.constructor.name);
506
- return ensureFrameForNativeView(nativeView);
507
- }
508
- // If still no luck, let's examine the root element more carefully
509
- if (VERBOSE)
510
- console.log("[hmr-client-vue] No nativeView found, examining root element structure...");
511
- if (VERBOSE)
512
- console.log("[hmr-client-vue] Root element details:", {
513
- nodeName: vm.$el?.nodeName,
514
- tagName: vm.$el?.tagName,
515
- nodeType: vm.$el?.nodeType,
516
- textContent: vm.$el?.textContent?.substring(0, 50),
517
- innerHTML: vm.$el?.innerHTML?.substring(0, 100),
518
- });
519
- throw new Error("Vue mounting succeeded but no NativeScript view found");
520
- }
521
- catch (vueRenderError) {
522
- console.error("[hmr-client-vue] Vue component rendering failed:", vueRenderError);
523
- // Final fallback
524
- console.warn("[hmr-client-vue] Using simple fallback page");
525
- const fallbackPage = new Page();
526
- const fallbackLabel = new Label();
527
- fallbackLabel.text = "HMR Update Failed - Please restart app";
528
- fallbackPage.content = fallbackLabel;
529
- return ensureFrameForNativeView(fallbackPage);
530
- }
531
- }
532
- catch (error) {
533
- console.error("[hmr-client-vue] Error in mountRoot:", error);
534
- console.error("[hmr-client-vue] Stack trace:", error.stack);
535
- throw error;
536
- }
537
- }
538
- Application.resetRootView({
539
- create: mountRoot,
540
- });
541
- }
542
- // If the provided nativeView is a Page and there is no current Frame,
543
- // create a temporary Frame to host it so $navigateBack has a Frame context.
544
- function ensureFrameForNativeView(nativeView) {
545
- try {
546
- // If a Frame already exists, just return the view
547
- const top = Frame.topmost?.();
548
- if (top)
549
- return nativeView;
550
- }
551
- catch { }
552
- // No Frame present. If the view is a Page, create a Frame to host it.
553
- try {
554
- if (nativeView?.constructor?.name === "Page" || nativeView instanceof Page) {
555
- const frame = new Frame();
556
- frame.navigate({
557
- create: () => nativeView,
558
- animated: false,
559
- clearHistory: false,
560
- });
561
- if (VERBOSE)
562
- console.log("[hmr-client-vue] Wrapped Page in a temporary Frame for HMR");
563
- return frame;
564
- }
565
- }
566
- catch (e) {
567
- console.warn("[hmr-client-vue] Failed to wrap Page in Frame:", e);
568
- }
569
- return nativeView;
570
- }
571
- export function initHmrClient(opts) {
572
- if (opts?.wsUrl) {
573
- hmrWsUrl = opts.wsUrl;
574
- }
575
- if (VERBOSE)
576
- console.log("[hmr-client-vue] Initializing Vue HMR client", hmrWsUrl ? `(ws: ${hmrWsUrl})` : "");
577
- connectHmr();
578
- }
579
- export default function startViteHMR(opts) {
580
- if (VERBOSE)
581
- console.log("[hmr-client-vue] Starting HMR client", opts);
582
- initHmrClient(opts);
583
- }
584
- // Auto-initialization removed to prevent duplicate connections
585
- // HMR client is now only initialized via explicit startViteHMR() call from main entry
@@ -1,23 +0,0 @@
1
- interface ComponentTracker {
2
- registerComponent(id: string, instance: any): void;
3
- unregisterComponent(id: string, instance: any): void;
4
- getInstances(id: string): any[];
5
- getAllInstances(): Map<string, any[]>;
6
- findInstancesByFile(file: string): any[];
7
- }
8
- declare class NativeScriptVueComponentTracker implements ComponentTracker {
9
- private instanceMap;
10
- private fileToIdMap;
11
- registerComponent(id: string, instance: any): void;
12
- unregisterComponent(id: string, instance: any): void;
13
- getInstances(id: string): any[];
14
- getAllInstances(): Map<string, any[]>;
15
- findInstancesByFile(file: string): any[];
16
- private extractFileFromInstance;
17
- private normalizeFilePath;
18
- private filesMatch;
19
- }
20
- declare const componentTracker: NativeScriptVueComponentTracker;
21
- export declare function setupComponentTracking(): void;
22
- export { componentTracker };
23
- export default componentTracker;