@nativescript/vite 8.0.0-beta.0 → 8.0.0-rc.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 (577) hide show
  1. package/README.md +73 -14
  2. package/bin/cli.cjs +8 -14
  3. package/configuration/angular.d.ts +35 -2
  4. package/configuration/angular.js +541 -216
  5. package/configuration/angular.js.map +1 -1
  6. package/configuration/base.js +227 -77
  7. package/configuration/base.js.map +1 -1
  8. package/configuration/javascript.js +17 -96
  9. package/configuration/javascript.js.map +1 -1
  10. package/configuration/react.js +41 -73
  11. package/configuration/react.js.map +1 -1
  12. package/configuration/solid.js +58 -6
  13. package/configuration/solid.js.map +1 -1
  14. package/configuration/typescript.js +15 -96
  15. package/configuration/typescript.js.map +1 -1
  16. package/helpers/app-components.d.ts +2 -1
  17. package/helpers/app-components.js.map +1 -1
  18. package/helpers/app-css-refresh.d.ts +31 -0
  19. package/helpers/app-css-refresh.js +43 -0
  20. package/helpers/app-css-refresh.js.map +1 -0
  21. package/helpers/app-css-state.d.ts +17 -0
  22. package/helpers/app-css-state.js +51 -0
  23. package/helpers/app-css-state.js.map +1 -0
  24. package/helpers/bundler-context.d.ts +11 -0
  25. package/helpers/bundler-context.js +71 -0
  26. package/helpers/bundler-context.js.map +1 -0
  27. package/helpers/cli-flags.d.ts +12 -0
  28. package/helpers/cli-flags.js +34 -0
  29. package/helpers/cli-flags.js.map +1 -1
  30. package/helpers/commonjs-plugins.d.ts +5 -2
  31. package/helpers/commonjs-plugins.js +126 -0
  32. package/helpers/commonjs-plugins.js.map +1 -1
  33. package/helpers/config-as-json.js +10 -0
  34. package/helpers/config-as-json.js.map +1 -1
  35. package/helpers/css-platform-plugin.d.ts +14 -0
  36. package/helpers/css-platform-plugin.js +43 -25
  37. package/helpers/css-platform-plugin.js.map +1 -1
  38. package/helpers/dev-host.d.ts +360 -0
  39. package/helpers/dev-host.js +694 -0
  40. package/helpers/dev-host.js.map +1 -0
  41. package/helpers/dynamic-import-plugin.d.ts +2 -1
  42. package/helpers/dynamic-import-plugin.js +59 -53
  43. package/helpers/dynamic-import-plugin.js.map +1 -1
  44. package/helpers/esbuild-platform-resolver.js +9 -6
  45. package/helpers/esbuild-platform-resolver.js.map +1 -1
  46. package/helpers/external-configs.d.ts +10 -4
  47. package/helpers/external-configs.js +63 -15
  48. package/helpers/external-configs.js.map +1 -1
  49. package/helpers/flavor.d.ts +13 -0
  50. package/helpers/flavor.js +18 -1
  51. package/helpers/flavor.js.map +1 -1
  52. package/helpers/global-defines.d.ts +117 -0
  53. package/helpers/global-defines.js +209 -11
  54. package/helpers/global-defines.js.map +1 -1
  55. package/helpers/hmr-scope.d.ts +26 -0
  56. package/helpers/hmr-scope.js +67 -0
  57. package/helpers/hmr-scope.js.map +1 -0
  58. package/helpers/import-meta-path.d.ts +4 -0
  59. package/helpers/import-meta-path.js +5 -0
  60. package/helpers/import-meta-path.js.map +1 -0
  61. package/helpers/import-specifier.d.ts +1 -0
  62. package/helpers/import-specifier.js +18 -0
  63. package/helpers/import-specifier.js.map +1 -0
  64. package/helpers/init.js +6 -20
  65. package/helpers/init.js.map +1 -1
  66. package/helpers/logging.d.ts +1 -0
  67. package/helpers/logging.js +65 -4
  68. package/helpers/logging.js.map +1 -1
  69. package/helpers/main-entry.d.ts +8 -2
  70. package/helpers/main-entry.js +622 -120
  71. package/helpers/main-entry.js.map +1 -1
  72. package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
  73. package/helpers/nativeclass-esbuild-plugin.js +6 -1
  74. package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
  75. package/helpers/nativeclass-transform.d.ts +13 -0
  76. package/helpers/nativeclass-transform.js +42 -131
  77. package/helpers/nativeclass-transform.js.map +1 -1
  78. package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
  79. package/helpers/nativeclass-transformer-plugin.js +324 -37
  80. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  81. package/helpers/nativescript-package-resolver.js +10 -62
  82. package/helpers/nativescript-package-resolver.js.map +1 -1
  83. package/helpers/normalize-id.d.ts +42 -0
  84. package/helpers/normalize-id.js +60 -0
  85. package/helpers/normalize-id.js.map +1 -0
  86. package/helpers/ns-core-external-urls.d.ts +32 -0
  87. package/helpers/ns-core-external-urls.js +107 -0
  88. package/helpers/ns-core-external-urls.js.map +1 -0
  89. package/helpers/ns-core-url.d.ts +106 -0
  90. package/helpers/ns-core-url.js +225 -0
  91. package/helpers/ns-core-url.js.map +1 -0
  92. package/helpers/optimize-deps.d.ts +16 -0
  93. package/helpers/optimize-deps.js +17 -0
  94. package/helpers/optimize-deps.js.map +1 -0
  95. package/helpers/package-platform-aliases.js +34 -49
  96. package/helpers/package-platform-aliases.js.map +1 -1
  97. package/helpers/platform-types.d.ts +2 -0
  98. package/helpers/platform-types.js +2 -0
  99. package/helpers/platform-types.js.map +1 -0
  100. package/helpers/postcss-platform-config.d.ts +17 -1
  101. package/helpers/postcss-platform-config.js +20 -37
  102. package/helpers/postcss-platform-config.js.map +1 -1
  103. package/helpers/project.d.ts +35 -0
  104. package/helpers/project.js +120 -2
  105. package/helpers/project.js.map +1 -1
  106. package/helpers/resolve-main-field-platform.d.ts +20 -0
  107. package/helpers/resolve-main-field-platform.js +49 -0
  108. package/helpers/resolve-main-field-platform.js.map +1 -0
  109. package/helpers/resolver.js +17 -2
  110. package/helpers/resolver.js.map +1 -1
  111. package/helpers/theme-core-plugins.js +1 -1
  112. package/helpers/theme-core-plugins.js.map +1 -1
  113. package/helpers/ts-config-paths.d.ts +32 -0
  114. package/helpers/ts-config-paths.js +156 -27
  115. package/helpers/ts-config-paths.js.map +1 -1
  116. package/helpers/typescript-check.d.ts +2 -1
  117. package/helpers/typescript-check.js +4 -4
  118. package/helpers/typescript-check.js.map +1 -1
  119. package/helpers/ui-registration.d.ts +21 -0
  120. package/helpers/ui-registration.js +156 -0
  121. package/helpers/ui-registration.js.map +1 -0
  122. package/helpers/utils.d.ts +9 -0
  123. package/helpers/utils.js +22 -2
  124. package/helpers/utils.js.map +1 -1
  125. package/helpers/vite-package-version.d.ts +7 -0
  126. package/helpers/vite-package-version.js +44 -0
  127. package/helpers/vite-package-version.js.map +1 -0
  128. package/helpers/workers.d.ts +40 -19
  129. package/helpers/workers.js +312 -13
  130. package/helpers/workers.js.map +1 -1
  131. package/hmr/client/css-handler.d.ts +2 -1
  132. package/hmr/client/css-handler.js +95 -23
  133. package/hmr/client/css-handler.js.map +1 -1
  134. package/hmr/client/css-update-overlay.d.ts +18 -0
  135. package/hmr/client/css-update-overlay.js +27 -0
  136. package/hmr/client/css-update-overlay.js.map +1 -0
  137. package/hmr/client/framework-client-strategy.d.ts +87 -0
  138. package/hmr/client/framework-client-strategy.js +18 -0
  139. package/hmr/client/framework-client-strategy.js.map +1 -0
  140. package/hmr/client/hmr-pending-overlay.d.ts +13 -0
  141. package/hmr/client/hmr-pending-overlay.js +41 -0
  142. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  143. package/hmr/client/hot-context.d.ts +67 -0
  144. package/hmr/client/hot-context.js +307 -0
  145. package/hmr/client/hot-context.js.map +1 -0
  146. package/hmr/client/index.d.ts +9 -1
  147. package/hmr/client/index.js +91 -1418
  148. package/hmr/client/index.js.map +1 -1
  149. package/hmr/client/overlay-driver.d.ts +10 -0
  150. package/hmr/client/overlay-driver.js +33 -0
  151. package/hmr/client/overlay-driver.js.map +1 -0
  152. package/hmr/client/protocol-dispatch.d.ts +8 -0
  153. package/hmr/client/protocol-dispatch.js +308 -0
  154. package/hmr/client/protocol-dispatch.js.map +1 -0
  155. package/hmr/client/root-reset.d.ts +15 -0
  156. package/hmr/client/root-reset.js +358 -0
  157. package/hmr/client/root-reset.js.map +1 -0
  158. package/hmr/client/strategy-loader.d.ts +24 -0
  159. package/hmr/client/strategy-loader.js +100 -0
  160. package/hmr/client/strategy-loader.js.map +1 -0
  161. package/hmr/client/update-pipeline.d.ts +27 -0
  162. package/hmr/client/update-pipeline.js +464 -0
  163. package/hmr/client/update-pipeline.js.map +1 -0
  164. package/hmr/client/utils.d.ts +14 -1
  165. package/hmr/client/utils.js +265 -54
  166. package/hmr/client/utils.js.map +1 -1
  167. package/hmr/client/ws-transport.d.ts +21 -0
  168. package/hmr/client/ws-transport.js +323 -0
  169. package/hmr/client/ws-transport.js.map +1 -0
  170. package/hmr/entry-runtime.d.ts +11 -0
  171. package/hmr/entry-runtime.js +566 -43
  172. package/hmr/entry-runtime.js.map +1 -1
  173. package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
  174. package/hmr/frameworks/angular/build/angular-linker.js +113 -0
  175. package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
  176. package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
  177. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
  178. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
  179. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
  180. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
  181. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
  182. package/hmr/frameworks/angular/build/inline-decorator-component-templates.d.ts +3 -0
  183. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js +231 -0
  184. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
  185. package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
  186. package/hmr/frameworks/angular/build/js-lexer.js +182 -0
  187. package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
  188. package/hmr/frameworks/angular/build/linker-stats.d.ts +18 -0
  189. package/hmr/frameworks/angular/build/linker-stats.js +29 -0
  190. package/hmr/frameworks/angular/build/linker-stats.js.map +1 -0
  191. package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
  192. package/hmr/frameworks/angular/build/shared-linker.js +128 -0
  193. package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
  194. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.d.ts +1 -0
  195. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
  196. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
  197. package/hmr/frameworks/angular/build/synthesize-injectable-factories.d.ts +3 -0
  198. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js +241 -0
  199. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
  200. package/hmr/frameworks/angular/build/ts-fallback-transform.d.ts +5 -0
  201. package/hmr/frameworks/angular/build/ts-fallback-transform.js +138 -0
  202. package/hmr/frameworks/angular/build/ts-fallback-transform.js.map +1 -0
  203. package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
  204. package/hmr/frameworks/angular/build/util.js +155 -0
  205. package/hmr/frameworks/angular/build/util.js.map +1 -0
  206. package/hmr/frameworks/angular/build/worker-url-preserve.d.ts +5 -0
  207. package/hmr/frameworks/angular/build/worker-url-preserve.js +140 -0
  208. package/hmr/frameworks/angular/build/worker-url-preserve.js.map +1 -0
  209. package/hmr/frameworks/angular/client/index.d.ts +2 -1
  210. package/hmr/frameworks/angular/client/index.js +637 -23
  211. package/hmr/frameworks/angular/client/index.js.map +1 -1
  212. package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
  213. package/hmr/frameworks/angular/client/strategy.js +19 -0
  214. package/hmr/frameworks/angular/client/strategy.js.map +1 -0
  215. package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
  216. package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
  217. package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
  218. package/hmr/frameworks/angular/server/linker.js +37 -6
  219. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  220. package/hmr/frameworks/angular/server/ng-component-route.d.ts +43 -0
  221. package/hmr/frameworks/angular/server/ng-component-route.js +113 -0
  222. package/hmr/frameworks/angular/server/ng-component-route.js.map +1 -0
  223. package/hmr/frameworks/angular/server/strategy.js +697 -18
  224. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  225. package/hmr/frameworks/angular/server/websocket-angular-entry.d.ts +2 -0
  226. package/hmr/frameworks/angular/server/websocket-angular-entry.js +68 -0
  227. package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
  228. package/hmr/frameworks/angular/server/websocket-angular-hot-update.d.ts +94 -0
  229. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +485 -0
  230. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
  231. package/hmr/frameworks/react/client/strategy.d.ts +12 -0
  232. package/hmr/frameworks/react/client/strategy.js +27 -0
  233. package/hmr/frameworks/react/client/strategy.js.map +1 -0
  234. package/hmr/frameworks/react/server/strategy.d.ts +2 -0
  235. package/hmr/frameworks/react/server/strategy.js +230 -0
  236. package/hmr/frameworks/react/server/strategy.js.map +1 -0
  237. package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
  238. package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
  239. package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
  240. package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
  241. package/hmr/frameworks/solid/client/app-runtime.js +252 -0
  242. package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
  243. package/hmr/frameworks/solid/client/strategy.d.ts +7 -0
  244. package/hmr/frameworks/solid/client/strategy.js +391 -0
  245. package/hmr/frameworks/solid/client/strategy.js.map +1 -0
  246. package/hmr/frameworks/solid/server/strategy.js +293 -16
  247. package/hmr/frameworks/solid/server/strategy.js.map +1 -1
  248. package/hmr/frameworks/typescript/client/strategy.d.ts +7 -0
  249. package/hmr/frameworks/typescript/client/strategy.js +418 -0
  250. package/hmr/frameworks/typescript/client/strategy.js.map +1 -0
  251. package/hmr/frameworks/typescript/server/strategy.js +48 -16
  252. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  253. package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
  254. package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
  255. package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
  256. package/hmr/frameworks/vue/client/index.d.ts +10 -1
  257. package/hmr/frameworks/vue/client/index.js +287 -562
  258. package/hmr/frameworks/vue/client/index.js.map +1 -1
  259. package/hmr/frameworks/vue/client/navigate-app.d.ts +3 -0
  260. package/hmr/frameworks/vue/client/navigate-app.js +178 -0
  261. package/hmr/frameworks/vue/client/navigate-app.js.map +1 -0
  262. package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
  263. package/hmr/frameworks/vue/client/strategy.js +152 -0
  264. package/hmr/frameworks/vue/client/strategy.js.map +1 -0
  265. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
  266. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +124 -0
  267. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
  268. package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
  269. package/hmr/frameworks/vue/server/compiler.js +3 -1
  270. package/hmr/frameworks/vue/server/compiler.js.map +1 -1
  271. package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
  272. package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
  273. package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
  274. package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
  275. package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
  276. package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
  277. package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
  278. package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
  279. package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
  280. package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
  281. package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
  282. package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
  283. package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
  284. package/hmr/frameworks/vue/server/strategy.js +291 -7
  285. package/hmr/frameworks/vue/server/strategy.js.map +1 -1
  286. package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
  287. package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
  288. package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
  289. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  290. package/hmr/helpers/ast-normalizer.js +131 -24
  291. package/hmr/helpers/ast-normalizer.js.map +1 -1
  292. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  293. package/hmr/helpers/cjs-named-exports.js +152 -0
  294. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  295. package/hmr/helpers/package-exports.d.ts +16 -0
  296. package/hmr/helpers/package-exports.js +396 -0
  297. package/hmr/helpers/package-exports.js.map +1 -0
  298. package/hmr/helpers/vendor-rewrite.d.ts +1 -1
  299. package/hmr/helpers/vendor-rewrite.js +5 -3
  300. package/hmr/helpers/vendor-rewrite.js.map +1 -1
  301. package/hmr/server/boot-recording.d.ts +51 -0
  302. package/hmr/server/boot-recording.js +214 -0
  303. package/hmr/server/boot-recording.js.map +1 -0
  304. package/hmr/server/constants.d.ts +1 -0
  305. package/hmr/server/constants.js +21 -4
  306. package/hmr/server/constants.js.map +1 -1
  307. package/hmr/server/content-css-update.d.ts +54 -0
  308. package/hmr/server/content-css-update.js +78 -0
  309. package/hmr/server/content-css-update.js.map +1 -0
  310. package/hmr/server/core-bundle.d.ts +140 -0
  311. package/hmr/server/core-bundle.js +614 -0
  312. package/hmr/server/core-bundle.js.map +1 -0
  313. package/hmr/server/core-sanitize.d.ts +130 -4
  314. package/hmr/server/core-sanitize.js +393 -32
  315. package/hmr/server/core-sanitize.js.map +1 -1
  316. package/hmr/server/css-connect-sync.d.ts +28 -0
  317. package/hmr/server/css-connect-sync.js +59 -0
  318. package/hmr/server/css-connect-sync.js.map +1 -0
  319. package/hmr/server/css-device-module.d.ts +28 -0
  320. package/hmr/server/css-device-module.js +44 -0
  321. package/hmr/server/css-device-module.js.map +1 -0
  322. package/hmr/server/css-update-message.d.ts +23 -0
  323. package/hmr/server/css-update-message.js +41 -0
  324. package/hmr/server/css-update-message.js.map +1 -0
  325. package/hmr/server/deps-bundle.d.ts +233 -0
  326. package/hmr/server/deps-bundle.js +1022 -0
  327. package/hmr/server/deps-bundle.js.map +1 -0
  328. package/hmr/server/device-transform-helpers.d.ts +24 -0
  329. package/hmr/server/device-transform-helpers.js +408 -0
  330. package/hmr/server/device-transform-helpers.js.map +1 -0
  331. package/hmr/server/framework-strategy.d.ts +182 -11
  332. package/hmr/server/hmr-module-graph.d.ts +37 -0
  333. package/hmr/server/hmr-module-graph.js +215 -0
  334. package/hmr/server/hmr-module-graph.js.map +1 -0
  335. package/hmr/server/import-map.d.ts +99 -0
  336. package/hmr/server/import-map.js +294 -0
  337. package/hmr/server/import-map.js.map +1 -0
  338. package/hmr/server/index.d.ts +2 -1
  339. package/hmr/server/index.js +7 -16
  340. package/hmr/server/index.js.map +1 -1
  341. package/hmr/server/node-builtins-route.d.ts +12 -0
  342. package/hmr/server/node-builtins-route.js +86 -0
  343. package/hmr/server/node-builtins-route.js.map +1 -0
  344. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  345. package/hmr/server/ns-core-cjs-shape.js +271 -0
  346. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  347. package/hmr/server/ns-m-response-memo.d.ts +10 -0
  348. package/hmr/server/ns-m-response-memo.js +33 -0
  349. package/hmr/server/ns-m-response-memo.js.map +1 -0
  350. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  351. package/hmr/server/ns-rt-bridge.js +131 -0
  352. package/hmr/server/ns-rt-bridge.js.map +1 -0
  353. package/hmr/server/ns-rt-route.d.ts +5 -0
  354. package/hmr/server/ns-rt-route.js +39 -0
  355. package/hmr/server/ns-rt-route.js.map +1 -0
  356. package/hmr/server/perf-instrumentation.d.ts +114 -0
  357. package/hmr/server/perf-instrumentation.js +197 -0
  358. package/hmr/server/perf-instrumentation.js.map +1 -0
  359. package/hmr/server/process-code-for-device.d.ts +44 -0
  360. package/hmr/server/process-code-for-device.js +834 -0
  361. package/hmr/server/process-code-for-device.js.map +1 -0
  362. package/hmr/server/require-guard.d.ts +1 -0
  363. package/hmr/server/require-guard.js +12 -0
  364. package/hmr/server/require-guard.js.map +1 -0
  365. package/hmr/server/rewrite-imports.d.ts +2 -0
  366. package/hmr/server/rewrite-imports.js +631 -0
  367. package/hmr/server/rewrite-imports.js.map +1 -0
  368. package/hmr/server/route-helpers.d.ts +7 -0
  369. package/hmr/server/route-helpers.js +13 -0
  370. package/hmr/server/route-helpers.js.map +1 -0
  371. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  372. package/hmr/server/runtime-graph-filter.js +28 -0
  373. package/hmr/server/runtime-graph-filter.js.map +1 -0
  374. package/hmr/server/server-origin.d.ts +2 -0
  375. package/hmr/server/server-origin.js +88 -0
  376. package/hmr/server/server-origin.js.map +1 -0
  377. package/hmr/server/shared-transform-request.d.ts +12 -0
  378. package/hmr/server/shared-transform-request.js +143 -0
  379. package/hmr/server/shared-transform-request.js.map +1 -0
  380. package/hmr/server/socket-utils.d.ts +10 -0
  381. package/hmr/server/socket-utils.js +14 -0
  382. package/hmr/server/socket-utils.js.map +1 -0
  383. package/hmr/server/transform-cache-invalidation.d.ts +37 -0
  384. package/hmr/server/transform-cache-invalidation.js +156 -0
  385. package/hmr/server/transform-cache-invalidation.js.map +1 -0
  386. package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
  387. package/hmr/server/vendor-bare-module-shims.js +80 -0
  388. package/hmr/server/vendor-bare-module-shims.js.map +1 -0
  389. package/hmr/server/vite-plugin.d.ts +22 -1
  390. package/hmr/server/vite-plugin.js +655 -58
  391. package/hmr/server/vite-plugin.js.map +1 -1
  392. package/hmr/server/websocket-core-bridge.d.ts +68 -0
  393. package/hmr/server/websocket-core-bridge.js +370 -0
  394. package/hmr/server/websocket-core-bridge.js.map +1 -0
  395. package/hmr/server/websocket-device-transform.d.ts +3 -0
  396. package/hmr/server/websocket-device-transform.js +7 -0
  397. package/hmr/server/websocket-device-transform.js.map +1 -0
  398. package/hmr/server/websocket-graph-upsert.d.ts +21 -0
  399. package/hmr/server/websocket-graph-upsert.js +33 -0
  400. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  401. package/hmr/server/websocket-hmr-pending.d.ts +29 -0
  402. package/hmr/server/websocket-hmr-pending.js +33 -0
  403. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  404. package/hmr/server/websocket-hot-update.d.ts +80 -0
  405. package/hmr/server/websocket-hot-update.js +295 -0
  406. package/hmr/server/websocket-hot-update.js.map +1 -0
  407. package/hmr/server/websocket-import-map-route.d.ts +15 -0
  408. package/hmr/server/websocket-import-map-route.js +51 -0
  409. package/hmr/server/websocket-import-map-route.js.map +1 -0
  410. package/hmr/server/websocket-module-bindings.d.ts +21 -0
  411. package/hmr/server/websocket-module-bindings.js +504 -0
  412. package/hmr/server/websocket-module-bindings.js.map +1 -0
  413. package/hmr/server/websocket-module-specifiers.d.ts +96 -0
  414. package/hmr/server/websocket-module-specifiers.js +819 -0
  415. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  416. package/hmr/server/websocket-ns-core.d.ts +34 -0
  417. package/hmr/server/websocket-ns-core.js +414 -0
  418. package/hmr/server/websocket-ns-core.js.map +1 -0
  419. package/hmr/server/websocket-ns-entry.d.ts +21 -0
  420. package/hmr/server/websocket-ns-entry.js +163 -0
  421. package/hmr/server/websocket-ns-entry.js.map +1 -0
  422. package/hmr/server/websocket-ns-m-paths.d.ts +19 -0
  423. package/hmr/server/websocket-ns-m-paths.js +115 -0
  424. package/hmr/server/websocket-ns-m-paths.js.map +1 -0
  425. package/hmr/server/websocket-ns-m-request.d.ts +46 -0
  426. package/hmr/server/websocket-ns-m-request.js +197 -0
  427. package/hmr/server/websocket-ns-m-request.js.map +1 -0
  428. package/hmr/server/websocket-ns-m.d.ts +52 -0
  429. package/hmr/server/websocket-ns-m.js +590 -0
  430. package/hmr/server/websocket-ns-m.js.map +1 -0
  431. package/hmr/server/websocket-served-module-helpers.d.ts +89 -0
  432. package/hmr/server/websocket-served-module-helpers.js +935 -0
  433. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  434. package/hmr/server/websocket-txn.d.ts +6 -0
  435. package/hmr/server/websocket-txn.js +42 -0
  436. package/hmr/server/websocket-txn.js.map +1 -0
  437. package/hmr/server/websocket-vendor-unifier.d.ts +9 -0
  438. package/hmr/server/websocket-vendor-unifier.js +46 -0
  439. package/hmr/server/websocket-vendor-unifier.js.map +1 -0
  440. package/hmr/server/websocket.d.ts +7 -17
  441. package/hmr/server/websocket.js +723 -5376
  442. package/hmr/server/websocket.js.map +1 -1
  443. package/hmr/shared/ns-globals.d.ts +107 -0
  444. package/hmr/shared/ns-globals.js +29 -0
  445. package/hmr/shared/ns-globals.js.map +1 -0
  446. package/hmr/shared/package-classifier.d.ts +9 -0
  447. package/hmr/shared/package-classifier.js +58 -0
  448. package/hmr/shared/package-classifier.js.map +1 -0
  449. package/hmr/shared/protocol.d.ts +157 -0
  450. package/hmr/shared/protocol.js +28 -0
  451. package/hmr/shared/protocol.js.map +1 -0
  452. package/hmr/shared/runtime/boot-complete.d.ts +14 -0
  453. package/hmr/shared/runtime/boot-complete.js +32 -0
  454. package/hmr/shared/runtime/boot-complete.js.map +1 -0
  455. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  456. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  457. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  458. package/hmr/shared/runtime/boot-progress.d.ts +44 -0
  459. package/hmr/shared/runtime/boot-progress.js +134 -0
  460. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  461. package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
  462. package/hmr/shared/runtime/boot-timeline.js +40 -0
  463. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  464. package/hmr/shared/runtime/browser-runtime-contract.d.ts +97 -0
  465. package/hmr/shared/runtime/browser-runtime-contract.js +66 -0
  466. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  467. package/hmr/shared/runtime/dev-overlay-ios.d.ts +87 -0
  468. package/hmr/shared/runtime/dev-overlay-ios.js +521 -0
  469. package/hmr/shared/runtime/dev-overlay-ios.js.map +1 -0
  470. package/hmr/shared/runtime/dev-overlay-shared.d.ts +58 -0
  471. package/hmr/shared/runtime/dev-overlay-shared.js +116 -0
  472. package/hmr/shared/runtime/dev-overlay-shared.js.map +1 -0
  473. package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
  474. package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
  475. package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
  476. package/hmr/shared/runtime/dev-overlay-tree.d.ts +59 -0
  477. package/hmr/shared/runtime/dev-overlay-tree.js +712 -0
  478. package/hmr/shared/runtime/dev-overlay-tree.js.map +1 -0
  479. package/hmr/shared/runtime/dev-overlay.d.ts +39 -0
  480. package/hmr/shared/runtime/dev-overlay.js +292 -0
  481. package/hmr/shared/runtime/dev-overlay.js.map +1 -0
  482. package/hmr/shared/runtime/global-scope.d.ts +18 -0
  483. package/hmr/shared/runtime/global-scope.js +21 -0
  484. package/hmr/shared/runtime/global-scope.js.map +1 -0
  485. package/hmr/shared/runtime/hooks.js +2 -1
  486. package/hmr/shared/runtime/hooks.js.map +1 -1
  487. package/hmr/shared/runtime/launch-bridge.d.ts +9 -0
  488. package/hmr/shared/runtime/launch-bridge.js +98 -0
  489. package/hmr/shared/runtime/launch-bridge.js.map +1 -0
  490. package/hmr/shared/runtime/module-provenance.d.ts +1 -0
  491. package/hmr/shared/runtime/module-provenance.js +64 -0
  492. package/hmr/shared/runtime/module-provenance.js.map +1 -0
  493. package/hmr/shared/runtime/ns-runtime-test-double.d.ts +21 -0
  494. package/hmr/shared/runtime/ns-runtime-test-double.js +20 -0
  495. package/hmr/shared/runtime/ns-runtime-test-double.js.map +1 -0
  496. package/hmr/shared/runtime/overlay-flag.d.ts +9 -0
  497. package/hmr/shared/runtime/overlay-flag.js +34 -0
  498. package/hmr/shared/runtime/overlay-flag.js.map +1 -0
  499. package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
  500. package/hmr/shared/runtime/platform-polyfills.js +122 -0
  501. package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
  502. package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
  503. package/hmr/shared/runtime/root-placeholder-view.js +311 -0
  504. package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
  505. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  506. package/hmr/shared/runtime/root-placeholder.js +778 -83
  507. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  508. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  509. package/hmr/shared/runtime/session-bootstrap.js +350 -0
  510. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  511. package/hmr/shared/runtime/vendor-bootstrap.js +54 -16
  512. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  513. package/hmr/shared/runtime/vendor-resolve.d.ts +22 -0
  514. package/hmr/shared/runtime/vendor-resolve.js +45 -0
  515. package/hmr/shared/runtime/vendor-resolve.js.map +1 -0
  516. package/hmr/shared/runtime/worker-tracking.d.ts +28 -0
  517. package/hmr/shared/runtime/worker-tracking.js +114 -0
  518. package/hmr/shared/runtime/worker-tracking.js.map +1 -0
  519. package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
  520. package/hmr/shared/vendor/manifest-collect.js +909 -0
  521. package/hmr/shared/vendor/manifest-collect.js.map +1 -0
  522. package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
  523. package/hmr/shared/vendor/manifest-loader.js +5 -3
  524. package/hmr/shared/vendor/manifest-loader.js.map +1 -1
  525. package/hmr/shared/vendor/manifest.d.ts +12 -0
  526. package/hmr/shared/vendor/manifest.js +341 -545
  527. package/hmr/shared/vendor/manifest.js.map +1 -1
  528. package/hmr/shared/vendor/registry.d.ts +2 -0
  529. package/hmr/shared/vendor/registry.js +118 -7
  530. package/hmr/shared/vendor/registry.js.map +1 -1
  531. package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
  532. package/hmr/shared/vendor/vendor-device-shim.js +208 -0
  533. package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
  534. package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +107 -0
  535. package/hmr/shared/vendor/vendor-esbuild-plugins.js +540 -0
  536. package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
  537. package/index.d.ts +1 -0
  538. package/index.js +5 -0
  539. package/index.js.map +1 -1
  540. package/package.json +76 -14
  541. package/runtime/core-aliases-early.js +103 -81
  542. package/runtime/core-aliases-early.js.map +1 -1
  543. package/shims/react-jsx-runtime.d.ts +4 -0
  544. package/shims/react-jsx-runtime.js +61 -0
  545. package/shims/react-jsx-runtime.js.map +1 -0
  546. package/shims/solid-jsx-runtime.d.ts +7 -0
  547. package/shims/solid-jsx-runtime.js +17 -0
  548. package/shims/solid-jsx-runtime.js.map +1 -0
  549. package/helpers/angular/angular-linker.d.ts +0 -13
  550. package/helpers/angular/angular-linker.js +0 -189
  551. package/helpers/angular/angular-linker.js.map +0 -1
  552. package/helpers/angular/shared-linker.d.ts +0 -4
  553. package/helpers/angular/shared-linker.js +0 -39
  554. package/helpers/angular/shared-linker.js.map +0 -1
  555. package/helpers/angular/util.js +0 -67
  556. package/helpers/angular/util.js.map +0 -1
  557. package/helpers/module-runner-patch.d.ts +0 -3
  558. package/helpers/module-runner-patch.js +0 -63
  559. package/helpers/module-runner-patch.js.map +0 -1
  560. package/helpers/prelink-angular.d.ts +0 -2
  561. package/helpers/prelink-angular.js +0 -117
  562. package/helpers/prelink-angular.js.map +0 -1
  563. package/hmr/shared/runtime/http-only-boot.d.ts +0 -1
  564. package/hmr/shared/runtime/http-only-boot.js +0 -124
  565. package/hmr/shared/runtime/http-only-boot.js.map +0 -1
  566. package/hmr/vendor-bootstrap.d.ts +0 -3
  567. package/hmr/vendor-bootstrap.js +0 -32
  568. package/hmr/vendor-bootstrap.js.map +0 -1
  569. package/shims/react-reconciler-constants.d.ts +0 -14
  570. package/shims/react-reconciler-constants.js +0 -21
  571. package/shims/react-reconciler-constants.js.map +0 -1
  572. package/shims/react-reconciler.d.ts +0 -8
  573. package/shims/react-reconciler.js +0 -15
  574. package/shims/react-reconciler.js.map +0 -1
  575. package/transformers/NativeClass/index.d.ts +0 -2
  576. package/transformers/NativeClass/index.js +0 -222
  577. package/transformers/NativeClass/index.js.map +0 -1
@@ -1,46 +1,660 @@
1
1
  import { createRequire } from 'node:module';
2
+ import fs from 'node:fs';
2
3
  import path from 'path';
3
- import os from 'os';
4
4
  import { pathToFileURL } from 'url';
5
+ import { NS_DEFAULT_DEV_FEATURE_FLAGS, NS_DEFAULT_HOST_MODULES } from '../shared/runtime/browser-runtime-contract.js';
6
+ import { resolveDeviceReachableHost } from '../../helpers/dev-host.js';
7
+ import { setUserDefineEntries } from '../../helpers/global-defines.js';
8
+ import { getMonorepoWorkspaceRoot } from '../../helpers/project.js';
5
9
  const require = createRequire(import.meta.url);
6
10
  const VIRTUAL_ID = 'virtual:ns-hmr-client';
7
11
  const RESOLVED_ID = '\0' + VIRTUAL_ID;
8
- export function nsHmrClientVitePlugin(opts) {
9
- let config;
10
- const guessLanHost = () => {
11
- try {
12
- const nets = os.networkInterfaces();
13
- for (const name of Object.keys(nets)) {
14
- const addrs = nets[name] || [];
15
- for (const a of addrs) {
16
- if (!a)
17
- continue;
18
- // Node typings vary across versions; keep checks defensive
19
- const family = a.family;
20
- const internal = !!a.internal;
21
- const address = String(a.address || '');
22
- if (internal)
23
- continue;
24
- if (family === 'IPv4' || family === 4) {
25
- if (address && address !== '127.0.0.1')
26
- return address;
27
- }
28
- }
12
+ export function computeClientImportSpecifier(options) {
13
+ const { projectRoot, clientFsPath } = options;
14
+ let clientImport = clientFsPath;
15
+ try {
16
+ const fsPosix = clientFsPath.replace(/\\/g, '/');
17
+ const rel = path.relative(projectRoot, clientFsPath);
18
+ const relPosix = rel.replace(/\\/g, '/');
19
+ if (path.isAbsolute(rel)) {
20
+ clientImport = pathToFileURL(clientFsPath).toString();
21
+ }
22
+ else {
23
+ // Prefer routing via the absolute fs path's `node_modules/...` tail. This
24
+ // covers monorepo / pnpm setups where node_modules is hoisted ABOVE the
25
+ // project root and `path.relative` would otherwise produce a
26
+ // "../../node_modules/..." specifier. That relative form is sent to the
27
+ // device's bootstrap as `__NS_BROWSER_RUNTIME_CLIENT_IMPORT__`, where the
28
+ // URL constructor resolves it against `${origin}/__ns_dev__/client` and
29
+ // collapses the leading `..` segments back to `${origin}/node_modules/...`.
30
+ // That URL bypasses the `/ns/m/` AST-normalizer pipeline (which strips
31
+ // browser-only `/@vite/client` imports), so the on-device HTTP loader
32
+ // eventually tries to fetch `/@vite/client` and fails with
33
+ // "HTTP import failed (status=0)" / "Instantiation failed (http-loader)".
34
+ const lastNm = fsPosix.lastIndexOf('/node_modules/');
35
+ if (lastNm !== -1) {
36
+ return `/ns/m${fsPosix.slice(lastNm)}`;
37
+ }
38
+ // Monorepo dist symlink (e.g. `"@nativescript/vite": "file:../../dist/packages/vite"`):
39
+ // require.resolve follows the node_modules symlink to its REAL path under
40
+ // the workspace root, which contains no `/node_modules/` segment. The
41
+ // `../../dist/...` relative form below would resolve on-device to
42
+ // `${origin}/dist/...`, which Vite's middleware 404s (outside root, not
43
+ // /@fs/). Route through /ns/m with a workspace-root-relative path so the
44
+ // fetch goes through the same served-module pipeline as everything else.
45
+ const wsRoot = getMonorepoWorkspaceRoot(projectRoot)?.replace(/\\/g, '/');
46
+ if (wsRoot && fsPosix.startsWith(wsRoot + '/')) {
47
+ return `/ns/m/${fsPosix.slice(wsRoot.length + 1)}`;
29
48
  }
49
+ const normalizedRel = (relPosix.startsWith('.') ? relPosix : `/${relPosix}`).replace(/\/+/g, '/');
50
+ clientImport = normalizedRel.startsWith('/node_modules/') ? `/ns/m${normalizedRel}` : normalizedRel;
30
51
  }
31
- catch { }
32
- return undefined;
52
+ }
53
+ catch {
54
+ clientImport = clientFsPath.replace(/\\/g, '/');
55
+ }
56
+ return clientImport;
57
+ }
58
+ export function resolveProjectMainEntryPath(projectRoot) {
59
+ try {
60
+ const packageJsonPath = path.join(projectRoot, 'package.json');
61
+ const raw = fs.readFileSync(packageJsonPath, 'utf-8');
62
+ const parsed = JSON.parse(raw);
63
+ const mainEntry = typeof parsed.main === 'string' && parsed.main ? parsed.main : 'src/app.ts';
64
+ const resolved = path.resolve(projectRoot, mainEntry);
65
+ const relative = path.relative(projectRoot, resolved).replace(/\\/g, '/');
66
+ return `/${relative}`.replace(/\/+/g, '/');
67
+ }
68
+ catch {
69
+ return '/src/app.ts';
70
+ }
71
+ }
72
+ export function createNsDevSessionDescriptor(options) {
73
+ const protocol = options.secure ? 'https' : 'http';
74
+ const wsProtocol = options.secure ? 'wss' : 'ws';
75
+ const origin = `${protocol}://${options.requestHost}`;
76
+ const entryPathname = options.mainEntryPathname || resolveProjectMainEntryPath(options.projectRoot);
77
+ // Canonical (untagged) entry URL. Boot-progress instrumentation is
78
+ // injected self-gating by the /ns/m module server (the snippet no-ops
79
+ // once `__NS_HMR_BOOT_COMPLETE__` flips), so the entry URL needs no
80
+ // `__ns_boot__` decoration — module identity IS the URL.
81
+ const canonicalEntryPathname = entryPathname.startsWith('/ns/m/') ? entryPathname : `/ns/m${entryPathname.startsWith('/') ? entryPathname : `/${entryPathname}`}`;
82
+ return {
83
+ sessionId: options.sessionId,
84
+ origin,
85
+ entryUrl: `${origin}${canonicalEntryPathname}`,
86
+ clientUrl: `${origin}/__ns_dev__/client`,
87
+ wsUrl: `${wsProtocol}://${options.requestHost}/ns-hmr`,
88
+ platform: options.platform,
89
+ runtimeConfigUrl: `${origin}/ns/import-map.json`,
90
+ hostModules: [...NS_DEFAULT_HOST_MODULES],
91
+ features: { ...NS_DEFAULT_DEV_FEATURE_FLAGS },
33
92
  };
93
+ }
94
+ function resolveBootstrapImportUrl(origin, clientImport) {
95
+ const normalizedOrigin = origin.replace(/\/$/, '');
96
+ if (!clientImport) {
97
+ return clientImport;
98
+ }
99
+ if (/^(?:https?|file):\/\//i.test(clientImport)) {
100
+ return clientImport;
101
+ }
102
+ if (clientImport.startsWith('/')) {
103
+ return `${normalizedOrigin}${clientImport}`;
104
+ }
105
+ try {
106
+ return new URL(clientImport, `${normalizedOrigin}/__ns_dev__/client`).toString();
107
+ }
108
+ catch {
109
+ return clientImport;
110
+ }
111
+ }
112
+ export function createNsDevClientBootstrapCode(options) {
113
+ const normalizedOrigin = options.origin.replace(/\/$/, '');
114
+ const resolvedClientImport = resolveBootstrapImportUrl(normalizedOrigin, options.clientImport);
115
+ const vendorBundleUrl = `${normalizedOrigin}/@nativescript/vendor.mjs`;
116
+ const vendorBootstrapUrl = `${normalizedOrigin}/ns/m/node_modules/@nativescript/vite/hmr/shared/runtime/vendor-bootstrap.js`;
117
+ const resolvedHotContextImport = resolveBootstrapImportUrl(normalizedOrigin, options.hotContextImport || '/ns/m/node_modules/@nativescript/vite/hmr/client/hot-context.js');
118
+ const entryRuntimeUrl = `${normalizedOrigin}/ns/m/node_modules/@nativescript/vite/hmr/entry-runtime.js`;
119
+ const cssHandlerUrl = `${normalizedOrigin}/ns/m/node_modules/@nativescript/vite/hmr/client/css-handler.js`;
120
+ // Canonical, unversioned core-bridge URL (see helpers/ns-core-url.ts) — the
121
+ // app graph already loaded this exact URL during boot, so importing it here
122
+ // resolves to the SAME module record/realm instead of minting a new one.
123
+ const coreBridgeUrl = `${normalizedOrigin}/ns/core`;
124
+ const launchBridgeUrl = `${normalizedOrigin}/ns/m/node_modules/@nativescript/vite/hmr/shared/runtime/launch-bridge.js`;
125
+ return `
126
+ import { installVendorBootstrap as __nsBrowserRuntimeInstallVendorBootstrap } from ${JSON.stringify(vendorBootstrapUrl)};
127
+ import { vendorManifest as __nsBrowserRuntimeVendorManifest, __nsVendorModuleMap as __nsBrowserRuntimeVendorModuleMap } from ${JSON.stringify(vendorBundleUrl)};
128
+ import { installNsHotRegistry as __nsBrowserRuntimeInstallHotRegistry } from ${JSON.stringify(resolvedHotContextImport)};
129
+ import { installLaunchNotificationBridge as __nsBrowserRuntimeInstallLaunchBridge } from ${JSON.stringify(launchBridgeUrl)};
130
+ import * as __nsBrowserRuntimeCoreBridge from ${JSON.stringify(coreBridgeUrl)};
131
+
132
+ // Launch-notification bridge — must precede the app entry (this wrapper is
133
+ // imported by the session bootstrap BEFORE the entry graph). Passing the
134
+ // /ns/core realm's Application: that is the instance app code gets, and the
135
+ // only deterministic wrap point (the full HMR client evaluates async and
136
+ // loses the race against the entry). See shared/runtime/launch-bridge.ts.
137
+ try {
138
+ const __nsCoreNs = __nsBrowserRuntimeCoreBridge && (__nsBrowserRuntimeCoreBridge.default ?? __nsBrowserRuntimeCoreBridge);
139
+ __nsBrowserRuntimeInstallLaunchBridge(__nsCoreNs && __nsCoreNs.Application);
140
+ } catch (launchBridgeErr) {
141
+ console.warn('[ns-browser-runtime-client] launch-notification bridge install failed', launchBridgeErr);
142
+ }
143
+
144
+ // Install the JS hot registry FIRST: every served app module's injected
145
+ // prelude reads globalThis.__NS_HOT_REGISTRY__ at evaluation time, and this
146
+ // bootstrap is imported before the entry graph (see session-bootstrap.ts).
147
+ try {
148
+ __nsBrowserRuntimeInstallHotRegistry();
149
+ } catch (hotErr) {
150
+ console.warn('[ns-browser-runtime-client] failed to install hot registry', hotErr);
151
+ }
152
+
153
+ const __NS_BROWSER_RUNTIME_WS_URL__ = ${JSON.stringify(options.wsUrl)};
154
+ const __NS_BROWSER_RUNTIME_ORIGIN__ = ${JSON.stringify(options.origin)};
155
+ const __NS_BROWSER_RUNTIME_CLIENT_IMPORT__ = ${JSON.stringify(resolvedClientImport)};
156
+ const __NS_BROWSER_RUNTIME_VERBOSE__ = ${options.verbose ? 'true' : 'false'};
157
+ let __nsBrowserRuntimeHmrClientStartPromise;
158
+ let __nsBrowserRuntimeSocket;
159
+ let __nsBrowserRuntimeSocketReconnectTimer;
160
+ let __nsBrowserRuntimeDelegationTimer;
161
+ let __nsBrowserRuntimeDelegationWarningIssued = false;
162
+ let __nsBrowserRuntimeBootWaitWarningIssued = false;
163
+
164
+ function __nsBrowserRuntimeWithSocketRole(url, role) {
165
+ try {
166
+ const resolved = new URL(url);
167
+ resolved.searchParams.set('ns_hmr_role', role);
168
+ return resolved.toString();
169
+ } catch {
170
+ const sep = url.includes('?') ? '&' : '?';
171
+ return url + sep + 'ns_hmr_role=' + encodeURIComponent(role);
172
+ }
173
+ }
174
+
175
+ const __NS_BROWSER_RUNTIME_FALLBACK_WS_URL__ = __nsBrowserRuntimeWithSocketRole(__NS_BROWSER_RUNTIME_WS_URL__, 'bootstrap');
176
+ const __NS_BROWSER_RUNTIME_FULL_CLIENT_WS_URL__ = __nsBrowserRuntimeWithSocketRole(__NS_BROWSER_RUNTIME_WS_URL__, 'full');
177
+
178
+ function __nsBrowserRuntimeEnsureVendorBootstrap() {
179
+ __nsBrowserRuntimeInstallVendorBootstrap(__nsBrowserRuntimeVendorManifest, __nsBrowserRuntimeVendorModuleMap, __NS_BROWSER_RUNTIME_VERBOSE__);
180
+ const registry = globalThis.__nsVendorRegistry;
181
+ if (!(registry && typeof registry.get === 'function')) {
182
+ throw new Error('NativeScript vendor registry was not initialized');
183
+ }
184
+ }
185
+
186
+ // Pure-JS CSS apply for the bootstrap fallback client. Prefers the HTTP
187
+ // core realm applier installed by the entry runtime
188
+ // (__NS_HMR_APPLY_CSS__), then falls back to Application.addCss through
189
+ // the vendor realm. No native CSS hook exists anymore.
190
+ function __nsBrowserRuntimeApplyCss(cssText) {
191
+ if (typeof cssText !== 'string' || !cssText.length) {
192
+ return false;
193
+ }
194
+ try {
195
+ const applyInCoreRealm = globalThis.__NS_HMR_APPLY_CSS__;
196
+ if (typeof applyInCoreRealm === 'function') {
197
+ applyInCoreRealm(cssText, true);
198
+ return true;
199
+ }
200
+ } catch (cssErr) {
201
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
202
+ console.warn('[ns-browser-runtime-client] __NS_HMR_APPLY_CSS__ threw', cssErr);
203
+ }
204
+ }
205
+ try {
206
+ const registry = globalThis.__nsVendorRegistry;
207
+ const coreMod = registry && typeof registry.get === 'function' ? registry.get('@nativescript/core') : null;
208
+ const core = (coreMod && (coreMod.default || coreMod)) || coreMod;
209
+ const Application = core && core.Application;
210
+ if (Application && typeof Application.addCss === 'function') {
211
+ Application.addCss(cssText);
212
+ try {
213
+ const rootView = typeof Application.getRootView === 'function' ? Application.getRootView() : null;
214
+ if (rootView && typeof rootView._onCssStateChange === 'function') {
215
+ rootView._onCssStateChange();
216
+ }
217
+ } catch {}
218
+ return true;
219
+ }
220
+ } catch (cssErr) {
221
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
222
+ console.warn('[ns-browser-runtime-client] Application.addCss fallback threw', cssErr);
223
+ }
224
+ }
225
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
226
+ console.warn('[ns-browser-runtime-client] no CSS applier available; skipping CSS update');
227
+ }
228
+ return false;
229
+ }
230
+
231
+ async function __nsBrowserRuntimeInstallHttpCoreCssApplier() {
232
+ // Monorepo / per-module core dev boots ship a minimal vendor bundle with NO
233
+ // @nativescript/core, so neither quick applier above exists. Install the
234
+ // same HTTP-core-realm applier the http-bootloader fallback path uses
235
+ // (entry-runtime's installHttpCoreCssSupport): it prefers the pre-parsed
236
+ // app.css AST (globalThis.__NS_HMR_APP_CSS_AST__), applies the seeded CSS,
237
+ // flips __NS_HMR_HTTP_APP_CSS_APPLIED__, and installs __NS_HMR_APPLY_CSS__
238
+ // so later live CSS edits land in the core realm the app actually uses.
239
+ try {
240
+ const entryRuntime = await import(${JSON.stringify(entryRuntimeUrl)});
241
+ const installHttpCoreCssSupport = entryRuntime && entryRuntime.installHttpCoreCssSupport;
242
+ if (typeof installHttpCoreCssSupport !== 'function') {
243
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
244
+ console.warn('[ns-browser-runtime-client] entry runtime is missing installHttpCoreCssSupport; skipping CSS install');
245
+ }
246
+ return false;
247
+ }
248
+ const coreBridge = await import(${JSON.stringify(coreBridgeUrl)});
249
+ const applier = installHttpCoreCssSupport(coreBridge, __NS_BROWSER_RUNTIME_VERBOSE__);
250
+ if (applier && __NS_BROWSER_RUNTIME_VERBOSE__) {
251
+ console.info('[ns-entry] app.css applied in HTTP core realm');
252
+ }
253
+ return !!applier;
254
+ } catch (cssErr) {
255
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
256
+ console.warn('[ns-browser-runtime-client] HTTP core realm CSS install failed', cssErr);
257
+ }
258
+ return false;
259
+ }
260
+ }
261
+
262
+ async function __nsBrowserRuntimeReplaySeededCss() {
263
+ const cssText = globalThis.__NS_HMR_APP_CSS__;
264
+ if (typeof cssText !== 'string' || !cssText.length || globalThis.__NS_HMR_HTTP_APP_CSS_APPLIED__) {
265
+ return;
266
+ }
267
+ if (__nsBrowserRuntimeApplyCss(cssText)) {
268
+ globalThis.__NS_HMR_HTTP_APP_CSS_APPLIED__ = true;
269
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
270
+ console.info('[ns-entry] app.css applied in HTTP core realm');
271
+ }
272
+ return;
273
+ }
274
+ await __nsBrowserRuntimeInstallHttpCoreCssApplier();
275
+ }
276
+
277
+ async function __nsBrowserRuntimeFetchText(url) {
278
+ try {
279
+ if (typeof globalThis.fetch === 'function') {
280
+ const res = await globalThis.fetch(url);
281
+ return await res.text();
282
+ }
283
+ const Http = globalThis.Http;
284
+ if (Http && typeof Http.getString === 'function') {
285
+ return await Http.getString(url);
286
+ }
287
+ } catch (error) {
288
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
289
+ console.warn('[ns-browser-runtime-client] failed to fetch text', url, error);
290
+ }
291
+ }
292
+ return '';
293
+ }
294
+
295
+ let __nsBrowserRuntimeCssHandlerPromise;
296
+ function __nsBrowserRuntimeLoadCssHandler() {
297
+ if (!__nsBrowserRuntimeCssHandlerPromise) {
298
+ __nsBrowserRuntimeCssHandlerPromise = import(${JSON.stringify(cssHandlerUrl)}).catch((error) => {
299
+ // Allow a retry on the next update instead of caching the failure.
300
+ __nsBrowserRuntimeCssHandlerPromise = undefined;
301
+ throw error;
302
+ });
303
+ }
304
+ return __nsBrowserRuntimeCssHandlerPromise;
305
+ }
306
+
307
+ async function __nsBrowserRuntimeHandleCssUpdates(msg) {
308
+ const updates = Array.isArray(msg?.updates) ? msg.updates : [];
309
+ if (!updates.length) {
310
+ return;
311
+ }
312
+ // Delegate to the shared client css-handler — the ONE fetch+apply pipeline
313
+ // for bootstrap and full client alike, honoring per-update tags (a
314
+ // component styleUrls update must replace under its own tag; the inline
315
+ // applier below only knows the global stylesheet).
316
+ try {
317
+ const cssHandler = await __nsBrowserRuntimeLoadCssHandler();
318
+ if (cssHandler && typeof cssHandler.handleCssUpdates === 'function') {
319
+ await cssHandler.handleCssUpdates(updates, __NS_BROWSER_RUNTIME_ORIGIN__);
320
+ return;
321
+ }
322
+ } catch (cssHandlerErr) {
323
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
324
+ console.warn('[ns-browser-runtime-client] shared css-handler unavailable; using inline fallback', cssHandlerErr);
325
+ }
326
+ }
327
+ // Inline fallback (css-handler import failed): GLOBAL updates only. The
328
+ // inline applier replaces under the global app.css tag, so applying a
329
+ // component-tagged update here would clobber the global stylesheet.
330
+ for (const update of updates) {
331
+ if (update && typeof update.tag === 'string' && update.tag) {
332
+ console.warn('[ns-browser-runtime-client] skipped component CSS update (tagged applier unavailable):', update.tag);
333
+ continue;
334
+ }
335
+ const cssPath = update?.path || update?.acceptedPath || '';
336
+ if (!cssPath) {
337
+ continue;
338
+ }
339
+ const timestamp = update?.timestamp || Date.now();
340
+ const sep = cssPath.includes('?') ? '&' : '?';
341
+ const url = __NS_BROWSER_RUNTIME_ORIGIN__ + cssPath + sep + 'direct=1&t=' + String(timestamp);
342
+ const cssText = await __nsBrowserRuntimeFetchText(url);
343
+ if (typeof cssText === 'string' && cssText.length) {
344
+ __nsBrowserRuntimeApplyCss(cssText);
345
+ }
346
+ }
347
+ }
348
+
349
+ function __nsBrowserRuntimeHandleAngularUpdate() {
350
+ const reboot = globalThis.__reboot_ng_modules__;
351
+ if (typeof reboot !== 'function') {
352
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
353
+ console.warn('[ns-browser-runtime-client] Angular reboot hook unavailable');
354
+ }
355
+ return;
356
+ }
357
+ try {
358
+ globalThis.__NS_HMR_IMPORT_NONCE__ = (typeof globalThis.__NS_HMR_IMPORT_NONCE__ === 'number' ? globalThis.__NS_HMR_IMPORT_NONCE__ : 0) + 1;
359
+ } catch {}
360
+ try {
361
+ globalThis.__NS_DEV_RESET_IN_PROGRESS__ = true;
362
+ } catch {}
363
+ try {
364
+ reboot(false);
365
+ } finally {
366
+ try {
367
+ globalThis.__NS_DEV_RESET_IN_PROGRESS__ = false;
368
+ } catch {}
369
+ }
370
+ }
371
+
372
+ function __nsBrowserRuntimeHandleSocketMessage(msg) {
373
+ if (!msg || typeof msg.type !== 'string') {
374
+ return;
375
+ }
376
+ if (msg.type === 'ns:hmr-full-graph') {
377
+ globalThis.__NS_HMR_BROWSER_RUNTIME_GRAPH_VERSION__ = typeof msg.version === 'number' ? msg.version : 0;
378
+ return;
379
+ }
380
+ if (globalThis.__NS_HMR_BROWSER_RUNTIME_DELEGATED__) {
381
+ return;
382
+ }
383
+ if (msg.type === 'ns:angular-update') {
384
+ __nsBrowserRuntimeHandleAngularUpdate();
385
+ return;
386
+ }
387
+ if (msg.type === 'ns:css-updates') {
388
+ void __nsBrowserRuntimeHandleCssUpdates(msg);
389
+ }
390
+ }
391
+
392
+ function __nsBrowserRuntimeScheduleReconnect() {
393
+ if (__nsBrowserRuntimeSocketReconnectTimer) {
394
+ return;
395
+ }
396
+ __nsBrowserRuntimeSocketReconnectTimer = setTimeout(() => {
397
+ __nsBrowserRuntimeSocketReconnectTimer = null;
398
+ __nsBrowserRuntimeConnectSocket();
399
+ }, 1000);
400
+ }
401
+
402
+ function __nsBrowserRuntimeClearDelegationTimer() {
403
+ if (__nsBrowserRuntimeDelegationTimer) {
404
+ clearTimeout(__nsBrowserRuntimeDelegationTimer);
405
+ __nsBrowserRuntimeDelegationTimer = null;
406
+ }
407
+ }
408
+
409
+ function __nsBrowserRuntimeCloseFallbackSocket(reason) {
410
+ __nsBrowserRuntimeClearDelegationTimer();
411
+ const ws = __nsBrowserRuntimeSocket;
412
+ if (ws) {
413
+ try {
414
+ ws.onopen = null;
415
+ ws.onmessage = null;
416
+ ws.onerror = null;
417
+ ws.onclose = null;
418
+ } catch {}
419
+ try {
420
+ ws.close();
421
+ } catch {}
422
+ }
423
+ __nsBrowserRuntimeSocket = null;
424
+ globalThis.__NS_HMR_BROWSER_RUNTIME_SOCKET_READY__ = false;
425
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
426
+ console.info('[ns-browser-runtime-client] delegated to full HMR client; closing bootstrap fallback socket', reason || 'delegated');
427
+ }
428
+ }
429
+
430
+ function __nsBrowserRuntimeWaitForDelegation(startedAt) {
431
+ if (globalThis.__NS_HMR_BROWSER_RUNTIME_DELEGATED__) {
432
+ __nsBrowserRuntimeClearDelegationTimer();
433
+ return;
434
+ }
435
+ if (globalThis.__NS_HMR_CLIENT_SOCKET_READY__) {
436
+ globalThis.__NS_HMR_BROWSER_RUNTIME_DELEGATED__ = true;
437
+ __nsBrowserRuntimeCloseFallbackSocket('full-client-ready');
438
+ return;
439
+ }
440
+ if (!__nsBrowserRuntimeDelegationWarningIssued && Date.now() - startedAt >= 10000) {
441
+ __nsBrowserRuntimeDelegationWarningIssued = true;
442
+ // Verbose-only: the 10s threshold trips on every real Angular
443
+ // cold boot. The bootstrap fallback keeps running; the message
444
+ // is diagnostic, not actionable.
445
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
446
+ console.warn('[ns-browser-runtime-client] full HMR client did not confirm websocket readiness; keeping bootstrap fallback active');
447
+ }
448
+ __nsBrowserRuntimeClearDelegationTimer();
449
+ return;
450
+ }
451
+ __nsBrowserRuntimeDelegationTimer = setTimeout(() => {
452
+ __nsBrowserRuntimeDelegationTimer = null;
453
+ __nsBrowserRuntimeWaitForDelegation(startedAt);
454
+ }, 100);
455
+ }
456
+
457
+ function __nsBrowserRuntimeTrackDelegation() {
458
+ if (globalThis.__NS_HMR_BROWSER_RUNTIME_DELEGATED__) {
459
+ return;
460
+ }
461
+ __nsBrowserRuntimeDelegationWarningIssued = false;
462
+ __nsBrowserRuntimeClearDelegationTimer();
463
+ __nsBrowserRuntimeWaitForDelegation(Date.now());
464
+ }
465
+
466
+ function __nsBrowserRuntimeConnectSocket() {
467
+ const WebSocketCtor = globalThis.WebSocket;
468
+ if (typeof WebSocketCtor !== 'function') {
469
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
470
+ console.warn('[ns-browser-runtime-client] WebSocket API unavailable');
471
+ }
472
+ __nsBrowserRuntimeScheduleReconnect();
473
+ return;
474
+ }
475
+ try {
476
+ if (__nsBrowserRuntimeSocket) {
477
+ const readyState = __nsBrowserRuntimeSocket.readyState;
478
+ const openState = typeof __nsBrowserRuntimeSocket.OPEN === 'number' ? __nsBrowserRuntimeSocket.OPEN : 1;
479
+ const connectingState = typeof WebSocketCtor.CONNECTING === 'number' ? WebSocketCtor.CONNECTING : 0;
480
+ if (readyState === openState || readyState === connectingState) {
481
+ return;
482
+ }
483
+ }
484
+ const ws = new WebSocketCtor(__NS_BROWSER_RUNTIME_FALLBACK_WS_URL__);
485
+ __nsBrowserRuntimeSocket = ws;
486
+ ws.onopen = () => {
487
+ globalThis.__NS_HMR_BROWSER_RUNTIME_SOCKET_READY__ = true;
488
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
489
+ console.info('[ns-browser-runtime-client] connected', __NS_BROWSER_RUNTIME_FALLBACK_WS_URL__);
490
+ }
491
+ };
492
+ ws.onmessage = (event) => {
493
+ try {
494
+ const raw = typeof event?.data === 'string' ? event.data : String(event?.data || '');
495
+ if (!raw) {
496
+ return;
497
+ }
498
+ __nsBrowserRuntimeHandleSocketMessage(JSON.parse(raw));
499
+ } catch (error) {
500
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
501
+ console.warn('[ns-browser-runtime-client] failed to process websocket message', error);
502
+ }
503
+ }
504
+ };
505
+ ws.onerror = (error) => {
506
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
507
+ console.warn('[ns-browser-runtime-client] websocket error', error);
508
+ }
509
+ };
510
+ ws.onclose = () => {
511
+ if (__nsBrowserRuntimeSocket === ws) {
512
+ __nsBrowserRuntimeSocket = null;
513
+ }
514
+ globalThis.__NS_HMR_BROWSER_RUNTIME_SOCKET_READY__ = false;
515
+ __nsBrowserRuntimeScheduleReconnect();
516
+ };
517
+ } catch (error) {
518
+ console.warn('[ns-browser-runtime-client] failed to create websocket', error);
519
+ __nsBrowserRuntimeScheduleReconnect();
520
+ }
521
+ }
522
+
523
+ async function __nsBrowserRuntimeEnsureFullClientStarted() {
524
+ if (!__nsBrowserRuntimeHmrClientStartPromise) {
525
+ __nsBrowserRuntimeHmrClientStartPromise = import(__NS_BROWSER_RUNTIME_CLIENT_IMPORT__)
526
+ .then((mod) => {
527
+ const start = mod?.default;
528
+ if (typeof start !== 'function') {
529
+ throw new Error('NativeScript HMR client bootstrap is missing a default export');
530
+ }
531
+ start({ wsUrl: __NS_BROWSER_RUNTIME_FULL_CLIENT_WS_URL__ });
532
+ __nsBrowserRuntimeTrackDelegation();
533
+ })
534
+ .catch((error) => {
535
+ globalThis.__NS_HMR_BROWSER_RUNTIME_CLIENT_ACTIVE__ = false;
536
+ console.error('[ns-browser-runtime-client] failed to start full NativeScript HMR client', __NS_BROWSER_RUNTIME_CLIENT_IMPORT__, error);
537
+ throw error;
538
+ });
539
+ }
540
+ return __nsBrowserRuntimeHmrClientStartPromise;
541
+ }
542
+
543
+ __nsBrowserRuntimeEnsureVendorBootstrap();
544
+
545
+
546
+ if (!globalThis.__NS_HMR_BROWSER_RUNTIME_CLIENT_ACTIVE__) {
547
+ globalThis.__NS_HMR_BROWSER_RUNTIME_CLIENT_ACTIVE__ = true;
548
+ globalThis.__NS_HTTP_ORIGIN__ = __NS_BROWSER_RUNTIME_ORIGIN__;
549
+ __nsBrowserRuntimeConnectSocket();
550
+ const __nsBrowserRuntimeBootWaitStartedAt = Date.now();
551
+ const __nsBrowserRuntimeWaitForBoot = () => {
552
+ if (globalThis.__NS_HMR_BOOT_COMPLETE__) {
553
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
554
+ console.info('[ns-browser-runtime-client] boot complete observed; starting full HMR client');
555
+ }
556
+ void __nsBrowserRuntimeReplaySeededCss();
557
+ void __nsBrowserRuntimeEnsureFullClientStarted();
558
+ } else {
559
+ if (!__nsBrowserRuntimeBootWaitWarningIssued && Date.now() - __nsBrowserRuntimeBootWaitStartedAt >= 10000) {
560
+ __nsBrowserRuntimeBootWaitWarningIssued = true;
561
+ // Verbose-only: real Angular cold boots routinely take
562
+ // 15-30s through importing-main. The poller keeps watching
563
+ // __NS_HMR_BOOT_COMPLETE__; until it flips this looks like
564
+ // an error to users but is purely informational.
565
+ // (No backticks: this script body is embedded in a template
566
+ // literal in vite-plugin.ts.)
567
+ if (__NS_BROWSER_RUNTIME_VERBOSE__) {
568
+ console.warn('[ns-browser-runtime-client] boot completion was not observed; full HMR client start is still pending');
569
+ }
570
+ }
571
+ setTimeout(__nsBrowserRuntimeWaitForBoot, 100);
572
+ }
573
+ };
574
+ __nsBrowserRuntimeWaitForBoot();
575
+ }
576
+ `;
577
+ }
578
+ export function nsHmrClientVitePlugin(opts) {
579
+ let config;
580
+ const sessionId = new Date().toISOString();
34
581
  return {
35
582
  name: 'ns-hmr-client',
36
583
  configResolved(c) {
37
584
  config = c;
585
+ // Capture app-configured `__FOO__` defines so HMR-served modules get a
586
+ // const shim for them (Vite's text-substitution doesn't reach raw-served
587
+ // modules; without a shim a free `__FOO__` is mis-bound to /ns/rt → wrong
588
+ // value under HMR vs the production bundle). See setUserDefineEntries.
589
+ setUserDefineEntries(c.define);
38
590
  },
39
591
  resolveId(id) {
40
592
  if (id === VIRTUAL_ID)
41
593
  return RESOLVED_ID;
42
594
  return null;
43
595
  },
596
+ configureServer(server) {
597
+ server.middlewares.use((req, res, next) => {
598
+ try {
599
+ const url = new URL(req.url || '', 'http://localhost');
600
+ if (url.pathname === '/__ns_dev__/client') {
601
+ const requestHost = String(req.headers.host || 'localhost:5173');
602
+ const secure = !!config?.server?.https;
603
+ const origin = `${secure ? 'https' : 'http'}://${requestHost}`;
604
+ const wsUrl = `${secure ? 'wss' : 'ws'}://${requestHost}/ns-hmr`;
605
+ const clientFsPath = require.resolve('@nativescript/vite/hmr/client/index.js');
606
+ const projectRoot = config?.root || process.cwd();
607
+ const clientImport = computeClientImportSpecifier({ projectRoot, clientFsPath });
608
+ let hotContextImport;
609
+ try {
610
+ const hotContextFsPath = require.resolve('@nativescript/vite/hmr/client/hot-context.js');
611
+ hotContextImport = computeClientImportSpecifier({ projectRoot, clientFsPath: hotContextFsPath });
612
+ }
613
+ catch { }
614
+ const code = createNsDevClientBootstrapCode({
615
+ origin,
616
+ wsUrl,
617
+ clientImport,
618
+ hotContextImport,
619
+ verbose: opts.verbose,
620
+ });
621
+ res.setHeader('Access-Control-Allow-Origin', '*');
622
+ res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
623
+ if (req.method === 'OPTIONS') {
624
+ res.statusCode = 204;
625
+ res.end();
626
+ return;
627
+ }
628
+ res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
629
+ res.end(code);
630
+ return;
631
+ }
632
+ if (url.pathname !== '/__ns_dev__/session')
633
+ return next();
634
+ res.setHeader('Access-Control-Allow-Origin', '*');
635
+ res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
636
+ if (req.method === 'OPTIONS') {
637
+ res.statusCode = 204;
638
+ res.end();
639
+ return;
640
+ }
641
+ const descriptor = createNsDevSessionDescriptor({
642
+ projectRoot: config?.root || process.cwd(),
643
+ requestHost: String(req.headers.host || 'localhost:5173'),
644
+ platform: opts.platform,
645
+ sessionId,
646
+ secure: !!config?.server?.https,
647
+ });
648
+ res.setHeader('Content-Type', 'application/json');
649
+ res.end(JSON.stringify(descriptor, null, 2));
650
+ }
651
+ catch (error) {
652
+ res.statusCode = 500;
653
+ res.setHeader('Content-Type', 'application/json');
654
+ res.end(JSON.stringify({ error: error?.message || 'Failed to build NativeScript dev session descriptor' }));
655
+ }
656
+ });
657
+ },
44
658
  load(id) {
45
659
  if (id !== RESOLVED_ID)
46
660
  return null;
@@ -53,41 +667,24 @@ export function nsHmrClientVitePlugin(opts) {
53
667
  const clientFsPath = require.resolve('@nativescript/vite/hmr/client/index.js');
54
668
  // Prefer project root when available; otherwise fall back to cwd.
55
669
  const projectRoot = config?.root || process.cwd();
56
- let clientImport = clientFsPath;
57
- try {
58
- // Compute a project-relative POSIX path when possible. When `path.relative`
59
- // returns an absolute path (this can occur on Windows if roots differ or
60
- // when path.relative returns a drive-letter-prefixed path), avoid creating
61
- // a specifier like `/D:/...` which later gets resolved to `D:\D:\...`.
62
- const rel = path.relative(projectRoot, clientFsPath);
63
- const relPosix = rel.replace(/\\/g, '/');
64
- // If `rel` is absolute (e.g. starts with a drive letter on Windows),
65
- // use a file:// URL for the import so Vite/Rollup do not prepend the
66
- // project root and cause duplicated drive prefixes.
67
- if (path.isAbsolute(rel)) {
68
- clientImport = pathToFileURL(clientFsPath).toString();
69
- }
70
- else {
71
- clientImport = (relPosix.startsWith('.') ? relPosix : `/${relPosix}`).replace(/\/+/g, '/');
72
- }
73
- }
74
- catch {
75
- // On any failure, keep the original path but normalize to POSIX
76
- clientImport = clientFsPath.replace(/\\/g, '/');
77
- }
78
- // Build ws url from Vite server info
79
- let host = process.env.NS_HMR_HOST || config?.server?.host;
80
- // If Vite is bound to all interfaces, prefer a LAN IP so physical devices work.
81
- // The HMR client will still try emulator/localhost fallbacks when needed.
82
- const hostStr = typeof host === 'string' ? host : '';
83
- const isWildcard = host === true || hostStr === '0.0.0.0' || hostStr === '::' || hostStr === '';
84
- if (isWildcard) {
85
- host = guessLanHost() || (opts.platform === 'android' ? '10.0.2.2' : 'localhost');
86
- }
87
- else if (!host) {
88
- host = opts.platform === 'android' ? guessLanHost() || '10.0.2.2' : 'localhost';
89
- }
670
+ const clientImport = computeClientImportSpecifier({ projectRoot, clientFsPath });
671
+ // Build ws url from Vite server info. Routes through the same
672
+ // canonical helper as `main-entry.ts` / `base.ts` so the
673
+ // websocket endpoint embedded in `bundle.mjs` and every other
674
+ // `/ns/*` URL share one origin string — required by the iOS
675
+ // HTTP ESM cache identity rule, and necessary for Android
676
+ // emulators that can't reach `0.0.0.0` / `localhost`.
90
677
  const port = Number(config?.server?.port || 5173);
678
+ // Pass `port` through so the Android emulator path attempts
679
+ // `adb reverse tcp:<port> tcp:<port>` before falling back to
680
+ // `10.0.2.2`. The websocket URL and bundle.mjs URLs both
681
+ // flow from this same helper, so they stay byte-identical
682
+ // (required by the iOS HTTP ESM cache identity rule).
683
+ const { host } = resolveDeviceReachableHost({
684
+ host: config?.server?.host,
685
+ platform: opts.platform,
686
+ port,
687
+ });
91
688
  const secure = !!config?.server?.https;
92
689
  const protocol = secure ? 'wss' : 'ws';
93
690
  const wsUrl = `${protocol}://${host}:${port}/ns-hmr`;