@nativescript/vite 8.0.0-alpha.1 → 8.0.0-alpha.3

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.
Files changed (145) hide show
  1. package/configuration/angular.d.ts +1 -1
  2. package/configuration/angular.js +323 -119
  3. package/configuration/angular.js.map +1 -1
  4. package/configuration/base.js +41 -24
  5. package/configuration/base.js.map +1 -1
  6. package/configuration/javascript.js +3 -3
  7. package/configuration/javascript.js.map +1 -1
  8. package/configuration/solid.js +7 -0
  9. package/configuration/solid.js.map +1 -1
  10. package/configuration/typescript.js +3 -3
  11. package/configuration/typescript.js.map +1 -1
  12. package/helpers/angular/angular-linker.js +39 -34
  13. package/helpers/angular/angular-linker.js.map +1 -1
  14. package/helpers/angular/inline-decorator-component-templates.d.ts +3 -0
  15. package/helpers/angular/inline-decorator-component-templates.js +400 -0
  16. package/helpers/angular/inline-decorator-component-templates.js.map +1 -0
  17. package/helpers/angular/shared-linker.d.ts +7 -0
  18. package/helpers/angular/shared-linker.js +37 -1
  19. package/helpers/angular/shared-linker.js.map +1 -1
  20. package/helpers/angular/synthesize-decorator-ctor-parameters.d.ts +1 -0
  21. package/helpers/angular/synthesize-decorator-ctor-parameters.js +256 -0
  22. package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +1 -0
  23. package/helpers/angular/synthesize-injectable-factories.d.ts +3 -0
  24. package/helpers/angular/synthesize-injectable-factories.js +414 -0
  25. package/helpers/angular/synthesize-injectable-factories.js.map +1 -0
  26. package/helpers/commonjs-plugins.d.ts +5 -2
  27. package/helpers/commonjs-plugins.js +126 -0
  28. package/helpers/commonjs-plugins.js.map +1 -1
  29. package/helpers/esbuild-platform-resolver.js +5 -5
  30. package/helpers/esbuild-platform-resolver.js.map +1 -1
  31. package/helpers/external-configs.d.ts +9 -1
  32. package/helpers/external-configs.js +31 -6
  33. package/helpers/external-configs.js.map +1 -1
  34. package/helpers/import-meta-path.d.ts +4 -0
  35. package/helpers/import-meta-path.js +5 -0
  36. package/helpers/import-meta-path.js.map +1 -0
  37. package/helpers/import-specifier.d.ts +1 -0
  38. package/helpers/import-specifier.js +18 -0
  39. package/helpers/import-specifier.js.map +1 -0
  40. package/helpers/main-entry.d.ts +5 -2
  41. package/helpers/main-entry.js +112 -95
  42. package/helpers/main-entry.js.map +1 -1
  43. package/helpers/nativeclass-transform.js +8 -127
  44. package/helpers/nativeclass-transform.js.map +1 -1
  45. package/helpers/nativeclass-transformer-plugin.d.ts +12 -1
  46. package/helpers/nativeclass-transformer-plugin.js +175 -36
  47. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  48. package/hmr/client/css-handler.js +60 -20
  49. package/hmr/client/css-handler.js.map +1 -1
  50. package/hmr/client/index.js +524 -23
  51. package/hmr/client/index.js.map +1 -1
  52. package/hmr/client/utils.js +57 -6
  53. package/hmr/client/utils.js.map +1 -1
  54. package/hmr/entry-runtime.d.ts +10 -0
  55. package/hmr/entry-runtime.js +263 -21
  56. package/hmr/entry-runtime.js.map +1 -1
  57. package/hmr/frameworks/angular/client/index.d.ts +2 -1
  58. package/hmr/frameworks/angular/client/index.js +72 -19
  59. package/hmr/frameworks/angular/client/index.js.map +1 -1
  60. package/hmr/frameworks/angular/server/linker.js +36 -2
  61. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  62. package/hmr/frameworks/angular/server/strategy.js +20 -5
  63. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  64. package/hmr/frameworks/typescript/server/strategy.js +8 -2
  65. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  66. package/hmr/helpers/ast-normalizer.js +22 -10
  67. package/hmr/helpers/ast-normalizer.js.map +1 -1
  68. package/hmr/server/constants.d.ts +1 -0
  69. package/hmr/server/constants.js +2 -0
  70. package/hmr/server/constants.js.map +1 -1
  71. package/hmr/server/core-sanitize.d.ts +43 -0
  72. package/hmr/server/core-sanitize.js +219 -13
  73. package/hmr/server/core-sanitize.js.map +1 -1
  74. package/hmr/server/import-map.d.ts +65 -0
  75. package/hmr/server/import-map.js +219 -0
  76. package/hmr/server/import-map.js.map +1 -0
  77. package/hmr/server/index.d.ts +2 -1
  78. package/hmr/server/index.js.map +1 -1
  79. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  80. package/hmr/server/runtime-graph-filter.js +21 -0
  81. package/hmr/server/runtime-graph-filter.js.map +1 -0
  82. package/hmr/server/shared-transform-request.d.ts +12 -0
  83. package/hmr/server/shared-transform-request.js +137 -0
  84. package/hmr/server/shared-transform-request.js.map +1 -0
  85. package/hmr/server/vite-plugin.d.ts +21 -1
  86. package/hmr/server/vite-plugin.js +443 -22
  87. package/hmr/server/vite-plugin.js.map +1 -1
  88. package/hmr/server/websocket-angular-entry.d.ts +2 -0
  89. package/hmr/server/websocket-angular-entry.js +68 -0
  90. package/hmr/server/websocket-angular-entry.js.map +1 -0
  91. package/hmr/server/websocket-angular-hot-update.d.ts +61 -0
  92. package/hmr/server/websocket-angular-hot-update.js +239 -0
  93. package/hmr/server/websocket-angular-hot-update.js.map +1 -0
  94. package/hmr/server/websocket-core-bridge.d.ts +23 -0
  95. package/hmr/server/websocket-core-bridge.js +360 -0
  96. package/hmr/server/websocket-core-bridge.js.map +1 -0
  97. package/hmr/server/websocket-graph-upsert.d.ts +6 -0
  98. package/hmr/server/websocket-graph-upsert.js +13 -0
  99. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  100. package/hmr/server/websocket-module-bindings.d.ts +6 -0
  101. package/hmr/server/websocket-module-bindings.js +471 -0
  102. package/hmr/server/websocket-module-bindings.js.map +1 -0
  103. package/hmr/server/websocket-module-specifiers.d.ts +37 -0
  104. package/hmr/server/websocket-module-specifiers.js +637 -0
  105. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  106. package/hmr/server/websocket.d.ts +26 -3
  107. package/hmr/server/websocket.js +1402 -678
  108. package/hmr/server/websocket.js.map +1 -1
  109. package/hmr/shared/package-classifier.d.ts +9 -0
  110. package/hmr/shared/package-classifier.js +58 -0
  111. package/hmr/shared/package-classifier.js.map +1 -0
  112. package/hmr/shared/runtime/browser-runtime-contract.d.ts +64 -0
  113. package/hmr/shared/runtime/browser-runtime-contract.js +54 -0
  114. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  115. package/hmr/shared/runtime/dev-overlay.d.ts +38 -0
  116. package/hmr/shared/runtime/dev-overlay.js +675 -0
  117. package/hmr/shared/runtime/dev-overlay.js.map +1 -0
  118. package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
  119. package/hmr/shared/runtime/http-only-boot.js +53 -6
  120. package/hmr/shared/runtime/http-only-boot.js.map +1 -1
  121. package/hmr/shared/runtime/module-provenance.d.ts +1 -0
  122. package/hmr/shared/runtime/module-provenance.js +66 -0
  123. package/hmr/shared/runtime/module-provenance.js.map +1 -0
  124. package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
  125. package/hmr/shared/runtime/platform-polyfills.js +122 -0
  126. package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
  127. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  128. package/hmr/shared/runtime/root-placeholder.js +576 -76
  129. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  130. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  131. package/hmr/shared/runtime/session-bootstrap.js +146 -0
  132. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  133. package/hmr/shared/runtime/vendor-bootstrap.js +51 -6
  134. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  135. package/hmr/shared/vendor/manifest.d.ts +7 -0
  136. package/hmr/shared/vendor/manifest.js +363 -23
  137. package/hmr/shared/vendor/manifest.js.map +1 -1
  138. package/hmr/shared/vendor/registry.js +104 -7
  139. package/hmr/shared/vendor/registry.js.map +1 -1
  140. package/package.json +12 -2
  141. package/runtime/core-aliases-early.js +83 -32
  142. package/runtime/core-aliases-early.js.map +1 -1
  143. package/shims/solid-jsx-runtime.d.ts +7 -0
  144. package/shims/solid-jsx-runtime.js +17 -0
  145. package/shims/solid-jsx-runtime.js.map +1 -0
@@ -1,70 +1,419 @@
1
+ import { setHmrBootStage } from './dev-overlay.js';
2
+ function isPlaceholderView(view, placeholderRoot) {
3
+ if (!view) {
4
+ return false;
5
+ }
6
+ if (placeholderRoot && view === placeholderRoot) {
7
+ return true;
8
+ }
9
+ try {
10
+ if (view.__ns_dev_placeholder) {
11
+ return true;
12
+ }
13
+ }
14
+ catch { }
15
+ return false;
16
+ }
17
+ function getCommittedRootView(application, placeholderRoot) {
18
+ try {
19
+ const root = application?.getRootView?.() || null;
20
+ if (!root) {
21
+ return null;
22
+ }
23
+ if (!isPlaceholderView(root, placeholderRoot)) {
24
+ return root;
25
+ }
26
+ const currentPage = root.currentPage || root._currentEntry?.resolvedPage || null;
27
+ if (currentPage && !isPlaceholderView(currentPage, placeholderRoot)) {
28
+ return root;
29
+ }
30
+ }
31
+ catch { }
32
+ return null;
33
+ }
34
+ function getPlaceholderWaitDiagnosticSnapshot(g, application, placeholderRoot) {
35
+ const snapshot = {
36
+ bootComplete: !!g.__NS_HMR_BOOT_COMPLETE__,
37
+ hasPlaceholderRoot: !!placeholderRoot,
38
+ hasPlaceholderFlag: !!g.__NS_DEV_PLACEHOLDER_ROOT_EARLY__,
39
+ hasAngularAppRef: !!g.__NS_ANGULAR_APP_REF__,
40
+ hasAngularReboot: typeof g.__reboot_ng_modules__ === 'function',
41
+ };
42
+ try {
43
+ snapshot.applicationType = application?.constructor?.name;
44
+ snapshot.hasLaunched = typeof application?.hasLaunched === 'function' ? !!application.hasLaunched() : undefined;
45
+ snapshot.rootViewType = application?.getRootView?.()?.constructor?.name;
46
+ }
47
+ catch { }
48
+ try {
49
+ const Frame = g.Frame;
50
+ const topmost = Frame?.topmost?.() || null;
51
+ snapshot.topmostFrameType = topmost?.constructor?.name;
52
+ snapshot.topmostPageType = topmost?.currentPage?.constructor?.name || topmost?._currentEntry?.resolvedPage?.constructor?.name;
53
+ }
54
+ catch { }
55
+ return snapshot;
56
+ }
57
+ function restoreOriginalApplicationRun(g) {
58
+ const originalRun = g['__NS_DEV_ORIGINAL_APP_RUN__'];
59
+ if (typeof originalRun !== 'function') {
60
+ return;
61
+ }
62
+ const application = g['__NS_DEV_PLACEHOLDER_APPLICATION__'] || g.Application;
63
+ try {
64
+ if (application) {
65
+ application.run = originalRun;
66
+ }
67
+ }
68
+ catch { }
69
+ try {
70
+ if (g.Application && g.Application !== application) {
71
+ g.Application.run = originalRun;
72
+ }
73
+ }
74
+ catch { }
75
+ try {
76
+ const proto = application ? Object.getPrototypeOf(application) : null;
77
+ if (proto && typeof proto.run === 'function' && proto.run !== originalRun) {
78
+ proto.run = originalRun;
79
+ }
80
+ }
81
+ catch { }
82
+ delete g['__NS_DEV_ORIGINAL_APP_RUN__'];
83
+ }
84
+ function clearPlaceholderGlobals(g) {
85
+ delete g['__NS_DEV_PLACEHOLDER_ROOT_VIEW__'];
86
+ delete g['__NS_DEV_PLACEHOLDER_ROOT_EARLY__'];
87
+ delete g['__NS_DEV_BOOT_STATUS_LABEL__'];
88
+ delete g['__NS_DEV_BOOT_ACTIVITY_INDICATOR__'];
89
+ delete g['__NS_DEV_PLACEHOLDER_LAUNCH_HANDLER__'];
90
+ delete g['__NS_DEV_PLACEHOLDER_APPLICATION__'];
91
+ const timer = g['__NS_DEV_PLACEHOLDER_RESTORE_TIMER__'];
92
+ if (timer) {
93
+ try {
94
+ clearTimeout(timer);
95
+ }
96
+ catch { }
97
+ }
98
+ delete g['__NS_DEV_PLACEHOLDER_RESTORE_TIMER__'];
99
+ }
100
+ export function tryFinalizeBootPlaceholder(reason, verbose) {
101
+ const g = globalThis;
102
+ const placeholderRoot = g['__NS_DEV_PLACEHOLDER_ROOT_VIEW__'] || null;
103
+ const hadPlaceholder = !!placeholderRoot || !!g['__NS_DEV_PLACEHOLDER_ROOT_EARLY__'] || !!g['__NS_DEV_BOOT_STATUS_LABEL__'] || !!g['__NS_DEV_BOOT_ACTIVITY_INDICATOR__'];
104
+ const application = g['__NS_DEV_PLACEHOLDER_APPLICATION__'] || g.Application;
105
+ const committedRoot = getCommittedRootView(application, placeholderRoot);
106
+ if (!committedRoot) {
107
+ return false;
108
+ }
109
+ let detachedPlaceholder = false;
110
+ if (hadPlaceholder) {
111
+ try {
112
+ const launchHandler = g['__NS_DEV_PLACEHOLDER_LAUNCH_HANDLER__'];
113
+ if (application && typeof application.off === 'function' && launchHandler) {
114
+ application.off(application.launchEvent, launchHandler);
115
+ }
116
+ }
117
+ catch { }
118
+ restoreOriginalApplicationRun(g);
119
+ clearPlaceholderGlobals(g);
120
+ detachedPlaceholder = true;
121
+ }
122
+ try {
123
+ g.__NS_HMR_BOOT_COMPLETE__ = true;
124
+ }
125
+ catch { }
126
+ if (detachedPlaceholder) {
127
+ setHmrBootStage('app-root-committed', {
128
+ detail: 'The real app root replaced the boot placeholder.',
129
+ });
130
+ }
131
+ if (verbose) {
132
+ try {
133
+ console.info('[ns-placeholder] real app root committed', {
134
+ reason,
135
+ rootType: committedRoot?.constructor?.name || typeof committedRoot,
136
+ detachedPlaceholder,
137
+ });
138
+ }
139
+ catch { }
140
+ }
141
+ return true;
142
+ }
143
+ function scheduleBootPlaceholderFinalize(reason, verbose) {
144
+ const g = globalThis;
145
+ if (g['__NS_DEV_PLACEHOLDER_RESTORE_TIMER__']) {
146
+ return;
147
+ }
148
+ const startedAt = Date.now();
149
+ const maxWaitMs = 20000;
150
+ let attempts = 0;
151
+ const tick = () => {
152
+ delete g['__NS_DEV_PLACEHOLDER_RESTORE_TIMER__'];
153
+ if (tryFinalizeBootPlaceholder(reason, verbose)) {
154
+ return;
155
+ }
156
+ attempts += 1;
157
+ if (Date.now() - startedAt >= maxWaitMs) {
158
+ if (verbose) {
159
+ try {
160
+ console.info('[ns-placeholder] waiting for real root commit timed out', {
161
+ reason,
162
+ attempts,
163
+ waitMs: Date.now() - startedAt,
164
+ state: getPlaceholderWaitDiagnosticSnapshot(g, g['__NS_DEV_PLACEHOLDER_APPLICATION__'] || g.Application, g['__NS_DEV_PLACEHOLDER_ROOT_VIEW__'] || null),
165
+ });
166
+ }
167
+ catch { }
168
+ }
169
+ return;
170
+ }
171
+ g['__NS_DEV_PLACEHOLDER_RESTORE_TIMER__'] = setTimeout(tick, attempts === 1 ? 0 : 100);
172
+ };
173
+ tick();
174
+ }
1
175
  // Root placeholder installer used during dev HMR until HTTP ESM loads.
176
+ //
177
+ // Architecture:
178
+ // 1. Install a launchEvent handler that provides a placeholder Frame/Page
179
+ // 2. Call Application.run() to start the iOS lifecycle (required or app terminates)
180
+ // 3. Inside the handler (after root is set), patch Application.run so subsequent
181
+ // calls (from the real app module) become Application.resetRootView()
182
+ //
183
+ // This means the app's entry (e.g., index.ts) can call Application.run({ create })
184
+ // exactly as it would in production — the patch intercepts it and does a clean
185
+ // root replacement instead of fighting the already-running lifecycle.
2
186
  export function installRootPlaceholder(verbose) {
3
187
  const g = globalThis;
4
188
  if (g['__NS_DEV_PLACEHOLDER_ROOT_EARLY__'])
5
189
  return;
6
190
  g['__NS_DEV_PLACEHOLDER_ROOT_EARLY__'] = true;
191
+ g['__NS_DEV_RESTORE_PLACEHOLDER__'] = (reason) => {
192
+ if (!tryFinalizeBootPlaceholder(reason, verbose)) {
193
+ scheduleBootPlaceholderFinalize(reason, verbose);
194
+ }
195
+ };
7
196
  try {
197
+ const resolveModule = (moduleIds) => {
198
+ for (const moduleId of moduleIds) {
199
+ try {
200
+ if (typeof g.moduleExists === 'function' && g.moduleExists(moduleId) && typeof g.loadModule === 'function') {
201
+ const mod = g.loadModule(moduleId);
202
+ if (mod)
203
+ return { value: (mod.default ?? mod) || mod, via: 'loadModule', moduleId };
204
+ }
205
+ }
206
+ catch { }
207
+ try {
208
+ const reg = g.__nsVendorRegistry;
209
+ if (reg?.has?.(moduleId)) {
210
+ const mod = reg.get(moduleId);
211
+ if (mod)
212
+ return { value: (mod.default ?? mod) || mod, via: '__nsVendorRegistry', moduleId };
213
+ }
214
+ }
215
+ catch { }
216
+ try {
217
+ const req = g.__nsVendorRequire || g.__nsRequire || g.require;
218
+ if (typeof req === 'function') {
219
+ const mod = req(moduleId);
220
+ if (mod)
221
+ return { value: (mod.default ?? mod) || mod, via: 'require', moduleId };
222
+ }
223
+ }
224
+ catch { }
225
+ try {
226
+ const nr = g.__nativeRequire;
227
+ if (typeof nr === 'function') {
228
+ const mod = nr(moduleId, '/');
229
+ if (mod)
230
+ return { value: (mod.default ?? mod) || mod, via: '__nativeRequire', moduleId };
231
+ }
232
+ }
233
+ catch { }
234
+ }
235
+ return undefined;
236
+ };
8
237
  const getCore = (name) => {
9
- try {
10
- const reg = g.__nsVendorRegistry;
11
- const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
12
- let mod = null;
13
- if (reg && reg.has('@nativescript/core'))
14
- mod = reg.get('@nativescript/core');
15
- else if (typeof req === 'function') {
16
- try {
17
- mod = req('@nativescript/core');
238
+ if (name === 'Application' && g.Application && (typeof g.Application.run === 'function' || typeof g.Application.on === 'function' || typeof g.Application.resetRootView === 'function')) {
239
+ return { value: g.Application, source: 'globalThis.Application' };
240
+ }
241
+ const pickApplicationApi = (candidate, source) => {
242
+ if (!candidate)
243
+ return null;
244
+ const candidates = [
245
+ { value: candidate, source },
246
+ { value: candidate.Application, source: `${source}#Application` },
247
+ { value: candidate.app, source: `${source}#app` },
248
+ { value: candidate.application, source: `${source}#application` },
249
+ ];
250
+ for (const entry of candidates) {
251
+ if (entry.value && (typeof entry.value.run === 'function' || typeof entry.value.on === 'function' || typeof entry.value.resetRootView === 'function')) {
252
+ return entry;
18
253
  }
19
- catch { }
20
254
  }
21
- const ns = (mod && (mod.default ?? mod)) || mod;
22
- if (name === 'Application' && ns && (ns.Application || ns))
23
- return ns.Application || ns;
24
- if (ns && ns[name])
25
- return ns[name];
255
+ return null;
256
+ };
257
+ if (name === 'Application') {
258
+ const applicationModule = resolveModule(['@nativescript/core/application']);
259
+ const pickedFromAppModule = pickApplicationApi(applicationModule?.value, applicationModule ? `${applicationModule.via}:${applicationModule.moduleId}` : '@nativescript/core/application');
260
+ if (pickedFromAppModule)
261
+ return pickedFromAppModule;
26
262
  }
27
- catch { }
28
- try {
29
- const nr = g.__nativeRequire;
30
- if (typeof nr === 'function') {
31
- try {
32
- const mod = nr('@nativescript/core', '/');
33
- const ns = (mod && (mod.default ?? mod)) || mod;
34
- if (name === 'Application' && ns && (ns.Application || ns))
35
- return ns.Application || ns;
36
- if (ns && ns[name])
37
- return ns[name];
263
+ const primary = resolveModule(['@nativescript/core']);
264
+ if (name === 'Application' && primary?.value) {
265
+ const pickedFromPrimary = pickApplicationApi(primary.value, `${primary.via}:${primary.moduleId}`);
266
+ if (pickedFromPrimary)
267
+ return pickedFromPrimary;
268
+ }
269
+ if (primary?.value && primary.value[name])
270
+ return { value: primary.value[name], source: `${primary.via}:${primary.moduleId}` };
271
+ const ui = resolveModule(['@nativescript/core/ui']);
272
+ if (ui?.value && ui.value[name])
273
+ return { value: ui.value[name], source: `${ui.via}:${ui.moduleId}` };
274
+ return { value: undefined, source: 'unresolved' };
275
+ };
276
+ const applicationResolved = getCore('Application');
277
+ const frameResolved = getCore('Frame');
278
+ const pageResolved = getCore('Page');
279
+ const labelResolved = getCore('Label');
280
+ const activityResolved = getCore('ActivityIndicator');
281
+ const Application = applicationResolved.value;
282
+ const Frame = frameResolved.value;
283
+ const Page = pageResolved.value;
284
+ const Label = labelResolved.value;
285
+ const ActivityIndicator = activityResolved.value;
286
+ if (!Application) {
287
+ if (verbose) {
288
+ console.warn('[ns-placeholder] Application unavailable', {
289
+ resolution: {
290
+ Application: applicationResolved.source,
291
+ Frame: frameResolved.source,
292
+ Page: pageResolved.source,
293
+ Label: labelResolved.source,
294
+ },
295
+ moduleApis: {
296
+ moduleExists: typeof g.moduleExists === 'function',
297
+ loadModule: typeof g.loadModule === 'function',
298
+ uiModuleRegistered: typeof g.moduleExists === 'function' ? !!g.moduleExists('@nativescript/core/ui') : false,
299
+ },
300
+ });
301
+ }
302
+ return;
303
+ }
304
+ g['__NS_DEV_PLACEHOLDER_APPLICATION__'] = Application;
305
+ const isAndroid = !!(g.__ANDROID__ || typeof g.android !== 'undefined');
306
+ if (!isAndroid && typeof Application.resetRootView === 'function' && !g['__NS_DEV_PATCHED_RESET_ROOT_VIEW__']) {
307
+ const __ns_dev_original_reset_root_view = Application.resetRootView.bind(Application);
308
+ const __ns_dev_patched_reset_root_view = function __ns_dev_patched_reset_root_view(entry) {
309
+ const result = __ns_dev_original_reset_root_view(entry);
310
+ try {
311
+ const restore = g['__NS_DEV_RESTORE_PLACEHOLDER__'];
312
+ if (typeof restore === 'function') {
313
+ restore('Application.resetRootView');
38
314
  }
39
- catch { }
315
+ }
316
+ catch { }
317
+ return result;
318
+ };
319
+ Application.resetRootView = __ns_dev_patched_reset_root_view;
320
+ try {
321
+ if (g.Application && g.Application !== Application) {
322
+ g.Application.resetRootView = __ns_dev_patched_reset_root_view;
40
323
  }
41
324
  }
42
325
  catch { }
43
- return undefined;
44
- };
45
- const Application = getCore('Application');
46
- const Frame = getCore('Frame');
47
- const Page = getCore('Page');
48
- const Label = getCore('Label');
49
- if (!Application || !Frame || !Page || !Label) {
50
326
  try {
51
- console.warn('[ns-entry] (early) core classes unavailable for placeholder');
327
+ const proto = Object.getPrototypeOf(Application);
328
+ if (proto && typeof proto.resetRootView === 'function' && proto.resetRootView !== __ns_dev_patched_reset_root_view) {
329
+ proto.resetRootView = __ns_dev_patched_reset_root_view;
330
+ }
52
331
  }
53
332
  catch { }
333
+ g['__NS_DEV_PATCHED_RESET_ROOT_VIEW__'] = true;
54
334
  }
335
+ const canCreatePlaceholderRoot = !!Frame && !!Page && !!Label;
336
+ if (!canCreatePlaceholderRoot && verbose) {
337
+ console.warn('[ns-placeholder] visual placeholder unavailable; starting lifecycle without placeholder root', {
338
+ resolution: {
339
+ Application: applicationResolved.source,
340
+ Frame: frameResolved.source,
341
+ Page: pageResolved.source,
342
+ Label: labelResolved.source,
343
+ ActivityIndicator: activityResolved.source,
344
+ },
345
+ moduleApis: {
346
+ moduleExists: typeof g.moduleExists === 'function',
347
+ loadModule: typeof g.loadModule === 'function',
348
+ uiModuleRegistered: typeof g.moduleExists === 'function' ? !!g.moduleExists('@nativescript/core/ui') : false,
349
+ },
350
+ });
351
+ }
352
+ let handlerFired = false;
353
+ // launchEvent handler: provides a placeholder root, then patches Application.run
55
354
  const __ns_launch_handler = (args) => {
355
+ if (verbose) {
356
+ try {
357
+ console.info('[ns-placeholder] launch handler fired', {
358
+ hasArgs: !!args,
359
+ hasExistingRoot: !!args?.root,
360
+ hasLaunched: typeof Application.hasLaunched === 'function' ? !!Application.hasLaunched() : undefined,
361
+ started: !!Application.started,
362
+ });
363
+ }
364
+ catch { }
365
+ }
56
366
  try {
57
367
  const prev = args?.root;
58
- if (verbose)
59
- console.info('[ns-entry] (early) launchEvent fired; existing root:', !!prev);
60
- if (!prev && Frame && Page && Label) {
368
+ if (!prev && canCreatePlaceholderRoot && Frame && Page && Label) {
369
+ const StackLayout = getCore('StackLayout').value;
61
370
  const page = new Page();
62
371
  page.actionBarHidden = true;
63
- const label = new Label();
64
- label.text = 'Starting NativeScript + Vite dev server…';
65
- label.textAlignment = 'center';
66
- label.padding = 12;
67
- page.content = label;
372
+ const titleLabel = new Label();
373
+ titleLabel.text = 'NativeScript Vite preparing dev session...';
374
+ titleLabel.textAlignment = 'center';
375
+ titleLabel.textWrap = true;
376
+ titleLabel.fontSize = 20;
377
+ const statusLabel = new Label();
378
+ statusLabel.text = 'Preparing the HTTP HMR bootstrap (4%)';
379
+ statusLabel.textAlignment = 'center';
380
+ statusLabel.textWrap = true;
381
+ statusLabel.fontSize = 14;
382
+ statusLabel.marginTop = 12;
383
+ const activityIndicator = ActivityIndicator
384
+ ? (() => {
385
+ const indicator = new ActivityIndicator();
386
+ indicator.busy = true;
387
+ indicator.marginTop = 16;
388
+ indicator.width = 28;
389
+ indicator.height = 28;
390
+ indicator.horizontalAlignment = 'center';
391
+ return indicator;
392
+ })()
393
+ : null;
394
+ if (StackLayout) {
395
+ const root = new StackLayout();
396
+ root.padding = 24;
397
+ root.verticalAlignment = 'middle';
398
+ root.horizontalAlignment = 'center';
399
+ root.addChild(titleLabel);
400
+ root.addChild(statusLabel);
401
+ if (activityIndicator) {
402
+ root.addChild(activityIndicator);
403
+ }
404
+ page.content = root;
405
+ }
406
+ else {
407
+ // Fallback: just show the title label centered
408
+ titleLabel.verticalAlignment = 'middle';
409
+ titleLabel.horizontalAlignment = 'center';
410
+ titleLabel.width = 280;
411
+ titleLabel.padding = 12;
412
+ page.content = titleLabel;
413
+ }
414
+ // Store refs so the overlay API can update the status label
415
+ g['__NS_DEV_BOOT_STATUS_LABEL__'] = statusLabel;
416
+ g['__NS_DEV_BOOT_ACTIVITY_INDICATOR__'] = activityIndicator;
68
417
  const frame = new Frame();
69
418
  frame.navigate({ create: () => page, clearHistory: true, animated: false });
70
419
  try {
@@ -73,70 +422,221 @@ export function installRootPlaceholder(verbose) {
73
422
  g['__NS_DEV_PLACEHOLDER_ROOT_VIEW__'] = frame;
74
423
  }
75
424
  catch { }
425
+ if (verbose) {
426
+ try {
427
+ console.info('[ns-placeholder] assigned placeholder root', {
428
+ frameType: frame?.constructor?.name,
429
+ pageType: page?.constructor?.name,
430
+ hasStackLayout: !!StackLayout,
431
+ hasActivityIndicator: !!activityIndicator,
432
+ });
433
+ }
434
+ catch { }
435
+ }
76
436
  if (args)
77
437
  args.root = frame;
78
- if (verbose)
79
- console.info('[ns-entry] (early) temporary root provided via launch args');
80
438
  }
81
439
  }
82
440
  catch (e) {
441
+ console.error('[ns-placeholder] root error', e);
442
+ }
443
+ if (!handlerFired) {
444
+ handlerFired = true;
445
+ // Patch Application.run() → resetRootView() for subsequent calls.
446
+ // The app lifecycle is now running — a second run() is undefined
447
+ // behavior, but resetRootView() is the documented API for
448
+ // replacing the root of a running app.
449
+ //
450
+ // Patch on ALL possible references. The vendor-registry Application,
451
+ // globalThis.Application, and the prototype may be different objects.
83
452
  try {
84
- console.error('[ns-entry] (early) temp root error', e);
453
+ if (Application && typeof Application.run === 'function') {
454
+ const _originalRun = Application.run.bind(Application);
455
+ g['__NS_DEV_ORIGINAL_APP_RUN__'] = _originalRun;
456
+ const __ns_dev_patched_run = function __ns_dev_patched_run(entry) {
457
+ try {
458
+ // Detach the launch handler, but keep placeholder refs until the
459
+ // real app root is actually committed.
460
+ try {
461
+ if (Application && Application.off) {
462
+ Application.off(Application.launchEvent, __ns_launch_handler);
463
+ }
464
+ }
465
+ catch { }
466
+ // When entry is undefined/null, the calling framework (e.g. Angular)
467
+ // manages root views itself via launch events and resetRootView().
468
+ // Don't attempt resetRootView(undefined) which throws "Main entry is missing".
469
+ if (!entry) {
470
+ if (verbose)
471
+ console.info('[ns-placeholder] patched run() called with no entry; framework manages root view');
472
+ return;
473
+ }
474
+ const isModuleNameEntry = entry && entry.moduleName && !entry.create;
475
+ if (isModuleNameEntry) {
476
+ if (typeof Application.resetRootView === 'function') {
477
+ Application.resetRootView(entry);
478
+ }
479
+ }
480
+ else {
481
+ // Framework path: two-phase boot with dominative document
482
+ Application._rootView = null;
483
+ try {
484
+ const domModule = g.__nsVendorRegistry?.get?.('dominative') ||
485
+ (typeof require === 'function'
486
+ ? (() => {
487
+ try {
488
+ return require('dominative');
489
+ }
490
+ catch {
491
+ return null;
492
+ }
493
+ })()
494
+ : null);
495
+ const doc = domModule?.document;
496
+ if (doc && typeof Application.resetRootView === 'function') {
497
+ Application.resetRootView({ create: () => doc });
498
+ if (entry && typeof entry.create === 'function') {
499
+ entry.create();
500
+ }
501
+ }
502
+ else {
503
+ if (typeof Application.resetRootView === 'function') {
504
+ Application.resetRootView(entry);
505
+ }
506
+ }
507
+ }
508
+ catch (e2) {
509
+ if (verbose)
510
+ console.warn('[ns-placeholder] two-phase boot failed:', e2?.message || e2);
511
+ try {
512
+ if (typeof Application.resetRootView === 'function') {
513
+ Application.resetRootView(entry);
514
+ }
515
+ }
516
+ catch { }
517
+ }
518
+ }
519
+ }
520
+ catch (e) {
521
+ console.warn('[ns-placeholder] patched run() error:', e);
522
+ }
523
+ };
524
+ Application.run = __ns_dev_patched_run;
525
+ if (verbose) {
526
+ try {
527
+ console.info('[ns-placeholder] patched Application.run');
528
+ }
529
+ catch { }
530
+ }
531
+ if (g.Application && g.Application !== Application) {
532
+ g.Application.run = __ns_dev_patched_run;
533
+ }
534
+ try {
535
+ const proto = Object.getPrototypeOf(Application);
536
+ if (proto && typeof proto.run === 'function' && proto.run !== __ns_dev_patched_run) {
537
+ proto.run = __ns_dev_patched_run;
538
+ }
539
+ }
540
+ catch { }
541
+ }
85
542
  }
86
543
  catch { }
87
544
  }
88
545
  };
546
+ g['__NS_DEV_PLACEHOLDER_LAUNCH_HANDLER__'] = __ns_launch_handler;
89
547
  try {
90
- g['__NS_DEV_LAUNCH_HANDLER__'] = __ns_launch_handler;
91
- }
92
- catch { }
93
- try {
94
- if (!g['__NS_DEV_LAUNCH_ATTACHED__'] && Application && Application.on) {
548
+ if (Application && Application.on) {
95
549
  Application.on(Application.launchEvent, __ns_launch_handler);
96
- g['__NS_DEV_LAUNCH_ATTACHED__'] = true;
97
550
  }
98
551
  }
99
552
  catch { }
553
+ // Determine boot path
100
554
  try {
101
- g['__NS_DEV_RESTORE_PLACEHOLDER__'] = () => {
555
+ const appAny = Application;
556
+ const methodState = {
557
+ hasRun: typeof appAny?.run === 'function',
558
+ hasOn: typeof appAny?.on === 'function',
559
+ hasOff: typeof appAny?.off === 'function',
560
+ hasHasLaunched: typeof appAny?.hasLaunched === 'function',
561
+ hasGetRootView: typeof appAny?.getRootView === 'function',
562
+ hasResetRootView: typeof appAny?.resetRootView === 'function',
563
+ hasRunAsMainApp: typeof appAny?.runAsMainApp === 'function',
564
+ type: appAny?.constructor?.name,
565
+ };
566
+ if (verbose) {
102
567
  try {
103
- if (g['__NS_DEV_LAUNCH_HANDLER__'] && Application && Application.off) {
104
- Application.off(Application.launchEvent, g['__NS_DEV_LAUNCH_HANDLER__']);
105
- }
568
+ console.info('[ns-placeholder] application methods', methodState);
569
+ console.info('[ns-placeholder] application source', applicationResolved.source);
106
570
  }
107
571
  catch { }
108
- // Clear flags and drop any retained placeholder Frame reference
572
+ }
573
+ if (!appAny || typeof appAny.run !== 'function') {
574
+ console.warn('[ns-placeholder] Application.run unavailable', {
575
+ ...methodState,
576
+ source: applicationResolved.source,
577
+ });
578
+ return;
579
+ }
580
+ const hasLaunched = typeof appAny.hasLaunched === 'function' ? !!appAny.hasLaunched() : false;
581
+ const hasRootView = typeof appAny.getRootView === 'function' ? !!appAny.getRootView() : false;
582
+ const started = !!appAny.started;
583
+ const nativeApp = appAny.nativeApp;
584
+ const iosNativeApp = appAny.ios?.nativeApp;
585
+ const canRunAsMainApp = typeof appAny.runAsMainApp === 'function';
586
+ if (verbose) {
109
587
  try {
110
- delete g['__NS_DEV_PLACEHOLDER_ROOT_EARLY__'];
588
+ console.info('[ns-placeholder] boot state', {
589
+ hasLaunched,
590
+ hasRootView,
591
+ started,
592
+ nativeApp: !!nativeApp,
593
+ iosNativeApp: !!iosNativeApp,
594
+ canRunAsMainApp,
595
+ hasResetRootView: typeof appAny.resetRootView === 'function',
596
+ });
111
597
  }
112
598
  catch { }
599
+ }
600
+ if (hasLaunched || hasRootView) {
601
+ // App lifecycle is already active. Skip starting it again and only install
602
+ // the placeholder root/patching behavior for the existing instance.
603
+ if (verbose) {
604
+ try {
605
+ console.info('[ns-placeholder] boot branch: existing lifecycle');
606
+ }
607
+ catch { }
608
+ }
113
609
  try {
114
- delete g['__NS_DEV_LAUNCH_ATTACHED__'];
610
+ __ns_launch_handler();
115
611
  }
116
612
  catch { }
117
- try {
118
- const fr = g['__NS_DEV_PLACEHOLDER_ROOT_VIEW__'];
119
- if (fr && typeof fr._removeFromSuperview === 'function') {
120
- try {
121
- fr._removeFromSuperview();
122
- }
123
- catch { }
613
+ }
614
+ else if (canRunAsMainApp) {
615
+ if (verbose) {
616
+ try {
617
+ console.info('[ns-placeholder] boot branch: runAsMainApp');
124
618
  }
619
+ catch { }
125
620
  }
126
- catch { }
127
- try {
128
- delete g['__NS_DEV_PLACEHOLDER_ROOT_VIEW__'];
621
+ appAny.started = true;
622
+ appAny.runAsMainApp();
623
+ }
624
+ else {
625
+ if (verbose) {
626
+ try {
627
+ console.info('[ns-placeholder] boot branch: Application.run');
628
+ }
629
+ catch { }
129
630
  }
130
- catch { }
131
- };
631
+ appAny.run();
632
+ }
633
+ }
634
+ catch (e) {
635
+ console.warn('[ns-placeholder] boot error', e);
132
636
  }
133
- catch { }
134
637
  }
135
638
  catch (e) {
136
- try {
137
- console.error('[ns-entry] (early) failed to install launchEvent handler', e);
138
- }
139
- catch { }
639
+ console.error('[ns-placeholder] install failed', e);
140
640
  }
141
641
  }
142
642
  //# sourceMappingURL=root-placeholder.js.map