@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,114 +1,72 @@
1
1
  import { mergeConfig } from 'vite';
2
2
  import path from 'path';
3
3
  import fs from 'node:fs';
4
- import { createRequire } from 'node:module';
5
4
  import angular from '@analogjs/vite-plugin-angular';
6
- import { angularLinkerVitePlugin, angularLinkerVitePluginPost } from '../helpers/angular/angular-linker.js';
7
- import { ensureSharedAngularLinker } from '../helpers/angular/shared-linker.js';
8
- import { containsRealNgDeclare } from '../helpers/angular/util.js';
5
+ import { angularLinkerVitePlugin, angularLinkerVitePluginPost } from '../hmr/frameworks/angular/build/angular-linker.js';
6
+ import { synthesizeMissingInjectableFactories } from '../hmr/frameworks/angular/build/synthesize-injectable-factories.js';
7
+ import { getAngularLinkerFactory, runAngularLinker } from '../hmr/frameworks/angular/build/shared-linker.js';
8
+ import { recordLinkerHit, reportLinkerLayerStats } from '../hmr/frameworks/angular/build/linker-stats.js';
9
+ import { inlineDecoratorComponentTemplates } from '../hmr/frameworks/angular/build/inline-decorator-component-templates.js';
10
+ import { appendComponentHmrRegistration, findComponentClassNames, INJECTION_MARKER as HMR_REGISTER_MARKER } from '../hmr/frameworks/angular/build/inject-component-hmr-registration.js';
11
+ import { injectAngularHmrViteIgnore } from '../hmr/frameworks/angular/build/inject-hmr-vite-ignore.js';
12
+ import { synthesizeDecoratorCtorParameters } from '../hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js';
13
+ import { containsRealNgDeclare, stripJsComments } from '../hmr/frameworks/angular/build/util.js';
9
14
  import { baseConfig } from './base.js';
10
15
  import { getCliFlags } from '../helpers/cli-flags.js';
16
+ import { getMonorepoWorkspaceRoot } from '../helpers/project.js';
17
+ import { resolveRelativeToImportMeta } from '../helpers/import-meta-path.js';
18
+ import { resolveVerboseFlag } from '../helpers/logging.js';
19
+ import { NS_OPTIMIZE_DEPS_EXCLUDE } from '../helpers/optimize-deps.js';
20
+ function hasNgDeclarePartial(code) {
21
+ return code.indexOf('\u0275\u0275ngDeclare') !== -1 || code.indexOf('ɵɵngDeclare') !== -1 || code.indexOf('ngDeclare') !== -1;
22
+ }
11
23
  // Rollup-level linker to guarantee Angular libraries are linked when included in the bundle graph.
12
24
  function angularRollupLinker(projectRoot) {
13
- let babel = null;
14
- let createLinker = null;
15
25
  const FILTER = /node_modules\/(?:@angular|@nativescript\/angular)\/.*\.[mc]?js$/;
16
- async function ensureDeps() {
17
- if (babel && createLinker)
18
- return;
19
- try {
20
- const req = createRequire((projectRoot ? projectRoot + '/package.json' : import.meta.url));
21
- const babelPath = req.resolve('@babel/core');
22
- const linkerPath = req.resolve('@angular/compiler-cli/linker/babel');
23
- babel = await import(babelPath);
24
- const linkerMod = await import(linkerPath);
25
- createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin;
26
- }
27
- catch {
28
- try {
29
- babel = await import('@babel/core');
30
- }
31
- catch { }
32
- try {
33
- const linkerMod = await import('@angular/compiler-cli/linker/babel');
34
- createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin;
35
- }
36
- catch { }
37
- }
38
- }
26
+ const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
39
27
  return {
40
28
  name: 'ns-angular-linker-rollup',
41
29
  enforce: 'pre',
42
30
  apply: 'build',
43
31
  async load(id) {
44
- const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
45
- const cleanId = id.split('?', 1)[0];
32
+ const cleanId = normalizeAngularWatchPath(id);
46
33
  if (!FILTER.test(cleanId))
47
34
  return null;
48
35
  try {
49
- await ensureDeps();
50
- if (!babel || !createLinker)
51
- return null;
52
36
  const fs = await import('node:fs/promises');
53
37
  const code = await fs.readFile(cleanId, 'utf8');
54
38
  const forceLink = cleanId.includes('/node_modules/@nativescript/angular/') && cleanId.includes('polyfills');
55
39
  if (!code)
56
40
  return null;
57
- if (!forceLink && code.indexOf('\u0275\u0275ngDeclare') === -1 && code.indexOf('ɵɵngDeclare') === -1 && code.indexOf('ngDeclare') === -1)
41
+ if (!forceLink && !hasNgDeclarePartial(code))
58
42
  return null;
59
- const plugin = createLinker({ sourceMapping: false });
60
- if (debug) {
61
- try {
62
- console.log('[ns-angular-linker][rollup-load] linking', cleanId);
63
- }
64
- catch { }
65
- }
66
- const result = await babel.transformAsync(code, {
67
- filename: cleanId,
68
- configFile: false,
69
- babelrc: false,
70
- sourceMaps: false,
71
- compact: false,
72
- plugins: [plugin],
73
- });
74
- if (result?.code && result.code !== code) {
75
- return { code: result.code, map: null };
43
+ const linked = await runAngularLinker(code, { filename: cleanId, projectRoot, freshPlugin: true });
44
+ if (linked) {
45
+ recordLinkerHit('rollup-load');
46
+ if (debug)
47
+ console.log('[ns-angular-linker][rollup-load] linked', cleanId);
48
+ return { code: linked, map: null };
76
49
  }
77
50
  }
78
51
  catch { }
79
52
  return null;
80
53
  },
81
54
  async transform(code, id) {
82
- const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
83
- const cleanId = id.split('?', 1)[0];
55
+ const cleanId = normalizeAngularWatchPath(id);
84
56
  if (!FILTER.test(cleanId))
85
57
  return null;
86
58
  const forceLink = cleanId.includes('/node_modules/@nativescript/angular/') && cleanId.includes('polyfills');
87
59
  if (!code)
88
60
  return null;
89
- if (!forceLink && code.indexOf('\u0275\u0275ngDeclare') === -1 && code.indexOf('ɵɵngDeclare') === -1 && code.indexOf('ngDeclare') === -1)
90
- return null;
91
- await ensureDeps();
92
- if (!babel || !createLinker)
61
+ if (!forceLink && !hasNgDeclarePartial(code))
93
62
  return null;
94
63
  try {
95
- const plugin = createLinker({ sourceMapping: false });
96
- if (debug) {
97
- try {
98
- console.log('[ns-angular-linker][rollup] linking', cleanId);
99
- }
100
- catch { }
101
- }
102
- const result = await babel.transformAsync(code, {
103
- filename: cleanId,
104
- configFile: false,
105
- babelrc: false,
106
- sourceMaps: false,
107
- compact: false,
108
- plugins: [plugin],
109
- });
110
- if (result?.code && result.code !== code) {
111
- return { code: result.code, map: null };
64
+ const linked = await runAngularLinker(code, { filename: cleanId, projectRoot, freshPlugin: true });
65
+ if (linked) {
66
+ recordLinkerHit('rollup');
67
+ if (debug)
68
+ console.log('[ns-angular-linker][rollup] linked', cleanId);
69
+ return { code: linked, map: null };
112
70
  }
113
71
  }
114
72
  catch { }
@@ -119,6 +77,24 @@ function angularRollupLinker(projectRoot) {
119
77
  const cliFlags = getCliFlags();
120
78
  const isDevEnv = process.env.NODE_ENV !== 'production';
121
79
  const hmrActive = isDevEnv && !!cliFlags.hmr;
80
+ /**
81
+ * Web-style template HMR opt-out (`NS_VITE_ANGULAR_LIVE_RELOAD=0`).
82
+ *
83
+ * With HMR active we default to the in-place template-replacement pipeline
84
+ * (see the `liveReload` option below). If a project hits a regression
85
+ * (broken styling, unresolved `?ngcomp=` imports), this env flag rolls back
86
+ * to the legacy reboot pipeline without an upstream patch. `0`, `false`,
87
+ * `off`, and `no` (case-insensitive) mean "off"; anything else — including
88
+ * unset — keeps the new path on. Read once at module load, like `hmrActive`.
89
+ */
90
+ const angularLiveReloadDisabledByEnv = (() => {
91
+ const raw = process.env.NS_VITE_ANGULAR_LIVE_RELOAD;
92
+ if (typeof raw !== 'string')
93
+ return false;
94
+ const v = raw.trim().toLowerCase();
95
+ return v === '0' || v === 'false' || v === 'off' || v === 'no';
96
+ })();
97
+ const hmrAngularLiveReload = hmrActive && !angularLiveReloadDisabledByEnv;
122
98
  const projectRoot = process.cwd();
123
99
  const tsConfigAppPath = path.resolve(projectRoot, 'tsconfig.app.json');
124
100
  const tsConfigPath = path.resolve(projectRoot, 'tsconfig.json');
@@ -126,93 +102,441 @@ let tsConfig = tsConfigAppPath;
126
102
  if (!fs.existsSync(tsConfigAppPath) && fs.existsSync(tsConfigPath)) {
127
103
  tsConfig = tsConfigPath;
128
104
  }
129
- const plugins = [
130
- // Allow external html template changes to trigger hot reload: Make .ts files depend on their .html templates
131
- {
132
- name: 'angular-template-deps',
133
- transform(code, id) {
134
- // For .ts files that reference templateUrl, add the .html file as a dependency
135
- if (id.endsWith('.ts') && code.includes('templateUrl')) {
136
- const templateUrlMatch = code.match(/templateUrl:\s*['"]\.\/(.*?\.html)['"]/);
137
- if (templateUrlMatch) {
138
- const htmlPath = path.resolve(path.dirname(id), templateUrlMatch[1]);
139
- // Add the HTML file as a dependency so Vite watches it
140
- this.addWatchFile(htmlPath);
141
- }
105
+ function normalizeAngularWatchPath(filePath) {
106
+ return filePath
107
+ .split('?', 1)[0]
108
+ .replace(/\\/g, '/')
109
+ .replace(/^file:\/\//, '');
110
+ }
111
+ function normalizeAngularWatchKey(filePath) {
112
+ const normalizedPath = normalizeAngularWatchPath(filePath);
113
+ const fileSystemPath = normalizedPath.startsWith('/@fs/') ? normalizedPath.slice('/@fs'.length) : normalizedPath;
114
+ const normalizedProjectRoot = projectRoot.replace(/\\/g, '/').replace(/\/$/, '');
115
+ if (normalizedProjectRoot && fileSystemPath.startsWith(normalizedProjectRoot)) {
116
+ const relative = fileSystemPath.slice(normalizedProjectRoot.length);
117
+ return relative.startsWith('/') ? relative : `/${relative}`;
118
+ }
119
+ return fileSystemPath;
120
+ }
121
+ function getAngularWatchKeys(filePath) {
122
+ const normalizedPath = normalizeAngularWatchPath(filePath);
123
+ const keys = new Set();
124
+ keys.add(normalizedPath);
125
+ keys.add(normalizeAngularWatchKey(normalizedPath));
126
+ return Array.from(keys).filter(Boolean);
127
+ }
128
+ function resolveAngularWatchFilePath(filePath) {
129
+ const normalizedPath = normalizeAngularWatchPath(filePath);
130
+ const fileSystemPath = normalizedPath.startsWith('/@fs/') ? normalizedPath.slice('/@fs'.length) : normalizedPath;
131
+ if (path.isAbsolute(fileSystemPath) && fs.existsSync(fileSystemPath)) {
132
+ return fileSystemPath;
133
+ }
134
+ if (fileSystemPath.startsWith('/')) {
135
+ return path.resolve(projectRoot, `.${fileSystemPath}`);
136
+ }
137
+ return path.resolve(projectRoot, fileSystemPath);
138
+ }
139
+ function extractComponentAssetPaths(code, componentId) {
140
+ const componentPath = normalizeAngularWatchPath(componentId);
141
+ const assetPaths = new Set();
142
+ const resolveAssetPath = (assetPath) => normalizeAngularWatchPath(path.resolve(path.dirname(componentPath), assetPath));
143
+ // Blank out `//` and `/* */` comments before scanning. The regexes below
144
+ // are intentionally simple (no JS parser) so they would otherwise match
145
+ // commented-out `templateUrl` / `styleUrls` declarations and register
146
+ // phantom asset deps via `addWatchFile`. In current Rolldown-Vite that
147
+ // also enrolls them as `_addedImports`, which `vite:import-analysis`
148
+ // then tries to resolve — surfacing as a misleading
149
+ // `Failed to resolve import "<file>" from "<importer>". Does the file
150
+ // exist?` pre-transform error if the file (predictably) doesn't exist.
151
+ const scanCode = stripJsComments(code);
152
+ const templateUrlMatch = scanCode.match(/templateUrl\s*:\s*['"](.+?\.(?:html|htm))['"]/);
153
+ if (templateUrlMatch) {
154
+ assetPaths.add(resolveAssetPath(templateUrlMatch[1]));
155
+ }
156
+ const styleUrlMatch = scanCode.match(/styleUrl\s*:\s*['"](.+?\.(?:css|less|sass|scss))['"]/);
157
+ if (styleUrlMatch) {
158
+ assetPaths.add(resolveAssetPath(styleUrlMatch[1]));
159
+ }
160
+ const styleUrlsMatch = scanCode.match(/styleUrls\s*:\s*\[([\s\S]*?)\]/m);
161
+ if (styleUrlsMatch) {
162
+ for (const match of styleUrlsMatch[1].matchAll(/['"](.+?\.(?:css|less|sass|scss))['"]/g)) {
163
+ assetPaths.add(resolveAssetPath(match[1]));
164
+ }
165
+ }
166
+ return Array.from(assetPaths);
167
+ }
168
+ function createAngularPlugins(opts) {
169
+ const verbose = resolveVerboseFlag();
170
+ const assetToComponents = new Map();
171
+ const componentToAssets = new Map();
172
+ const pendingComponentInvalidations = new Set();
173
+ // Shared state between the `enforce: 'pre'` discovery plugin and the
174
+ // `enforce: 'post'` injection plugin. Maps a clean (no-querystring)
175
+ // .ts file id to the list of `@Component`-decorated class names found
176
+ // in its RAW TypeScript source. The pre plugin populates this map;
177
+ // the post plugin reads it to know which class names to register
178
+ // against the compiled output. Cleared on each pre-plugin invocation
179
+ // so renames or `@Component` removals don't leave stale entries.
180
+ const componentsByCleanId = new Map();
181
+ const untrackComponentAssets = (componentPath) => {
182
+ const previousAssets = componentToAssets.get(componentPath);
183
+ if (!previousAssets)
184
+ return;
185
+ for (const assetPath of previousAssets) {
186
+ const components = assetToComponents.get(assetPath);
187
+ if (!components)
188
+ continue;
189
+ components.delete(componentPath);
190
+ if (components.size === 0) {
191
+ assetToComponents.delete(assetPath);
142
192
  }
143
- return null;
193
+ }
194
+ componentToAssets.delete(componentPath);
195
+ };
196
+ const trackComponentAssets = (componentPath, assetPaths) => {
197
+ untrackComponentAssets(componentPath);
198
+ if (assetPaths.length === 0)
199
+ return;
200
+ const normalizedAssets = new Set(assetPaths.flatMap((assetPath) => getAngularWatchKeys(assetPath)));
201
+ componentToAssets.set(componentPath, normalizedAssets);
202
+ for (const assetPath of normalizedAssets) {
203
+ const components = assetToComponents.get(assetPath) || new Set();
204
+ components.add(componentPath);
205
+ assetToComponents.set(assetPath, components);
206
+ }
207
+ };
208
+ const isCandidateComponentTs = (cleanId) => {
209
+ if (!cleanId.endsWith('.ts'))
210
+ return false;
211
+ if (cleanId.includes('/node_modules/'))
212
+ return false;
213
+ if (cleanId.endsWith('.d.ts'))
214
+ return false;
215
+ if (cleanId.endsWith('.spec.ts') || cleanId.endsWith('.test.ts'))
216
+ return false;
217
+ return true;
218
+ };
219
+ return [
220
+ // HMR self-registration runs in two steps:
221
+ //
222
+ // 1. (this plugin, `enforce: 'pre'`) Record the names of
223
+ // `@Component`-decorated classes from the RAW TypeScript source
224
+ // into `componentsByCleanId` — discovery must happen pre-compile
225
+ // because the Analog plugin rewrites the textual decorator away.
226
+ // 2. (`ns-component-hmr-register-post`, `enforce: 'post'`) Append the
227
+ // `__NS_HMR_REGISTER_COMPONENT__` calls to the COMPILED output.
228
+ //
229
+ // The split is mandatory: Analog's `transform` returns its own compiled
230
+ // output (from its `outputFiles` cache), silently discarding any code
231
+ // modification made earlier in the pipeline — appending in the pre
232
+ // plugin leaves the HMR class registry empty.
233
+ //
234
+ // `apply: 'serve'` (registry hook is dev-only) but intentionally NOT
235
+ // gated on `hmrActive`: the injected snippet self-guards on
236
+ // `typeof globalThis.__NS_HMR_REGISTER_COMPONENT__ === 'function'`, and
237
+ // gating the transform itself left `--no-hmr` users with an empty
238
+ // registry.
239
+ {
240
+ name: 'ns-component-hmr-register',
241
+ enforce: 'pre',
242
+ apply: 'serve',
243
+ transform(code, id) {
244
+ const cleanId = normalizeAngularWatchPath(id);
245
+ if (!isCandidateComponentTs(cleanId))
246
+ return null;
247
+ const componentNames = findComponentClassNames(code);
248
+ if (componentNames.length === 0) {
249
+ // Drop any stale entry from a previous transform
250
+ // pass; the file may have lost its `@Component`
251
+ // decorator across a rename/refactor.
252
+ componentsByCleanId.delete(cleanId);
253
+ return null;
254
+ }
255
+ componentsByCleanId.set(cleanId, componentNames);
256
+ if (verbose) {
257
+ console.info(`[ns-hmr][ns-component-hmr-register] discovered ${componentNames.length} component(s) in ${cleanId} (${componentNames.join(', ')})`);
258
+ }
259
+ // Discovery only — never modify the raw TS source. Any
260
+ // modification here is discarded by the Analog Angular
261
+ // plugin downstream; the actual snippet append happens
262
+ // in `ns-component-hmr-register-post`.
263
+ return null;
264
+ },
144
265
  },
145
- },
146
- // Transform Angular partial declarations in node_modules to avoid runtime JIT
147
- // Pass the project root so linker deps resolve from the app, not the plugin package.
148
- angularLinkerVitePlugin(process.cwd()),
149
- // Simplify: rely on Vite pre plugin (load/transform) for linking; Rollup safety net disabled unless re-enabled later
150
- // angularRollupLinker(process.cwd()),
151
- angular({
152
- liveReload: false, // Disable live reload in favor of HMR
153
- tsconfig: tsConfig,
154
- }),
155
- // Post-phase linker to catch any declarations introduced after other transforms (including project code)
156
- angularLinkerVitePluginPost(process.cwd()),
157
- // Enforce: fully disable dependency optimization during serve to avoid rxjs esm5 crawling and OOM
158
- {
159
- name: 'ns-disable-optimize-deps',
160
- enforce: 'post',
161
- apply: 'serve',
162
- config(userConfig) {
163
- const od = userConfig?.optimizeDeps || {};
164
- const prevExclude = Array.isArray(od.exclude) ? od.exclude : [];
165
- const exclude = new Set(prevExclude);
166
- ['@nativescript/core', 'rxjs', '@valor/nativescript-websockets', 'set-value', 'react', 'react-reconciler', 'react-nativescript'].forEach((x) => exclude.add(x));
167
- return {
168
- optimizeDeps: {
169
- noDiscovery: true,
170
- entries: [],
171
- include: [],
172
- exclude: Array.from(exclude),
173
- rolldownOptions: {
174
- ...(od.rolldownOptions || {}),
175
- plugins: [],
176
- },
177
- },
178
- };
266
+ // Step 2: append the HMR registration snippet to the compiled output
267
+ // (post-Analog), keyed by the names recorded in step 1.
268
+ {
269
+ name: 'ns-component-hmr-register-post',
270
+ enforce: 'post',
271
+ apply: 'serve',
272
+ transform(code, id) {
273
+ const cleanId = normalizeAngularWatchPath(id);
274
+ if (!isCandidateComponentTs(cleanId))
275
+ return null;
276
+ const componentNames = componentsByCleanId.get(cleanId);
277
+ if (!componentNames || componentNames.length === 0)
278
+ return null;
279
+ // Idempotency: Vite may replay transforms on cached modules; the
280
+ // marker guards against double-injection.
281
+ if (code.includes(HMR_REGISTER_MARKER))
282
+ return null;
283
+ const result = appendComponentHmrRegistration(code, componentNames);
284
+ if (!result.code)
285
+ return null;
286
+ if (verbose) {
287
+ console.info(`[ns-hmr][ns-component-hmr-register-post] appended registrations for ${result.componentNames.length} component(s) in ${cleanId} (${result.componentNames.join(', ')})`);
288
+ }
289
+ // map: null is fine for dev — the appended snippet sits after the
290
+ // original body, so upstream line mappings stay valid.
291
+ return { code: result.code, map: null };
292
+ },
293
+ },
294
+ // Allow external html template changes to trigger hot reload: Make .ts files depend on their .html templates
295
+ {
296
+ name: 'angular-template-deps',
297
+ enforce: 'pre',
298
+ transform(code, id) {
299
+ const componentPath = normalizeAngularWatchPath(id);
300
+ const componentKey = normalizeAngularWatchKey(id);
301
+ if (!componentKey.endsWith('.ts'))
302
+ return null;
303
+ const assetPaths = extractComponentAssetPaths(code, componentPath);
304
+ trackComponentAssets(componentKey, assetPaths);
305
+ for (const assetPath of assetPaths) {
306
+ this.addWatchFile(assetPath);
307
+ }
308
+ // First fence of the HTML→TS invalidation pipeline: no [tracking]
309
+ // log for a component means the watcher can never fire for it.
310
+ if (verbose) {
311
+ console.info(`[ns-hmr][angular-template-deps] [tracking] componentKey=${componentKey} assets=${assetPaths.length} (${assetPaths.slice(0, 4).join(', ')})`);
312
+ }
313
+ return null;
314
+ },
315
+ watchChange(id) {
316
+ const changedPath = normalizeAngularWatchPath(id);
317
+ const components = new Set();
318
+ for (const assetKey of getAngularWatchKeys(changedPath)) {
319
+ for (const componentPath of assetToComponents.get(assetKey) || []) {
320
+ components.add(componentPath);
321
+ }
322
+ }
323
+ if (components?.size) {
324
+ for (const componentPath of components) {
325
+ pendingComponentInvalidations.add(componentPath);
326
+ }
327
+ if (verbose) {
328
+ console.info(`[ns-hmr][angular-template-deps] watchChange [via assetToComponents] changed=${changedPath} → invalidating ${components.size} component(s):`, Array.from(components));
329
+ }
330
+ return;
331
+ }
332
+ if (/\.(html|htm)$/i.test(changedPath)) {
333
+ const componentPath = changedPath.replace(/\.(html|htm)$/i, '.ts');
334
+ const exists = fs.existsSync(resolveAngularWatchFilePath(componentPath));
335
+ if (exists) {
336
+ const componentKey = normalizeAngularWatchKey(componentPath);
337
+ pendingComponentInvalidations.add(componentKey);
338
+ if (verbose) {
339
+ console.info(`[ns-hmr][angular-template-deps] watchChange [via fallback .html→.ts] changed=${changedPath} componentKey=${componentKey}`);
340
+ }
341
+ }
342
+ else {
343
+ // Truly anomalous: a watched template/style asset has no companion
344
+ // `.ts` file, so we cannot route the edit through the Angular
345
+ // HMR pipeline. Always-on warning so it surfaces in non-verbose
346
+ // runs — silent fallback would hide a real wiring break.
347
+ console.warn(`[ns-hmr][angular-template-deps] watchChange [no companion .ts found] changed=${changedPath} expectedTs=${componentPath}`);
348
+ }
349
+ }
350
+ },
351
+ shouldTransformCachedModule({ id }) {
352
+ const componentPath = normalizeAngularWatchKey(id);
353
+ if (!pendingComponentInvalidations.has(componentPath))
354
+ return null;
355
+ pendingComponentInvalidations.delete(componentPath);
356
+ if (verbose) {
357
+ console.info(`[ns-hmr][angular-template-deps] shouldTransformCachedModule → re-transform componentKey=${componentPath}`);
358
+ }
359
+ return true;
360
+ },
361
+ },
362
+ // Transform Angular partial declarations in node_modules to avoid runtime JIT
363
+ // Pass the project root so linker deps resolve from the app, not the plugin package.
364
+ angularLinkerVitePlugin(process.cwd()),
365
+ // A Rollup-phase linker safety net (angularRollupLinker) is additionally
366
+ // appended for HMR sessions — see `enableRollupLinker` below.
367
+ ...angular({
368
+ experimental: {
369
+ useAngularCompilationAPI: opts.useAngularCompilationAPI,
370
+ },
371
+ // `liveReload` enables Angular's web-style in-place template HMR:
372
+ // 1. `_enableHmr = true` on the TS compiler — each compiled component
373
+ // `.mjs` emits `<ClassName>_HmrLoad` plus an
374
+ // `import.meta.hot.on('angular:component-update', ...)` listener.
375
+ // 2. A `/@ng/component?c=<id>` middleware serving recompiled
376
+ // `_UpdateMetadata` sources on demand.
377
+ // 3. `angular:component-update` broadcasts on `.html`/style edits so
378
+ // the runtime calls `ɵɵreplaceMetadata` on the live class — views
379
+ // recreate in-place with NO reboot and NO route navigation (the
380
+ // reboot path via `__reboot_ng_modules__` remains for `.ts` edits).
381
+ //
382
+ // Load-bearing interactions:
383
+ // - Analog's middleware matches `req.url.includes('/@ng/component')`
384
+ // (substring), so the `/ns/m/`-prefixed device fetch still hits it.
385
+ // - The device client (`hmr/client/protocol-dispatch.ts`) forwards
386
+ // `{ type: 'custom', event, data }` to `import.meta.hot.on`
387
+ // listeners and short-circuits before the reboot path for
388
+ // `angular:component-update`.
389
+ // - `hmr/server/websocket.ts` skips its own `ns:angular-update`
390
+ // broadcast for `.html`/component-style edits to avoid double-fire.
391
+ // - Rollback to reboot-only: set `NS_VITE_ANGULAR_LIVE_RELOAD=0`.
392
+ liveReload: hmrAngularLiveReload,
393
+ // NativeScript can't consume `externalRuntimeStyles` (runtime-loaded
394
+ // `<hash>.css` URLs need a browser CSSOM/`<link>` pipeline), so keep
395
+ // component styles inlined in the metadata's `styles: [...]` array.
396
+ // Independent of `liveReload` — template HMR stays on. The option is
397
+ // honored by our patched Analog plugin (upstream PR pending) and is a
398
+ // no-op on stock releases; not yet in the published `PluginOptions`.
399
+ // @ts-expect-error -- pending upstream Analog type publish
400
+ externalRuntimeStyles: false,
401
+ tsconfig: tsConfig,
402
+ // Forward Angular-style file replacements (e.g. `environment.ts`
403
+ // → `environment.stg.ts`) directly into the Analog plugin so the
404
+ // Angular TypeScript host (which reads source files via its own
405
+ // CompilerHost, bypassing Vite's load chain) sees the swap. This
406
+ // is the same hook Angular CLI uses for `fileReplacements` in
407
+ // `angular.json` build configurations.
408
+ fileReplacements: opts.fileReplacements ?? [],
409
+ // Component-HMR id alignment. Angular's compiler embeds each
410
+ // component's HMR id relative to the TS compilation's base path —
411
+ // in an Nx monorepo that's the WORKSPACE root (tsconfig.base.json's
412
+ // baseUrl), not the app dir. Analog uses `workspaceRoot` both to
413
+ // build the `angular:component-update` broadcast id
414
+ // (`relative(workspaceRoot, file)`) and to resolve `/@ng/component?c=`
415
+ // fetches back to absolute paths (`resolve(workspaceRoot, id)`).
416
+ // Defaulting to `process.cwd()` (the app dir) makes the broadcast id
417
+ // `src/...` while every compiled listener guards on
418
+ // `apps/<app>/src/...` — `d.id === id` never matches, so template
419
+ // edits dispatch cleanly but visually apply nothing. Default to the
420
+ // monorepo root when one exists so all three id producers agree;
421
+ // standalone apps (no monorepo root) keep the cwd behavior.
422
+ workspaceRoot: opts.workspaceRoot ?? getMonorepoWorkspaceRoot(process.cwd()) ?? process.cwd(),
423
+ }),
424
+ // Post-phase linker to catch any declarations introduced after other transforms (including project code)
425
+ angularLinkerVitePluginPost(process.cwd()),
426
+ // Re-inject `/* @vite-ignore */` onto Angular's HMR initializer dynamic
427
+ // imports. Angular emits `import(/* @vite-ignore */ i0.ɵɵgetReplaceMetadataURL(...))`,
428
+ // but the annotation gets stripped in the post-Angular pipeline
429
+ // (empirically the linker's `compact: false` Babel pass) — Vite's static
430
+ // analyzer then rewrites the call through its runtime resolver, which
431
+ // throws `TypeError at ɵɵgetReplaceMetadataURL` on the iOS device.
432
+ // `enforce: 'post'` sees the file after every comment-stripping
433
+ // transform; `apply: 'serve'` because the initializer is `ngDevMode`-
434
+ // gated and never runs in production. Idempotent.
435
+ {
436
+ name: 'ns-angular-hmr-vite-ignore',
437
+ enforce: 'post',
438
+ apply: 'serve',
439
+ transform(code, id) {
440
+ if (!hmrAngularLiveReload)
441
+ return null;
442
+ const cleanId = normalizeAngularWatchPath(id);
443
+ if (!cleanId.endsWith('.ts') && !cleanId.endsWith('.mjs') && !cleanId.endsWith('.js'))
444
+ return null;
445
+ if (cleanId.includes('/node_modules/'))
446
+ return null;
447
+ const next = injectAngularHmrViteIgnore(code);
448
+ if (next === code)
449
+ return null;
450
+ return { code: next, map: null };
451
+ },
179
452
  },
180
- configResolved(resolved) {
181
- const deps = (resolved.optimizeDeps || (resolved.optimizeDeps = {}));
182
- deps.noDiscovery = true;
183
- deps.entries = [];
184
- deps.include = [];
185
- const exclude = new Set(Array.isArray(deps.exclude) ? deps.exclude : []);
186
- ['@nativescript/core', 'rxjs', '@valor/nativescript-websockets', 'set-value', 'react', 'react-reconciler', 'react-nativescript'].forEach((x) => exclude.add(x));
187
- deps.exclude = Array.from(exclude);
188
- const rolldownOptions = (deps.rolldownOptions || (deps.rolldownOptions = {}));
189
- rolldownOptions.plugins = [];
453
+ // Enforce: fully disable dependency optimization during serve to avoid rxjs esm5 crawling and OOM
454
+ {
455
+ name: 'ns-disable-optimize-deps',
456
+ enforce: 'post',
457
+ apply: 'serve',
458
+ config(userConfig) {
459
+ const od = userConfig?.optimizeDeps || {};
460
+ const prevExclude = Array.isArray(od.exclude) ? od.exclude : [];
461
+ const exclude = new Set(prevExclude);
462
+ [...NS_OPTIMIZE_DEPS_EXCLUDE, 'rxjs'].forEach((x) => exclude.add(x));
463
+ return {
464
+ optimizeDeps: {
465
+ noDiscovery: true,
466
+ entries: [],
467
+ include: [],
468
+ exclude: Array.from(exclude),
469
+ rolldownOptions: {
470
+ ...(od.rolldownOptions || {}),
471
+ plugins: [],
472
+ },
473
+ },
474
+ };
475
+ },
476
+ configResolved(resolved) {
477
+ const resolvedConfig = resolved;
478
+ const deps = (resolvedConfig.optimizeDeps || (resolvedConfig.optimizeDeps = {}));
479
+ deps.noDiscovery = true;
480
+ deps.entries = [];
481
+ deps.include = [];
482
+ const exclude = new Set(Array.isArray(deps.exclude) ? deps.exclude : []);
483
+ [...NS_OPTIMIZE_DEPS_EXCLUDE, 'rxjs'].forEach((x) => exclude.add(x));
484
+ deps.exclude = Array.from(exclude);
485
+ const rolldownOptions = (deps.rolldownOptions || (deps.rolldownOptions = {}));
486
+ rolldownOptions.plugins = [];
487
+ },
190
488
  },
191
- },
192
- ];
193
- export const angularConfig = ({ mode }) => {
489
+ ];
490
+ }
491
+ export const angularConfig = ({ mode, fileReplacements, workspaceRoot, }) => {
492
+ const useSingleBundleDevOutput = mode === 'development' && !hmrActive;
493
+ const plugins = createAngularPlugins({
494
+ // Vite build --watch with the legacy Analog compilation path can regress
495
+ // Angular app sources from Ivy output back to decorator emit on rebuild.
496
+ // Restrict the newer compilation API to NativeScript's development no-HMR
497
+ // flow, which is where the unstable rebuilds occur today.
498
+ useAngularCompilationAPI: useSingleBundleDevOutput,
499
+ fileReplacements,
500
+ workspaceRoot,
501
+ });
502
+ // Angular browser animations are never used in NativeScript; the stub alias below is unconditional.
194
503
  const disableAnimations = true;
195
- //process.env.NS_DISABLE_NG_ANIMATIONS === "1" ||
196
- //process.env.NS_DISABLE_NG_ANIMATIONS === "true";
197
504
  // Post-link emitted chunks to catch any remaining partial declarations that slipped through
198
505
  // due to plugin order or external transforms.
506
+ const applyAngularChunkPostProcessing = (code, options = {}) => {
507
+ const codeWithInjectables = synthesizeMissingInjectableFactories(code, {
508
+ vendorInjectExport: options.vendorInjectExport,
509
+ });
510
+ const codeWithCtorParameters = synthesizeDecoratorCtorParameters(codeWithInjectables);
511
+ return inlineDecoratorComponentTemplates(codeWithCtorParameters, {
512
+ projectRoot: process.cwd(),
513
+ });
514
+ };
199
515
  const postLinker = {
200
516
  name: 'ns-angular-linker-post',
201
517
  apply: 'build',
202
518
  enforce: 'post',
203
519
  async generateBundle(_options, bundle) {
520
+ function isNsAngularPolyfillsModule(id) {
521
+ return normalizeAngularWatchPath(id).includes('node_modules/@nativescript/angular/fesm2022/nativescript-angular-polyfills.mjs');
522
+ }
204
523
  function isNsAngularPolyfillsChunk(chunk) {
205
524
  if (!chunk || !chunk.modules)
206
525
  return false;
207
- return Object.keys(chunk.modules).some((m) => m.includes('node_modules/@nativescript/angular/fesm2022/nativescript-angular-polyfills.mjs'));
526
+ return Object.keys(chunk.modules).some(isNsAngularPolyfillsModule);
208
527
  }
209
- const { babel, linkerPlugin } = await ensureSharedAngularLinker(process.cwd());
210
- if (!babel || !linkerPlugin)
528
+ const { babel, createLinker } = await getAngularLinkerFactory(process.cwd());
529
+ if (!babel || !createLinker)
211
530
  return;
212
531
  const strict = process.env.NS_STRICT_NG_LINK === '1' || process.env.NS_STRICT_NG_LINK === 'true';
213
532
  const enforceStrict = process.env.NS_STRICT_NG_LINK_ENFORCE === '1' || process.env.NS_STRICT_NG_LINK_ENFORCE === 'true';
214
533
  const debug = process.env.VITE_DEBUG_LOGS === '1' || process.env.VITE_DEBUG_LOGS === 'true';
215
534
  const unlinked = [];
535
+ const vendorInjectExport = (() => {
536
+ const vendorChunk = Object.entries(bundle).find(([name, value]) => value && value.type === 'chunk' && /(^|\/)vendor\.mjs$/.test(name));
537
+ const vendorCode = vendorChunk ? vendorChunk[1].code : undefined;
538
+ return vendorCode?.match(/\binject as ([A-Za-z_$][\w$]*)/)?.[1];
539
+ })();
216
540
  for (const [fileName, chunk] of Object.entries(bundle)) {
217
541
  if (!fileName.endsWith('.mjs') && !fileName.endsWith('.js'))
218
542
  continue;
@@ -222,44 +546,41 @@ export const angularConfig = ({ mode }) => {
222
546
  continue;
223
547
  const isNsPolyfills = isNsAngularPolyfillsChunk(chunk);
224
548
  try {
225
- const res = await babel.transformAsync(code, {
226
- filename: fileName,
227
- configFile: false,
228
- babelrc: false,
229
- sourceMaps: false,
230
- compact: false,
231
- plugins: [linkerPlugin],
232
- });
233
- const finalCode = res?.code && res.code !== code ? res.code : code;
549
+ // Fresh plugin per chunk — avoids stale linker state across watch-mode rebuilds.
550
+ const linked = await runAngularLinker(code, { filename: fileName, projectRoot: process.cwd(), freshPlugin: true });
551
+ const finalCode = applyAngularChunkPostProcessing(linked ?? code, { vendorInjectExport });
234
552
  if (finalCode !== code) {
235
553
  chunk.code = finalCode;
554
+ recordLinkerHit('post');
236
555
  if (debug) {
237
- try {
238
- console.log('[ns-angular-linker][post] linked', fileName, isNsPolyfills ? '(polyfills)' : '');
239
- }
240
- catch { }
556
+ console.log('[ns-angular-linker][post] linked', fileName, isNsPolyfills ? '(polyfills)' : '');
241
557
  }
242
558
  }
243
559
  if (strict && !isNsPolyfills && containsRealNgDeclare(finalCode)) {
244
560
  unlinked.push(fileName);
245
561
  }
246
562
  }
247
- catch {
563
+ catch (e) {
564
+ console.warn(`[ns-angular-linker][post] linking FAILED for ${fileName}:`, e?.message || e);
248
565
  if (strict)
249
566
  unlinked.push(fileName);
250
567
  }
251
568
  }
252
569
  }
570
+ // Evidence for pruning the stacked linker layers: print which of the
571
+ // five layers actually linked anything this build. A layer that
572
+ // reports 0 across the full flavor matrix is a candidate for removal.
573
+ reportLinkerLayerStats();
253
574
  if (strict && unlinked.length) {
254
575
  const details = [];
255
576
  for (const fname of unlinked) {
256
577
  const chunk = bundle[fname];
257
578
  const modIds = chunk?.modules
258
579
  ? Object.keys(chunk.modules)
259
- .filter((m) => /node_modules\/(?:@angular|@nativescript\/angular)\//.test(m))
580
+ .filter((m) => /node_modules\/(?:@angular|@nativescript\/angular)\//.test(normalizeAngularWatchPath(m)))
260
581
  .slice(0, 8)
261
582
  : [];
262
- const isOnlyPolyfills = modIds.length > 0 && modIds.every((m) => m.includes('node_modules/@nativescript/angular/fesm2022/nativescript-angular-polyfills.mjs'));
583
+ const isOnlyPolyfills = modIds.length > 0 && modIds.every(isNsAngularPolyfillsModule);
263
584
  if (isOnlyPolyfills)
264
585
  continue;
265
586
  let snippet = '';
@@ -282,89 +603,79 @@ export const angularConfig = ({ mode }) => {
282
603
  throw new Error(message);
283
604
  }
284
605
  else {
285
- try {
286
- console.warn(`[ns-angular-linker-post] ${message}`);
287
- }
288
- catch { }
606
+ console.warn(`[ns-angular-linker-post] ${message}`);
289
607
  }
290
608
  }
291
609
  },
292
610
  };
293
- // Safety net: transform each rendered chunk to link any remaining ɵɵngDeclare* call sites
611
+ // Safety net: transform each rendered chunk to link any remaining ɵɵngDeclare* call sites.
612
+ // IMPORTANT: create a FRESH linker plugin per invocation — the shared instance may have
613
+ // stale internal state from a prior build cycle, causing silent failures in watch-mode rebuilds.
294
614
  const renderChunkLinker = {
295
615
  name: 'ns-angular-linker-render',
296
616
  apply: 'build',
297
617
  enforce: 'post',
298
618
  async renderChunk(code, chunk) {
619
+ if (!code)
620
+ return null;
621
+ const filename = chunk.fileName || chunk.name || 'chunk.mjs';
622
+ const debug = process.env.VITE_DEBUG_LOGS === '1' || process.env.VITE_DEBUG_LOGS === 'true';
299
623
  try {
300
- if (!code)
301
- return null;
302
- if (!containsRealNgDeclare(code))
303
- return null;
304
- const { babel, linkerPlugin } = await ensureSharedAngularLinker(process.cwd());
305
- if (!babel || !linkerPlugin)
306
- return null;
307
- const filename = chunk.fileName || chunk.name || 'chunk.mjs';
308
- const debug = process.env.VITE_DEBUG_LOGS === '1' || process.env.VITE_DEBUG_LOGS === 'true';
309
- const runLink = async (input) => {
310
- const result = await babel.transformAsync(input, {
311
- filename,
312
- configFile: false,
313
- babelrc: false,
314
- sourceMaps: false,
315
- compact: false,
316
- plugins: [linkerPlugin],
317
- });
318
- return result?.code ?? input;
319
- };
320
- let transformed = await runLink(code);
321
- if (containsRealNgDeclare(transformed)) {
322
- transformed = await runLink(transformed);
624
+ let transformed = code;
625
+ if (containsRealNgDeclare(code)) {
626
+ const { babel, createLinker } = await getAngularLinkerFactory(process.cwd());
627
+ if (!babel || !createLinker)
628
+ return null;
629
+ // Fresh plugin per pass — avoids stale linker state across watch-mode rebuilds.
630
+ transformed = (await runAngularLinker(code, { filename, projectRoot: process.cwd(), freshPlugin: true })) ?? code;
631
+ if (containsRealNgDeclare(transformed)) {
632
+ transformed = (await runAngularLinker(transformed, { filename, projectRoot: process.cwd(), freshPlugin: true })) ?? transformed;
633
+ }
323
634
  }
635
+ transformed = applyAngularChunkPostProcessing(transformed);
324
636
  if (transformed !== code) {
637
+ recordLinkerHit('render');
325
638
  if (debug) {
326
- try {
327
- console.log('[ns-angular-linker][render] linked', filename);
328
- }
329
- catch { }
639
+ console.log('[ns-angular-linker][render] linked', filename);
330
640
  }
331
641
  return { code: transformed, map: null };
332
642
  }
333
643
  }
334
- catch { }
644
+ catch (e) {
645
+ console.warn(`[ns-angular-linker][render] linking FAILED for ${filename}:`, e?.message || e);
646
+ }
335
647
  return null;
336
648
  },
337
649
  };
338
650
  const enableRollupLinker = process.env.NS_ENABLE_ROLLUP_LINKER === '1' || process.env.NS_ENABLE_ROLLUP_LINKER === 'true' || hmrActive;
339
- return mergeConfig(baseConfig({ mode, flavor: 'angular' }), {
651
+ // Single merged alias array — a second `resolve` key from a conditional
652
+ // spread would silently clobber the fesm2022 and RxJS aliases.
653
+ const angularAliases = [
654
+ // Map Angular deep ESM paths to bare package ids
655
+ { find: /^@angular\/([^/]+)\/fesm2022\/.*\.mjs$/, replacement: '@angular/$1' },
656
+ { find: /^@nativescript\/angular\/fesm2022\/.*\.mjs$/, replacement: '@nativescript/angular' },
657
+ // RxJS esm5 → esm redirects removed: Vite 8 enforces the rxjs `exports` field,
658
+ // blocking deep path aliases. Instead, the `es2015` resolve condition is added
659
+ // below so rxjs resolves to its modern ESM builds via the exports map.
660
+ ];
661
+ if (disableAnimations) {
662
+ angularAliases.push({
663
+ find: /^@angular\/animations(\/.+)?$/, // match subpaths too
664
+ replacement: resolveRelativeToImportMeta(import.meta.url, '../shims/angular-animations-stub.js'),
665
+ }, {
666
+ find: /^@angular\/platform-browser\/animations(\/.+)?$/,
667
+ replacement: resolveRelativeToImportMeta(import.meta.url, '../shims/angular-animations-stub.js'),
668
+ });
669
+ }
670
+ const config = mergeConfig(baseConfig({ mode, flavor: 'angular' }), {
340
671
  plugins: [...plugins, ...(enableRollupLinker ? [angularRollupLinker(process.cwd())] : []), renderChunkLinker, postLinker],
341
- // Always alias fesm2022 deep imports to package root so vendor bridge can externalize properly
342
672
  resolve: {
343
- alias: [
344
- // Map Angular deep ESM paths to bare package ids
345
- { find: /^@angular\/([^/]+)\/fesm2022\/.*\.mjs$/, replacement: '@angular/$1' },
346
- { find: /^@nativescript\/angular\/fesm2022\/.*\.mjs$/, replacement: '@nativescript/angular' },
347
- // Prefer modern RxJS builds; avoid esm5 which explodes module count and memory
348
- { find: /^rxjs\/dist\/esm5\/(.*)$/, replacement: 'rxjs/dist/esm2015/$1' },
349
- { find: /^rxjs\/operators$/, replacement: 'rxjs/dist/esm2015/operators/index.js' },
350
- { find: /^rxjs$/, replacement: 'rxjs/dist/esm2015/index.js' },
351
- // Existing optional animations shims
352
- ],
673
+ alias: angularAliases,
674
+ // Add 'es2015' condition so RxJS resolves to dist/esm (modern ESM) rather
675
+ // than dist/esm5 via the 'default' condition. This avoids the esm5 module
676
+ // explosion and OOM while respecting the package's exports field in Vite 8.
677
+ conditions: ['es2015'],
353
678
  },
354
- ...(disableAnimations && {
355
- resolve: {
356
- alias: [
357
- {
358
- find: /^@angular\/animations(\/.+)?$/, // match subpaths too
359
- replacement: new URL('../shims/angular-animations-stub.js', import.meta.url).pathname,
360
- },
361
- {
362
- find: /^@angular\/platform-browser\/animations(\/.+)?$/,
363
- replacement: new URL('../shims/angular-animations-stub.js', import.meta.url).pathname,
364
- },
365
- ],
366
- },
367
- }),
368
679
  // Disable dependency optimization entirely for NativeScript Angular HMR.
369
680
  // Vite 5.1+: use noDiscovery with an empty include list (disabled was removed).
370
681
  // The HTTP loader + vendor bridge manage dependencies; pre-bundling can OOM.
@@ -376,5 +687,19 @@ export const angularConfig = ({ mode }) => {
376
687
  rolldownOptions: { plugins: [] },
377
688
  },
378
689
  });
690
+ if (useSingleBundleDevOutput) {
691
+ const build = (config.build ?? (config.build = {}));
692
+ const rolldownOptions = (build.rolldownOptions ?? (build.rolldownOptions = {}));
693
+ const outputConfigs = Array.isArray(rolldownOptions.output) ? rolldownOptions.output : [rolldownOptions.output ?? {}];
694
+ for (const output of outputConfigs) {
695
+ // Angular non-HMR reloads are more reliable when rebuilds keep a single boot bundle.
696
+ // This avoids watch-time chunk alias/name drift that can leave the native app reloading into stale split points.
697
+ delete output.manualChunks;
698
+ delete output.chunkFileNames;
699
+ output.codeSplitting = false;
700
+ }
701
+ rolldownOptions.output = Array.isArray(rolldownOptions.output) ? outputConfigs : outputConfigs[0];
702
+ }
703
+ return config;
379
704
  };
380
705
  //# sourceMappingURL=angular.js.map