@nativescript/vite 0.0.1-alpha.1 → 0.0.1-alpha.2

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 (55) hide show
  1. package/dist/configuration/base.js +134 -36
  2. package/dist/helpers/external-configs.js +1 -1
  3. package/dist/helpers/global-defines.d.ts +1 -0
  4. package/dist/helpers/global-defines.js +2 -0
  5. package/dist/helpers/main-entry-hmr-includes.d.ts +1 -0
  6. package/dist/helpers/main-entry-hmr-includes.js +18 -0
  7. package/dist/helpers/main-entry.d.ts +2 -2
  8. package/dist/helpers/main-entry.js +58 -94
  9. package/dist/helpers/module-runner-patch.d.ts +3 -0
  10. package/dist/helpers/module-runner-patch.js +65 -0
  11. package/dist/helpers/ns-cli-plugins.d.ts +1 -14
  12. package/dist/helpers/ns-cli-plugins.js +54 -107
  13. package/dist/helpers/package-platform-aliases.d.ts +1 -1
  14. package/dist/helpers/package-platform-aliases.js +4 -4
  15. package/dist/helpers/ts-config-paths.d.ts +1 -1
  16. package/dist/helpers/ts-config-paths.js +3 -3
  17. package/dist/hmr/client-vue.d.ts +6 -0
  18. package/dist/hmr/client-vue.js +563 -0
  19. package/dist/hmr/component-tracker.d.ts +23 -0
  20. package/dist/hmr/component-tracker.js +193 -0
  21. package/dist/hmr/css-handler.d.ts +4 -0
  22. package/dist/hmr/css-handler.js +77 -0
  23. package/dist/hmr/message-handler.d.ts +1 -0
  24. package/dist/hmr/message-handler.js +590 -0
  25. package/dist/hmr/nsv-hooks.d.ts +2 -0
  26. package/dist/hmr/nsv-hooks.js +481 -0
  27. package/dist/hmr/plugin-vue.d.ts +2 -0
  28. package/dist/hmr/plugin-vue.js +38 -0
  29. package/dist/hmr/plugins/index.d.ts +1 -0
  30. package/dist/hmr/plugins/index.js +16 -0
  31. package/dist/hmr/plugins/plugin-vue.d.ts +2 -0
  32. package/dist/hmr/plugins/plugin-vue.js +41 -0
  33. package/dist/hmr/plugins/websocket-vue.d.ts +2 -0
  34. package/dist/hmr/plugins/websocket-vue.js +882 -0
  35. package/dist/hmr/runtime-vue.d.ts +13 -0
  36. package/dist/hmr/runtime-vue.js +2306 -0
  37. package/dist/hmr/types.d.ts +24 -0
  38. package/dist/hmr/types.js +2 -0
  39. package/dist/hmr/websocket-vue.d.ts +2 -0
  40. package/dist/hmr/websocket-vue.js +875 -0
  41. package/dist/shims/node-module.d.ts +5 -0
  42. package/dist/shims/node-module.js +12 -0
  43. package/package.json +2 -1
  44. package/dist/configuration/old-without-merge-base.d.ts +0 -13
  45. package/dist/configuration/old-without-merge-base.js +0 -249
  46. package/dist/helpers/side-effects.d.ts +0 -14
  47. package/dist/helpers/side-effects.js +0 -69
  48. package/dist/hmr/hmr-angular.d.ts +0 -1
  49. package/dist/hmr/hmr-angular.js +0 -34
  50. package/dist/hmr/hmr-bridge.d.ts +0 -18
  51. package/dist/hmr/hmr-bridge.js +0 -154
  52. package/dist/hmr/hmr-client.d.ts +0 -5
  53. package/dist/hmr/hmr-client.js +0 -93
  54. package/dist/hmr/hmr-server.d.ts +0 -20
  55. package/dist/hmr/hmr-server.js +0 -179
@@ -0,0 +1,481 @@
1
+ // NativeScript-Vue integration hooks for HMR in non-DOM/runtime-light environments
2
+ // - Monkey-patches nativescript-vue createApp to add a global mixin that tracks component instances
3
+ // - Captures the app and root instance for debugging and fallbacks
4
+ import componentTracker from './component-tracker';
5
+ const VERBOSE = true;
6
+ // Apply hooks immediately when this module loads
7
+ let hooksAttempted = false;
8
+ let hookRetryCount = 0;
9
+ const MAX_HOOK_RETRIES = 3; // Reduced from 10
10
+ let lastRetryTime = 0;
11
+ const RETRY_COOLDOWN = 1000; // 1 second cooldown between retries
12
+ // Function to attempt hook setup with smart retries
13
+ function attemptHookSetup() {
14
+ const now = Date.now();
15
+ const g = globalThis;
16
+ // Already applied successfully
17
+ if (g.__NS_VUE_HOOKS_APPLIED__)
18
+ return;
19
+ // Respect cooldown period
20
+ if (now - lastRetryTime < RETRY_COOLDOWN)
21
+ return;
22
+ // Max retries reached
23
+ if (hookRetryCount >= MAX_HOOK_RETRIES) {
24
+ if (VERBOSE && hookRetryCount === MAX_HOOK_RETRIES) {
25
+ console.info('[ns-hmr][nsv-hooks] Max retry attempts reached, switching to passive mode');
26
+ hookRetryCount++; // Prevent this message from repeating
27
+ }
28
+ return;
29
+ }
30
+ hookRetryCount++;
31
+ lastRetryTime = now;
32
+ if (VERBOSE && hookRetryCount > 1) {
33
+ console.info('[ns-hmr][nsv-hooks] Retrying hook setup...', { attempt: hookRetryCount });
34
+ }
35
+ setupNativeScriptVueHooks();
36
+ }
37
+ export function setupNativeScriptVueHooks() {
38
+ try {
39
+ const g = globalThis;
40
+ if (g.__NS_VUE_HOOKS_APPLIED__)
41
+ return;
42
+ hooksAttempted = true;
43
+ // Check if app is already created (common in Vite/ES module environments)
44
+ const existingApp = g.__NS_VUE_APP__;
45
+ const existingRoot = g.__NS_VUE_ROOT_INSTANCE__;
46
+ if (existingApp) {
47
+ if (VERBOSE)
48
+ console.info('[ns-hmr][nsv-hooks] Found existing app, applying hooks retroactively');
49
+ retrofitExistingApp(existingApp);
50
+ g.__NS_VUE_HOOKS_APPLIED__ = true;
51
+ if (existingRoot) {
52
+ if (VERBOSE)
53
+ console.info('[ns-hmr][nsv-hooks] Found existing root instance, registering');
54
+ setTimeout(() => registerExistingInstancesWithRuntime(), 0);
55
+ }
56
+ return;
57
+ }
58
+ // Debug: Let's see what's actually available
59
+ if (VERBOSE) {
60
+ console.info('[ns-hmr][nsv-hooks] Debug - Available globals:', {
61
+ hasRequire: !!(g.require),
62
+ hasGlobalRequire: !!globalThis.__require,
63
+ hasModuleRequire: typeof require !== 'undefined',
64
+ hasNSVueGlobal: !!(g.nativescriptVue || g.NativeScriptVue),
65
+ hasVueGlobal: !!g.Vue,
66
+ requireType: typeof g.require,
67
+ hasExistingApp: !!existingApp,
68
+ hasExistingRoot: !!existingRoot
69
+ });
70
+ }
71
+ // Try multiple ways to get the module (for proactive hook setup)
72
+ let nsv = null;
73
+ // Method 1: Check global objects first (ES modules often expose via globals)
74
+ nsv = g.nativescriptVue || g.NativeScriptVue || g.Vue || g.__VUE__;
75
+ if (VERBOSE && nsv) {
76
+ console.info('[ns-hmr][nsv-hooks] Found Vue via global object');
77
+ }
78
+ // Method 2: Try require as fallback (may return empty object in ES modules)
79
+ if (!nsv) {
80
+ const req = g.require || globalThis.__require || (typeof require !== 'undefined' ? require : null);
81
+ if (req) {
82
+ const nsvModule = safeRequire('nativescript-vue');
83
+ const vueModule = safeRequire('vue');
84
+ // In ES modules mode, modules might be available but empty - check if they have real content
85
+ if (nsvModule && Object.keys(nsvModule).length > 0) {
86
+ nsv = nsvModule;
87
+ if (VERBOSE)
88
+ console.info('[ns-hmr][nsv-hooks] Found nativescript-vue via require with content');
89
+ }
90
+ else if (vueModule && Object.keys(vueModule).length > 0) {
91
+ nsv = vueModule;
92
+ if (VERBOSE)
93
+ console.info('[ns-hmr][nsv-hooks] Found vue via require with content');
94
+ }
95
+ else if (VERBOSE) {
96
+ console.info('[ns-hmr][nsv-hooks] require() available but modules empty (ES modules mode detected)');
97
+ }
98
+ }
99
+ }
100
+ if (!nsv) {
101
+ if (VERBOSE && hookRetryCount === 1) {
102
+ console.info('[ns-hmr][nsv-hooks] No nativescript-vue module available via any method - app likely uses ES imports');
103
+ console.info('[ns-hmr][nsv-hooks] Will wait for app to be created and then apply hooks retroactively');
104
+ }
105
+ return;
106
+ }
107
+ if (VERBOSE) {
108
+ console.info('[ns-hmr][nsv-hooks] Found Vue module:', {
109
+ hasCreateApp: !!nsv.createApp,
110
+ hasSetRootApp: !!nsv.setRootApp,
111
+ moduleKeys: Object.keys(nsv).slice(0, 10)
112
+ });
113
+ }
114
+ // In ES modules mode, Vue APIs might be distributed differently
115
+ let createAppFn = nsv.createApp;
116
+ if (!createAppFn) {
117
+ // Try to find createApp in various Vue-related globals
118
+ const vueGlobals = [g.Vue, g.__VUE__, g.nativescriptVue, g.NativeScriptVue];
119
+ for (const vueRef of vueGlobals) {
120
+ if (vueRef && vueRef.createApp) {
121
+ createAppFn = vueRef.createApp;
122
+ nsv = vueRef; // Use the Vue reference that has createApp
123
+ if (VERBOSE)
124
+ console.info('[ns-hmr][nsv-hooks] Found createApp in Vue global reference');
125
+ break;
126
+ }
127
+ }
128
+ }
129
+ if (!createAppFn) {
130
+ if (VERBOSE)
131
+ console.info('[ns-hmr][nsv-hooks] No createApp function found in any Vue reference');
132
+ // In ES modules mode, we might need to wait for the app to be created
133
+ // Set up a fallback mechanism to apply hooks later
134
+ if (!g.__nsv_esModulesFallback) {
135
+ g.__nsv_esModulesFallback = true;
136
+ if (VERBOSE)
137
+ console.info('[ns-hmr][nsv-hooks] Setting up ES modules fallback for later hook application');
138
+ }
139
+ return;
140
+ }
141
+ hookCreateApp(nsv);
142
+ }
143
+ catch (e) {
144
+ if (VERBOSE)
145
+ console.info('[ns-hmr][nsv-hooks] Setup failed:', e?.message || String(e));
146
+ }
147
+ }
148
+ function hookCreateApp(nsv) {
149
+ try {
150
+ const g = globalThis;
151
+ if (g.__NS_VUE_HOOKS_APPLIED__)
152
+ return;
153
+ // Check if app already exists - if so, retrofit the hooks
154
+ const existingApp = g.__NS_VUE_APP__;
155
+ if (existingApp) {
156
+ if (VERBOSE)
157
+ console.info('[ns-hmr][nsv-hooks] Found existing app, retrofitting hooks');
158
+ retrofitExistingApp(existingApp);
159
+ }
160
+ // Also check for root instance and register it
161
+ const existingRoot = g.__NS_VUE_ROOT_INSTANCE__;
162
+ if (existingRoot) {
163
+ if (VERBOSE)
164
+ console.info('[ns-hmr][nsv-hooks] Found existing root instance, registering');
165
+ try {
166
+ registerExistingInstancesWithRuntime();
167
+ }
168
+ catch (e) {
169
+ if (VERBOSE)
170
+ console.warn('[ns-hmr][nsv-hooks] Failed to register existing instances:', e?.message);
171
+ }
172
+ }
173
+ const originalCreateApp = nsv.createApp.bind(nsv);
174
+ const originalSetRootApp = typeof nsv.setRootApp === 'function' ? nsv.setRootApp.bind(nsv) : null;
175
+ // Capture setRootApp invocations for app access
176
+ if (originalSetRootApp) {
177
+ try {
178
+ nsv.setRootApp = (app) => {
179
+ try {
180
+ g.__NS_VUE_APP__ = app;
181
+ if (VERBOSE)
182
+ console.info('[ns-hmr][nsv-hooks] setRootApp called');
183
+ // Apply mixin to existing app if not already done
184
+ if (!app.__nsHmrMixinApplied) {
185
+ applyHmrMixin(app);
186
+ }
187
+ }
188
+ catch { }
189
+ return originalSetRootApp(app);
190
+ };
191
+ }
192
+ catch { }
193
+ }
194
+ nsv.createApp = (...args) => {
195
+ const app = originalCreateApp(...args);
196
+ try {
197
+ g.__NS_VUE_APP__ = app;
198
+ if (VERBOSE)
199
+ console.info('[ns-hmr][nsv-hooks] Stored __NS_VUE_APP__');
200
+ }
201
+ catch { }
202
+ // Apply HMR mixin
203
+ applyHmrMixin(app);
204
+ // Capture the root instance on start
205
+ if (typeof app.start === 'function') {
206
+ const originalStart = app.start.bind(app);
207
+ app.start = (...sArgs) => {
208
+ const instance = originalStart(...sArgs);
209
+ try {
210
+ g.__NS_VUE_ROOT_INSTANCE__ = instance;
211
+ if (VERBOSE)
212
+ console.info('[ns-hmr][nsv-hooks] Root instance captured from start()');
213
+ // Register this instance and any children with HMR runtime
214
+ setTimeout(() => {
215
+ try {
216
+ registerExistingInstancesWithRuntime();
217
+ }
218
+ catch { }
219
+ }, 0);
220
+ }
221
+ catch { }
222
+ return instance;
223
+ };
224
+ }
225
+ return app;
226
+ };
227
+ g.__NS_VUE_HOOKS_APPLIED__ = true;
228
+ if (VERBOSE)
229
+ console.info('[ns-hmr][nsv-hooks] Applied NativeScript-Vue hooks');
230
+ }
231
+ catch (e) {
232
+ if (VERBOSE)
233
+ console.info('[ns-hmr][nsv-hooks] Setup failed:', e?.message || String(e));
234
+ }
235
+ }
236
+ // Function to retrofit an existing app with HMR capabilities
237
+ function retrofitExistingApp(app) {
238
+ try {
239
+ if (app.__nsHmrMixinApplied)
240
+ return;
241
+ // Apply the HMR mixin to the existing app
242
+ applyHmrMixin(app);
243
+ if (VERBOSE)
244
+ console.info('[ns-hmr][nsv-hooks] Retrofitted existing app with HMR mixin');
245
+ }
246
+ catch (e) {
247
+ if (VERBOSE)
248
+ console.warn('[ns-hmr][nsv-hooks] Failed to retrofit existing app:', e?.message);
249
+ }
250
+ }
251
+ // Function to apply the HMR tracking mixin
252
+ function applyHmrMixin(app) {
253
+ try {
254
+ if (app.__nsHmrMixinApplied)
255
+ return;
256
+ // Register a global mixin to track component instances
257
+ app.mixin({
258
+ mounted() {
259
+ try {
260
+ const id = this?.$?.type?.__file || this?.type?.__file || (this?.$?.uid ? String(this.$.uid) : undefined);
261
+ const key = id || (this?.$?.type?.name) || 'unknown';
262
+ componentTracker.registerComponent(key, this);
263
+ if (VERBOSE)
264
+ console.info('[ns-hmr][nsv-hooks] Component mounted:', {
265
+ key,
266
+ hasType: !!(this?.$?.type || this?.type),
267
+ hasFile: !!(this?.$?.type?.__file || this?.type?.__file),
268
+ typeName: (this?.$?.type?.name || this?.type?.name)
269
+ });
270
+ // Also attempt to register this instance with Vue's HMR runtime so rerenders reach it
271
+ try {
272
+ const rt = globalThis.__VUE_HMR_RUNTIME__;
273
+ if (rt && typeof rt.registerInstance === 'function') {
274
+ const variants = computeIdVariants(key);
275
+ for (const vid of variants) {
276
+ try {
277
+ if (!rt.isRecorded || !rt.isRecorded(vid)) {
278
+ if (typeof rt.createRecord === 'function')
279
+ rt.createRecord(vid, (this?.$?.type || this?.type || {}));
280
+ }
281
+ }
282
+ catch { }
283
+ try {
284
+ rt.registerInstance(vid, this);
285
+ }
286
+ catch { }
287
+ }
288
+ if (VERBOSE)
289
+ console.info('[ns-hmr][nsv-hooks] registered instance with HMR runtime', { file: key, ids: Array.from(variants) });
290
+ }
291
+ }
292
+ catch { }
293
+ }
294
+ catch { }
295
+ },
296
+ unmounted() {
297
+ try {
298
+ const id = this?.$?.type?.__file || this?.type?.__file || (this?.$?.uid ? String(this.$.uid) : undefined);
299
+ const key = id || (this?.$?.type?.name) || 'unknown';
300
+ componentTracker.unregisterComponent(key, this);
301
+ if (VERBOSE)
302
+ console.info('[ns-hmr][nsv-hooks] Component unmounted:', key);
303
+ }
304
+ catch { }
305
+ }
306
+ });
307
+ app.__nsHmrMixinApplied = true;
308
+ }
309
+ catch (e) {
310
+ if (VERBOSE)
311
+ console.info('[ns-hmr][nsv-hooks] Failed to apply HMR mixin:', e?.message || String(e));
312
+ }
313
+ }
314
+ function safeRequire(name) {
315
+ try {
316
+ // Try global require first
317
+ const globalReq = globalThis.require;
318
+ if (globalReq) {
319
+ try {
320
+ const result = globalReq(name);
321
+ if (VERBOSE)
322
+ console.info(`[ns-hmr][nsv-hooks] Successfully required '${name}' via global.require`);
323
+ return result;
324
+ }
325
+ catch (e) {
326
+ if (VERBOSE)
327
+ console.info(`[ns-hmr][nsv-hooks] Failed to require '${name}' via global.require:`, e?.message);
328
+ }
329
+ }
330
+ // Try standard require if available
331
+ if (typeof require !== 'undefined') {
332
+ try {
333
+ const result = require(name);
334
+ if (VERBOSE)
335
+ console.info(`[ns-hmr][nsv-hooks] Successfully required '${name}' via standard require`);
336
+ return result;
337
+ }
338
+ catch (e) {
339
+ if (VERBOSE)
340
+ console.info(`[ns-hmr][nsv-hooks] Failed to require '${name}' via standard require:`, e?.message);
341
+ }
342
+ }
343
+ // Try alternative require locations
344
+ const altReq = globalThis.__require || globalThis.global?.require;
345
+ if (altReq) {
346
+ try {
347
+ const result = altReq(name);
348
+ if (VERBOSE)
349
+ console.info(`[ns-hmr][nsv-hooks] Successfully required '${name}' via alternative require`);
350
+ return result;
351
+ }
352
+ catch (e) {
353
+ if (VERBOSE)
354
+ console.info(`[ns-hmr][nsv-hooks] Failed to require '${name}' via alternative require:`, e?.message);
355
+ }
356
+ }
357
+ }
358
+ catch (e) {
359
+ if (VERBOSE)
360
+ console.info(`[ns-hmr][nsv-hooks] safeRequire('${name}') failed completely:`, e?.message);
361
+ }
362
+ return null;
363
+ }
364
+ // Attempt to apply hooks immediately when this module loads
365
+ // This ensures hooks are applied before createApp is called
366
+ try {
367
+ setupNativeScriptVueHooks();
368
+ }
369
+ catch (e) {
370
+ if (VERBOSE)
371
+ console.info('[ns-hmr][nsv-hooks] Initial hook setup failed:', e?.message);
372
+ }
373
+ export default setupNativeScriptVueHooks;
374
+ // Helpers
375
+ function computeIdVariants(raw) {
376
+ const out = new Set();
377
+ try {
378
+ if (!raw)
379
+ return out;
380
+ let s = String(raw);
381
+ // prefer source file path if available on component type
382
+ // normalize slashes and strip query
383
+ s = s.replace(/\\/g, '/');
384
+ const noQuery = s.split('?')[0];
385
+ const withVueQ = noQuery + (noQuery.endsWith('?vue') ? '' : '?vue');
386
+ const relFromSrc = noQuery.replace(/^.*?\/src\//, '/src/');
387
+ const relNoLead = relFromSrc.replace(/^\//, '');
388
+ out.add(s);
389
+ out.add(noQuery);
390
+ out.add(withVueQ);
391
+ out.add(relFromSrc);
392
+ out.add(relNoLead);
393
+ if (!relNoLead.endsWith('?vue'))
394
+ out.add(relNoLead + '?vue');
395
+ }
396
+ catch { }
397
+ return out;
398
+ }
399
+ function registerExistingInstancesWithRuntime() {
400
+ try {
401
+ const g = globalThis;
402
+ const rt = g.__VUE_HMR_RUNTIME__;
403
+ if (!rt || (typeof rt.registerInstance !== 'function'))
404
+ return;
405
+ const root = g.__NS_VUE_ROOT_INSTANCE__;
406
+ if (!root)
407
+ return;
408
+ let count = 0;
409
+ const seen = new Set();
410
+ const queue = [root];
411
+ const enqueueChildren = (node) => {
412
+ try {
413
+ if (!node || seen.has(node))
414
+ return;
415
+ seen.add(node);
416
+ const internal = (node.$ ? node.$ : node);
417
+ if (internal?.subTree)
418
+ queue.push(internal.subTree);
419
+ if (node && typeof node === 'object') {
420
+ if (node.component)
421
+ queue.push(node.component);
422
+ const ch = node.children || node.child || null;
423
+ if (Array.isArray(ch))
424
+ ch.forEach((c) => { if (c && typeof c === 'object')
425
+ queue.push(c); });
426
+ else if (ch && typeof ch === 'object')
427
+ queue.push(ch);
428
+ }
429
+ }
430
+ catch { }
431
+ };
432
+ const handle = (ins) => {
433
+ try {
434
+ const type = (ins?.$?.type) || ins?.type || null;
435
+ const file = (type && type.__file) ? String(type.__file) : undefined;
436
+ const name = (type && (type.__name || type.name)) ? String(type.__name || type.name) : undefined;
437
+ const key = file || name;
438
+ if (!key)
439
+ return;
440
+ const variants = computeIdVariants(key);
441
+ variants.forEach((vid) => {
442
+ try {
443
+ if (!rt.isRecorded || !rt.isRecorded(vid)) {
444
+ if (typeof rt.createRecord === 'function')
445
+ rt.createRecord(vid, type || {});
446
+ }
447
+ }
448
+ catch { }
449
+ try {
450
+ rt.registerInstance(vid, ins);
451
+ }
452
+ catch { }
453
+ });
454
+ count++;
455
+ }
456
+ catch { }
457
+ };
458
+ while (queue.length) {
459
+ const cur = queue.shift();
460
+ try {
461
+ handle(cur);
462
+ }
463
+ catch { }
464
+ try {
465
+ enqueueChildren(cur);
466
+ }
467
+ catch { }
468
+ }
469
+ try {
470
+ if (VERBOSE)
471
+ console.info('[ns-hmr][nsv-hooks] registered existing instances with HMR runtime', { count });
472
+ }
473
+ catch { }
474
+ }
475
+ catch { }
476
+ }
477
+ // Actually execute the hooks setup as early as possible
478
+ console.info('[ns-hmr][nsv-hooks] Initializing hooks...');
479
+ attemptHookSetup();
480
+ // Export to global for external triggers
481
+ globalThis.__ns_attemptHookSetup = attemptHookSetup;
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function hmrPluginVue(platform: string): Plugin;
@@ -0,0 +1,38 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+ const VIRTUAL_ID = "virtual:pure-vue-hmr";
4
+ const RESOLVED_ID = "\0" + VIRTUAL_ID;
5
+ // TODO: make switch statement on flavors to load different flavor clients
6
+ export function hmrPluginVue(platform) {
7
+ let config;
8
+ return {
9
+ name: "nativescript-pure-vue-hmr",
10
+ configResolved(c) {
11
+ config = c;
12
+ },
13
+ resolveId(id) {
14
+ if (id === VIRTUAL_ID)
15
+ return RESOLVED_ID;
16
+ return null;
17
+ },
18
+ load(id) {
19
+ if (id !== RESOLVED_ID)
20
+ return null;
21
+ const clientPath = require.resolve("@nativescript/vite/dist/hmr/client-vue.js");
22
+ // Build ws url from Vite server info
23
+ const host = process.env.NS_HMR_HOST ||
24
+ config?.server?.host ||
25
+ (platform === 'android' ? "10.0.2.2" : "localhost");
26
+ const port = Number(config?.server?.port || 5173);
27
+ const secure = !!config?.server?.https;
28
+ const protocol = secure ? "wss" : "ws";
29
+ const wsUrl = `${protocol}://${host}:${port}/ns-hmr`;
30
+ // Import client and start it with explicit ws URL
31
+ return `
32
+ import startViteHMR from "${clientPath}";
33
+ console.log('[hmr-plugin-vue] starting client -> ${wsUrl}');
34
+ startViteHMR({ wsUrl: ${JSON.stringify(wsUrl)} });
35
+ `;
36
+ },
37
+ };
38
+ }
@@ -0,0 +1 @@
1
+ export declare function getHMRPlugins(platform: string, flavor: string, verboseLogs: boolean): import("vite").Plugin<any>[];
@@ -0,0 +1,16 @@
1
+ import { hmrPluginVue } from "./plugin-vue.js";
2
+ import { hmrWebSocketVue } from "./websocket-vue.js";
3
+ export function getHMRPlugins(platform, flavor, verboseLogs) {
4
+ switch (flavor) {
5
+ case "vue":
6
+ return [hmrPluginVue(platform, verboseLogs), hmrWebSocketVue()];
7
+ case "react":
8
+ return []; // TODO: add React HMR plugins
9
+ case "angular":
10
+ return []; // TODO: add Angular HMR plugins
11
+ case "solid":
12
+ return []; // TODO: add Solid HMR plugins
13
+ default:
14
+ return [];
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function hmrPluginVue(platform: string, verboseLogs?: boolean): Plugin;
@@ -0,0 +1,41 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+ const VIRTUAL_ID = "virtual:hmr-vue";
4
+ const RESOLVED_ID = "\0" + VIRTUAL_ID;
5
+ // TODO: make switch statement on flavors to load different flavor clients
6
+ export function hmrPluginVue(platform, verboseLogs = false) {
7
+ let config;
8
+ return {
9
+ name: "nativescript-hmr-vue",
10
+ configResolved(c) {
11
+ config = c;
12
+ },
13
+ resolveId(id) {
14
+ if (id === VIRTUAL_ID)
15
+ return RESOLVED_ID;
16
+ return null;
17
+ },
18
+ load(id) {
19
+ if (id !== RESOLVED_ID)
20
+ return null;
21
+ const clientPath = require.resolve("@nativescript/vite/dist/hmr/client-vue.js");
22
+ // Build ws url from Vite server info
23
+ const host = process.env.NS_HMR_HOST ||
24
+ config?.server?.host ||
25
+ (platform === 'android' ? "10.0.2.2" : "localhost");
26
+ const port = Number(config?.server?.port || 5173);
27
+ const secure = !!config?.server?.https;
28
+ const protocol = secure ? "wss" : "ws";
29
+ const wsUrl = `${protocol}://${host}:${port}/ns-hmr`;
30
+ // Import client and start it with explicit ws URL
31
+ const banner = verboseLogs
32
+ ? `console.log('[hmr-plugin-vue] starting client -> ${wsUrl}');`
33
+ : "";
34
+ return `
35
+ import startViteHMR from "${clientPath}";
36
+ ${banner}
37
+ startViteHMR({ wsUrl: ${JSON.stringify(wsUrl)} });
38
+ `;
39
+ },
40
+ };
41
+ }
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function hmrWebSocketVue(verboseLogs?: boolean): Plugin;