@nativescript/vite 8.0.0-alpha.9 → 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 (554) hide show
  1. package/README.md +89 -14
  2. package/bin/cli.cjs +8 -14
  3. package/configuration/angular.d.ts +34 -1
  4. package/configuration/angular.js +196 -217
  5. package/configuration/angular.js.map +1 -1
  6. package/configuration/base.js +152 -104
  7. package/configuration/base.js.map +1 -1
  8. package/configuration/javascript.js +14 -93
  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 +51 -6
  13. package/configuration/solid.js.map +1 -1
  14. package/configuration/typescript.js +11 -92
  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/css-platform-plugin.d.ts +14 -0
  34. package/helpers/css-platform-plugin.js +43 -25
  35. package/helpers/css-platform-plugin.js.map +1 -1
  36. package/helpers/dev-host.d.ts +360 -0
  37. package/helpers/dev-host.js +694 -0
  38. package/helpers/dev-host.js.map +1 -0
  39. package/helpers/dynamic-import-plugin.d.ts +2 -1
  40. package/helpers/dynamic-import-plugin.js +59 -53
  41. package/helpers/dynamic-import-plugin.js.map +1 -1
  42. package/helpers/esbuild-platform-resolver.js +4 -1
  43. package/helpers/esbuild-platform-resolver.js.map +1 -1
  44. package/helpers/external-configs.d.ts +10 -12
  45. package/helpers/external-configs.js +58 -35
  46. package/helpers/external-configs.js.map +1 -1
  47. package/helpers/flavor.d.ts +31 -0
  48. package/helpers/flavor.js +53 -2
  49. package/helpers/flavor.js.map +1 -1
  50. package/helpers/global-defines.d.ts +100 -33
  51. package/helpers/global-defines.js +192 -66
  52. package/helpers/global-defines.js.map +1 -1
  53. package/helpers/hmr-scope.d.ts +26 -0
  54. package/helpers/hmr-scope.js +67 -0
  55. package/helpers/hmr-scope.js.map +1 -0
  56. package/helpers/init.js +24 -26
  57. package/helpers/init.js.map +1 -1
  58. package/helpers/logging.d.ts +11 -1
  59. package/helpers/logging.js +45 -2
  60. package/helpers/logging.js.map +1 -1
  61. package/helpers/main-entry.d.ts +4 -1
  62. package/helpers/main-entry.js +293 -40
  63. package/helpers/main-entry.js.map +1 -1
  64. package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
  65. package/helpers/nativeclass-esbuild-plugin.js +6 -1
  66. package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
  67. package/helpers/nativeclass-transform.d.ts +13 -0
  68. package/helpers/nativeclass-transform.js +37 -7
  69. package/helpers/nativeclass-transform.js.map +1 -1
  70. package/helpers/nativeclass-transformer-plugin.js +8 -3
  71. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  72. package/helpers/nativescript-package-resolver.js +10 -62
  73. package/helpers/nativescript-package-resolver.js.map +1 -1
  74. package/helpers/normalize-id.d.ts +42 -0
  75. package/helpers/normalize-id.js +60 -0
  76. package/helpers/normalize-id.js.map +1 -0
  77. package/helpers/ns-core-external-urls.d.ts +32 -0
  78. package/helpers/ns-core-external-urls.js +107 -0
  79. package/helpers/ns-core-external-urls.js.map +1 -0
  80. package/helpers/ns-core-url.d.ts +26 -3
  81. package/helpers/ns-core-url.js +66 -8
  82. package/helpers/ns-core-url.js.map +1 -1
  83. package/helpers/optimize-deps.d.ts +16 -0
  84. package/helpers/optimize-deps.js +17 -0
  85. package/helpers/optimize-deps.js.map +1 -0
  86. package/helpers/package-platform-aliases.js +34 -49
  87. package/helpers/package-platform-aliases.js.map +1 -1
  88. package/helpers/platform-types.d.ts +2 -0
  89. package/helpers/platform-types.js +2 -0
  90. package/helpers/platform-types.js.map +1 -0
  91. package/helpers/postcss-platform-config.d.ts +17 -1
  92. package/helpers/postcss-platform-config.js +20 -37
  93. package/helpers/postcss-platform-config.js.map +1 -1
  94. package/helpers/resolve-main-field-platform.d.ts +20 -0
  95. package/helpers/resolve-main-field-platform.js +49 -0
  96. package/helpers/resolve-main-field-platform.js.map +1 -0
  97. package/helpers/resolver.js +17 -2
  98. package/helpers/resolver.js.map +1 -1
  99. package/helpers/theme-core-plugins.js +1 -1
  100. package/helpers/theme-core-plugins.js.map +1 -1
  101. package/helpers/ts-config-paths.d.ts +32 -0
  102. package/helpers/ts-config-paths.js +143 -62
  103. package/helpers/ts-config-paths.js.map +1 -1
  104. package/helpers/typescript-check.d.ts +3 -3
  105. package/helpers/typescript-check.js +4 -4
  106. package/helpers/typescript-check.js.map +1 -1
  107. package/helpers/ui-registration.d.ts +21 -0
  108. package/helpers/ui-registration.js +156 -0
  109. package/helpers/ui-registration.js.map +1 -0
  110. package/helpers/utils.d.ts +9 -0
  111. package/helpers/utils.js +22 -2
  112. package/helpers/utils.js.map +1 -1
  113. package/helpers/vite-package-version.d.ts +7 -0
  114. package/helpers/vite-package-version.js +44 -0
  115. package/helpers/vite-package-version.js.map +1 -0
  116. package/helpers/workers.d.ts +33 -0
  117. package/helpers/workers.js +237 -10
  118. package/helpers/workers.js.map +1 -1
  119. package/hmr/client/css-handler.d.ts +2 -1
  120. package/hmr/client/css-handler.js +63 -32
  121. package/hmr/client/css-handler.js.map +1 -1
  122. package/hmr/client/css-update-overlay.d.ts +18 -0
  123. package/hmr/client/css-update-overlay.js +27 -0
  124. package/hmr/client/css-update-overlay.js.map +1 -0
  125. package/hmr/client/framework-client-strategy.d.ts +117 -0
  126. package/hmr/client/framework-client-strategy.js +18 -0
  127. package/hmr/client/framework-client-strategy.js.map +1 -0
  128. package/hmr/client/framework.d.ts +31 -0
  129. package/hmr/client/framework.js +17 -0
  130. package/hmr/client/framework.js.map +1 -0
  131. package/hmr/client/hmr-pending-overlay.d.ts +0 -14
  132. package/hmr/client/hmr-pending-overlay.js +2 -11
  133. package/hmr/client/hmr-pending-overlay.js.map +1 -1
  134. package/hmr/client/hot-context.d.ts +89 -0
  135. package/hmr/client/hot-context.js +404 -0
  136. package/hmr/client/hot-context.js.map +1 -0
  137. package/hmr/client/index.d.ts +9 -1
  138. package/hmr/client/index.js +70 -1970
  139. package/hmr/client/index.js.map +1 -1
  140. package/hmr/client/overlay-driver.d.ts +10 -0
  141. package/hmr/client/overlay-driver.js +33 -0
  142. package/hmr/client/overlay-driver.js.map +1 -0
  143. package/hmr/client/protocol-dispatch.d.ts +8 -0
  144. package/hmr/client/protocol-dispatch.js +308 -0
  145. package/hmr/client/protocol-dispatch.js.map +1 -0
  146. package/hmr/client/root-reset.d.ts +15 -0
  147. package/hmr/client/root-reset.js +358 -0
  148. package/hmr/client/root-reset.js.map +1 -0
  149. package/hmr/client/strategy-loader.d.ts +24 -0
  150. package/hmr/client/strategy-loader.js +136 -0
  151. package/hmr/client/strategy-loader.js.map +1 -0
  152. package/hmr/client/update-pipeline.d.ts +27 -0
  153. package/hmr/client/update-pipeline.js +489 -0
  154. package/hmr/client/update-pipeline.js.map +1 -0
  155. package/hmr/client/utils.d.ts +9 -1
  156. package/hmr/client/utils.js +117 -97
  157. package/hmr/client/utils.js.map +1 -1
  158. package/hmr/client/ws-transport.d.ts +21 -0
  159. package/hmr/client/ws-transport.js +323 -0
  160. package/hmr/client/ws-transport.js.map +1 -0
  161. package/hmr/entry-runtime.d.ts +2 -1
  162. package/hmr/entry-runtime.js +279 -44
  163. package/hmr/entry-runtime.js.map +1 -1
  164. package/hmr/framework-flavors.d.ts +59 -0
  165. package/hmr/framework-flavors.js +108 -0
  166. package/hmr/framework-flavors.js.map +1 -0
  167. package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
  168. package/hmr/frameworks/angular/build/angular-linker.js +113 -0
  169. package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
  170. package/{helpers/angular → hmr/frameworks/angular/build}/inject-component-hmr-registration.js +2 -70
  171. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
  172. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
  173. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
  174. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
  175. package/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.js +1 -170
  176. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
  177. package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
  178. package/{helpers/angular/synthesize-decorator-ctor-parameters.js → hmr/frameworks/angular/build/js-lexer.js} +22 -96
  179. package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
  180. package/hmr/frameworks/angular/build/linker-stats.d.ts +18 -0
  181. package/hmr/frameworks/angular/build/linker-stats.js +29 -0
  182. package/hmr/frameworks/angular/build/linker-stats.js.map +1 -0
  183. package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
  184. package/hmr/frameworks/angular/build/shared-linker.js +128 -0
  185. package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
  186. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
  187. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
  188. package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.js +1 -174
  189. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
  190. package/hmr/frameworks/angular/build/ts-fallback-transform.d.ts +5 -0
  191. package/hmr/frameworks/angular/build/ts-fallback-transform.js +138 -0
  192. package/hmr/frameworks/angular/build/ts-fallback-transform.js.map +1 -0
  193. package/hmr/frameworks/angular/build/util.js.map +1 -0
  194. package/hmr/frameworks/angular/build/worker-url-preserve.d.ts +5 -0
  195. package/hmr/frameworks/angular/build/worker-url-preserve.js +140 -0
  196. package/hmr/frameworks/angular/build/worker-url-preserve.js.map +1 -0
  197. package/hmr/frameworks/angular/client/index.d.ts +0 -1
  198. package/hmr/frameworks/angular/client/index.js +360 -194
  199. package/hmr/frameworks/angular/client/index.js.map +1 -1
  200. package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
  201. package/hmr/frameworks/angular/client/strategy.js +19 -0
  202. package/hmr/frameworks/angular/client/strategy.js.map +1 -0
  203. package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
  204. package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
  205. package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
  206. package/hmr/frameworks/angular/server/ng-component-route.d.ts +43 -0
  207. package/hmr/frameworks/angular/server/ng-component-route.js +113 -0
  208. package/hmr/frameworks/angular/server/ng-component-route.js.map +1 -0
  209. package/hmr/frameworks/angular/server/strategy.js +668 -13
  210. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  211. package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.js +2 -2
  212. package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
  213. package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.d.ts +27 -11
  214. package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.js +179 -107
  215. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
  216. package/hmr/frameworks/react/client/strategy.d.ts +12 -0
  217. package/hmr/frameworks/react/client/strategy.js +27 -0
  218. package/hmr/frameworks/react/client/strategy.js.map +1 -0
  219. package/hmr/frameworks/react/server/strategy.d.ts +2 -0
  220. package/hmr/frameworks/react/server/strategy.js +230 -0
  221. package/hmr/frameworks/react/server/strategy.js.map +1 -0
  222. package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
  223. package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
  224. package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
  225. package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
  226. package/hmr/frameworks/solid/client/app-runtime.js +252 -0
  227. package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
  228. package/hmr/frameworks/solid/client/strategy.d.ts +7 -0
  229. package/hmr/frameworks/solid/client/strategy.js +391 -0
  230. package/hmr/frameworks/solid/client/strategy.js.map +1 -0
  231. package/hmr/frameworks/solid/server/strategy.js +293 -16
  232. package/hmr/frameworks/solid/server/strategy.js.map +1 -1
  233. package/hmr/frameworks/typescript/client/strategy.d.ts +7 -0
  234. package/hmr/frameworks/typescript/client/strategy.js +418 -0
  235. package/hmr/frameworks/typescript/client/strategy.js.map +1 -0
  236. package/hmr/frameworks/typescript/server/strategy.js +40 -14
  237. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  238. package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
  239. package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
  240. package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
  241. package/hmr/frameworks/vue/client/index.d.ts +10 -1
  242. package/hmr/frameworks/vue/client/index.js +270 -521
  243. package/hmr/frameworks/vue/client/index.js.map +1 -1
  244. package/hmr/frameworks/vue/client/navigate-app.d.ts +3 -0
  245. package/hmr/frameworks/vue/client/navigate-app.js +178 -0
  246. package/hmr/frameworks/vue/client/navigate-app.js.map +1 -0
  247. package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
  248. package/hmr/frameworks/vue/client/strategy.js +152 -0
  249. package/hmr/frameworks/vue/client/strategy.js.map +1 -0
  250. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
  251. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +124 -0
  252. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
  253. package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
  254. package/hmr/frameworks/vue/server/compiler.js +3 -1
  255. package/hmr/frameworks/vue/server/compiler.js.map +1 -1
  256. package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
  257. package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
  258. package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
  259. package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
  260. package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
  261. package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
  262. package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
  263. package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
  264. package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
  265. package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
  266. package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
  267. package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
  268. package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
  269. package/hmr/frameworks/vue/server/strategy.js +291 -7
  270. package/hmr/frameworks/vue/server/strategy.js.map +1 -1
  271. package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
  272. package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
  273. package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
  274. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  275. package/hmr/helpers/ast-normalizer.js +109 -14
  276. package/hmr/helpers/ast-normalizer.js.map +1 -1
  277. package/hmr/helpers/package-exports.d.ts +16 -0
  278. package/hmr/helpers/package-exports.js +396 -0
  279. package/hmr/helpers/package-exports.js.map +1 -0
  280. package/hmr/helpers/vendor-rewrite.d.ts +1 -1
  281. package/hmr/helpers/vendor-rewrite.js +5 -3
  282. package/hmr/helpers/vendor-rewrite.js.map +1 -1
  283. package/hmr/server/boot-recording.d.ts +51 -0
  284. package/hmr/server/boot-recording.js +214 -0
  285. package/hmr/server/boot-recording.js.map +1 -0
  286. package/hmr/server/constants.js +7 -1
  287. package/hmr/server/constants.js.map +1 -1
  288. package/hmr/server/content-css-update.d.ts +54 -0
  289. package/hmr/server/content-css-update.js +78 -0
  290. package/hmr/server/content-css-update.js.map +1 -0
  291. package/hmr/server/core-bundle.d.ts +140 -0
  292. package/hmr/server/core-bundle.js +614 -0
  293. package/hmr/server/core-bundle.js.map +1 -0
  294. package/hmr/server/core-sanitize.d.ts +86 -7
  295. package/hmr/server/core-sanitize.js +155 -37
  296. package/hmr/server/core-sanitize.js.map +1 -1
  297. package/hmr/server/css-connect-sync.d.ts +28 -0
  298. package/hmr/server/css-connect-sync.js +59 -0
  299. package/hmr/server/css-connect-sync.js.map +1 -0
  300. package/hmr/server/css-device-module.d.ts +28 -0
  301. package/hmr/server/css-device-module.js +44 -0
  302. package/hmr/server/css-device-module.js.map +1 -0
  303. package/hmr/server/css-update-message.d.ts +23 -0
  304. package/hmr/server/css-update-message.js +41 -0
  305. package/hmr/server/css-update-message.js.map +1 -0
  306. package/hmr/server/deps-bundle.d.ts +233 -0
  307. package/hmr/server/deps-bundle.js +1022 -0
  308. package/hmr/server/deps-bundle.js.map +1 -0
  309. package/hmr/server/device-transform-helpers.d.ts +24 -0
  310. package/hmr/server/device-transform-helpers.js +408 -0
  311. package/hmr/server/device-transform-helpers.js.map +1 -0
  312. package/hmr/server/framework-strategy.d.ts +182 -11
  313. package/hmr/server/hmr-module-graph.d.ts +37 -0
  314. package/hmr/server/hmr-module-graph.js +215 -0
  315. package/hmr/server/hmr-module-graph.js.map +1 -0
  316. package/hmr/server/import-map.d.ts +57 -23
  317. package/hmr/server/import-map.js +142 -70
  318. package/hmr/server/import-map.js.map +1 -1
  319. package/hmr/server/index.js +7 -16
  320. package/hmr/server/index.js.map +1 -1
  321. package/hmr/server/node-builtins-route.d.ts +12 -0
  322. package/hmr/server/node-builtins-route.js +86 -0
  323. package/hmr/server/node-builtins-route.js.map +1 -0
  324. package/hmr/server/ns-m-response-memo.d.ts +10 -0
  325. package/hmr/server/ns-m-response-memo.js +33 -0
  326. package/hmr/server/ns-m-response-memo.js.map +1 -0
  327. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  328. package/hmr/server/ns-rt-bridge.js +131 -0
  329. package/hmr/server/ns-rt-bridge.js.map +1 -0
  330. package/hmr/server/ns-rt-route.d.ts +5 -0
  331. package/hmr/server/ns-rt-route.js +39 -0
  332. package/hmr/server/ns-rt-route.js.map +1 -0
  333. package/hmr/server/perf-instrumentation.d.ts +1 -1
  334. package/hmr/server/perf-instrumentation.js +3 -1
  335. package/hmr/server/perf-instrumentation.js.map +1 -1
  336. package/hmr/server/process-code-for-device.d.ts +54 -0
  337. package/hmr/server/process-code-for-device.js +832 -0
  338. package/hmr/server/process-code-for-device.js.map +1 -0
  339. package/hmr/server/require-guard.d.ts +1 -0
  340. package/hmr/server/require-guard.js +12 -0
  341. package/hmr/server/require-guard.js.map +1 -0
  342. package/hmr/server/rewrite-imports.d.ts +2 -0
  343. package/hmr/server/rewrite-imports.js +631 -0
  344. package/hmr/server/rewrite-imports.js.map +1 -0
  345. package/hmr/server/route-helpers.d.ts +7 -0
  346. package/hmr/server/route-helpers.js +13 -0
  347. package/hmr/server/route-helpers.js.map +1 -0
  348. package/hmr/server/runtime-graph-filter.js +8 -1
  349. package/hmr/server/runtime-graph-filter.js.map +1 -1
  350. package/hmr/server/server-origin.d.ts +2 -0
  351. package/hmr/server/server-origin.js +88 -0
  352. package/hmr/server/server-origin.js.map +1 -0
  353. package/hmr/server/shared-transform-request.js +1 -2
  354. package/hmr/server/shared-transform-request.js.map +1 -1
  355. package/hmr/server/socket-utils.d.ts +10 -0
  356. package/hmr/server/socket-utils.js +14 -0
  357. package/hmr/server/socket-utils.js.map +1 -0
  358. package/hmr/server/transform-cache-invalidation.d.ts +37 -0
  359. package/hmr/server/transform-cache-invalidation.js +156 -0
  360. package/hmr/server/transform-cache-invalidation.js.map +1 -0
  361. package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
  362. package/hmr/server/vendor-bare-module-shims.js +80 -0
  363. package/hmr/server/vendor-bare-module-shims.js.map +1 -0
  364. package/hmr/server/vite-plugin.d.ts +1 -0
  365. package/hmr/server/vite-plugin.js +211 -53
  366. package/hmr/server/vite-plugin.js.map +1 -1
  367. package/hmr/server/websocket-core-bridge.d.ts +51 -4
  368. package/hmr/server/websocket-core-bridge.js +62 -49
  369. package/hmr/server/websocket-core-bridge.js.map +1 -1
  370. package/hmr/server/websocket-device-transform.d.ts +3 -0
  371. package/hmr/server/websocket-device-transform.js +7 -0
  372. package/hmr/server/websocket-device-transform.js.map +1 -0
  373. package/hmr/server/websocket-hmr-pending.d.ts +2 -16
  374. package/hmr/server/websocket-hmr-pending.js +0 -22
  375. package/hmr/server/websocket-hmr-pending.js.map +1 -1
  376. package/hmr/server/websocket-hot-update.d.ts +80 -0
  377. package/hmr/server/websocket-hot-update.js +299 -0
  378. package/hmr/server/websocket-hot-update.js.map +1 -0
  379. package/hmr/server/websocket-import-map-route.d.ts +15 -0
  380. package/hmr/server/websocket-import-map-route.js +51 -0
  381. package/hmr/server/websocket-import-map-route.js.map +1 -0
  382. package/hmr/server/websocket-module-bindings.d.ts +15 -0
  383. package/hmr/server/websocket-module-bindings.js +36 -3
  384. package/hmr/server/websocket-module-bindings.js.map +1 -1
  385. package/hmr/server/websocket-module-specifiers.d.ts +2 -5
  386. package/hmr/server/websocket-module-specifiers.js +42 -30
  387. package/hmr/server/websocket-module-specifiers.js.map +1 -1
  388. package/hmr/server/websocket-ns-core.d.ts +34 -0
  389. package/hmr/server/websocket-ns-core.js +414 -0
  390. package/hmr/server/websocket-ns-core.js.map +1 -0
  391. package/hmr/server/websocket-ns-entry.d.ts +21 -0
  392. package/hmr/server/websocket-ns-entry.js +163 -0
  393. package/hmr/server/websocket-ns-entry.js.map +1 -0
  394. package/hmr/server/websocket-ns-m-paths.d.ts +19 -3
  395. package/hmr/server/websocket-ns-m-paths.js +98 -75
  396. package/hmr/server/websocket-ns-m-paths.js.map +1 -1
  397. package/hmr/server/websocket-ns-m-request.d.ts +2 -1
  398. package/hmr/server/websocket-ns-m-request.js +3 -2
  399. package/hmr/server/websocket-ns-m-request.js.map +1 -1
  400. package/hmr/server/websocket-ns-m.d.ts +52 -0
  401. package/hmr/server/websocket-ns-m.js +592 -0
  402. package/hmr/server/websocket-ns-m.js.map +1 -0
  403. package/hmr/server/websocket-served-module-helpers.d.ts +65 -3
  404. package/hmr/server/websocket-served-module-helpers.js +457 -140
  405. package/hmr/server/websocket-served-module-helpers.js.map +1 -1
  406. package/hmr/server/websocket-txn.js +6 -9
  407. package/hmr/server/websocket-txn.js.map +1 -1
  408. package/hmr/server/websocket-vendor-unifier.d.ts +0 -1
  409. package/hmr/server/websocket-vendor-unifier.js +4 -9
  410. package/hmr/server/websocket-vendor-unifier.js.map +1 -1
  411. package/hmr/server/websocket.d.ts +6 -40
  412. package/hmr/server/websocket.js +661 -6751
  413. package/hmr/server/websocket.js.map +1 -1
  414. package/hmr/shared/ns-globals.d.ts +108 -0
  415. package/hmr/shared/ns-globals.js +29 -0
  416. package/hmr/shared/ns-globals.js.map +1 -0
  417. package/hmr/shared/protocol.d.ts +157 -0
  418. package/hmr/shared/protocol.js +28 -0
  419. package/hmr/shared/protocol.js.map +1 -0
  420. package/hmr/shared/runtime/boot-complete.d.ts +14 -0
  421. package/hmr/shared/runtime/boot-complete.js +32 -0
  422. package/hmr/shared/runtime/boot-complete.js.map +1 -0
  423. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  424. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  425. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  426. package/hmr/shared/runtime/boot-progress.d.ts +44 -0
  427. package/hmr/shared/runtime/boot-progress.js +134 -0
  428. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  429. package/hmr/shared/runtime/boot-timeline.d.ts +1 -1
  430. package/hmr/shared/runtime/boot-timeline.js +8 -19
  431. package/hmr/shared/runtime/boot-timeline.js.map +1 -1
  432. package/hmr/shared/runtime/browser-runtime-contract.d.ts +58 -25
  433. package/hmr/shared/runtime/browser-runtime-contract.js +21 -9
  434. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -1
  435. package/hmr/shared/runtime/dev-overlay-ios.d.ts +87 -0
  436. package/hmr/shared/runtime/dev-overlay-ios.js +521 -0
  437. package/hmr/shared/runtime/dev-overlay-ios.js.map +1 -0
  438. package/hmr/shared/runtime/dev-overlay-shared.d.ts +58 -0
  439. package/hmr/shared/runtime/dev-overlay-shared.js +116 -0
  440. package/hmr/shared/runtime/dev-overlay-shared.js.map +1 -0
  441. package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
  442. package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
  443. package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
  444. package/hmr/shared/runtime/dev-overlay-tree.d.ts +59 -0
  445. package/hmr/shared/runtime/dev-overlay-tree.js +712 -0
  446. package/hmr/shared/runtime/dev-overlay-tree.js.map +1 -0
  447. package/hmr/shared/runtime/dev-overlay.d.ts +23 -69
  448. package/hmr/shared/runtime/dev-overlay.js +67 -1011
  449. package/hmr/shared/runtime/dev-overlay.js.map +1 -1
  450. package/hmr/shared/runtime/global-scope.d.ts +18 -0
  451. package/hmr/shared/runtime/global-scope.js +21 -0
  452. package/hmr/shared/runtime/global-scope.js.map +1 -0
  453. package/hmr/shared/runtime/hooks.js +2 -1
  454. package/hmr/shared/runtime/hooks.js.map +1 -1
  455. package/hmr/shared/runtime/launch-bridge.d.ts +9 -0
  456. package/hmr/shared/runtime/launch-bridge.js +98 -0
  457. package/hmr/shared/runtime/launch-bridge.js.map +1 -0
  458. package/hmr/shared/runtime/module-provenance.js +3 -2
  459. package/hmr/shared/runtime/module-provenance.js.map +1 -1
  460. package/hmr/shared/runtime/ns-runtime-test-double.d.ts +21 -0
  461. package/hmr/shared/runtime/ns-runtime-test-double.js +20 -0
  462. package/hmr/shared/runtime/ns-runtime-test-double.js.map +1 -0
  463. package/hmr/shared/runtime/overlay-flag.d.ts +9 -0
  464. package/hmr/shared/runtime/overlay-flag.js +34 -0
  465. package/hmr/shared/runtime/overlay-flag.js.map +1 -0
  466. package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
  467. package/hmr/shared/runtime/root-placeholder-view.js +311 -0
  468. package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
  469. package/hmr/shared/runtime/root-placeholder.js +382 -157
  470. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  471. package/hmr/shared/runtime/session-bootstrap.js +209 -54
  472. package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
  473. package/hmr/shared/runtime/vendor-bootstrap.js +2 -1
  474. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  475. package/hmr/shared/runtime/vendor-resolve.d.ts +22 -0
  476. package/hmr/shared/runtime/vendor-resolve.js +45 -0
  477. package/hmr/shared/runtime/vendor-resolve.js.map +1 -0
  478. package/hmr/shared/runtime/worker-tracking.d.ts +28 -0
  479. package/hmr/shared/runtime/worker-tracking.js +114 -0
  480. package/hmr/shared/runtime/worker-tracking.js.map +1 -0
  481. package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
  482. package/hmr/shared/vendor/manifest-collect.js +909 -0
  483. package/hmr/shared/vendor/manifest-collect.js.map +1 -0
  484. package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
  485. package/hmr/shared/vendor/manifest-loader.js +5 -3
  486. package/hmr/shared/vendor/manifest-loader.js.map +1 -1
  487. package/hmr/shared/vendor/manifest.d.ts +10 -35
  488. package/hmr/shared/vendor/manifest.js +154 -978
  489. package/hmr/shared/vendor/manifest.js.map +1 -1
  490. package/hmr/shared/vendor/registry.d.ts +2 -0
  491. package/hmr/shared/vendor/registry.js +14 -0
  492. package/hmr/shared/vendor/registry.js.map +1 -1
  493. package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
  494. package/hmr/shared/vendor/vendor-device-shim.js +208 -0
  495. package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
  496. package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +107 -0
  497. package/hmr/shared/vendor/vendor-esbuild-plugins.js +540 -0
  498. package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
  499. package/package.json +70 -13
  500. package/runtime/core-aliases-early.js +11 -16
  501. package/runtime/core-aliases-early.js.map +1 -1
  502. package/shims/react-jsx-runtime.d.ts +4 -0
  503. package/shims/react-jsx-runtime.js +61 -0
  504. package/shims/react-jsx-runtime.js.map +1 -0
  505. package/helpers/angular/angular-linker.d.ts +0 -13
  506. package/helpers/angular/angular-linker.js +0 -185
  507. package/helpers/angular/angular-linker.js.map +0 -1
  508. package/helpers/angular/inject-component-hmr-registration.js.map +0 -1
  509. package/helpers/angular/inline-decorator-component-templates.js.map +0 -1
  510. package/helpers/angular/shared-linker.d.ts +0 -11
  511. package/helpers/angular/shared-linker.js +0 -75
  512. package/helpers/angular/shared-linker.js.map +0 -1
  513. package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +0 -1
  514. package/helpers/angular/synthesize-injectable-factories.js.map +0 -1
  515. package/helpers/angular/util.js.map +0 -1
  516. package/helpers/module-runner-patch.d.ts +0 -3
  517. package/helpers/module-runner-patch.js +0 -63
  518. package/helpers/module-runner-patch.js.map +0 -1
  519. package/helpers/prelink-angular.d.ts +0 -2
  520. package/helpers/prelink-angular.js +0 -114
  521. package/helpers/prelink-angular.js.map +0 -1
  522. package/hmr/server/websocket-angular-entry.js.map +0 -1
  523. package/hmr/server/websocket-angular-hot-update.js.map +0 -1
  524. package/hmr/server/websocket-ns-m-finalize.d.ts +0 -22
  525. package/hmr/server/websocket-ns-m-finalize.js +0 -88
  526. package/hmr/server/websocket-ns-m-finalize.js.map +0 -1
  527. package/hmr/server/websocket-runtime-compat.d.ts +0 -19
  528. package/hmr/server/websocket-runtime-compat.js +0 -287
  529. package/hmr/server/websocket-runtime-compat.js.map +0 -1
  530. package/hmr/server/websocket-vue-sfc.d.ts +0 -27
  531. package/hmr/server/websocket-vue-sfc.js +0 -1069
  532. package/hmr/server/websocket-vue-sfc.js.map +0 -1
  533. package/hmr/shared/runtime/http-only-boot.d.ts +0 -2
  534. package/hmr/shared/runtime/http-only-boot.js +0 -171
  535. package/hmr/shared/runtime/http-only-boot.js.map +0 -1
  536. package/hmr/vendor-bootstrap.d.ts +0 -3
  537. package/hmr/vendor-bootstrap.js +0 -32
  538. package/hmr/vendor-bootstrap.js.map +0 -1
  539. package/shims/react-reconciler-constants.d.ts +0 -14
  540. package/shims/react-reconciler-constants.js +0 -21
  541. package/shims/react-reconciler-constants.js.map +0 -1
  542. package/shims/react-reconciler.d.ts +0 -8
  543. package/shims/react-reconciler.js +0 -15
  544. package/shims/react-reconciler.js.map +0 -1
  545. package/transformers/NativeClass/index.d.ts +0 -2
  546. package/transformers/NativeClass/index.js +0 -222
  547. package/transformers/NativeClass/index.js.map +0 -1
  548. /package/{helpers/angular → hmr/frameworks/angular/build}/inject-component-hmr-registration.d.ts +0 -0
  549. /package/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.d.ts +0 -0
  550. /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-decorator-ctor-parameters.d.ts +0 -0
  551. /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.d.ts +0 -0
  552. /package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +0 -0
  553. /package/{helpers/angular → hmr/frameworks/angular/build}/util.js +0 -0
  554. /package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.d.ts +0 -0
@@ -0,0 +1,832 @@
1
+ // Device code-transform: cleans Vite/framework noise out of a served module,
2
+ // injects NativeScript build globals + the process.env shim, normalizes
3
+ // imports/helpers for the on-device ESM runtime, and collects an importer's
4
+ // app-relative dependencies. Pure functions only.
5
+ import { sanitizeStrayCoreReferences, isDeepCoreSubpath } from './core-sanitize.js';
6
+ import * as path from 'path';
7
+ import * as PAT from './constants.js';
8
+ import { astNormalizeModuleImportsAndHelpers, astVerifyAndAnnotateDuplicates } from '../helpers/ast-normalizer.js';
9
+ import { stripDanglingViteCjsImports } from '../helpers/sanitize.js';
10
+ import { getVendorManifest, resolveVendorSpecifier } from '../shared/vendor/registry.js';
11
+ import { getProjectRootPath } from '../../helpers/project.js';
12
+ import { getCliFlags, resolvePlatform } from '../../helpers/cli-flags.js';
13
+ import { resolveVerboseFlag } from '../../helpers/logging.js';
14
+ import { getProjectFlavor } from '../../helpers/flavor.js';
15
+ import { buildDefineShimStatements, buildGuardedDefineSeedStatement, buildUserDefineShimStatements, getRuntimeDefineValues, getUserProcessEnvDefineEntries } from '../../helpers/global-defines.js';
16
+ import { linkAngularPartialsIfNeeded } from '../frameworks/angular/server/linker.js';
17
+ import { isCoreGlobalsReference, isNativeScriptCoreModule, isNativeScriptPluginModule, normalizeNativeScriptCoreSpecifier, resolveVendorFromCandidate } from './websocket-module-specifiers.js';
18
+ import { ensureNativeScriptModuleBindings, getProcessCodeResolvedSpecifierOverrides } from './websocket-module-bindings.js';
19
+ import { deduplicateLinkerImports, ensureDestructureRtImports, ensureVariableDynamicImportHelper, hoistTopLevelStaticImports, repairImportEqualsAssignments, stripCoreGlobalsImports, stripViteDynamicImportVirtual } from './websocket-served-module-helpers.js';
20
+ import { buildNodeModuleProvenancePrelude, normalizeImportPath, removeNamedImports, rewriteVitePrebundleImportsForDevice, shouldRemapImport } from './device-transform-helpers.js';
21
+ import { nsConfigToJson } from '../../helpers/utils.js';
22
+ // Build a serialized process.env object from CLI --env.* flags.
23
+ // This is injected into every HTTP-served module so app code referencing
24
+ // process.env.TEST_ENV (etc.) works on device in HMR dev mode.
25
+ const __processEnvEntries = { NODE_ENV: 'development' };
26
+ try {
27
+ const flags = getCliFlags();
28
+ for (const [k, v] of Object.entries(flags || {})) {
29
+ // Skip internal NativeScript build flags
30
+ if (['ios', 'android', 'visionos', 'platform', 'hmr', 'verbose'].includes(k))
31
+ continue;
32
+ __processEnvEntries[k] = String(v);
33
+ }
34
+ }
35
+ catch { }
36
+ // Serialized lazily (and cached) so the app's `process.env.<KEY>` define
37
+ // entries — captured from the resolved Vite config in `configResolved`, i.e.
38
+ // AFTER this module evaluates — are included. Production bundles get those
39
+ // values via Vite's textual substitution; raw-served HMR modules only see
40
+ // this shim. CLI --env.* flags win on key collisions (they are the more
41
+ // specific, per-invocation input).
42
+ let __processEnvJsonCache = null;
43
+ function getProcessEnvJson() {
44
+ if (__processEnvJsonCache === null) {
45
+ __processEnvJsonCache = JSON.stringify({ ...getUserProcessEnvDefineEntries(), ...__processEnvEntries });
46
+ }
47
+ return __processEnvJsonCache;
48
+ }
49
+ // Canonical define values resolved once
50
+ const __runtimeDefines = (() => {
51
+ let platform;
52
+ let verbose = false;
53
+ try {
54
+ platform = resolvePlatform();
55
+ verbose = resolveVerboseFlag();
56
+ }
57
+ catch { }
58
+ return { platform, values: getRuntimeDefineValues({ platform, isDevMode: true, verbose }) };
59
+ })();
60
+ // Guarded platform seed injected ahead of the per-module define shims so
61
+ // whichever HTTP-served module evaluates FIRST seeds globalThis correctly.
62
+ //
63
+ // Why this is needed: under HMR the device bundle's externalized core imports
64
+ // (`import "http://…/ns/core/globals"` etc.) evaluate BEFORE the bundle's own
65
+ // body per ESM semantics — so the bundle's inlined `virtual:ns-defines-seed`
66
+ // statements have NOT run when the HTTP core graph instantiates. Without this
67
+ // seed, code reading `globalThis.__APPLE__` directly would see undefined.
68
+ // Only emitted when a platform flag was actually detected — seeding
69
+ // all-false platform flags would be worse than not seeding.
70
+ const __platformSeed = __runtimeDefines.platform ? buildGuardedDefineSeedStatement(__runtimeDefines.values) : '';
71
+ /**
72
+ * True when the served module id names a worker ENTRY by the NativeScript
73
+ * `.worker` filename convention (`zip.worker.ts`, `effect.worker`, …). The
74
+ * /ns/m route strips script extensions, so match both the extensionless and
75
+ * extension-carrying forms, ignoring any query suffix.
76
+ */
77
+ export function isWorkerEntryModuleId(sourceId) {
78
+ if (!sourceId) {
79
+ return false;
80
+ }
81
+ const clean = sourceId.split('?')[0];
82
+ return /\.worker(?:\.(?:ts|tsx|js|jsx|mjs|mts|cts))?$/i.test(clean);
83
+ }
84
+ // Default-import forms of the app's nativescript.config-as-JSON module:
85
+ // the Vite-resolved virtual id (`/@id/__x00__nsvite:nsconfig-json`, any query
86
+ // suffix) and the raw `~/package.json` alias it originates from (see
87
+ // helpers/config-as-json.ts).
88
+ const NS_CONFIG_VIRTUAL_IMPORT_RE = /(^|\n)([\t ]*)import\s+([A-Za-z_$][\w$]*)\s+from\s*["'](?:\/@id\/(?:__x00__)?|\0)?nsvite:nsconfig-json[^"']*["'];?/g;
89
+ const NS_CONFIG_TILDE_IMPORT_RE = /(^|\n)([\t ]*)import\s+([A-Za-z_$][\w$]*)\s+from\s*["']~\/package\.json(?:\?[^"']*)?["'];?/g;
90
+ let cachedNsConfigJsonLiteral = null;
91
+ function getNsConfigJsonLiteral() {
92
+ if (cachedNsConfigJsonLiteral === null) {
93
+ try {
94
+ cachedNsConfigJsonLiteral = JSON.stringify(nsConfigToJson());
95
+ }
96
+ catch {
97
+ // No nativescript.config reachable (tests, bare fixtures) — the
98
+ // importers only read optional profiling/cssParser hints from it.
99
+ cachedNsConfigJsonLiteral = '{}';
100
+ }
101
+ }
102
+ return cachedNsConfigJsonLiteral;
103
+ }
104
+ /**
105
+ * Inline the app's nativescript.config JSON where a served module default-
106
+ * imports it. @nativescript/core's `profiling/index.ts` and
107
+ * `ui/styling/style-scope.ts` do `import appConfig from '~/package.json'`,
108
+ * which Vite resolves to the `nsvite:nsconfig-json` virtual module and emits
109
+ * as `/@id/__x00__nsvite:nsconfig-json`. The generic /@id/ virtual-import
110
+ * strip in processCodeForDevice would delete that import and leave a bare
111
+ * `appConfig` reference — a `ReferenceError: appConfig is not defined` at
112
+ * module eval (hit when monorepo core source is served through /ns/m).
113
+ * Replacing the import with `const <name> = <config-json>;` mirrors what the
114
+ * production build (config-as-json.ts) and the dev core bundle
115
+ * (core-bundle.ts's nsConfigPlugin) already provide.
116
+ */
117
+ export function inlineNsConfigVirtualImports(code) {
118
+ if (!code || (!code.includes('nsvite:nsconfig-json') && !code.includes('~/package.json')))
119
+ return code;
120
+ const replace = (_m, pfx, indent, name) => `${pfx}${indent}const ${name} = ${getNsConfigJsonLiteral()};`;
121
+ return code.replace(NS_CONFIG_VIRTUAL_IMPORT_RE, replace).replace(NS_CONFIG_TILDE_IMPORT_RE, replace);
122
+ }
123
+ // Canonical hot-context id for a served app module: project-relative,
124
+ // extensionless, query-free. Must agree with `canonicalHotKey` in
125
+ // `hmr/client/hot-context.ts` so cold-boot evaluation and HMR re-evaluation
126
+ // resolve the same `hot.data` entry.
127
+ export function computeHotContextId(sourceId, projectRoot) {
128
+ if (!sourceId || typeof sourceId !== 'string')
129
+ return null;
130
+ let id = sourceId.split('?')[0].split('#')[0].replace(/\\/g, '/');
131
+ if (!id)
132
+ return null;
133
+ id = id.replace(/^\/@fs/, '');
134
+ if (projectRoot) {
135
+ const rootPosix = projectRoot.replace(/\\/g, '/').replace(/\/$/, '');
136
+ if (rootPosix && id.startsWith(rootPosix + '/')) {
137
+ id = id.slice(rootPosix.length);
138
+ }
139
+ }
140
+ if (id.startsWith('/ns/m/'))
141
+ id = id.slice('/ns/m'.length);
142
+ id = id.replace(/\.(ts|tsx|js|jsx|mjs|mts|cts)$/i, '');
143
+ if (!id.startsWith('/'))
144
+ id = '/' + id;
145
+ return id;
146
+ }
147
+ // One-line `import.meta.hot` prelude. Single-statement, no internal `;` or
148
+ // newline, so that if any later sanitize pass re-applies
149
+ // `IMPORT_META_HOT_ASSIGNMENT` the whole statement strips cleanly (module
150
+ // degrades to `import.meta.hot === undefined` instead of a SyntaxError).
151
+ // The registry global is installed by the `/__ns_dev__/client` bootstrap
152
+ // BEFORE the entry graph evaluates; outside dev it's absent and the
153
+ // expression yields `undefined`, matching Vite's production semantics.
154
+ export function buildHotContextPrelude(hotContextId) {
155
+ const idJson = JSON.stringify(hotContextId);
156
+ return `import.meta.hot = globalThis.__NS_HOT_REGISTRY__ && globalThis.__NS_HOT_REGISTRY__.createHotContext ? globalThis.__NS_HOT_REGISTRY__.createHotContext(${idJson}) : undefined;\n`;
157
+ }
158
+ function collectImportDependencies(code, importerPath) {
159
+ const importerDir = path.posix.dirname(importerPath);
160
+ const deps = new Set();
161
+ const patterns = [PAT.IMPORT_PATTERN_1, PAT.IMPORT_PATTERN_2, PAT.EXPORT_PATTERN, PAT.IMPORT_PATTERN_3];
162
+ for (const pattern of patterns) {
163
+ pattern.lastIndex = 0;
164
+ let match;
165
+ while ((match = pattern.exec(code)) !== null) {
166
+ const rawSpec = match[2];
167
+ const spec = normalizeNativeScriptCoreSpecifier(rawSpec);
168
+ if (!spec || !shouldRemapImport(spec)) {
169
+ continue;
170
+ }
171
+ if (resolveVendorFromCandidate(spec)) {
172
+ continue;
173
+ }
174
+ // Manifest-aware vendor spec detection
175
+ try {
176
+ if (resolveVendorSpecifier && resolveVendorSpecifier(spec)) {
177
+ continue;
178
+ }
179
+ }
180
+ catch { }
181
+ const normalized = normalizeImportPath(spec, importerDir);
182
+ if (normalized) {
183
+ if (resolveVendorFromCandidate(normalized)) {
184
+ continue;
185
+ }
186
+ try {
187
+ if (resolveVendorSpecifier && resolveVendorSpecifier(normalized)) {
188
+ continue;
189
+ }
190
+ }
191
+ catch { }
192
+ if (isCoreGlobalsReference(normalized)) {
193
+ continue;
194
+ }
195
+ if (isNativeScriptCoreModule(normalized)) {
196
+ continue;
197
+ }
198
+ if (isNativeScriptPluginModule(normalized)) {
199
+ continue;
200
+ }
201
+ deps.add(normalized);
202
+ }
203
+ }
204
+ }
205
+ return deps;
206
+ }
207
+ function cleanCode(code, strategy, options) {
208
+ let result = code;
209
+ // Remove Vite client and hot module noise ('$1' keeps the preceding
210
+ // newline/semicolon boundary — see VITE_CLIENT_IMPORT in constants.ts).
211
+ // Vite's own `import.meta.hot = __vite__createHotContext(...)` targets the
212
+ // browser client; we strip it and processCodeForDevice injects the NS
213
+ // hot-context prelude instead (JS-owned import.meta.hot).
214
+ result = result.replace(PAT.VITE_CLIENT_IMPORT, '$1');
215
+ result = result.replace(PAT.IMPORT_META_HOT_ASSIGNMENT, '');
216
+ result = strategy.preClean?.(result) ?? result;
217
+ result = strategy.rewriteFrameworkImports?.(result) ?? result;
218
+ // Vendor manifest-driven import rewrites
219
+ // NOTE: Static and side-effect vendor imports are intentionally NOT rewritten here.
220
+ // They are left as import statements so that ensureNativeScriptModuleBindings()
221
+ // (called later in processCodeForDevice) can transform them using the robust
222
+ // __nsVendorRequire + __nsPick pattern that works on device.
223
+ // Only dynamic imports are handled here since ensureNativeScriptModuleBindings
224
+ // does not process dynamic import() calls.
225
+ try {
226
+ const manifest = getVendorManifest();
227
+ if (manifest) {
228
+ // Dynamic import rewrites: import('pkg') -> Promise.resolve(__nsVendor('id'))
229
+ const dynImportRE = /(import\(\s*["'])([^"']+)(["']\s*\))/g;
230
+ result = result.replace(dynImportRE, (full, pre, spec, post) => {
231
+ if (isNativeScriptCoreModule(spec))
232
+ return full;
233
+ const resolved = resolveVendorSpecifier(spec);
234
+ if (!resolved || /^@nativescript\/core(\b|\/)/i.test(resolved))
235
+ return full;
236
+ return `Promise.resolve(__nsVendor(${JSON.stringify(resolved)}))`;
237
+ });
238
+ }
239
+ }
240
+ catch (e) {
241
+ // Non-fatal; fallback to original code if manifest logic fails
242
+ }
243
+ result = result.replace(PAT.VITE_CLIENT_IMPORT, '$1').replace(PAT.IMPORT_META_HOT_ASSIGNMENT, '');
244
+ // The stripped /@vite/client import may have carried the `injectQuery`
245
+ // binding (Vite 8 rewrites worker/url dynamic imports to
246
+ // `__vite__injectQuery(url, 'import')`). Shim it as identity — query
247
+ // injection is meaningless for the on-device HTTP loader.
248
+ if (/\b__vite__injectQuery\s*\(/.test(result) && !/(?:const|let|var|function)\s+__vite__injectQuery\b/.test(result)) {
249
+ result = `const __vite__injectQuery = (url) => url;\n` + result;
250
+ }
251
+ // Clean up HMR noise
252
+ result = strategy.postClean?.(result) ?? result;
253
+ if (!options?.workerRealm)
254
+ result = stripCoreGlobalsImports(result);
255
+ return result;
256
+ }
257
+ /**
258
+ * Process code for device: inject globals, remove framework imports
259
+ */
260
+ function processCodeForDevice(code, isVitePreBundled, preserveVendorImports = false, isNodeModule = false, sourceId, options) {
261
+ let result = code;
262
+ const resolvedSpecifierOverrides = options?.resolvedSpecifierOverrides || getProcessCodeResolvedSpecifierOverrides(sourceId, getProjectRootPath());
263
+ const bindingOptions = {
264
+ preserveNonPluginVendorImports: preserveVendorImports,
265
+ resolvedSpecifierOverrides,
266
+ // Worker entries evaluate in their own realm, where the main realm's
267
+ // vendor registry / __nsRequire never exist — route their vendor
268
+ // imports to the /ns/m/node_modules HTTP ESM form instead (realm-local
269
+ // copy via the deps-bundle bridge, matching webpack's per-worker
270
+ // bundling semantics). Entry-level detection by the `.worker` filename
271
+ // convention; a worker's TRANSITIVE imports share URLs with the main
272
+ // realm and cannot be forked per-realm, so plugins consumed by worker
273
+ // code should be imported from the worker entry itself.
274
+ vendorImportsAsHttp: options?.workerRealm || isWorkerEntryModuleId(sourceId),
275
+ };
276
+ // Ensure Angular partial declarations are linked before any sanitizers run so runtime never hits the JIT path.
277
+ result = linkAngularPartialsIfNeeded(result);
278
+ // Post-linker: deduplicate/resolve imports the Angular linker injected with bare specifiers
279
+ result = deduplicateLinkerImports(result);
280
+ // First: aggressively strip any lingering virtual dynamic-import-helper before anything else.
281
+ // Doing this up-front prevents downstream dependency collection from seeing the virtual id.
282
+ result = stripViteDynamicImportVirtual(result);
283
+ // Skip reactive injection for Vite pre-bundled deps (they have Vue bundled already)
284
+ if (isVitePreBundled) {
285
+ return result;
286
+ }
287
+ // Inject ALL NativeScript/build globals at the top (matching global-defines.ts)
288
+ // This ensures any code using __DEV__, __ANDROID__, __IOS__, etc. works correctly
289
+ const allGlobals = [
290
+ // Minimal process shim — populated with CLI --env.* flags at module load time.
291
+ // In production builds, Vite/Rollup replaces process.env.* statically.
292
+ // In HMR dev mode the code runs as-is on device, so we need the shim.
293
+ //
294
+ // IMPORTANT: every check goes through `globalThis.process` (a member
295
+ // expression), NEVER bare `typeof process` (an identifier reference).
296
+ // bare identifier resolution
297
+ // against runtime-added global object properties is not reliable in
298
+ // V8 module scope. `globalThis.process` is unambiguous: it always
299
+ // reads the `process` property off the (single) global object.
300
+ //
301
+ // The shim is also strictly additive — it only initializes
302
+ // `globalThis.process` and `globalThis.process.env` if they are
303
+ // missing. App code that pre-populates `process.env` (e.g. an Azure
304
+ // App Configuration boot module) is preserved; we never overwrite a
305
+ // populated env with the bare `{ NODE_ENV: 'development' }` stub.
306
+ `if (typeof globalThis.process === "undefined" || globalThis.process === null) { globalThis.process = { env: ${getProcessEnvJson()} }; } else if (!globalThis.process.env) { globalThis.process.env = ${getProcessEnvJson()}; }`,
307
+ // Seed platform defines from the dev server's CLI flags BEFORE the const
308
+ // shims snapshot them — see __platformSeed above for the ESM-ordering
309
+ // rationale (externalized core imports evaluate before the bundle body).
310
+ ...(__platformSeed ? [__platformSeed] : []),
311
+ // Per-module shim consts with canonical fallbacks — generated from the
312
+ // same getRuntimeDefineValues source as the seed and Vite's `define`.
313
+ ...buildDefineShimStatements(__runtimeDefines.values),
314
+ // App-configured `__FOO__` defines (e.g. __NS_NATIVE_OVERRIDES__). Excludes
315
+ // the builtin keys just shimmed above so we never emit a duplicate `const`.
316
+ ...buildUserDefineShimStatements(Object.keys(__runtimeDefines.values)),
317
+ ];
318
+ result = allGlobals.join('\n') + '\n' + result;
319
+ const nodeModuleProvenancePrelude = buildNodeModuleProvenancePrelude(sourceId);
320
+ if (nodeModuleProvenancePrelude) {
321
+ result = nodeModuleProvenancePrelude + result;
322
+ }
323
+ // JS-owned `import.meta.hot`: app modules get a hot context bound to
324
+ // their canonical id (library code never registers hot boundaries).
325
+ if (!isNodeModule) {
326
+ const hotContextId = computeHotContextId(sourceId, getProjectRootPath());
327
+ if (hotContextId) {
328
+ result = buildHotContextPrelude(hotContextId) + result;
329
+ }
330
+ }
331
+ // AST normalization: inject /ns/rt helper aliases for underscore-prefixed identifiers.
332
+ // ONLY for app source files — library code in node_modules should be served as-is.
333
+ // Running the normalizer on libraries like tslib injects harmful destructures
334
+ // (e.g., `const { SuppressedError } = __ns_rt_ns_1`) that shadow globals.
335
+ if (!isNodeModule) {
336
+ // CRITICAL ORDERING: canonicalise any bare `@nativescript/core[/sub]`
337
+ // specifiers to `/ns/core[/sub]` BEFORE the AST normaliser sees them.
338
+ // `astNormalizeModuleImportsAndHelpers` defensively rewrites bare
339
+ // `@nativescript/core` imports and emits a one-shot
340
+ // `[ast-normalizer] unexpected @nativescript/core spec` warning —
341
+ // the warning means the upstream rewriter regressed. For Vue SFC
342
+ // `<script>` blocks the bare specifier flows through Vite's
343
+ // transform pipeline without a per-statement source-string rewrite
344
+ // (Vite's resolver only edits the module graph, not the emitted
345
+ // code), so the only upstream rewriter that can canonicalise these
346
+ // in dev mode is this regex sweep. Running it here keeps the AST
347
+ // normaliser purely a tripwire instead of an active rewriter.
348
+ try {
349
+ result = sanitizeStrayCoreReferences(result);
350
+ }
351
+ catch { }
352
+ try {
353
+ // The unsound underscore TEXT-SCAN fallback inside the normalizer is
354
+ // only meaningful for compiled Vue template helpers; on every other
355
+ // flavor it has misread app/library internals as helpers (see the
356
+ // fallback's comment in ast-normalizer.ts). AST-based detection stays
357
+ // on for all flavors.
358
+ result = astNormalizeModuleImportsAndHelpers(result, { underscoreTextFallback: getProjectFlavor() === 'vue' });
359
+ }
360
+ catch { }
361
+ // Verify there are no duplicate top-level const/let bindings after AST normalization
362
+ try {
363
+ result = astVerifyAndAnnotateDuplicates(result);
364
+ }
365
+ catch { }
366
+ }
367
+ // If AST marker present OR this is a node_modules file, skip regex-based helper
368
+ // alias injection. Library code should NOT get /ns/rt destructures injected —
369
+ // underscore-prefixed identifiers in libraries are internal variables, not NS helpers.
370
+ // Vue-only for the same reason as the normalizer's text fallback: /ns/rt
371
+ // underscore helpers (`_toDisplayString`, …) only exist in compiled Vue
372
+ // template output; on other flavors this scope-blind regex misreads app
373
+ // internals as helpers.
374
+ if (getProjectFlavor() === 'vue' && !isNodeModule && !/^\s*(?:\/\/|\/\*) \[ast-normalized\]/m.test(result)) {
375
+ try {
376
+ const underscored = new Set();
377
+ // `(?![\w$])` (not `\b`): `\w` excludes `$`, so `\b` would match the prefix
378
+ // `_Symbol` inside Babel temp vars like `_Symbol$toStringTag`.
379
+ const re = /(^|[^.\w$])_([A-Za-z]\w*)(?![\w$])/g;
380
+ let m;
381
+ while ((m = re.exec(result))) {
382
+ const name = m[2];
383
+ if (name === 'ctx' || name === 'cache')
384
+ continue;
385
+ if (name.startsWith('hoisted_'))
386
+ continue;
387
+ if (name.startsWith('component_'))
388
+ continue;
389
+ if (name.startsWith('directive_'))
390
+ continue;
391
+ if (name === 'sfc_main')
392
+ continue;
393
+ if (name === 'ns_sfc__' || name.startsWith('ns_sfc'))
394
+ continue;
395
+ if (name.startsWith('sfc'))
396
+ continue;
397
+ try {
398
+ const declRE = new RegExp(`(^|\\n)\\s*(?:const|let|var)\\s+_${name}\\b`);
399
+ if (declRE.test(result))
400
+ continue;
401
+ }
402
+ catch { }
403
+ underscored.add(name);
404
+ }
405
+ if (underscored.size) {
406
+ const needed = [];
407
+ for (const n of underscored) {
408
+ const aliasNeedle = new RegExp(`\\b${n}\\s+as\\s+_${n}\\b`);
409
+ if (!aliasNeedle.test(result))
410
+ needed.push(n);
411
+ }
412
+ if (needed.length) {
413
+ const importLine = `import { ${needed.map((n) => `${n} as _${n}`).join(', ')} } from "/ns/rt";\n`;
414
+ result = importLine + result;
415
+ }
416
+ }
417
+ }
418
+ catch { }
419
+ }
420
+ // In strict dev mode, proactively surface duplicate-binding diagnostics to avoid "already declared" runtime errors
421
+ try {
422
+ if (/^\s*\/\/ \[ast-verify\]\[duplicate-bindings\]/m.test(result)) {
423
+ const diagnosticLine = (result.match(/^\s*\/\/ \[ast-verify\]\[duplicate-bindings\][^\n]*/m) || [])[0] || '// [ast-verify][duplicate-bindings]';
424
+ const brief = diagnosticLine.replace(/^[^:]*:?\s?/, '');
425
+ const escaped = brief.replace(/["\\]/g, '\\$&');
426
+ const thrower = `throw new Error("[nsv-hmr] Duplicate top-level bindings detected: ${escaped}");`;
427
+ result = `${thrower}\n` + result;
428
+ }
429
+ }
430
+ catch { }
431
+ // Inline the nativescript.config JSON import BEFORE the generic /@id/
432
+ // strip below, which would otherwise delete it and leave the consumer's
433
+ // binding (`appConfig` in core's profiling/style-scope) undefined.
434
+ try {
435
+ result = inlineNsConfigVirtualImports(result);
436
+ }
437
+ catch { }
438
+ // Un-prefix REAL bare-module ids Vite serves as `/@id/<id>` (no `__x00__`
439
+ // virtual marker) BEFORE the virtual-id strip below. Vite uses `/@id/` for
440
+ // any resolved id that isn't a file path — including genuine packages that
441
+ // aren't in optimizeDeps (e.g. `html-entities`), not just virtual modules.
442
+ // Restoring the bare specifier lets the module-bindings pass route them
443
+ // like any other dependency import; deleting them left the consumer's
444
+ // bindings undefined (observed as `decode is not defined` in
445
+ // DecodeHtmlEntitiesPipe).
446
+ result = result.replace(/(import\s+[^;]+\s+from\s+["'])\/@id\/(?!__x00__)([^"']+)(["'])/g, '$1$2$3');
447
+ // Remove Vite internal imports (dynamic-import-helper, etc.)
448
+ // This handles both standalone lines and concatenated imports on the same line
449
+ // EXCEPT oxc runtime helpers (decorators etc.): Vite 8's oxc transform emits
450
+ // `import _decorate from "/@id/__x00__@oxc-project+runtime@<ver>/helpers/decorate.js"`.
451
+ // Unlike other virtual ids these are real, servable dev-server URLs returning
452
+ // self-contained ESM — stripping them leaves `_decorate`/`_decorateMetadata`
453
+ // undefined at runtime. They're origin-prefixed for the device in rewriteImports.
454
+ result = result.replace(/import\s+[^;]+\s+from\s+["']\/@id\/(?!__x00__@oxc-project\+runtime)[^"']*["'];?\s*/g, '');
455
+ // Also remove side-effect only virtual id imports like: import "/@id/__x00__vite/dynamic-import-helper.js";
456
+ // These can slip through and cause the NativeScript runtime to attempt resolving
457
+ // a non-existent physical file (e.g. /@id/__x00__vite/dynamic-import-helper.js) leading to
458
+ // module not found crashes during HMR evaluation.
459
+ if (/^[\t ]*import\s+["']\/@id\/[^"']+["'];?\s*$/m.test(result)) {
460
+ result = result.replace(/^[\t ]*import\s+["']\/@id\/[^"']+["'];?\s*$/gm, '');
461
+ // Inject a lightweight marker comment (harmless if left in output) so devs can confirm rewrite took place when viewing streamed artifact.
462
+ result = `// [hmr-sanitize] stripped virtual /@id/ side-effect imports\n${result}`;
463
+ }
464
+ // IMPORTANT: Perform vendor-module binding injection BEFORE stripping Vite prebundle imports.
465
+ // This allows the rewriter to see and canonicalize '/node_modules/.vite/deps/*' specifiers back
466
+ // to their package ids (e.g., '@nativescript/firebase-core') and generate require-based bindings
467
+ // so named imports like `{ firebase }` are preserved as const bindings.
468
+ //
469
+ // Some upstream transforms can emit a multiline form:
470
+ // import { x } from
471
+ // "/node_modules/.vite/deps/...";
472
+ // If we don't normalize it, later stripping of naked string-only lines can leave
473
+ // an invalid `import ... from` statement.
474
+ try {
475
+ result = result.replace(/(^|\n)([\t ]*import\s+[^;]*?\s+from)\s*\n\s*("\/?node_modules\/\.vite\/deps\/[^"\n]+"\s*;?\s*)/gm, (_m, p1, p2, p3) => `${p1}${p2} ${p3}`);
476
+ }
477
+ catch { }
478
+ // When preserveVendorImports is true (HMR /ns/m/ endpoint), skip the
479
+ // __nsVendorRequire + __nsPick rewrite. Vendor imports stay as bare
480
+ // specifiers so the device-side import map resolves them via V8's native
481
+ // module system, which correctly handles export * re-exports.
482
+ result = ensureNativeScriptModuleBindings(result, bindingOptions);
483
+ // Repair any accidental "import ... = expr" assignments that may have slipped in.
484
+ try {
485
+ result = repairImportEqualsAssignments(result);
486
+ }
487
+ catch { }
488
+ // Strip Vite prebundle deps imports (both named and side-effect) and any malformed const string artifacts
489
+ // Example problematic line observed: const "/node_modules/.vite/deps/@nativescript_firebase-messaging.js?v=...";
490
+ if (/node_modules\/\.vite\/deps\//.test(result)) {
491
+ result = rewriteVitePrebundleImportsForDevice(result, preserveVendorImports);
492
+ // Malformed const string lines accidentally produced by upstream transforms
493
+ result = result.replace(/^[\t ]*const\s+["']\/?node_modules\/\.vite\/deps\/[^"']+["'];?\s*$/gm, '// [hmr-sanitize] stripped malformed const prebundle ref\n');
494
+ // Naked string-only lines pointing at prebundle deps
495
+ result = result.replace(/^[\t ]*["']\/?node_modules\/\.vite\/deps\/[^"']+["'];?\s*$/gm, '// [hmr-sanitize] stripped prebundle side-effect literal\n');
496
+ }
497
+ // Dynamic aliasing covers helper imports; no further static list handling needed.
498
+ // Handle navigation helpers (dev bridge): $navigateTo, $navigateBack
499
+ // Note: do NOT inject $showModal as a named import; AST normalizer/destructure covers it when imported,
500
+ // and free-uses are handled via AST injection. This avoids duplicate identifier redeclarations.
501
+ if (/\$(?:navigate(?:To|Back)|showModal)\b/.test(result)) {
502
+ const navHelpers = [];
503
+ // Only consider free uses (not property access like obj.$navigateTo)
504
+ const needTo = /(^|[^.\w$])\$navigateTo\b/.test(result);
505
+ const needBack = /(^|[^.\w$])\$navigateBack\b/.test(result);
506
+ if (needTo)
507
+ navHelpers.push('$navigateTo');
508
+ if (needBack)
509
+ navHelpers.push('$navigateBack');
510
+ // Intentionally exclude $showModal from navHelpers injection to prevent named import reinsertion
511
+ // Remove any direct imports/usages that might shadow globals
512
+ // 1) From 'vue' or 'nativescript-vue' sources
513
+ result = removeNamedImports(result, navHelpers);
514
+ // 2) From our runtime bridge '/ns/rt' (versioned or not)
515
+ try {
516
+ // Do NOT re-introduce named imports from /ns/rt for nav helpers; drop them entirely after removing nav helpers.
517
+ const rtNamedRE = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["'](?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?["'];?\s*/gm;
518
+ // Also compute locally-declared helpers to drop regardless of free-use detection
519
+ const hasLocalToForDrop = /(^|[\n;])\s*(?:const|let|var|function)\s+\$navigateTo\b/.test(result);
520
+ const hasLocalBackForDrop = /(^|[\n;])\s*(?:const|let|var|function)\s+\$navigateBack\b/.test(result);
521
+ result = result.replace(rtNamedRE, (full, pfx, specList) => {
522
+ const drop = new Set(navHelpers);
523
+ if (hasLocalToForDrop)
524
+ drop.add('$navigateTo');
525
+ if (hasLocalBackForDrop)
526
+ drop.add('$navigateBack');
527
+ const remaining = String(specList)
528
+ .split(',')
529
+ .map((s) => s.trim())
530
+ .filter(Boolean)
531
+ .filter((entry) => {
532
+ const base = entry.split(/\s+as\s+/i)[0].trim();
533
+ return !drop.has(base);
534
+ });
535
+ if (!remaining.length)
536
+ return pfx || '';
537
+ // Preserve non-navigation named imports for later normalization
538
+ return `${pfx}import { ${remaining.join(', ')} } from "/ns/rt";`;
539
+ });
540
+ // Also strip $navigateTo/$navigateBack from any destructuring previously created from /ns/rt
541
+ // Also remove from destructures bound off any __ns_rt_ns temp (including _re)
542
+ const rtDestructureRE = /(^|[\n;])\s*const\s*\{([^}]+)\}\s*=\s*(__ns_rt_ns(?:\d+|_re))\s*;?\s*/gm;
543
+ result = result.replace(rtDestructureRE, (full, pfx, specList, varName) => {
544
+ const cleaned = String(specList)
545
+ .split(',')
546
+ .map((s) => s.trim())
547
+ .filter(Boolean)
548
+ .filter((seg) => {
549
+ const lhs = seg.split(':')[0].trim();
550
+ return !/^\$navigate(?:To|Back)$/.test(lhs);
551
+ });
552
+ if (!cleaned.length)
553
+ return pfx || '';
554
+ return `${pfx}const { ${cleaned.join(', ')} } = ${varName};`;
555
+ });
556
+ }
557
+ catch { }
558
+ // Inject named imports from /ns/rt to provide bindings without redeclaration collisions
559
+ const imports = [];
560
+ const hasImportTo = /(^|\n)\s*import\s*\{[^}]*\$navigateTo[^}]*\}\s*from\s*["'](?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?["']/.test(result);
561
+ const hasImportBack = /(^|\n)\s*import\s*\{[^}]*\$navigateBack[^}]*\}\s*from\s*["'](?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?["']/.test(result);
562
+ // Avoid adding named imports if a local binding already exists (e.g., wrapper const)
563
+ const hasLocalTo = /(^|[\n;])\s*(?:const|let|var|function)\s+\$navigateTo\b/.test(result);
564
+ const hasLocalBack = /(^|[\n;])\s*(?:const|let|var|function)\s+\$navigateBack\b/.test(result);
565
+ if (needTo && !hasImportTo && !hasLocalTo)
566
+ imports.push('$navigateTo');
567
+ if (needBack && !hasImportBack && !hasLocalBack)
568
+ imports.push('$navigateBack');
569
+ // Do not inject $showModal named import; avoid duplicates with destructures created upstream
570
+ if (imports.length) {
571
+ result = `import { ${imports.join(', ')} } from "/ns/rt";\n` + result;
572
+ }
573
+ }
574
+ // Ensure vendor bindings also apply after potential wrapper injections above
575
+ // (idempotent: second pass will be a no-op if imports already consumed).
576
+ result = ensureNativeScriptModuleBindings(result, bindingOptions);
577
+ try {
578
+ result = repairImportEqualsAssignments(result);
579
+ }
580
+ catch { }
581
+ // Rewrite any previously-injected vendor-based core access to the unified HTTP core bridge
582
+ try {
583
+ const vendorCoreRE1 = /globalThis\.__nsVendor\s*\(\s*["']@nativescript\/core["']\s*\)/g;
584
+ const vendorCoreRE2 = /__nsVendor\s*\(\s*["']@nativescript\/core["']\s*\)/g;
585
+ if (vendorCoreRE1.test(result) || vendorCoreRE2.test(result)) {
586
+ const hasImport = /import\s+__ns_core_bridge\s+from\s+["'][^"']*\/(?:\@ns|ns)\/core(?:\/[^"']+)?["']\s*;?/.test(result) || /(^|\n)\s*import\s+__ns_core_bridge\s+from\s+["']\/(?:\@ns|ns)\/core["']\s*;?/m.test(result);
587
+ if (!hasImport) {
588
+ result = `import __ns_core_bridge from "/ns/core";\n` + result;
589
+ }
590
+ result = result.replace(vendorCoreRE1, '__ns_core_bridge');
591
+ result = result.replace(vendorCoreRE2, '__ns_core_bridge');
592
+ }
593
+ }
594
+ catch { }
595
+ // Rewrite any explicit require('@nativescript/core[/sub]') calls to the unified core bridge
596
+ try {
597
+ const reqCoreRE1 = /(^|[^.\w$])require\(\s*["']@nativescript\/core([^"'\n]*)["']\s*\)/g;
598
+ const reqCoreRE2 = /(?:globalThis|window|self)\.require\(\s*["']@nativescript\/core([^"'\n]*)["']\s*\)/g;
599
+ if (reqCoreRE1.test(result) || reqCoreRE2.test(result)) {
600
+ const hasImport = /import\s+__ns_core_bridge\s+from\s+["'][^"']*\/(?:\@ns|ns)\/core(?:\/[^"']+)?["']\s*;?/.test(result) || /(^|\n)\s*import\s+__ns_core_bridge\s+from\s+["']\/(?:\@ns|ns)\/core["']\s*;?/m.test(result);
601
+ if (!hasImport) {
602
+ result = `import __ns_core_bridge from "/ns/core";\n` + result;
603
+ }
604
+ result = result.replace(reqCoreRE1, (_m, p1, _sub) => `${p1}__ns_core_bridge`);
605
+ result = result.replace(reqCoreRE2, '__ns_core_bridge');
606
+ }
607
+ }
608
+ catch { }
609
+ // Apply the three-pass safety net for stray @nativescript/core references
610
+ // (naked string literals, dangling `from` merges, lingering resolved-path
611
+ // references). Centralised in core-sanitize.sanitizeStrayCoreReferences so
612
+ // every NS-M emitter applies the same passes in the same order.
613
+ result = sanitizeStrayCoreReferences(result);
614
+ result = ensureVariableDynamicImportHelper(result);
615
+ // Normalize any lingering @nativescript/core imports to the /ns/core bridge (non-destructive best-effort)
616
+ try {
617
+ // Rewrite named imports from the /ns/core bridge into default import + destructuring.
618
+ // This makes `import { Frame } from '@nativescript/core'` work even if the bridge provides only a default export.
619
+ {
620
+ let __core_ns_seq = 0;
621
+ const toDestructureCore = (specList) => specList
622
+ .split(',')
623
+ .map((s) => s.trim())
624
+ .filter(Boolean)
625
+ .map((seg) => {
626
+ const m = seg.split(/\s+as\s+/i);
627
+ return m.length === 2 ? `${m[0].trim()}: ${m[1].trim()}` : seg;
628
+ })
629
+ .join(', ');
630
+ const reNamed = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']+)?)['"];?\s*/gm;
631
+ result = result.replace(reNamed, (_full, pfx, specList, src) => {
632
+ // Deep subpath URLs serve actual ESM with real named exports — skip.
633
+ if (isDeepCoreSubpath(src))
634
+ return _full;
635
+ __core_ns_seq++;
636
+ const tmp = `__ns_core_ns${__core_ns_seq}`;
637
+ const decl = `const { ${toDestructureCore(specList)} } = ${tmp};`;
638
+ return `${pfx}import ${tmp} from ${JSON.stringify(src)};\n${decl}\n`;
639
+ });
640
+ const reMixed = /(^|\n)\s*import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']+)?)['"];?\s*/gm;
641
+ result = result.replace(reMixed, (_full, pfx, defName, specList, src) => {
642
+ if (isDeepCoreSubpath(src))
643
+ return _full;
644
+ const decl = `const { ${toDestructureCore(specList)} } = ${defName};`;
645
+ return `${pfx}import ${defName} from ${JSON.stringify(src)};\n${decl}\n`;
646
+ });
647
+ }
648
+ }
649
+ catch { }
650
+ // Note: Removed legacy var-based underscore prelude to avoid const/var redeclaration conflicts.
651
+ // Normalize concatenated imports that may have ended up after a statement on the same line
652
+ try {
653
+ // Common concatenations
654
+ // Keep a single semicolon before the import to avoid generating ';;'
655
+ result = result.replace(/;\s*import\s+/g, ';\nimport ');
656
+ result = result.replace(/}\s*import\s+/g, '}\nimport ');
657
+ // Fallback: ensure any static import that isn't at start of line gets a newline before it.
658
+ //
659
+ // Only match after **structural** statement-ending characters: `;`, `}`, `)`, `]`. We
660
+ // deliberately do NOT include `'`, `"`, or `` ` `` here — those are string-literal
661
+ // terminators (and openers!), and including them caused the regex to fire inside
662
+ // example code embedded in error strings. Concrete failure observed:
663
+ // `@supabase/realtime-js` throws an Error whose message contains the literal
664
+ // `' import ws from "ws"\n' +`. With `'` in the delimiter class, the engine matched
665
+ // the opening `'` of that string literal as a "statement terminator" and rewrote the
666
+ // example to `'\nimport ws from "..."` — splitting the string across two lines and
667
+ // producing a SyntaxError on device. The structural delimiters below do not appear
668
+ // inside string-literal openers, so the rewrite is safe.
669
+ result = result.replace(/([;}\)\]])\s*(import\s+[^;\n]*\s+from\s*["'][^"']+["'])/g, '$1\n$2');
670
+ }
671
+ catch { }
672
+ // Collapse duplicate destructuring from the same temp namespace var (e.g., multiple const { x } = __ns_rt_ns1)
673
+ try {
674
+ const collapse = (code, prefix) => {
675
+ const re = new RegExp(`(^|\\n)\\s*const\\s*\\{([^}]+)\\}\\s*=\\s*(${prefix}\\d+)\\s*;?\\s*`, 'gm');
676
+ const byVar = {};
677
+ code.replace(re, (_full, _pfx, specList, varName) => {
678
+ const set = (byVar[varName] || (byVar[varName] = new Set()));
679
+ String(specList)
680
+ .split(',')
681
+ .map((s) => s.trim())
682
+ .filter(Boolean)
683
+ .forEach((seg) => set.add(seg));
684
+ return '';
685
+ });
686
+ if (Object.keys(byVar).length) {
687
+ // Remove all existing destructures first
688
+ code = code.replace(re, (full, pfx) => pfx || '');
689
+ // Re-emit one per var
690
+ const blocks = Object.entries(byVar).map(([varName, set]) => `const { ${Array.from(set).join(', ')} } = ${varName};`);
691
+ code = blocks.join('\n') + '\n' + code;
692
+ }
693
+ return code;
694
+ };
695
+ result = collapse(result, '__ns_rt_ns');
696
+ result = collapse(result, '__ns_core_ns');
697
+ }
698
+ catch { }
699
+ // After consolidating destructures, hoist static import declarations to the very top so imports
700
+ // always come before any statements that might reference their bindings. This ordering avoids
701
+ // device runtimes that are stricter about imports-first semantics during module instantiation.
702
+ try {
703
+ result = hoistTopLevelStaticImports(result);
704
+ }
705
+ catch { }
706
+ // Final safety: normalize any lingering named imports from /ns/rt into default+destructure
707
+ // Skip for node_modules (no /ns/rt helpers needed) and when AST marker present
708
+ try {
709
+ if (!isNodeModule && !/^\s*\/\* \[ast-normalized\] \*\//m.test(result)) {
710
+ result = ensureDestructureRtImports(result);
711
+ }
712
+ }
713
+ catch { }
714
+ // Post-pass: if both a destructure from __ns_rt_ns* and named imports from /ns/rt exist,
715
+ // remove overlapping named specifiers to avoid "Identifier has already been declared".
716
+ try {
717
+ // Collect all bindings destructured from any __ns_rt_ns* temp
718
+ const rtDestructureRE = /(^|\n)\s*const\s*\{([^}]+)\}\s*=\s*(__ns_rt_ns(?:\d+|_re))\s*;?\s*/gm;
719
+ const rtBound = new Set();
720
+ let m;
721
+ while ((m = rtDestructureRE.exec(result)) !== null) {
722
+ const specList = String(m[2] || '');
723
+ specList
724
+ .split(',')
725
+ .map((s) => s.trim())
726
+ .filter(Boolean)
727
+ .forEach((seg) => {
728
+ const bind = seg.includes(':') ? seg.split(':')[1].trim() : seg;
729
+ if (bind)
730
+ rtBound.add(bind);
731
+ });
732
+ }
733
+ if (rtBound.size) {
734
+ // Rewrite named imports from /ns/rt by removing any specifiers already provided via destructure
735
+ const rtNamedImportRE = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?)["'];?\s*/gm;
736
+ const edits = [];
737
+ while ((m = rtNamedImportRE.exec(result)) !== null) {
738
+ const full = m[0];
739
+ const pfx = m[1] || '';
740
+ const specList = String(m[2] || '');
741
+ const src = m[3];
742
+ const kept = [];
743
+ specList
744
+ .split(',')
745
+ .map((s) => s.trim())
746
+ .filter(Boolean)
747
+ .forEach((seg) => {
748
+ const name = seg.split(/\s+as\s+/i)[0].trim();
749
+ if (!rtBound.has(name))
750
+ kept.push(seg);
751
+ });
752
+ let replacement = '';
753
+ if (kept.length) {
754
+ replacement = `${pfx}import { ${kept.join(', ')} } from ${JSON.stringify(src)};`;
755
+ }
756
+ else {
757
+ // Drop the import entirely if nothing remains
758
+ replacement = pfx || '';
759
+ }
760
+ edits.push({
761
+ start: rtNamedImportRE.lastIndex - full.length,
762
+ end: rtNamedImportRE.lastIndex,
763
+ text: replacement,
764
+ });
765
+ }
766
+ if (edits.length) {
767
+ // Apply edits in reverse order
768
+ edits
769
+ .sort((a, b) => b.start - a.start)
770
+ .forEach((e) => {
771
+ result = result.slice(0, e.start) + e.text + result.slice(e.end);
772
+ });
773
+ }
774
+ }
775
+ }
776
+ catch { }
777
+ // Tidy-ups: remove stray lines that are only semicolons and collapse excessive blank lines
778
+ try {
779
+ // Remove lines that contain only an optional whitespace and a single ';'
780
+ result = result.replace(/^[ \t]*;[ \t]*$/gm, '');
781
+ // Collapse 3+ blank lines into at most 2 to keep output compact and consistent
782
+ result = result.replace(/\n{3,}/g, '\n\n');
783
+ }
784
+ catch { }
785
+ // De-duplicate destructured bindings across different temp vars to avoid 'Identifier has already been declared'
786
+ try {
787
+ const reDestructureAny = /(^|\n)\s*const\s*\{([^}]+)\}\s*=\s*(__ns_(?:rt|core)_[A-Za-z0-9_]+)\s*;?\s*/gm;
788
+ const seenBindings = new Set();
789
+ const edits = [];
790
+ let m;
791
+ while ((m = reDestructureAny.exec(result)) !== null) {
792
+ const full = m[0];
793
+ const pfx = m.index;
794
+ const specList = m[2];
795
+ const varName = m[3];
796
+ const entries = specList
797
+ .split(',')
798
+ .map((s) => s.trim())
799
+ .filter(Boolean);
800
+ const kept = [];
801
+ for (const seg of entries) {
802
+ const bind = seg.includes(':') ? seg.split(':')[1].trim() : seg;
803
+ if (seenBindings.has(bind))
804
+ continue;
805
+ seenBindings.add(bind);
806
+ kept.push(seg);
807
+ }
808
+ const replacement = kept.length ? `${m[1]}const { ${kept.join(', ')} } = ${varName};` : m[1] || '';
809
+ edits.push({ start: pfx, end: pfx + full.length, text: replacement });
810
+ }
811
+ if (edits.length) {
812
+ // Apply edits in reverse order to not mess up indices
813
+ edits
814
+ .sort((a, b) => b.start - a.start)
815
+ .forEach((e) => {
816
+ result = result.slice(0, e.start) + e.text + result.slice(e.end);
817
+ });
818
+ }
819
+ }
820
+ catch { }
821
+ // As a final safety net, neutralize any uses of Vite's CJS import helpers when the helper variable
822
+ // itself is not declared (e.g., stripped earlier during sanitation). This prevents runtime errors like
823
+ // "Cannot read properties of undefined (reading 'initNorrix')" on device when accessing
824
+ // __vite__cjsImportX__pkg["prop"].
825
+ try {
826
+ result = stripDanglingViteCjsImports(result);
827
+ }
828
+ catch { }
829
+ return result;
830
+ }
831
+ export { processCodeForDevice, cleanCode, collectImportDependencies };
832
+ //# sourceMappingURL=process-code-for-device.js.map