@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,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
+ // }
@@ -0,0 +1,5 @@
1
+ export * from './configuration/base.js';
2
+ export * from './configuration/angular.js';
3
+ export * from './configuration/react.js';
4
+ export * from './configuration/solid.js';
5
+ export * from './configuration/vue.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './configuration/base.js';
2
+ export * from './configuration/angular.js';
3
+ export * from './configuration/react.js';
4
+ export * from './configuration/solid.js';
5
+ export * from './configuration/vue.js';
@@ -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
+ declare const _default: {};
7
+ export default _default;
@@ -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
+ declare const _default: {};
7
+ export default _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
+ declare const _default: {};
7
+ export default _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,8 @@
1
+ /**
2
+ * Shim for react-reconciler to fix namespace call issues
3
+ * This resolves the "Cannot call a namespace" error
4
+ */
5
+ declare const ReactReconciler: any;
6
+ export * from 'react-reconciler';
7
+ export default ReactReconciler;
8
+ export { ReactReconciler };
@@ -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,4 @@
1
+ /**
2
+ * shim for set-value commonjs package export
3
+ */
4
+ export default function setValue(obj: any, path: any, value: any): any;
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * A TypeScript transform that compiles classes marked with `@NativeClass` as es5
4
+ */
5
+ export default function (ctx: ts.TransformationContext): (source: ts.SourceFile) => ts.SourceFile;
@@ -0,0 +1,46 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * A TypeScript transform that compiles classes marked with `@NativeClass` as es5
4
+ */
5
+ export default function (ctx) {
6
+ function isNativeClassExtension(node) {
7
+ let decorators;
8
+ if ('canHaveDecorators' in ts && ts.canHaveDecorators(node)) {
9
+ // use the newer decorators API when using a newer typescript version
10
+ // @ts-ignore
11
+ decorators = ts.getDecorators(node);
12
+ }
13
+ else {
14
+ // fallback to old behavior on older typescript versions
15
+ decorators = node.decorators;
16
+ }
17
+ return !!decorators?.some((d) => {
18
+ const fullText = d.getFullText().trim();
19
+ if (fullText.indexOf('@NativeClass') > -1) {
20
+ console.log('found @NativeClass decorator in:', fullText);
21
+ }
22
+ return fullText.indexOf('@NativeClass') > -1;
23
+ });
24
+ }
25
+ function visitNode(node) {
26
+ if (ts.isClassDeclaration(node) && isNativeClassExtension(node)) {
27
+ return createHelper(node);
28
+ }
29
+ return ts.visitEachChild(node, visitNode, ctx);
30
+ }
31
+ function createHelper(node) {
32
+ // we remove the decorator for now!
33
+ return ts.factory.createIdentifier(ts
34
+ .transpileModule(node.getText().replace(/@NativeClass(\((.|\n)*?\))?/gm, ''), {
35
+ compilerOptions: {
36
+ noEmitHelpers: true,
37
+ module: ts.ModuleKind.ESNext,
38
+ target: ts.ScriptTarget.ES5,
39
+ experimentalDecorators: true,
40
+ emitDecoratorMetadata: true,
41
+ },
42
+ })
43
+ .outputText.replace(/(Object\.defineProperty\(.*?{.*?)(enumerable:\s*false)(.*?}\))/gs, '$1enumerable: true$3'));
44
+ }
45
+ return (source) => ts.factory.updateSourceFile(source, ts.visitNodes(source.statements, visitNode));
46
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@nativescript/vite",
3
+ "version": "0.0.1",
4
+ "description": "Vite for NativeScript",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "type": "module",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "keywords": [
13
+ "nativescript",
14
+ "vite"
15
+ ],
16
+ "dependencies": {
17
+ "@analogjs/vite-plugin-angular": "^1.20.2",
18
+ "@angular-devkit/build-angular": "^20.0.0",
19
+ "@angular/build": "^20.0.0",
20
+ "@rollup/plugin-alias": "^5.1.1",
21
+ "@rollup/plugin-commonjs": "^28.0.0",
22
+ "@vitejs/plugin-vue": "^6.0.1",
23
+ "@vitejs/plugin-vue-jsx": "^5.1.1",
24
+ "minimist": "^1.2.8",
25
+ "react-reconciler": "^0.32.0",
26
+ "sass": ">=1.70.0 <2",
27
+ "vite": "^7.1.0",
28
+ "vite-plugin-solid": "^2.11.8",
29
+ "vite-plugin-static-copy": "^3.1.0"
30
+ }
31
+ }