@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
@@ -1,93 +0,0 @@
1
- /**
2
- * Simple NativeScript HMR Client for Vite
3
- * Based on @nativescript/webpack loaders but simplified for Vite
4
- */
5
- // Import WebSocket polyfill directly
6
- import { WebSocket as NativeScriptWebSocket } from '@valor/nativescript-websockets/websocket';
7
- // Ensure WebSocket is available globally for other code
8
- if (typeof global !== 'undefined') {
9
- global.WebSocket = NativeScriptWebSocket;
10
- }
11
- // Make WebSocket available in current scope
12
- const WebSocket = NativeScriptWebSocket;
13
- // import { Application } from "@nativescript/core";
14
- let hmrBootEmittedSymbol = Symbol.for("HMRBootEmitted");
15
- let originalLiveSyncSymbol = Symbol.for("OriginalLiveSync");
16
- let hmrRuntimeLastLiveSyncSymbol = Symbol.for("HMRRuntimeLastLiveSync");
17
- if (global.__onLiveSync !== global[hmrRuntimeLastLiveSyncSymbol]) {
18
- // we store the original liveSync here in case this code runs again
19
- // which happens when you module.hot.accept() the main file
20
- global[originalLiveSyncSymbol] = global.__onLiveSync;
21
- }
22
- global[hmrRuntimeLastLiveSyncSymbol] = async function () {
23
- console.log(`calling global[hmrRuntimeLastLiveSyncSymbol]`);
24
- await global[originalLiveSyncSymbol]();
25
- };
26
- global.__onLiveSync = global[hmrRuntimeLastLiveSyncSymbol];
27
- if (!global[hmrBootEmittedSymbol]) {
28
- global[hmrBootEmittedSymbol] = true;
29
- }
30
- /**
31
- * Note: allow vite to inject each flavor client handling
32
- * Start Manual Flavor Testing
33
- */
34
- const flavor = "angular";
35
- import { handleAngularHmrUpdate } from "./hmr-angular.js";
36
- /**
37
- * End Manual Flavor Testing
38
- */
39
- class SimpleNativeScriptHMRClient {
40
- constructor() {
41
- this.ws = null;
42
- console.log("🔥 Simple HMR Client starting...");
43
- console.log("🔥 WebSocket available:", typeof WebSocket !== 'undefined');
44
- console.log("🔥 global.WebSocket available:", typeof global !== 'undefined' && typeof global.WebSocket !== 'undefined');
45
- this.connect();
46
- }
47
- connect() {
48
- try {
49
- // Check if WebSocket is available
50
- if (typeof WebSocket === 'undefined') {
51
- console.error("🔥 WebSocket is not available - HMR disabled");
52
- return;
53
- }
54
- this.ws = new WebSocket("ws://localhost:24678");
55
- this.ws.onopen = () => {
56
- console.log("🔥 HMR connected");
57
- };
58
- this.ws.onmessage = (event) => {
59
- try {
60
- const update = JSON.parse(event.data);
61
- this.handleUpdate(update);
62
- }
63
- catch (error) {
64
- console.error("🔥 HMR message error:", error);
65
- }
66
- };
67
- }
68
- catch (error) {
69
- console.error("🔥 HMR connection failed:", error);
70
- }
71
- }
72
- handleUpdate(update) {
73
- console.log("🔥 HMR update received:", update.type);
74
- if (update.type === "build-complete" && update.isHMR) {
75
- // skip very first one since it's initial build
76
- console.log("🔥 Applying HMR update for:", update.changedFiles);
77
- switch (flavor) {
78
- case "angular":
79
- // Handle Angular specific HMR updates
80
- handleAngularHmrUpdate();
81
- break;
82
- }
83
- }
84
- }
85
- }
86
- // Initialize on app launch
87
- let hmrClient;
88
- if (!hmrClient) {
89
- console.log("🔥 Initializing Simple NativeScript HMR Client");
90
- // Application.on(Application.launchEvent, () => {
91
- hmrClient = new SimpleNativeScriptHMRClient();
92
- // });
93
- }
@@ -1,20 +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
- declare class NativeScriptHMRServer {
8
- private viteServer;
9
- private wsServer;
10
- private buildProcess;
11
- private connectedClients;
12
- start(): Promise<void>;
13
- private startViteDevServer;
14
- private startHMRBridge;
15
- private handleViteHMRMessage;
16
- private broadcastToClients;
17
- private startBuildProcess;
18
- stop(): Promise<void>;
19
- }
20
- export { NativeScriptHMRServer };
@@ -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
- // }