Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
7a381cf
feat(ios): serve Vite dev over the USB CoreDevice tunnel
edusperoni Nov 21, 2026
091f0fe
fix(ios): count only the --device selection when deciding on the USB …
edusperoni Nov 22, 2026
8c5b274
refactor(ios): build the USB tunnel service on the DI contract
edusperoni Nov 24, 2026
822423e
test(ios): register the USB tunnel service and its stubs by contract …
edusperoni Nov 24, 2026
3411519
refactor(ios): make the USB tunnel service an internal contract
edusperoni Dec 1, 2026
cd43584
style(ios): match the DI conventions used elsewhere
edusperoni Dec 3, 2026
61e0ae7
refactor(ios): implement the USB tunnel service's contract rather tha…
edusperoni Dec 4, 2026
cfd83c6
fix(ios): bound each devicectl listing for the USB tunnel
edusperoni Dec 4, 2026
1097c08
feat(android): send a file from memory over the livesync socket
edusperoni Dec 4, 2026
9249d25
feat(vite): choose each device's dev server origin in the CLI
edusperoni Dec 4, 2026
3a5b9bc
feat(vite): deliver dev-server.json to each device on every full sync
edusperoni Dec 4, 2026
b515300
feat(vite): write an https origin when the dev server serves https
edusperoni Dec 4, 2026
12cb19d
feat(ios): move a device to another origin when its USB tunnel drops
edusperoni Dec 4, 2026
f0d3349
docs(vite): say which origin hand-off each @nativescript/vite gets
edusperoni Dec 4, 2026
97d003c
feat(vite): give every device the LAN origin when NS_HMR_PREFER_LAN_H…
edusperoni Dec 4, 2026
202b04a
fix(vite): deliver dev-server.json again after a recovery reinstall
edusperoni Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { provideLazy } from "./common/di";
import { injector } from "./common/yok";
import { registerBuiltInCommand } from "./common/services/command-definition-adapter";
import { DevServerOriginService } from "./contracts/internal/dev-server-origin-service";
import { IOSDeviceTunnelService } from "./contracts/internal/ios-device-tunnel-service";
import type { fontsCommandDefinition } from "./commands/fonts";
import { AndroidPluginMirrorService } from "./contracts/internal/android-plugin-mirror-service";
import { NativeFileHashesMemo } from "./contracts/internal/native-file-hashes-memo";
Expand Down Expand Up @@ -694,6 +696,22 @@ injector.require(
"viteHmrPortService",
"./services/bundler/vite-hmr-port-service",
);
injector.register(
provideLazy(
IOSDeviceTunnelService,
() =>
require("./services/ios/ios-device-tunnel-service")
.IOSDeviceTunnelServiceImpl,
),
);
injector.register(
provideLazy(
DevServerOriginService,
() =>
require("./services/bundler/dev-server-origin-service")
.DevServerOriginServiceImpl,
),
);

injector.require(
"applePortalSessionService",
Expand Down
6 changes: 6 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export const RSPACK_PLUGIN_NAME = "@nativescript/rspack";
// and tells `@nativescript/vite` where via `NS_VITE_DIST_DIR`; the package's
// own fallback (`.ns-vite-build`) only applies to standalone `vite` runs.
export const VITE_DIST_FOLDER_NAME = ".ns-vite-build";
/**
* Per-device file next to `bundle.mjs` that tells a Vite HMR app the dev
* server's origin and token. Never part of the shared platforms app folder:
* the origin differs between devices.
*/
export const DEV_SERVER_FILE_NAME = "dev-server.json";
export const TNS_CORE_MODULES_WIDGETS_NAME = "tns-core-modules-widgets";
export const UI_MOBILE_BASE_NAME = "@nativescript/ui-mobile-base";
export const TNS_ANDROID_RUNTIME_NAME = "tns-android";
Expand Down
42 changes: 42 additions & 0 deletions lib/contracts/internal/dev-server-origin-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Contract } from "../../common/di/contract";

export interface IDevServerOriginOptions {
/** Android: `adb reverse tcp:<port> tcp:<port>` is confirmed for the device. */
adbReverse?: boolean;
}

/**
* Decides, per device, the origin an app uses to reach the platform's Vite
* dev server, and the content of the `dev-server.json` file that hands the
* origin and the dev server's token to the app.
*/
@Contract()
export abstract class DevServerOriginService {
/**
* The token of the platform's dev server. Generated on first use and kept
* for the life of the process, so a restarted dev server still accepts the
* files already on the devices.
*/
abstract getToken(platform: string): string;

/**
* Chooses the device's origin from what the CLI knows about how it reaches
* this machine, records it and resolves it. A physical iOS / visionOS
* device uses its USB tunnel only while one is open.
*/
abstract chooseOrigin(
device: Mobile.IDevice,
options?: IDevServerOriginOptions,
): Promise<string>;

/** The device's last chosen origin, if any. */
abstract getOrigin(deviceIdentifier: string): string | undefined;

/**
* The `dev-server.json` content for the device, or null when no origin was
* chosen for it, in which case nothing is delivered.
*/
abstract getDevServerFile(deviceIdentifier: string): string | null;

abstract forget(deviceIdentifier: string): void;
}
30 changes: 30 additions & 0 deletions lib/contracts/internal/ios-device-tunnel-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Contract } from "../../common/di/contract";

/**
* Holds the CoreDevice tunnel of a USB-connected iOS 17+ / visionOS device
* so an app can reach the Vite dev server on the Mac over the cable, without
* Wi-Fi or the Local Network prompt.
*/
@Contract()
export abstract class IOSDeviceTunnelService {
/**
* Opens the device's CoreDevice tunnel and keeps it up until `close` or
* the CLI exits. Resolves the Mac's address on the tunnel, or null when
* the device has no usable USB tunnel. A tunnel gets a new address every
* time it is re-established.
*/
abstract open(device: Mobile.IDevice): Promise<string | null>;

/**
* The Mac's address on the device's tunnel while the tunnel is up.
*/
abstract getHostAddress(deviceIdentifier: string): string | undefined;

abstract close(deviceIdentifier: string): Promise<void>;

/**
* Calls `listener` with the device's identifier when an open tunnel goes
* down without `close`, after `getHostAddress` stopped returning it.
*/
abstract onTunnelLost(listener: (deviceIdentifier: string) => void): void;
}
5 changes: 2 additions & 3 deletions lib/contracts/vite-hmr-port-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ export abstract class ViteHmrPortService {
* Resolves the port the Vite dev server for `platform` listens on: the
* first free port at or above `NS_HMR_PORT` (default 5173) that no other
* platform in this process holds. Resolved once per platform and stable
* for the life of the process, so the build watcher (which bakes the port
* into `bundle.mjs`), the dev server and the Android `adb reverse` tunnel
* all agree on it.
* for the life of the process, so the dev server, the origin each device
* is given and the Android `adb reverse` tunnel all agree on it.
*
* With `NS_HMR_STRICT_PORT` set, a busy preferred port fails instead of
* moving to the next one.
Expand Down
Loading
Loading