@nativescript/vite 0.0.1-alpha.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/dist/configuration/angular.d.ts +4 -0
- package/dist/configuration/angular.js +30 -0
- package/dist/configuration/base.d.ts +4 -0
- package/dist/configuration/base.js +270 -0
- package/dist/configuration/old-without-merge-base.d.ts +13 -0
- package/dist/configuration/old-without-merge-base.js +249 -0
- package/dist/configuration/react.d.ts +4 -0
- package/dist/configuration/react.js +85 -0
- package/dist/configuration/solid.d.ts +4 -0
- package/dist/configuration/solid.js +48 -0
- package/dist/configuration/vue.d.ts +4 -0
- package/dist/configuration/vue.js +45 -0
- package/dist/helpers/commonjs-plugins.d.ts +6 -0
- package/dist/helpers/commonjs-plugins.js +75 -0
- package/dist/helpers/config-as-json.d.ts +2 -0
- package/dist/helpers/config-as-json.js +35 -0
- package/dist/helpers/css-tree.d.ts +4 -0
- package/dist/helpers/css-tree.js +21 -0
- package/dist/helpers/dynamic-import-plugin.d.ts +4 -0
- package/dist/helpers/dynamic-import-plugin.js +62 -0
- package/dist/helpers/external-configs.d.ts +6 -0
- package/dist/helpers/external-configs.js +33 -0
- package/dist/helpers/flavor.d.ts +5 -0
- package/dist/helpers/flavor.js +40 -0
- package/dist/helpers/global-defines.d.ts +14 -0
- package/dist/helpers/global-defines.js +18 -0
- package/dist/helpers/main-entry.d.ts +5 -0
- package/dist/helpers/main-entry.js +75 -0
- package/dist/helpers/module-resolution.d.ts +1 -0
- package/dist/helpers/module-resolution.js +17 -0
- package/dist/helpers/nativescript-package-resolver.d.ts +5 -0
- package/dist/helpers/nativescript-package-resolver.js +139 -0
- package/dist/helpers/ns-cli-plugins.d.ts +19 -0
- package/dist/helpers/ns-cli-plugins.js +162 -0
- package/dist/helpers/package-platform-aliases.d.ts +4 -0
- package/dist/helpers/package-platform-aliases.js +83 -0
- package/dist/helpers/project.d.ts +23 -0
- package/dist/helpers/project.js +28 -0
- package/dist/helpers/resolver.d.ts +4 -0
- package/dist/helpers/resolver.js +31 -0
- package/dist/helpers/ts-config-paths.d.ts +4 -0
- package/dist/helpers/ts-config-paths.js +241 -0
- package/dist/helpers/utils.d.ts +29 -0
- package/dist/helpers/utils.js +101 -0
- package/dist/helpers/workers.d.ts +20 -0
- package/dist/helpers/workers.js +86 -0
- package/dist/hmr/hmr-angular.d.ts +1 -0
- package/dist/hmr/hmr-angular.js +34 -0
- package/dist/hmr/hmr-bridge.d.ts +18 -0
- package/dist/hmr/hmr-bridge.js +154 -0
- package/dist/hmr/hmr-client.d.ts +5 -0
- package/dist/hmr/hmr-client.js +93 -0
- package/dist/hmr/hmr-server.d.ts +20 -0
- package/dist/hmr/hmr-server.js +179 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/polyfills/mdn-data-at-rules.d.ts +7 -0
- package/dist/polyfills/mdn-data-at-rules.js +7 -0
- package/dist/polyfills/mdn-data-properties.d.ts +7 -0
- package/dist/polyfills/mdn-data-properties.js +7 -0
- package/dist/polyfills/mdn-data-syntaxes.d.ts +7 -0
- package/dist/polyfills/mdn-data-syntaxes.js +7 -0
- package/dist/polyfills/module.d.ts +17 -0
- package/dist/polyfills/module.js +29 -0
- package/dist/shims/react-reconciler-constants.d.ts +14 -0
- package/dist/shims/react-reconciler-constants.js +20 -0
- package/dist/shims/react-reconciler.d.ts +8 -0
- package/dist/shims/react-reconciler.js +14 -0
- package/dist/shims/set-value.d.ts +4 -0
- package/dist/shims/set-value.js +21 -0
- package/dist/transformers/NativeClass/index.d.ts +5 -0
- package/dist/transformers/NativeClass/index.js +46 -0
- package/package.json +31 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple HMR Notification Bridge
|
|
3
|
+
*
|
|
4
|
+
* This creates a lightweight WebSocket server that the NativeScript CLI
|
|
5
|
+
* can notify when builds complete, and forwards those to the app.
|
|
6
|
+
*/
|
|
7
|
+
import { WebSocketServer } from 'ws';
|
|
8
|
+
import WebSocketType from 'ws';
|
|
9
|
+
import { spawn } from 'child_process';
|
|
10
|
+
import { pathToFileURL } from 'node:url';
|
|
11
|
+
import { resolve } from 'node:path';
|
|
12
|
+
const isMain = () => typeof process !== 'undefined' &&
|
|
13
|
+
!!process.argv?.[1] &&
|
|
14
|
+
import.meta.url === pathToFileURL(resolve(process.argv[1])).href;
|
|
15
|
+
class SimpleHMRBridge {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.connectedClients = new Set();
|
|
18
|
+
}
|
|
19
|
+
async start() {
|
|
20
|
+
console.log('🔥 Starting Simple HMR Bridge...');
|
|
21
|
+
// Start WebSocket server for NativeScript app
|
|
22
|
+
this.startWebSocketServer();
|
|
23
|
+
// Start NativeScript build process
|
|
24
|
+
this.startNativeScriptBuild();
|
|
25
|
+
console.log('🔥 HMR Bridge ready!');
|
|
26
|
+
}
|
|
27
|
+
startWebSocketServer() {
|
|
28
|
+
const HMR_WS_PORT = 24678;
|
|
29
|
+
this.wsServer = new WebSocketServer({ port: HMR_WS_PORT });
|
|
30
|
+
this.wsServer.on('connection', (ws) => {
|
|
31
|
+
console.log('🔥 NativeScript client connected to HMR bridge');
|
|
32
|
+
this.connectedClients.add(ws);
|
|
33
|
+
// Send connection confirmation
|
|
34
|
+
ws.send(JSON.stringify({
|
|
35
|
+
type: 'connected',
|
|
36
|
+
timestamp: Date.now()
|
|
37
|
+
}));
|
|
38
|
+
ws.on('close', () => {
|
|
39
|
+
console.log('🔥 NativeScript client disconnected');
|
|
40
|
+
this.connectedClients.delete(ws);
|
|
41
|
+
});
|
|
42
|
+
ws.on('message', (message) => {
|
|
43
|
+
try {
|
|
44
|
+
const data = JSON.parse(message.toString());
|
|
45
|
+
console.log('🔥 Received from NativeScript:', data);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error('🔥 Invalid message from NativeScript:', e);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
console.log(`🔥 HMR bridge listening on ws://localhost:${HMR_WS_PORT}`);
|
|
53
|
+
}
|
|
54
|
+
startNativeScriptBuild() {
|
|
55
|
+
console.log('🔥 Starting NativeScript build with HMR notifications...');
|
|
56
|
+
// Get platform from command line arguments (default to 'ios' if not provided)
|
|
57
|
+
const platform = process.argv[2] || 'ios';
|
|
58
|
+
console.log(`🔥 Building for platform: ${platform}`);
|
|
59
|
+
// Start ns run with specified platform
|
|
60
|
+
const args = ['debug', platform];
|
|
61
|
+
this.buildProcess = spawn('ns', args, {
|
|
62
|
+
cwd: process.cwd(),
|
|
63
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
64
|
+
env: {
|
|
65
|
+
...process.env,
|
|
66
|
+
NS_HMR_BRIDGE: 'true' // Signal to our Vite config that HMR bridge is active
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
this.buildProcess.stdout.on('data', (data) => {
|
|
70
|
+
const output = data.toString();
|
|
71
|
+
process.stdout.write(output);
|
|
72
|
+
// Listen for build completion messages
|
|
73
|
+
this.parseBuildOutput(output);
|
|
74
|
+
});
|
|
75
|
+
this.buildProcess.stderr.on('data', (data) => {
|
|
76
|
+
process.stderr.write(data);
|
|
77
|
+
});
|
|
78
|
+
this.buildProcess.on('close', (code) => {
|
|
79
|
+
console.log(`🔥 NativeScript build process exited with code ${code}`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
parseBuildOutput(output) {
|
|
83
|
+
// Look for our HMR indicators in the build output
|
|
84
|
+
const lines = output.split('\n');
|
|
85
|
+
for (const line of lines) {
|
|
86
|
+
// Look for our HMR build completion messages
|
|
87
|
+
if (line.includes('🔥 HMR update - copying only changed files')) {
|
|
88
|
+
// Extract changed files from the next lines
|
|
89
|
+
const changedFilesMatch = line.match(/🔥 HMR update - copying only changed files for: (.+)/);
|
|
90
|
+
if (changedFilesMatch) {
|
|
91
|
+
try {
|
|
92
|
+
const changedFiles = JSON.parse(changedFilesMatch[1].replace(/'/g, '"'));
|
|
93
|
+
this.notifyClients({
|
|
94
|
+
type: 'build-complete',
|
|
95
|
+
timestamp: Date.now(),
|
|
96
|
+
changedFiles,
|
|
97
|
+
buildType: 'incremental',
|
|
98
|
+
isHMR: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.log('🔥 Could not parse changed files from:', changedFilesMatch[1]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (line.includes('🔥 Full build - copying all files')) {
|
|
107
|
+
this.notifyClients({
|
|
108
|
+
type: 'build-complete',
|
|
109
|
+
timestamp: Date.now(),
|
|
110
|
+
buildType: 'full',
|
|
111
|
+
isHMR: false
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else if (line.includes('Vite build completed!')) {
|
|
115
|
+
// Build is done, notify clients
|
|
116
|
+
console.log('🔥 Build completed, notifying clients...');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
notifyClients(update) {
|
|
121
|
+
const message = JSON.stringify(update);
|
|
122
|
+
let sentCount = 0;
|
|
123
|
+
this.connectedClients.forEach((client) => {
|
|
124
|
+
if (client.readyState === WebSocketType.OPEN) {
|
|
125
|
+
client.send(message);
|
|
126
|
+
sentCount++;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
if (sentCount > 0) {
|
|
130
|
+
console.log(`🔥 Notified ${sentCount} clients of update:`, update.type);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async stop() {
|
|
134
|
+
console.log('🔥 Stopping HMR bridge...');
|
|
135
|
+
if (this.buildProcess) {
|
|
136
|
+
this.buildProcess.kill('SIGTERM');
|
|
137
|
+
}
|
|
138
|
+
if (this.wsServer) {
|
|
139
|
+
this.wsServer.close();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Export for use in startup script
|
|
144
|
+
export { SimpleHMRBridge };
|
|
145
|
+
// Auto-start if run directly
|
|
146
|
+
if (isMain()) {
|
|
147
|
+
const bridge = new SimpleHMRBridge();
|
|
148
|
+
bridge.start().catch(console.error);
|
|
149
|
+
// Handle graceful shutdown
|
|
150
|
+
process.on('SIGINT', () => {
|
|
151
|
+
console.log('\n🔥 Shutting down HMR bridge...');
|
|
152
|
+
bridge.stop().then(() => process.exit(0));
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 };
|
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
// }
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock for mdn-data/css/at-rules.json
|
|
3
|
+
* Returns empty object since css-tree has its own comprehensive data
|
|
4
|
+
* This prevents css-tree from failing when trying to patch its data
|
|
5
|
+
*/
|
|
6
|
+
// Return empty object - css-tree will use its built-in data instead
|
|
7
|
+
export default {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock for mdn-data/css/properties.json
|
|
3
|
+
* Returns empty object since css-tree has its own comprehensive data
|
|
4
|
+
* This prevents css-tree from failing when trying to patch its data
|
|
5
|
+
*/
|
|
6
|
+
// Return empty object - css-tree will use its built-in data instead
|
|
7
|
+
export default {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock for mdn-data/css/syntaxes.json
|
|
3
|
+
* Returns empty object since css-tree has its own comprehensive data
|
|
4
|
+
* This prevents css-tree from failing when trying to patch its data
|
|
5
|
+
*/
|
|
6
|
+
// Return empty object - css-tree will use its built-in data instead
|
|
7
|
+
export default {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for Node.js 'module' built-in
|
|
3
|
+
* Provides minimal implementation for NativeScript environment
|
|
4
|
+
*/
|
|
5
|
+
export declare function createRequire(filename: string): (id: string) => {
|
|
6
|
+
atrules: {};
|
|
7
|
+
properties: {};
|
|
8
|
+
types: {};
|
|
9
|
+
} | {
|
|
10
|
+
atrules?: undefined;
|
|
11
|
+
properties?: undefined;
|
|
12
|
+
types?: undefined;
|
|
13
|
+
};
|
|
14
|
+
declare const _default: {
|
|
15
|
+
createRequire: typeof createRequire;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for Node.js 'module' built-in
|
|
3
|
+
* Provides minimal implementation for NativeScript environment
|
|
4
|
+
*/
|
|
5
|
+
// Mock createRequire function that css-tree uses
|
|
6
|
+
export function createRequire(filename) {
|
|
7
|
+
// Return a mock require function
|
|
8
|
+
return function mockRequire(id) {
|
|
9
|
+
// Handle css-tree's internal patch.json file
|
|
10
|
+
if (id.includes('../data/patch.json') || id.includes('patch.json')) {
|
|
11
|
+
// Return css-tree's patch structure
|
|
12
|
+
return {
|
|
13
|
+
atrules: {},
|
|
14
|
+
properties: {},
|
|
15
|
+
types: {},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// For mdn-data files, return empty objects
|
|
19
|
+
if (id.includes('mdn-data')) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
// For any other requires, return empty object
|
|
23
|
+
return {};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// Also export as default for compatibility
|
|
27
|
+
export default {
|
|
28
|
+
createRequire: createRequire,
|
|
29
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const DefaultEventPriority = 16;
|
|
2
|
+
export declare const DiscreteEventPriority = 1;
|
|
3
|
+
export declare const ContinuousEventPriority = 4;
|
|
4
|
+
export declare const IdleEventPriority = 268435456;
|
|
5
|
+
export declare const ConcurrentMode = 1;
|
|
6
|
+
export declare const ProfileMode = 2;
|
|
7
|
+
export declare const StrictMode = 8;
|
|
8
|
+
export declare const NoMode = 0;
|
|
9
|
+
export declare const BlockingMode = 2;
|
|
10
|
+
export declare const DebugTracingMode = 4;
|
|
11
|
+
export declare const StrictLegacyMode = 16;
|
|
12
|
+
export declare const StrictEffectsMode = 32;
|
|
13
|
+
export declare const LegacyRoot = 0;
|
|
14
|
+
export declare const ConcurrentRoot = 1;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Shim for react-reconciler/constants.js to handle missing exports
|
|
2
|
+
// This addresses the issue where react-nativescript tries to import
|
|
3
|
+
// exports that don't exist in the current version of react-reconciler
|
|
4
|
+
// Event priorities (these are the primary values react-nativescript needs)
|
|
5
|
+
export const DefaultEventPriority = 16;
|
|
6
|
+
export const DiscreteEventPriority = 1;
|
|
7
|
+
export const ContinuousEventPriority = 4;
|
|
8
|
+
export const IdleEventPriority = 268435456;
|
|
9
|
+
// Mode constants
|
|
10
|
+
export const ConcurrentMode = 1;
|
|
11
|
+
export const ProfileMode = 2;
|
|
12
|
+
export const StrictMode = 8;
|
|
13
|
+
export const NoMode = 0;
|
|
14
|
+
export const BlockingMode = 2;
|
|
15
|
+
export const DebugTracingMode = 4;
|
|
16
|
+
export const StrictLegacyMode = 16;
|
|
17
|
+
export const StrictEffectsMode = 32;
|
|
18
|
+
// Root modes (required by react-nativescript)
|
|
19
|
+
export const LegacyRoot = 0;
|
|
20
|
+
export const ConcurrentRoot = 1;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shim for react-reconciler to fix namespace call issues
|
|
3
|
+
* This resolves the "Cannot call a namespace" error
|
|
4
|
+
*/
|
|
5
|
+
// Import the actual reconciler
|
|
6
|
+
import * as ReactReconcilerModule from 'react-reconciler';
|
|
7
|
+
// Export the reconciler as a callable function, not a namespace
|
|
8
|
+
const ReactReconciler = ReactReconcilerModule.default || ReactReconcilerModule;
|
|
9
|
+
// Re-export everything from the module
|
|
10
|
+
export * from 'react-reconciler';
|
|
11
|
+
// Export the main reconciler function
|
|
12
|
+
export default ReactReconciler;
|
|
13
|
+
// Also export as named export for compatibility
|
|
14
|
+
export { ReactReconciler };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shim for set-value commonjs package export
|
|
3
|
+
*/
|
|
4
|
+
export default function setValue(obj, path, value) {
|
|
5
|
+
if (!obj)
|
|
6
|
+
return obj;
|
|
7
|
+
const parts = Array.isArray(path)
|
|
8
|
+
? path
|
|
9
|
+
: String(path).replace(/\[(\d+)\]/g, '.$1').split('.').filter(Boolean);
|
|
10
|
+
let cur = obj;
|
|
11
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
12
|
+
const k = parts[i];
|
|
13
|
+
const next = parts[i + 1];
|
|
14
|
+
if (cur[k] == null || typeof cur[k] !== 'object') {
|
|
15
|
+
cur[k] = /^\d+$/.test(next) ? [] : {};
|
|
16
|
+
}
|
|
17
|
+
cur = cur[k];
|
|
18
|
+
}
|
|
19
|
+
cur[parts[parts.length - 1]] = value;
|
|
20
|
+
return obj;
|
|
21
|
+
}
|