@nativescript/vite 8.0.0-beta.0 → 8.0.0-rc.0

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