@nativescript/vite 8.0.0-beta.0 → 8.0.0-dev.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 (586) hide show
  1. package/README.md +89 -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 +228 -78
  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/framework.d.ts +22 -0
  17. package/framework.js +18 -0
  18. package/framework.js.map +1 -0
  19. package/helpers/app-components.d.ts +2 -1
  20. package/helpers/app-components.js.map +1 -1
  21. package/helpers/app-css-refresh.d.ts +31 -0
  22. package/helpers/app-css-refresh.js +43 -0
  23. package/helpers/app-css-refresh.js.map +1 -0
  24. package/helpers/app-css-state.d.ts +17 -0
  25. package/helpers/app-css-state.js +51 -0
  26. package/helpers/app-css-state.js.map +1 -0
  27. package/helpers/bundler-context.d.ts +11 -0
  28. package/helpers/bundler-context.js +71 -0
  29. package/helpers/bundler-context.js.map +1 -0
  30. package/helpers/cli-flags.d.ts +12 -0
  31. package/helpers/cli-flags.js +34 -0
  32. package/helpers/cli-flags.js.map +1 -1
  33. package/helpers/commonjs-plugins.d.ts +5 -2
  34. package/helpers/commonjs-plugins.js +126 -0
  35. package/helpers/commonjs-plugins.js.map +1 -1
  36. package/helpers/config-as-json.js +10 -0
  37. package/helpers/config-as-json.js.map +1 -1
  38. package/helpers/css-platform-plugin.d.ts +14 -0
  39. package/helpers/css-platform-plugin.js +43 -25
  40. package/helpers/css-platform-plugin.js.map +1 -1
  41. package/helpers/dev-host.d.ts +360 -0
  42. package/helpers/dev-host.js +694 -0
  43. package/helpers/dev-host.js.map +1 -0
  44. package/helpers/dynamic-import-plugin.d.ts +2 -1
  45. package/helpers/dynamic-import-plugin.js +59 -53
  46. package/helpers/dynamic-import-plugin.js.map +1 -1
  47. package/helpers/esbuild-platform-resolver.js +9 -6
  48. package/helpers/esbuild-platform-resolver.js.map +1 -1
  49. package/helpers/external-configs.d.ts +10 -4
  50. package/helpers/external-configs.js +63 -15
  51. package/helpers/external-configs.js.map +1 -1
  52. package/helpers/flavor.d.ts +31 -0
  53. package/helpers/flavor.js +53 -2
  54. package/helpers/flavor.js.map +1 -1
  55. package/helpers/global-defines.d.ts +118 -0
  56. package/helpers/global-defines.js +214 -11
  57. package/helpers/global-defines.js.map +1 -1
  58. package/helpers/hmr-scope.d.ts +26 -0
  59. package/helpers/hmr-scope.js +67 -0
  60. package/helpers/hmr-scope.js.map +1 -0
  61. package/helpers/import-meta-path.d.ts +4 -0
  62. package/helpers/import-meta-path.js +5 -0
  63. package/helpers/import-meta-path.js.map +1 -0
  64. package/helpers/import-specifier.d.ts +1 -0
  65. package/helpers/import-specifier.js +18 -0
  66. package/helpers/import-specifier.js.map +1 -0
  67. package/helpers/init.js +24 -26
  68. package/helpers/init.js.map +1 -1
  69. package/helpers/logging.d.ts +12 -1
  70. package/helpers/logging.js +81 -5
  71. package/helpers/logging.js.map +1 -1
  72. package/helpers/main-entry.d.ts +8 -2
  73. package/helpers/main-entry.js +622 -120
  74. package/helpers/main-entry.js.map +1 -1
  75. package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
  76. package/helpers/nativeclass-esbuild-plugin.js +6 -1
  77. package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
  78. package/helpers/nativeclass-transform.d.ts +13 -0
  79. package/helpers/nativeclass-transform.js +42 -131
  80. package/helpers/nativeclass-transform.js.map +1 -1
  81. package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
  82. package/helpers/nativeclass-transformer-plugin.js +324 -37
  83. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  84. package/helpers/nativescript-package-resolver.js +10 -62
  85. package/helpers/nativescript-package-resolver.js.map +1 -1
  86. package/helpers/normalize-id.d.ts +42 -0
  87. package/helpers/normalize-id.js +60 -0
  88. package/helpers/normalize-id.js.map +1 -0
  89. package/helpers/ns-core-external-urls.d.ts +32 -0
  90. package/helpers/ns-core-external-urls.js +107 -0
  91. package/helpers/ns-core-external-urls.js.map +1 -0
  92. package/helpers/ns-core-url.d.ts +106 -0
  93. package/helpers/ns-core-url.js +225 -0
  94. package/helpers/ns-core-url.js.map +1 -0
  95. package/helpers/optimize-deps.d.ts +16 -0
  96. package/helpers/optimize-deps.js +17 -0
  97. package/helpers/optimize-deps.js.map +1 -0
  98. package/helpers/package-platform-aliases.js +34 -49
  99. package/helpers/package-platform-aliases.js.map +1 -1
  100. package/helpers/platform-types.d.ts +2 -0
  101. package/helpers/platform-types.js +2 -0
  102. package/helpers/platform-types.js.map +1 -0
  103. package/helpers/postcss-platform-config.d.ts +17 -1
  104. package/helpers/postcss-platform-config.js +20 -37
  105. package/helpers/postcss-platform-config.js.map +1 -1
  106. package/helpers/project.d.ts +35 -0
  107. package/helpers/project.js +120 -2
  108. package/helpers/project.js.map +1 -1
  109. package/helpers/resolve-main-field-platform.d.ts +20 -0
  110. package/helpers/resolve-main-field-platform.js +49 -0
  111. package/helpers/resolve-main-field-platform.js.map +1 -0
  112. package/helpers/resolver.js +17 -2
  113. package/helpers/resolver.js.map +1 -1
  114. package/helpers/theme-core-plugins.js +1 -1
  115. package/helpers/theme-core-plugins.js.map +1 -1
  116. package/helpers/ts-config-paths.d.ts +32 -0
  117. package/helpers/ts-config-paths.js +156 -27
  118. package/helpers/ts-config-paths.js.map +1 -1
  119. package/helpers/typescript-check.d.ts +3 -3
  120. package/helpers/typescript-check.js +4 -4
  121. package/helpers/typescript-check.js.map +1 -1
  122. package/helpers/ui-registration.d.ts +21 -0
  123. package/helpers/ui-registration.js +156 -0
  124. package/helpers/ui-registration.js.map +1 -0
  125. package/helpers/utils.d.ts +9 -0
  126. package/helpers/utils.js +22 -2
  127. package/helpers/utils.js.map +1 -1
  128. package/helpers/vite-package-version.d.ts +7 -0
  129. package/helpers/vite-package-version.js +44 -0
  130. package/helpers/vite-package-version.js.map +1 -0
  131. package/helpers/workers.d.ts +40 -19
  132. package/helpers/workers.js +312 -13
  133. package/helpers/workers.js.map +1 -1
  134. package/hmr/client/css-handler.d.ts +2 -1
  135. package/hmr/client/css-handler.js +95 -23
  136. package/hmr/client/css-handler.js.map +1 -1
  137. package/hmr/client/css-update-overlay.d.ts +18 -0
  138. package/hmr/client/css-update-overlay.js +27 -0
  139. package/hmr/client/css-update-overlay.js.map +1 -0
  140. package/hmr/client/framework-client-strategy.d.ts +117 -0
  141. package/hmr/client/framework-client-strategy.js +18 -0
  142. package/hmr/client/framework-client-strategy.js.map +1 -0
  143. package/hmr/client/framework.d.ts +31 -0
  144. package/hmr/client/framework.js +17 -0
  145. package/hmr/client/framework.js.map +1 -0
  146. package/hmr/client/hmr-pending-overlay.d.ts +13 -0
  147. package/hmr/client/hmr-pending-overlay.js +41 -0
  148. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  149. package/hmr/client/hot-context.d.ts +89 -0
  150. package/hmr/client/hot-context.js +404 -0
  151. package/hmr/client/hot-context.js.map +1 -0
  152. package/hmr/client/index.d.ts +9 -1
  153. package/hmr/client/index.js +91 -1418
  154. package/hmr/client/index.js.map +1 -1
  155. package/hmr/client/overlay-driver.d.ts +10 -0
  156. package/hmr/client/overlay-driver.js +33 -0
  157. package/hmr/client/overlay-driver.js.map +1 -0
  158. package/hmr/client/protocol-dispatch.d.ts +8 -0
  159. package/hmr/client/protocol-dispatch.js +308 -0
  160. package/hmr/client/protocol-dispatch.js.map +1 -0
  161. package/hmr/client/root-reset.d.ts +15 -0
  162. package/hmr/client/root-reset.js +358 -0
  163. package/hmr/client/root-reset.js.map +1 -0
  164. package/hmr/client/strategy-loader.d.ts +24 -0
  165. package/hmr/client/strategy-loader.js +136 -0
  166. package/hmr/client/strategy-loader.js.map +1 -0
  167. package/hmr/client/update-pipeline.d.ts +27 -0
  168. package/hmr/client/update-pipeline.js +489 -0
  169. package/hmr/client/update-pipeline.js.map +1 -0
  170. package/hmr/client/utils.d.ts +14 -1
  171. package/hmr/client/utils.js +265 -54
  172. package/hmr/client/utils.js.map +1 -1
  173. package/hmr/client/ws-transport.d.ts +21 -0
  174. package/hmr/client/ws-transport.js +323 -0
  175. package/hmr/client/ws-transport.js.map +1 -0
  176. package/hmr/entry-runtime.d.ts +11 -0
  177. package/hmr/entry-runtime.js +566 -43
  178. package/hmr/entry-runtime.js.map +1 -1
  179. package/hmr/framework-flavors.d.ts +59 -0
  180. package/hmr/framework-flavors.js +108 -0
  181. package/hmr/framework-flavors.js.map +1 -0
  182. package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
  183. package/hmr/frameworks/angular/build/angular-linker.js +113 -0
  184. package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
  185. package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
  186. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
  187. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
  188. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
  189. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
  190. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
  191. package/hmr/frameworks/angular/build/inline-decorator-component-templates.d.ts +3 -0
  192. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js +231 -0
  193. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
  194. package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
  195. package/hmr/frameworks/angular/build/js-lexer.js +182 -0
  196. package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
  197. package/hmr/frameworks/angular/build/linker-stats.d.ts +18 -0
  198. package/hmr/frameworks/angular/build/linker-stats.js +29 -0
  199. package/hmr/frameworks/angular/build/linker-stats.js.map +1 -0
  200. package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
  201. package/hmr/frameworks/angular/build/shared-linker.js +128 -0
  202. package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
  203. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.d.ts +1 -0
  204. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
  205. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
  206. package/hmr/frameworks/angular/build/synthesize-injectable-factories.d.ts +3 -0
  207. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js +241 -0
  208. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
  209. package/hmr/frameworks/angular/build/ts-fallback-transform.d.ts +5 -0
  210. package/hmr/frameworks/angular/build/ts-fallback-transform.js +138 -0
  211. package/hmr/frameworks/angular/build/ts-fallback-transform.js.map +1 -0
  212. package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
  213. package/hmr/frameworks/angular/build/util.js +155 -0
  214. package/hmr/frameworks/angular/build/util.js.map +1 -0
  215. package/hmr/frameworks/angular/build/worker-url-preserve.d.ts +5 -0
  216. package/hmr/frameworks/angular/build/worker-url-preserve.js +140 -0
  217. package/hmr/frameworks/angular/build/worker-url-preserve.js.map +1 -0
  218. package/hmr/frameworks/angular/client/index.d.ts +2 -1
  219. package/hmr/frameworks/angular/client/index.js +637 -23
  220. package/hmr/frameworks/angular/client/index.js.map +1 -1
  221. package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
  222. package/hmr/frameworks/angular/client/strategy.js +19 -0
  223. package/hmr/frameworks/angular/client/strategy.js.map +1 -0
  224. package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
  225. package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
  226. package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
  227. package/hmr/frameworks/angular/server/linker.js +37 -6
  228. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  229. package/hmr/frameworks/angular/server/ng-component-route.d.ts +43 -0
  230. package/hmr/frameworks/angular/server/ng-component-route.js +113 -0
  231. package/hmr/frameworks/angular/server/ng-component-route.js.map +1 -0
  232. package/hmr/frameworks/angular/server/strategy.js +697 -18
  233. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  234. package/hmr/frameworks/angular/server/websocket-angular-entry.d.ts +2 -0
  235. package/hmr/frameworks/angular/server/websocket-angular-entry.js +68 -0
  236. package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
  237. package/hmr/frameworks/angular/server/websocket-angular-hot-update.d.ts +94 -0
  238. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +485 -0
  239. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
  240. package/hmr/frameworks/react/client/strategy.d.ts +12 -0
  241. package/hmr/frameworks/react/client/strategy.js +27 -0
  242. package/hmr/frameworks/react/client/strategy.js.map +1 -0
  243. package/hmr/frameworks/react/server/strategy.d.ts +2 -0
  244. package/hmr/frameworks/react/server/strategy.js +230 -0
  245. package/hmr/frameworks/react/server/strategy.js.map +1 -0
  246. package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
  247. package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
  248. package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
  249. package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
  250. package/hmr/frameworks/solid/client/app-runtime.js +252 -0
  251. package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
  252. package/hmr/frameworks/solid/client/strategy.d.ts +7 -0
  253. package/hmr/frameworks/solid/client/strategy.js +391 -0
  254. package/hmr/frameworks/solid/client/strategy.js.map +1 -0
  255. package/hmr/frameworks/solid/server/strategy.js +293 -16
  256. package/hmr/frameworks/solid/server/strategy.js.map +1 -1
  257. package/hmr/frameworks/typescript/client/strategy.d.ts +7 -0
  258. package/hmr/frameworks/typescript/client/strategy.js +418 -0
  259. package/hmr/frameworks/typescript/client/strategy.js.map +1 -0
  260. package/hmr/frameworks/typescript/server/strategy.js +48 -16
  261. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  262. package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
  263. package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
  264. package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
  265. package/hmr/frameworks/vue/client/index.d.ts +10 -1
  266. package/hmr/frameworks/vue/client/index.js +287 -562
  267. package/hmr/frameworks/vue/client/index.js.map +1 -1
  268. package/hmr/frameworks/vue/client/navigate-app.d.ts +3 -0
  269. package/hmr/frameworks/vue/client/navigate-app.js +178 -0
  270. package/hmr/frameworks/vue/client/navigate-app.js.map +1 -0
  271. package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
  272. package/hmr/frameworks/vue/client/strategy.js +152 -0
  273. package/hmr/frameworks/vue/client/strategy.js.map +1 -0
  274. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
  275. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +124 -0
  276. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
  277. package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
  278. package/hmr/frameworks/vue/server/compiler.js +3 -1
  279. package/hmr/frameworks/vue/server/compiler.js.map +1 -1
  280. package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
  281. package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
  282. package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
  283. package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
  284. package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
  285. package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
  286. package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
  287. package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
  288. package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
  289. package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
  290. package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
  291. package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
  292. package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
  293. package/hmr/frameworks/vue/server/strategy.js +291 -7
  294. package/hmr/frameworks/vue/server/strategy.js.map +1 -1
  295. package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
  296. package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
  297. package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
  298. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  299. package/hmr/helpers/ast-normalizer.js +131 -24
  300. package/hmr/helpers/ast-normalizer.js.map +1 -1
  301. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  302. package/hmr/helpers/cjs-named-exports.js +152 -0
  303. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  304. package/hmr/helpers/package-exports.d.ts +16 -0
  305. package/hmr/helpers/package-exports.js +396 -0
  306. package/hmr/helpers/package-exports.js.map +1 -0
  307. package/hmr/helpers/vendor-rewrite.d.ts +1 -1
  308. package/hmr/helpers/vendor-rewrite.js +5 -3
  309. package/hmr/helpers/vendor-rewrite.js.map +1 -1
  310. package/hmr/server/boot-recording.d.ts +51 -0
  311. package/hmr/server/boot-recording.js +214 -0
  312. package/hmr/server/boot-recording.js.map +1 -0
  313. package/hmr/server/constants.d.ts +1 -0
  314. package/hmr/server/constants.js +21 -4
  315. package/hmr/server/constants.js.map +1 -1
  316. package/hmr/server/content-css-update.d.ts +54 -0
  317. package/hmr/server/content-css-update.js +78 -0
  318. package/hmr/server/content-css-update.js.map +1 -0
  319. package/hmr/server/core-bundle.d.ts +140 -0
  320. package/hmr/server/core-bundle.js +614 -0
  321. package/hmr/server/core-bundle.js.map +1 -0
  322. package/hmr/server/core-sanitize.d.ts +130 -4
  323. package/hmr/server/core-sanitize.js +393 -32
  324. package/hmr/server/core-sanitize.js.map +1 -1
  325. package/hmr/server/css-connect-sync.d.ts +28 -0
  326. package/hmr/server/css-connect-sync.js +59 -0
  327. package/hmr/server/css-connect-sync.js.map +1 -0
  328. package/hmr/server/css-device-module.d.ts +28 -0
  329. package/hmr/server/css-device-module.js +44 -0
  330. package/hmr/server/css-device-module.js.map +1 -0
  331. package/hmr/server/css-update-message.d.ts +23 -0
  332. package/hmr/server/css-update-message.js +41 -0
  333. package/hmr/server/css-update-message.js.map +1 -0
  334. package/hmr/server/deps-bundle.d.ts +233 -0
  335. package/hmr/server/deps-bundle.js +1022 -0
  336. package/hmr/server/deps-bundle.js.map +1 -0
  337. package/hmr/server/device-transform-helpers.d.ts +24 -0
  338. package/hmr/server/device-transform-helpers.js +408 -0
  339. package/hmr/server/device-transform-helpers.js.map +1 -0
  340. package/hmr/server/framework-strategy.d.ts +182 -11
  341. package/hmr/server/hmr-module-graph.d.ts +37 -0
  342. package/hmr/server/hmr-module-graph.js +215 -0
  343. package/hmr/server/hmr-module-graph.js.map +1 -0
  344. package/hmr/server/import-map.d.ts +99 -0
  345. package/hmr/server/import-map.js +294 -0
  346. package/hmr/server/import-map.js.map +1 -0
  347. package/hmr/server/index.d.ts +2 -1
  348. package/hmr/server/index.js +7 -16
  349. package/hmr/server/index.js.map +1 -1
  350. package/hmr/server/node-builtins-route.d.ts +12 -0
  351. package/hmr/server/node-builtins-route.js +86 -0
  352. package/hmr/server/node-builtins-route.js.map +1 -0
  353. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  354. package/hmr/server/ns-core-cjs-shape.js +271 -0
  355. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  356. package/hmr/server/ns-m-response-memo.d.ts +10 -0
  357. package/hmr/server/ns-m-response-memo.js +33 -0
  358. package/hmr/server/ns-m-response-memo.js.map +1 -0
  359. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  360. package/hmr/server/ns-rt-bridge.js +131 -0
  361. package/hmr/server/ns-rt-bridge.js.map +1 -0
  362. package/hmr/server/ns-rt-route.d.ts +5 -0
  363. package/hmr/server/ns-rt-route.js +39 -0
  364. package/hmr/server/ns-rt-route.js.map +1 -0
  365. package/hmr/server/perf-instrumentation.d.ts +114 -0
  366. package/hmr/server/perf-instrumentation.js +197 -0
  367. package/hmr/server/perf-instrumentation.js.map +1 -0
  368. package/hmr/server/process-code-for-device.d.ts +54 -0
  369. package/hmr/server/process-code-for-device.js +832 -0
  370. package/hmr/server/process-code-for-device.js.map +1 -0
  371. package/hmr/server/require-guard.d.ts +1 -0
  372. package/hmr/server/require-guard.js +12 -0
  373. package/hmr/server/require-guard.js.map +1 -0
  374. package/hmr/server/rewrite-imports.d.ts +2 -0
  375. package/hmr/server/rewrite-imports.js +631 -0
  376. package/hmr/server/rewrite-imports.js.map +1 -0
  377. package/hmr/server/route-helpers.d.ts +7 -0
  378. package/hmr/server/route-helpers.js +13 -0
  379. package/hmr/server/route-helpers.js.map +1 -0
  380. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  381. package/hmr/server/runtime-graph-filter.js +28 -0
  382. package/hmr/server/runtime-graph-filter.js.map +1 -0
  383. package/hmr/server/server-origin.d.ts +2 -0
  384. package/hmr/server/server-origin.js +88 -0
  385. package/hmr/server/server-origin.js.map +1 -0
  386. package/hmr/server/shared-transform-request.d.ts +12 -0
  387. package/hmr/server/shared-transform-request.js +143 -0
  388. package/hmr/server/shared-transform-request.js.map +1 -0
  389. package/hmr/server/socket-utils.d.ts +10 -0
  390. package/hmr/server/socket-utils.js +14 -0
  391. package/hmr/server/socket-utils.js.map +1 -0
  392. package/hmr/server/transform-cache-invalidation.d.ts +37 -0
  393. package/hmr/server/transform-cache-invalidation.js +156 -0
  394. package/hmr/server/transform-cache-invalidation.js.map +1 -0
  395. package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
  396. package/hmr/server/vendor-bare-module-shims.js +80 -0
  397. package/hmr/server/vendor-bare-module-shims.js.map +1 -0
  398. package/hmr/server/vite-plugin.d.ts +22 -1
  399. package/hmr/server/vite-plugin.js +655 -58
  400. package/hmr/server/vite-plugin.js.map +1 -1
  401. package/hmr/server/websocket-core-bridge.d.ts +68 -0
  402. package/hmr/server/websocket-core-bridge.js +370 -0
  403. package/hmr/server/websocket-core-bridge.js.map +1 -0
  404. package/hmr/server/websocket-device-transform.d.ts +3 -0
  405. package/hmr/server/websocket-device-transform.js +7 -0
  406. package/hmr/server/websocket-device-transform.js.map +1 -0
  407. package/hmr/server/websocket-graph-upsert.d.ts +21 -0
  408. package/hmr/server/websocket-graph-upsert.js +33 -0
  409. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  410. package/hmr/server/websocket-hmr-pending.d.ts +29 -0
  411. package/hmr/server/websocket-hmr-pending.js +33 -0
  412. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  413. package/hmr/server/websocket-hot-update.d.ts +80 -0
  414. package/hmr/server/websocket-hot-update.js +299 -0
  415. package/hmr/server/websocket-hot-update.js.map +1 -0
  416. package/hmr/server/websocket-import-map-route.d.ts +15 -0
  417. package/hmr/server/websocket-import-map-route.js +51 -0
  418. package/hmr/server/websocket-import-map-route.js.map +1 -0
  419. package/hmr/server/websocket-module-bindings.d.ts +21 -0
  420. package/hmr/server/websocket-module-bindings.js +504 -0
  421. package/hmr/server/websocket-module-bindings.js.map +1 -0
  422. package/hmr/server/websocket-module-specifiers.d.ts +98 -0
  423. package/hmr/server/websocket-module-specifiers.js +832 -0
  424. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  425. package/hmr/server/websocket-ns-core.d.ts +34 -0
  426. package/hmr/server/websocket-ns-core.js +414 -0
  427. package/hmr/server/websocket-ns-core.js.map +1 -0
  428. package/hmr/server/websocket-ns-entry.d.ts +21 -0
  429. package/hmr/server/websocket-ns-entry.js +163 -0
  430. package/hmr/server/websocket-ns-entry.js.map +1 -0
  431. package/hmr/server/websocket-ns-m-paths.d.ts +19 -0
  432. package/hmr/server/websocket-ns-m-paths.js +115 -0
  433. package/hmr/server/websocket-ns-m-paths.js.map +1 -0
  434. package/hmr/server/websocket-ns-m-request.d.ts +46 -0
  435. package/hmr/server/websocket-ns-m-request.js +197 -0
  436. package/hmr/server/websocket-ns-m-request.js.map +1 -0
  437. package/hmr/server/websocket-ns-m.d.ts +52 -0
  438. package/hmr/server/websocket-ns-m.js +592 -0
  439. package/hmr/server/websocket-ns-m.js.map +1 -0
  440. package/hmr/server/websocket-served-module-helpers.d.ts +98 -0
  441. package/hmr/server/websocket-served-module-helpers.js +948 -0
  442. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  443. package/hmr/server/websocket-txn.d.ts +6 -0
  444. package/hmr/server/websocket-txn.js +42 -0
  445. package/hmr/server/websocket-txn.js.map +1 -0
  446. package/hmr/server/websocket-vendor-unifier.d.ts +9 -0
  447. package/hmr/server/websocket-vendor-unifier.js +46 -0
  448. package/hmr/server/websocket-vendor-unifier.js.map +1 -0
  449. package/hmr/server/websocket.d.ts +6 -17
  450. package/hmr/server/websocket.js +723 -5376
  451. package/hmr/server/websocket.js.map +1 -1
  452. package/hmr/shared/ns-globals.d.ts +108 -0
  453. package/hmr/shared/ns-globals.js +29 -0
  454. package/hmr/shared/ns-globals.js.map +1 -0
  455. package/hmr/shared/package-classifier.d.ts +9 -0
  456. package/hmr/shared/package-classifier.js +58 -0
  457. package/hmr/shared/package-classifier.js.map +1 -0
  458. package/hmr/shared/protocol.d.ts +157 -0
  459. package/hmr/shared/protocol.js +28 -0
  460. package/hmr/shared/protocol.js.map +1 -0
  461. package/hmr/shared/runtime/boot-complete.d.ts +14 -0
  462. package/hmr/shared/runtime/boot-complete.js +32 -0
  463. package/hmr/shared/runtime/boot-complete.js.map +1 -0
  464. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  465. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  466. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  467. package/hmr/shared/runtime/boot-progress.d.ts +44 -0
  468. package/hmr/shared/runtime/boot-progress.js +134 -0
  469. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  470. package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
  471. package/hmr/shared/runtime/boot-timeline.js +40 -0
  472. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  473. package/hmr/shared/runtime/browser-runtime-contract.d.ts +97 -0
  474. package/hmr/shared/runtime/browser-runtime-contract.js +66 -0
  475. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  476. package/hmr/shared/runtime/dev-overlay-ios.d.ts +87 -0
  477. package/hmr/shared/runtime/dev-overlay-ios.js +521 -0
  478. package/hmr/shared/runtime/dev-overlay-ios.js.map +1 -0
  479. package/hmr/shared/runtime/dev-overlay-shared.d.ts +58 -0
  480. package/hmr/shared/runtime/dev-overlay-shared.js +116 -0
  481. package/hmr/shared/runtime/dev-overlay-shared.js.map +1 -0
  482. package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
  483. package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
  484. package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
  485. package/hmr/shared/runtime/dev-overlay-tree.d.ts +59 -0
  486. package/hmr/shared/runtime/dev-overlay-tree.js +712 -0
  487. package/hmr/shared/runtime/dev-overlay-tree.js.map +1 -0
  488. package/hmr/shared/runtime/dev-overlay.d.ts +39 -0
  489. package/hmr/shared/runtime/dev-overlay.js +292 -0
  490. package/hmr/shared/runtime/dev-overlay.js.map +1 -0
  491. package/hmr/shared/runtime/global-scope.d.ts +18 -0
  492. package/hmr/shared/runtime/global-scope.js +21 -0
  493. package/hmr/shared/runtime/global-scope.js.map +1 -0
  494. package/hmr/shared/runtime/hooks.js +2 -1
  495. package/hmr/shared/runtime/hooks.js.map +1 -1
  496. package/hmr/shared/runtime/launch-bridge.d.ts +9 -0
  497. package/hmr/shared/runtime/launch-bridge.js +98 -0
  498. package/hmr/shared/runtime/launch-bridge.js.map +1 -0
  499. package/hmr/shared/runtime/module-provenance.d.ts +1 -0
  500. package/hmr/shared/runtime/module-provenance.js +64 -0
  501. package/hmr/shared/runtime/module-provenance.js.map +1 -0
  502. package/hmr/shared/runtime/ns-runtime-test-double.d.ts +21 -0
  503. package/hmr/shared/runtime/ns-runtime-test-double.js +20 -0
  504. package/hmr/shared/runtime/ns-runtime-test-double.js.map +1 -0
  505. package/hmr/shared/runtime/overlay-flag.d.ts +9 -0
  506. package/hmr/shared/runtime/overlay-flag.js +34 -0
  507. package/hmr/shared/runtime/overlay-flag.js.map +1 -0
  508. package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
  509. package/hmr/shared/runtime/platform-polyfills.js +122 -0
  510. package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
  511. package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
  512. package/hmr/shared/runtime/root-placeholder-view.js +311 -0
  513. package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
  514. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  515. package/hmr/shared/runtime/root-placeholder.js +778 -83
  516. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  517. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  518. package/hmr/shared/runtime/session-bootstrap.js +350 -0
  519. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  520. package/hmr/shared/runtime/vendor-bootstrap.js +54 -16
  521. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  522. package/hmr/shared/runtime/vendor-resolve.d.ts +22 -0
  523. package/hmr/shared/runtime/vendor-resolve.js +45 -0
  524. package/hmr/shared/runtime/vendor-resolve.js.map +1 -0
  525. package/hmr/shared/runtime/worker-tracking.d.ts +28 -0
  526. package/hmr/shared/runtime/worker-tracking.js +114 -0
  527. package/hmr/shared/runtime/worker-tracking.js.map +1 -0
  528. package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
  529. package/hmr/shared/vendor/manifest-collect.js +909 -0
  530. package/hmr/shared/vendor/manifest-collect.js.map +1 -0
  531. package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
  532. package/hmr/shared/vendor/manifest-loader.js +5 -3
  533. package/hmr/shared/vendor/manifest-loader.js.map +1 -1
  534. package/hmr/shared/vendor/manifest.d.ts +12 -0
  535. package/hmr/shared/vendor/manifest.js +341 -545
  536. package/hmr/shared/vendor/manifest.js.map +1 -1
  537. package/hmr/shared/vendor/registry.d.ts +2 -0
  538. package/hmr/shared/vendor/registry.js +118 -7
  539. package/hmr/shared/vendor/registry.js.map +1 -1
  540. package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
  541. package/hmr/shared/vendor/vendor-device-shim.js +208 -0
  542. package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
  543. package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +107 -0
  544. package/hmr/shared/vendor/vendor-esbuild-plugins.js +540 -0
  545. package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
  546. package/index.d.ts +1 -0
  547. package/index.js +5 -0
  548. package/index.js.map +1 -1
  549. package/package.json +83 -14
  550. package/runtime/core-aliases-early.js +103 -81
  551. package/runtime/core-aliases-early.js.map +1 -1
  552. package/shims/react-jsx-runtime.d.ts +4 -0
  553. package/shims/react-jsx-runtime.js +61 -0
  554. package/shims/react-jsx-runtime.js.map +1 -0
  555. package/shims/solid-jsx-runtime.d.ts +7 -0
  556. package/shims/solid-jsx-runtime.js +17 -0
  557. package/shims/solid-jsx-runtime.js.map +1 -0
  558. package/helpers/angular/angular-linker.d.ts +0 -13
  559. package/helpers/angular/angular-linker.js +0 -189
  560. package/helpers/angular/angular-linker.js.map +0 -1
  561. package/helpers/angular/shared-linker.d.ts +0 -4
  562. package/helpers/angular/shared-linker.js +0 -39
  563. package/helpers/angular/shared-linker.js.map +0 -1
  564. package/helpers/angular/util.js +0 -67
  565. package/helpers/angular/util.js.map +0 -1
  566. package/helpers/module-runner-patch.d.ts +0 -3
  567. package/helpers/module-runner-patch.js +0 -63
  568. package/helpers/module-runner-patch.js.map +0 -1
  569. package/helpers/prelink-angular.d.ts +0 -2
  570. package/helpers/prelink-angular.js +0 -117
  571. package/helpers/prelink-angular.js.map +0 -1
  572. package/hmr/shared/runtime/http-only-boot.d.ts +0 -1
  573. package/hmr/shared/runtime/http-only-boot.js +0 -124
  574. package/hmr/shared/runtime/http-only-boot.js.map +0 -1
  575. package/hmr/vendor-bootstrap.d.ts +0 -3
  576. package/hmr/vendor-bootstrap.js +0 -32
  577. package/hmr/vendor-bootstrap.js.map +0 -1
  578. package/shims/react-reconciler-constants.d.ts +0 -14
  579. package/shims/react-reconciler-constants.js +0 -21
  580. package/shims/react-reconciler-constants.js.map +0 -1
  581. package/shims/react-reconciler.d.ts +0 -8
  582. package/shims/react-reconciler.js +0 -15
  583. package/shims/react-reconciler.js.map +0 -1
  584. package/transformers/NativeClass/index.d.ts +0 -2
  585. package/transformers/NativeClass/index.js +0 -222
  586. package/transformers/NativeClass/index.js.map +0 -1
@@ -1,10 +1,18 @@
1
1
  import { getPackageJson, getProjectFilePath, getProjectRootPath } from './project.js';
2
2
  import fs from 'fs';
3
- import os from 'os';
4
3
  import path from 'path';
4
+ import { preprocessCSS } from 'vite';
5
+ import { parse as parseCssToAst } from 'css';
5
6
  import { getProjectFlavor } from './flavor.js';
6
- import { getProjectAppPath, getProjectAppRelativePath, getProjectAppVirtualPath } from './utils.js';
7
+ import { getProjectAppPath, getProjectAppRelativePath, getProjectAppVirtualPath, resolveProjectGlobalCssPath } from './utils.js';
7
8
  import { getResolvedAppComponents } from './app-components.js';
9
+ import { toStaticImportSpecifier } from './import-specifier.js';
10
+ import { buildCoreUrl } from './ns-core-url.js';
11
+ import { resolveDeviceReachableOrigin } from './dev-host.js';
12
+ import { setAppCssState } from './app-css-state.js';
13
+ import { createAppCssRefresher } from './app-css-refresh.js';
14
+ import { rewritePlatformCssImports } from './css-platform-plugin.js';
15
+ import { buildGlobalSeedStatements, getRuntimeSeedValues } from './global-defines.js';
8
16
  // Switched to runtime modules to avoid fragile string injection and enable TS checks
9
17
  const projectRoot = getProjectRootPath();
10
18
  const appRootDir = getProjectAppPath();
@@ -21,6 +29,7 @@ const mainEntryRelPosix = (() => {
21
29
  return getProjectAppVirtualPath('app.ts');
22
30
  }
23
31
  })();
32
+ const mainEntryImportSpecifier = toStaticImportSpecifier(projectRoot, mainEntry);
24
33
  const flavor = getProjectFlavor();
25
34
  // Optional polyfills support (non-HMR specific but dev friendly)
26
35
  // Resolve polyfills relative to the main entry directory so it works both for standalone projects and monorepos/workspaces where the workspace root and app root differ.
@@ -41,56 +50,556 @@ const polyfillsImportSpecifier = (() => {
41
50
  })();
42
51
  const VIRTUAL_ID = 'virtual:entry-with-polyfills';
43
52
  const RESOLVED = '\0' + VIRTUAL_ID;
53
+ const APP_CSS_VIRTUAL_ID = 'virtual:ns-app-css';
54
+ const APP_CSS_RESOLVED = '\0' + APP_CSS_VIRTUAL_ID;
55
+ // Build-only applier for SFC `<style>` + JS/TS-imported `.css`/`.scss` that Vite
56
+ // extracts into a CSS asset. NativeScript has no DOM to `<link>` it, so the
57
+ // `--no-hmr` build would otherwise drop those styles (HMR applies them at
58
+ // runtime). `load` emits the apply with a sentinel; `generateBundle` rewrites it
59
+ // to the collected rework-CSS AST (the form `app.css` uses). Replaces the per-app
60
+ // `nsSfcStylesPlugin` workaround — apps no longer need their own.
61
+ const BUNDLE_CSS_VIRTUAL_ID = 'virtual:ns-bundle-css';
62
+ const BUNDLE_CSS_RESOLVED = '\0' + BUNDLE_CSS_VIRTUAL_ID;
63
+ const BUNDLE_CSS_AST_SENTINEL = '__NS_BUNDLE_CSS_AST__';
64
+ // Virtual module that installs the XHR polyfill from @nativescript/core/xhr.
65
+ // Rolldown tree-shakes the polyfill-xhr.ts side-effect import from @nativescript/core/globals,
66
+ // so XMLHttpRequest never gets registered as a global. This dedicated module ensures the XHR
67
+ // polyfill is installed during module evaluation (before zone.js patches run).
68
+ const XHR_POLYFILL_VIRTUAL_ID = 'virtual:ns-xhr-polyfill';
69
+ const XHR_POLYFILL_RESOLVED = '\0' + XHR_POLYFILL_VIRTUAL_ID;
70
+ // Virtual module that seeds compile-time defines (`__APPLE__`, `__IOS__`,
71
+ // `__DEV__`, etc.) on `globalThis` BEFORE any other module evaluates.
72
+ //
73
+ // Why this exists. The per-module shim that `processCodeForDevice` injects
74
+ // at the top of every served module reads these values from `globalThis`:
75
+ // const __APPLE__ = globalThis.__APPLE__ !== undefined
76
+ // ? globalThis.__APPLE__
77
+ // : (__IOS__ || __VISIONOS__);
78
+ // `const` evaluates ONCE at module instantiation. So every module needs
79
+ // `globalThis.__APPLE__` to already be set when it instantiates — otherwise
80
+ // it locks in `false` for the lifetime of the module.
81
+ //
82
+ // In ESM, all `import` statements hoist to the top of the module's
83
+ // evaluation phase: imports run in DFS post-order BEFORE the importing
84
+ // module's body. If we put the seed assignments inline in the entry's
85
+ // body (e.g. `globalThis.__APPLE__ = true`), they run AFTER every module
86
+ // transitively imported via `bundle-entry-points` (which reaches the
87
+ // user's `main.ts` → `app.module.ts` → services → util files). Those
88
+ // utility modules then snapshot `globalThis.__APPLE__ = undefined` and
89
+ // fall through to the `false` branch — landing iOS code in the
90
+ // `else { /* Android */ }` branch and crashing on `Utils.android.*`.
91
+ //
92
+ // The fix is to import this virtual module FIRST in the entry. As a leaf
93
+ // in the dependency graph it evaluates before every sibling import, so
94
+ // its body assignments happen before any user module instantiates and
95
+ // reads `globalThis.__*`. This is the architecturally-correct way to
96
+ // make values available to other modules across the import graph in ESM.
97
+ const DEFINES_SEED_VIRTUAL_ID = 'virtual:ns-defines-seed';
98
+ const DEFINES_SEED_RESOLVED = '\0' + DEFINES_SEED_VIRTUAL_ID;
44
99
  export function mainEntryPlugin(opts) {
100
+ let resolvedConfig;
101
+ // Prefer the flavor the active config DECLARES (threaded from baseConfig)
102
+ // over deps-based detection: in workspaces whose app package.json doesn't
103
+ // list the framework package (hoisted to the root), detection falls through
104
+ // to 'typescript' — which previously emitted the ts-only
105
+ // `virtual:ns-ui-registration` import into an Angular entry with no
106
+ // resolver registered, and seeded the wrong `__NS_TARGET_FLAVOR__`.
107
+ const effectiveFlavor = opts.flavor || flavor;
45
108
  return {
46
109
  name: 'main-entry',
110
+ configResolved(config) {
111
+ resolvedConfig = config;
112
+ },
113
+ // Fill the `virtual:ns-bundle-css` sentinel with the extracted CSS and drop
114
+ // the orphan asset (non-HMR builds only; HMR delivers this CSS at runtime).
115
+ generateBundle(_outputOptions, bundle) {
116
+ if (opts.hmrActive)
117
+ return;
118
+ try {
119
+ const cssAssets = Object.values(bundle).filter((f) => f && f.type === 'asset' && typeof f.fileName === 'string' && f.fileName.endsWith('.css'));
120
+ let cssText = '';
121
+ for (const a of cssAssets) {
122
+ const src = a.source;
123
+ cssText += (typeof src === 'string' ? src : new TextDecoder().decode(src)) + '\n';
124
+ }
125
+ // Rework AST, position-stripped (the form app.css uses; ~halves size).
126
+ const ast = parseCssToAst(cssText, { silent: true });
127
+ const astJson = JSON.stringify(ast, (key, value) => (key === 'position' ? undefined : value));
128
+ // Rewrite the sentinel in whichever chunk carries the applier.
129
+ const sentinelRe = new RegExp(`(['"])${BUNDLE_CSS_AST_SENTINEL}\\1`);
130
+ let replaced = false;
131
+ for (const file of Object.values(bundle)) {
132
+ if (file && file.type === 'chunk' && typeof file.code === 'string' && sentinelRe.test(file.code)) {
133
+ file.code = file.code.replace(sentinelRe, () => astJson);
134
+ replaced = true;
135
+ break;
136
+ }
137
+ }
138
+ // Drop the orphan asset only after its rules are applied above.
139
+ if (replaced) {
140
+ for (const a of cssAssets)
141
+ delete bundle[a.fileName];
142
+ }
143
+ if (opts.verbose) {
144
+ console.info(`[ns-entry] bundle CSS: ${cssAssets.length} asset(s), ${cssText.length} bytes, applied=${replaced}`);
145
+ }
146
+ }
147
+ catch (e) {
148
+ if (opts.verbose)
149
+ console.warn('[ns-entry] bundle CSS injection failed:', e?.message || e);
150
+ }
151
+ },
152
+ // Warm chokidar with `app.css`'s @import dependency tree at
153
+ // server startup. Without this, the FIRST save to a workspace
154
+ // `@import` dep (e.g. `<repo>/libs/.../index.css`) is silently
155
+ // dropped: nothing in the cold-boot path causes the dev server
156
+ // to transform `app.css`, so `vite:css` never registers
157
+ // `@import`-resolved deps with the watcher. Eagerly resolving
158
+ // them here breaks the chicken-and-egg.
159
+ //
160
+ // We ALSO stash the resolved dep set on the server itself so
161
+ // the HMR websocket handler can recognize when a non-CSS edit
162
+ // (e.g. a `.html` template or `.ts` file scanned by Tailwind's
163
+ // content config) should trigger a fresh `app.css` fetch. The
164
+ // `preprocessCSS` deps include every file PostCSS reported as
165
+ // a `dependency` message — for Tailwind 3 with content globs,
166
+ // Vite's `compileCSS` expands the `dir-dependency` glob into
167
+ // the individual file paths, so we get the full content set.
168
+ //
169
+ // `app.css` is NEVER a real Vite module in NS HMR (the virtual
170
+ // `:ns-app-css` module re-runs `preprocessCSS` in its load
171
+ // hook), so the standard moduleGraph `addWatchFile` →
172
+ // `_addedImports` → file-only-entry-importer chain doesn't
173
+ // populate, and `ctx.modules` for a content-file edit never
174
+ // links back to a CSS module. The dep set fills that gap.
175
+ configureServer(server) {
176
+ if (server.config.command !== 'serve')
177
+ return;
178
+ // Prefer `app.css`, fall back to `styles.css` (common in web projects).
179
+ const appCssPath = resolveProjectGlobalCssPath(projectRoot);
180
+ if (!appCssPath)
181
+ return;
182
+ const normalizeFsPath = (p) => path.resolve(p).replace(/\\/g, '/');
183
+ const normalizedAppCssPath = normalizeFsPath(appCssPath);
184
+ const watchedDeps = new Set([normalizedAppCssPath]);
185
+ // The refresher owns serialization, previous-output comparison, and the
186
+ // startup baseline (see helpers/app-css-refresh.ts). This thunk owns the
187
+ // generation itself plus the watcher/dep-set side effects of a scan.
188
+ const generate = async () => {
189
+ const rawCode = fs.readFileSync(appCssPath, 'utf-8');
190
+ // Same platform @import rewrite as the virtual:ns-app-css load hook —
191
+ // this raw read also bypasses the ns-css-platform transform.
192
+ const code = rewritePlatformCssImports(rawCode, path.dirname(appCssPath), opts.platform) ?? rawCode;
193
+ const result = await preprocessCSS(code, appCssPath, server.config);
194
+ server.watcher.add(appCssPath);
195
+ const next = new Set([normalizedAppCssPath]);
196
+ for (const dep of result?.deps ?? []) {
197
+ if (typeof dep === 'string' && dep) {
198
+ server.watcher.add(dep);
199
+ next.add(normalizeFsPath(dep));
200
+ }
201
+ }
202
+ // Atomic-ish replace: clear + repopulate the existing
203
+ // Set so any concurrent reader sees a consistent view
204
+ // when iterating with `.has()`.
205
+ watchedDeps.clear();
206
+ for (const f of next)
207
+ watchedDeps.add(f);
208
+ return result?.code ?? '';
209
+ };
210
+ const refresh = createAppCssRefresher({ generate, verbose: opts.verbose });
211
+ setAppCssState(server, { path: normalizedAppCssPath, deps: watchedDeps, refresh });
212
+ void refresh();
213
+ // Re-scan when `app.css` itself or a Tailwind config file
214
+ // changes — Tailwind's content list and utility definitions
215
+ // can both shift, so the dep set has to follow. Debounced
216
+ // because watcher events for the same edit can fire in
217
+ // quick succession (chokidar's atomic save handling).
218
+ let pendingRefresh = null;
219
+ const scheduleRefresh = () => {
220
+ if (pendingRefresh)
221
+ clearTimeout(pendingRefresh);
222
+ pendingRefresh = setTimeout(() => {
223
+ pendingRefresh = null;
224
+ void refresh();
225
+ }, 50);
226
+ };
227
+ const isAppCssOrTailwindConfig = (file) => {
228
+ const normalized = normalizeFsPath(file);
229
+ if (normalized === normalizedAppCssPath)
230
+ return true;
231
+ return /\/tailwind\.config\.[mc]?[jt]s$/.test(normalized);
232
+ };
233
+ server.watcher.on('change', (file) => {
234
+ if (isAppCssOrTailwindConfig(file))
235
+ scheduleRefresh();
236
+ });
237
+ // `add`/`unlink` cover Tailwind's content set growing or
238
+ // shrinking — new template files, deleted partials, etc.
239
+ // Re-running `preprocessCSS` is the safest way to keep the
240
+ // glob expansion accurate without re-implementing the
241
+ // match.
242
+ server.watcher.on('add', scheduleRefresh);
243
+ server.watcher.on('unlink', scheduleRefresh);
244
+ },
47
245
  resolveId(id) {
48
246
  if (id === VIRTUAL_ID)
49
247
  return RESOLVED;
248
+ if (id === APP_CSS_VIRTUAL_ID)
249
+ return APP_CSS_RESOLVED;
250
+ if (id === BUNDLE_CSS_VIRTUAL_ID)
251
+ return BUNDLE_CSS_RESOLVED;
252
+ if (id === XHR_POLYFILL_VIRTUAL_ID)
253
+ return XHR_POLYFILL_RESOLVED;
254
+ if (id === DEFINES_SEED_VIRTUAL_ID)
255
+ return DEFINES_SEED_RESOLVED;
50
256
  return null;
51
257
  },
52
- load(id) {
258
+ async load(id) {
259
+ // Compute the dev server origin for HMR mode. Under HMR we emit
260
+ // `@nativescript/core*` imports as FULL HTTP URLs so iOS's ESM loader
261
+ // can fetch them directly during bundle.mjs module instantiation —
262
+ // the import map isn't installed yet at that phase. For non-HMR
263
+ // builds, we keep bare specifiers so production bundlers inline core
264
+ // the normal way.
265
+ //
266
+ // Pre-configure invariant. bundle.mjs is a local ES module entry, so
267
+ // its static import graph is fetched and keyed by the runtime BEFORE
268
+ // its body runs `configureLoader` (session-bootstrap). Unconfigured,
269
+ // the runtime keys an HTTP module by its URL verbatim (fragment
270
+ // stripped, nothing else). Every URL reachable from this entry's
271
+ // static graph must therefore be canonical on its own — absolute,
272
+ // query-free, resolvable without the import map — or the same module
273
+ // requested after configuration lands under a second registry key
274
+ // and evaluates twice. The /ns/core bridge URLs satisfy this
275
+ // (`buildCoreUrl` emits no query, and the bridge shims import only
276
+ // `/ns/core-bundle.mjs`); anything served through /ns/m must be
277
+ // reached from the dev session, after configuration.
278
+ //
279
+ // Routes through `resolveDeviceReachableOrigin` so the URL baked
280
+ // into the bundle is something the DEVICE can reach: wildcard
281
+ // binds (`0.0.0.0`) and Android loopback get remapped to a real
282
+ // LAN IP (preferred) or the platform's reachable fallback
283
+ // (`10.0.2.2` for the Android emulator). Without this, Android
284
+ // crashes at boot trying to fetch `http://0.0.0.0:5173/ns/core/xhr`.
285
+ const getBootOrigin = () => {
286
+ if (!opts.hmrActive)
287
+ return null;
288
+ try {
289
+ const { origin } = resolveDeviceReachableOrigin({
290
+ host: resolvedConfig.server.host,
291
+ platform: opts.platform,
292
+ protocol: resolvedConfig.server.https || opts.useHttps ? 'https' : 'http',
293
+ port: Number(resolvedConfig.server.port || 5173),
294
+ });
295
+ return origin;
296
+ }
297
+ catch {
298
+ return null;
299
+ }
300
+ };
301
+ // Return a spec string for @nativescript/core or a subpath that is
302
+ // guaranteed to resolve at iOS module-instantiation time. Under HMR
303
+ // this is always a full HTTP URL into the /ns/core bridge (no
304
+ // import-map dependency). Under non-HMR it's the bare specifier for
305
+ // the bundler to handle.
306
+ //
307
+ // Under HMR, delegates to buildCoreUrl() — the ONE canonical URL
308
+ // generator. Every URL emitter in the build/runtime pipeline (this
309
+ // function, ns-core-external-urls, rewriteSpec, runtime import map)
310
+ // uses the same function so iOS's HTTP ESM cache sees byte-identical
311
+ // URLs.
312
+ const coreSpec = (subpath) => {
313
+ const origin = getBootOrigin();
314
+ if (origin) {
315
+ return buildCoreUrl(origin, subpath);
316
+ }
317
+ const sub = subpath ? String(subpath).replace(/^\/+/, '') : '';
318
+ return sub ? `@nativescript/core/${sub}` : '@nativescript/core';
319
+ };
320
+ // Virtual module that processes app.css through PostCSS/Tailwind and emits a
321
+ // JS module that BOTH applies the CSS as a side-effect AND exports the raw
322
+ // CSS string as default.
323
+ //
324
+ // Background: Vite's default `?inline` CSS handling collides with
325
+ // @analogjs/vite-plugin-angular's load hook in Vite 8 (it converts ?inline
326
+ // CSS to JS without setting moduleType:'js', so vite:css still tries to run
327
+ // PostCSS on the JS output). This virtual module sidesteps that.
328
+ //
329
+ // We still export the raw CSS string as default so the entry can seed
330
+ // `globalThis.__NS_HMR_APP_CSS__` for HMR's HTTP-core-realm replay path.
331
+ //
332
+ // We always pre-parse with rework `css` and either:
333
+ // - non-HMR: call `addTaggedAdditionalCSS(astJson, 'app.css')` directly
334
+ // so the bundled `style-scope` realm gets the styles before any view
335
+ // is created.
336
+ // - HMR: stash the AST on `globalThis.__NS_HMR_APP_CSS_AST__` so
337
+ // `installHttpCoreCssSupport` can apply it via the SAME AST path
338
+ // in the HTTP-core realm. Without this, the HTTP path would fall
339
+ // back to applying the raw text via `cssTreeParse` at runtime,
340
+ // which has produced subtle behavioral mismatches with the rework
341
+ // AST (e.g. `.text-sm { line-height: 20 }` rendering with extra
342
+ // line spacing under HMR but not under the no-HMR rolldown
343
+ // bundle, even though both bundles serialize the identical
344
+ // declaration). Pre-parsing once at build time and shipping the
345
+ // AST to BOTH paths keeps cold-boot rendering identical between
346
+ // the two modes. Live HMR edits still arrive as raw text via the
347
+ // dev-server WebSocket, so `installHttpCoreCssSupport` keeps the
348
+ // raw-text fallback for that case.
349
+ if (id === APP_CSS_RESOLVED) {
350
+ // Same resolver as the entry generator (app.css → styles.css fallback)
351
+ // so both always pick the same file. Only reached when a global
352
+ // stylesheet exists, but guard defensively against a mid-session delete.
353
+ const appCssPath = resolveProjectGlobalCssPath(projectRoot);
354
+ if (!appCssPath) {
355
+ return { code: 'export default "";', moduleType: 'js' };
356
+ }
357
+ const rawCode = fs.readFileSync(appCssPath, 'utf-8');
358
+ // Rewrite platform-suffixed @imports (foo.css -> foo.ios.css) BEFORE
359
+ // preprocessCSS: this raw read bypasses the plugin transform chain, so
360
+ // the ns-css-platform plugin never sees this content, and Vite's
361
+ // internal postcss-import (which runs ahead of any user postcss
362
+ // plugins) can't resolve the generic specifier on its own.
363
+ const code = rewritePlatformCssImports(rawCode, path.dirname(appCssPath), opts.platform) ?? rawCode;
364
+ const result = await preprocessCSS(code, appCssPath, resolvedConfig);
365
+ const ast = parseCssToAst(result.code, { silent: true });
366
+ // `css` emits `position` metadata on every AST node. NS doesn't
367
+ // use it, and stripping it ~halves the inlined JSON size — same
368
+ // thing webpack's css2json-loader does.
369
+ const astJson = JSON.stringify(ast, (key, value) => (key === 'position' ? undefined : value));
370
+ const lines = [];
371
+ if (opts.hmrActive) {
372
+ // Stash AST on globalThis BEFORE the entry seeds
373
+ // `__NS_HMR_APP_CSS__` from this module's default export, so
374
+ // `installHttpCoreCssSupport` can prefer the AST and match
375
+ // the no-HMR application path exactly.
376
+ lines.push(`try { (globalThis).__NS_HMR_APP_CSS_AST__ = ${astJson}; } catch {}`);
377
+ }
378
+ else {
379
+ lines.push(`import { addTaggedAdditionalCSS } from ${JSON.stringify(coreSpec('ui/styling/style-scope'))};`, `addTaggedAdditionalCSS(${astJson}, 'app.css');`);
380
+ }
381
+ lines.push(`export default ${JSON.stringify(result.code)};`);
382
+ return {
383
+ code: lines.join('\n'),
384
+ moduleType: 'js',
385
+ };
386
+ }
387
+ // Emit the bundle-CSS apply with a sentinel that generateBundle fills in
388
+ // (the CSS isn't known until then). No-op under HMR (dev server applies
389
+ // it at runtime, and the entry skips this import in HMR mode).
390
+ if (id === BUNDLE_CSS_RESOLVED) {
391
+ if (opts.hmrActive) {
392
+ return { code: 'export default "";', moduleType: 'js' };
393
+ }
394
+ return {
395
+ code: [`import { addTaggedAdditionalCSS } from ${JSON.stringify(coreSpec('ui/styling/style-scope'))};`, `try { addTaggedAdditionalCSS(${JSON.stringify(BUNDLE_CSS_AST_SENTINEL)}, 'ns-bundle-css'); } catch (e) {}`, `export default "";`].join('\n'),
396
+ moduleType: 'js',
397
+ };
398
+ }
399
+ // Virtual module that installs XHR polyfill. Its module body runs during import evaluation,
400
+ // guaranteeing XMLHttpRequest is on globalThis before zone.js or any other code accesses it.
401
+ if (id === XHR_POLYFILL_RESOLVED) {
402
+ return {
403
+ code: [`import * as xhrImpl from ${JSON.stringify(coreSpec('xhr'))};`, "var polyfills = ['XMLHttpRequest','FormData','Blob','File','FileReader'];", 'for (var i = 0; i < polyfills.length; i++) {', ' var n = polyfills[i];', ' if (!(n in globalThis) && xhrImpl[n]) globalThis[n] = xhrImpl[n];', '}'].join('\n'),
404
+ moduleType: 'js',
405
+ };
406
+ }
407
+ // Virtual module that seeds compile-time defines on globalThis.
408
+ // Imported FIRST in the entry so it evaluates as a leaf before
409
+ // any other module — including the `bundle-entry-points` chain
410
+ // that transitively reaches the user's app code. See the
411
+ // DEFINES_SEED_VIRTUAL_ID comment at the top of this file.
412
+ if (id === DEFINES_SEED_RESOLVED) {
413
+ // The FULL seed map: canonical platform defines (shared with Vite's
414
+ // `define` config and the dev server's per-module shims) PLUS every
415
+ // `__NS_*__` value raw-served client files consume (runtime flavor,
416
+ // app-root paths, overlay knobs). Vite's define substitution
417
+ // never reaches those raw-served files, so anything they read must be
418
+ // planted on globalThis here — see getRuntimeSeedValues for the rule.
419
+ const seedLines = buildGlobalSeedStatements(getRuntimeSeedValues({ platform: opts.platform, isDevMode: opts.isDevMode, verbose: opts.verbose, flavor: effectiveFlavor, isCI: !!process.env.CI }));
420
+ return {
421
+ code: seedLines.join('\n') + '\n',
422
+ moduleType: 'js',
423
+ };
424
+ }
53
425
  if (id !== RESOLVED)
54
426
  return null;
427
+ let imports = '';
428
+ // Under HMR: import the defines-seed virtual module FIRST so its
429
+ // body — which sets `globalThis.__APPLE__`, `__IOS__`, `__DEV__`,
430
+ // etc. — evaluates as a leaf in the dependency graph BEFORE any
431
+ // other module instantiates. Per-module shims injected by
432
+ // `processCodeForDevice` read these from globalThis and snapshot
433
+ // them at instantiation time, so they MUST be set first.
434
+ //
435
+ // Under non-HMR: Vite's `define` config handles substitution
436
+ // statically at build time — no runtime seeding needed.
437
+ if (opts.hmrActive) {
438
+ imports += `import '${DEFINES_SEED_VIRTUAL_ID}';\n`;
439
+ }
55
440
  // consistent verbose flag to easily reference below
56
- let imports = "const __nsVerboseLog = typeof __NS_ENV_VERBOSE__ !== 'undefined' && __NS_ENV_VERBOSE__;\n";
57
- // Ensure any CommonJS-style tooling requires (e.g. from Babel or other
58
- // build-time libraries that may be accidentally bundled) do not attempt
59
- // to resolve Node built-ins like 'fs' or 'path' on device. These modules
60
- // are not used at runtime for NativeScript apps, so we safely return an
61
- // empty object from a global require shim when present.
62
- imports += "try { if (typeof globalThis !== 'undefined') { globalThis.require = function () { return {}; }; } } catch {}\n";
441
+ imports += "const __nsVerboseLog = typeof __NS_ENV_VERBOSE__ !== 'undefined' && __NS_ENV_VERBOSE__;\n";
442
+ // Ensure any CommonJS-style tooling requires (e.g. from Babel or
443
+ // other build-time libraries that may be accidentally bundled) do
444
+ // not attempt to resolve Node built-ins like 'fs' or 'path' on
445
+ // device. These modules are not used at runtime for NativeScript
446
+ // apps, so we safely return an empty object from a shim.
447
+ //
448
+ // IMPORTANT: Under HMR, vendor packages call the real NativeScript
449
+ // CommonJS require() with `@nativescript/core/<sub>` specifiers
450
+ // (e.g. `require('@nativescript/core/ui/core/view').View` in
451
+ // `@nativescript-community/gesturehandler`). If we overwrite
452
+ // globalThis.require with a blanket stub, every such call returns
453
+ // `{}` and any property access on the result (e.g. `.View`) is
454
+ // `undefined`, cascading into `TypeError: Cannot read properties
455
+ // of undefined (reading 'prototype')` inside `applyMixins` when
456
+ // vendor install() hooks run.
457
+ //
458
+ // Instead, install a DELEGATING shim:
459
+ // - If the specifier is a Node built-in (fs, path, os, …) or
460
+ // a webpack-only runtime hook (require.context), return a
461
+ // safe empty stub.
462
+ // - Otherwise, delegate to the preserved original
463
+ // `globalThis.require` (NativeScript's native CJS loader),
464
+ // which routes `@nativescript/core*` through the HTTP bridge
465
+ // or, for already-HTTP-loaded modules, through the
466
+ // `globalThis.__NS_CORE_MODULES__` registry populated by the
467
+ // `/ns/core` bridge preamble.
468
+ imports += "try { if (typeof globalThis !== 'undefined') {\n";
469
+ imports += " var __nsOrigRequire = typeof globalThis.require === 'function' ? globalThis.require : null;\n";
470
+ imports += ' var __nsNodeBuiltins = { fs: 1, path: 1, os: 1, url: 1, crypto: 1, util: 1, stream: 1, events: 1, buffer: 1, http: 1, https: 1, net: 1, tls: 1, dns: 1, child_process: 1, module: 1, zlib: 1, querystring: 1, assert: 1, constants: 1, vm: 1 };\n';
471
+ // Mirror helpers/ns-core-url.ts normalizeCoreSub() inline so the
472
+ // lookup against __NS_CORE_MODULES__ uses the same keys the
473
+ // /ns/core handler registers under.
474
+ imports += ' var __nsNormSub = function (s) {\n';
475
+ imports += " if (!s) return '';\n";
476
+ imports += " var t = String(s).split('?')[0].split('#')[0].trim();\n";
477
+ imports += " t = t.replace(/^\\/+/, '').replace(/\\/+$/, '');\n";
478
+ imports += " t = t.replace(/\\.(?:mjs|cjs|js)$/, '');\n";
479
+ imports += " if (t.length >= 6 && t.substring(t.length - 6) === '/index') t = t.substring(0, t.length - 6);\n";
480
+ imports += " if (!t || t === 'index') return '';\n";
481
+ imports += ' return t;\n';
482
+ imports += ' };\n';
483
+ // Invariant D: CJS/ESM interop shape helper.
484
+ //
485
+ // Install a global, idempotent shape function that converts
486
+ // ESM Module Namespace Objects (which have [[Prototype]] = null
487
+ // per spec §9.4.6) into plain Objects that inherit from
488
+ // Object.prototype. CJS consumers — especially zone.js's
489
+ // patchMethod() — call `hasOwnProperty`, `toString`, etc. on
490
+ // their require() result; a null-proto namespace throws
491
+ // "X is not a function" on the first such call.
492
+ //
493
+ // Properties:
494
+ // - Recursive: @nativescript/core re-exports Utils/Http/Trace
495
+ // as nested namespaces (`export * as Utils from './utils'`),
496
+ // each also null-proto. Shallow wrapping leaves those.
497
+ // - Identity-preserving via a WeakMap cache keyed on the
498
+ // underlying namespace. zone.js MUTATES its target (stashes
499
+ // delegate symbols, overwrites methods); a fresh copy per
500
+ // require() would lose those mutations on the next lookup.
501
+ // - Installed ONCE on globalThis so the /ns/core handler's
502
+ // registration footer, the vendor shim's createRequire, and
503
+ // any other consumer share the same cache and see
504
+ // mutation-consistent shapes.
505
+ imports += ' var __nsShapeCache = globalThis.__NS_CJS_SHAPE_CACHE__ || (globalThis.__NS_CJS_SHAPE_CACHE__ = new WeakMap());\n';
506
+ imports += ' var __nsShapeCjs = globalThis.__NS_CJS_SHAPE__ || (globalThis.__NS_CJS_SHAPE__ = function __nsShape(obj) {\n';
507
+ imports += " if (!obj || typeof obj !== 'object') return obj;\n";
508
+ imports += ' var proto = Object.getPrototypeOf(obj);\n';
509
+ imports += ' var isNsModule = false;\n';
510
+ imports += " try { isNsModule = obj[Symbol.toStringTag] === 'Module'; } catch (e) {}\n";
511
+ imports += ' if (proto !== null && !isNsModule) return obj;\n';
512
+ imports += ' if (__nsShapeCache.has(obj)) return __nsShapeCache.get(obj);\n';
513
+ imports += ' var out = {};\n';
514
+ imports += ' __nsShapeCache.set(obj, out);\n';
515
+ imports += ' try {\n';
516
+ imports += ' var keys = Object.keys(obj);\n';
517
+ imports += ' for (var i = 0; i < keys.length; i++) {\n';
518
+ imports += ' var k = keys[i];\n';
519
+ imports += ' try { out[k] = __nsShape(obj[k]); } catch (e) {}\n';
520
+ imports += ' }\n';
521
+ imports += ' } catch (e) {}\n';
522
+ imports += ' return out;\n';
523
+ imports += ' });\n';
524
+ imports += ' var _nsReq = function (id) {\n';
525
+ imports += ' try {\n';
526
+ imports += " var n = String(id || '');\n";
527
+ imports += " var stripped = n.indexOf('node:') === 0 ? n.slice(5) : n;\n";
528
+ imports += ' if (__nsNodeBuiltins[stripped]) return {};\n';
529
+ imports += " if (n === '@nativescript/core' || n.indexOf('@nativescript/core/') === 0) {\n";
530
+ imports += ' var table = globalThis.__NS_CORE_MODULES__;\n';
531
+ imports += ' if (table) {\n';
532
+ // Table entries are ALREADY shaped (the /ns/core footer stores
533
+ // the shape, not the raw namespace). But we pass through
534
+ // __nsShapeCjs anyway — it's a no-op on already-shaped values
535
+ // (fast path: `proto !== null && !isNsModule` returns obj as-is)
536
+ // and guards against future changes to how the registry is
537
+ // populated (e.g., by direct assignment from test code).
538
+ imports += ' if (table[n]) return __nsShapeCjs(table[n]);\n';
539
+ imports += " var rawSub = n === '@nativescript/core' ? '' : n.slice('@nativescript/core/'.length);\n";
540
+ imports += ' var normSub = __nsNormSub(rawSub);\n';
541
+ imports += " var bareKey = normSub ? '@nativescript/core/' + normSub : '@nativescript/core';\n";
542
+ imports += ' if (table[bareKey]) return __nsShapeCjs(table[bareKey]);\n';
543
+ imports += ' if (table[normSub]) return __nsShapeCjs(table[normSub]);\n';
544
+ imports += ' }\n';
545
+ imports += ' }\n';
546
+ // Fallback to native require (NativeScript CJS loader via HTTP
547
+ // bridge). Shape the result too — the native loader may return
548
+ // a raw ESM namespace for core subpaths served before the /ns/core
549
+ // footer runs.
550
+ imports += ' if (__nsOrigRequire) return __nsShapeCjs(__nsOrigRequire(id));\n';
551
+ imports += ' } catch (e) {}\n';
552
+ imports += ' return {};\n';
553
+ imports += ' };\n';
554
+ imports += ' _nsReq.context = function () { var _c = { keys: function () { return []; } }; _c.__esModule = true; return _c; };\n';
555
+ imports += ' if (__nsOrigRequire) { try { _nsReq.resolve = __nsOrigRequire.resolve ? __nsOrigRequire.resolve.bind(__nsOrigRequire) : function (id) { return id; }; } catch (e) {} }\n';
556
+ imports += ' globalThis.require = _nsReq;\n';
557
+ imports += ' globalThis.__nsOrigRequire = __nsOrigRequire;\n';
558
+ imports += '} } catch {}\n';
63
559
  // Banner diagnostics for visibility at runtime
64
560
  if (opts.verbose) {
65
561
  imports += `console.info('[ns-entry] begin', { platform: ${JSON.stringify(opts.platform)}, dev: ${JSON.stringify(opts.isDevMode)}, hmr: ${JSON.stringify(opts.hmrActive)}, verbose: ${JSON.stringify(opts.verbose)}, mainEntry: ${JSON.stringify(mainEntry)}, mainRel: ${JSON.stringify(mainEntryRelPosix)}, time: new Date().toISOString() });\n`;
66
562
  }
67
563
  if (opts.hmrActive) {
68
- // Seed platform globals on the primary bundle realm using the same
69
- // CLI-derived platform that drives global-defines.ts. This ensures
70
- // HMR-delivered HTTP ESM modules can reliably read platform flags
71
- imports += `globalThis.__DEV__ = ${opts.isDevMode ? 'true' : 'false'};\n`;
72
- imports += `globalThis.__ANDROID__ = ${opts.platform === 'android' ? 'true' : 'false'};\n`;
73
- imports += `globalThis.__IOS__ = ${opts.platform === 'ios' ? 'true' : 'false'};\n`;
74
- imports += `globalThis.__VISIONOS__ = ${opts.platform === 'visionos' ? 'true' : 'false'};\n`;
75
- imports += `globalThis.__APPLE__ = ${opts.platform === 'ios' || opts.platform === 'visionos' ? 'true' : 'false'};\n`;
76
- // ---- Vendor manifest bootstrap ----
77
- // Use single self-contained vendor module to avoid extra imports affecting chunking
78
- imports += "import vendorManifest, { __nsVendorModuleMap } from '@nativescript/vendor';\n";
79
- imports += "import { installVendorBootstrap } from '@nativescript/vite/hmr/shared/runtime/vendor-bootstrap.js';\n";
80
- if (opts.verbose) {
81
- imports += `console.info('[ns-entry] vendor manifest imported', { keys: Object.keys(vendorManifest||{}).length, hasMap: typeof __nsVendorModuleMap === 'object' });\n`;
82
- }
83
- imports += 'installVendorBootstrap(vendorManifest, __nsVendorModuleMap, __nsVerboseLog);\n';
84
- if (opts.verbose) {
85
- imports += `console.info('[ns-entry] vendor bootstrap installed');\n`;
86
- }
564
+ // NOTE: globalThis defines (`__APPLE__`, `__IOS__`, `__DEV__`,
565
+ // etc.) are seeded by the `virtual:ns-defines-seed` import at
566
+ // the very top of this entry — see the import on line ~192.
567
+ // They MUST run as a leaf module ahead of any other graph
568
+ // node, so we can't seed them inline here (ESM imports hoist
569
+ // past inline body code, so any module reachable through
570
+ // `bundle-entry-points` would otherwise see undefined).
571
+ imports += "import { installModuleProvenanceRecorder } from '@nativescript/vite/hmr/shared/runtime/module-provenance.js';\n";
572
+ imports += 'installModuleProvenanceRecorder(__nsVerboseLog);\n';
87
573
  }
88
574
  // ---- Core runtime globals (always-needed) ----
89
- // Load globals early
90
- imports += "import '@nativescript/core/globals/index';\n";
575
+ // Install XHR polyfill FIRST — its virtual module body runs during import evaluation,
576
+ // before any subsequent import (like zone.js) can reference XMLHttpRequest.
577
+ imports += `import '${XHR_POLYFILL_VIRTUAL_ID}';\n`;
578
+ // Load globals early. Under HMR we use a full HTTP URL so iOS's
579
+ // ESM loader can fetch it directly at module-instantiation time —
580
+ // the import map isn't installed yet at that phase.
581
+ imports += `import ${JSON.stringify(coreSpec('globals/index'))};\n`;
91
582
  if (opts.verbose) {
92
583
  imports += `console.info('[ns-entry] core globals loaded');\n`;
93
584
  }
585
+ // Seed the real NativeScript Application singleton before any early HMR/placeholder
586
+ // code runs. Dynamic discovery is too late for iOS placeholder startup.
587
+ imports += `import { Application as __nsEarlyApplication } from ${JSON.stringify(coreSpec('application'))};\n`;
588
+ imports += `try { if (__nsEarlyApplication && (typeof __nsEarlyApplication.run === 'function' || typeof __nsEarlyApplication.on === 'function' || typeof __nsEarlyApplication.resetRootView === 'function')) { globalThis.Application = __nsEarlyApplication; } } catch {}\n`;
589
+ if (opts.verbose) {
590
+ imports += `console.info('[ns-entry] early Application seeded', { hasRun: typeof globalThis.Application?.run === 'function', hasOn: typeof globalThis.Application?.on === 'function', hasResetRootView: typeof globalThis.Application?.resetRootView === 'function' });\n`;
591
+ }
592
+ // In dev mode for Angular apps, ensure @angular/compiler (JIT) is loaded.
593
+ // With experimentalDecorators:true, TypeScript emits __decorate patterns.
594
+ // On watch-mode rebuilds the Angular compiler may not re-emit ɵfac for
595
+ // cached files, so the JIT compiler must be available as a fallback.
596
+ if (opts.isDevMode && effectiveFlavor === 'angular') {
597
+ imports += "import { publishFacade as __nsPublishAngularCompilerFacade } from '@angular/compiler';\n";
598
+ imports += '__nsPublishAngularCompilerFacade(globalThis);\n';
599
+ if (opts.verbose) {
600
+ imports += `console.info('[ns-entry] @angular/compiler (JIT) loaded for dev mode');\n`;
601
+ }
602
+ }
94
603
  /**
95
604
  * Ensure the canonical @nativescript/core classes are available on globalThis
96
605
  * before any other framework modules execute (like bundle-entry-points) to avoid duplicate realms
@@ -111,13 +620,32 @@ export function mainEntryPlugin(opts) {
111
620
  }
112
621
  }
113
622
  // Load NS bundle entry points after early hook
114
- imports += "import '@nativescript/core/bundle-entry-points';\n";
623
+ imports += `import ${JSON.stringify(coreSpec('bundle-entry-points'))};\n`;
115
624
  if (opts.verbose) {
116
625
  imports += `console.info('[ns-entry] bundle-entry-points loaded');\n`;
117
626
  }
118
- if (flavor === 'typescript') {
627
+ // XML-driven flavors: register @nativescript/core/ui + element nicknames
628
+ // with the bundler module registry, import the bundler context, and apply
629
+ // View prototype guards. Provided as a virtual module by
630
+ // createUiRegistrationPlugin (wired in typescript.ts / javascript.ts) —
631
+ // imported HERE, right after bundle-entry-points, instead of being
632
+ // string-injected into this generated entry by a marker-matching
633
+ // transform (the marker drifted once and silently broke all XML builds
634
+ // with "Module 'Frame' not found").
635
+ if (effectiveFlavor === 'typescript' || effectiveFlavor === 'javascript') {
636
+ imports += "import 'virtual:ns-ui-registration';\n";
637
+ }
638
+ if (effectiveFlavor === 'typescript') {
119
639
  // Statically import bundler context synchronously before app code
120
640
  imports += "import 'virtual:ns-bundler-context';\n";
641
+ if (opts.hmrActive) {
642
+ // Snapshot original module registry functions for HMR diagnostics
643
+ imports += `(function() {
644
+ globalThis.__NS_ORIG_GET_REGISTERED_MODULES__ = globalThis.getRegisteredModules;
645
+ globalThis.__NS_ORIG_MODULE_EXISTS__ = globalThis.moduleExists;
646
+ globalThis.__NS_ORIG_LOAD_MODULE__ = globalThis.loadModule;
647
+ })();\n`;
648
+ }
121
649
  }
122
650
  // ---- Custom App Components (Activity/Application) ----
123
651
  // These must be loaded early so the JS class is registered before Android instantiates them
@@ -127,7 +655,7 @@ export function mainEntryPlugin(opts) {
127
655
  for (const component of appComponents) {
128
656
  // The appComponentsPlugin bundles these as separate .mjs entry points
129
657
  // We must import the output file, not the source, since it's a separate entry
130
- imports += `import "~/${component.outputName}.mjs";\n`;
658
+ imports += `import ${JSON.stringify(`~/${component.outputName}.mjs`)};\n`;
131
659
  if (opts.verbose) {
132
660
  imports += `console.info('[ns-entry] app component loaded: ${component.outputName}');\n`;
133
661
  }
@@ -138,54 +666,17 @@ export function mainEntryPlugin(opts) {
138
666
  }
139
667
  }
140
668
  // ---- Platform-specific always-needed modules ----
141
- // Track if we need to defer Android activity import (non-HMR only)
142
669
  let needsAndroidActivityDefer = false;
143
670
  if (opts.platform === 'android') {
144
- if (opts.hmrActive) {
145
- /**
146
- * Ensure the Java Activity class exists by executing the vendor-packed
147
- * activity registration module via the vendor registry (not ESM import).
148
- * This avoids any on-disk vendor.mjs export mismatches and guarantees the
149
- * class is registered before Android tries to instantiate it.
150
- */
151
- imports += `
152
- (function __nsEnsureAndroidActivityForHMR(){
153
- try {
154
- const g = globalThis;
155
- const req = (g.__nsVendorRequire || g.__nsRequire);
156
- if (!req) {
157
- ${opts.verbose ? "console.warn('[ns-entry] vendor require not available yet; activity registration may be deferred');" : ''}
158
- return;
159
- }
160
- const candidates = [
161
- '@nativescript/core/ui/frame/activity.android',
162
- '@nativescript/core/ui/frame/activity.android.js'
163
- ];
164
- for (const id of candidates) {
165
- try {
166
- req(id);
167
- ${opts.verbose ? "console.info('[ns-entry] android activity registered via vendor', id);" : ''}
168
- break;
169
- } catch {}
170
- }
171
- } catch (e) {
172
- try { console.error('[ns-entry] failed to require android activity from vendor', e); } catch {}
173
- }
174
- })();\n`;
175
- }
176
- else {
177
- /**
178
- * Non-HMR: Defer activity lifecycle wiring until native Application is ready
179
- * to avoid "application is null" errors at production boot.
180
- * We set a flag here and emit the actual code after the static Application import
181
- * to avoid mixing dynamic and static imports of @nativescript/core.
182
- */
183
- needsAndroidActivityDefer = true;
184
- }
671
+ /**
672
+ * Defer activity lifecycle wiring until native Application is ready
673
+ * to avoid "application is null" errors during startup.
674
+ */
675
+ needsAndroidActivityDefer = true;
185
676
  }
186
677
  // ---- Optional polyfills ----
187
678
  if (polyfillsExists) {
188
- imports += `import '${polyfillsImportSpecifier}';\n`;
679
+ imports += `import ${JSON.stringify(polyfillsImportSpecifier)};\n`;
189
680
  if (opts.verbose) {
190
681
  imports += `console.info('[ns-entry] polyfills imported from', ${JSON.stringify(polyfillsImportSpecifier)});\n`;
191
682
  }
@@ -200,26 +691,43 @@ export function mainEntryPlugin(opts) {
200
691
  if (opts.verbose) {
201
692
  imports += "console.info('[ns-entry] websockets polyfill imported');\n";
202
693
  }
203
- // Load HMR client for WebSocket connection to Vite dev server before HTTP-only boot attempts.
204
- imports += "import 'virtual:ns-hmr-client';\n";
205
- imports += "console.info('@nativescript/vite HMR client loaded.');\n";
206
694
  }
207
695
  // ---- Global CSS injection (always-needed if file exists) ----
208
- const appCssPath = path.resolve(projectRoot, getProjectAppRelativePath('app.css'));
209
- const hasAppCss = fs.existsSync(appCssPath);
696
+ // Prefer `app.css`, fall back to `styles.css` (common in web projects).
697
+ const appCssPath = resolveProjectGlobalCssPath(projectRoot);
698
+ const hasAppCss = !!appCssPath;
210
699
  // Import Application statically if needed for CSS or Android activity defer
211
700
  if (hasAppCss || needsAndroidActivityDefer) {
212
701
  if (hasAppCss) {
213
- imports += `// Import and apply global CSS before app bootstrap\n`;
214
- imports += `import appCssContent from './${appRootDir}/app.css?inline';\n`;
215
- }
216
- imports += `import { Application } from '@nativescript/core';\n`;
217
- if (hasAppCss) {
218
- imports += `if (appCssContent) { try { Application.addCss(appCssContent); } catch (error) { console.error('Error applying CSS:', error); } }\n`;
702
+ // The virtual module's body either:
703
+ // - non-HMR: calls `addTaggedAdditionalCSS(ast, 'app.css')`
704
+ // as an import-time side-effect, landing CSS in NS's
705
+ // selector tables before any view is created.
706
+ // - HMR: stashes the rework AST on
707
+ // `globalThis.__NS_HMR_APP_CSS_AST__` so
708
+ // `installHttpCoreCssSupport` can apply it via the SAME
709
+ // AST path in the HTTP-core realm. The default export
710
+ // is the raw CSS string, also seeded onto
711
+ // `globalThis.__NS_HMR_APP_CSS__` here as a
712
+ // raw-text fallback (used for live HMR edits via the
713
+ // dev-server WebSocket).
714
+ imports += `// Apply global CSS before app bootstrap (AST under non-HMR; AST stashed for HMR cold boot)\n`;
715
+ imports += `import appCssContent from '${APP_CSS_VIRTUAL_ID}';\n`;
716
+ if (opts.hmrActive) {
717
+ imports += `try { globalThis.__NS_HMR_APP_CSS__ = appCssContent; } catch {}\n`;
718
+ }
219
719
  if (opts.verbose) {
220
- imports += `console.info('[ns-entry] app.css applied');\n`;
720
+ imports += `console.info('[ns-entry] app.css applied as AST');\n`;
221
721
  }
222
722
  }
723
+ if (needsAndroidActivityDefer) {
724
+ imports += `import { Application } from ${JSON.stringify(coreSpec())};\n`;
725
+ }
726
+ }
727
+ // SFC/imported CSS (non-HMR build). After app.css so component rules win
728
+ // specificity ties. generateBundle fills it in; HMR applies at runtime.
729
+ if (!opts.hmrActive) {
730
+ imports += `import '${BUNDLE_CSS_VIRTUAL_ID}';\n`;
223
731
  }
224
732
  // ---- Deferred Android activity import (non-HMR only) ----
225
733
  // Uses the statically imported Application to avoid mixing dynamic and static imports
@@ -242,48 +750,42 @@ export function mainEntryPlugin(opts) {
242
750
  }
243
751
  // ---- Application main entry ----
244
752
  if (opts.hmrActive) {
245
- // HTTP-only dev boot: try to import the entire app over HTTP; if not reachable, keep retrying.
753
+ // Deterministic dev boot: fetch one session descriptor and let the runtime
754
+ // import the session client + app entry over HTTP.
246
755
  if (opts.verbose) {
247
- imports += `console.info('[ns-entry] including HTTP-only boot', { platform: ${JSON.stringify(opts.platform)}, mainRel: ${JSON.stringify(mainEntryRelPosix)} });\n`;
756
+ imports += `console.info('[ns-entry] including deterministic dev session bootstrap', { platform: ${JSON.stringify(opts.platform)}, mainRel: ${JSON.stringify(mainEntryRelPosix)} });\n`;
248
757
  }
249
- const guessLanHost = () => {
250
- try {
251
- const nets = os.networkInterfaces();
252
- for (const name of Object.keys(nets)) {
253
- const addrs = nets[name] || [];
254
- for (const a of addrs) {
255
- if (!a)
256
- continue;
257
- const family = a.family;
258
- const internal = !!a.internal;
259
- const address = String(a.address || '');
260
- if (internal)
261
- continue;
262
- if ((family === 'IPv4' || family === 4) && address && address !== '127.0.0.1')
263
- return address;
264
- }
265
- }
266
- }
267
- catch { }
268
- return undefined;
269
- };
270
- // Prefer LAN IP so physical devices work by default; emulator will still be tried as a fallback.
271
- const defaultHost = opts.platform === 'android' ? guessLanHost() || '10.0.2.2' : guessLanHost() || 'localhost';
272
- imports += "import { startHttpOnlyBoot } from '@nativescript/vite/hmr/shared/runtime/http-only-boot.js';\n";
273
- imports += `startHttpOnlyBoot(${JSON.stringify(opts.platform)}, ${JSON.stringify(mainEntryRelPosix)}, ${JSON.stringify((process.env.NS_HMR_HOST || '')) || JSON.stringify('')} || ${JSON.stringify(defaultHost)}, __nsVerboseLog);\n`;
758
+ // Same device-reachable origin as `getBootOrigin()` so the
759
+ // session-descriptor URL and every `/ns/core/*` URL baked
760
+ // into bundle.mjs come from one canonical source. Without
761
+ // this, Android's `bundle.mjs` would hit `0.0.0.0:5173` for
762
+ // both endpoints (server.host's wildcard bind) and fail at
763
+ // boot before any user code runs.
764
+ const { origin: bootOrigin } = resolveDeviceReachableOrigin({
765
+ host: resolvedConfig.server.host,
766
+ platform: opts.platform,
767
+ protocol: resolvedConfig.server.https || opts.useHttps ? 'https' : 'http',
768
+ port: Number(resolvedConfig.server.port || 5173),
769
+ });
770
+ const sessionUrl = bootOrigin + '/__ns_dev__/session';
771
+ imports += "import { startBrowserRuntimeSession } from '@nativescript/vite/hmr/shared/runtime/session-bootstrap.js';\n";
772
+ imports += `startBrowserRuntimeSession(${JSON.stringify(sessionUrl)}, __nsVerboseLog).catch((error) => {\n`;
773
+ imports += ` try { globalThis.__NS_ENTRY_ERROR__ = { phase: 'deterministic-dev-session', message: String(error && (error.message || error)), stack: error && error.stack ? String(error.stack) : '' }; } catch {}\n`;
774
+ imports += ` console.error('[ns-entry] deterministic dev session bootstrap failed', error && error.stack ? error.stack : error);\n`;
775
+ imports += `});\n`;
274
776
  if (opts.verbose) {
275
- imports += `console.info('[ns-entry] HTTP-only boot code appended');\n`;
777
+ imports += `console.info('[ns-entry] deterministic dev session bootstrap appended');\n`;
276
778
  }
277
779
  }
278
780
  else {
279
781
  if (opts.verbose) {
280
- imports += `console.info('[ns-entry] Importing main entry', '${mainEntry}');\n`;
782
+ imports += `console.info('[ns-entry] Importing main entry', ${JSON.stringify(mainEntryImportSpecifier)});\n`;
281
783
  }
282
- imports += `import '${mainEntry}';\n`;
784
+ imports += `import ${JSON.stringify(mainEntryImportSpecifier)};\n`;
283
785
  }
284
786
  if (opts.isDevMode) {
285
787
  // debug tools support
286
- imports += "import '@nativescript/core/inspector_modules';\n";
788
+ imports += `import ${JSON.stringify(coreSpec('inspector_modules'))};\n`;
287
789
  if (opts.verbose) {
288
790
  imports += "console.info('[ns-entry] inspector modules imported');\n";
289
791
  }