@nativescript/vite 8.0.0-alpha.19 → 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/base.js +17 -4
- package/configuration/base.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/main-entry.js +28 -10
- package/helpers/main-entry.js.map +1 -1
- package/hmr/entry-runtime.js +39 -0
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/server/core-sanitize.d.ts +62 -1
- package/hmr/server/core-sanitize.js +85 -7
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/import-map.js +32 -0
- package/hmr/server/import-map.js.map +1 -1
- package/hmr/server/vite-plugin.js +17 -37
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket.d.ts +36 -1
- package/hmr/server/websocket.js +94 -33
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/runtime/root-placeholder.js +254 -44
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import os from 'os';
|
|
5
4
|
import { pathToFileURL } from 'url';
|
|
6
5
|
import { NS_DEFAULT_DEV_FEATURE_FLAGS, NS_DEFAULT_HOST_MODULES } from '../shared/runtime/browser-runtime-contract.js';
|
|
6
|
+
import { resolveDeviceReachableHost } from '../../helpers/dev-host.js';
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
const VIRTUAL_ID = 'virtual:ns-hmr-client';
|
|
9
9
|
const RESOLVED_ID = '\0' + VIRTUAL_ID;
|
|
@@ -432,30 +432,6 @@ if (!globalThis.__NS_HMR_BROWSER_RUNTIME_CLIENT_ACTIVE__) {
|
|
|
432
432
|
export function nsHmrClientVitePlugin(opts) {
|
|
433
433
|
let config;
|
|
434
434
|
const sessionId = new Date().toISOString();
|
|
435
|
-
const guessLanHost = () => {
|
|
436
|
-
try {
|
|
437
|
-
const nets = os.networkInterfaces();
|
|
438
|
-
for (const name of Object.keys(nets)) {
|
|
439
|
-
const addrs = nets[name] || [];
|
|
440
|
-
for (const a of addrs) {
|
|
441
|
-
if (!a)
|
|
442
|
-
continue;
|
|
443
|
-
// Node typings vary across versions; keep checks defensive
|
|
444
|
-
const family = a.family;
|
|
445
|
-
const internal = !!a.internal;
|
|
446
|
-
const address = String(a.address || '');
|
|
447
|
-
if (internal)
|
|
448
|
-
continue;
|
|
449
|
-
if (family === 'IPv4' || family === 4) {
|
|
450
|
-
if (address && address !== '127.0.0.1')
|
|
451
|
-
return address;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
catch { }
|
|
457
|
-
return undefined;
|
|
458
|
-
};
|
|
459
435
|
return {
|
|
460
436
|
name: 'ns-hmr-client',
|
|
461
437
|
configResolved(c) {
|
|
@@ -534,19 +510,23 @@ export function nsHmrClientVitePlugin(opts) {
|
|
|
534
510
|
// Prefer project root when available; otherwise fall back to cwd.
|
|
535
511
|
const projectRoot = config?.root || process.cwd();
|
|
536
512
|
const clientImport = computeClientImportSpecifier({ projectRoot, clientFsPath });
|
|
537
|
-
// Build ws url from Vite server info
|
|
538
|
-
|
|
539
|
-
//
|
|
540
|
-
//
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (isWildcard) {
|
|
544
|
-
host = guessLanHost() || (opts.platform === 'android' ? '10.0.2.2' : 'localhost');
|
|
545
|
-
}
|
|
546
|
-
else if (!host) {
|
|
547
|
-
host = opts.platform === 'android' ? guessLanHost() || '10.0.2.2' : 'localhost';
|
|
548
|
-
}
|
|
513
|
+
// Build ws url from Vite server info. Routes through the same
|
|
514
|
+
// canonical helper as `main-entry.ts` / `base.ts` so the
|
|
515
|
+
// websocket endpoint embedded in `bundle.mjs` and every other
|
|
516
|
+
// `/ns/*` URL share one origin string — required by the iOS
|
|
517
|
+
// HTTP ESM cache identity rule, and necessary for Android
|
|
518
|
+
// emulators that can't reach `0.0.0.0` / `localhost`.
|
|
549
519
|
const port = Number(config?.server?.port || 5173);
|
|
520
|
+
// Pass `port` through so the Android emulator path attempts
|
|
521
|
+
// `adb reverse tcp:<port> tcp:<port>` before falling back to
|
|
522
|
+
// `10.0.2.2`. The websocket URL and bundle.mjs URLs both
|
|
523
|
+
// flow from this same helper, so they stay byte-identical
|
|
524
|
+
// (required by the iOS HTTP ESM cache identity rule).
|
|
525
|
+
const { host } = resolveDeviceReachableHost({
|
|
526
|
+
host: config?.server?.host,
|
|
527
|
+
platform: opts.platform,
|
|
528
|
+
port,
|
|
529
|
+
});
|
|
550
530
|
const secure = !!config?.server?.https;
|
|
551
531
|
const protocol = secure ? 'wss' : 'ws';
|
|
552
532
|
const wsUrl = `${protocol}://${host}:${port}/ns-hmr`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/server/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/server/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAmD,MAAM,+CAA+C,CAAC;AACvK,OAAO,EAAE,0BAA0B,EAAE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AyD;YACzD,8DAA8D;YAC9D,4DAA4D;YAC5D,0DAA0D;YAC1D,sDAAsD;YACtD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC;YAClD,4DAA4D;YAC5D,6DAA6D;YAC7D,yDAAyD;YACzD,0DAA0D;YAC1D,sDAAsD;YACtD,MAAM,EAAE,IAAI,EAAE,GAAG,0BAA0B,CAAC;gBAC3C,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI;gBAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,IAAI;aACJ,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;YACvC,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;YACvC,MAAM,KAAK,GAAG,GAAG,QAAQ,MAAM,IAAI,IAAI,IAAI,SAAS,CAAC;YAErD,kDAAkD;YAClD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,mDAAmD,KAAK,kDAAkD,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9I,OAAO;gBACN,IAAI,EAAE;4BACkB,YAAY;EACtC,MAAM;wBACgB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;CAC5C;gBACG,UAAU,EAAE,IAAI;aAChB,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
1
|
+
import type { Plugin, ViteDevServer } from 'vite';
|
|
2
2
|
import '../vendor-bootstrap.js';
|
|
3
3
|
import { angularSourceHasSemanticDecorator, canonicalizeTransformRequestCacheKey, collectAngularEvictionUrls, collectAngularHotUpdateRoots, collectAngularTransformCacheInvalidationUrls, collectAngularTransitiveImportersForInvalidation, collectGraphUpdateModulesForHotUpdate, normalizeHotReloadMatchPath, shouldInvalidateAngularTransitiveImporters, shouldSuppressDefaultViteHotUpdate, shouldSuppressViteFullReloadPayload, type HotUpdateGraphModuleLike, type PendingAngularReloadSuppressionEntry, type TransitiveImporterModuleLike } from './websocket-angular-hot-update.js';
|
|
4
4
|
import { classifyGraphUpsert, shouldBroadcastGraphUpsertDelta, shouldBumpGraphVersion, type GraphUpsertClassification } from './websocket-graph-upsert.js';
|
|
@@ -40,6 +40,41 @@ export declare function hmrWebSocketSolid(opts: {
|
|
|
40
40
|
export declare function hmrWebSocketTypescript(opts: {
|
|
41
41
|
verbose?: boolean;
|
|
42
42
|
}): Plugin;
|
|
43
|
+
/**
|
|
44
|
+
* Get the dev-server origin string baked into every module the rewriter
|
|
45
|
+
* serves to the device (`/ns/core/...`, `/ns/m/...`, etc.).
|
|
46
|
+
*
|
|
47
|
+
* This MUST agree with the origin `dev-host.ts` bakes into `bundle.mjs`
|
|
48
|
+
* itself. If the two disagree (e.g. the bundle imports
|
|
49
|
+
* `http://localhost:5173/ns/core/utils` while the rewriter splices in
|
|
50
|
+
* `http://192.168.0.8:5173/ns/core/utils`) V8's ESM loader keys those
|
|
51
|
+
* as DIFFERENT modules and the app ends up with two side-by-side
|
|
52
|
+
* realms of `@nativescript/core` — a classic singleton-state split.
|
|
53
|
+
* `internal/debug-sessions/LATEST-05-12-2026-HMR_CORE_REALM_SPLIT.md`
|
|
54
|
+
* documents the symptom.
|
|
55
|
+
*
|
|
56
|
+
* Routing all platforms through `resolveDeviceReachableOrigin` keeps
|
|
57
|
+
* them in lock-step:
|
|
58
|
+
*
|
|
59
|
+
* - Android wildcard / loopback → `10.0.2.2` (emulator NAT can't
|
|
60
|
+
* reach the host's LAN IP; physical devices opt in via
|
|
61
|
+
* `NS_HMR_PREFER_LAN_HOST=1`).
|
|
62
|
+
*
|
|
63
|
+
* - iOS / visionOS wildcard → `localhost` (simulator shares the
|
|
64
|
+
* host's network stack; physical devices opt in via the same
|
|
65
|
+
* `NS_HMR_PREFER_LAN_HOST=1` or `NS_HMR_HOST=<lan-ip>` env).
|
|
66
|
+
*
|
|
67
|
+
* - Explicit non-loopback `server.host` (e.g. a developer-set LAN
|
|
68
|
+
* IP) on any platform → trusted verbatim.
|
|
69
|
+
*
|
|
70
|
+
* The old `resolvedUrls.network[0]` preference is intentionally
|
|
71
|
+
* dropped — Vite reports a LAN IP whenever it detects one, but that
|
|
72
|
+
* IP is neither reachable from an Android emulator nor consistent
|
|
73
|
+
* with what `dev-host.ts` selects, so leaning on it created the
|
|
74
|
+
* realm-split risk above.
|
|
75
|
+
*/
|
|
76
|
+
declare function getServerOrigin(server: ViteDevServer): string;
|
|
43
77
|
export declare const __test_processCodeForDevice: typeof processCodeForDevice;
|
|
44
78
|
export declare const __test_resolveVendorRouting: typeof resolveVendorRouting;
|
|
45
79
|
export declare const __test_getBlockedDeviceNodeModulesReason: typeof getBlockedDeviceNodeModulesReason;
|
|
80
|
+
export declare const __test_getServerOrigin: typeof getServerOrigin;
|
package/hmr/server/websocket.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { sanitizeStrayCoreReferences, isDeepCoreSubpath, rewriteSpecifiersForDevice } from './core-sanitize.js';
|
|
2
|
+
import { sanitizeStrayCoreReferences, isDeepCoreSubpath, isDirectoryIndexFilename, rewriteSpecifiersForDevice } from './core-sanitize.js';
|
|
3
3
|
import { buildDefaultExportFooter, buildShapeInstallHeader, hasNamespaceReExport, rewriteNamespaceReExportsForShape } from './ns-core-cjs-shape.js';
|
|
4
4
|
// AST tooling for robust transformations
|
|
5
5
|
import { parse as babelParse } from '@babel/parser';
|
|
@@ -35,6 +35,7 @@ import { getProjectAppPath, getProjectAppRelativePath, getProjectAppVirtualPath
|
|
|
35
35
|
import { buildRuntimeConfig, generateImportMap } from './import-map.js';
|
|
36
36
|
import { getCliFlags } from '../../helpers/cli-flags.js';
|
|
37
37
|
import { buildCoreUrl, buildCoreUrlPath, normalizeCoreSub as normalizeCoreSubCanonical } from '../../helpers/ns-core-url.js';
|
|
38
|
+
import { resolveDeviceReachableOrigin } from '../../helpers/dev-host.js';
|
|
38
39
|
import { isRuntimeGraphExcludedPath, matchesRuntimeGraphModuleId, normalizeRuntimeGraphPath, shouldIncludeRuntimeGraphFile, shouldSkipRuntimeGraphDirectoryName } from './runtime-graph-filter.js';
|
|
39
40
|
import { resolveAngularCoreHmrImportSource, rewriteAngularEntryRegisterOnly } from './websocket-angular-entry.js';
|
|
40
41
|
import { angularSourceHasSemanticDecorator, canonicalizeTransformRequestCacheKey, collectAngularEvictionUrls, collectAngularHotUpdateRoots, collectAngularTransformCacheInvalidationUrls, collectAngularTransitiveImportersForInvalidation, collectGraphUpdateModulesForHotUpdate, normalizeHotReloadMatchPath, shouldInvalidateAngularTransitiveImporters, shouldSuppressDefaultViteHotUpdate, shouldSuppressViteFullReloadPayload } from './websocket-angular-hot-update.js';
|
|
@@ -4362,7 +4363,24 @@ export const piniaSymbol = p.piniaSymbol;
|
|
|
4362
4363
|
// Vite's transform output references module IDs with /@fs,
|
|
4363
4364
|
// relative specifiers, or absolute project paths. Rewrite
|
|
4364
4365
|
// those to URLs iOS can fetch over HTTP.
|
|
4365
|
-
|
|
4366
|
+
//
|
|
4367
|
+
// We also thread a `RelativeBase` so any lingering relative
|
|
4368
|
+
// specifiers (`./x`, `../x`) — which Vite's import-analysis
|
|
4369
|
+
// sometimes leaves untouched for `node_modules` files — get
|
|
4370
|
+
// resolved against the served URL's logical directory and
|
|
4371
|
+
// rewritten to canonical `/ns/core/<resolved>` URLs.
|
|
4372
|
+
//
|
|
4373
|
+
// Without this, V8/iOS apply RFC 3986 URL resolution against
|
|
4374
|
+
// the served URL (which has no trailing slash) and treat the
|
|
4375
|
+
// last path segment as a *file*, so `./layout-helper-common`
|
|
4376
|
+
// from `/ns/core/utils/layout-helper` becomes
|
|
4377
|
+
// `/ns/core/utils/layout-helper-common` — a sibling that
|
|
4378
|
+
// doesn't exist, producing "Failed to load url … Does the
|
|
4379
|
+
// file exist?" from Vite and a stuck boot screen.
|
|
4380
|
+
const __rawSubForRel = String(normalizedSub || sub || '').replace(/^\/+|\/+$/g, '');
|
|
4381
|
+
const __isDirIndex = isDirectoryIndexFilename(modulePath || '');
|
|
4382
|
+
const __relBase = { sub: __rawSubForRel, isDirectoryIndex: __isDirIndex };
|
|
4383
|
+
let rewritten = rewriteSpecifiersForDevice(transformed.code, getServerOrigin(server), Number(graphVersion || 0), __relBase);
|
|
4366
4384
|
// Invariant D (CJS/ESM interop shape) — EXPORT-SIDE fix.
|
|
4367
4385
|
//
|
|
4368
4386
|
// `@nativescript/core/index.js` declares namespace
|
|
@@ -7469,52 +7487,95 @@ export function hmrWebSocketTypescript(opts) {
|
|
|
7469
7487
|
return createHmrWebSocketPlugin(opts);
|
|
7470
7488
|
}
|
|
7471
7489
|
/**
|
|
7472
|
-
* Get server origin
|
|
7490
|
+
* Get the dev-server origin string baked into every module the rewriter
|
|
7491
|
+
* serves to the device (`/ns/core/...`, `/ns/m/...`, etc.).
|
|
7492
|
+
*
|
|
7493
|
+
* This MUST agree with the origin `dev-host.ts` bakes into `bundle.mjs`
|
|
7494
|
+
* itself. If the two disagree (e.g. the bundle imports
|
|
7495
|
+
* `http://localhost:5173/ns/core/utils` while the rewriter splices in
|
|
7496
|
+
* `http://192.168.0.8:5173/ns/core/utils`) V8's ESM loader keys those
|
|
7497
|
+
* as DIFFERENT modules and the app ends up with two side-by-side
|
|
7498
|
+
* realms of `@nativescript/core` — a classic singleton-state split.
|
|
7499
|
+
* `internal/debug-sessions/LATEST-05-12-2026-HMR_CORE_REALM_SPLIT.md`
|
|
7500
|
+
* documents the symptom.
|
|
7501
|
+
*
|
|
7502
|
+
* Routing all platforms through `resolveDeviceReachableOrigin` keeps
|
|
7503
|
+
* them in lock-step:
|
|
7504
|
+
*
|
|
7505
|
+
* - Android wildcard / loopback → `10.0.2.2` (emulator NAT can't
|
|
7506
|
+
* reach the host's LAN IP; physical devices opt in via
|
|
7507
|
+
* `NS_HMR_PREFER_LAN_HOST=1`).
|
|
7508
|
+
*
|
|
7509
|
+
* - iOS / visionOS wildcard → `localhost` (simulator shares the
|
|
7510
|
+
* host's network stack; physical devices opt in via the same
|
|
7511
|
+
* `NS_HMR_PREFER_LAN_HOST=1` or `NS_HMR_HOST=<lan-ip>` env).
|
|
7512
|
+
*
|
|
7513
|
+
* - Explicit non-loopback `server.host` (e.g. a developer-set LAN
|
|
7514
|
+
* IP) on any platform → trusted verbatim.
|
|
7515
|
+
*
|
|
7516
|
+
* The old `resolvedUrls.network[0]` preference is intentionally
|
|
7517
|
+
* dropped — Vite reports a LAN IP whenever it detects one, but that
|
|
7518
|
+
* IP is neither reachable from an Android emulator nor consistent
|
|
7519
|
+
* with what `dev-host.ts` selects, so leaning on it created the
|
|
7520
|
+
* realm-split risk above.
|
|
7473
7521
|
*/
|
|
7474
7522
|
function getServerOrigin(server) {
|
|
7475
|
-
const
|
|
7476
|
-
// Prefer a real LAN/network URL when available so emulators/devices can reach the host directly.
|
|
7477
|
-
if (urls?.network?.length) {
|
|
7478
|
-
try {
|
|
7479
|
-
const u = new URL(String(urls.network[0]));
|
|
7480
|
-
const origin = `${u.protocol}//${u.host}`;
|
|
7481
|
-
if (!/^https?:\/\/[\w\-.:\[\]]+$/.test(origin)) {
|
|
7482
|
-
console.warn('[hmr][origin] invariant failed for resolvedUrls.network:', urls.network[0], '→', origin);
|
|
7483
|
-
}
|
|
7484
|
-
return origin;
|
|
7485
|
-
}
|
|
7486
|
-
catch {
|
|
7487
|
-
// Fallthrough to local below if network parse fails
|
|
7488
|
-
}
|
|
7489
|
-
}
|
|
7490
|
-
if (urls?.local?.length) {
|
|
7491
|
-
try {
|
|
7492
|
-
const u = new URL(String(urls.local[0]));
|
|
7493
|
-
const origin = `${u.protocol}//${u.host}`;
|
|
7494
|
-
if (!/^https?:\/\/[\w\-.:\[\]]+$/.test(origin)) {
|
|
7495
|
-
console.warn('[hmr][origin] invariant failed for resolvedUrls.local:', urls.local[0], '→', origin);
|
|
7496
|
-
}
|
|
7497
|
-
return origin;
|
|
7498
|
-
}
|
|
7499
|
-
catch {
|
|
7500
|
-
// Fallthrough to manual construction
|
|
7501
|
-
}
|
|
7502
|
-
}
|
|
7523
|
+
const platform = detectDevHostPlatform();
|
|
7503
7524
|
const isHttps = !!server.config.server?.https;
|
|
7525
|
+
const protocol = isHttps ? 'https' : 'http';
|
|
7504
7526
|
const httpServer = server.httpServer;
|
|
7505
7527
|
const addr = httpServer?.address?.();
|
|
7506
7528
|
const port = Number(server.config.server?.port || addr?.port || 5173);
|
|
7529
|
+
try {
|
|
7530
|
+
const { origin } = resolveDeviceReachableOrigin({
|
|
7531
|
+
host: server.config.server?.host,
|
|
7532
|
+
platform,
|
|
7533
|
+
protocol,
|
|
7534
|
+
port,
|
|
7535
|
+
});
|
|
7536
|
+
if (/^https?:\/\/[\w\-.:\[\]]+$/.test(origin)) {
|
|
7537
|
+
return origin;
|
|
7538
|
+
}
|
|
7539
|
+
console.warn('[hmr][origin] invariant failed for resolveDeviceReachableOrigin:', origin);
|
|
7540
|
+
}
|
|
7541
|
+
catch (err) {
|
|
7542
|
+
console.warn('[hmr][origin] resolveDeviceReachableOrigin threw:', err?.message || String(err));
|
|
7543
|
+
}
|
|
7544
|
+
// Last-ditch fallback for the implausible case where the resolver
|
|
7545
|
+
// throws (CI containers with no NICs, exotic `process.env` shapes,
|
|
7546
|
+
// etc.). We deliberately do NOT consult `resolvedUrls.network[0]`
|
|
7547
|
+
// here — see the file-level comment above for why.
|
|
7507
7548
|
const hostCfg = server.config.server?.host;
|
|
7508
|
-
const
|
|
7509
|
-
const origin = `${
|
|
7549
|
+
const fallbackHost = typeof hostCfg === 'string' && hostCfg && hostCfg !== '0.0.0.0' ? hostCfg : platform === 'android' ? '10.0.2.2' : '127.0.0.1';
|
|
7550
|
+
const origin = `${protocol}://${fallbackHost}:${port}`;
|
|
7510
7551
|
if (!/^https?:\/\/[\w\-.:\[\]]+$/.test(origin)) {
|
|
7511
7552
|
console.warn('[hmr][origin] invariant failed for constructed origin:', origin);
|
|
7512
7553
|
}
|
|
7513
7554
|
return origin;
|
|
7514
7555
|
}
|
|
7556
|
+
/**
|
|
7557
|
+
* Resolve the device target platform from the CLI flags the dev server
|
|
7558
|
+
* was launched with. The `--env.android` / `--env.visionos` flags are
|
|
7559
|
+
* surfaced by the NativeScript CLI when it spawns Vite; iOS is the
|
|
7560
|
+
* safe default when no flag is set so the helper stays a pure
|
|
7561
|
+
* function and standalone `vite serve` sessions still get sensible
|
|
7562
|
+
* URLs.
|
|
7563
|
+
*/
|
|
7564
|
+
function detectDevHostPlatform() {
|
|
7565
|
+
try {
|
|
7566
|
+
const flags = (getCliFlags() || {});
|
|
7567
|
+
if (flags.android)
|
|
7568
|
+
return 'android';
|
|
7569
|
+
if (flags.visionos)
|
|
7570
|
+
return 'visionos';
|
|
7571
|
+
}
|
|
7572
|
+
catch { }
|
|
7573
|
+
return 'ios';
|
|
7574
|
+
}
|
|
7515
7575
|
// Test-only export: allow unit tests to run the sanitizer on snippets without booting a server
|
|
7516
7576
|
// Safe in production builds; this is a named export that tests can import explicitly.
|
|
7517
7577
|
export const __test_processCodeForDevice = processCodeForDevice;
|
|
7518
7578
|
export const __test_resolveVendorRouting = resolveVendorRouting;
|
|
7519
7579
|
export const __test_getBlockedDeviceNodeModulesReason = getBlockedDeviceNodeModulesReason;
|
|
7580
|
+
export const __test_getServerOrigin = getServerOrigin;
|
|
7520
7581
|
//# sourceMappingURL=websocket.js.map
|