@nativescript/vite 8.0.0-alpha.6 → 8.0.0-alpha.61

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