@nativescript/vite 8.0.0-alpha.4 → 8.0.0-alpha.41

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 (410) 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 +376 -165
  5. package/configuration/angular.js.map +1 -1
  6. package/configuration/base.js +256 -30
  7. package/configuration/base.js.map +1 -1
  8. package/configuration/javascript.js +12 -90
  9. package/configuration/javascript.js.map +1 -1
  10. package/configuration/solid.js +33 -4
  11. package/configuration/solid.js.map +1 -1
  12. package/configuration/typescript.js +10 -90
  13. package/configuration/typescript.js.map +1 -1
  14. package/helpers/app-components.d.ts +2 -1
  15. package/helpers/app-components.js.map +1 -1
  16. package/helpers/app-css-state.d.ts +8 -0
  17. package/helpers/app-css-state.js +8 -0
  18. package/helpers/app-css-state.js.map +1 -0
  19. package/helpers/bundler-context.d.ts +11 -0
  20. package/helpers/bundler-context.js +71 -0
  21. package/helpers/bundler-context.js.map +1 -0
  22. package/helpers/config-as-json.js +10 -0
  23. package/helpers/config-as-json.js.map +1 -1
  24. package/helpers/css-platform-plugin.d.ts +14 -0
  25. package/helpers/css-platform-plugin.js +43 -25
  26. package/helpers/css-platform-plugin.js.map +1 -1
  27. package/helpers/dev-host.d.ts +360 -0
  28. package/helpers/dev-host.js +692 -0
  29. package/helpers/dev-host.js.map +1 -0
  30. package/helpers/dynamic-import-plugin.js +1 -1
  31. package/helpers/dynamic-import-plugin.js.map +1 -1
  32. package/helpers/esbuild-platform-resolver.js +4 -1
  33. package/helpers/esbuild-platform-resolver.js.map +1 -1
  34. package/helpers/external-configs.d.ts +10 -12
  35. package/helpers/external-configs.js +54 -35
  36. package/helpers/external-configs.js.map +1 -1
  37. package/helpers/global-defines.d.ts +128 -0
  38. package/helpers/global-defines.js +174 -11
  39. package/helpers/global-defines.js.map +1 -1
  40. package/helpers/hmr-scope.d.ts +26 -0
  41. package/helpers/hmr-scope.js +67 -0
  42. package/helpers/hmr-scope.js.map +1 -0
  43. package/helpers/init.js +0 -18
  44. package/helpers/init.js.map +1 -1
  45. package/helpers/logging.d.ts +1 -0
  46. package/helpers/logging.js +65 -4
  47. package/helpers/logging.js.map +1 -1
  48. package/helpers/main-entry.d.ts +3 -1
  49. package/helpers/main-entry.js +444 -50
  50. package/helpers/main-entry.js.map +1 -1
  51. package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
  52. package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
  53. package/helpers/nativeclass-transform.js +5 -6
  54. package/helpers/nativeclass-transform.js.map +1 -1
  55. package/helpers/nativeclass-transformer-plugin.d.ts +9 -2
  56. package/helpers/nativeclass-transformer-plugin.js +157 -14
  57. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  58. package/helpers/nativescript-package-resolver.js +10 -62
  59. package/helpers/nativescript-package-resolver.js.map +1 -1
  60. package/helpers/normalize-id.d.ts +42 -0
  61. package/helpers/normalize-id.js +60 -0
  62. package/helpers/normalize-id.js.map +1 -0
  63. package/helpers/ns-core-url.d.ts +106 -0
  64. package/helpers/ns-core-url.js +225 -0
  65. package/helpers/ns-core-url.js.map +1 -0
  66. package/helpers/optimize-deps.d.ts +16 -0
  67. package/helpers/optimize-deps.js +17 -0
  68. package/helpers/optimize-deps.js.map +1 -0
  69. package/helpers/package-platform-aliases.js +34 -49
  70. package/helpers/package-platform-aliases.js.map +1 -1
  71. package/helpers/platform-types.d.ts +2 -0
  72. package/helpers/platform-types.js +2 -0
  73. package/helpers/platform-types.js.map +1 -0
  74. package/helpers/postcss-platform-config.d.ts +17 -1
  75. package/helpers/postcss-platform-config.js +20 -37
  76. package/helpers/postcss-platform-config.js.map +1 -1
  77. package/helpers/project.d.ts +35 -0
  78. package/helpers/project.js +120 -2
  79. package/helpers/project.js.map +1 -1
  80. package/helpers/resolve-main-field-platform.d.ts +20 -0
  81. package/helpers/resolve-main-field-platform.js +49 -0
  82. package/helpers/resolve-main-field-platform.js.map +1 -0
  83. package/helpers/resolver.js +17 -2
  84. package/helpers/resolver.js.map +1 -1
  85. package/helpers/theme-core-plugins.js +1 -1
  86. package/helpers/theme-core-plugins.js.map +1 -1
  87. package/helpers/ts-config-paths.d.ts +14 -0
  88. package/helpers/ts-config-paths.js +90 -9
  89. package/helpers/ts-config-paths.js.map +1 -1
  90. package/helpers/typescript-check.d.ts +2 -1
  91. package/helpers/typescript-check.js.map +1 -1
  92. package/helpers/ui-registration.d.ts +21 -0
  93. package/helpers/ui-registration.js +156 -0
  94. package/helpers/ui-registration.js.map +1 -0
  95. package/helpers/utils.js +1 -2
  96. package/helpers/utils.js.map +1 -1
  97. package/helpers/workers.d.ts +20 -19
  98. package/helpers/workers.js +624 -4
  99. package/helpers/workers.js.map +1 -1
  100. package/hmr/client/css-handler.d.ts +2 -1
  101. package/hmr/client/css-handler.js +50 -26
  102. package/hmr/client/css-handler.js.map +1 -1
  103. package/hmr/client/css-update-overlay.d.ts +18 -0
  104. package/hmr/client/css-update-overlay.js +27 -0
  105. package/hmr/client/css-update-overlay.js.map +1 -0
  106. package/hmr/client/framework-client-strategy.d.ts +79 -0
  107. package/hmr/client/framework-client-strategy.js +19 -0
  108. package/hmr/client/framework-client-strategy.js.map +1 -0
  109. package/hmr/client/hmr-pending-overlay.d.ts +13 -0
  110. package/hmr/client/hmr-pending-overlay.js +60 -0
  111. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  112. package/hmr/client/index.js +820 -212
  113. package/hmr/client/index.js.map +1 -1
  114. package/hmr/client/utils.d.ts +7 -1
  115. package/hmr/client/utils.js +207 -29
  116. package/hmr/client/utils.js.map +1 -1
  117. package/hmr/entry-runtime.d.ts +2 -1
  118. package/hmr/entry-runtime.js +256 -69
  119. package/hmr/entry-runtime.js.map +1 -1
  120. package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
  121. package/hmr/frameworks/angular/build/angular-linker.js +109 -0
  122. package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
  123. package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
  124. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
  125. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
  126. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
  127. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
  128. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
  129. package/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.js +1 -170
  130. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
  131. package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
  132. package/{helpers/angular/synthesize-decorator-ctor-parameters.js → hmr/frameworks/angular/build/js-lexer.js} +22 -96
  133. package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
  134. package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
  135. package/hmr/frameworks/angular/build/shared-linker.js +128 -0
  136. package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
  137. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
  138. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
  139. package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.js +1 -174
  140. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
  141. package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
  142. package/hmr/frameworks/angular/build/util.js +155 -0
  143. package/hmr/frameworks/angular/build/util.js.map +1 -0
  144. package/hmr/frameworks/angular/client/index.d.ts +1 -0
  145. package/hmr/frameworks/angular/client/index.js +803 -21
  146. package/hmr/frameworks/angular/client/index.js.map +1 -1
  147. package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
  148. package/hmr/frameworks/angular/client/strategy.js +19 -0
  149. package/hmr/frameworks/angular/client/strategy.js.map +1 -0
  150. package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
  151. package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
  152. package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
  153. package/hmr/frameworks/angular/server/linker.js +1 -4
  154. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  155. package/hmr/frameworks/angular/server/strategy.js +460 -12
  156. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  157. package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.js +2 -2
  158. package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
  159. package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.d.ts +17 -11
  160. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +336 -0
  161. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
  162. package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
  163. package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
  164. package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
  165. package/hmr/frameworks/solid/server/strategy.js +291 -16
  166. package/hmr/frameworks/solid/server/strategy.js.map +1 -1
  167. package/hmr/frameworks/typescript/server/strategy.js +38 -14
  168. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  169. package/hmr/frameworks/vue/client/dep-propagation.d.ts +36 -0
  170. package/hmr/frameworks/vue/client/dep-propagation.js +101 -0
  171. package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
  172. package/hmr/frameworks/vue/client/index.d.ts +8 -0
  173. package/hmr/frameworks/vue/client/index.js +56 -243
  174. package/hmr/frameworks/vue/client/index.js.map +1 -1
  175. package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
  176. package/hmr/frameworks/vue/client/strategy.js +157 -0
  177. package/hmr/frameworks/vue/client/strategy.js.map +1 -0
  178. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
  179. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +142 -0
  180. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
  181. package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
  182. package/hmr/frameworks/vue/server/sfc-route-assemble.js +747 -0
  183. package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
  184. package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
  185. package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
  186. package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
  187. package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
  188. package/hmr/frameworks/vue/server/sfc-route-serve.js +459 -0
  189. package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
  190. package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +38 -0
  191. package/hmr/frameworks/vue/server/sfc-route-shared.js +48 -0
  192. package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
  193. package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
  194. package/hmr/frameworks/vue/server/strategy.js +278 -1
  195. package/hmr/frameworks/vue/server/strategy.js.map +1 -1
  196. package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
  197. package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
  198. package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
  199. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  200. package/hmr/helpers/ast-normalizer.js +77 -10
  201. package/hmr/helpers/ast-normalizer.js.map +1 -1
  202. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  203. package/hmr/helpers/cjs-named-exports.js +152 -0
  204. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  205. package/hmr/helpers/package-exports.d.ts +16 -0
  206. package/hmr/helpers/package-exports.js +396 -0
  207. package/hmr/helpers/package-exports.js.map +1 -0
  208. package/hmr/server/constants.js +20 -5
  209. package/hmr/server/constants.js.map +1 -1
  210. package/hmr/server/core-sanitize.d.ts +90 -7
  211. package/hmr/server/core-sanitize.js +211 -56
  212. package/hmr/server/core-sanitize.js.map +1 -1
  213. package/hmr/server/device-transform-helpers.d.ts +24 -0
  214. package/hmr/server/device-transform-helpers.js +369 -0
  215. package/hmr/server/device-transform-helpers.js.map +1 -0
  216. package/hmr/server/framework-strategy.d.ts +108 -11
  217. package/hmr/server/hmr-module-graph.d.ts +37 -0
  218. package/hmr/server/hmr-module-graph.js +214 -0
  219. package/hmr/server/hmr-module-graph.js.map +1 -0
  220. package/hmr/server/import-map.d.ts +11 -2
  221. package/hmr/server/import-map.js +95 -44
  222. package/hmr/server/import-map.js.map +1 -1
  223. package/hmr/server/index.js +7 -16
  224. package/hmr/server/index.js.map +1 -1
  225. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  226. package/hmr/server/ns-core-cjs-shape.js +271 -0
  227. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  228. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  229. package/hmr/server/ns-rt-bridge.js +131 -0
  230. package/hmr/server/ns-rt-bridge.js.map +1 -0
  231. package/hmr/server/ns-rt-route.d.ts +5 -0
  232. package/hmr/server/ns-rt-route.js +38 -0
  233. package/hmr/server/ns-rt-route.js.map +1 -0
  234. package/hmr/server/perf-instrumentation.d.ts +114 -0
  235. package/hmr/server/perf-instrumentation.js +197 -0
  236. package/hmr/server/perf-instrumentation.js.map +1 -0
  237. package/hmr/server/process-code-for-device.d.ts +14 -0
  238. package/hmr/server/process-code-for-device.js +702 -0
  239. package/hmr/server/process-code-for-device.js.map +1 -0
  240. package/hmr/server/require-guard.d.ts +1 -0
  241. package/hmr/server/require-guard.js +12 -0
  242. package/hmr/server/require-guard.js.map +1 -0
  243. package/hmr/server/rewrite-imports.d.ts +2 -0
  244. package/hmr/server/rewrite-imports.js +600 -0
  245. package/hmr/server/rewrite-imports.js.map +1 -0
  246. package/hmr/server/route-helpers.d.ts +7 -0
  247. package/hmr/server/route-helpers.js +13 -0
  248. package/hmr/server/route-helpers.js.map +1 -0
  249. package/hmr/server/server-origin.d.ts +2 -0
  250. package/hmr/server/server-origin.js +83 -0
  251. package/hmr/server/server-origin.js.map +1 -0
  252. package/hmr/server/shared-transform-request.js +13 -7
  253. package/hmr/server/shared-transform-request.js.map +1 -1
  254. package/hmr/server/transform-cache-invalidation.d.ts +37 -0
  255. package/hmr/server/transform-cache-invalidation.js +156 -0
  256. package/hmr/server/transform-cache-invalidation.js.map +1 -0
  257. package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
  258. package/hmr/server/vendor-bare-module-shims.js +80 -0
  259. package/hmr/server/vendor-bare-module-shims.js.map +1 -0
  260. package/hmr/server/vite-plugin.js +72 -42
  261. package/hmr/server/vite-plugin.js.map +1 -1
  262. package/hmr/server/websocket-core-bridge.d.ts +45 -6
  263. package/hmr/server/websocket-core-bridge.js +81 -77
  264. package/hmr/server/websocket-core-bridge.js.map +1 -1
  265. package/hmr/server/websocket-css-hot-update.d.ts +33 -0
  266. package/hmr/server/websocket-css-hot-update.js +65 -0
  267. package/hmr/server/websocket-css-hot-update.js.map +1 -0
  268. package/hmr/server/websocket-device-transform.d.ts +3 -0
  269. package/hmr/server/websocket-device-transform.js +7 -0
  270. package/hmr/server/websocket-device-transform.js.map +1 -0
  271. package/hmr/server/websocket-graph-upsert.d.ts +15 -0
  272. package/hmr/server/websocket-graph-upsert.js +20 -0
  273. package/hmr/server/websocket-graph-upsert.js.map +1 -1
  274. package/hmr/server/websocket-hmr-pending.d.ts +37 -0
  275. package/hmr/server/websocket-hmr-pending.js +55 -0
  276. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  277. package/hmr/server/websocket-hot-update.d.ts +77 -0
  278. package/hmr/server/websocket-hot-update.js +360 -0
  279. package/hmr/server/websocket-hot-update.js.map +1 -0
  280. package/hmr/server/websocket-import-map-route.d.ts +15 -0
  281. package/hmr/server/websocket-import-map-route.js +50 -0
  282. package/hmr/server/websocket-import-map-route.js.map +1 -0
  283. package/hmr/server/websocket-module-bindings.js +3 -3
  284. package/hmr/server/websocket-module-bindings.js.map +1 -1
  285. package/hmr/server/websocket-module-specifiers.d.ts +66 -2
  286. package/hmr/server/websocket-module-specifiers.js +203 -20
  287. package/hmr/server/websocket-module-specifiers.js.map +1 -1
  288. package/hmr/server/websocket-ns-core.d.ts +21 -0
  289. package/hmr/server/websocket-ns-core.js +311 -0
  290. package/hmr/server/websocket-ns-core.js.map +1 -0
  291. package/hmr/server/websocket-ns-entry.d.ts +21 -0
  292. package/hmr/server/websocket-ns-entry.js +164 -0
  293. package/hmr/server/websocket-ns-entry.js.map +1 -0
  294. package/hmr/server/websocket-ns-m-paths.d.ts +1 -1
  295. package/hmr/server/websocket-ns-m-paths.js +58 -13
  296. package/hmr/server/websocket-ns-m-paths.js.map +1 -1
  297. package/hmr/server/websocket-ns-m-request.d.ts +11 -1
  298. package/hmr/server/websocket-ns-m-request.js +18 -25
  299. package/hmr/server/websocket-ns-m-request.js.map +1 -1
  300. package/hmr/server/websocket-ns-m.d.ts +33 -0
  301. package/hmr/server/websocket-ns-m.js +752 -0
  302. package/hmr/server/websocket-ns-m.js.map +1 -0
  303. package/hmr/server/websocket-served-module-helpers.d.ts +82 -0
  304. package/hmr/server/websocket-served-module-helpers.js +879 -0
  305. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  306. package/hmr/server/websocket-txn.js +2 -8
  307. package/hmr/server/websocket-txn.js.map +1 -1
  308. package/hmr/server/websocket-vendor-unifier.d.ts +0 -1
  309. package/hmr/server/websocket-vendor-unifier.js +4 -9
  310. package/hmr/server/websocket-vendor-unifier.js.map +1 -1
  311. package/hmr/server/websocket.d.ts +8 -39
  312. package/hmr/server/websocket.js +514 -4030
  313. package/hmr/server/websocket.js.map +1 -1
  314. package/hmr/shared/ns-globals.d.ts +118 -0
  315. package/hmr/shared/ns-globals.js +29 -0
  316. package/hmr/shared/ns-globals.js.map +1 -0
  317. package/hmr/shared/protocol.d.ts +145 -0
  318. package/hmr/shared/protocol.js +28 -0
  319. package/hmr/shared/protocol.js.map +1 -0
  320. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  321. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  322. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  323. package/hmr/shared/runtime/boot-progress.d.ts +44 -0
  324. package/hmr/shared/runtime/boot-progress.js +133 -0
  325. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  326. package/hmr/shared/runtime/boot-timeline.d.ts +18 -0
  327. package/hmr/shared/runtime/boot-timeline.js +42 -0
  328. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  329. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -1
  330. package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
  331. package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
  332. package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
  333. package/hmr/shared/runtime/dev-overlay.d.ts +119 -26
  334. package/hmr/shared/runtime/dev-overlay.js +1153 -261
  335. package/hmr/shared/runtime/dev-overlay.js.map +1 -1
  336. package/hmr/shared/runtime/global-scope.d.ts +18 -0
  337. package/hmr/shared/runtime/global-scope.js +21 -0
  338. package/hmr/shared/runtime/global-scope.js.map +1 -0
  339. package/hmr/shared/runtime/hooks.js +2 -1
  340. package/hmr/shared/runtime/hooks.js.map +1 -1
  341. package/hmr/shared/runtime/http-only-boot.js +7 -6
  342. package/hmr/shared/runtime/http-only-boot.js.map +1 -1
  343. package/hmr/shared/runtime/module-provenance.js +4 -6
  344. package/hmr/shared/runtime/module-provenance.js.map +1 -1
  345. package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
  346. package/hmr/shared/runtime/root-placeholder-view.js +311 -0
  347. package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
  348. package/hmr/shared/runtime/root-placeholder.js +371 -197
  349. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  350. package/hmr/shared/runtime/session-bootstrap.js +168 -4
  351. package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
  352. package/hmr/shared/runtime/vendor-bootstrap.js +3 -10
  353. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  354. package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
  355. package/hmr/shared/vendor/manifest-collect.js +512 -0
  356. package/hmr/shared/vendor/manifest-collect.js.map +1 -0
  357. package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
  358. package/hmr/shared/vendor/manifest-loader.js +5 -3
  359. package/hmr/shared/vendor/manifest-loader.js.map +1 -1
  360. package/hmr/shared/vendor/manifest.d.ts +1 -7
  361. package/hmr/shared/vendor/manifest.js +102 -741
  362. package/hmr/shared/vendor/manifest.js.map +1 -1
  363. package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
  364. package/hmr/shared/vendor/vendor-device-shim.js +208 -0
  365. package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
  366. package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +16 -0
  367. package/hmr/shared/vendor/vendor-esbuild-plugins.js +203 -0
  368. package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
  369. package/hmr/vendor-bootstrap.d.ts +1 -3
  370. package/hmr/vendor-bootstrap.js +4 -6
  371. package/hmr/vendor-bootstrap.js.map +1 -1
  372. package/index.d.ts +1 -0
  373. package/index.js +5 -0
  374. package/index.js.map +1 -1
  375. package/package.json +55 -11
  376. package/runtime/core-aliases-early.js +25 -55
  377. package/runtime/core-aliases-early.js.map +1 -1
  378. package/helpers/angular/angular-linker.d.ts +0 -13
  379. package/helpers/angular/angular-linker.js +0 -194
  380. package/helpers/angular/angular-linker.js.map +0 -1
  381. package/helpers/angular/inline-decorator-component-templates.js.map +0 -1
  382. package/helpers/angular/shared-linker.d.ts +0 -11
  383. package/helpers/angular/shared-linker.js +0 -75
  384. package/helpers/angular/shared-linker.js.map +0 -1
  385. package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +0 -1
  386. package/helpers/angular/synthesize-injectable-factories.js.map +0 -1
  387. package/helpers/angular/util.js +0 -67
  388. package/helpers/angular/util.js.map +0 -1
  389. package/helpers/prelink-angular.d.ts +0 -2
  390. package/helpers/prelink-angular.js +0 -117
  391. package/helpers/prelink-angular.js.map +0 -1
  392. package/hmr/server/websocket-angular-entry.js.map +0 -1
  393. package/hmr/server/websocket-angular-hot-update.js +0 -239
  394. package/hmr/server/websocket-angular-hot-update.js.map +0 -1
  395. package/hmr/server/websocket-ns-m-finalize.d.ts +0 -32
  396. package/hmr/server/websocket-ns-m-finalize.js +0 -73
  397. package/hmr/server/websocket-ns-m-finalize.js.map +0 -1
  398. package/hmr/server/websocket-runtime-compat.d.ts +0 -19
  399. package/hmr/server/websocket-runtime-compat.js +0 -286
  400. package/hmr/server/websocket-runtime-compat.js.map +0 -1
  401. package/hmr/server/websocket-vue-sfc.d.ts +0 -35
  402. package/hmr/server/websocket-vue-sfc.js +0 -1116
  403. package/hmr/server/websocket-vue-sfc.js.map +0 -1
  404. package/transformers/NativeClass/index.d.ts +0 -2
  405. package/transformers/NativeClass/index.js +0 -222
  406. package/transformers/NativeClass/index.js.map +0 -1
  407. /package/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.d.ts +0 -0
  408. /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-decorator-ctor-parameters.d.ts +0 -0
  409. /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.d.ts +0 -0
  410. /package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.d.ts +0 -0
@@ -0,0 +1,692 @@
1
+ /**
2
+ * Canonical resolver for the Vite dev-server origin that a NativeScript
3
+ * device or simulator can actually reach.
4
+ *
5
+ * Why this exists. The Vite dev server commonly binds to `0.0.0.0`
6
+ * (the wildcard "all interfaces" address) so both the host browser and
7
+ * a sibling mobile device can hit it. That bind address is fine for
8
+ * the LISTENING socket — but it is NOT a routable hostname:
9
+ *
10
+ * - iOS Simulator shares the host's network stack, so `localhost` /
11
+ * `127.0.0.1` work from inside the simulator and even `0.0.0.0`
12
+ * sometimes resolves there. The simulator path is forgiving.
13
+ *
14
+ * - Physical iOS / visionOS devices are NOT forgiving: `localhost`
15
+ * on the phone is the phone itself, and there is no iOS analog of
16
+ * `adb reverse` (usbmuxd's `iproxy` forwards host→device only, the
17
+ * wrong direction for a device-side fetch). The first HTTP ESM
18
+ * import in `bundle.mjs` dies with
19
+ * `HTTP import failed: http://localhost:5173/ns/core/xhr (status=0)`
20
+ * before any user code runs. The standard route is the host's LAN IP over
21
+ * a shared network. Because the Simulator shares the host's
22
+ * network stack, it reaches that LAN IP exactly as well as
23
+ * loopback — so iOS/visionOS dev URLs simply USE the LAN IP
24
+ * whenever a LAN NIC is up. One deterministic origin, both
25
+ * targets, no device detection. (We deliberately do NOT probe for
26
+ * attached hardware: `xcrun devicectl` state flaps between
27
+ * `connected` and `available (paired)` for an idle USB/Wi-Fi
28
+ * phone, so any probe-based answer is a coin toss.) `localhost`
29
+ * remains the fallback when no NIC is found, and
30
+ * `NS_HMR_PREFER_LAN_HOST=0` forces loopback for firewalled Macs
31
+ * that block LAN inbound.
32
+ *
33
+ * - Android Emulator runs inside a virtual NIC with NAT (QEMU
34
+ * `slirp`). `0.0.0.0` and `localhost` / `127.0.0.1` refer to the
35
+ * EMULATOR ITSELF, not the development host. Two routable paths
36
+ * exist:
37
+ *
38
+ * (a) `adb reverse tcp:<port> tcp:<port>` — multiplexes the
39
+ * device-side `127.0.0.1:<port>` over the existing ADB
40
+ * transport to the host. This is the PREFERRED path: slirp
41
+ * is famously flaky under burst-connect load and drops
42
+ * ~80% of cold-boot module-loader fetches with
43
+ * `IOException: unexpected end of stream`. The ADB tunnel
44
+ * bypasses slirp entirely and is reliable. We try this
45
+ * automatically — see `tryEnableAdbReverse`. We emit the
46
+ * IPv4 literal `127.0.0.1` instead of `localhost` because
47
+ * Android API 36+ system images periodically ship without
48
+ * a `localhost` mapping in the resolver, and
49
+ * `UnknownHostException` fires before adb-reverse can do
50
+ * its job.
51
+ *
52
+ * (b) `10.0.2.2` (Genymotion: `10.0.3.2`) — slirp's host alias.
53
+ * Used as a fallback when ADB isn't available or the user
54
+ * opted out via `NS_HMR_NO_ADB_REVERSE=1`. Works, just less
55
+ * reliable than the ADB tunnel.
56
+ *
57
+ * - Physical Android devices over USB get the same automatic
58
+ * `adb reverse` treatment as emulators. Over Wi-Fi (no ADB
59
+ * tunnel), the user must opt out of adb reverse via
60
+ * `NS_HMR_NO_ADB_REVERSE=1` and supply a routable host via
61
+ * `NS_HMR_HOST=<ip>` or `NS_HMR_PREFER_LAN_HOST=1`.
62
+ *
63
+ * Without this normalization, `bundle.mjs` ships with statically
64
+ * embedded URLs like `http://0.0.0.0:5173/ns/core/xhr` and the very
65
+ * first dynamic import during Application boot fails with
66
+ * `status=0 (network unreachable)` on Android, killing the runtime
67
+ * before any user code runs.
68
+ *
69
+ * Resolution rules (highest precedence first):
70
+ *
71
+ * 1. `process.env.NS_HMR_HOST` — always wins. CI, tunneled setups,
72
+ * and remote devices use this to point at a known-good origin.
73
+ *
74
+ * 2. A concrete non-wildcard, non-loopback `host` arg — trust the
75
+ * developer's explicit choice (`server.host: '192.168.1.42'`
76
+ * already routes from any device on the LAN).
77
+ *
78
+ * 3. `process.env.NS_HMR_PREFER_LAN_HOST` truthy AND a LAN NIC is
79
+ * detected — emit the LAN IP. Opt-in for physical-device-over-
80
+ * Wi-Fi dev. Also disables the adb-reverse path below so the
81
+ * caller actually gets LAN routing.
82
+ *
83
+ * 4. Wildcard bind (`0.0.0.0`, `::`, `true`, empty) OR Android
84
+ * loopback — emit the platform-appropriate routable address.
85
+ * For Android, we first try `adb reverse tcp:<port> tcp:<port>`
86
+ * and emit `127.0.0.1` on success (bypasses slirp NAT entirely
87
+ * and avoids Android API 36+'s missing-`localhost`-from-resolver
88
+ * bug); on failure we fall back to `10.0.2.2`. iOS/visionOS emit
89
+ * the host's LAN IP when a LAN NIC is up (reachable from both
90
+ * physical devices and the Simulator), otherwise `localhost`.
91
+ * `NS_HMR_PREFER_LAN_HOST=0` forces `localhost`. iOS/visionOS
92
+ * loopback passes through unchanged.
93
+ *
94
+ * Every dev-mode emitter that bakes a URL into `bundle.mjs` or sends
95
+ * one to a device-side fetch site MUST run through this helper so the
96
+ * device receives a single canonical, reachable origin.
97
+ */
98
+ import os from 'node:os';
99
+ import path from 'node:path';
100
+ import fs from 'node:fs';
101
+ import { execFileSync } from 'node:child_process';
102
+ const WILDCARD_HOSTS = new Set(['0.0.0.0', '::', '', 'true']);
103
+ const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '::1']);
104
+ const adbReverseCache = new Map();
105
+ /**
106
+ * Returns the first non-internal IPv4 address on the host machine, or
107
+ * `undefined` if no LAN NIC is up. Pure wrapper around
108
+ * `os.networkInterfaces()` so callers and tests can stub it cleanly.
109
+ */
110
+ export function guessLanHost() {
111
+ try {
112
+ const nets = os.networkInterfaces();
113
+ for (const name of Object.keys(nets)) {
114
+ const addrs = nets[name] || [];
115
+ for (const addr of addrs) {
116
+ if (!addr)
117
+ continue;
118
+ // Node typings vary across versions; keep checks defensive.
119
+ const family = addr.family;
120
+ const internal = !!addr.internal;
121
+ const address = String(addr.address || '');
122
+ if (internal)
123
+ continue;
124
+ if (family !== 'IPv4' && family !== 4)
125
+ continue;
126
+ // Skip link-local (APIPA) addresses — macOS surfaces
127
+ // 169.254.x.x on AWDL / idle USB NICs and they don't
128
+ // route reliably across devices.
129
+ if (address.startsWith('169.254.'))
130
+ continue;
131
+ if (address && address !== '127.0.0.1')
132
+ return address;
133
+ }
134
+ }
135
+ }
136
+ catch { }
137
+ return undefined;
138
+ }
139
+ function normalizeHostInput(host) {
140
+ if (host === true)
141
+ return '0.0.0.0';
142
+ if (host === false || host == null)
143
+ return '';
144
+ const s = String(host).trim();
145
+ return s;
146
+ }
147
+ /**
148
+ * Whether the given host string is a wildcard "all interfaces" bind
149
+ * address rather than a routable hostname. `host` may be the literal
150
+ * string from a Vite config (`'0.0.0.0'`), an empty string, or `'true'`
151
+ * (some older Vite/CLI surfaces stringify the boolean).
152
+ */
153
+ export function isWildcardHost(host) {
154
+ return WILDCARD_HOSTS.has(host);
155
+ }
156
+ /**
157
+ * Whether the given host string is loopback. On Android the loopback
158
+ * address is the device itself, NOT the development host — so callers
159
+ * must remap it for Android consumers.
160
+ */
161
+ export function isLoopbackHost(host) {
162
+ return LOOPBACK_HOSTS.has(host);
163
+ }
164
+ function isTruthyEnvFlag(value) {
165
+ if (typeof value !== 'string')
166
+ return false;
167
+ const v = value.trim().toLowerCase();
168
+ if (!v)
169
+ return false;
170
+ return v !== '0' && v !== 'false' && v !== 'off' && v !== 'no';
171
+ }
172
+ /**
173
+ * Resolve the `adb` executable the way the Android SDK tooling does,
174
+ * so the plugin and the NativeScript CLI drive the *same* adb client.
175
+ *
176
+ * Why this is load-bearing. A bare `adb` from `$PATH` is frequently a
177
+ * DIFFERENT version than the one the CLI resolves from the SDK. When
178
+ * two adb *clients* of differing versions talk to the one global adb
179
+ * server (port 5037), the newer client prints
180
+ * `adb server version (NN) doesn't match this client (MM); killing...`
181
+ * and restarts the daemon — severing the CLI's `track-devices` stream
182
+ * and hanging it at "Searching for devices…" forever. Resolving the
183
+ * exact SDK adb eliminates that mismatch.
184
+ *
185
+ * Precedence:
186
+ * 1. `NS_ADB_PATH` — the CLI exports the absolute path to the adb it
187
+ * itself uses. Always wins so the two processes are byte-identical.
188
+ * 2. `$ANDROID_HOME/platform-tools/adb` (+ `.exe` on Windows).
189
+ * 3. `$ANDROID_SDK_ROOT/platform-tools/adb`.
190
+ * 4. Bare `adb` — last-resort PATH lookup (kept only so a machine
191
+ * with adb on PATH but no SDK env still limps along).
192
+ *
193
+ * Candidates from (2)/(3) are existence-checked; a stale env var that
194
+ * points at a missing binary falls through rather than guaranteeing a
195
+ * spawn failure.
196
+ */
197
+ export function resolveAdbPath(env = process.env) {
198
+ const explicit = (env.NS_ADB_PATH || '').trim();
199
+ if (explicit)
200
+ return explicit;
201
+ const exe = process.platform === 'win32' ? 'adb.exe' : 'adb';
202
+ for (const root of [env.ANDROID_HOME, env.ANDROID_SDK_ROOT]) {
203
+ const r = (root || '').trim();
204
+ if (!r)
205
+ continue;
206
+ const candidate = path.join(r, 'platform-tools', exe);
207
+ try {
208
+ if (fs.existsSync(candidate))
209
+ return candidate;
210
+ }
211
+ catch {
212
+ // fs probe failed (perms, race) — fall through to the next root.
213
+ }
214
+ }
215
+ return exe;
216
+ }
217
+ /**
218
+ * Read-only view of the current `adb reverse` status for a given
219
+ * dev-server port. Returns `undefined` if `tryEnableAdbReverse` has
220
+ * never been called for that port.
221
+ */
222
+ export function getAdbReverseStatus(port) {
223
+ return adbReverseCache.get(port);
224
+ }
225
+ /**
226
+ * Test hook — clears the per-port cache so unit tests can exercise
227
+ * fresh "first call" behavior without leaking state between cases.
228
+ * NOT exported from the package barrel; spec files import via the
229
+ * file path directly.
230
+ */
231
+ export function __resetAdbReverseCacheForTests() {
232
+ adbReverseCache.clear();
233
+ }
234
+ /**
235
+ * Try to set up `adb reverse tcp:<port> tcp:<port>` for every
236
+ * connected Android device / emulator so device-side `localhost:port`
237
+ * routes through the ADB transport to the host's dev server.
238
+ *
239
+ * Why this beats `10.0.2.2`. The Android emulator's stock NAT is
240
+ * QEMU's `slirp` user-mode network stack, which is well-known to
241
+ * drop bursts of concurrent TCP setups to the host. In practice this
242
+ * surfaces as ~80% of synchronous module-loader fetches failing with
243
+ * `IOException: unexpected end of stream` — the connection establishes,
244
+ * the request goes out, and then slirp drops the response before
245
+ * okhttp can read the status line. The failures are random per-module
246
+ * across runs, retries help but don't eliminate them, and the symptom
247
+ * masquerades as a server-side bug.
248
+ *
249
+ * `adb reverse` bypasses the emulator NIC entirely — the device-side
250
+ * connection is multiplexed over the existing ADB USB / TCP channel
251
+ * to the host.
252
+ *
253
+ * Caching. The result is cached per-port so repeat callers don't
254
+ * fork extra subprocesses. The cache is keyed on port (not platform)
255
+ * because the wildcard "Android-ness" of the call is already implied
256
+ * by the caller — only Android consumers hit this path.
257
+ *
258
+ * CLI handoff (the preferred path). When the NativeScript CLI drives
259
+ * the run it already owns device discovery, install, and launch — it
260
+ * knows the exact target serial and exactly when the device is ready.
261
+ * In that mode the CLI performs the `adb reverse` itself, with its own
262
+ * SDK-resolved adb, AFTER the device is up, and exports
263
+ * `NS_ADB_REVERSE_READY=1`. Seeing that flag, this function returns a
264
+ * synthetic success WITHOUT spawning adb at all — removing the second,
265
+ * racing adb owner that used to collide with the CLI's device search
266
+ * during cold start. `NS_DEVICE_SERIAL` (the CLI's deploy target) and
267
+ * `NS_ADB_PATH` (the CLI's adb) are honored in the self-managed
268
+ * fallback below for setups where the CLI did NOT pre-wire the reverse.
269
+ *
270
+ * Self-managed hardening (fallback). When `NS_ADB_REVERSE_READY` is
271
+ * absent we still set the mapping ourselves, but defensively:
272
+ * - resolve adb from the SDK (`resolveAdbPath`) — never a bare PATH
273
+ * `adb` that could version-mismatch and kill the CLI's daemon;
274
+ * - `adb start-server` once up front so a cold daemon is owned by a
275
+ * single, version-matched client before anything else touches it;
276
+ * - argv `execFileSync` (no shell) with a child-killing timeout so a
277
+ * hung adb is reaped rather than orphaned;
278
+ * - `wait-for-device` per serial so we don't issue `reverse` against
279
+ * an emulator whose `adbd` hasn't finished coming up.
280
+ *
281
+ * Failure modes (all surface as a cached `succeeded: false`):
282
+ * - `NS_HMR_NO_ADB_REVERSE=1` — explicit opt-out for unusual
283
+ * setups (e.g. Wi-Fi-connected device with no ADB tunnel, CI
284
+ * containers without ADB installed).
285
+ * - `adb` not resolvable / not runnable.
286
+ * - No connected devices — user started Vite before booting the
287
+ * emulator. We do NOT keep retrying after the first failure
288
+ * because the URL is baked into bundle.mjs at config-load time
289
+ * and there's no point in flipping it later.
290
+ * - "more than one device" — fatal for unqualified `adb reverse`,
291
+ * so we target each serial individually with `-s <serial>`. As
292
+ * long as at least one device gets the mapping we treat the whole
293
+ * call as a success.
294
+ */
295
+ export function tryEnableAdbReverse(opts) {
296
+ const cached = adbReverseCache.get(opts.port);
297
+ if (cached)
298
+ return cached;
299
+ const env = opts.env || process.env;
300
+ // Explicit opt-out wins over everything — the user wants the
301
+ // `10.0.2.2` / LAN path, so don't claim a tunnel exists even if the
302
+ // CLI thinks it wired one.
303
+ if (isTruthyEnvFlag(env.NS_HMR_NO_ADB_REVERSE)) {
304
+ const status = { attempted: false, succeeded: false, devices: [], error: 'opt-out via NS_HMR_NO_ADB_REVERSE' };
305
+ adbReverseCache.set(opts.port, status);
306
+ return status;
307
+ }
308
+ // CLI handoff. The CLI already established the reverse with its own
309
+ // adb after the device was ready; we trust it and never spawn adb.
310
+ // This is what removes the cold-start race entirely.
311
+ if (isTruthyEnvFlag(env.NS_ADB_REVERSE_READY)) {
312
+ const serial = (env.NS_DEVICE_SERIAL || '').trim();
313
+ const status = {
314
+ attempted: false,
315
+ succeeded: true,
316
+ devices: serial ? [serial] : [],
317
+ viaCli: true,
318
+ };
319
+ adbReverseCache.set(opts.port, status);
320
+ try {
321
+ console.log(`[NativeScript] adb reverse for tcp:${opts.port} provided by the NativeScript CLI${serial ? ` (device ${serial})` : ''} — device-side 127.0.0.1:${opts.port} tunnels to host.`);
322
+ }
323
+ catch { }
324
+ return status;
325
+ }
326
+ // Test-safety guard. When we're running inside vitest / jest /
327
+ // any other test runner AND the caller did NOT inject an explicit
328
+ // exec stub, refuse to spawn a real `adb` subprocess. Spec files
329
+ // that pass `env: {}` aren't expecting us to mutate the dev's real
330
+ // device state (set up an actual `adb reverse` mapping on
331
+ // `port:5173` they didn't ask for) just by exercising the host
332
+ // resolver. We DO NOT cache this skip — a subsequent call with a
333
+ // real `exec` stub from the same suite should still run.
334
+ const ambient = process.env;
335
+ const inTestRunner = ambient.VITEST === 'true' || ambient.NODE_ENV === 'test' || typeof ambient.JEST_WORKER_ID === 'string';
336
+ if (!opts.exec && inTestRunner) {
337
+ return { attempted: false, succeeded: false, devices: [], error: 'test environment (auto-skip)' };
338
+ }
339
+ const adbPath = resolveAdbPath(env);
340
+ const exec = opts.exec ||
341
+ ((bin, args, o) => execFileSync(bin, args, {
342
+ timeout: o.timeout,
343
+ // No `/bin/sh` wrapper: on timeout the signal lands on the
344
+ // real adb child, not a shell that would orphan it.
345
+ killSignal: 'SIGKILL',
346
+ stdio: ['ignore', 'pipe', 'pipe'],
347
+ encoding: 'utf8',
348
+ }));
349
+ // Ensure a single, version-matched adb daemon is up and owned by
350
+ // THIS client before any other command. Best-effort: if it throws,
351
+ // the `adb devices` call below reports the real failure.
352
+ try {
353
+ exec(adbPath, ['start-server'], { timeout: 10000 });
354
+ }
355
+ catch {
356
+ // start-server failures are reported via the enumerate step.
357
+ }
358
+ // Determine target serials. When the CLI handed us the deploy
359
+ // target (`NS_DEVICE_SERIAL`) we scope to exactly that serial and
360
+ // skip enumeration — no `adb devices`, no multi-device ambiguity.
361
+ // Otherwise enumerate so we (a) bail cleanly when there's no device
362
+ // and (b) target each connected device individually.
363
+ let devices = [];
364
+ const targetSerial = (env.NS_DEVICE_SERIAL || '').trim();
365
+ if (targetSerial) {
366
+ devices = [targetSerial];
367
+ }
368
+ else {
369
+ try {
370
+ const raw = exec(adbPath, ['devices'], { timeout: 5000 });
371
+ devices = parseAdbDevicesOutput(raw);
372
+ }
373
+ catch (err) {
374
+ const status = {
375
+ attempted: true,
376
+ succeeded: false,
377
+ devices: [],
378
+ error: `adb not available: ${String(err?.message || err)}`,
379
+ };
380
+ adbReverseCache.set(opts.port, status);
381
+ return status;
382
+ }
383
+ if (devices.length === 0) {
384
+ const status = {
385
+ attempted: true,
386
+ succeeded: false,
387
+ devices: [],
388
+ error: 'no connected Android devices',
389
+ };
390
+ adbReverseCache.set(opts.port, status);
391
+ try {
392
+ console.warn(`[NativeScript] adb reverse skipped — no Android devices connected yet. Bundle URLs will use 10.0.2.2 (emulator NAT). For best reliability boot the emulator BEFORE \`ns run android\` so adb reverse can wire 127.0.0.1:${opts.port} through ADB instead.`);
393
+ }
394
+ catch { }
395
+ return status;
396
+ }
397
+ }
398
+ // Apply per-device so multi-device setups don't hit the "more
399
+ // than one device" failure. We tolerate per-device failures so
400
+ // long as at least one mapping landed — the user's target device
401
+ // is almost always the first connected one.
402
+ const successes = [];
403
+ const errors = [];
404
+ for (const serial of devices) {
405
+ try {
406
+ // Don't `reverse` against a device whose adbd isn't accepting
407
+ // yet (emulators report `device` state before `adbd` is ready).
408
+ // `wait-for-device` blocks only until the transport is up, then
409
+ // returns immediately on an already-ready device.
410
+ try {
411
+ exec(adbPath, ['-s', serial, 'wait-for-device'], { timeout: 10000 });
412
+ }
413
+ catch {
414
+ // Non-fatal: fall through and let `reverse` surface the real
415
+ // error if the device truly isn't reachable.
416
+ }
417
+ exec(adbPath, ['-s', serial, 'reverse', `tcp:${opts.port}`, `tcp:${opts.port}`], { timeout: 5000 });
418
+ successes.push(serial);
419
+ }
420
+ catch (err) {
421
+ errors.push(`${serial}: ${String(err?.message || err)}`);
422
+ }
423
+ }
424
+ const status = {
425
+ attempted: true,
426
+ succeeded: successes.length > 0,
427
+ devices: successes,
428
+ error: successes.length === 0 ? errors.join('; ') || 'all devices failed' : undefined,
429
+ };
430
+ adbReverseCache.set(opts.port, status);
431
+ // One-line user-facing receipt so the dev knows why bundle.mjs
432
+ // suddenly switched from `10.0.2.2` to `127.0.0.1`. We only log
433
+ // outside test runners (covered above) so spec output stays clean.
434
+ try {
435
+ if (status.succeeded) {
436
+ console.log(`[NativeScript] adb reverse tcp:${opts.port} tcp:${opts.port} → ${successes.join(', ')} (Android device-side 127.0.0.1:${opts.port} now tunnels to host — bypasses emulator NAT)`);
437
+ }
438
+ else if (errors.length > 0) {
439
+ console.warn(`[NativeScript] adb reverse failed for tcp:${opts.port} — falling back to 10.0.2.2 (slirp NAT). Module fetches may hit IOException: unexpected end of stream under load. Reasons: ${status.error}`);
440
+ }
441
+ }
442
+ catch {
443
+ // Logging is best-effort. We never want a console misbehavior
444
+ // to take down dev-server boot.
445
+ }
446
+ return status;
447
+ }
448
+ /**
449
+ * Parse the line-oriented output of `adb devices`:
450
+ *
451
+ * List of devices attached
452
+ * emulator-5554\tdevice
453
+ * ABCDEF12\tdevice
454
+ * somemodel\tunauthorized
455
+ *
456
+ * We keep only entries whose second column is exactly `device`
457
+ * (skip `unauthorized`, `offline`, `recovery`, etc. — none of those
458
+ * can accept an `adb reverse` command).
459
+ */
460
+ function parseAdbDevicesOutput(raw) {
461
+ const out = [];
462
+ const lines = String(raw || '').split(/\r?\n/);
463
+ for (const line of lines) {
464
+ const trimmed = line.trim();
465
+ if (!trimmed)
466
+ continue;
467
+ if (trimmed.startsWith('List of devices'))
468
+ continue;
469
+ if (trimmed.startsWith('*'))
470
+ continue; // daemon startup chatter
471
+ const parts = trimmed.split(/\s+/);
472
+ if (parts.length < 2)
473
+ continue;
474
+ if (parts[1] !== 'device')
475
+ continue;
476
+ out.push(parts[0]);
477
+ }
478
+ return out;
479
+ }
480
+ /**
481
+ * Pick the host string a device or simulator can actually reach.
482
+ *
483
+ * See the file-level comment for the full resolution-precedence
484
+ * narrative. Returns the chosen host alongside a `source` tag so
485
+ * callers (and logs) can explain why a given URL was emitted.
486
+ */
487
+ export function resolveDeviceReachableHost(opts) {
488
+ const env = opts.env || process.env;
489
+ const lanHostResolver = opts.lanHostResolver || guessLanHost;
490
+ // 1. Explicit env override always wins.
491
+ const envOverride = env.NS_HMR_HOST;
492
+ if (typeof envOverride === 'string' && envOverride.length > 0) {
493
+ return { host: envOverride, source: 'env' };
494
+ }
495
+ const raw = normalizeHostInput(opts.host);
496
+ // 2. Explicit non-wildcard, non-loopback host — trust the developer.
497
+ // Loopback addresses on Android still need remapping (see step 4),
498
+ // so we only short-circuit here for the truly routable case.
499
+ if (raw && !isWildcardHost(raw) && !isLoopbackHost(raw)) {
500
+ return { host: raw, source: 'explicit' };
501
+ }
502
+ // 3. Physical-device opt-in. The Android emulator default below
503
+ // (`10.0.2.2`) doesn't reach a real device on the LAN, so users
504
+ // running on hardware set `NS_HMR_PREFER_LAN_HOST=1` to pick up
505
+ // the host's LAN IP at build time. iOS/visionOS rarely needs
506
+ // this (the simulator stays on the loopback path) but the same
507
+ // opt-in works on those platforms for parity.
508
+ //
509
+ // `NS_HMR_PREFER_LAN_HOST` ALSO suppresses the adb-reverse path
510
+ // below — when the user has explicitly asked for LAN routing
511
+ // we don't want to silently bypass them with an ADB tunnel.
512
+ if (isTruthyEnvFlag(env.NS_HMR_PREFER_LAN_HOST)) {
513
+ const lan = lanHostResolver();
514
+ if (lan) {
515
+ return { host: lan, source: 'lan' };
516
+ }
517
+ // Fall through to the platform default when no LAN NIC was
518
+ // detected (e.g. running in a CI container) — better to fail
519
+ // at the always-works fallback than emit nothing.
520
+ }
521
+ // 4. Wildcard bind — fall back to the platform-appropriate routable
522
+ // address. We DELIBERATELY do NOT auto-pick a LAN IP here on
523
+ // Android: standard emulator NAT drops packets destined for the
524
+ // host's LAN IP, even when those IPs resolve fine from the
525
+ // host's own browser. `10.0.2.2` is the next-best fallback when
526
+ // adb reverse isn't available; otherwise the emulator slirp NAT
527
+ // drops a meaningful fraction of TCP setups under burst load and
528
+ // cold-boot hits `IOException: unexpected end of stream` for
529
+ // random modules each run.
530
+ if (isWildcardHost(raw)) {
531
+ return platformDefault(opts);
532
+ }
533
+ // 5. Loopback. iOS / visionOS keeps `localhost` (simulator network
534
+ // stack reaches the host); Android remaps to `10.0.2.2` /
535
+ // `localhost`-via-adb-reverse (loopback on Android refers to
536
+ // the EMULATOR ITSELF, not the host).
537
+ if (isLoopbackHost(raw)) {
538
+ if (opts.platform === 'android') {
539
+ return platformDefault(opts);
540
+ }
541
+ return { host: raw, source: 'explicit' };
542
+ }
543
+ // 6. Empty / unrecognised — fall back to platform default.
544
+ return platformDefault(opts);
545
+ }
546
+ function platformDefault(opts) {
547
+ if (opts.platform === 'android') {
548
+ // Try to bring up an `adb reverse` tunnel first. When that
549
+ // succeeds, `localhost` on the device routes through the
550
+ // existing ADB channel to the host's dev server — which
551
+ // sidesteps the QEMU slirp NAT entirely (see
552
+ // `tryEnableAdbReverse` for why that matters). When adb is
553
+ // unavailable, the device is disconnected, or the user opted
554
+ // out via `NS_HMR_NO_ADB_REVERSE`, we fall through to
555
+ // `10.0.2.2` so the cold boot still has *some* working path.
556
+ //
557
+ // We only attempt adb reverse when we know the port — without
558
+ // it we can't issue a valid `adb reverse` command. Older
559
+ // fixtures that call `resolveDeviceReachableHost` without a
560
+ // port still get the legacy `10.0.2.2` answer.
561
+ if (typeof opts.port === 'number' && Number.isFinite(opts.port)) {
562
+ const status = tryEnableAdbReverse({ port: opts.port, env: opts.env, exec: opts.adbExec });
563
+ if (status.succeeded) {
564
+ // Emit `127.0.0.1` (IPv4 literal) instead of `localhost`.
565
+ // Android API 36+ system images periodically ship without
566
+ // a `localhost` entry in the resolver's `/etc/hosts`, so
567
+ // `getaddrinfo("localhost")` throws
568
+ // `UnknownHostException: No address associated with
569
+ // hostname` BEFORE the TCP connect even starts. The IPv4
570
+ // literal bypasses DNS entirely and ADB reverse intercepts
571
+ // loopback traffic regardless of how it's spelled.
572
+ return { host: '127.0.0.1', source: 'adb-reverse' };
573
+ }
574
+ }
575
+ // Stock Android emulator host alias. Physical devices that
576
+ // can't use `adb reverse` need NS_HMR_HOST=<LAN IP> or
577
+ // NS_HMR_PREFER_LAN_HOST=1.
578
+ return { host: '10.0.2.2', source: 'platform-default' };
579
+ }
580
+ // iOS / visionOS. `localhost` only works from simulators (they share
581
+ // the host's network stack); on physical hardware it points at the
582
+ // device itself and the very first HTTP ESM import in bundle.mjs dies
583
+ // with `status=0` before any user code runs — and iOS has no
584
+ // device→host port forward to tunnel around that. The Simulator
585
+ // reaches the host's LAN IP exactly as well as loopback, so the LAN
586
+ // IP is the one origin that serves BOTH targets: emit it whenever a
587
+ // LAN NIC is up, no device detection involved. `localhost` remains
588
+ // the no-NIC (offline) fallback; `NS_HMR_PREFER_LAN_HOST=0` forces
589
+ // loopback for Macs whose firewall blocks LAN inbound.
590
+ if (!isExplicitlyFalsyEnvFlag((opts.env || process.env).NS_HMR_PREFER_LAN_HOST)) {
591
+ // Ambient-machine guard, same shape as the adb test-skip above:
592
+ // inside a test runner with no injected `lanHostResolver`, don't
593
+ // read real NICs — specs would become machine-dependent.
594
+ const ambient = process.env;
595
+ const inTestRunner = ambient.VITEST === 'true' || ambient.NODE_ENV === 'test' || typeof ambient.JEST_WORKER_ID === 'string';
596
+ if (opts.lanHostResolver || !inTestRunner) {
597
+ const lan = (opts.lanHostResolver || guessLanHost)();
598
+ if (lan) {
599
+ logAppleLanReceiptOnce(lan);
600
+ return { host: lan, source: 'lan' };
601
+ }
602
+ }
603
+ }
604
+ return { host: 'localhost', source: 'platform-default' };
605
+ }
606
+ /**
607
+ * Whether the env flag is SET and spells "off". Distinct from
608
+ * `!isTruthyEnvFlag(...)` — an unset flag must not count as an explicit
609
+ * opt-out.
610
+ */
611
+ function isExplicitlyFalsyEnvFlag(value) {
612
+ if (typeof value !== 'string')
613
+ return false;
614
+ const v = value.trim().toLowerCase();
615
+ if (!v)
616
+ return false;
617
+ return v === '0' || v === 'false' || v === 'off' || v === 'no';
618
+ }
619
+ /**
620
+ * One-line receipt (once per process) so the dev knows why URLs say
621
+ * `192.168.x.x` instead of `localhost` and which knobs change it.
622
+ */
623
+ let appleLanReceiptLogged = false;
624
+ function logAppleLanReceiptOnce(lan) {
625
+ if (appleLanReceiptLogged)
626
+ return;
627
+ appleLanReceiptLogged = true;
628
+ try {
629
+ console.log(`[NativeScript] iOS dev-server URLs use this Mac's LAN address ${lan} so physical devices on the same network can reach Vite (simulators reach it too). Override with NS_HMR_HOST=<host>, or force localhost with NS_HMR_PREFER_LAN_HOST=0.`);
630
+ }
631
+ catch {
632
+ // Logging is best-effort, never boot-fatal.
633
+ }
634
+ }
635
+ /**
636
+ * Convenience wrapper that returns the full `protocol://host:port`
637
+ * origin string alongside the host-resolution metadata. The vast
638
+ * majority of callers want the assembled origin to splice into a
639
+ * `/ns/...` URL, so this saves them the trivial template string.
640
+ *
641
+ * When the resolved host already includes a `:port` suffix (a common
642
+ * shape for `NS_HMR_HOST=tunnel.example.com:5173`), we split it back
643
+ * out so the assembled origin never doubles up the port.
644
+ */
645
+ export function resolveDeviceReachableOrigin(opts) {
646
+ const protocol = opts.protocol === 'https' ? 'https' : 'http';
647
+ const requestedPort = typeof opts.port === 'number' && Number.isFinite(opts.port) ? opts.port : 5173;
648
+ // Forward the resolved port to the host resolver so the Android
649
+ // `platformDefault` step can attempt `adb reverse` for the same
650
+ // port the dev server is actually listening on.
651
+ const { host: rawHost, source } = resolveDeviceReachableHost({ ...opts, port: requestedPort });
652
+ const { host, port } = splitHostAndPort(rawHost, requestedPort);
653
+ return {
654
+ host,
655
+ source,
656
+ protocol,
657
+ port,
658
+ origin: `${protocol}://${host}:${port}`,
659
+ };
660
+ }
661
+ function splitHostAndPort(rawHost, fallbackPort) {
662
+ // Bracketed IPv6 — `[::1]:5173` — keep the brackets on the host so
663
+ // callers can splice it straight into a URL without re-escaping.
664
+ if (rawHost.startsWith('[')) {
665
+ const closing = rawHost.indexOf(']');
666
+ if (closing !== -1) {
667
+ const bracketed = rawHost.slice(0, closing + 1);
668
+ const rest = rawHost.slice(closing + 1);
669
+ if (rest.startsWith(':')) {
670
+ const parsed = Number(rest.slice(1));
671
+ if (Number.isFinite(parsed) && parsed > 0) {
672
+ return { host: bracketed, port: parsed };
673
+ }
674
+ }
675
+ return { host: bracketed, port: fallbackPort };
676
+ }
677
+ }
678
+ // `host:port` for IPv4 / DNS names. We deliberately do NOT split on
679
+ // the first colon when more than one is present (that would
680
+ // misinterpret an unbracketed IPv6 literal), and we leave the host
681
+ // alone if the trailing segment isn't a positive integer.
682
+ const colonCount = (rawHost.match(/:/g) || []).length;
683
+ if (colonCount === 1) {
684
+ const idx = rawHost.indexOf(':');
685
+ const candidatePort = Number(rawHost.slice(idx + 1));
686
+ if (Number.isFinite(candidatePort) && candidatePort > 0) {
687
+ return { host: rawHost.slice(0, idx), port: candidatePort };
688
+ }
689
+ }
690
+ return { host: rawHost, port: fallbackPort };
691
+ }
692
+ //# sourceMappingURL=dev-host.js.map