@nativescript/vite 0.0.1 → 1.0.0
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/LICENSE +19 -0
- package/README.md +81 -0
- package/{dist/configuration → configuration}/angular.d.ts +1 -1
- package/configuration/angular.js +371 -0
- package/configuration/angular.js.map +1 -0
- package/configuration/base.d.ts +5 -0
- package/configuration/base.js +491 -0
- package/configuration/base.js.map +1 -0
- package/configuration/javascript.d.ts +4 -0
- package/configuration/javascript.js +152 -0
- package/configuration/javascript.js.map +1 -0
- package/{dist/configuration → configuration}/react.d.ts +1 -1
- package/{dist/configuration → configuration}/react.js +18 -17
- package/configuration/react.js.map +1 -0
- package/{dist/configuration → configuration}/solid.d.ts +1 -1
- package/{dist/configuration → configuration}/solid.js +17 -16
- package/configuration/solid.js.map +1 -0
- package/configuration/typescript.d.ts +4 -0
- package/configuration/typescript.js +176 -0
- package/configuration/typescript.js.map +1 -0
- package/{dist/configuration → configuration}/vue.d.ts +1 -1
- package/configuration/vue.js +163 -0
- package/configuration/vue.js.map +1 -0
- package/helpers/angular/angular-linker.d.ts +13 -0
- package/helpers/angular/angular-linker.js +189 -0
- package/helpers/angular/angular-linker.js.map +1 -0
- package/helpers/angular/shared-linker.d.ts +4 -0
- package/helpers/angular/shared-linker.js +39 -0
- package/helpers/angular/shared-linker.js.map +1 -0
- package/helpers/angular/util.d.ts +1 -0
- package/helpers/angular/util.js +67 -0
- package/helpers/angular/util.js.map +1 -0
- package/helpers/cli-flags.d.ts +1 -0
- package/helpers/cli-flags.js +15 -0
- package/helpers/cli-flags.js.map +1 -0
- package/{dist/helpers → helpers}/commonjs-plugins.js +14 -13
- package/helpers/commonjs-plugins.js.map +1 -0
- package/{dist/helpers → helpers}/config-as-json.d.ts +1 -1
- package/{dist/helpers → helpers}/config-as-json.js +7 -6
- package/helpers/config-as-json.js.map +1 -0
- package/helpers/css-platform-plugin.d.ts +10 -0
- package/helpers/css-platform-plugin.js +76 -0
- package/helpers/css-platform-plugin.js.map +1 -0
- package/helpers/css-tree.js +22 -0
- package/helpers/css-tree.js.map +1 -0
- package/{dist/helpers → helpers}/dynamic-import-plugin.js +8 -7
- package/helpers/dynamic-import-plugin.js.map +1 -0
- package/helpers/esbuild-platform-resolver.d.ts +14 -0
- package/helpers/esbuild-platform-resolver.js +93 -0
- package/helpers/esbuild-platform-resolver.js.map +1 -0
- package/helpers/external-configs.d.ts +6 -0
- package/helpers/external-configs.js +34 -0
- package/helpers/external-configs.js.map +1 -0
- package/{dist/helpers → helpers}/flavor.d.ts +1 -0
- package/helpers/flavor.js +51 -0
- package/helpers/flavor.js.map +1 -0
- package/helpers/global-defines.d.ts +25 -0
- package/helpers/global-defines.js +29 -0
- package/helpers/global-defines.js.map +1 -0
- package/helpers/init.d.ts +1 -0
- package/helpers/init.js +119 -0
- package/helpers/init.js.map +1 -0
- package/helpers/logging.d.ts +13 -0
- package/helpers/logging.js +115 -0
- package/helpers/logging.js.map +1 -0
- package/helpers/main-entry.d.ts +10 -0
- package/helpers/main-entry.js +223 -0
- package/helpers/main-entry.js.map +1 -0
- package/{dist/helpers → helpers}/module-resolution.js +4 -3
- package/helpers/module-resolution.js.map +1 -0
- package/helpers/module-runner-patch.d.ts +3 -0
- package/helpers/module-runner-patch.js +63 -0
- package/helpers/module-runner-patch.js.map +1 -0
- package/helpers/nativeclass-transform.d.ts +7 -0
- package/helpers/nativeclass-transform.js +158 -0
- package/helpers/nativeclass-transform.js.map +1 -0
- package/helpers/nativeclass-transformer-plugin.d.ts +5 -0
- package/helpers/nativeclass-transformer-plugin.js +23 -0
- package/helpers/nativeclass-transformer-plugin.js.map +1 -0
- package/{dist/helpers → helpers}/nativescript-package-resolver.js +18 -17
- package/helpers/nativescript-package-resolver.js.map +1 -0
- package/helpers/ns-cli-plugins.d.ts +14 -0
- package/helpers/ns-cli-plugins.js +165 -0
- package/helpers/ns-cli-plugins.js.map +1 -0
- package/helpers/package-platform-aliases.d.ts +10 -0
- package/{dist/helpers → helpers}/package-platform-aliases.js +19 -23
- package/helpers/package-platform-aliases.js.map +1 -0
- package/helpers/postcss-platform-config.d.ts +13 -0
- package/helpers/postcss-platform-config.js +97 -0
- package/helpers/postcss-platform-config.js.map +1 -0
- package/helpers/prelink-angular.d.ts +2 -0
- package/helpers/prelink-angular.js +117 -0
- package/helpers/prelink-angular.js.map +1 -0
- package/helpers/preserve-imports.d.ts +2 -0
- package/helpers/preserve-imports.js +38 -0
- package/helpers/preserve-imports.js.map +1 -0
- package/{dist/helpers → helpers}/project.js +2 -4
- package/helpers/project.js.map +1 -0
- package/helpers/resolver.d.ts +4 -0
- package/{dist/helpers → helpers}/resolver.js +7 -6
- package/helpers/resolver.js.map +1 -0
- package/helpers/theme-core-plugins.d.ts +14 -0
- package/helpers/theme-core-plugins.js +121 -0
- package/helpers/theme-core-plugins.js.map +1 -0
- package/helpers/ts-config-paths.d.ts +10 -0
- package/{dist/helpers → helpers}/ts-config-paths.js +73 -72
- package/helpers/ts-config-paths.js.map +1 -0
- package/{dist/helpers → helpers}/utils.d.ts +10 -0
- package/helpers/utils.js +143 -0
- package/helpers/utils.js.map +1 -0
- package/{dist/helpers → helpers}/workers.js +15 -16
- package/helpers/workers.js.map +1 -0
- package/hmr/client/css-handler.d.ts +4 -0
- package/hmr/client/css-handler.js +78 -0
- package/hmr/client/css-handler.js.map +1 -0
- package/hmr/client/index.d.ts +13 -0
- package/hmr/client/index.js +1723 -0
- package/hmr/client/index.js.map +1 -0
- package/hmr/client/utils.d.ts +38 -0
- package/hmr/client/utils.js +426 -0
- package/hmr/client/utils.js.map +1 -0
- package/hmr/entry-runtime.d.ts +8 -0
- package/hmr/entry-runtime.js +135 -0
- package/hmr/entry-runtime.js.map +1 -0
- package/hmr/frameworks/angular/client/index.d.ts +8 -0
- package/hmr/frameworks/angular/client/index.js +59 -0
- package/hmr/frameworks/angular/client/index.js.map +1 -0
- package/hmr/frameworks/angular/server/linker.d.ts +1 -0
- package/hmr/frameworks/angular/server/linker.js +101 -0
- package/hmr/frameworks/angular/server/linker.js.map +1 -0
- package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
- package/hmr/frameworks/angular/server/strategy.js +187 -0
- package/hmr/frameworks/angular/server/strategy.js.map +1 -0
- package/hmr/frameworks/solid/server/strategy.d.ts +2 -0
- package/hmr/frameworks/solid/server/strategy.js +56 -0
- package/hmr/frameworks/solid/server/strategy.js.map +1 -0
- package/hmr/frameworks/typescript/server/strategy.d.ts +2 -0
- package/hmr/frameworks/typescript/server/strategy.js +125 -0
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -0
- package/hmr/frameworks/vue/client/index.d.ts +22 -0
- package/hmr/frameworks/vue/client/index.js +1541 -0
- package/hmr/frameworks/vue/client/index.js.map +1 -0
- package/hmr/frameworks/vue/server/compiler.d.ts +11 -0
- package/hmr/frameworks/vue/server/compiler.js +26 -0
- package/hmr/frameworks/vue/server/compiler.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-transforms.d.ts +14 -0
- package/hmr/frameworks/vue/server/sfc-transforms.js +282 -0
- package/hmr/frameworks/vue/server/sfc-transforms.js.map +1 -0
- package/hmr/frameworks/vue/server/strategy.d.ts +2 -0
- package/hmr/frameworks/vue/server/strategy.js +272 -0
- package/hmr/frameworks/vue/server/strategy.js.map +1 -0
- package/hmr/helpers/ast-extract.d.ts +6 -0
- package/hmr/helpers/ast-extract.js +72 -0
- package/hmr/helpers/ast-extract.js.map +1 -0
- package/hmr/helpers/ast-normalizer.d.ts +7 -0
- package/hmr/helpers/ast-normalizer.js +772 -0
- package/hmr/helpers/ast-normalizer.js.map +1 -0
- package/hmr/helpers/babel.d.ts +3 -0
- package/hmr/helpers/babel.js +17 -0
- package/hmr/helpers/babel.js.map +1 -0
- package/hmr/helpers/sanitize.d.ts +6 -0
- package/hmr/helpers/sanitize.js +55 -0
- package/hmr/helpers/sanitize.js.map +1 -0
- package/hmr/helpers/vendor-rewrite.d.ts +1 -0
- package/hmr/helpers/vendor-rewrite.js +35 -0
- package/hmr/helpers/vendor-rewrite.js.map +1 -0
- package/hmr/server/compiler.d.ts +2 -0
- package/hmr/server/compiler.js +75 -0
- package/hmr/server/compiler.js.map +1 -0
- package/hmr/server/constants.d.ts +14 -0
- package/hmr/server/constants.js +23 -0
- package/hmr/server/constants.js.map +1 -0
- package/hmr/server/core-sanitize.d.ts +32 -0
- package/hmr/server/core-sanitize.js +134 -0
- package/hmr/server/core-sanitize.js.map +1 -0
- package/hmr/server/framework-strategy.d.ts +68 -0
- package/hmr/server/framework-strategy.js +2 -0
- package/hmr/server/framework-strategy.js.map +1 -0
- package/hmr/server/index.d.ts +5 -0
- package/hmr/server/index.js +23 -0
- package/hmr/server/index.js.map +1 -0
- package/hmr/server/vite-plugin.d.ts +5 -0
- package/hmr/server/vite-plugin.js +44 -0
- package/hmr/server/vite-plugin.js.map +1 -0
- package/hmr/server/websocket.d.ts +21 -0
- package/hmr/server/websocket.js +5619 -0
- package/hmr/server/websocket.js.map +1 -0
- package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
- package/hmr/shared/runtime/http-only-boot.js +107 -0
- package/hmr/shared/runtime/http-only-boot.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +142 -0
- package/hmr/shared/runtime/root-placeholder.js.map +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.d.ts +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.js +134 -0
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -0
- package/hmr/shared/vendor/manifest-loader.d.ts +9 -0
- package/hmr/shared/vendor/manifest-loader.js +38 -0
- package/hmr/shared/vendor/manifest-loader.js.map +1 -0
- package/hmr/shared/vendor/manifest.d.ts +35 -0
- package/hmr/shared/vendor/manifest.js +811 -0
- package/hmr/shared/vendor/manifest.js.map +1 -0
- package/hmr/shared/vendor/registry.d.ts +9 -0
- package/hmr/shared/vendor/registry.js +62 -0
- package/hmr/shared/vendor/registry.js.map +1 -0
- package/hmr/vendor-bootstrap.d.ts +3 -0
- package/hmr/vendor-bootstrap.js +32 -0
- package/hmr/vendor-bootstrap.js.map +1 -0
- package/{dist/index.d.ts → index.d.ts} +2 -0
- package/index.js +19 -0
- package/index.js.map +1 -0
- package/package.json +42 -30
- package/{dist/polyfills → polyfills}/mdn-data-at-rules.js +1 -0
- package/polyfills/mdn-data-at-rules.js.map +1 -0
- package/{dist/polyfills → polyfills}/mdn-data-properties.js +1 -0
- package/polyfills/mdn-data-properties.js.map +1 -0
- package/{dist/polyfills → polyfills}/mdn-data-syntaxes.js +1 -0
- package/polyfills/mdn-data-syntaxes.js.map +1 -0
- package/{dist/polyfills → polyfills}/module.js +1 -0
- package/polyfills/module.js.map +1 -0
- package/runtime/core-aliases-early.d.ts +1 -0
- package/runtime/core-aliases-early.js +334 -0
- package/runtime/core-aliases-early.js.map +1 -0
- package/shims/angular-animations-stub.d.ts +68 -0
- package/shims/angular-animations-stub.js +140 -0
- package/shims/angular-animations-stub.js.map +1 -0
- package/shims/node-module.d.ts +5 -0
- package/shims/node-module.js +13 -0
- package/shims/node-module.js.map +1 -0
- package/{dist/shims → shims}/react-reconciler-constants.js +2 -1
- package/shims/react-reconciler-constants.js.map +1 -0
- package/{dist/shims → shims}/react-reconciler.js +1 -0
- package/shims/react-reconciler.js.map +1 -0
- package/{dist/shims → shims}/set-value.js +5 -1
- package/shims/set-value.js.map +1 -0
- package/transformers/NativeClass/index.d.ts +2 -0
- package/transformers/NativeClass/index.js +222 -0
- package/transformers/NativeClass/index.js.map +1 -0
- package/dist/configuration/angular.js +0 -30
- package/dist/configuration/base.d.ts +0 -13
- package/dist/configuration/base.js +0 -228
- package/dist/configuration/old-without-merge-base.d.ts +0 -13
- package/dist/configuration/old-without-merge-base.js +0 -249
- package/dist/configuration/vue.js +0 -45
- package/dist/helpers/css-tree.js +0 -21
- package/dist/helpers/flavor.js +0 -40
- package/dist/helpers/global-defines.d.ts +0 -14
- package/dist/helpers/global-defines.js +0 -18
- package/dist/helpers/main-entry.d.ts +0 -5
- package/dist/helpers/main-entry.js +0 -75
- package/dist/helpers/ns-cli-plugins.d.ts +0 -17
- package/dist/helpers/ns-cli-plugins.js +0 -128
- package/dist/helpers/package-platform-aliases.d.ts +0 -4
- package/dist/helpers/resolver.d.ts +0 -4
- package/dist/helpers/ts-config-paths.d.ts +0 -4
- package/dist/helpers/utils.js +0 -94
- package/dist/hmr/hmr-angular.d.ts +0 -1
- package/dist/hmr/hmr-angular.js +0 -34
- package/dist/hmr/hmr-bridge.d.ts +0 -18
- package/dist/hmr/hmr-bridge.js +0 -154
- package/dist/hmr/hmr-client.d.ts +0 -5
- package/dist/hmr/hmr-client.js +0 -93
- package/dist/hmr/hmr-server.d.ts +0 -20
- package/dist/hmr/hmr-server.js +0 -179
- package/dist/index.js +0 -5
- package/dist/transformers/NativeClass/index.d.ts +0 -5
- package/dist/transformers/NativeClass/index.js +0 -46
- /package/{dist/helpers → helpers}/commonjs-plugins.d.ts +0 -0
- /package/{dist/helpers → helpers}/css-tree.d.ts +0 -0
- /package/{dist/helpers → helpers}/dynamic-import-plugin.d.ts +0 -0
- /package/{dist/helpers → helpers}/module-resolution.d.ts +0 -0
- /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
- /package/{dist/helpers → helpers}/project.d.ts +0 -0
- /package/{dist/helpers → helpers}/workers.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-at-rules.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-properties.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-syntaxes.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/module.d.ts +0 -0
- /package/{dist/shims → shims}/react-reconciler-constants.d.ts +0 -0
- /package/{dist/shims → shims}/react-reconciler.d.ts +0 -0
- /package/{dist/shims → shims}/set-value.d.ts +0 -0
|
@@ -0,0 +1,1541 @@
|
|
|
1
|
+
import { attachDiagnosticsToFrame, deriveHttpOrigin, getCore, getCurrentApp, getGraphVersion, getHMRWsUrl, getHttpOriginForVite, normalizeSpec, safeDynImport, safeReadDefault, setCurrentApp } from '../../../client/utils.js';
|
|
2
|
+
const APP_VIRTUAL_WITH_SLASH = (() => {
|
|
3
|
+
const root = typeof __NS_APP_ROOT_VIRTUAL__ === 'string' && __NS_APP_ROOT_VIRTUAL__ ? __NS_APP_ROOT_VIRTUAL__ : '/src';
|
|
4
|
+
return root.replace(/\/+$/, '') + '/';
|
|
5
|
+
})();
|
|
6
|
+
// Optional runtime knob: allow disabling assembler path in favor of variant-only flow
|
|
7
|
+
const DISABLE_ASM = !!globalThis.__NS_HMR_DISABLE_ASM__;
|
|
8
|
+
// Module-scoped state to avoid leaking into globalThis
|
|
9
|
+
let nsVueInitDone = false; // nativescript-vue init guard
|
|
10
|
+
let nsStartDone = false; // start() guard
|
|
11
|
+
// Track SFC changes by graph version to prioritize SFC root reset before non-Vue evaluation
|
|
12
|
+
let sfcChangedVersion = null;
|
|
13
|
+
export const sfcChangedIds = new Set();
|
|
14
|
+
// Map of original SFC source absolute/relative path -> compiled sfc-*.mjs filename written to Documents
|
|
15
|
+
export const sfcArtifactMap = new Map();
|
|
16
|
+
// Install dev shims for nativescript-vue navigation to observe and (optionally) rescue
|
|
17
|
+
export function installNsVueDevShims() {
|
|
18
|
+
try {
|
|
19
|
+
const g = globalThis;
|
|
20
|
+
const reg = g.__nsVendorRegistry;
|
|
21
|
+
const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
22
|
+
const getMod = (id) => {
|
|
23
|
+
try {
|
|
24
|
+
if (reg && reg.has(id))
|
|
25
|
+
return reg.get(id);
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
try {
|
|
29
|
+
if (typeof req === 'function')
|
|
30
|
+
return req(id);
|
|
31
|
+
}
|
|
32
|
+
catch { }
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
const nv = getMod('nativescript-vue');
|
|
36
|
+
const rh = getMod('nativescript-vue/dist/runtimeHelpers');
|
|
37
|
+
const wrap = (orig, label) => {
|
|
38
|
+
if (typeof orig !== 'function')
|
|
39
|
+
return orig;
|
|
40
|
+
if (orig.__ns_wrapped__)
|
|
41
|
+
return orig; // idempotent
|
|
42
|
+
const wrapped = function __ns_nav_wrap(component, params) {
|
|
43
|
+
try {
|
|
44
|
+
if (__NS_ENV_VERBOSE__) {
|
|
45
|
+
console.log('[diag][nv][navigateTo]', {
|
|
46
|
+
from: label,
|
|
47
|
+
hasComp: !!component,
|
|
48
|
+
paramKeys: Object.keys(params || {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return orig.apply(this, arguments);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
try {
|
|
55
|
+
console.warn('[diag][nv][navigateTo][error]', (e && e.message) || e);
|
|
56
|
+
}
|
|
57
|
+
catch { }
|
|
58
|
+
try {
|
|
59
|
+
// Rescue path: attempt navigation via authoritative app Frame
|
|
60
|
+
return globalThis.__nsNavigateUsingApp?.(component, params);
|
|
61
|
+
}
|
|
62
|
+
catch { }
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
wrapped.__ns_wrapped__ = true;
|
|
68
|
+
}
|
|
69
|
+
catch { }
|
|
70
|
+
return wrapped;
|
|
71
|
+
};
|
|
72
|
+
if (nv) {
|
|
73
|
+
try {
|
|
74
|
+
if (nv.navigateTo)
|
|
75
|
+
nv.navigateTo = wrap(nv.navigateTo, 'nv');
|
|
76
|
+
if (nv.$navigateTo)
|
|
77
|
+
nv.$navigateTo = wrap(nv.$navigateTo, '$nv');
|
|
78
|
+
}
|
|
79
|
+
catch { }
|
|
80
|
+
}
|
|
81
|
+
if (rh) {
|
|
82
|
+
try {
|
|
83
|
+
if (rh.navigateTo)
|
|
84
|
+
rh.navigateTo = wrap(rh.navigateTo, 'rh');
|
|
85
|
+
}
|
|
86
|
+
catch { }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch { }
|
|
90
|
+
}
|
|
91
|
+
// initial root component for back fallback
|
|
92
|
+
let ORIG_ROOT_COMPONENT = null;
|
|
93
|
+
// Ensure Vue runtime global functions exist before evaluating SFC artifacts that rely on globalThis.* indirections.
|
|
94
|
+
export function ensureVueGlobals() {
|
|
95
|
+
try {
|
|
96
|
+
const g = globalThis;
|
|
97
|
+
const vueAlready = g.defineComponent && g.resolveComponent && g.createVNode;
|
|
98
|
+
const req = globalThis.__nsVendorRegistry?.get ? globalThis.__nsVendorRequire || globalThis.__nsRequire || globalThis.require : globalThis.__nsRequire || globalThis.require;
|
|
99
|
+
const registry = globalThis.__nsVendorRegistry;
|
|
100
|
+
let nvMod = null;
|
|
101
|
+
let vueMod = null;
|
|
102
|
+
// Prefer nativescript-vue first so createApp has .start and NSVRoot is available
|
|
103
|
+
if (registry && registry.has('nativescript-vue')) {
|
|
104
|
+
nvMod = registry.get('nativescript-vue');
|
|
105
|
+
}
|
|
106
|
+
if (registry && registry.has('vue')) {
|
|
107
|
+
vueMod = registry.get('vue');
|
|
108
|
+
}
|
|
109
|
+
if (!nvMod && typeof req === 'function') {
|
|
110
|
+
try {
|
|
111
|
+
nvMod = req('nativescript-vue');
|
|
112
|
+
}
|
|
113
|
+
catch { }
|
|
114
|
+
}
|
|
115
|
+
if (!vueMod && typeof req === 'function') {
|
|
116
|
+
try {
|
|
117
|
+
vueMod = req('vue');
|
|
118
|
+
}
|
|
119
|
+
catch { }
|
|
120
|
+
if (!vueMod) {
|
|
121
|
+
try {
|
|
122
|
+
vueMod = req('@vue/runtime-core');
|
|
123
|
+
}
|
|
124
|
+
catch { }
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const baseMod = nvMod || vueMod;
|
|
128
|
+
let chosenMod = baseMod;
|
|
129
|
+
if (!chosenMod) {
|
|
130
|
+
// Last-ditch attempts on known ids
|
|
131
|
+
try {
|
|
132
|
+
chosenMod = req && typeof req === 'function' ? req('nativescript-vue') : null;
|
|
133
|
+
}
|
|
134
|
+
catch { }
|
|
135
|
+
if (!chosenMod) {
|
|
136
|
+
try {
|
|
137
|
+
chosenMod = req && typeof req === 'function' ? req('vue') : null;
|
|
138
|
+
}
|
|
139
|
+
catch { }
|
|
140
|
+
}
|
|
141
|
+
if (!chosenMod)
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!vueMod) {
|
|
145
|
+
// Last-ditch attempts on known ids
|
|
146
|
+
try {
|
|
147
|
+
vueMod = req && typeof req === 'function' ? req('vue') : null;
|
|
148
|
+
}
|
|
149
|
+
catch { }
|
|
150
|
+
if (!vueMod) {
|
|
151
|
+
try {
|
|
152
|
+
vueMod = req && typeof req === 'function' ? req('nativescript-vue') : null;
|
|
153
|
+
}
|
|
154
|
+
catch { }
|
|
155
|
+
}
|
|
156
|
+
if (!vueMod)
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// Polyfill essential runtime helpers often imported from 'vue' by compiled SFC render code
|
|
160
|
+
try {
|
|
161
|
+
const polyNormalizeClass = (val) => {
|
|
162
|
+
if (!val)
|
|
163
|
+
return '';
|
|
164
|
+
if (typeof val === 'string')
|
|
165
|
+
return val;
|
|
166
|
+
if (Array.isArray(val))
|
|
167
|
+
return val.map(polyNormalizeClass).filter(Boolean).join(' ');
|
|
168
|
+
if (typeof val === 'object')
|
|
169
|
+
return Object.keys(val)
|
|
170
|
+
.filter((k) => !!val[k])
|
|
171
|
+
.join(' ');
|
|
172
|
+
return '';
|
|
173
|
+
};
|
|
174
|
+
const polyNormalizeStyle = (val) => {
|
|
175
|
+
if (!val)
|
|
176
|
+
return null;
|
|
177
|
+
if (Array.isArray(val))
|
|
178
|
+
return val.reduce((acc, v) => Object.assign(acc, polyNormalizeStyle(v) || {}), {});
|
|
179
|
+
if (typeof val === 'string') {
|
|
180
|
+
const out = {};
|
|
181
|
+
val.split(';').forEach((pair) => {
|
|
182
|
+
const idx = pair.indexOf(':');
|
|
183
|
+
if (idx > -1) {
|
|
184
|
+
const k = pair.slice(0, idx).trim();
|
|
185
|
+
const v = pair.slice(idx + 1).trim();
|
|
186
|
+
if (k)
|
|
187
|
+
out[k] = v;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
if (typeof val === 'object')
|
|
193
|
+
return { ...val };
|
|
194
|
+
return null;
|
|
195
|
+
};
|
|
196
|
+
const polyToDisplayString = (val) => {
|
|
197
|
+
try {
|
|
198
|
+
if (val == null)
|
|
199
|
+
return '';
|
|
200
|
+
if (typeof val === 'object')
|
|
201
|
+
return JSON.stringify(val);
|
|
202
|
+
return String(val);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return String(val);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const vmAny = vueMod;
|
|
209
|
+
if (vmAny && typeof vmAny === 'object') {
|
|
210
|
+
if (!('normalizeClass' in vmAny))
|
|
211
|
+
vmAny.normalizeClass = polyNormalizeClass;
|
|
212
|
+
if (!('normalizeStyle' in vmAny))
|
|
213
|
+
vmAny.normalizeStyle = polyNormalizeStyle;
|
|
214
|
+
if (!('toDisplayString' in vmAny))
|
|
215
|
+
vmAny.toDisplayString = polyToDisplayString;
|
|
216
|
+
}
|
|
217
|
+
// Do not assign polyfills onto globalThis; compiled helpers are wired via alias() below
|
|
218
|
+
}
|
|
219
|
+
catch { }
|
|
220
|
+
const runtime = (chosenMod && (chosenMod.default ?? chosenMod)) || chosenMod;
|
|
221
|
+
const { defineComponent, resolveComponent, createVNode, createTextVNode, createCommentVNode,
|
|
222
|
+
// We deliberately pull createApp here but assign it globally below to avoid mixing module instances
|
|
223
|
+
createApp: _createApp, Fragment, withCtx, openBlock, createBlock, createElementVNode, createElementBlock, renderSlot, mergeProps, toHandlers, renderList, normalizeProps, guardReactiveProps, withDirectives, resolveDirective, withModifiers, withKeys, isRef, ref, shallowRef, unref, computed, onMounted, onBeforeUnmount, onUnmounted, watch, nextTick, vShow, } = (runtime || {});
|
|
224
|
+
// Assign only if not already set to avoid clobbering potentially patched versions.
|
|
225
|
+
if (!vueAlready) {
|
|
226
|
+
g.defineComponent || (g.defineComponent = defineComponent);
|
|
227
|
+
g.resolveComponent || (g.resolveComponent = resolveComponent);
|
|
228
|
+
g.createVNode || (g.createVNode = createVNode);
|
|
229
|
+
g.createTextVNode || (g.createTextVNode = createTextVNode);
|
|
230
|
+
g.createCommentVNode || (g.createCommentVNode = createCommentVNode);
|
|
231
|
+
g.Fragment || (g.Fragment = Fragment);
|
|
232
|
+
// Critical: ensure createApp and runtime-bound classes/functions reference the same module instance
|
|
233
|
+
try {
|
|
234
|
+
g.createApp || (g.createApp = _createApp || runtime?.createApp || nvMod?.createApp || vueMod?.createApp);
|
|
235
|
+
}
|
|
236
|
+
catch { }
|
|
237
|
+
try {
|
|
238
|
+
g.NSVRoot || (g.NSVRoot = runtime?.NSVRoot || nvMod?.NSVRoot || vueMod?.NSVRoot);
|
|
239
|
+
}
|
|
240
|
+
catch { }
|
|
241
|
+
try {
|
|
242
|
+
g.registerElement || (g.registerElement = runtime?.registerElement || nvMod?.registerElement || vueMod?.registerElement);
|
|
243
|
+
}
|
|
244
|
+
catch { }
|
|
245
|
+
try {
|
|
246
|
+
g.start || (g.start = runtime?.start || nvMod?.start || vueMod?.start);
|
|
247
|
+
}
|
|
248
|
+
catch { }
|
|
249
|
+
g.withCtx || (g.withCtx = withCtx);
|
|
250
|
+
g.openBlock || (g.openBlock = openBlock);
|
|
251
|
+
g.createBlock || (g.createBlock = createBlock);
|
|
252
|
+
g.createElementVNode || (g.createElementVNode = createElementVNode || createVNode);
|
|
253
|
+
g.createElementBlock || (g.createElementBlock = createElementBlock || createBlock);
|
|
254
|
+
g.renderSlot || (g.renderSlot = renderSlot);
|
|
255
|
+
g.mergeProps || (g.mergeProps = mergeProps);
|
|
256
|
+
g.toHandlers || (g.toHandlers = toHandlers);
|
|
257
|
+
g.renderList || (g.renderList = renderList);
|
|
258
|
+
g.normalizeProps || (g.normalizeProps = normalizeProps);
|
|
259
|
+
g.guardReactiveProps || (g.guardReactiveProps = guardReactiveProps);
|
|
260
|
+
g.withDirectives || (g.withDirectives = withDirectives);
|
|
261
|
+
g.resolveDirective || (g.resolveDirective = resolveDirective);
|
|
262
|
+
g.withModifiers || (g.withModifiers = withModifiers);
|
|
263
|
+
g.withKeys || (g.withKeys = withKeys);
|
|
264
|
+
g.isRef || (g.isRef = isRef);
|
|
265
|
+
g.ref || (g.ref = ref);
|
|
266
|
+
g.shallowRef || (g.shallowRef = shallowRef);
|
|
267
|
+
g.unref || (g.unref = unref);
|
|
268
|
+
g.computed || (g.computed = computed);
|
|
269
|
+
g.onMounted || (g.onMounted = onMounted);
|
|
270
|
+
g.onBeforeUnmount || (g.onBeforeUnmount = onBeforeUnmount);
|
|
271
|
+
g.onUnmounted || (g.onUnmounted = onUnmounted);
|
|
272
|
+
g.watch || (g.watch = watch);
|
|
273
|
+
g.nextTick || (g.nextTick = nextTick);
|
|
274
|
+
// Built-in directives
|
|
275
|
+
g.vShow || (g.vShow = vShow);
|
|
276
|
+
// Create underscore aliases to satisfy compiled helper identifiers (e.g. _renderSlot)
|
|
277
|
+
try {
|
|
278
|
+
const alias = (from, to) => {
|
|
279
|
+
try {
|
|
280
|
+
const val = g[from];
|
|
281
|
+
const key = to || '_' + from;
|
|
282
|
+
if (val && !(key in g))
|
|
283
|
+
g[key] = val;
|
|
284
|
+
}
|
|
285
|
+
catch { }
|
|
286
|
+
};
|
|
287
|
+
alias('renderSlot');
|
|
288
|
+
alias('normalizeClass');
|
|
289
|
+
alias('normalizeStyle');
|
|
290
|
+
alias('toDisplayString');
|
|
291
|
+
alias('openBlock');
|
|
292
|
+
alias('createElementBlock');
|
|
293
|
+
alias('createElementVNode');
|
|
294
|
+
alias('createVNode');
|
|
295
|
+
alias('createBlock');
|
|
296
|
+
alias('normalizeProps');
|
|
297
|
+
alias('guardReactiveProps');
|
|
298
|
+
alias('mergeProps');
|
|
299
|
+
alias('toHandlers');
|
|
300
|
+
alias('withCtx');
|
|
301
|
+
alias('withDirectives');
|
|
302
|
+
alias('resolveComponent');
|
|
303
|
+
alias('resolveDirective');
|
|
304
|
+
alias('withModifiers');
|
|
305
|
+
alias('withKeys');
|
|
306
|
+
alias('isRef');
|
|
307
|
+
alias('unref');
|
|
308
|
+
alias('vShow');
|
|
309
|
+
alias('Fragment', '_Fragment');
|
|
310
|
+
}
|
|
311
|
+
catch { }
|
|
312
|
+
}
|
|
313
|
+
// Navigation helpers: no longer patched onto globalThis; use __nsNavigateUsingApp via imports or app instance
|
|
314
|
+
// If Vue was already present originally we still ensure nav helpers; that's why we delayed early return.
|
|
315
|
+
}
|
|
316
|
+
catch { }
|
|
317
|
+
}
|
|
318
|
+
// Ensure Pinia is installed on the given Vue app during HMR remounts.
|
|
319
|
+
// We keep a singleton Pinia instance on globalThis to preserve store state across resets when possible.
|
|
320
|
+
export function ensurePiniaOnApp(app) {
|
|
321
|
+
try {
|
|
322
|
+
if (!app || typeof app.use !== 'function')
|
|
323
|
+
return;
|
|
324
|
+
const g = globalThis;
|
|
325
|
+
// If this app already has a Pinia provide, skip
|
|
326
|
+
try {
|
|
327
|
+
const prov = app?._context?.provides;
|
|
328
|
+
if (prov) {
|
|
329
|
+
const hasString = Object.prototype.hasOwnProperty.call(prov, 'pinia');
|
|
330
|
+
const knownSym = g.__NS_PINIA_SYMBOL__;
|
|
331
|
+
const hasKnownSym = knownSym ? Object.prototype.hasOwnProperty.call(prov, knownSym) : false;
|
|
332
|
+
const hasSym = hasKnownSym || Object.getOwnPropertySymbols(prov).some((s) => /pinia/i.test(s.description || ''));
|
|
333
|
+
if (hasString || hasSym)
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch { }
|
|
338
|
+
// If a global Pinia instance is already present, just use it and avoid importing new copies
|
|
339
|
+
if (g.__NS_HMR_PINIA__) {
|
|
340
|
+
try {
|
|
341
|
+
app.use(g.__NS_HMR_PINIA__);
|
|
342
|
+
}
|
|
343
|
+
catch { }
|
|
344
|
+
// Attempt to set active pinia if API is available
|
|
345
|
+
try {
|
|
346
|
+
const registry = g.__nsVendorRegistry;
|
|
347
|
+
const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
348
|
+
let piniaMod = null;
|
|
349
|
+
if (registry && registry.has('pinia'))
|
|
350
|
+
piniaMod = registry.get('pinia');
|
|
351
|
+
if (!piniaMod && typeof req === 'function') {
|
|
352
|
+
try {
|
|
353
|
+
piniaMod = req('pinia');
|
|
354
|
+
}
|
|
355
|
+
catch { }
|
|
356
|
+
}
|
|
357
|
+
const resolved = (piniaMod && (piniaMod.default ?? piniaMod)) || null;
|
|
358
|
+
const setActivePinia = resolved?.setActivePinia;
|
|
359
|
+
if (typeof setActivePinia === 'function')
|
|
360
|
+
setActivePinia(g.__NS_HMR_PINIA__);
|
|
361
|
+
}
|
|
362
|
+
catch { }
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
// Prefer vendor registry/require to load 'pinia'
|
|
366
|
+
const registry = g.__nsVendorRegistry;
|
|
367
|
+
const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
368
|
+
let piniaMod = null;
|
|
369
|
+
if (registry && registry.has('pinia')) {
|
|
370
|
+
piniaMod = registry.get('pinia');
|
|
371
|
+
}
|
|
372
|
+
if (!piniaMod && typeof req === 'function') {
|
|
373
|
+
try {
|
|
374
|
+
piniaMod = req('pinia');
|
|
375
|
+
}
|
|
376
|
+
catch { }
|
|
377
|
+
}
|
|
378
|
+
if (!piniaMod)
|
|
379
|
+
return;
|
|
380
|
+
const resolved = (piniaMod && (piniaMod.default ?? piniaMod)) || null;
|
|
381
|
+
const createPinia = resolved?.createPinia;
|
|
382
|
+
const setActivePinia = resolved?.setActivePinia;
|
|
383
|
+
if (typeof createPinia !== 'function')
|
|
384
|
+
return;
|
|
385
|
+
// Reuse across HMR cycles
|
|
386
|
+
const pinia = (g.__NS_HMR_PINIA__ || (g.__NS_HMR_PINIA__ = createPinia()));
|
|
387
|
+
try {
|
|
388
|
+
app.use(pinia);
|
|
389
|
+
}
|
|
390
|
+
catch { }
|
|
391
|
+
try {
|
|
392
|
+
if (typeof setActivePinia === 'function')
|
|
393
|
+
setActivePinia(pinia);
|
|
394
|
+
}
|
|
395
|
+
catch { }
|
|
396
|
+
}
|
|
397
|
+
catch { }
|
|
398
|
+
}
|
|
399
|
+
// Prefer nativescript-vue's own bootstrap to set up element registry and built-ins
|
|
400
|
+
export function ensureNsVueBootstrap() {
|
|
401
|
+
try {
|
|
402
|
+
const g = globalThis;
|
|
403
|
+
if (nsVueInitDone)
|
|
404
|
+
return;
|
|
405
|
+
const reg = g.__nsVendorRegistry;
|
|
406
|
+
const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
407
|
+
if (typeof req !== 'function')
|
|
408
|
+
return;
|
|
409
|
+
// Try full init, which should register core elements and built-in components
|
|
410
|
+
try {
|
|
411
|
+
const nv = req('nativescript-vue/dist/nativescript');
|
|
412
|
+
const init = (nv && (nv.init || nv.default?.init)) || undefined;
|
|
413
|
+
if (typeof init === 'function') {
|
|
414
|
+
init();
|
|
415
|
+
nsVueInitDone = true;
|
|
416
|
+
if (__NS_ENV_VERBOSE__)
|
|
417
|
+
console.log('[hmr-client] nativescript-vue init() executed');
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
catch { }
|
|
422
|
+
// Fallback: register core elements only
|
|
423
|
+
try {
|
|
424
|
+
const elems = req('nativescript-vue/dist/nativescript/elements');
|
|
425
|
+
const fn = (elems && (elems.registerCoreElements || elems.default?.registerCoreElements)) || undefined;
|
|
426
|
+
if (typeof fn === 'function') {
|
|
427
|
+
fn();
|
|
428
|
+
if (__NS_ENV_VERBOSE__)
|
|
429
|
+
console.log('[hmr-client] registerCoreElements executed');
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch { }
|
|
433
|
+
}
|
|
434
|
+
catch { }
|
|
435
|
+
}
|
|
436
|
+
// Install built-in components from nativescript-vue onto the given app (idempotent)
|
|
437
|
+
function installBuiltInComponentsOnApp(app) {
|
|
438
|
+
try {
|
|
439
|
+
if (!app || typeof app.component !== 'function')
|
|
440
|
+
return;
|
|
441
|
+
const g = globalThis;
|
|
442
|
+
const reg = g.__nsVendorRegistry;
|
|
443
|
+
const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
444
|
+
if (typeof req !== 'function')
|
|
445
|
+
return;
|
|
446
|
+
const comps = (() => {
|
|
447
|
+
try {
|
|
448
|
+
return req('nativescript-vue/dist/components');
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
})();
|
|
454
|
+
const built = comps && (comps.BUILT_IN_COMPONENTS || comps.default?.BUILT_IN_COMPONENTS);
|
|
455
|
+
if (!built || typeof built !== 'object')
|
|
456
|
+
return;
|
|
457
|
+
const ctx = app._context;
|
|
458
|
+
const registered = new Set(Object.keys((ctx && ctx.components) || {}));
|
|
459
|
+
for (const [name, def] of Object.entries(built)) {
|
|
460
|
+
try {
|
|
461
|
+
if (!registered.has(name)) {
|
|
462
|
+
app.component(name, def);
|
|
463
|
+
registered.add(name);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
catch { }
|
|
467
|
+
}
|
|
468
|
+
if (__NS_ENV_VERBOSE__) {
|
|
469
|
+
console.log('[hmr-client] installed built-in components:', Array.from(registered).join(','));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
catch { }
|
|
473
|
+
}
|
|
474
|
+
// Ensure the Pinia instance is also active in the HTTP ESM module world and that we provide
|
|
475
|
+
// the exact piniaSymbol exported by that module, so getActivePinia() and inject() both succeed
|
|
476
|
+
// regardless of which module copy a component imports.
|
|
477
|
+
async function syncPiniaAcrossEsm(app) {
|
|
478
|
+
try {
|
|
479
|
+
const g = globalThis;
|
|
480
|
+
const piniaInst = g.__NS_HMR_PINIA__ || app?._context?.provides?.pinia;
|
|
481
|
+
if (!piniaInst)
|
|
482
|
+
return;
|
|
483
|
+
// Resolve Pinia from ESM world and set active
|
|
484
|
+
let esmUrl = null;
|
|
485
|
+
try {
|
|
486
|
+
esmUrl = await requestModuleFromServer('pinia');
|
|
487
|
+
}
|
|
488
|
+
catch { }
|
|
489
|
+
if (esmUrl) {
|
|
490
|
+
try {
|
|
491
|
+
const mod = await safeDynImport(esmUrl);
|
|
492
|
+
const resolved = (mod && (mod.default ?? mod)) || mod;
|
|
493
|
+
const setActivePinia = resolved?.setActivePinia || mod?.setActivePinia;
|
|
494
|
+
const piniaSymbol = resolved?.piniaSymbol || mod?.piniaSymbol;
|
|
495
|
+
if (typeof setActivePinia === 'function') {
|
|
496
|
+
try {
|
|
497
|
+
setActivePinia(piniaInst);
|
|
498
|
+
}
|
|
499
|
+
catch { }
|
|
500
|
+
}
|
|
501
|
+
if (piniaSymbol && app?._context?.provides && !app._context.provides[piniaSymbol]) {
|
|
502
|
+
try {
|
|
503
|
+
app._context.provides[piniaSymbol] = piniaInst;
|
|
504
|
+
}
|
|
505
|
+
catch { }
|
|
506
|
+
try {
|
|
507
|
+
g.__NS_PINIA_SYMBOL__ = piniaSymbol;
|
|
508
|
+
}
|
|
509
|
+
catch { }
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
catch (e) {
|
|
513
|
+
if (__NS_ENV_VERBOSE__)
|
|
514
|
+
console.warn('[hmr-client] syncPiniaAcrossEsm failed import', e);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
catch { }
|
|
519
|
+
}
|
|
520
|
+
function bridgePiniaProvides(app, existingApp) {
|
|
521
|
+
try {
|
|
522
|
+
const g = globalThis;
|
|
523
|
+
if (!app || !app._context)
|
|
524
|
+
return;
|
|
525
|
+
const newProv = app._context.provides || (app._context.provides = {});
|
|
526
|
+
// Determine pinia instance to bind
|
|
527
|
+
let piniaInst = g.__NS_HMR_PINIA__;
|
|
528
|
+
if (!piniaInst)
|
|
529
|
+
piniaInst = newProv['pinia'];
|
|
530
|
+
if (!piniaInst && existingApp)
|
|
531
|
+
piniaInst = existingApp?._context?.provides?.['pinia'];
|
|
532
|
+
if (!piniaInst && existingApp) {
|
|
533
|
+
const syms = Object.getOwnPropertySymbols(existingApp?._context?.provides || {});
|
|
534
|
+
for (const s of syms) {
|
|
535
|
+
if (/pinia/i.test(s.description || '')) {
|
|
536
|
+
piniaInst = existingApp._context.provides[s];
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (!piniaInst)
|
|
542
|
+
return;
|
|
543
|
+
// Collect candidate symbols to bind
|
|
544
|
+
const candidates = [];
|
|
545
|
+
try {
|
|
546
|
+
const known = g.__NS_PINIA_SYMBOL__;
|
|
547
|
+
if (known && typeof known === 'symbol')
|
|
548
|
+
candidates.push(known);
|
|
549
|
+
}
|
|
550
|
+
catch { }
|
|
551
|
+
try {
|
|
552
|
+
const vendorReg = g.__nsVendorRegistry;
|
|
553
|
+
const req = vendorReg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
554
|
+
let vmod = null;
|
|
555
|
+
if (vendorReg && vendorReg.has('pinia'))
|
|
556
|
+
vmod = vendorReg.get('pinia');
|
|
557
|
+
else if (typeof req === 'function') {
|
|
558
|
+
try {
|
|
559
|
+
vmod = req('pinia');
|
|
560
|
+
}
|
|
561
|
+
catch { }
|
|
562
|
+
}
|
|
563
|
+
const resolved = (vmod && (vmod.default ?? vmod)) || vmod;
|
|
564
|
+
const vendorSym = resolved?.piniaSymbol || vmod?.piniaSymbol;
|
|
565
|
+
if (vendorSym && typeof vendorSym === 'symbol')
|
|
566
|
+
candidates.push(vendorSym);
|
|
567
|
+
// Also set active pinia on vendor module if possible
|
|
568
|
+
const setActivePinia = resolved?.setActivePinia || vmod?.setActivePinia;
|
|
569
|
+
if (typeof setActivePinia === 'function') {
|
|
570
|
+
try {
|
|
571
|
+
setActivePinia(piniaInst);
|
|
572
|
+
}
|
|
573
|
+
catch { }
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
catch { }
|
|
577
|
+
try {
|
|
578
|
+
const oldProv = existingApp?._context?.provides || {};
|
|
579
|
+
const oldSyms = Object.getOwnPropertySymbols(oldProv || {});
|
|
580
|
+
for (const s of oldSyms) {
|
|
581
|
+
if (/pinia/i.test(s.description || ''))
|
|
582
|
+
candidates.push(s);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
catch { }
|
|
586
|
+
// De-duplicate symbols
|
|
587
|
+
const uniq = [];
|
|
588
|
+
for (const s of candidates) {
|
|
589
|
+
if (typeof s === 'symbol' && !uniq.includes(s))
|
|
590
|
+
uniq.push(s);
|
|
591
|
+
}
|
|
592
|
+
// Bind all symbols to the same instance
|
|
593
|
+
for (const s of uniq) {
|
|
594
|
+
try {
|
|
595
|
+
newProv[s] = piniaInst;
|
|
596
|
+
}
|
|
597
|
+
catch { }
|
|
598
|
+
}
|
|
599
|
+
// Also ensure string key for any code that looks up string provides
|
|
600
|
+
try {
|
|
601
|
+
if (!newProv['pinia'])
|
|
602
|
+
newProv['pinia'] = piniaInst;
|
|
603
|
+
}
|
|
604
|
+
catch { }
|
|
605
|
+
try {
|
|
606
|
+
g.__NS_PINIA_SYMBOL__ || (g.__NS_PINIA_SYMBOL__ = uniq[0] || undefined);
|
|
607
|
+
}
|
|
608
|
+
catch { }
|
|
609
|
+
if (__NS_ENV_VERBOSE__) {
|
|
610
|
+
try {
|
|
611
|
+
const syms = Object.getOwnPropertySymbols(newProv).map((s) => s.description || String(s));
|
|
612
|
+
console.log('[hmr-client] bridged pinia provides', {
|
|
613
|
+
stringKey: !!newProv['pinia'],
|
|
614
|
+
symbols: syms,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
catch { }
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
catch { }
|
|
621
|
+
}
|
|
622
|
+
export function handleVueSfcRegistry(msg) {
|
|
623
|
+
try {
|
|
624
|
+
const entries = msg.entries || [];
|
|
625
|
+
// Mapping-only: record presence for quick readiness checks (no disk writes in HTTP mode)
|
|
626
|
+
for (const e of entries) {
|
|
627
|
+
addSfcMapping(e.path, e.fileName);
|
|
628
|
+
}
|
|
629
|
+
if (__NS_ENV_VERBOSE__)
|
|
630
|
+
console.log('[hmr][sfc-registry] entries=', entries.length, 'map size', sfcArtifactMap.size);
|
|
631
|
+
}
|
|
632
|
+
catch (e) {
|
|
633
|
+
console.warn('[hmr-client][sfc-registry] install failed', e);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
export async function handleVueSfcRegistryUpdate(msg, graphVersion) {
|
|
637
|
+
try {
|
|
638
|
+
if (typeof msg.path === 'string' && /\.vue$/i.test(msg.path)) {
|
|
639
|
+
// Gate updates: only remount if this path is actually marked as changed in the current delta
|
|
640
|
+
try {
|
|
641
|
+
const base = String(msg.path).split('?')[0];
|
|
642
|
+
const inChanged = sfcChangedIds.has(base) || sfcChangedIds.has(msg.path);
|
|
643
|
+
const versionsMatch = sfcChangedVersion != null && sfcChangedVersion === graphVersion;
|
|
644
|
+
if (!inChanged || !versionsMatch) {
|
|
645
|
+
// Be resilient to out-of-order delivery: treat the registry update itself
|
|
646
|
+
// as authoritative signal that this SFC changed for the announced version.
|
|
647
|
+
// This unblocks remounts when the delta was dropped or applied earlier than we recorded.
|
|
648
|
+
try {
|
|
649
|
+
const effectiveVersion = typeof msg.version === 'number' ? msg.version : graphVersion;
|
|
650
|
+
sfcChangedVersion = effectiveVersion;
|
|
651
|
+
sfcChangedIds.add(base);
|
|
652
|
+
if (__NS_ENV_VERBOSE__)
|
|
653
|
+
console.log('[hmr][sfc-registry-update] accepting as change (out-of-order)', { path: msg.path, graphVersion, sfcChangedVersion });
|
|
654
|
+
}
|
|
655
|
+
catch { }
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
catch { }
|
|
659
|
+
try {
|
|
660
|
+
ensureVueGlobals();
|
|
661
|
+
const changedPath = String(msg.path);
|
|
662
|
+
// Prefer remounting the SFC that actually changed so you immediately see it
|
|
663
|
+
// (e.g., editing Details.vue should remount Details.vue even if Home.vue is currently displayed).
|
|
664
|
+
// This keeps existing behavior intact when the changed file is already the root.
|
|
665
|
+
const targetPath = changedPath;
|
|
666
|
+
const comp = await loadSfcComponent(targetPath, 'sfc_update');
|
|
667
|
+
return comp;
|
|
668
|
+
}
|
|
669
|
+
catch (e) {
|
|
670
|
+
console.warn('[hmr-client] update path failed for', msg.path, e);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
catch (e) {
|
|
676
|
+
console.warn('[hmr-client][sfc-registry] update failed', e);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
export function recordVuePayloadChanges(changed, graphVersion) {
|
|
680
|
+
// Record .vue changes seen in this delta
|
|
681
|
+
let sawVue = false;
|
|
682
|
+
for (const m of changed) {
|
|
683
|
+
if (m && typeof m.id === 'string' && /\.vue$/i.test(m.id)) {
|
|
684
|
+
sfcChangedIds.add(m.id);
|
|
685
|
+
sawVue = true;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (sawVue)
|
|
689
|
+
sfcChangedVersion = graphVersion;
|
|
690
|
+
}
|
|
691
|
+
async function waitForSfcMapping(id, timeoutMs = 350) {
|
|
692
|
+
if (!/\.vue$/i.test(id))
|
|
693
|
+
return true;
|
|
694
|
+
const base = id.split('?')[0];
|
|
695
|
+
const srcIdx = base.indexOf(APP_VIRTUAL_WITH_SLASH);
|
|
696
|
+
const rel = srcIdx !== -1 ? base.slice(srcIdx) : base;
|
|
697
|
+
if (sfcArtifactMap.has(rel) || sfcArtifactMap.has(base))
|
|
698
|
+
return true;
|
|
699
|
+
const start = Date.now();
|
|
700
|
+
while (Date.now() - start < timeoutMs) {
|
|
701
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
702
|
+
if (sfcArtifactMap.has(rel) || sfcArtifactMap.has(base))
|
|
703
|
+
return true;
|
|
704
|
+
}
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
// Map a graph id (possibly a .vue source path) to actual import spec
|
|
708
|
+
export function addSfcMapping(originalPath, fileName) {
|
|
709
|
+
try {
|
|
710
|
+
if (!originalPath || !fileName)
|
|
711
|
+
return;
|
|
712
|
+
const base = originalPath.split('?')[0];
|
|
713
|
+
const norm = normalizeSpec(base);
|
|
714
|
+
// Also derive a relative variant if under app root to handle lookups that slice to that portion
|
|
715
|
+
let rel = norm;
|
|
716
|
+
const srcIdx = norm.indexOf(APP_VIRTUAL_WITH_SLASH);
|
|
717
|
+
if (srcIdx !== -1)
|
|
718
|
+
rel = norm.slice(srcIdx);
|
|
719
|
+
sfcArtifactMap.set(norm, fileName);
|
|
720
|
+
if (rel !== norm)
|
|
721
|
+
sfcArtifactMap.set(rel, fileName);
|
|
722
|
+
}
|
|
723
|
+
catch { }
|
|
724
|
+
}
|
|
725
|
+
// Build explicit SFC variant URL (script/template). Always preserves the variant query.
|
|
726
|
+
function resolveSfcVariantSpec(id, type, cacheBustTag) {
|
|
727
|
+
const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
|
|
728
|
+
const base = id.split('?')[0];
|
|
729
|
+
if (!origin)
|
|
730
|
+
return base + `?vue&type=${type}`;
|
|
731
|
+
const safePath = base.startsWith('/') ? base : '/' + base;
|
|
732
|
+
const ver = typeof getGraphVersion() === 'number' && getGraphVersion() > 0 ? String(getGraphVersion()) : '0';
|
|
733
|
+
let url = origin + `/ns/sfc/${ver}` + safePath + `?vue&type=${type}`;
|
|
734
|
+
return url;
|
|
735
|
+
}
|
|
736
|
+
// Resolve deterministic SFC assembler ESM module
|
|
737
|
+
function resolveSfcAssemblerSpec(id, cacheBustTag) {
|
|
738
|
+
const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
|
|
739
|
+
const base = id.split('?')[0];
|
|
740
|
+
if (!origin)
|
|
741
|
+
return base; // fallback: device will likely fail; origin should be available in dev
|
|
742
|
+
const safePath = base.startsWith('/') ? base : '/' + base;
|
|
743
|
+
const ver = typeof getGraphVersion() === 'number' && getGraphVersion() > 0 ? String(getGraphVersion()) : '0';
|
|
744
|
+
let url = origin + `/ns/asm/${ver}` + `?path=${encodeURIComponent(safePath)}`;
|
|
745
|
+
try {
|
|
746
|
+
if (globalThis.__NS_HMR_ASM_DIAG__) {
|
|
747
|
+
url += '&diag=1';
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
catch { }
|
|
751
|
+
return url;
|
|
752
|
+
}
|
|
753
|
+
// Resolve metadata endpoint for an SFC
|
|
754
|
+
function resolveSfcMetaSpec(id, cacheBustTag) {
|
|
755
|
+
const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
|
|
756
|
+
const base = id.split('?')[0];
|
|
757
|
+
if (!origin)
|
|
758
|
+
return base;
|
|
759
|
+
const safePath = base.startsWith('/') ? base : '/' + base;
|
|
760
|
+
const ver = typeof getGraphVersion() === 'number' && getGraphVersion() > 0 ? String(getGraphVersion()) : '0';
|
|
761
|
+
let url = origin + `/ns/sfc-meta/${ver}` + `?path=${encodeURIComponent(safePath)}`;
|
|
762
|
+
return url;
|
|
763
|
+
}
|
|
764
|
+
async function fetchSfcMeta(id, tag) {
|
|
765
|
+
try {
|
|
766
|
+
const url = resolveSfcMetaSpec(id, tag + '_meta');
|
|
767
|
+
const res = await fetch(url, { method: 'GET' });
|
|
768
|
+
if (!res.ok)
|
|
769
|
+
return null;
|
|
770
|
+
const json = await res.json();
|
|
771
|
+
return json;
|
|
772
|
+
}
|
|
773
|
+
catch {
|
|
774
|
+
return null;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// Safely load a component for a .vue SFC. Prefer deterministic assembler first to avoid
|
|
778
|
+
// any variant-compile or TDZ flakiness; only fall back to variant assembly if needed.
|
|
779
|
+
export async function loadSfcComponent(targetVuePath, tag) {
|
|
780
|
+
// Minimal mode removed: always go through deterministic assembler + device reset
|
|
781
|
+
// Ensure Vue globals exist BEFORE evaluating variant modules; their top-level aliasing reads globalThis.* once.
|
|
782
|
+
ensureVueGlobals();
|
|
783
|
+
// Consult metadata to choose optimal path
|
|
784
|
+
let meta = null;
|
|
785
|
+
try {
|
|
786
|
+
meta = await fetchSfcMeta(targetVuePath, tag);
|
|
787
|
+
}
|
|
788
|
+
catch { }
|
|
789
|
+
if (__NS_ENV_VERBOSE__ && meta) {
|
|
790
|
+
try {
|
|
791
|
+
console.log('[hmr][vue-reset][meta]', targetVuePath, meta);
|
|
792
|
+
}
|
|
793
|
+
catch { }
|
|
794
|
+
}
|
|
795
|
+
// Prefer deterministic assembler first so AST normalization (including nav helpers) always applies.
|
|
796
|
+
try {
|
|
797
|
+
if (!DISABLE_ASM) {
|
|
798
|
+
const asmMod = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm_first'));
|
|
799
|
+
const asmComp = asmMod?.default ?? asmMod;
|
|
800
|
+
if (asmComp && typeof asmComp === 'object') {
|
|
801
|
+
if (__NS_ENV_VERBOSE__)
|
|
802
|
+
console.log('[hmr][vue-reset][diag] using assembler-first component');
|
|
803
|
+
return asmComp;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
catch (e) {
|
|
808
|
+
if (__NS_ENV_VERBOSE__)
|
|
809
|
+
console.warn('[hmr][vue-reset][diag] assembler-first failed; trying variants', e);
|
|
810
|
+
}
|
|
811
|
+
// 1) Variant assembly (script then template) – closest to browser behavior
|
|
812
|
+
try {
|
|
813
|
+
// Import script variant FIRST to avoid TDZ due to cyclic evaluation between script/template.
|
|
814
|
+
const scriptMod = await safeDynImport(resolveSfcVariantSpec(targetVuePath, 'script', tag + '_script'));
|
|
815
|
+
// Ensure script default is readable before importing the template; this enforces a stable order.
|
|
816
|
+
const base = await safeReadDefault(scriptMod);
|
|
817
|
+
// Now import the template render implementation
|
|
818
|
+
const templateMod = await safeDynImport(resolveSfcVariantSpec(targetVuePath, 'template', tag + '_template'));
|
|
819
|
+
if (__NS_ENV_VERBOSE__) {
|
|
820
|
+
try {
|
|
821
|
+
const sKeys = scriptMod ? Object.keys(scriptMod).join(',') : '<none>';
|
|
822
|
+
const tKeys = templateMod ? Object.keys(templateMod).join(',') : '<none>';
|
|
823
|
+
console.log('[hmr][vue-reset][diag] variant-imports', targetVuePath, 'script.keys=', sKeys, 'template.keys=', tKeys);
|
|
824
|
+
try {
|
|
825
|
+
console.log('[hmr][vue-reset][diag] scriptMod:', scriptMod);
|
|
826
|
+
}
|
|
827
|
+
catch { }
|
|
828
|
+
try {
|
|
829
|
+
console.log('[hmr][vue-reset][diag] templateMod:', {
|
|
830
|
+
render: typeof templateMod?.render,
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
catch { }
|
|
834
|
+
}
|
|
835
|
+
catch { }
|
|
836
|
+
}
|
|
837
|
+
// Only use variant assembly when the script provides a real component options object.
|
|
838
|
+
const render = templateMod?.render;
|
|
839
|
+
const scriptExports = scriptMod || {};
|
|
840
|
+
const exportKeys = Object.keys(scriptExports).filter((k) => k !== 'default' && k !== '__esModule');
|
|
841
|
+
if (base && typeof base === 'object') {
|
|
842
|
+
// If variant template didn't produce a render, try assembler as a targeted fallback.
|
|
843
|
+
if (!render) {
|
|
844
|
+
try {
|
|
845
|
+
if (__NS_ENV_VERBOSE__)
|
|
846
|
+
console.log('[hmr][vue-reset][diag] no render from template variant; attempting assembler for', targetVuePath);
|
|
847
|
+
const asmMod = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm_norender'));
|
|
848
|
+
const asmComp = asmMod?.default ?? asmMod;
|
|
849
|
+
if (asmComp && typeof asmComp === 'object' && typeof asmComp.render === 'function') {
|
|
850
|
+
try {
|
|
851
|
+
base.render = asmComp.render;
|
|
852
|
+
}
|
|
853
|
+
catch { }
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
catch (e) {
|
|
857
|
+
if (__NS_ENV_VERBOSE__)
|
|
858
|
+
console.warn('[hmr][vue-reset][diag] assembler no-render fallback failed', e);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
try {
|
|
863
|
+
base.render = render;
|
|
864
|
+
}
|
|
865
|
+
catch { }
|
|
866
|
+
}
|
|
867
|
+
// Merge named exports (likely locally-declared components) into the component's components map
|
|
868
|
+
if (exportKeys.length) {
|
|
869
|
+
try {
|
|
870
|
+
base.components = base.components || {};
|
|
871
|
+
for (const k of exportKeys) {
|
|
872
|
+
try {
|
|
873
|
+
base.components[k] = scriptExports[k];
|
|
874
|
+
}
|
|
875
|
+
catch { }
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
catch { }
|
|
879
|
+
}
|
|
880
|
+
if (__NS_ENV_VERBOSE__) {
|
|
881
|
+
try {
|
|
882
|
+
console.log('[hmr][vue-reset][diag] assembled.component (from script default) keys=', Object.keys(base).join(','), 'has.render=', !!base.render, 'components=', Object.keys(base.components || {}).join(','));
|
|
883
|
+
}
|
|
884
|
+
catch { }
|
|
885
|
+
}
|
|
886
|
+
return base;
|
|
887
|
+
}
|
|
888
|
+
// If script default is absent (common with <script setup> or named exports), but we have a template render,
|
|
889
|
+
// prefer loading the full SFC first if the script provided no named exports — the full SFC may contain
|
|
890
|
+
// compiled metadata (local components, hoisted helpers) that variant assembly can't reconstruct.
|
|
891
|
+
if (!base && typeof render === 'function') {
|
|
892
|
+
if (!exportKeys.length) {
|
|
893
|
+
if (__NS_ENV_VERBOSE__)
|
|
894
|
+
console.log('[hmr][vue-reset][diag] no script exports detected; attempting assembler import for', targetVuePath);
|
|
895
|
+
try {
|
|
896
|
+
const asm = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm'));
|
|
897
|
+
const compAsm = asm?.default ?? asm;
|
|
898
|
+
if (compAsm && typeof compAsm === 'object') {
|
|
899
|
+
if (__NS_ENV_VERBOSE__)
|
|
900
|
+
console.log('[hmr][vue-reset][diag] assembler import succeeded and will be used');
|
|
901
|
+
return compAsm;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
catch (e) {
|
|
905
|
+
if (__NS_ENV_VERBOSE__)
|
|
906
|
+
console.warn('[hmr][vue-reset][diag] assembler import failed, will synthesize as fallback', e);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
// Synthesize a minimal component and attach named exports as local components so template resolveComponent works.
|
|
910
|
+
try {
|
|
911
|
+
ensureVueGlobals();
|
|
912
|
+
const comp = globalThis.defineComponent
|
|
913
|
+
? globalThis.defineComponent({
|
|
914
|
+
name: targetVuePath.split('/').pop() || 'AnonymousSFC',
|
|
915
|
+
render,
|
|
916
|
+
})
|
|
917
|
+
: {
|
|
918
|
+
name: targetVuePath.split('/').pop() || 'AnonymousSFC',
|
|
919
|
+
render,
|
|
920
|
+
};
|
|
921
|
+
if (exportKeys.length) {
|
|
922
|
+
try {
|
|
923
|
+
comp.components = comp.components || {};
|
|
924
|
+
for (const k of exportKeys) {
|
|
925
|
+
try {
|
|
926
|
+
comp.components[k] = scriptExports[k];
|
|
927
|
+
}
|
|
928
|
+
catch { }
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
catch { }
|
|
932
|
+
}
|
|
933
|
+
if (__NS_ENV_VERBOSE__) {
|
|
934
|
+
try {
|
|
935
|
+
console.log('[hmr][vue-reset][diag] synthesized.component keys=', Object.keys(comp).join(','), 'components=', Object.keys(comp.components || {}).join(','));
|
|
936
|
+
}
|
|
937
|
+
catch { }
|
|
938
|
+
}
|
|
939
|
+
return comp;
|
|
940
|
+
}
|
|
941
|
+
catch (e) {
|
|
942
|
+
if (__NS_ENV_VERBOSE__)
|
|
943
|
+
console.warn('[hmr][vue-reset][diag] synthesize component failed', e);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
// Otherwise fall through to full SFC import.
|
|
947
|
+
}
|
|
948
|
+
catch (e2) {
|
|
949
|
+
if (__NS_ENV_VERBOSE__)
|
|
950
|
+
console.warn('[hmr][vue-reset][variant-import] failed; will try full SFC', targetVuePath, e2);
|
|
951
|
+
}
|
|
952
|
+
// 2) Final fallback: assembler import (after a short delay to let dependents settle)
|
|
953
|
+
try {
|
|
954
|
+
if (DISABLE_ASM)
|
|
955
|
+
throw new Error('asm disabled by __NS_HMR_DISABLE_ASM__');
|
|
956
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
957
|
+
const mod = await safeDynImport(resolveSfcAssemblerSpec(targetVuePath, tag + '_asm_final'));
|
|
958
|
+
try {
|
|
959
|
+
const comp = await safeReadDefault(mod);
|
|
960
|
+
if (comp)
|
|
961
|
+
return comp;
|
|
962
|
+
}
|
|
963
|
+
catch (err) {
|
|
964
|
+
if (__NS_ENV_VERBOSE__)
|
|
965
|
+
console.warn('[hmr][vue-reset][asm-import-default-read] error', targetVuePath, err);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
catch (e) {
|
|
969
|
+
if (__NS_ENV_VERBOSE__)
|
|
970
|
+
console.warn('[hmr][vue-reset][asm-import] failed', targetVuePath, e);
|
|
971
|
+
}
|
|
972
|
+
// Final soft fallback: return a minimal placeholder so rerender can proceed and surface UI
|
|
973
|
+
return null;
|
|
974
|
+
}
|
|
975
|
+
export function getRootForVue(newComponent, state) {
|
|
976
|
+
const t0 = Date.now();
|
|
977
|
+
if (__NS_ENV_VERBOSE__)
|
|
978
|
+
console.log('[hmr-client] [createRoot] begin');
|
|
979
|
+
ensureVueGlobals();
|
|
980
|
+
const g = globalThis;
|
|
981
|
+
const AppFactory = g.createApp;
|
|
982
|
+
let RootCtor = g.NSVRoot;
|
|
983
|
+
// Hygiene: unmount any existing app instance to avoid duplicate lifecycle hooks
|
|
984
|
+
try {
|
|
985
|
+
const existing = (getCurrentApp() || g.__NS_VUE_APP__);
|
|
986
|
+
if (existing && typeof existing.unmount === 'function') {
|
|
987
|
+
if (__NS_ENV_VERBOSE__)
|
|
988
|
+
console.log('[hmr-client] [createRoot] unmounting existing app before remount');
|
|
989
|
+
try {
|
|
990
|
+
existing.unmount();
|
|
991
|
+
}
|
|
992
|
+
catch { }
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
catch { }
|
|
996
|
+
try {
|
|
997
|
+
if (!RootCtor) {
|
|
998
|
+
const registry = g.__nsVendorRegistry;
|
|
999
|
+
const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
1000
|
+
let domMod = null;
|
|
1001
|
+
if (registry && registry.has('nativescript-vue/dist/dom')) {
|
|
1002
|
+
domMod = registry.get('nativescript-vue/dist/dom');
|
|
1003
|
+
if (__NS_ENV_VERBOSE__)
|
|
1004
|
+
console.log('[hmr-client] [createRoot] NS DOM from vendor registry');
|
|
1005
|
+
}
|
|
1006
|
+
else if (typeof req === 'function') {
|
|
1007
|
+
try {
|
|
1008
|
+
domMod = req('nativescript-vue/dist/dom');
|
|
1009
|
+
if (__NS_ENV_VERBOSE__)
|
|
1010
|
+
console.log('[hmr-client] [createRoot] NS DOM via require');
|
|
1011
|
+
}
|
|
1012
|
+
catch (e) {
|
|
1013
|
+
if (__NS_ENV_VERBOSE__)
|
|
1014
|
+
console.warn('[hmr-client] [createRoot] NS DOM require failed', e);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
if (domMod) {
|
|
1018
|
+
const nsDom = (domMod && (domMod.default ?? domMod)) || domMod;
|
|
1019
|
+
const ctor = nsDom?.NSVRoot || (nsDom?.default && nsDom.default.NSVRoot) || domMod?.NSVRoot;
|
|
1020
|
+
if (ctor)
|
|
1021
|
+
RootCtor = ctor;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
catch { }
|
|
1026
|
+
const existingApp = getCurrentApp() || g.__NS_VUE_APP__;
|
|
1027
|
+
try {
|
|
1028
|
+
ensureNsVueBootstrap();
|
|
1029
|
+
if (__NS_ENV_VERBOSE__)
|
|
1030
|
+
console.log('[hmr-client] [createRoot] ensured NS-Vue bootstrap');
|
|
1031
|
+
}
|
|
1032
|
+
catch (e) {
|
|
1033
|
+
if (__NS_ENV_VERBOSE__)
|
|
1034
|
+
console.warn('[hmr-client] [createRoot] ensureNsVueBootstrap failed', e);
|
|
1035
|
+
}
|
|
1036
|
+
try {
|
|
1037
|
+
if (typeof g.start === 'function' && !nsStartDone) {
|
|
1038
|
+
if (__NS_ENV_VERBOSE__)
|
|
1039
|
+
console.log('[hmr-client] [createRoot] invoking global start()');
|
|
1040
|
+
g.start();
|
|
1041
|
+
nsStartDone = true;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
catch (e) {
|
|
1045
|
+
if (__NS_ENV_VERBOSE__)
|
|
1046
|
+
console.warn('[hmr-client] [createRoot] start() failed', e);
|
|
1047
|
+
}
|
|
1048
|
+
if (!RootCtor)
|
|
1049
|
+
throw new Error('NSVRoot constructor unavailable during HMR remount');
|
|
1050
|
+
let app;
|
|
1051
|
+
try {
|
|
1052
|
+
const mk = globalThis.__NS_HMR_CREATE_APP__;
|
|
1053
|
+
if (typeof mk === 'function') {
|
|
1054
|
+
app = mk(newComponent);
|
|
1055
|
+
if (__NS_ENV_VERBOSE__)
|
|
1056
|
+
console.log('[hmr-client] [createRoot] app created via custom factory');
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
catch (e) {
|
|
1060
|
+
if (__NS_ENV_VERBOSE__)
|
|
1061
|
+
console.warn('[hmr-client] [createRoot] custom app factory failed', e);
|
|
1062
|
+
}
|
|
1063
|
+
if (!app) {
|
|
1064
|
+
app = AppFactory(newComponent);
|
|
1065
|
+
if (__NS_ENV_VERBOSE__)
|
|
1066
|
+
console.log('[hmr-client] [createRoot] app created via createApp');
|
|
1067
|
+
}
|
|
1068
|
+
try {
|
|
1069
|
+
const registry = g.__nsVendorRegistry;
|
|
1070
|
+
const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
1071
|
+
let rh = null;
|
|
1072
|
+
if (registry && registry.has('nativescript-vue/dist/runtimeHelpers'))
|
|
1073
|
+
rh = registry.get('nativescript-vue/dist/runtimeHelpers');
|
|
1074
|
+
if (!rh && typeof req === 'function') {
|
|
1075
|
+
try {
|
|
1076
|
+
rh = req('nativescript-vue/dist/runtimeHelpers');
|
|
1077
|
+
}
|
|
1078
|
+
catch { }
|
|
1079
|
+
}
|
|
1080
|
+
const setRootApp = rh && (rh.setRootApp || rh.default?.setRootApp);
|
|
1081
|
+
if (typeof setRootApp === 'function') {
|
|
1082
|
+
setRootApp(app);
|
|
1083
|
+
if (__NS_ENV_VERBOSE__)
|
|
1084
|
+
console.log('[hmr-client] [createRoot] runtimeHelpers.setRootApp applied');
|
|
1085
|
+
}
|
|
1086
|
+
try {
|
|
1087
|
+
let nv = null;
|
|
1088
|
+
if (registry && registry.has('nativescript-vue'))
|
|
1089
|
+
nv = registry.get('nativescript-vue');
|
|
1090
|
+
if (!nv && typeof req === 'function') {
|
|
1091
|
+
try {
|
|
1092
|
+
nv = req('nativescript-vue');
|
|
1093
|
+
}
|
|
1094
|
+
catch { }
|
|
1095
|
+
}
|
|
1096
|
+
const setRootApp2 = nv && (nv.setRootApp || nv.default?.setRootApp);
|
|
1097
|
+
if (typeof setRootApp2 === 'function') {
|
|
1098
|
+
setRootApp2(app);
|
|
1099
|
+
if (__NS_ENV_VERBOSE__)
|
|
1100
|
+
console.log('[hmr-client] [createRoot] nativescript-vue.setRootApp applied');
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
catch { }
|
|
1104
|
+
}
|
|
1105
|
+
catch { }
|
|
1106
|
+
try {
|
|
1107
|
+
const hook = globalThis.__NS_HMR_INSTALL_PLUGINS__;
|
|
1108
|
+
if (typeof hook === 'function') {
|
|
1109
|
+
hook(app);
|
|
1110
|
+
if (__NS_ENV_VERBOSE__)
|
|
1111
|
+
console.log('[hmr-client] [createRoot] plugins installed');
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
catch (e) {
|
|
1115
|
+
if (__NS_ENV_VERBOSE__)
|
|
1116
|
+
console.warn('[hmr-client] [createRoot] plugin install failed', e);
|
|
1117
|
+
}
|
|
1118
|
+
try {
|
|
1119
|
+
ensurePiniaOnApp(app);
|
|
1120
|
+
if (__NS_ENV_VERBOSE__)
|
|
1121
|
+
console.log('[hmr-client] [createRoot] Pinia ensured on app');
|
|
1122
|
+
}
|
|
1123
|
+
catch (e) {
|
|
1124
|
+
if (__NS_ENV_VERBOSE__)
|
|
1125
|
+
console.warn('[hmr-client] [createRoot] ensurePiniaOnApp failed', e);
|
|
1126
|
+
}
|
|
1127
|
+
try {
|
|
1128
|
+
(async () => {
|
|
1129
|
+
try {
|
|
1130
|
+
await syncPiniaAcrossEsm(app);
|
|
1131
|
+
if (__NS_ENV_VERBOSE__)
|
|
1132
|
+
console.log('[hmr-client] [createRoot] Pinia state sync requested');
|
|
1133
|
+
}
|
|
1134
|
+
catch (e) {
|
|
1135
|
+
if (__NS_ENV_VERBOSE__)
|
|
1136
|
+
console.warn('[hmr-client] [createRoot] syncPiniaAcrossEsm failed', e);
|
|
1137
|
+
}
|
|
1138
|
+
})();
|
|
1139
|
+
}
|
|
1140
|
+
catch { }
|
|
1141
|
+
try {
|
|
1142
|
+
bridgePiniaProvides(app, existingApp);
|
|
1143
|
+
if (__NS_ENV_VERBOSE__)
|
|
1144
|
+
console.log('[hmr-client] [createRoot] provides bridged from previous app');
|
|
1145
|
+
}
|
|
1146
|
+
catch (e) {
|
|
1147
|
+
if (__NS_ENV_VERBOSE__)
|
|
1148
|
+
console.warn('[hmr-client] [createRoot] bridgePiniaProvides failed', e);
|
|
1149
|
+
}
|
|
1150
|
+
try {
|
|
1151
|
+
installBuiltInComponentsOnApp(app);
|
|
1152
|
+
if (__NS_ENV_VERBOSE__)
|
|
1153
|
+
console.log('[hmr-client] [createRoot] built-in components installed');
|
|
1154
|
+
}
|
|
1155
|
+
catch (e) {
|
|
1156
|
+
if (__NS_ENV_VERBOSE__)
|
|
1157
|
+
console.warn('[hmr-client] [createRoot] installBuiltInComponentsOnApp failed', e);
|
|
1158
|
+
}
|
|
1159
|
+
const root = new RootCtor();
|
|
1160
|
+
const vm = typeof app.runWithContext === 'function' ? app.runWithContext(() => app.mount(root)) : app.mount(root);
|
|
1161
|
+
setCurrentApp(app);
|
|
1162
|
+
if (__NS_ENV_VERBOSE__) {
|
|
1163
|
+
try {
|
|
1164
|
+
console.log('[hmr-client] [createRoot] mount result', {
|
|
1165
|
+
hasEl: !!vm?.$el,
|
|
1166
|
+
elType: vm?.$el?.constructor?.name,
|
|
1167
|
+
hasNativeView: !!vm?.$el?.nativeView,
|
|
1168
|
+
nativeViewType: vm?.$el?.nativeView?.constructor?.name,
|
|
1169
|
+
elapsedMs: Date.now() - t0,
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
catch { }
|
|
1173
|
+
}
|
|
1174
|
+
const findNativeView = (element) => {
|
|
1175
|
+
if (element?.nativeView)
|
|
1176
|
+
return element.nativeView;
|
|
1177
|
+
const children = element?.childNodes || element?.children || [];
|
|
1178
|
+
for (const child of children) {
|
|
1179
|
+
const res = findNativeView(child);
|
|
1180
|
+
if (res)
|
|
1181
|
+
return res;
|
|
1182
|
+
}
|
|
1183
|
+
return null;
|
|
1184
|
+
};
|
|
1185
|
+
const findFrameNativeView = (element) => {
|
|
1186
|
+
if (!element)
|
|
1187
|
+
return null;
|
|
1188
|
+
const nv = element.nativeView;
|
|
1189
|
+
if (nv) {
|
|
1190
|
+
const ctorName = String(nv?.constructor?.name || '').replace(/^_+/, '');
|
|
1191
|
+
if (ctorName === 'Frame' || /^Frame(\$\d+)?$/.test(ctorName))
|
|
1192
|
+
return nv;
|
|
1193
|
+
}
|
|
1194
|
+
const kids = element?.childNodes || element?.children || [];
|
|
1195
|
+
for (const k of kids) {
|
|
1196
|
+
const res = findFrameNativeView(k);
|
|
1197
|
+
if (res)
|
|
1198
|
+
return res;
|
|
1199
|
+
}
|
|
1200
|
+
return null;
|
|
1201
|
+
};
|
|
1202
|
+
const findPageNativeView = (element) => {
|
|
1203
|
+
if (!element)
|
|
1204
|
+
return null;
|
|
1205
|
+
const nv = element.nativeView;
|
|
1206
|
+
if (nv) {
|
|
1207
|
+
const ctorName = String(nv?.constructor?.name || '').replace(/^_+/, '');
|
|
1208
|
+
if (ctorName === 'Page' || /^Page(\$\d+)?$/.test(ctorName))
|
|
1209
|
+
return nv;
|
|
1210
|
+
}
|
|
1211
|
+
const kids = element?.childNodes || element?.children || [];
|
|
1212
|
+
for (const k of kids) {
|
|
1213
|
+
const res = findPageNativeView(k);
|
|
1214
|
+
if (res)
|
|
1215
|
+
return res;
|
|
1216
|
+
}
|
|
1217
|
+
return null;
|
|
1218
|
+
};
|
|
1219
|
+
// Prefer adopting a Frame if the component produced one. This avoids nesting a Frame inside
|
|
1220
|
+
// the placeholder Frame and ensures a single authoritative Frame for app navigation.
|
|
1221
|
+
const nativeView = findFrameNativeView(vm?.$el) || findPageNativeView(vm?.$el) || findNativeView(vm?.$el);
|
|
1222
|
+
const GPage = getCore('Page');
|
|
1223
|
+
// Decide root type and cache it
|
|
1224
|
+
if (nativeView) {
|
|
1225
|
+
const ctorName = String(nativeView?.constructor?.name || '').replace(/^_+/, '');
|
|
1226
|
+
if (__NS_ENV_VERBOSE__)
|
|
1227
|
+
console.log('[hmr-client] [createRoot] nativeView found', {
|
|
1228
|
+
ctorName,
|
|
1229
|
+
});
|
|
1230
|
+
// Treat Frame as authoritative root regardless of whether it already has a currentPage.
|
|
1231
|
+
// This avoids producing a Frame inside a wrapper Page which can lead to blank content in complex apps.
|
|
1232
|
+
if (ctorName === 'Frame' || /^Frame(\$\d+)?$/.test(ctorName)) {
|
|
1233
|
+
try {
|
|
1234
|
+
attachDiagnosticsToFrame(nativeView);
|
|
1235
|
+
}
|
|
1236
|
+
catch { }
|
|
1237
|
+
if (__NS_ENV_VERBOSE__)
|
|
1238
|
+
console.log('[hmr-client] [createRoot] root kind=frame (adopting component Frame)');
|
|
1239
|
+
state.setRootKind('frame');
|
|
1240
|
+
state.setCachedRoot(nativeView);
|
|
1241
|
+
return state.getCachedRoot();
|
|
1242
|
+
}
|
|
1243
|
+
if (ctorName === 'Page' || /^Page(\$\d+)?$/.test(ctorName)) {
|
|
1244
|
+
if (__NS_ENV_VERBOSE__)
|
|
1245
|
+
console.log('[hmr-client] [createRoot] root kind=page');
|
|
1246
|
+
state.setRootKind('page');
|
|
1247
|
+
state.setCachedRoot(nativeView);
|
|
1248
|
+
return state.getCachedRoot();
|
|
1249
|
+
}
|
|
1250
|
+
// Treat Frame$N as Frame as well
|
|
1251
|
+
if (ctorName === 'Frame_OLD_NEVER_REACHED') {
|
|
1252
|
+
// If a Frame is produced, prefer adopting the Frame as the new root to ensure a single authoritative Frame.
|
|
1253
|
+
// Extracting the Page and navigating a placeholder Frame can split realms and break app-controlled navigation.
|
|
1254
|
+
let pageCandidate = undefined;
|
|
1255
|
+
try {
|
|
1256
|
+
pageCandidate = nativeView.currentPage || nativeView._currentEntry?.resolvedPage;
|
|
1257
|
+
}
|
|
1258
|
+
catch { }
|
|
1259
|
+
if (pageCandidate) {
|
|
1260
|
+
if (__NS_ENV_VERBOSE__)
|
|
1261
|
+
console.log('[hmr-client] [createRoot] Frame root with currentPage detected; adopting Frame as root');
|
|
1262
|
+
state.setRootKind('frame');
|
|
1263
|
+
state.setCachedRoot(nativeView);
|
|
1264
|
+
return state.getCachedRoot();
|
|
1265
|
+
}
|
|
1266
|
+
// No currentPage yet; construct a Page wrapper and mount the component inside it
|
|
1267
|
+
try {
|
|
1268
|
+
if (__NS_ENV_VERBOSE__)
|
|
1269
|
+
console.log('[hmr-client] [createRoot] no currentPage; creating Page wrapper for navigation-first');
|
|
1270
|
+
const registry = globalThis.__nsVendorRegistry;
|
|
1271
|
+
const req = registry?.get ? globalThis.__nsVendorRequire || globalThis.__nsRequire || globalThis.require : globalThis.__nsRequire || globalThis.require;
|
|
1272
|
+
let vueMod = null;
|
|
1273
|
+
if (registry && registry.has('vue'))
|
|
1274
|
+
vueMod = registry.get('vue');
|
|
1275
|
+
if (!vueMod && typeof req === 'function') {
|
|
1276
|
+
try {
|
|
1277
|
+
vueMod = req('vue');
|
|
1278
|
+
}
|
|
1279
|
+
catch { }
|
|
1280
|
+
}
|
|
1281
|
+
const h = vueMod?.h;
|
|
1282
|
+
const WrappedRoot = h
|
|
1283
|
+
? {
|
|
1284
|
+
name: 'HMRPageWrapper',
|
|
1285
|
+
setup() {
|
|
1286
|
+
return () => h('Page', null, [h(newComponent)]);
|
|
1287
|
+
},
|
|
1288
|
+
}
|
|
1289
|
+
: null;
|
|
1290
|
+
if (WrappedRoot) {
|
|
1291
|
+
const g = globalThis;
|
|
1292
|
+
const AppFactory = g.createApp;
|
|
1293
|
+
let app2 = AppFactory(WrappedRoot);
|
|
1294
|
+
try {
|
|
1295
|
+
const reg2 = g.__nsVendorRegistry;
|
|
1296
|
+
const req2 = reg2?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
|
|
1297
|
+
let rh2 = null;
|
|
1298
|
+
if (reg2 && reg2.has('nativescript-vue/dist/runtimeHelpers'))
|
|
1299
|
+
rh2 = reg2.get('nativescript-vue/dist/runtimeHelpers');
|
|
1300
|
+
if (!rh2 && typeof req2 === 'function') {
|
|
1301
|
+
try {
|
|
1302
|
+
rh2 = req2('nativescript-vue/dist/runtimeHelpers');
|
|
1303
|
+
}
|
|
1304
|
+
catch { }
|
|
1305
|
+
}
|
|
1306
|
+
const setRootApp2a = rh2 && (rh2.setRootApp || rh2.default?.setRootApp);
|
|
1307
|
+
if (typeof setRootApp2a === 'function')
|
|
1308
|
+
setRootApp2a(app2);
|
|
1309
|
+
try {
|
|
1310
|
+
let nv2 = null;
|
|
1311
|
+
if (reg2 && reg2.has('nativescript-vue'))
|
|
1312
|
+
nv2 = reg2.get('nativescript-vue');
|
|
1313
|
+
if (!nv2 && typeof req2 === 'function') {
|
|
1314
|
+
try {
|
|
1315
|
+
nv2 = req2('nativescript-vue');
|
|
1316
|
+
}
|
|
1317
|
+
catch { }
|
|
1318
|
+
}
|
|
1319
|
+
const setRootApp2b = nv2 && (nv2.setRootApp || nv2.default?.setRootApp);
|
|
1320
|
+
if (typeof setRootApp2b === 'function')
|
|
1321
|
+
setRootApp2b(app2);
|
|
1322
|
+
}
|
|
1323
|
+
catch { }
|
|
1324
|
+
}
|
|
1325
|
+
catch { }
|
|
1326
|
+
try {
|
|
1327
|
+
const hook = globalThis.__NS_HMR_INSTALL_PLUGINS__;
|
|
1328
|
+
if (typeof hook === 'function')
|
|
1329
|
+
hook(app2);
|
|
1330
|
+
}
|
|
1331
|
+
catch { }
|
|
1332
|
+
try {
|
|
1333
|
+
ensurePiniaOnApp(app2);
|
|
1334
|
+
}
|
|
1335
|
+
catch { }
|
|
1336
|
+
try {
|
|
1337
|
+
bridgePiniaProvides(app2, getCurrentApp() || globalThis.__NS_VUE_APP__);
|
|
1338
|
+
}
|
|
1339
|
+
catch { }
|
|
1340
|
+
try {
|
|
1341
|
+
installBuiltInComponentsOnApp(app2);
|
|
1342
|
+
}
|
|
1343
|
+
catch { }
|
|
1344
|
+
const RootCtor2 = globalThis.NSVRoot || RootCtor;
|
|
1345
|
+
const root2 = new RootCtor2();
|
|
1346
|
+
const vm2 = typeof app2.runWithContext === 'function' ? app2.runWithContext(() => app2.mount(root2)) : app2.mount(root2);
|
|
1347
|
+
setCurrentApp(app2);
|
|
1348
|
+
const findNativeView2 = (element) => {
|
|
1349
|
+
if (element?.nativeView)
|
|
1350
|
+
return element.nativeView;
|
|
1351
|
+
const kids = element?.childNodes || element?.children || [];
|
|
1352
|
+
for (const c of kids) {
|
|
1353
|
+
const r = findNativeView2(c);
|
|
1354
|
+
if (r)
|
|
1355
|
+
return r;
|
|
1356
|
+
}
|
|
1357
|
+
return null;
|
|
1358
|
+
};
|
|
1359
|
+
const findPageNativeView2 = (element) => {
|
|
1360
|
+
if (!element)
|
|
1361
|
+
return null;
|
|
1362
|
+
const nv = element.nativeView;
|
|
1363
|
+
if (nv) {
|
|
1364
|
+
const ctorName = String(nv?.constructor?.name || '').replace(/^_+/, '');
|
|
1365
|
+
if (ctorName === 'Page' || /^Page(\$\d+)?$/.test(ctorName))
|
|
1366
|
+
return nv;
|
|
1367
|
+
}
|
|
1368
|
+
const kids = element?.childNodes || element?.children || [];
|
|
1369
|
+
for (const k of kids) {
|
|
1370
|
+
const r = findPageNativeView2(k);
|
|
1371
|
+
if (r)
|
|
1372
|
+
return r;
|
|
1373
|
+
}
|
|
1374
|
+
return null;
|
|
1375
|
+
};
|
|
1376
|
+
const nv2 = findPageNativeView2(vm2?.$el) || findNativeView2(vm2?.$el);
|
|
1377
|
+
const ctor2 = String(nv2?.constructor?.name || '').replace(/^_+/, '');
|
|
1378
|
+
if (ctor2 === 'Page' || /^Page(\$\d+)?$/.test(ctor2)) {
|
|
1379
|
+
// Hide wrapper ActionBar to avoid double bars when a Frame is nested inside
|
|
1380
|
+
try {
|
|
1381
|
+
nv2.actionBarHidden = true;
|
|
1382
|
+
}
|
|
1383
|
+
catch { }
|
|
1384
|
+
if (__NS_ENV_VERBOSE__)
|
|
1385
|
+
console.log('[hmr-client] [createRoot] Page wrapper created successfully');
|
|
1386
|
+
state.setRootKind('page');
|
|
1387
|
+
state.setCachedRoot(nv2);
|
|
1388
|
+
return state.getCachedRoot();
|
|
1389
|
+
}
|
|
1390
|
+
if (__NS_ENV_VERBOSE__)
|
|
1391
|
+
console.warn('[hmr-client] [createRoot] Page wrapper did not yield Page; got', ctor2);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
catch (e) {
|
|
1395
|
+
if (__NS_ENV_VERBOSE__)
|
|
1396
|
+
console.warn('[hmr-client] [createRoot] Page wrapper attempt failed', e);
|
|
1397
|
+
}
|
|
1398
|
+
if (__NS_ENV_VERBOSE__)
|
|
1399
|
+
console.log('[hmr-client] [createRoot] root kind=frame (no currentPage)');
|
|
1400
|
+
state.setRootKind('frame');
|
|
1401
|
+
state.setCachedRoot(nativeView);
|
|
1402
|
+
return state.getCachedRoot();
|
|
1403
|
+
}
|
|
1404
|
+
if (GPage) {
|
|
1405
|
+
const page = new GPage();
|
|
1406
|
+
page.content = nativeView;
|
|
1407
|
+
// If we're wrapping a view inside a Page purely to drive navigation,
|
|
1408
|
+
// hide the default ActionBar to avoid duplicate bars.
|
|
1409
|
+
try {
|
|
1410
|
+
page.actionBarHidden = true;
|
|
1411
|
+
}
|
|
1412
|
+
catch { }
|
|
1413
|
+
if (__NS_ENV_VERBOSE__)
|
|
1414
|
+
console.log('[hmr-client] [createRoot] wrapped nativeView in Page (root kind=page)');
|
|
1415
|
+
state.setRootKind('page');
|
|
1416
|
+
state.setCachedRoot(page);
|
|
1417
|
+
return state.getCachedRoot();
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
// fallback page
|
|
1421
|
+
if (GPage) {
|
|
1422
|
+
if (__NS_ENV_VERBOSE__)
|
|
1423
|
+
console.log('[hmr-client] [createRoot] fallback empty Page');
|
|
1424
|
+
state.setRootKind('page');
|
|
1425
|
+
state.setCachedRoot(new GPage());
|
|
1426
|
+
return state.getCachedRoot();
|
|
1427
|
+
}
|
|
1428
|
+
state.setRootKind('page');
|
|
1429
|
+
state.setCachedRoot({});
|
|
1430
|
+
return state.getCachedRoot();
|
|
1431
|
+
}
|
|
1432
|
+
/** Install a robust $navigateBack wrapper once that falls back to remounting the
|
|
1433
|
+
* original root component if there's no usable Frame history. This keeps dev UX
|
|
1434
|
+
* predictable when testing deep links or isolated component mounts.
|
|
1435
|
+
*/
|
|
1436
|
+
export function ensureBackWrapperInstalled(performResetRoot, getCore) {
|
|
1437
|
+
try {
|
|
1438
|
+
const g = globalThis;
|
|
1439
|
+
// Provide global back-remount hooks for bridges to call
|
|
1440
|
+
if (!g.__nsAttemptBackRemount) {
|
|
1441
|
+
g.__nsAttemptBackRemount = () => {
|
|
1442
|
+
try {
|
|
1443
|
+
const orig = g.__NS_HMR_ORIG_ROOT_COMPONENT__ || ORIG_ROOT_COMPONENT;
|
|
1444
|
+
if (orig) {
|
|
1445
|
+
performResetRoot(orig);
|
|
1446
|
+
return true;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
catch { }
|
|
1450
|
+
return false;
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
if (!g.__NS_HMR_ON_NAVIGATE_BACK) {
|
|
1454
|
+
g.__NS_HMR_ON_NAVIGATE_BACK = () => {
|
|
1455
|
+
try {
|
|
1456
|
+
g.__nsAttemptBackRemount && g.__nsAttemptBackRemount();
|
|
1457
|
+
}
|
|
1458
|
+
catch { }
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
if (g.__NS_HMR_BACK_WRAPPED__)
|
|
1462
|
+
return;
|
|
1463
|
+
const originalBack = g.$navigateBack;
|
|
1464
|
+
// Mark wrapped before assigning to avoid re-entrancy races
|
|
1465
|
+
g.__NS_HMR_BACK_WRAPPED__ = true;
|
|
1466
|
+
g.$navigateBack = (...args) => {
|
|
1467
|
+
try {
|
|
1468
|
+
const F = getCore('Frame');
|
|
1469
|
+
const top = F?.topmost?.();
|
|
1470
|
+
if (top && top.canGoBack?.()) {
|
|
1471
|
+
if (typeof originalBack === 'function')
|
|
1472
|
+
return originalBack(...args);
|
|
1473
|
+
// If originalBack is not a function, try Frame fallback
|
|
1474
|
+
try {
|
|
1475
|
+
return top.goBack?.();
|
|
1476
|
+
}
|
|
1477
|
+
catch { }
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
catch (e) {
|
|
1482
|
+
// fall through to fallback
|
|
1483
|
+
}
|
|
1484
|
+
// Fallback: reset to original root component if available
|
|
1485
|
+
const orig = g.__NS_HMR_ORIG_ROOT_COMPONENT__ || ORIG_ROOT_COMPONENT;
|
|
1486
|
+
if (orig) {
|
|
1487
|
+
try {
|
|
1488
|
+
// Reuse the proven remount pipeline for consistency
|
|
1489
|
+
performResetRoot(orig);
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
catch (e) {
|
|
1493
|
+
console.warn('[hmr-client] Fallback back nav failed:', e);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
console.warn('[hmr-client] No usable Frame and no original root component available; cannot navigate back.');
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
catch { }
|
|
1500
|
+
}
|
|
1501
|
+
async function requestModuleFromServer(name) {
|
|
1502
|
+
try {
|
|
1503
|
+
// Derive the dev-server origin (mirrors other resolver helpers in this file)
|
|
1504
|
+
const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
|
|
1505
|
+
if (!origin)
|
|
1506
|
+
return null;
|
|
1507
|
+
// Candidate URL patterns that a Vite-like server might expose for resolving modules to importable URLs.
|
|
1508
|
+
const candidates = [
|
|
1509
|
+
// Vite serves bare imports under /@modules/<name>
|
|
1510
|
+
`${origin.replace(/\/$/, '')}/@modules/${encodeURIComponent(name)}`,
|
|
1511
|
+
// Some setups use @id for resolved module ids
|
|
1512
|
+
`${origin.replace(/\/$/, '')}/@id/${encodeURIComponent(name)}`,
|
|
1513
|
+
// Custom-ish endpoint pattern used elsewhere in this project style
|
|
1514
|
+
`${origin.replace(/\/$/, '')}/ns/esmmod?name=${encodeURIComponent(name)}`,
|
|
1515
|
+
];
|
|
1516
|
+
// Probe each candidate with a lightweight HEAD request first; if allowed, return the candidate URL.
|
|
1517
|
+
for (const url of candidates) {
|
|
1518
|
+
try {
|
|
1519
|
+
const res = await fetch(url, { method: 'HEAD' });
|
|
1520
|
+
if (res && (res.ok || res.status === 200))
|
|
1521
|
+
return url;
|
|
1522
|
+
}
|
|
1523
|
+
catch {
|
|
1524
|
+
// ignore and try next
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
// As a final attempt, try GET on the first candidate and return if we get a module-like response.
|
|
1528
|
+
try {
|
|
1529
|
+
const url = candidates[0];
|
|
1530
|
+
const res = await fetch(url, { method: 'GET' });
|
|
1531
|
+
if (res && res.ok)
|
|
1532
|
+
return url;
|
|
1533
|
+
}
|
|
1534
|
+
catch { }
|
|
1535
|
+
return null;
|
|
1536
|
+
}
|
|
1537
|
+
catch {
|
|
1538
|
+
return null;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
//# sourceMappingURL=index.js.map
|