@nativescript/vite 8.0.0-alpha.3 → 8.0.0-alpha.30
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/README.md +51 -11
- package/configuration/angular.d.ts +34 -1
- package/configuration/angular.js +369 -159
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +184 -14
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +5 -72
- package/configuration/javascript.js.map +1 -1
- package/configuration/solid.js +27 -1
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +5 -75
- package/configuration/typescript.js.map +1 -1
- package/helpers/angular/angular-linker.d.ts +5 -6
- package/helpers/angular/angular-linker.js +36 -121
- 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 +291 -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 +221 -0
- package/helpers/angular/inject-hmr-vite-ignore.js.map +1 -0
- package/helpers/angular/inline-decorator-component-templates.js +1 -170
- package/helpers/angular/inline-decorator-component-templates.js.map +1 -1
- package/helpers/angular/js-lexer.d.ts +4 -0
- package/helpers/angular/js-lexer.js +182 -0
- package/helpers/angular/js-lexer.js.map +1 -0
- package/helpers/angular/shared-linker.d.ts +31 -3
- package/helpers/angular/shared-linker.js +67 -14
- package/helpers/angular/shared-linker.js.map +1 -1
- package/helpers/angular/synthesize-decorator-ctor-parameters.js +2 -170
- package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +1 -1
- package/helpers/angular/synthesize-injectable-factories.js +1 -174
- package/helpers/angular/synthesize-injectable-factories.js.map +1 -1
- 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/app-components.d.ts +2 -1
- package/helpers/app-components.js.map +1 -1
- package/helpers/app-css-state.d.ts +8 -0
- package/helpers/app-css-state.js +8 -0
- package/helpers/app-css-state.js.map +1 -0
- package/helpers/bundler-context.d.ts +11 -0
- package/helpers/bundler-context.js +71 -0
- package/helpers/bundler-context.js.map +1 -0
- package/helpers/config-as-json.js +10 -0
- package/helpers/config-as-json.js.map +1 -1
- package/helpers/dev-host.d.ts +341 -0
- package/helpers/dev-host.js +617 -0
- package/helpers/dev-host.js.map +1 -0
- package/helpers/esbuild-platform-resolver.js +4 -1
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- 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/hmr-scope.d.ts +26 -0
- package/helpers/hmr-scope.js +67 -0
- package/helpers/hmr-scope.js.map +1 -0
- package/helpers/init.js +0 -18
- package/helpers/init.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 +2 -1
- package/helpers/main-entry.js +430 -47
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
- package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
- package/helpers/nativeclass-transform.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/nativescript-package-resolver.js +8 -3
- package/helpers/nativescript-package-resolver.js.map +1 -1
- package/helpers/normalize-id.d.ts +42 -0
- package/helpers/normalize-id.js +60 -0
- package/helpers/normalize-id.js.map +1 -0
- 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/package-platform-aliases.js +4 -3
- package/helpers/package-platform-aliases.js.map +1 -1
- package/helpers/platform-types.d.ts +2 -0
- package/helpers/platform-types.js +2 -0
- package/helpers/platform-types.js.map +1 -0
- package/helpers/prelink-angular.js +12 -33
- 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 +17 -2
- 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.d.ts +14 -0
- package/helpers/ts-config-paths.js +89 -8
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/typescript-check.d.ts +2 -1
- package/helpers/typescript-check.js.map +1 -1
- package/helpers/workers.d.ts +20 -19
- package/helpers/workers.js +624 -4
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.d.ts +1 -0
- package/hmr/client/css-handler.js +33 -20
- 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 +419 -15
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/utils.d.ts +6 -1
- package/hmr/client/utils.js +184 -8
- 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 +252 -65
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/frameworks/angular/client/index.d.ts +1 -0
- package/hmr/frameworks/angular/client/index.js +778 -20
- 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 +13 -15
- package/hmr/frameworks/angular/server/strategy.js.map +1 -1
- package/hmr/frameworks/solid/server/strategy.js +3 -18
- package/hmr/frameworks/solid/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/server/strategy.js +2 -15
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/client/index.js +30 -199
- 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/angular-root-component.d.ts +79 -0
- package/hmr/server/angular-root-component.js +149 -0
- package/hmr/server/angular-root-component.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 +90 -7
- package/hmr/server/core-sanitize.js +211 -56
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/framework-strategy.d.ts +9 -19
- package/hmr/server/hmr-module-graph.d.ts +37 -0
- package/hmr/server/hmr-module-graph.js +214 -0
- package/hmr/server/hmr-module-graph.js.map +1 -0
- package/hmr/server/import-map.js +60 -8
- package/hmr/server/import-map.js.map +1 -1
- package/hmr/server/index.js +1 -0
- 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/ns-rt-route.d.ts +5 -0
- package/hmr/server/ns-rt-route.js +35 -0
- package/hmr/server/ns-rt-route.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/require-guard.d.ts +1 -0
- package/hmr/server/require-guard.js +12 -0
- package/hmr/server/require-guard.js.map +1 -0
- package/hmr/server/route-helpers.d.ts +7 -0
- package/hmr/server/route-helpers.js +13 -0
- package/hmr/server/route-helpers.js.map +1 -0
- package/hmr/server/server-origin.d.ts +12 -0
- package/hmr/server/server-origin.js +66 -0
- package/hmr/server/server-origin.js.map +1 -0
- package/hmr/server/shared-transform-request.js +12 -5
- package/hmr/server/shared-transform-request.js.map +1 -1
- package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
- package/hmr/server/vendor-bare-module-shims.js +80 -0
- package/hmr/server/vendor-bare-module-shims.js.map +1 -0
- package/hmr/server/vite-plugin.js +60 -42
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-angular-entry.js +1 -1
- package/hmr/server/websocket-angular-entry.js.map +1 -1
- package/hmr/server/websocket-angular-hot-update.d.ts +17 -0
- package/hmr/server/websocket-angular-hot-update.js +176 -2
- package/hmr/server/websocket-angular-hot-update.js.map +1 -1
- package/hmr/server/websocket-core-bridge.d.ts +41 -6
- package/hmr/server/websocket-core-bridge.js +72 -75
- package/hmr/server/websocket-core-bridge.js.map +1 -1
- 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-device-transform.d.ts +21 -0
- package/hmr/server/websocket-device-transform.js +1570 -0
- package/hmr/server/websocket-device-transform.js.map +1 -0
- package/hmr/server/websocket-graph-upsert.d.ts +15 -0
- package/hmr/server/websocket-graph-upsert.js +20 -0
- package/hmr/server/websocket-graph-upsert.js.map +1 -1
- 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-hot-update.d.ts +51 -0
- package/hmr/server/websocket-hot-update.js +1160 -0
- package/hmr/server/websocket-hot-update.js.map +1 -0
- package/hmr/server/websocket-import-map-route.d.ts +15 -0
- package/hmr/server/websocket-import-map-route.js +44 -0
- package/hmr/server/websocket-import-map-route.js.map +1 -0
- package/hmr/server/websocket-module-bindings.js +3 -3
- package/hmr/server/websocket-module-bindings.js.map +1 -1
- package/hmr/server/websocket-module-specifiers.d.ts +66 -2
- package/hmr/server/websocket-module-specifiers.js +202 -19
- package/hmr/server/websocket-module-specifiers.js.map +1 -1
- package/hmr/server/websocket-ns-core.d.ts +21 -0
- package/hmr/server/websocket-ns-core.js +305 -0
- package/hmr/server/websocket-ns-core.js.map +1 -0
- package/hmr/server/websocket-ns-entry.d.ts +22 -0
- package/hmr/server/websocket-ns-entry.js +150 -0
- package/hmr/server/websocket-ns-entry.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-ns-m.d.ts +34 -0
- package/hmr/server/websocket-ns-m.js +853 -0
- package/hmr/server/websocket-ns-m.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +39 -0
- package/hmr/server/websocket-served-module-helpers.js +654 -0
- package/hmr/server/websocket-served-module-helpers.js.map +1 -0
- package/hmr/server/websocket-sfc.d.ts +24 -0
- package/hmr/server/websocket-sfc.js +1223 -0
- package/hmr/server/websocket-sfc.js.map +1 -0
- package/hmr/server/websocket-txn.d.ts +6 -0
- package/hmr/server/websocket-txn.js +39 -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 +45 -0
- package/hmr/server/websocket-vendor-unifier.js.map +1 -0
- package/hmr/server/websocket.d.ts +0 -30
- package/hmr/server/websocket.js +599 -6038
- package/hmr/server/websocket.js.map +1 -1
- 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/dev-overlay-snapshots.d.ts +31 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay.d.ts +75 -26
- package/hmr/shared/runtime/dev-overlay.js +990 -260
- 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-view.d.ts +19 -0
- package/hmr/shared/runtime/root-placeholder-view.js +310 -0
- package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.js +352 -194
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.js +164 -1
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
- package/hmr/shared/runtime/vendor-bootstrap.js +1 -9
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
- package/hmr/shared/vendor/manifest-collect.d.ts +32 -0
- package/hmr/shared/vendor/manifest-collect.js +512 -0
- package/hmr/shared/vendor/manifest-collect.js.map +1 -0
- package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
- package/hmr/shared/vendor/manifest-loader.js +3 -2
- package/hmr/shared/vendor/manifest-loader.js.map +1 -1
- package/hmr/shared/vendor/manifest.d.ts +1 -5
- package/hmr/shared/vendor/manifest.js +102 -739
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
- package/hmr/shared/vendor/vendor-device-shim.js +208 -0
- package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +16 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js +203 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +55 -11
- package/runtime/core-aliases-early.js +17 -41
- package/runtime/core-aliases-early.js.map +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Recursively collect every file under `dir` (posix paths), tolerating unreadable entries. */
|
|
4
|
+
export function walkAppFiles(dir, out = []) {
|
|
5
|
+
let entries = [];
|
|
6
|
+
try {
|
|
7
|
+
entries = readdirSync(dir);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
const full = path.posix.join(dir, entry);
|
|
14
|
+
let st;
|
|
15
|
+
try {
|
|
16
|
+
st = statSync(full);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (st.isDirectory())
|
|
22
|
+
walkAppFiles(full, out);
|
|
23
|
+
else
|
|
24
|
+
out.push(full);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
/** Skip partials (`_`-prefixed), `.d.ts`, worker modules, and platform-mismatched files. */
|
|
29
|
+
export function shouldExcludePlatformFile(p, platform) {
|
|
30
|
+
const file = p.split('/').pop() || '';
|
|
31
|
+
if (file.startsWith('_'))
|
|
32
|
+
return true;
|
|
33
|
+
if (/\.d\.ts$/.test(p))
|
|
34
|
+
return true;
|
|
35
|
+
if (/([.-]worker)\.(ts|js)$/.test(file))
|
|
36
|
+
return true;
|
|
37
|
+
const isAndroidTagged = /\.android\./.test(p);
|
|
38
|
+
const isIosTagged = /\.ios\./.test(p) || /\.visionos\./.test(p);
|
|
39
|
+
if (platform === 'android' && isIosTagged)
|
|
40
|
+
return true;
|
|
41
|
+
if ((platform === 'ios' || platform === 'visionos') && isAndroidTagged)
|
|
42
|
+
return true;
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
/** Absolute app path → root-anchored import specifier the dev server can serve. */
|
|
46
|
+
export function toContextImportSpecifier(abs) {
|
|
47
|
+
return '/' + abs.replace(/^\/+/, '');
|
|
48
|
+
}
|
|
49
|
+
/** Loads `.xml` files as default-exported strings (shared by the JS and TS configs). */
|
|
50
|
+
export function createXmlLoaderPlugin(name) {
|
|
51
|
+
return {
|
|
52
|
+
name,
|
|
53
|
+
enforce: 'pre',
|
|
54
|
+
load(id) {
|
|
55
|
+
if (!id.endsWith('.xml'))
|
|
56
|
+
return null;
|
|
57
|
+
try {
|
|
58
|
+
const src = readFileSync(id, 'utf-8');
|
|
59
|
+
const xml = JSON.stringify(src)
|
|
60
|
+
.replace(/\u2028/g, '\\u2028')
|
|
61
|
+
.replace(/\u2029/g, '\\u2029');
|
|
62
|
+
const code = `const ___XML___ = ${xml};\nexport default ___XML___;`;
|
|
63
|
+
return { code, map: null };
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=bundler-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler-context.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/bundler-context.ts"],"names":[],"mappings":"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"}
|
|
@@ -27,6 +27,16 @@ export default function nsConfigAsJsonPlugin() {
|
|
|
27
27
|
// 3. After Rollup has generated all chunks, emit a package.json asset
|
|
28
28
|
// into the output directory (dist/ by default)
|
|
29
29
|
generateBundle(_options, _bundle) {
|
|
30
|
+
// Lazy-init in case no module in the graph imported '~/package.json'
|
|
31
|
+
// this build. (Under HMR with @nativescript/core external, the
|
|
32
|
+
// `~/package.json` import that lived inside core's graph is gone, so
|
|
33
|
+
// `load()` never fires. Without this guard, `configObject` is
|
|
34
|
+
// undefined, `JSON.stringify` returns undefined, and rolldown's
|
|
35
|
+
// emitFile rejects it with "Missing field `inner` on
|
|
36
|
+
// BindingEmittedAsset.source".)
|
|
37
|
+
if (!configObject) {
|
|
38
|
+
configObject = nsConfigToJson();
|
|
39
|
+
}
|
|
30
40
|
const json = JSON.stringify(configObject, null, 2);
|
|
31
41
|
this.emitFile({
|
|
32
42
|
type: 'asset',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-as-json.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/config-as-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAEnD,MAAM,CAAC,OAAO,UAAU,oBAAoB;IAC3C,sCAAsC;IACtC,IAAI,YAAiC,CAAC;IAEtC,OAAO;QACN,IAAI,EAAE,yBAAyB;QAE/B,2CAA2C;QAC3C,SAAS,CAAC,MAAM;YACf,IAAI,MAAM,KAAK,gBAAgB,EAAE,CAAC;gBACjC,OAAO,iBAAiB,CAAC;YAC1B,CAAC;YACD,OAAO,IAAI,CAAC;QACb,CAAC;QAED,kDAAkD;QAClD,IAAI,CAAC,EAAE;YACN,IAAI,EAAE,KAAK,iBAAiB,EAAE,CAAC;gBAC9B,YAAY,GAAG,cAAc,EAAE,CAAC;gBAEhC,+DAA+D;gBAC/D,OAAO;oBACN,IAAI,EAAE,kBAAkB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG;oBACvD,UAAU,EAAE,IAAI;iBAChB,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACb,CAAC;QAED,sEAAsE;QACtE,kDAAkD;QAClD,cAAc,CAAC,QAAQ,EAAE,OAAO;YAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACnD,IAAI,CAAC,QAAQ,CAAC;gBACb,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,cAAc;gBACxB,MAAM,EAAE,IAAI;aACZ,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"config-as-json.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/config-as-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAEnD,MAAM,CAAC,OAAO,UAAU,oBAAoB;IAC3C,sCAAsC;IACtC,IAAI,YAAiC,CAAC;IAEtC,OAAO;QACN,IAAI,EAAE,yBAAyB;QAE/B,2CAA2C;QAC3C,SAAS,CAAC,MAAM;YACf,IAAI,MAAM,KAAK,gBAAgB,EAAE,CAAC;gBACjC,OAAO,iBAAiB,CAAC;YAC1B,CAAC;YACD,OAAO,IAAI,CAAC;QACb,CAAC;QAED,kDAAkD;QAClD,IAAI,CAAC,EAAE;YACN,IAAI,EAAE,KAAK,iBAAiB,EAAE,CAAC;gBAC9B,YAAY,GAAG,cAAc,EAAE,CAAC;gBAEhC,+DAA+D;gBAC/D,OAAO;oBACN,IAAI,EAAE,kBAAkB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG;oBACvD,UAAU,EAAE,IAAI;iBAChB,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACb,CAAC;QAED,sEAAsE;QACtE,kDAAkD;QAClD,cAAc,CAAC,QAAQ,EAAE,OAAO;YAC/B,qEAAqE;YACrE,+DAA+D;YAC/D,qEAAqE;YACrE,8DAA8D;YAC9D,gEAAgE;YAChE,qDAAqD;YACrD,gCAAgC;YAChC,IAAI,CAAC,YAAY,EAAE,CAAC;gBACnB,YAAY,GAAG,cAAc,EAAE,CAAC;YACjC,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACnD,IAAI,CAAC,QAAQ,CAAC;gBACb,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,cAAc;gBACxB,MAAM,EAAE,IAAI;aACZ,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,341 @@
|
|
|
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
|
+
import type { Platform } from './platform-types.js';
|
|
78
|
+
export type DevHostPlatform = Platform;
|
|
79
|
+
/**
|
|
80
|
+
* Per-port cache of `adb reverse` setup attempts. Keyed by port so
|
|
81
|
+
* dev servers that switch ports across restarts get a clean attempt
|
|
82
|
+
* each time. The cache is required because every entry point that
|
|
83
|
+
* embeds a device-reachable URL (the bundle.mjs boot path, the
|
|
84
|
+
* `/ns/core/*` external resolver, the websocket URL emitter, the
|
|
85
|
+
* served-module rewriter) hits `resolveDeviceReachable*` — if we
|
|
86
|
+
* spawned `adb reverse` on every call we'd fork ~half a dozen
|
|
87
|
+
* subprocesses per Vite startup and the cold-boot would slow
|
|
88
|
+
* noticeably.
|
|
89
|
+
*
|
|
90
|
+
* The cache also gives us a stable answer across all consumers: once
|
|
91
|
+
* the first caller learns that adb reverse is available, every later
|
|
92
|
+
* caller in the same process gets the same `localhost`/`10.0.2.2`
|
|
93
|
+
* decision. URL identity is what keeps the iOS HTTP ESM realm from
|
|
94
|
+
* splitting and what keeps the Android HMR client and bundle.mjs
|
|
95
|
+
* pointing at the same origin.
|
|
96
|
+
*/
|
|
97
|
+
interface AdbReverseStatus {
|
|
98
|
+
attempted: boolean;
|
|
99
|
+
succeeded: boolean;
|
|
100
|
+
error?: string;
|
|
101
|
+
/** Device serials that successfully received the reverse mapping. */
|
|
102
|
+
devices: string[];
|
|
103
|
+
/**
|
|
104
|
+
* Set when the mapping was established by the NativeScript CLI (it
|
|
105
|
+
* exported `NS_ADB_REVERSE_READY=1`) rather than by this plugin.
|
|
106
|
+
* In that case the plugin never spawned `adb` at all — it simply
|
|
107
|
+
* trusts that `127.0.0.1:<port>` already tunnels to the host. See
|
|
108
|
+
* the CLI-handoff note in `tryEnableAdbReverse`.
|
|
109
|
+
*/
|
|
110
|
+
viaCli?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Returns the first non-internal IPv4 address on the host machine, or
|
|
114
|
+
* `undefined` if no LAN NIC is up. Pure wrapper around
|
|
115
|
+
* `os.networkInterfaces()` so callers and tests can stub it cleanly.
|
|
116
|
+
*/
|
|
117
|
+
export declare function guessLanHost(): string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the given host string is a wildcard "all interfaces" bind
|
|
120
|
+
* address rather than a routable hostname. `host` may be the literal
|
|
121
|
+
* string from a Vite config (`'0.0.0.0'`), an empty string, or `'true'`
|
|
122
|
+
* (some older Vite/CLI surfaces stringify the boolean).
|
|
123
|
+
*/
|
|
124
|
+
export declare function isWildcardHost(host: string): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Whether the given host string is loopback. On Android the loopback
|
|
127
|
+
* address is the device itself, NOT the development host — so callers
|
|
128
|
+
* must remap it for Android consumers.
|
|
129
|
+
*/
|
|
130
|
+
export declare function isLoopbackHost(host: string): boolean;
|
|
131
|
+
export interface DeviceHostResolution {
|
|
132
|
+
/** Final host string baked into the device-side URL. */
|
|
133
|
+
host: string;
|
|
134
|
+
/**
|
|
135
|
+
* How the value was chosen. `'env'` / `'explicit'` mean the result
|
|
136
|
+
* is locked-in; `'lan'`, `'adb-reverse'`, and `'platform-default'`
|
|
137
|
+
* are fallbacks selected by this helper.
|
|
138
|
+
*/
|
|
139
|
+
source: 'env' | 'explicit' | 'lan' | 'adb-reverse' | 'platform-default';
|
|
140
|
+
}
|
|
141
|
+
export interface ResolveDeviceHostOptions {
|
|
142
|
+
/** The raw host value from the Vite config (`server.host`). */
|
|
143
|
+
host?: unknown;
|
|
144
|
+
/** Target device platform. Drives the loopback / wildcard fallback. */
|
|
145
|
+
platform: DevHostPlatform;
|
|
146
|
+
/**
|
|
147
|
+
* Override for `process.env`. Tests pass a fixture object; runtime
|
|
148
|
+
* callers omit this and pick up the ambient process environment.
|
|
149
|
+
*/
|
|
150
|
+
env?: NodeJS.ProcessEnv;
|
|
151
|
+
/**
|
|
152
|
+
* Override for `guessLanHost()`. Tests stub a fixed return value;
|
|
153
|
+
* runtime callers omit this and the helper hits real NICs.
|
|
154
|
+
*/
|
|
155
|
+
lanHostResolver?: () => string | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Dev-server port. When set AND `platform === 'android'`, this
|
|
158
|
+
* helper will lazily attempt `adb reverse tcp:<port> tcp:<port>`
|
|
159
|
+
* on first call and, if it succeeds, emit `localhost` instead of
|
|
160
|
+
* `10.0.2.2`. See `tryEnableAdbReverse` for the full rationale.
|
|
161
|
+
*
|
|
162
|
+
* Optional for backwards compatibility — callers that already have
|
|
163
|
+
* the port (which is everyone except a couple of legacy test
|
|
164
|
+
* fixtures) should pass it so Android emulator users get the
|
|
165
|
+
* reliable ADB tunnel path instead of QEMU slirp's flaky NAT.
|
|
166
|
+
*/
|
|
167
|
+
port?: number;
|
|
168
|
+
/**
|
|
169
|
+
* Test seam for the adb-reverse subprocess. When passed, this
|
|
170
|
+
* helper uses the injected exec function instead of spawning
|
|
171
|
+
* `child_process.execFileSync`. Runtime callers omit this and pick
|
|
172
|
+
* up the SDK-resolved adb binary (see `resolveAdbPath`).
|
|
173
|
+
*/
|
|
174
|
+
adbExec?: AdbExec;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Subprocess shim used by `tryEnableAdbReverse`. Production code
|
|
178
|
+
* routes through `child_process.execFileSync` — argv form, NO
|
|
179
|
+
* `/bin/sh -c` wrapper. That matters for two reasons:
|
|
180
|
+
*
|
|
181
|
+
* 1. On timeout, `execFileSync` signals the actual `adb` child
|
|
182
|
+
* directly. The old `execSync('adb …')` form spawned a shell
|
|
183
|
+
* that spawned adb; killing the shell on timeout ORPHANED the
|
|
184
|
+
* adb grandchild, and a half-handshaked orphan can wedge the
|
|
185
|
+
* adb daemon out from under the CLI's device tracker.
|
|
186
|
+
*
|
|
187
|
+
* 2. No shell means no quoting / `$PATH` surprises — we invoke an
|
|
188
|
+
* absolute, SDK-resolved adb binary (see `resolveAdbPath`) with
|
|
189
|
+
* a literal argv.
|
|
190
|
+
*
|
|
191
|
+
* Tests stub this so the suite can exercise success / failure /
|
|
192
|
+
* "multiple devices" / "no ADB" paths without touching a real
|
|
193
|
+
* Android emulator. The shim receives the resolved adb path and the
|
|
194
|
+
* argv array (e.g. `['-s', 'emulator-5554', 'reverse', …]`).
|
|
195
|
+
*/
|
|
196
|
+
export type AdbExec = (adbPath: string, args: string[], opts: {
|
|
197
|
+
timeout: number;
|
|
198
|
+
}) => string;
|
|
199
|
+
/**
|
|
200
|
+
* Resolve the `adb` executable the way the Android SDK tooling does,
|
|
201
|
+
* so the plugin and the NativeScript CLI drive the *same* adb client.
|
|
202
|
+
*
|
|
203
|
+
* Why this is load-bearing. A bare `adb` from `$PATH` is frequently a
|
|
204
|
+
* DIFFERENT version than the one the CLI resolves from the SDK. When
|
|
205
|
+
* two adb *clients* of differing versions talk to the one global adb
|
|
206
|
+
* server (port 5037), the newer client prints
|
|
207
|
+
* `adb server version (NN) doesn't match this client (MM); killing...`
|
|
208
|
+
* and restarts the daemon — severing the CLI's `track-devices` stream
|
|
209
|
+
* and hanging it at "Searching for devices…" forever. Resolving the
|
|
210
|
+
* exact SDK adb eliminates that mismatch.
|
|
211
|
+
*
|
|
212
|
+
* Precedence:
|
|
213
|
+
* 1. `NS_ADB_PATH` — the CLI exports the absolute path to the adb it
|
|
214
|
+
* itself uses. Always wins so the two processes are byte-identical.
|
|
215
|
+
* 2. `$ANDROID_HOME/platform-tools/adb` (+ `.exe` on Windows).
|
|
216
|
+
* 3. `$ANDROID_SDK_ROOT/platform-tools/adb`.
|
|
217
|
+
* 4. Bare `adb` — last-resort PATH lookup (kept only so a machine
|
|
218
|
+
* with adb on PATH but no SDK env still limps along).
|
|
219
|
+
*
|
|
220
|
+
* Candidates from (2)/(3) are existence-checked; a stale env var that
|
|
221
|
+
* points at a missing binary falls through rather than guaranteeing a
|
|
222
|
+
* spawn failure.
|
|
223
|
+
*/
|
|
224
|
+
export declare function resolveAdbPath(env?: NodeJS.ProcessEnv): string;
|
|
225
|
+
export interface TryEnableAdbReverseOptions {
|
|
226
|
+
/** Port to forward on both sides of the ADB bridge. */
|
|
227
|
+
port: number;
|
|
228
|
+
/** Override for `process.env`; tests pass a fixture object. */
|
|
229
|
+
env?: NodeJS.ProcessEnv;
|
|
230
|
+
/** Test seam — see `AdbExec`. */
|
|
231
|
+
exec?: AdbExec;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Read-only view of the current `adb reverse` status for a given
|
|
235
|
+
* dev-server port. Returns `undefined` if `tryEnableAdbReverse` has
|
|
236
|
+
* never been called for that port.
|
|
237
|
+
*/
|
|
238
|
+
export declare function getAdbReverseStatus(port: number): AdbReverseStatus | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* Test hook — clears the per-port cache so unit tests can exercise
|
|
241
|
+
* fresh "first call" behavior without leaking state between cases.
|
|
242
|
+
* NOT exported from the package barrel; spec files import via the
|
|
243
|
+
* file path directly.
|
|
244
|
+
*/
|
|
245
|
+
export declare function __resetAdbReverseCacheForTests(): void;
|
|
246
|
+
/**
|
|
247
|
+
* Try to set up `adb reverse tcp:<port> tcp:<port>` for every
|
|
248
|
+
* connected Android device / emulator so device-side `localhost:port`
|
|
249
|
+
* routes through the ADB transport to the host's dev server.
|
|
250
|
+
*
|
|
251
|
+
* Why this beats `10.0.2.2`. The Android emulator's stock NAT is
|
|
252
|
+
* QEMU's `slirp` user-mode network stack, which is well-known to
|
|
253
|
+
* drop bursts of concurrent TCP setups to the host. In practice this
|
|
254
|
+
* surfaces as ~80% of synchronous module-loader fetches failing with
|
|
255
|
+
* `IOException: unexpected end of stream` — the connection establishes,
|
|
256
|
+
* the request goes out, and then slirp drops the response before
|
|
257
|
+
* okhttp can read the status line. The failures are random per-module
|
|
258
|
+
* across runs, retries help but don't eliminate them, and the symptom
|
|
259
|
+
* masquerades as a server-side bug.
|
|
260
|
+
*
|
|
261
|
+
* `adb reverse` bypasses the emulator NIC entirely — the device-side
|
|
262
|
+
* connection is multiplexed over the existing ADB USB / TCP channel
|
|
263
|
+
* to the host. It's the same mechanism React Native, Expo, and
|
|
264
|
+
* Flutter use for Android dev, and it works for both emulators and
|
|
265
|
+
* USB-connected physical devices.
|
|
266
|
+
*
|
|
267
|
+
* Caching. The result is cached per-port so repeat callers don't
|
|
268
|
+
* fork extra subprocesses. The cache is keyed on port (not platform)
|
|
269
|
+
* because the wildcard "Android-ness" of the call is already implied
|
|
270
|
+
* by the caller — only Android consumers hit this path.
|
|
271
|
+
*
|
|
272
|
+
* CLI handoff (the preferred path). When the NativeScript CLI drives
|
|
273
|
+
* the run it already owns device discovery, install, and launch — it
|
|
274
|
+
* knows the exact target serial and exactly when the device is ready.
|
|
275
|
+
* In that mode the CLI performs the `adb reverse` itself, with its own
|
|
276
|
+
* SDK-resolved adb, AFTER the device is up, and exports
|
|
277
|
+
* `NS_ADB_REVERSE_READY=1`. Seeing that flag, this function returns a
|
|
278
|
+
* synthetic success WITHOUT spawning adb at all — removing the second,
|
|
279
|
+
* racing adb owner that used to collide with the CLI's device search
|
|
280
|
+
* during cold start. `NS_DEVICE_SERIAL` (the CLI's deploy target) and
|
|
281
|
+
* `NS_ADB_PATH` (the CLI's adb) are honored in the self-managed
|
|
282
|
+
* fallback below for setups where the CLI did NOT pre-wire the reverse.
|
|
283
|
+
*
|
|
284
|
+
* Self-managed hardening (fallback). When `NS_ADB_REVERSE_READY` is
|
|
285
|
+
* absent we still set the mapping ourselves, but defensively:
|
|
286
|
+
* - resolve adb from the SDK (`resolveAdbPath`) — never a bare PATH
|
|
287
|
+
* `adb` that could version-mismatch and kill the CLI's daemon;
|
|
288
|
+
* - `adb start-server` once up front so a cold daemon is owned by a
|
|
289
|
+
* single, version-matched client before anything else touches it;
|
|
290
|
+
* - argv `execFileSync` (no shell) with a child-killing timeout so a
|
|
291
|
+
* hung adb is reaped rather than orphaned;
|
|
292
|
+
* - `wait-for-device` per serial so we don't issue `reverse` against
|
|
293
|
+
* an emulator whose `adbd` hasn't finished coming up.
|
|
294
|
+
*
|
|
295
|
+
* Failure modes (all surface as a cached `succeeded: false`):
|
|
296
|
+
* - `NS_HMR_NO_ADB_REVERSE=1` — explicit opt-out for unusual
|
|
297
|
+
* setups (e.g. Wi-Fi-connected device with no ADB tunnel, CI
|
|
298
|
+
* containers without ADB installed).
|
|
299
|
+
* - `adb` not resolvable / not runnable.
|
|
300
|
+
* - No connected devices — user started Vite before booting the
|
|
301
|
+
* emulator. We do NOT keep retrying after the first failure
|
|
302
|
+
* because the URL is baked into bundle.mjs at config-load time
|
|
303
|
+
* and there's no point in flipping it later.
|
|
304
|
+
* - "more than one device" — fatal for unqualified `adb reverse`,
|
|
305
|
+
* so we target each serial individually with `-s <serial>`. As
|
|
306
|
+
* long as at least one device gets the mapping we treat the whole
|
|
307
|
+
* call as a success.
|
|
308
|
+
*/
|
|
309
|
+
export declare function tryEnableAdbReverse(opts: TryEnableAdbReverseOptions): AdbReverseStatus;
|
|
310
|
+
/**
|
|
311
|
+
* Pick the host string a device or simulator can actually reach.
|
|
312
|
+
*
|
|
313
|
+
* See the file-level comment for the full resolution-precedence
|
|
314
|
+
* narrative. Returns the chosen host alongside a `source` tag so
|
|
315
|
+
* callers (and logs) can explain why a given URL was emitted.
|
|
316
|
+
*/
|
|
317
|
+
export declare function resolveDeviceReachableHost(opts: ResolveDeviceHostOptions): DeviceHostResolution;
|
|
318
|
+
export interface ResolveDeviceOriginOptions extends ResolveDeviceHostOptions {
|
|
319
|
+
/** Wire protocol; usually 'http' unless `server.https` is set. */
|
|
320
|
+
protocol?: 'http' | 'https';
|
|
321
|
+
/** Server port; defaults to 5173 to match the Vite dev default. */
|
|
322
|
+
port?: number;
|
|
323
|
+
}
|
|
324
|
+
export interface DeviceOriginResolution extends DeviceHostResolution {
|
|
325
|
+
/** Fully assembled `protocol://host:port` string. */
|
|
326
|
+
origin: string;
|
|
327
|
+
protocol: 'http' | 'https';
|
|
328
|
+
port: number;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Convenience wrapper that returns the full `protocol://host:port`
|
|
332
|
+
* origin string alongside the host-resolution metadata. The vast
|
|
333
|
+
* majority of callers want the assembled origin to splice into a
|
|
334
|
+
* `/ns/...` URL, so this saves them the trivial template string.
|
|
335
|
+
*
|
|
336
|
+
* When the resolved host already includes a `:port` suffix (a common
|
|
337
|
+
* shape for `NS_HMR_HOST=tunnel.example.com:5173`), we split it back
|
|
338
|
+
* out so the assembled origin never doubles up the port.
|
|
339
|
+
*/
|
|
340
|
+
export declare function resolveDeviceReachableOrigin(opts: ResolveDeviceOriginOptions): DeviceOriginResolution;
|
|
341
|
+
export {};
|