@nativescript/vite 8.0.0-alpha.2 → 8.0.0-alpha.21

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 (209) hide show
  1. package/configuration/angular.d.ts +34 -1
  2. package/configuration/angular.js +380 -34
  3. package/configuration/angular.js.map +1 -1
  4. package/configuration/base.js +171 -7
  5. package/configuration/base.js.map +1 -1
  6. package/configuration/solid.js +27 -1
  7. package/configuration/solid.js.map +1 -1
  8. package/configuration/typescript.js +1 -1
  9. package/configuration/typescript.js.map +1 -1
  10. package/helpers/angular/angular-linker.js +3 -12
  11. package/helpers/angular/angular-linker.js.map +1 -1
  12. package/helpers/angular/inject-component-hmr-registration.d.ts +112 -0
  13. package/helpers/angular/inject-component-hmr-registration.js +359 -0
  14. package/helpers/angular/inject-component-hmr-registration.js.map +1 -0
  15. package/helpers/angular/inject-hmr-vite-ignore.d.ts +75 -0
  16. package/helpers/angular/inject-hmr-vite-ignore.js +288 -0
  17. package/helpers/angular/inject-hmr-vite-ignore.js.map +1 -0
  18. package/helpers/angular/util.d.ts +1 -0
  19. package/helpers/angular/util.js +88 -0
  20. package/helpers/angular/util.js.map +1 -1
  21. package/helpers/commonjs-plugins.d.ts +5 -2
  22. package/helpers/commonjs-plugins.js +126 -0
  23. package/helpers/commonjs-plugins.js.map +1 -1
  24. package/helpers/config-as-json.js +10 -0
  25. package/helpers/config-as-json.js.map +1 -1
  26. package/helpers/dev-host.d.ts +274 -0
  27. package/helpers/dev-host.js +491 -0
  28. package/helpers/dev-host.js.map +1 -0
  29. package/helpers/global-defines.d.ts +51 -0
  30. package/helpers/global-defines.js +77 -0
  31. package/helpers/global-defines.js.map +1 -1
  32. package/helpers/logging.d.ts +1 -0
  33. package/helpers/logging.js +63 -3
  34. package/helpers/logging.js.map +1 -1
  35. package/helpers/main-entry.d.ts +3 -1
  36. package/helpers/main-entry.js +450 -125
  37. package/helpers/main-entry.js.map +1 -1
  38. package/helpers/nativeclass-transformer-plugin.d.ts +9 -2
  39. package/helpers/nativeclass-transformer-plugin.js +157 -14
  40. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  41. package/helpers/ns-core-url.d.ts +88 -0
  42. package/helpers/ns-core-url.js +191 -0
  43. package/helpers/ns-core-url.js.map +1 -0
  44. package/helpers/prelink-angular.js +1 -4
  45. package/helpers/prelink-angular.js.map +1 -1
  46. package/helpers/project.d.ts +35 -0
  47. package/helpers/project.js +120 -2
  48. package/helpers/project.js.map +1 -1
  49. package/helpers/resolver.js +9 -1
  50. package/helpers/resolver.js.map +1 -1
  51. package/helpers/solid-jsx-deps.d.ts +15 -0
  52. package/helpers/solid-jsx-deps.js +178 -0
  53. package/helpers/solid-jsx-deps.js.map +1 -0
  54. package/helpers/ts-config-paths.js +50 -2
  55. package/helpers/ts-config-paths.js.map +1 -1
  56. package/helpers/workers.d.ts +20 -19
  57. package/helpers/workers.js +620 -3
  58. package/helpers/workers.js.map +1 -1
  59. package/hmr/client/css-handler.d.ts +1 -0
  60. package/hmr/client/css-handler.js +34 -5
  61. package/hmr/client/css-handler.js.map +1 -1
  62. package/hmr/client/css-update-overlay.d.ts +18 -0
  63. package/hmr/client/css-update-overlay.js +27 -0
  64. package/hmr/client/css-update-overlay.js.map +1 -0
  65. package/hmr/client/hmr-pending-overlay.d.ts +27 -0
  66. package/hmr/client/hmr-pending-overlay.js +50 -0
  67. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  68. package/hmr/client/index.js +491 -34
  69. package/hmr/client/index.js.map +1 -1
  70. package/hmr/client/utils.d.ts +5 -0
  71. package/hmr/client/utils.js +283 -12
  72. package/hmr/client/utils.js.map +1 -1
  73. package/hmr/client/vue-sfc-update-overlay.d.ts +82 -0
  74. package/hmr/client/vue-sfc-update-overlay.js +133 -0
  75. package/hmr/client/vue-sfc-update-overlay.js.map +1 -0
  76. package/hmr/entry-runtime.d.ts +2 -1
  77. package/hmr/entry-runtime.js +253 -66
  78. package/hmr/entry-runtime.js.map +1 -1
  79. package/hmr/frameworks/angular/client/index.d.ts +3 -1
  80. package/hmr/frameworks/angular/client/index.js +802 -10
  81. package/hmr/frameworks/angular/client/index.js.map +1 -1
  82. package/hmr/frameworks/angular/server/linker.js +1 -4
  83. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  84. package/hmr/frameworks/angular/server/strategy.js +30 -6
  85. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  86. package/hmr/frameworks/typescript/server/strategy.js +8 -2
  87. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  88. package/hmr/frameworks/vue/client/index.js +30 -45
  89. package/hmr/frameworks/vue/client/index.js.map +1 -1
  90. package/hmr/helpers/ast-normalizer.js +52 -5
  91. package/hmr/helpers/ast-normalizer.js.map +1 -1
  92. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  93. package/hmr/helpers/cjs-named-exports.js +152 -0
  94. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  95. package/hmr/helpers/package-exports.d.ts +16 -0
  96. package/hmr/helpers/package-exports.js +396 -0
  97. package/hmr/helpers/package-exports.js.map +1 -0
  98. package/hmr/server/constants.js +13 -4
  99. package/hmr/server/constants.js.map +1 -1
  100. package/hmr/server/core-sanitize.d.ts +93 -8
  101. package/hmr/server/core-sanitize.js +222 -49
  102. package/hmr/server/core-sanitize.js.map +1 -1
  103. package/hmr/server/import-map.js +80 -22
  104. package/hmr/server/import-map.js.map +1 -1
  105. package/hmr/server/index.d.ts +2 -1
  106. package/hmr/server/index.js.map +1 -1
  107. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  108. package/hmr/server/ns-core-cjs-shape.js +271 -0
  109. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  110. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  111. package/hmr/server/ns-rt-bridge.js +131 -0
  112. package/hmr/server/ns-rt-bridge.js.map +1 -0
  113. package/hmr/server/perf-instrumentation.d.ts +114 -0
  114. package/hmr/server/perf-instrumentation.js +195 -0
  115. package/hmr/server/perf-instrumentation.js.map +1 -0
  116. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  117. package/hmr/server/runtime-graph-filter.js +21 -0
  118. package/hmr/server/runtime-graph-filter.js.map +1 -0
  119. package/hmr/server/shared-transform-request.d.ts +12 -0
  120. package/hmr/server/shared-transform-request.js +144 -0
  121. package/hmr/server/shared-transform-request.js.map +1 -0
  122. package/hmr/server/vite-plugin.d.ts +21 -1
  123. package/hmr/server/vite-plugin.js +497 -58
  124. package/hmr/server/vite-plugin.js.map +1 -1
  125. package/hmr/server/websocket-angular-entry.d.ts +2 -0
  126. package/hmr/server/websocket-angular-entry.js +68 -0
  127. package/hmr/server/websocket-angular-entry.js.map +1 -0
  128. package/hmr/server/websocket-angular-hot-update.d.ts +78 -0
  129. package/hmr/server/websocket-angular-hot-update.js +413 -0
  130. package/hmr/server/websocket-angular-hot-update.js.map +1 -0
  131. package/hmr/server/websocket-core-bridge.d.ts +58 -0
  132. package/hmr/server/websocket-core-bridge.js +368 -0
  133. package/hmr/server/websocket-core-bridge.js.map +1 -0
  134. package/hmr/server/websocket-css-hot-update.d.ts +33 -0
  135. package/hmr/server/websocket-css-hot-update.js +65 -0
  136. package/hmr/server/websocket-css-hot-update.js.map +1 -0
  137. package/hmr/server/websocket-graph-upsert.d.ts +21 -0
  138. package/hmr/server/websocket-graph-upsert.js +33 -0
  139. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  140. package/hmr/server/websocket-hmr-pending.d.ts +43 -0
  141. package/hmr/server/websocket-hmr-pending.js +55 -0
  142. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  143. package/hmr/server/websocket-module-bindings.d.ts +6 -0
  144. package/hmr/server/websocket-module-bindings.js +471 -0
  145. package/hmr/server/websocket-module-bindings.js.map +1 -0
  146. package/hmr/server/websocket-module-specifiers.d.ts +101 -0
  147. package/hmr/server/websocket-module-specifiers.js +820 -0
  148. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  149. package/hmr/server/websocket-ns-m-finalize.d.ts +22 -0
  150. package/hmr/server/websocket-ns-m-finalize.js +88 -0
  151. package/hmr/server/websocket-ns-m-finalize.js.map +1 -0
  152. package/hmr/server/websocket-ns-m-paths.d.ts +3 -0
  153. package/hmr/server/websocket-ns-m-paths.js +92 -0
  154. package/hmr/server/websocket-ns-m-paths.js.map +1 -0
  155. package/hmr/server/websocket-ns-m-request.d.ts +45 -0
  156. package/hmr/server/websocket-ns-m-request.js +196 -0
  157. package/hmr/server/websocket-ns-m-request.js.map +1 -0
  158. package/hmr/server/websocket-served-module-helpers.d.ts +36 -0
  159. package/hmr/server/websocket-served-module-helpers.js +644 -0
  160. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  161. package/hmr/server/websocket-txn.d.ts +6 -0
  162. package/hmr/server/websocket-txn.js +45 -0
  163. package/hmr/server/websocket-txn.js.map +1 -0
  164. package/hmr/server/websocket-vendor-unifier.d.ts +10 -0
  165. package/hmr/server/websocket-vendor-unifier.js +51 -0
  166. package/hmr/server/websocket-vendor-unifier.js.map +1 -0
  167. package/hmr/server/websocket-vue-sfc.d.ts +26 -0
  168. package/hmr/server/websocket-vue-sfc.js +1053 -0
  169. package/hmr/server/websocket-vue-sfc.js.map +1 -0
  170. package/hmr/server/websocket.d.ts +58 -75
  171. package/hmr/server/websocket.js +2232 -1802
  172. package/hmr/server/websocket.js.map +1 -1
  173. package/hmr/shared/package-classifier.d.ts +9 -0
  174. package/hmr/shared/package-classifier.js +58 -0
  175. package/hmr/shared/package-classifier.js.map +1 -0
  176. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  177. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  178. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  179. package/hmr/shared/runtime/boot-progress.d.ts +40 -0
  180. package/hmr/shared/runtime/boot-progress.js +128 -0
  181. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  182. package/hmr/shared/runtime/boot-timeline.d.ts +18 -0
  183. package/hmr/shared/runtime/boot-timeline.js +52 -0
  184. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  185. package/hmr/shared/runtime/browser-runtime-contract.d.ts +64 -0
  186. package/hmr/shared/runtime/browser-runtime-contract.js +54 -0
  187. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  188. package/hmr/shared/runtime/dev-overlay.d.ts +78 -3
  189. package/hmr/shared/runtime/dev-overlay.js +1094 -26
  190. package/hmr/shared/runtime/dev-overlay.js.map +1 -1
  191. package/hmr/shared/runtime/module-provenance.js +1 -4
  192. package/hmr/shared/runtime/module-provenance.js.map +1 -1
  193. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  194. package/hmr/shared/runtime/root-placeholder.js +1019 -151
  195. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  196. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  197. package/hmr/shared/runtime/session-bootstrap.js +309 -0
  198. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  199. package/hmr/shared/runtime/vendor-bootstrap.js +1 -9
  200. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  201. package/hmr/shared/vendor/manifest.d.ts +32 -0
  202. package/hmr/shared/vendor/manifest.js +411 -46
  203. package/hmr/shared/vendor/manifest.js.map +1 -1
  204. package/index.d.ts +1 -0
  205. package/index.js +5 -0
  206. package/index.js.map +1 -1
  207. package/package.json +9 -1
  208. package/runtime/core-aliases-early.js +94 -67
  209. package/runtime/core-aliases-early.js.map +1 -1
@@ -0,0 +1,274 @@
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
+ * - Android Emulator runs inside a virtual NIC with NAT (QEMU
15
+ * `slirp`). `0.0.0.0` and `localhost` / `127.0.0.1` refer to the
16
+ * EMULATOR ITSELF, not the development host. Two routable paths
17
+ * exist:
18
+ *
19
+ * (a) `adb reverse tcp:<port> tcp:<port>` — multiplexes the
20
+ * device-side `127.0.0.1:<port>` over the existing ADB
21
+ * transport to the host. This is the PREFERRED path: slirp
22
+ * is famously flaky under burst-connect load and drops
23
+ * ~80% of cold-boot module-loader fetches with
24
+ * `IOException: unexpected end of stream`. The ADB tunnel
25
+ * bypasses slirp entirely and is reliable. We try this
26
+ * automatically — see `tryEnableAdbReverse`. We emit the
27
+ * IPv4 literal `127.0.0.1` instead of `localhost` because
28
+ * Android API 36+ system images periodically ship without
29
+ * a `localhost` mapping in the resolver, and
30
+ * `UnknownHostException` fires before adb-reverse can do
31
+ * its job.
32
+ *
33
+ * (b) `10.0.2.2` (Genymotion: `10.0.3.2`) — slirp's host alias.
34
+ * Used as a fallback when ADB isn't available or the user
35
+ * opted out via `NS_HMR_NO_ADB_REVERSE=1`. Works, just less
36
+ * reliable than the ADB tunnel.
37
+ *
38
+ * - Physical Android devices over USB get the same automatic
39
+ * `adb reverse` treatment as emulators. Over Wi-Fi (no ADB
40
+ * tunnel), the user must opt out of adb reverse via
41
+ * `NS_HMR_NO_ADB_REVERSE=1` and supply a routable host via
42
+ * `NS_HMR_HOST=<ip>` or `NS_HMR_PREFER_LAN_HOST=1`.
43
+ *
44
+ * Without this normalization, `bundle.mjs` ships with statically
45
+ * embedded URLs like `http://0.0.0.0:5173/ns/core/xhr` and the very
46
+ * first dynamic import during Application boot fails with
47
+ * `status=0 (network unreachable)` on Android, killing the runtime
48
+ * before any user code runs.
49
+ *
50
+ * Resolution rules (highest precedence first):
51
+ *
52
+ * 1. `process.env.NS_HMR_HOST` — always wins. CI, tunneled setups,
53
+ * and remote devices use this to point at a known-good origin.
54
+ *
55
+ * 2. A concrete non-wildcard, non-loopback `host` arg — trust the
56
+ * developer's explicit choice (`server.host: '192.168.1.42'`
57
+ * already routes from any device on the LAN).
58
+ *
59
+ * 3. `process.env.NS_HMR_PREFER_LAN_HOST` truthy AND a LAN NIC is
60
+ * detected — emit the LAN IP. Opt-in for physical-device-over-
61
+ * Wi-Fi dev. Also disables the adb-reverse path below so the
62
+ * caller actually gets LAN routing.
63
+ *
64
+ * 4. Wildcard bind (`0.0.0.0`, `::`, `true`, empty) OR Android
65
+ * loopback — emit the platform-appropriate routable address.
66
+ * For Android, we first try `adb reverse tcp:<port> tcp:<port>`
67
+ * and emit `127.0.0.1` on success (bypasses slirp NAT entirely
68
+ * and avoids Android API 36+'s missing-`localhost`-from-resolver
69
+ * bug); on failure we fall back to `10.0.2.2`. iOS/visionOS get
70
+ * `localhost` directly. iOS/visionOS loopback passes through
71
+ * unchanged.
72
+ *
73
+ * Every dev-mode emitter that bakes a URL into `bundle.mjs` or sends
74
+ * one to a device-side fetch site MUST run through this helper so the
75
+ * device receives a single canonical, reachable origin.
76
+ */
77
+ export type DevHostPlatform = 'android' | 'ios' | 'visionos';
78
+ /**
79
+ * Per-port cache of `adb reverse` setup attempts. Keyed by port so
80
+ * dev servers that switch ports across restarts get a clean attempt
81
+ * each time. The cache is required because every entry point that
82
+ * embeds a device-reachable URL (the bundle.mjs boot path, the
83
+ * `/ns/core/*` external resolver, the websocket URL emitter, the
84
+ * served-module rewriter) hits `resolveDeviceReachable*` — if we
85
+ * spawned `adb reverse` on every call we'd fork ~half a dozen
86
+ * subprocesses per Vite startup and the cold-boot would slow
87
+ * noticeably.
88
+ *
89
+ * The cache also gives us a stable answer across all consumers: once
90
+ * the first caller learns that adb reverse is available, every later
91
+ * caller in the same process gets the same `localhost`/`10.0.2.2`
92
+ * decision. URL identity is what keeps the iOS HTTP ESM realm from
93
+ * splitting and what keeps the Android HMR client and bundle.mjs
94
+ * pointing at the same origin.
95
+ */
96
+ interface AdbReverseStatus {
97
+ attempted: boolean;
98
+ succeeded: boolean;
99
+ error?: string;
100
+ /** Device serials that successfully received the reverse mapping. */
101
+ devices: string[];
102
+ }
103
+ /**
104
+ * Returns the first non-internal IPv4 address on the host machine, or
105
+ * `undefined` if no LAN NIC is up. Pure wrapper around
106
+ * `os.networkInterfaces()` so callers and tests can stub it cleanly.
107
+ */
108
+ export declare function guessLanHost(): string | undefined;
109
+ /**
110
+ * Whether the given host string is a wildcard "all interfaces" bind
111
+ * address rather than a routable hostname. `host` may be the literal
112
+ * string from a Vite config (`'0.0.0.0'`), an empty string, or `'true'`
113
+ * (some older Vite/CLI surfaces stringify the boolean).
114
+ */
115
+ export declare function isWildcardHost(host: string): boolean;
116
+ /**
117
+ * Whether the given host string is loopback. On Android the loopback
118
+ * address is the device itself, NOT the development host — so callers
119
+ * must remap it for Android consumers.
120
+ */
121
+ export declare function isLoopbackHost(host: string): boolean;
122
+ export interface DeviceHostResolution {
123
+ /** Final host string baked into the device-side URL. */
124
+ host: string;
125
+ /**
126
+ * How the value was chosen. `'env'` / `'explicit'` mean the result
127
+ * is locked-in; `'lan'`, `'adb-reverse'`, and `'platform-default'`
128
+ * are fallbacks selected by this helper.
129
+ */
130
+ source: 'env' | 'explicit' | 'lan' | 'adb-reverse' | 'platform-default';
131
+ }
132
+ export interface ResolveDeviceHostOptions {
133
+ /** The raw host value from the Vite config (`server.host`). */
134
+ host?: unknown;
135
+ /** Target device platform. Drives the loopback / wildcard fallback. */
136
+ platform: DevHostPlatform;
137
+ /**
138
+ * Override for `process.env`. Tests pass a fixture object; runtime
139
+ * callers omit this and pick up the ambient process environment.
140
+ */
141
+ env?: NodeJS.ProcessEnv;
142
+ /**
143
+ * Override for `guessLanHost()`. Tests stub a fixed return value;
144
+ * runtime callers omit this and the helper hits real NICs.
145
+ */
146
+ lanHostResolver?: () => string | undefined;
147
+ /**
148
+ * Dev-server port. When set AND `platform === 'android'`, this
149
+ * helper will lazily attempt `adb reverse tcp:<port> tcp:<port>`
150
+ * on first call and, if it succeeds, emit `localhost` instead of
151
+ * `10.0.2.2`. See `tryEnableAdbReverse` for the full rationale.
152
+ *
153
+ * Optional for backwards compatibility — callers that already have
154
+ * the port (which is everyone except a couple of legacy test
155
+ * fixtures) should pass it so Android emulator users get the
156
+ * reliable ADB tunnel path instead of QEMU slirp's flaky NAT.
157
+ */
158
+ port?: number;
159
+ /**
160
+ * Test seam for the adb-reverse subprocess. When passed, this
161
+ * helper uses the injected exec function instead of spawning
162
+ * `child_process.execSync`. Runtime callers omit this and pick
163
+ * up the real ADB binary on PATH.
164
+ */
165
+ adbExec?: AdbExec;
166
+ }
167
+ /**
168
+ * Subprocess shim used by `tryEnableAdbReverse`. Production code
169
+ * routes through `child_process.execSync`; tests stub it so the
170
+ * suite can exercise success / failure / "multiple devices" /
171
+ * "no ADB on PATH" paths without touching a real Android emulator.
172
+ *
173
+ * The signature deliberately matches the subset of `execSync` we
174
+ * need so we never have to plumb `ExecSyncOptionsWithBufferEncoding`
175
+ * through the call chain — a string-returning shim is enough here.
176
+ */
177
+ export type AdbExec = (cmd: string, opts: {
178
+ timeout: number;
179
+ }) => string;
180
+ export interface TryEnableAdbReverseOptions {
181
+ /** Port to forward on both sides of the ADB bridge. */
182
+ port: number;
183
+ /** Override for `process.env`; tests pass a fixture object. */
184
+ env?: NodeJS.ProcessEnv;
185
+ /** Test seam — see `AdbExec`. */
186
+ exec?: AdbExec;
187
+ }
188
+ /**
189
+ * Read-only view of the current `adb reverse` status for a given
190
+ * dev-server port. Returns `undefined` if `tryEnableAdbReverse` has
191
+ * never been called for that port.
192
+ */
193
+ export declare function getAdbReverseStatus(port: number): AdbReverseStatus | undefined;
194
+ /**
195
+ * Test hook — clears the per-port cache so unit tests can exercise
196
+ * fresh "first call" behavior without leaking state between cases.
197
+ * NOT exported from the package barrel; spec files import via the
198
+ * file path directly.
199
+ */
200
+ export declare function __resetAdbReverseCacheForTests(): void;
201
+ /**
202
+ * Try to set up `adb reverse tcp:<port> tcp:<port>` for every
203
+ * connected Android device / emulator so device-side `localhost:port`
204
+ * routes through the ADB transport to the host's dev server.
205
+ *
206
+ * Why this beats `10.0.2.2`. The Android emulator's stock NAT is
207
+ * QEMU's `slirp` user-mode network stack, which is well-known to
208
+ * drop bursts of concurrent TCP setups to the host. In practice this
209
+ * surfaces as ~80% of synchronous module-loader fetches failing with
210
+ * `IOException: unexpected end of stream` — the connection establishes,
211
+ * the request goes out, and then slirp drops the response before
212
+ * okhttp can read the status line. The failures are random per-module
213
+ * across runs, retries help but don't eliminate them, and the symptom
214
+ * masquerades as a server-side bug.
215
+ *
216
+ * `adb reverse` bypasses the emulator NIC entirely — the device-side
217
+ * connection is multiplexed over the existing ADB USB / TCP channel
218
+ * to the host. It's the same mechanism React Native, Expo, and
219
+ * Flutter use for Android dev, and it works for both emulators and
220
+ * USB-connected physical devices.
221
+ *
222
+ * Caching. The result is cached per-port so repeat callers don't
223
+ * fork extra subprocesses. The cache is keyed on port (not platform)
224
+ * because the wildcard "Android-ness" of the call is already implied
225
+ * by the caller — only Android consumers hit this path.
226
+ *
227
+ * Failure modes (all surface as a cached `succeeded: false`):
228
+ * - `NS_HMR_NO_ADB_REVERSE=1` — explicit opt-out for unusual
229
+ * setups (e.g. Wi-Fi-connected device with no ADB tunnel, CI
230
+ * containers without ADB installed).
231
+ * - `adb` not on PATH — common in fresh dev machines that have
232
+ * the Android SDK installed but no shell init.
233
+ * - No connected devices — user started Vite before booting the
234
+ * emulator. We do NOT keep retrying after the first failure
235
+ * because the URL is baked into bundle.mjs at config-load time
236
+ * and there's no point in flipping it later.
237
+ * - "more than one device" — fatal for unqualified `adb reverse`,
238
+ * so we enumerate via `adb devices` and apply the reverse
239
+ * individually with `-s <serial>`. As long as at least one
240
+ * device gets the mapping we treat the whole call as a success.
241
+ */
242
+ export declare function tryEnableAdbReverse(opts: TryEnableAdbReverseOptions): AdbReverseStatus;
243
+ /**
244
+ * Pick the host string a device or simulator can actually reach.
245
+ *
246
+ * See the file-level comment for the full resolution-precedence
247
+ * narrative. Returns the chosen host alongside a `source` tag so
248
+ * callers (and logs) can explain why a given URL was emitted.
249
+ */
250
+ export declare function resolveDeviceReachableHost(opts: ResolveDeviceHostOptions): DeviceHostResolution;
251
+ export interface ResolveDeviceOriginOptions extends ResolveDeviceHostOptions {
252
+ /** Wire protocol; usually 'http' unless `server.https` is set. */
253
+ protocol?: 'http' | 'https';
254
+ /** Server port; defaults to 5173 to match the Vite dev default. */
255
+ port?: number;
256
+ }
257
+ export interface DeviceOriginResolution extends DeviceHostResolution {
258
+ /** Fully assembled `protocol://host:port` string. */
259
+ origin: string;
260
+ protocol: 'http' | 'https';
261
+ port: number;
262
+ }
263
+ /**
264
+ * Convenience wrapper that returns the full `protocol://host:port`
265
+ * origin string alongside the host-resolution metadata. The vast
266
+ * majority of callers want the assembled origin to splice into a
267
+ * `/ns/...` URL, so this saves them the trivial template string.
268
+ *
269
+ * When the resolved host already includes a `:port` suffix (a common
270
+ * shape for `NS_HMR_HOST=tunnel.example.com:5173`), we split it back
271
+ * out so the assembled origin never doubles up the port.
272
+ */
273
+ export declare function resolveDeviceReachableOrigin(opts: ResolveDeviceOriginOptions): DeviceOriginResolution;
274
+ export {};