Skip to content

Commit 396c3de

Browse files
edusperoniNathanWalker
authored andcommitted
docs(vite): say which origin hand-off each @nativescript/vite gets
The comments on the dev server spawn, the shared child environment, the port service and the Android pre-build reverse described the `NS_ADB_*` hand-off and the bundle-baked origin as the only way. They apply only to a package without `nativescriptCli.devServerFile`.
1 parent 296c00d commit 396c3de

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎lib/contracts/vite-hmr-port-service.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ export abstract class ViteHmrPortService {
99
* Resolves the port the Vite dev server for `platform` listens on: the
1010
* first free port at or above `NS_HMR_PORT` (default 5173) that no other
1111
* platform in this process holds. Resolved once per platform and stable
12-
* for the life of the process, so the build watcher (which bakes the port
13-
* into `bundle.mjs`), the dev server and the Android `adb reverse` tunnel
14-
* all agree on it.
12+
* for the life of the process, so the dev server, the origin each device
13+
* is given and the Android `adb reverse` tunnel all agree on it.
1514
*
1615
* With `NS_HMR_STRICT_PORT` set, a busy preferred port fails instead of
1716
* moving to the next one.

‎lib/controllers/run-controller.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,9 @@ export class RunController extends EventEmitter implements IRunController {
981981
* Set up `adb reverse tcp:<port> tcp:<port>` for an Android device
982982
* when the project bundles with Vite in HMR/watch mode, then export
983983
* the result to the bundler subprocess via environment variables.
984+
* Only for a `@nativescript/vite` that bakes the origin into
985+
* `bundle.mjs`; see `chooseDevServerOrigin` for one that reads
986+
* `dev-server.json`.
984987
*
985988
* The Vite dev-host helper prefers an ADB tunnel (device-side
986989
* `127.0.0.1:<port>` → host) over the emulator's flaky slirp NAT

‎lib/services/bundler/bundler-compiler-service.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,11 @@ export class BundlerCompilerService
860860
* Environment both Vite children (the build watcher and the dev server)
861861
* must share for a platform: the staging directory, and — for HMR
862862
* sessions — the dev-server port. The port is resolved here, once, and
863-
* handed to `@nativescript/vite` as `NS_HMR_PORT`, so the URLs baked into
864-
* `bundle.mjs`, the server's bind and the `adb reverse` tunnel all match.
865-
* When the devices read their origin from `dev-server.json`, the server
866-
* also gets the token the CLI writes into that file.
863+
* handed to `@nativescript/vite` as `NS_HMR_PORT`, so the server's bind,
864+
* the device origins and the `adb reverse` tunnel all match. When the
865+
* devices read their origin from `dev-server.json`, the server also gets
866+
* the token the CLI writes into that file; otherwise the package bakes
867+
* the origin into `bundle.mjs`.
867868
*/
868869
private async getViteChildEnv(
869870
platform: string,
@@ -894,11 +895,11 @@ export class BundlerCompilerService
894895
* baked into the app. Historically users wired this up themselves with
895896
* `concurrently`/`wait-on`, which left two uncoordinated processes both
896897
* touching adb during cold start (the source of the Android
897-
* "Searching for devices…" freeze). By spawning it here as a child of
898-
* the CLI, the dev server inherits the CLI's environment — crucially
899-
* `NS_ADB_REVERSE_READY`/`NS_DEVICE_SERIAL`/`NS_ADB_PATH` set by the
900-
* run-controller — so the CLI is the single adb owner and the dev
901-
* server never spawns adb itself.
898+
* "Searching for devices…" freeze). The CLI is the single adb owner. A
899+
* `@nativescript/vite` that reads `dev-server.json` knows no device
900+
* origin and never runs adb; an older one inherits the
901+
* `NS_ADB_REVERSE_READY`/`NS_DEVICE_SERIAL`/`NS_ADB_PATH` the
902+
* run-controller sets, so it doesn't spawn adb either.
902903
*
903904
* No-op unless bundler is vite, HMR is on, watch mode, and not release.
904905
* Best-effort: failures are logged, never thrown — a dev-server hiccup

0 commit comments

Comments
 (0)