@nativescript/vite 0.0.1-alpha.0 → 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 +178 -71
  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 +3 -3
  8. package/dist/helpers/main-entry.js +61 -54
  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 +4 -14
  12. package/dist/helpers/ns-cli-plugins.js +124 -101
  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/preserve-imports.d.ts +2 -0
  16. package/dist/helpers/preserve-imports.js +19 -0
  17. package/dist/helpers/ts-config-paths.d.ts +1 -1
  18. package/dist/helpers/ts-config-paths.js +6 -4
  19. package/dist/hmr/client-vue.d.ts +6 -0
  20. package/dist/hmr/client-vue.js +563 -0
  21. package/dist/hmr/component-tracker.d.ts +23 -0
  22. package/dist/hmr/component-tracker.js +193 -0
  23. package/dist/hmr/css-handler.d.ts +4 -0
  24. package/dist/hmr/css-handler.js +77 -0
  25. package/dist/hmr/message-handler.d.ts +1 -0
  26. package/dist/hmr/message-handler.js +590 -0
  27. package/dist/hmr/nsv-hooks.d.ts +2 -0
  28. package/dist/hmr/nsv-hooks.js +481 -0
  29. package/dist/hmr/plugin-vue.d.ts +2 -0
  30. package/dist/hmr/plugin-vue.js +38 -0
  31. package/dist/hmr/plugins/index.d.ts +1 -0
  32. package/dist/hmr/plugins/index.js +16 -0
  33. package/dist/hmr/plugins/plugin-vue.d.ts +2 -0
  34. package/dist/hmr/plugins/plugin-vue.js +41 -0
  35. package/dist/hmr/plugins/websocket-vue.d.ts +2 -0
  36. package/dist/hmr/plugins/websocket-vue.js +882 -0
  37. package/dist/hmr/runtime-vue.d.ts +13 -0
  38. package/dist/hmr/runtime-vue.js +2306 -0
  39. package/dist/hmr/types.d.ts +24 -0
  40. package/dist/hmr/types.js +2 -0
  41. package/dist/hmr/websocket-vue.d.ts +2 -0
  42. package/dist/hmr/websocket-vue.js +875 -0
  43. package/dist/shims/node-module.d.ts +5 -0
  44. package/dist/shims/node-module.js +12 -0
  45. package/package.json +2 -1
  46. package/dist/configuration/old-without-merge-base.d.ts +0 -13
  47. package/dist/configuration/old-without-merge-base.js +0 -249
  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
@@ -1,179 +0,0 @@
1
- /**
2
- * NativeScript True HMR Implementation
3
- *
4
- * This creates a bridge between Vite's dev server HMR and NativeScript runtime
5
- * to enable true hot module replacement without losing application state.
6
- */
7
- import { createServer } from 'vite';
8
- import { spawn } from 'child_process';
9
- import { WebSocketServer, WebSocket } from 'ws';
10
- import path from 'path';
11
- import fs from 'fs';
12
- import { getProjectFilePath } from '../helpers/project.js';
13
- const HMR_WS_PORT = 24678; // Different from Vite's default
14
- const VITE_DEV_PORT = 5173;
15
- class NativeScriptHMRServer {
16
- constructor() {
17
- this.connectedClients = new Set();
18
- }
19
- async start() {
20
- console.log('🔥 Starting NativeScript True HMR...');
21
- // 1. Start Vite dev server for true HMR
22
- await this.startViteDevServer();
23
- // 2. Start WebSocket bridge for NativeScript
24
- await this.startHMRBridge();
25
- // 3. Start build process for NativeScript integration
26
- await this.startBuildProcess();
27
- console.log('🔥 True HMR ready! Connect your NativeScript app.');
28
- }
29
- async startViteDevServer() {
30
- console.log('🔥 Starting Vite dev server...');
31
- this.viteServer = await createServer({
32
- configFile: getProjectFilePath('vite.config.ts'),
33
- server: {
34
- port: VITE_DEV_PORT,
35
- hmr: {
36
- port: VITE_DEV_PORT + 1, // Vite's internal HMR port
37
- }
38
- },
39
- mode: 'ios' // or get from args
40
- });
41
- await this.viteServer.listen();
42
- console.log(`🔥 Vite dev server running on http://localhost:${VITE_DEV_PORT}`);
43
- // Hook into Vite's HMR system
44
- this.viteServer.ws.on('send', (data) => {
45
- this.handleViteHMRMessage(data);
46
- });
47
- }
48
- async startHMRBridge() {
49
- console.log('🔥 Starting HMR WebSocket bridge...');
50
- this.wsServer = new WebSocketServer({ port: HMR_WS_PORT });
51
- this.wsServer.on('connection', (ws) => {
52
- console.log('🔥 NativeScript client connected to HMR bridge');
53
- this.connectedClients.add(ws);
54
- // Send connection confirmation
55
- ws.send(JSON.stringify({
56
- type: 'connected',
57
- timestamp: Date.now()
58
- }));
59
- ws.on('close', () => {
60
- console.log('🔥 NativeScript client disconnected');
61
- this.connectedClients.delete(ws);
62
- });
63
- ws.on('message', (message) => {
64
- try {
65
- const data = JSON.parse(message.toString());
66
- console.log('🔥 Received from NativeScript:', data);
67
- }
68
- catch (e) {
69
- console.error('🔥 Invalid message from NativeScript:', e);
70
- }
71
- });
72
- });
73
- console.log(`🔥 HMR bridge listening on ws://localhost:${HMR_WS_PORT}`);
74
- }
75
- handleViteHMRMessage(data) {
76
- if (!data || typeof data !== 'object')
77
- return;
78
- // Filter out irrelevant file changes
79
- if (data.updates) {
80
- const relevantUpdates = data.updates.filter(update => {
81
- const path = update.path || '';
82
- return (path.includes('/src/') ||
83
- path.endsWith('package.json') ||
84
- path.endsWith('vite.config.ts') ||
85
- path.endsWith('tsconfig.json') ||
86
- path.endsWith('nativescript.config.ts'));
87
- });
88
- if (relevantUpdates.length === 0) {
89
- console.log('🔥 Ignoring HMR update for non-src files');
90
- return; // Skip if no relevant updates
91
- }
92
- data.updates = relevantUpdates;
93
- }
94
- console.log('🔥 Vite HMR update:', data);
95
- // Transform Vite HMR message to NativeScript format
96
- let hmrUpdate;
97
- if (data.type === 'update') {
98
- // CSS updates
99
- const cssUpdates = data.updates?.filter(u => u.path.endsWith('.css') || u.path.endsWith('.scss'));
100
- if (cssUpdates?.length > 0) {
101
- hmrUpdate = {
102
- type: 'css-update',
103
- path: cssUpdates[0].path,
104
- timestamp: Date.now(),
105
- updates: cssUpdates
106
- };
107
- }
108
- // JS/TS updates
109
- else {
110
- hmrUpdate = {
111
- type: 'js-update',
112
- timestamp: Date.now(),
113
- updates: data.updates
114
- };
115
- }
116
- }
117
- else if (data.type === 'full-reload') {
118
- hmrUpdate = {
119
- type: 'full-reload',
120
- timestamp: Date.now()
121
- };
122
- }
123
- else {
124
- return; // Ignore other message types
125
- }
126
- // Broadcast to connected NativeScript clients
127
- this.broadcastToClients(hmrUpdate);
128
- }
129
- broadcastToClients(update) {
130
- const message = JSON.stringify(update);
131
- let sentCount = 0;
132
- this.connectedClients.forEach((client) => {
133
- if (client.readyState === WebSocket.OPEN) {
134
- client.send(message);
135
- sentCount++;
136
- }
137
- });
138
- console.log(`🔥 Broadcasted ${update.type} to ${sentCount} clients`);
139
- }
140
- async startBuildProcess() {
141
- // This runs the traditional build process for initial bundle creation
142
- // but won't be used for HMR - that's handled by the dev server
143
- console.log('🔥 Starting initial build process...');
144
- // We might not need this if we can serve directly from Vite dev server
145
- // But keeping it for compatibility with NativeScript CLI expectations
146
- }
147
- async stop() {
148
- console.log('🔥 Stopping HMR server...');
149
- if (this.viteServer) {
150
- await this.viteServer.close();
151
- }
152
- if (this.wsServer) {
153
- this.wsServer.close();
154
- }
155
- if (this.buildProcess) {
156
- this.buildProcess.kill();
157
- }
158
- }
159
- }
160
- // CLI interface
161
- async function main() {
162
- const hmrServer = new NativeScriptHMRServer();
163
- // Handle graceful shutdown
164
- process.on('SIGINT', async () => {
165
- await hmrServer.stop();
166
- process.exit(0);
167
- });
168
- process.on('SIGTERM', async () => {
169
- await hmrServer.stop();
170
- process.exit(0);
171
- });
172
- await hmrServer.start();
173
- }
174
- // Export for use in other contexts
175
- export { NativeScriptHMRServer };
176
- // Run if called directly
177
- // if (require.main === module) {
178
- // main().catch(console.error);
179
- // }