@nativescript/vite 0.0.1

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 (71) hide show
  1. package/dist/configuration/angular.d.ts +4 -0
  2. package/dist/configuration/angular.js +30 -0
  3. package/dist/configuration/base.d.ts +13 -0
  4. package/dist/configuration/base.js +228 -0
  5. package/dist/configuration/old-without-merge-base.d.ts +13 -0
  6. package/dist/configuration/old-without-merge-base.js +249 -0
  7. package/dist/configuration/react.d.ts +4 -0
  8. package/dist/configuration/react.js +85 -0
  9. package/dist/configuration/solid.d.ts +4 -0
  10. package/dist/configuration/solid.js +48 -0
  11. package/dist/configuration/vue.d.ts +4 -0
  12. package/dist/configuration/vue.js +45 -0
  13. package/dist/helpers/commonjs-plugins.d.ts +6 -0
  14. package/dist/helpers/commonjs-plugins.js +75 -0
  15. package/dist/helpers/config-as-json.d.ts +2 -0
  16. package/dist/helpers/config-as-json.js +35 -0
  17. package/dist/helpers/css-tree.d.ts +4 -0
  18. package/dist/helpers/css-tree.js +21 -0
  19. package/dist/helpers/dynamic-import-plugin.d.ts +4 -0
  20. package/dist/helpers/dynamic-import-plugin.js +62 -0
  21. package/dist/helpers/flavor.d.ts +5 -0
  22. package/dist/helpers/flavor.js +40 -0
  23. package/dist/helpers/global-defines.d.ts +14 -0
  24. package/dist/helpers/global-defines.js +18 -0
  25. package/dist/helpers/main-entry.d.ts +5 -0
  26. package/dist/helpers/main-entry.js +75 -0
  27. package/dist/helpers/module-resolution.d.ts +1 -0
  28. package/dist/helpers/module-resolution.js +17 -0
  29. package/dist/helpers/nativescript-package-resolver.d.ts +5 -0
  30. package/dist/helpers/nativescript-package-resolver.js +139 -0
  31. package/dist/helpers/ns-cli-plugins.d.ts +17 -0
  32. package/dist/helpers/ns-cli-plugins.js +128 -0
  33. package/dist/helpers/package-platform-aliases.d.ts +4 -0
  34. package/dist/helpers/package-platform-aliases.js +83 -0
  35. package/dist/helpers/project.d.ts +23 -0
  36. package/dist/helpers/project.js +28 -0
  37. package/dist/helpers/resolver.d.ts +4 -0
  38. package/dist/helpers/resolver.js +31 -0
  39. package/dist/helpers/ts-config-paths.d.ts +4 -0
  40. package/dist/helpers/ts-config-paths.js +241 -0
  41. package/dist/helpers/utils.d.ts +23 -0
  42. package/dist/helpers/utils.js +94 -0
  43. package/dist/helpers/workers.d.ts +20 -0
  44. package/dist/helpers/workers.js +86 -0
  45. package/dist/hmr/hmr-angular.d.ts +1 -0
  46. package/dist/hmr/hmr-angular.js +34 -0
  47. package/dist/hmr/hmr-bridge.d.ts +18 -0
  48. package/dist/hmr/hmr-bridge.js +154 -0
  49. package/dist/hmr/hmr-client.d.ts +5 -0
  50. package/dist/hmr/hmr-client.js +93 -0
  51. package/dist/hmr/hmr-server.d.ts +20 -0
  52. package/dist/hmr/hmr-server.js +179 -0
  53. package/dist/index.d.ts +5 -0
  54. package/dist/index.js +5 -0
  55. package/dist/polyfills/mdn-data-at-rules.d.ts +7 -0
  56. package/dist/polyfills/mdn-data-at-rules.js +7 -0
  57. package/dist/polyfills/mdn-data-properties.d.ts +7 -0
  58. package/dist/polyfills/mdn-data-properties.js +7 -0
  59. package/dist/polyfills/mdn-data-syntaxes.d.ts +7 -0
  60. package/dist/polyfills/mdn-data-syntaxes.js +7 -0
  61. package/dist/polyfills/module.d.ts +17 -0
  62. package/dist/polyfills/module.js +29 -0
  63. package/dist/shims/react-reconciler-constants.d.ts +14 -0
  64. package/dist/shims/react-reconciler-constants.js +20 -0
  65. package/dist/shims/react-reconciler.d.ts +8 -0
  66. package/dist/shims/react-reconciler.js +14 -0
  67. package/dist/shims/set-value.d.ts +4 -0
  68. package/dist/shims/set-value.js +21 -0
  69. package/dist/transformers/NativeClass/index.d.ts +5 -0
  70. package/dist/transformers/NativeClass/index.js +46 -0
  71. package/package.json +31 -0
@@ -0,0 +1,94 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { transformSync } from "esbuild";
4
+ import { satisfies } from "semver";
5
+ import { createRequire } from 'node:module';
6
+ const require = createRequire(import.meta.url);
7
+ import { getPackageJson, getProjectFilePath } from "./project.js";
8
+ // get the name from the package for the output
9
+ const packageJson = getPackageJson();
10
+ export function nsConfigToJson() {
11
+ let configObject;
12
+ ;
13
+ const tsPath = getProjectFilePath("nativescript.config.ts");
14
+ const tsCode = fs.readFileSync(tsPath, "utf-8");
15
+ // a) Transpile your TS config to CommonJS so we can require() it
16
+ const { code: cjsCode } = transformSync(tsCode, {
17
+ loader: "ts",
18
+ format: "cjs",
19
+ target: "esnext",
20
+ });
21
+ // b) Evaluate it in a VM-style sandbox to pull out the default export
22
+ const module = { exports: {} };
23
+ const requireFunc = (id) => require(id);
24
+ new Function("exports", "require", "module", "__filename", "__dirname", cjsCode)(module.exports, requireFunc, module, tsPath, path.dirname(tsPath));
25
+ configObject = module.exports.default ?? module.exports;
26
+ // ensure the config has a name
27
+ configObject.name = packageJson.name;
28
+ // ensure the main entry is set to "bundle"
29
+ configObject.main = "bundle";
30
+ return configObject;
31
+ }
32
+ /**
33
+ * Resolves the NativeScript platform-specific file for a given module ID.
34
+ * @param id The module ID to resolve.
35
+ * @param platform The target platform (e.g., "ios", "android").
36
+ * @returns The resolved file path or undefined if not found.
37
+ */
38
+ export function resolveNativeScriptPlatformFile(id, platform) {
39
+ const ext = path.extname(id);
40
+ const base = id.slice(0, -ext.length);
41
+ let platformFile = `${base}.${platform}${ext}`;
42
+ if (fs.existsSync(platformFile)) {
43
+ return platformFile;
44
+ }
45
+ // core uses indices for many barrels
46
+ platformFile = `${base}/index.${platform}${ext}`;
47
+ if (fs.existsSync(platformFile)) {
48
+ return platformFile;
49
+ }
50
+ // fallback to non-platform file
51
+ return fs.existsSync(id) ? id : undefined;
52
+ }
53
+ /**
54
+ * Utility to get all dependencies from the project package.json.
55
+ * The result combines dependencies and devDependencies
56
+ *
57
+ * @returns string[] dependencies
58
+ */
59
+ export function getAllDependencies() {
60
+ return [
61
+ ...Object.keys(packageJson.dependencies ?? {}),
62
+ ...Object.keys(packageJson.devDependencies ?? {}),
63
+ ];
64
+ }
65
+ /**
66
+ * Check if a dependency is present in package.json
67
+ */
68
+ export function hasDependency(packageName) {
69
+ try {
70
+ const packageJsonPath = path.resolve(process.cwd(), "package.json");
71
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
72
+ return !!(packageJson.dependencies?.[packageName] ||
73
+ packageJson.devDependencies?.[packageName] ||
74
+ packageJson.peerDependencies?.[packageName]);
75
+ }
76
+ catch {
77
+ return false;
78
+ }
79
+ }
80
+ /**
81
+ * Get the version of a dependency from package.json
82
+ */
83
+ export function getDependencyVersion(packageName) {
84
+ try {
85
+ const packageJsonPath = path.resolve(process.cwd(), "package.json");
86
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
87
+ return (packageJson.dependencies?.[packageName] ||
88
+ packageJson.devDependencies?.[packageName] ||
89
+ packageJson.peerDependencies?.[packageName]);
90
+ }
91
+ catch {
92
+ return undefined;
93
+ }
94
+ }
@@ -0,0 +1,20 @@
1
+ export declare function getWorkerPlugins(platform: string): ({
2
+ name: string;
3
+ resolveId(id: any): string;
4
+ load(id: any): string;
5
+ transform?: undefined;
6
+ } | {
7
+ name: string;
8
+ resolveId(id: any, importer: any): string;
9
+ load?: undefined;
10
+ transform?: undefined;
11
+ } | {
12
+ name: string;
13
+ transform(code: any, id: any): any;
14
+ resolveId?: undefined;
15
+ load?: undefined;
16
+ })[];
17
+ export declare function workerUrlPlugin(): {
18
+ name: string;
19
+ generateBundle(options: any, bundle: any): void;
20
+ };
@@ -0,0 +1,86 @@
1
+ import path from "path";
2
+ import { nsConfigToJson, resolveNativeScriptPlatformFile } from "./utils.js";
3
+ export function getWorkerPlugins(platform) {
4
+ return [
5
+ // Handle ~/package.json virtual module for workers
6
+ {
7
+ name: "worker-virtual-package-json",
8
+ resolveId(id) {
9
+ if (id === "~/package.json") {
10
+ return "\0worker:nsconfig-json"; // Use a completely different virtual ID that doesn't look like JSON
11
+ }
12
+ return null;
13
+ },
14
+ load(id) {
15
+ if (id === "\0worker:nsconfig-json") {
16
+ const configObject = nsConfigToJson();
17
+ // Return the NativeScript config as a JavaScript module
18
+ return `export default ${JSON.stringify(configObject, null, 2)};`;
19
+ }
20
+ return null;
21
+ },
22
+ },
23
+ // Resolve NativeScript platform-specific files for workers
24
+ {
25
+ name: "nativescript-platform-resolver-worker",
26
+ resolveId(id, importer) {
27
+ // Handle relative imports from node_modules (not just @nativescript/core)
28
+ if (importer) {
29
+ const resolvedPath = path.resolve(path.dirname(importer), id);
30
+ // Try different extensions with platform-specific resolution
31
+ const extensions = [".js", ".mjs", ".ts", ".vue"];
32
+ for (const ext of extensions) {
33
+ const testPath = resolvedPath + ext;
34
+ // Use the existing NativeScript platform file resolver
35
+ const platformResolvedFile = resolveNativeScriptPlatformFile(testPath, platform);
36
+ if (platformResolvedFile) {
37
+ return platformResolvedFile;
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+ return null;
43
+ },
44
+ },
45
+ // Handle import.meta expressions in workers
46
+ {
47
+ name: "worker-import-meta-handler",
48
+ transform(code, id) {
49
+ // Replace import.meta.dirname with a static value for workers
50
+ if (code.includes("import.meta.dirname")) {
51
+ code = code.replace(/import\.meta\.dirname/g, '""');
52
+ }
53
+ // Replace import.meta.url with a static value for workers
54
+ if (code.includes("import.meta.url")) {
55
+ code = code.replace(/import\.meta\.url/g, '"file:///app/"');
56
+ }
57
+ return code;
58
+ },
59
+ },
60
+ ];
61
+ }
62
+ export function workerUrlPlugin() {
63
+ return {
64
+ name: "nativescript-worker-url-transform",
65
+ generateBundle(options, bundle) {
66
+ // Transform the main bundle to use NativeScript worker paths
67
+ for (const [fileName, chunk] of Object.entries(bundle)) {
68
+ if (chunk.type === "chunk" && !fileName.includes(".worker")) {
69
+ // Transform Vite's worker URL pattern to NativeScript's expected format
70
+ // From: new Worker(new URL(/* @vite-ignore */ "/assets/sample.worker-C6wW8q2-.js", import.meta.url))
71
+ // To: new Worker('~/' + 'assets/sample.worker-C6wW8q2-.js')
72
+ const workerUrlRegex = /new\s+Worker\s*\(\s*new\s+URL\s*\(\s*(?:\/\*[^*]*\*\/\s*)?["']([^"']+)["']\s*,\s*import\.meta\.url\s*\)\s*\)/g;
73
+ if (workerUrlRegex.test(chunk.code)) {
74
+ chunk.code = chunk.code.replace(workerUrlRegex, (match, assetPath) => {
75
+ // Use the full asset path including assets/ folder
76
+ const fullPath = assetPath.startsWith("/")
77
+ ? assetPath.slice(1)
78
+ : assetPath;
79
+ return `new Worker('~/' + '${fullPath}')`;
80
+ });
81
+ }
82
+ }
83
+ }
84
+ },
85
+ };
86
+ }
@@ -0,0 +1 @@
1
+ export declare function handleAngularHmrUpdate(): void;
@@ -0,0 +1,34 @@
1
+ import { isDevMode, ɵresetCompiledComponents,
2
+ // @ts-ignore
3
+ } from "@angular/core";
4
+ export function handleAngularHmrUpdate() {
5
+ // Reset JIT compiled components cache
6
+ ɵresetCompiledComponents();
7
+ try {
8
+ console.log(`typeof global["__cleanup_ng_hot__"]`, typeof global["__cleanup_ng_hot__"]);
9
+ if (global["__cleanup_ng_hot__"])
10
+ global["__cleanup_ng_hot__"]();
11
+ global["__reboot_ng_modules__"]();
12
+ console.log('angular called __reboot_ng_modules__!');
13
+ // need to call some kind of apply here?
14
+ // Webpack would call in this order with angular-hot-loader/hmr-accept:
15
+ /**
16
+ * angular hot dispose called!
17
+ hot dispose called here?!
18
+ __cleanup_ng_hot__ called!
19
+ angular hot accept about to be called!
20
+ Angular is running in development mode.
21
+ [HMR][bd598ae5b97083449f33] success | Successfully applied update.
22
+ calling global.__onLiveSync!
23
+ */
24
+ global.__onLiveSync();
25
+ }
26
+ catch (e) {
27
+ console.error("[NG HMR] Error disposing previous module");
28
+ console.error(e, e?.stack);
29
+ // HMR breaks when rejecting the main module dispose, so we manually trigger an HMR restart
30
+ // const hash = __webpack_require__.h();
31
+ // console.log(`[HMR][${hash}] failure | Error disposing previous module`);
32
+ // throw e;
33
+ }
34
+ }
@@ -0,0 +1,18 @@
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
+ declare class SimpleHMRBridge {
8
+ private wsServer;
9
+ private connectedClients;
10
+ private buildProcess;
11
+ start(): Promise<void>;
12
+ private startWebSocketServer;
13
+ private startNativeScriptBuild;
14
+ private parseBuildOutput;
15
+ private notifyClients;
16
+ stop(): Promise<void>;
17
+ }
18
+ export { SimpleHMRBridge };
@@ -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,5 @@
1
+ /**
2
+ * Simple NativeScript HMR Client for Vite
3
+ * Based on @nativescript/webpack loaders but simplified for Vite
4
+ */
5
+ export {};
@@ -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 };