@nativescript/vite 0.0.1 → 1.0.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.
Files changed (281) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +81 -0
  3. package/{dist/configuration → configuration}/angular.d.ts +1 -1
  4. package/configuration/angular.js +371 -0
  5. package/configuration/angular.js.map +1 -0
  6. package/configuration/base.d.ts +5 -0
  7. package/configuration/base.js +491 -0
  8. package/configuration/base.js.map +1 -0
  9. package/configuration/javascript.d.ts +4 -0
  10. package/configuration/javascript.js +152 -0
  11. package/configuration/javascript.js.map +1 -0
  12. package/{dist/configuration → configuration}/react.d.ts +1 -1
  13. package/{dist/configuration → configuration}/react.js +18 -17
  14. package/configuration/react.js.map +1 -0
  15. package/{dist/configuration → configuration}/solid.d.ts +1 -1
  16. package/{dist/configuration → configuration}/solid.js +17 -16
  17. package/configuration/solid.js.map +1 -0
  18. package/configuration/typescript.d.ts +4 -0
  19. package/configuration/typescript.js +176 -0
  20. package/configuration/typescript.js.map +1 -0
  21. package/{dist/configuration → configuration}/vue.d.ts +1 -1
  22. package/configuration/vue.js +163 -0
  23. package/configuration/vue.js.map +1 -0
  24. package/helpers/angular/angular-linker.d.ts +13 -0
  25. package/helpers/angular/angular-linker.js +189 -0
  26. package/helpers/angular/angular-linker.js.map +1 -0
  27. package/helpers/angular/shared-linker.d.ts +4 -0
  28. package/helpers/angular/shared-linker.js +39 -0
  29. package/helpers/angular/shared-linker.js.map +1 -0
  30. package/helpers/angular/util.d.ts +1 -0
  31. package/helpers/angular/util.js +67 -0
  32. package/helpers/angular/util.js.map +1 -0
  33. package/helpers/cli-flags.d.ts +1 -0
  34. package/helpers/cli-flags.js +15 -0
  35. package/helpers/cli-flags.js.map +1 -0
  36. package/{dist/helpers → helpers}/commonjs-plugins.js +14 -13
  37. package/helpers/commonjs-plugins.js.map +1 -0
  38. package/{dist/helpers → helpers}/config-as-json.d.ts +1 -1
  39. package/{dist/helpers → helpers}/config-as-json.js +7 -6
  40. package/helpers/config-as-json.js.map +1 -0
  41. package/helpers/css-platform-plugin.d.ts +10 -0
  42. package/helpers/css-platform-plugin.js +76 -0
  43. package/helpers/css-platform-plugin.js.map +1 -0
  44. package/helpers/css-tree.js +22 -0
  45. package/helpers/css-tree.js.map +1 -0
  46. package/{dist/helpers → helpers}/dynamic-import-plugin.js +8 -7
  47. package/helpers/dynamic-import-plugin.js.map +1 -0
  48. package/helpers/esbuild-platform-resolver.d.ts +14 -0
  49. package/helpers/esbuild-platform-resolver.js +93 -0
  50. package/helpers/esbuild-platform-resolver.js.map +1 -0
  51. package/helpers/external-configs.d.ts +6 -0
  52. package/helpers/external-configs.js +34 -0
  53. package/helpers/external-configs.js.map +1 -0
  54. package/{dist/helpers → helpers}/flavor.d.ts +1 -0
  55. package/helpers/flavor.js +51 -0
  56. package/helpers/flavor.js.map +1 -0
  57. package/helpers/global-defines.d.ts +25 -0
  58. package/helpers/global-defines.js +29 -0
  59. package/helpers/global-defines.js.map +1 -0
  60. package/helpers/init.d.ts +1 -0
  61. package/helpers/init.js +119 -0
  62. package/helpers/init.js.map +1 -0
  63. package/helpers/logging.d.ts +13 -0
  64. package/helpers/logging.js +115 -0
  65. package/helpers/logging.js.map +1 -0
  66. package/helpers/main-entry.d.ts +10 -0
  67. package/helpers/main-entry.js +223 -0
  68. package/helpers/main-entry.js.map +1 -0
  69. package/{dist/helpers → helpers}/module-resolution.js +4 -3
  70. package/helpers/module-resolution.js.map +1 -0
  71. package/helpers/module-runner-patch.d.ts +3 -0
  72. package/helpers/module-runner-patch.js +63 -0
  73. package/helpers/module-runner-patch.js.map +1 -0
  74. package/helpers/nativeclass-transform.d.ts +7 -0
  75. package/helpers/nativeclass-transform.js +158 -0
  76. package/helpers/nativeclass-transform.js.map +1 -0
  77. package/helpers/nativeclass-transformer-plugin.d.ts +5 -0
  78. package/helpers/nativeclass-transformer-plugin.js +23 -0
  79. package/helpers/nativeclass-transformer-plugin.js.map +1 -0
  80. package/{dist/helpers → helpers}/nativescript-package-resolver.js +18 -17
  81. package/helpers/nativescript-package-resolver.js.map +1 -0
  82. package/helpers/ns-cli-plugins.d.ts +14 -0
  83. package/helpers/ns-cli-plugins.js +165 -0
  84. package/helpers/ns-cli-plugins.js.map +1 -0
  85. package/helpers/package-platform-aliases.d.ts +10 -0
  86. package/{dist/helpers → helpers}/package-platform-aliases.js +19 -23
  87. package/helpers/package-platform-aliases.js.map +1 -0
  88. package/helpers/postcss-platform-config.d.ts +13 -0
  89. package/helpers/postcss-platform-config.js +97 -0
  90. package/helpers/postcss-platform-config.js.map +1 -0
  91. package/helpers/prelink-angular.d.ts +2 -0
  92. package/helpers/prelink-angular.js +117 -0
  93. package/helpers/prelink-angular.js.map +1 -0
  94. package/helpers/preserve-imports.d.ts +2 -0
  95. package/helpers/preserve-imports.js +38 -0
  96. package/helpers/preserve-imports.js.map +1 -0
  97. package/{dist/helpers → helpers}/project.js +2 -4
  98. package/helpers/project.js.map +1 -0
  99. package/helpers/resolver.d.ts +4 -0
  100. package/{dist/helpers → helpers}/resolver.js +7 -6
  101. package/helpers/resolver.js.map +1 -0
  102. package/helpers/theme-core-plugins.d.ts +14 -0
  103. package/helpers/theme-core-plugins.js +121 -0
  104. package/helpers/theme-core-plugins.js.map +1 -0
  105. package/helpers/ts-config-paths.d.ts +10 -0
  106. package/{dist/helpers → helpers}/ts-config-paths.js +73 -72
  107. package/helpers/ts-config-paths.js.map +1 -0
  108. package/{dist/helpers → helpers}/utils.d.ts +10 -0
  109. package/helpers/utils.js +143 -0
  110. package/helpers/utils.js.map +1 -0
  111. package/{dist/helpers → helpers}/workers.js +15 -16
  112. package/helpers/workers.js.map +1 -0
  113. package/hmr/client/css-handler.d.ts +4 -0
  114. package/hmr/client/css-handler.js +78 -0
  115. package/hmr/client/css-handler.js.map +1 -0
  116. package/hmr/client/index.d.ts +13 -0
  117. package/hmr/client/index.js +1723 -0
  118. package/hmr/client/index.js.map +1 -0
  119. package/hmr/client/utils.d.ts +38 -0
  120. package/hmr/client/utils.js +426 -0
  121. package/hmr/client/utils.js.map +1 -0
  122. package/hmr/entry-runtime.d.ts +8 -0
  123. package/hmr/entry-runtime.js +135 -0
  124. package/hmr/entry-runtime.js.map +1 -0
  125. package/hmr/frameworks/angular/client/index.d.ts +8 -0
  126. package/hmr/frameworks/angular/client/index.js +59 -0
  127. package/hmr/frameworks/angular/client/index.js.map +1 -0
  128. package/hmr/frameworks/angular/server/linker.d.ts +1 -0
  129. package/hmr/frameworks/angular/server/linker.js +101 -0
  130. package/hmr/frameworks/angular/server/linker.js.map +1 -0
  131. package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
  132. package/hmr/frameworks/angular/server/strategy.js +187 -0
  133. package/hmr/frameworks/angular/server/strategy.js.map +1 -0
  134. package/hmr/frameworks/solid/server/strategy.d.ts +2 -0
  135. package/hmr/frameworks/solid/server/strategy.js +56 -0
  136. package/hmr/frameworks/solid/server/strategy.js.map +1 -0
  137. package/hmr/frameworks/typescript/server/strategy.d.ts +2 -0
  138. package/hmr/frameworks/typescript/server/strategy.js +125 -0
  139. package/hmr/frameworks/typescript/server/strategy.js.map +1 -0
  140. package/hmr/frameworks/vue/client/index.d.ts +22 -0
  141. package/hmr/frameworks/vue/client/index.js +1541 -0
  142. package/hmr/frameworks/vue/client/index.js.map +1 -0
  143. package/hmr/frameworks/vue/server/compiler.d.ts +11 -0
  144. package/hmr/frameworks/vue/server/compiler.js +26 -0
  145. package/hmr/frameworks/vue/server/compiler.js.map +1 -0
  146. package/hmr/frameworks/vue/server/sfc-transforms.d.ts +14 -0
  147. package/hmr/frameworks/vue/server/sfc-transforms.js +282 -0
  148. package/hmr/frameworks/vue/server/sfc-transforms.js.map +1 -0
  149. package/hmr/frameworks/vue/server/strategy.d.ts +2 -0
  150. package/hmr/frameworks/vue/server/strategy.js +272 -0
  151. package/hmr/frameworks/vue/server/strategy.js.map +1 -0
  152. package/hmr/helpers/ast-extract.d.ts +6 -0
  153. package/hmr/helpers/ast-extract.js +72 -0
  154. package/hmr/helpers/ast-extract.js.map +1 -0
  155. package/hmr/helpers/ast-normalizer.d.ts +7 -0
  156. package/hmr/helpers/ast-normalizer.js +772 -0
  157. package/hmr/helpers/ast-normalizer.js.map +1 -0
  158. package/hmr/helpers/babel.d.ts +3 -0
  159. package/hmr/helpers/babel.js +17 -0
  160. package/hmr/helpers/babel.js.map +1 -0
  161. package/hmr/helpers/sanitize.d.ts +6 -0
  162. package/hmr/helpers/sanitize.js +55 -0
  163. package/hmr/helpers/sanitize.js.map +1 -0
  164. package/hmr/helpers/vendor-rewrite.d.ts +1 -0
  165. package/hmr/helpers/vendor-rewrite.js +35 -0
  166. package/hmr/helpers/vendor-rewrite.js.map +1 -0
  167. package/hmr/server/compiler.d.ts +2 -0
  168. package/hmr/server/compiler.js +75 -0
  169. package/hmr/server/compiler.js.map +1 -0
  170. package/hmr/server/constants.d.ts +14 -0
  171. package/hmr/server/constants.js +23 -0
  172. package/hmr/server/constants.js.map +1 -0
  173. package/hmr/server/core-sanitize.d.ts +32 -0
  174. package/hmr/server/core-sanitize.js +134 -0
  175. package/hmr/server/core-sanitize.js.map +1 -0
  176. package/hmr/server/framework-strategy.d.ts +68 -0
  177. package/hmr/server/framework-strategy.js +2 -0
  178. package/hmr/server/framework-strategy.js.map +1 -0
  179. package/hmr/server/index.d.ts +5 -0
  180. package/hmr/server/index.js +23 -0
  181. package/hmr/server/index.js.map +1 -0
  182. package/hmr/server/vite-plugin.d.ts +5 -0
  183. package/hmr/server/vite-plugin.js +44 -0
  184. package/hmr/server/vite-plugin.js.map +1 -0
  185. package/hmr/server/websocket.d.ts +21 -0
  186. package/hmr/server/websocket.js +5619 -0
  187. package/hmr/server/websocket.js.map +1 -0
  188. package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
  189. package/hmr/shared/runtime/http-only-boot.js +107 -0
  190. package/hmr/shared/runtime/http-only-boot.js.map +1 -0
  191. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  192. package/hmr/shared/runtime/root-placeholder.js +142 -0
  193. package/hmr/shared/runtime/root-placeholder.js.map +1 -0
  194. package/hmr/shared/runtime/vendor-bootstrap.d.ts +1 -0
  195. package/hmr/shared/runtime/vendor-bootstrap.js +134 -0
  196. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -0
  197. package/hmr/shared/vendor/manifest-loader.d.ts +9 -0
  198. package/hmr/shared/vendor/manifest-loader.js +38 -0
  199. package/hmr/shared/vendor/manifest-loader.js.map +1 -0
  200. package/hmr/shared/vendor/manifest.d.ts +35 -0
  201. package/hmr/shared/vendor/manifest.js +811 -0
  202. package/hmr/shared/vendor/manifest.js.map +1 -0
  203. package/hmr/shared/vendor/registry.d.ts +9 -0
  204. package/hmr/shared/vendor/registry.js +62 -0
  205. package/hmr/shared/vendor/registry.js.map +1 -0
  206. package/hmr/vendor-bootstrap.d.ts +3 -0
  207. package/hmr/vendor-bootstrap.js +32 -0
  208. package/hmr/vendor-bootstrap.js.map +1 -0
  209. package/{dist/index.d.ts → index.d.ts} +2 -0
  210. package/index.js +19 -0
  211. package/index.js.map +1 -0
  212. package/package.json +42 -30
  213. package/{dist/polyfills → polyfills}/mdn-data-at-rules.js +1 -0
  214. package/polyfills/mdn-data-at-rules.js.map +1 -0
  215. package/{dist/polyfills → polyfills}/mdn-data-properties.js +1 -0
  216. package/polyfills/mdn-data-properties.js.map +1 -0
  217. package/{dist/polyfills → polyfills}/mdn-data-syntaxes.js +1 -0
  218. package/polyfills/mdn-data-syntaxes.js.map +1 -0
  219. package/{dist/polyfills → polyfills}/module.js +1 -0
  220. package/polyfills/module.js.map +1 -0
  221. package/runtime/core-aliases-early.d.ts +1 -0
  222. package/runtime/core-aliases-early.js +334 -0
  223. package/runtime/core-aliases-early.js.map +1 -0
  224. package/shims/angular-animations-stub.d.ts +68 -0
  225. package/shims/angular-animations-stub.js +140 -0
  226. package/shims/angular-animations-stub.js.map +1 -0
  227. package/shims/node-module.d.ts +5 -0
  228. package/shims/node-module.js +13 -0
  229. package/shims/node-module.js.map +1 -0
  230. package/{dist/shims → shims}/react-reconciler-constants.js +2 -1
  231. package/shims/react-reconciler-constants.js.map +1 -0
  232. package/{dist/shims → shims}/react-reconciler.js +1 -0
  233. package/shims/react-reconciler.js.map +1 -0
  234. package/{dist/shims → shims}/set-value.js +5 -1
  235. package/shims/set-value.js.map +1 -0
  236. package/transformers/NativeClass/index.d.ts +2 -0
  237. package/transformers/NativeClass/index.js +222 -0
  238. package/transformers/NativeClass/index.js.map +1 -0
  239. package/dist/configuration/angular.js +0 -30
  240. package/dist/configuration/base.d.ts +0 -13
  241. package/dist/configuration/base.js +0 -228
  242. package/dist/configuration/old-without-merge-base.d.ts +0 -13
  243. package/dist/configuration/old-without-merge-base.js +0 -249
  244. package/dist/configuration/vue.js +0 -45
  245. package/dist/helpers/css-tree.js +0 -21
  246. package/dist/helpers/flavor.js +0 -40
  247. package/dist/helpers/global-defines.d.ts +0 -14
  248. package/dist/helpers/global-defines.js +0 -18
  249. package/dist/helpers/main-entry.d.ts +0 -5
  250. package/dist/helpers/main-entry.js +0 -75
  251. package/dist/helpers/ns-cli-plugins.d.ts +0 -17
  252. package/dist/helpers/ns-cli-plugins.js +0 -128
  253. package/dist/helpers/package-platform-aliases.d.ts +0 -4
  254. package/dist/helpers/resolver.d.ts +0 -4
  255. package/dist/helpers/ts-config-paths.d.ts +0 -4
  256. package/dist/helpers/utils.js +0 -94
  257. package/dist/hmr/hmr-angular.d.ts +0 -1
  258. package/dist/hmr/hmr-angular.js +0 -34
  259. package/dist/hmr/hmr-bridge.d.ts +0 -18
  260. package/dist/hmr/hmr-bridge.js +0 -154
  261. package/dist/hmr/hmr-client.d.ts +0 -5
  262. package/dist/hmr/hmr-client.js +0 -93
  263. package/dist/hmr/hmr-server.d.ts +0 -20
  264. package/dist/hmr/hmr-server.js +0 -179
  265. package/dist/index.js +0 -5
  266. package/dist/transformers/NativeClass/index.d.ts +0 -5
  267. package/dist/transformers/NativeClass/index.js +0 -46
  268. /package/{dist/helpers → helpers}/commonjs-plugins.d.ts +0 -0
  269. /package/{dist/helpers → helpers}/css-tree.d.ts +0 -0
  270. /package/{dist/helpers → helpers}/dynamic-import-plugin.d.ts +0 -0
  271. /package/{dist/helpers → helpers}/module-resolution.d.ts +0 -0
  272. /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
  273. /package/{dist/helpers → helpers}/project.d.ts +0 -0
  274. /package/{dist/helpers → helpers}/workers.d.ts +0 -0
  275. /package/{dist/polyfills → polyfills}/mdn-data-at-rules.d.ts +0 -0
  276. /package/{dist/polyfills → polyfills}/mdn-data-properties.d.ts +0 -0
  277. /package/{dist/polyfills → polyfills}/mdn-data-syntaxes.d.ts +0 -0
  278. /package/{dist/polyfills → polyfills}/module.d.ts +0 -0
  279. /package/{dist/shims → shims}/react-reconciler-constants.d.ts +0 -0
  280. /package/{dist/shims → shims}/react-reconciler.d.ts +0 -0
  281. /package/{dist/shims → shims}/set-value.d.ts +0 -0
@@ -1,94 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export declare function handleAngularHmrUpdate(): void;
@@ -1,34 +0,0 @@
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
- }
@@ -1,18 +0,0 @@
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 };
@@ -1,154 +0,0 @@
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
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Simple NativeScript HMR Client for Vite
3
- * Based on @nativescript/webpack loaders but simplified for Vite
4
- */
5
- export {};
@@ -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
- // }
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
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';
@@ -1,5 +0,0 @@
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;
@@ -1,46 +0,0 @@
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
- }
File without changes
File without changes
File without changes