@nativescript/vite 8.0.0-alpha.2 → 8.0.0-alpha.20
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.
- package/configuration/angular.d.ts +34 -1
- package/configuration/angular.js +380 -34
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +171 -7
- package/configuration/base.js.map +1 -1
- package/configuration/solid.js +27 -1
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +1 -1
- package/configuration/typescript.js.map +1 -1
- package/helpers/angular/angular-linker.js +3 -12
- package/helpers/angular/angular-linker.js.map +1 -1
- package/helpers/angular/inject-component-hmr-registration.d.ts +112 -0
- package/helpers/angular/inject-component-hmr-registration.js +359 -0
- package/helpers/angular/inject-component-hmr-registration.js.map +1 -0
- package/helpers/angular/inject-hmr-vite-ignore.d.ts +75 -0
- package/helpers/angular/inject-hmr-vite-ignore.js +288 -0
- package/helpers/angular/inject-hmr-vite-ignore.js.map +1 -0
- package/helpers/angular/util.d.ts +1 -0
- package/helpers/angular/util.js +88 -0
- package/helpers/angular/util.js.map +1 -1
- package/helpers/commonjs-plugins.d.ts +5 -2
- package/helpers/commonjs-plugins.js +126 -0
- package/helpers/commonjs-plugins.js.map +1 -1
- package/helpers/config-as-json.js +10 -0
- package/helpers/config-as-json.js.map +1 -1
- package/helpers/dev-host.d.ts +274 -0
- package/helpers/dev-host.js +491 -0
- package/helpers/dev-host.js.map +1 -0
- package/helpers/global-defines.d.ts +51 -0
- package/helpers/global-defines.js +77 -0
- package/helpers/global-defines.js.map +1 -1
- package/helpers/logging.d.ts +1 -0
- package/helpers/logging.js +63 -3
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +3 -1
- package/helpers/main-entry.js +450 -125
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.d.ts +9 -2
- package/helpers/nativeclass-transformer-plugin.js +157 -14
- package/helpers/nativeclass-transformer-plugin.js.map +1 -1
- package/helpers/ns-core-url.d.ts +88 -0
- package/helpers/ns-core-url.js +191 -0
- package/helpers/ns-core-url.js.map +1 -0
- package/helpers/prelink-angular.js +1 -4
- package/helpers/prelink-angular.js.map +1 -1
- package/helpers/project.d.ts +35 -0
- package/helpers/project.js +120 -2
- package/helpers/project.js.map +1 -1
- package/helpers/resolver.js +9 -1
- package/helpers/resolver.js.map +1 -1
- package/helpers/solid-jsx-deps.d.ts +15 -0
- package/helpers/solid-jsx-deps.js +178 -0
- package/helpers/solid-jsx-deps.js.map +1 -0
- package/helpers/ts-config-paths.js +50 -2
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/workers.d.ts +20 -19
- package/helpers/workers.js +620 -3
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.d.ts +1 -0
- package/hmr/client/css-handler.js +34 -5
- package/hmr/client/css-handler.js.map +1 -1
- package/hmr/client/css-update-overlay.d.ts +18 -0
- package/hmr/client/css-update-overlay.js +27 -0
- package/hmr/client/css-update-overlay.js.map +1 -0
- package/hmr/client/hmr-pending-overlay.d.ts +27 -0
- package/hmr/client/hmr-pending-overlay.js +50 -0
- package/hmr/client/hmr-pending-overlay.js.map +1 -0
- package/hmr/client/index.js +483 -33
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/utils.d.ts +5 -0
- package/hmr/client/utils.js +283 -12
- package/hmr/client/utils.js.map +1 -1
- package/hmr/client/vue-sfc-update-overlay.d.ts +82 -0
- package/hmr/client/vue-sfc-update-overlay.js +133 -0
- package/hmr/client/vue-sfc-update-overlay.js.map +1 -0
- package/hmr/entry-runtime.d.ts +2 -1
- package/hmr/entry-runtime.js +253 -66
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/frameworks/angular/client/index.d.ts +3 -1
- package/hmr/frameworks/angular/client/index.js +802 -10
- package/hmr/frameworks/angular/client/index.js.map +1 -1
- package/hmr/frameworks/angular/server/linker.js +1 -4
- package/hmr/frameworks/angular/server/linker.js.map +1 -1
- package/hmr/frameworks/angular/server/strategy.js +30 -6
- package/hmr/frameworks/angular/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/server/strategy.js +8 -2
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/client/index.js +18 -42
- package/hmr/frameworks/vue/client/index.js.map +1 -1
- package/hmr/helpers/ast-normalizer.js +52 -5
- package/hmr/helpers/ast-normalizer.js.map +1 -1
- package/hmr/helpers/cjs-named-exports.d.ts +23 -0
- package/hmr/helpers/cjs-named-exports.js +152 -0
- package/hmr/helpers/cjs-named-exports.js.map +1 -0
- package/hmr/helpers/package-exports.d.ts +16 -0
- package/hmr/helpers/package-exports.js +396 -0
- package/hmr/helpers/package-exports.js.map +1 -0
- package/hmr/server/constants.js +13 -4
- package/hmr/server/constants.js.map +1 -1
- package/hmr/server/core-sanitize.d.ts +93 -8
- package/hmr/server/core-sanitize.js +222 -49
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/import-map.js +80 -22
- package/hmr/server/import-map.js.map +1 -1
- package/hmr/server/index.d.ts +2 -1
- package/hmr/server/index.js.map +1 -1
- package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
- package/hmr/server/ns-core-cjs-shape.js +271 -0
- package/hmr/server/ns-core-cjs-shape.js.map +1 -0
- package/hmr/server/ns-rt-bridge.d.ts +51 -0
- package/hmr/server/ns-rt-bridge.js +131 -0
- package/hmr/server/ns-rt-bridge.js.map +1 -0
- package/hmr/server/perf-instrumentation.d.ts +114 -0
- package/hmr/server/perf-instrumentation.js +195 -0
- package/hmr/server/perf-instrumentation.js.map +1 -0
- package/hmr/server/runtime-graph-filter.d.ts +5 -0
- package/hmr/server/runtime-graph-filter.js +21 -0
- package/hmr/server/runtime-graph-filter.js.map +1 -0
- package/hmr/server/shared-transform-request.d.ts +12 -0
- package/hmr/server/shared-transform-request.js +144 -0
- package/hmr/server/shared-transform-request.js.map +1 -0
- package/hmr/server/vite-plugin.d.ts +21 -1
- package/hmr/server/vite-plugin.js +497 -58
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-angular-entry.d.ts +2 -0
- package/hmr/server/websocket-angular-entry.js +68 -0
- package/hmr/server/websocket-angular-entry.js.map +1 -0
- package/hmr/server/websocket-angular-hot-update.d.ts +78 -0
- package/hmr/server/websocket-angular-hot-update.js +413 -0
- package/hmr/server/websocket-angular-hot-update.js.map +1 -0
- package/hmr/server/websocket-core-bridge.d.ts +58 -0
- package/hmr/server/websocket-core-bridge.js +368 -0
- package/hmr/server/websocket-core-bridge.js.map +1 -0
- package/hmr/server/websocket-css-hot-update.d.ts +33 -0
- package/hmr/server/websocket-css-hot-update.js +65 -0
- package/hmr/server/websocket-css-hot-update.js.map +1 -0
- package/hmr/server/websocket-graph-upsert.d.ts +21 -0
- package/hmr/server/websocket-graph-upsert.js +33 -0
- package/hmr/server/websocket-graph-upsert.js.map +1 -0
- package/hmr/server/websocket-hmr-pending.d.ts +43 -0
- package/hmr/server/websocket-hmr-pending.js +55 -0
- package/hmr/server/websocket-hmr-pending.js.map +1 -0
- package/hmr/server/websocket-module-bindings.d.ts +6 -0
- package/hmr/server/websocket-module-bindings.js +471 -0
- package/hmr/server/websocket-module-bindings.js.map +1 -0
- package/hmr/server/websocket-module-specifiers.d.ts +101 -0
- package/hmr/server/websocket-module-specifiers.js +820 -0
- package/hmr/server/websocket-module-specifiers.js.map +1 -0
- package/hmr/server/websocket-ns-m-finalize.d.ts +22 -0
- package/hmr/server/websocket-ns-m-finalize.js +88 -0
- package/hmr/server/websocket-ns-m-finalize.js.map +1 -0
- package/hmr/server/websocket-ns-m-paths.d.ts +3 -0
- package/hmr/server/websocket-ns-m-paths.js +92 -0
- package/hmr/server/websocket-ns-m-paths.js.map +1 -0
- package/hmr/server/websocket-ns-m-request.d.ts +45 -0
- package/hmr/server/websocket-ns-m-request.js +196 -0
- package/hmr/server/websocket-ns-m-request.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +36 -0
- package/hmr/server/websocket-served-module-helpers.js +644 -0
- package/hmr/server/websocket-served-module-helpers.js.map +1 -0
- package/hmr/server/websocket-txn.d.ts +6 -0
- package/hmr/server/websocket-txn.js +45 -0
- package/hmr/server/websocket-txn.js.map +1 -0
- package/hmr/server/websocket-vendor-unifier.d.ts +10 -0
- package/hmr/server/websocket-vendor-unifier.js +51 -0
- package/hmr/server/websocket-vendor-unifier.js.map +1 -0
- package/hmr/server/websocket-vue-sfc.d.ts +26 -0
- package/hmr/server/websocket-vue-sfc.js +1053 -0
- package/hmr/server/websocket-vue-sfc.js.map +1 -0
- package/hmr/server/websocket.d.ts +58 -75
- package/hmr/server/websocket.js +2230 -1802
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/package-classifier.d.ts +9 -0
- package/hmr/shared/package-classifier.js +58 -0
- package/hmr/shared/package-classifier.js.map +1 -0
- package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
- package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
- package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
- package/hmr/shared/runtime/boot-progress.d.ts +40 -0
- package/hmr/shared/runtime/boot-progress.js +128 -0
- package/hmr/shared/runtime/boot-progress.js.map +1 -0
- package/hmr/shared/runtime/boot-timeline.d.ts +18 -0
- package/hmr/shared/runtime/boot-timeline.js +52 -0
- package/hmr/shared/runtime/boot-timeline.js.map +1 -0
- package/hmr/shared/runtime/browser-runtime-contract.d.ts +64 -0
- package/hmr/shared/runtime/browser-runtime-contract.js +54 -0
- package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay.d.ts +78 -3
- package/hmr/shared/runtime/dev-overlay.js +1094 -26
- package/hmr/shared/runtime/dev-overlay.js.map +1 -1
- package/hmr/shared/runtime/module-provenance.js +1 -4
- package/hmr/shared/runtime/module-provenance.js.map +1 -1
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +1019 -151
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
- package/hmr/shared/runtime/session-bootstrap.js +309 -0
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.js +1 -9
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
- package/hmr/shared/vendor/manifest.d.ts +32 -0
- package/hmr/shared/vendor/manifest.js +411 -46
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +9 -1
- package/runtime/core-aliases-early.js +94 -67
- 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 {};
|