xanix 1.0.20 → 1.0.21

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 (275) hide show
  1. package/dist/bin/bundler/cache/buildCache.js +9 -11
  2. package/dist/bin/bundler/cache/index.js +70 -116
  3. package/dist/bin/bundler/cache/utils.d.ts +3 -2
  4. package/dist/bin/bundler/cache/utils.js +27 -24
  5. package/dist/bin/bundler/client/build.js +1 -1
  6. package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction copy.d.ts +3 -0
  7. package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction copy.js +32 -0
  8. package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction.d.ts +1 -1
  9. package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction.js +1 -1
  10. package/dist/bin/bundler/client/plugins/Transformer/TransformCreateSession.d.ts +1 -1
  11. package/dist/bin/bundler/client/plugins/Transformer/TransformCreateSession.js +1 -1
  12. package/dist/bin/bundler/client/plugins/Transformer/TransformDevModule.d.ts +13 -0
  13. package/dist/bin/bundler/client/plugins/Transformer/{transformModuleCache.js → TransformDevModule.js} +6 -18
  14. package/dist/bin/bundler/client/plugins/Transformer/TransformServerFunction.d.ts +1 -1
  15. package/dist/bin/bundler/client/plugins/Transformer/TransformServerFunction.js +1 -1
  16. package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionReplacer.d.ts +3 -0
  17. package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionReplacer.js +32 -0
  18. package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionTransformer.d.ts +3 -0
  19. package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionTransformer.js +32 -0
  20. package/dist/bin/bundler/client/plugins/Transformer/serverFunctionReplacer.d.ts +3 -0
  21. package/dist/bin/bundler/client/plugins/Transformer/serverFunctionReplacer.js +32 -0
  22. package/dist/bin/bundler/client/plugins/Transformer/useServerReplacer.d.ts +3 -0
  23. package/dist/bin/bundler/client/plugins/Transformer/useServerReplacer.js +42 -0
  24. package/dist/bin/bundler/client/plugins/Transformer.js +4 -2
  25. package/dist/bin/bundler/client/plugins/XanixAppRoot.d.ts +2 -0
  26. package/dist/bin/bundler/client/plugins/XanixAppRoot.js +46 -0
  27. package/dist/bin/bundler/client/plugins/XanixPage.js +30 -0
  28. package/dist/bin/bundler/client/plugins/XanixPages.js +8 -8
  29. package/dist/bin/bundler/client/plugins/replacer/cacheFunctionReplacer.d.ts +1 -1
  30. package/dist/bin/bundler/client/plugins/replacer/cacheFunctionReplacer.js +5 -1
  31. package/dist/bin/bundler/client/plugins/replacer/serverFunctionReplacer.d.ts +1 -1
  32. package/dist/bin/bundler/client/plugins/replacer/serverFunctionReplacer.js +5 -1
  33. package/dist/bin/bundler/client/plugins/replacer/useServerReplacer.d.ts +1 -1
  34. package/dist/bin/bundler/client/plugins/replacer/useServerReplacer.js +7 -3
  35. package/dist/bin/bundler/server/build.js +1 -1
  36. package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction copy.d.ts +3 -0
  37. package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction copy.js +32 -0
  38. package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction.d.ts +1 -1
  39. package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction.js +1 -1
  40. package/dist/bin/bundler/server/plugins/Transformer/TransformCreateSession.d.ts +1 -1
  41. package/dist/bin/bundler/server/plugins/Transformer/TransformCreateSession.js +1 -1
  42. package/dist/bin/bundler/server/plugins/Transformer/TransformExpressFunction.d.ts +1 -1
  43. package/dist/bin/bundler/server/plugins/Transformer/TransformExpressFunction.js +1 -1
  44. package/dist/bin/bundler/server/plugins/Transformer/TransformPage.js +1 -1
  45. package/dist/bin/bundler/server/plugins/Transformer/TransformServerFunction.d.ts +1 -1
  46. package/dist/bin/bundler/server/plugins/Transformer/TransformServerFunction.js +1 -1
  47. package/dist/bin/bundler/server/plugins/Transformer/cacheFunctionReplacer.d.ts +3 -0
  48. package/dist/bin/bundler/server/plugins/Transformer/cacheFunctionReplacer.js +32 -0
  49. package/dist/bin/bundler/server/plugins/Transformer/expressFunctionReplace.d.ts +3 -0
  50. package/dist/bin/bundler/server/plugins/Transformer/expressFunctionReplace.js +24 -0
  51. package/dist/bin/bundler/server/plugins/Transformer/pageReplacer.d.ts +4 -0
  52. package/dist/bin/bundler/server/plugins/Transformer/pageReplacer.js +31 -0
  53. package/dist/bin/bundler/server/plugins/Transformer/serverFunctionReplacer.d.ts +3 -0
  54. package/dist/bin/bundler/server/plugins/Transformer/serverFunctionReplacer.js +32 -0
  55. package/dist/bin/bundler/server/plugins/Transformer/useServerReplacer.d.ts +3 -0
  56. package/dist/bin/bundler/server/plugins/Transformer/useServerReplacer.js +42 -0
  57. package/dist/bin/bundler/server/plugins/Transformer copy.js +3 -3
  58. package/dist/bin/bundler/server/plugins/Transformer.js +2 -2
  59. package/dist/bin/bundler/server/plugins/replacer/cacheFunctionReplacer.d.ts +1 -1
  60. package/dist/bin/bundler/server/plugins/replacer/cacheFunctionReplacer.js +5 -1
  61. package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer copy.d.ts +3 -0
  62. package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer copy.js +26 -0
  63. package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer.d.ts +1 -1
  64. package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer.js +5 -1
  65. package/dist/bin/bundler/server/plugins/replacer/serverReplacer.d.ts +3 -0
  66. package/dist/bin/bundler/server/plugins/replacer/serverReplacer.js +26 -0
  67. package/dist/bin/bundler/server/plugins/replacer/useServerReplacer.d.ts +2 -2
  68. package/dist/bin/bundler/server/plugins/replacer/useServerReplacer.js +9 -5
  69. package/dist/bin/cli/dev.js +85 -71
  70. package/dist/bin/cli/start/index.d.ts +4 -1
  71. package/dist/bin/cli/start/index.js +60 -9
  72. package/dist/bin/finder/callbackReplacer.d.ts +2 -0
  73. package/dist/bin/finder/callbackReplacer.js +52 -0
  74. package/dist/bin/finder/findImport.d.ts +9 -0
  75. package/dist/bin/finder/findImport.js +50 -0
  76. package/dist/bin/finder/findImports.d.ts +16 -0
  77. package/dist/bin/finder/findImports.js +45 -0
  78. package/dist/bin/finder/findPage.d.ts +9 -0
  79. package/dist/bin/finder/findPage.js +30 -0
  80. package/dist/bin/finder/importFinder.d.ts +9 -0
  81. package/dist/bin/finder/importFinder.js +50 -0
  82. package/dist/bin/finder/pageFinder.d.ts +9 -0
  83. package/dist/bin/finder/pageFinder.js +30 -0
  84. package/dist/bin/finder/stripComments.d.ts +3 -0
  85. package/dist/bin/finder/stripComments.js +15 -0
  86. package/dist/bin/include/path.d.ts +5 -1
  87. package/dist/bin/include/path.js +15 -1
  88. package/dist/bin/include/sendFinder.d.ts +4 -1
  89. package/dist/bin/include/sendFinder.js +88 -53
  90. package/dist/bin/index.js +0 -0
  91. package/dist/bin/modifier/callbackReplacer.js +35 -80
  92. package/dist/bin/modifier/findImports.d.ts +16 -0
  93. package/dist/bin/modifier/findImports.js +45 -0
  94. package/dist/bin/modifier/importFinder.js +44 -63
  95. package/dist/bin/modifier/pageFinder.d.ts +1 -1
  96. package/dist/bin/modifier/pageFinder.js +19 -124
  97. package/dist/bin/modifier/sendFinder.d.ts +9 -0
  98. package/dist/bin/modifier/sendFinder.js +135 -0
  99. package/dist/bin/modifier/sriptCommnet.d.ts +1 -0
  100. package/dist/bin/modifier/sriptCommnet.js +12 -5
  101. package/dist/bin/modifier/stripComments.d.ts +3 -0
  102. package/dist/bin/modifier/stripComments.js +15 -0
  103. package/dist/bin/plugins/XanixAssets.js +2 -2
  104. package/dist/bin/plugins/XanixCss.js +13 -13
  105. package/dist/bin/plugins/XanixDocument.js +4 -4
  106. package/dist/components/Head.js +1 -1
  107. package/dist/hooks/encript.d.ts +2 -0
  108. package/dist/hooks/encript.js +13 -0
  109. package/dist/hooks/server.js +2 -2
  110. package/dist/hooks/session.js +2 -2
  111. package/dist/index.js +0 -0
  112. package/dist/libs/encoder.d.ts +2 -0
  113. package/dist/libs/encoder.js +13 -0
  114. package/dist/libs/encript.d.ts +2 -0
  115. package/dist/libs/encript.js +30 -0
  116. package/dist/navigate.js +1 -1
  117. package/dist/server/express/Router.js +4 -4
  118. package/dist/server/express/page.d.ts +1 -1
  119. package/dist/server/express/page.js +1 -1
  120. package/dist/types/assets.d.ts +72 -72
  121. package/dist/types/express.d.ts +11 -11
  122. package/dist/types/globals.d.ts +18 -18
  123. package/dist/types/xanix-virtual.d.ts +35 -35
  124. package/package.json +57 -60
  125. package/dist/bin/bundler/Cache.d.ts +0 -1
  126. package/dist/bin/bundler/Cache.js +0 -210
  127. package/dist/bin/bundler/External.d.ts +0 -3
  128. package/dist/bin/bundler/External.js +0 -6
  129. package/dist/bin/bundler/buildClient.d.ts +0 -3
  130. package/dist/bin/bundler/buildClient.js +0 -42
  131. package/dist/bin/bundler/buildServer.d.ts +0 -7
  132. package/dist/bin/bundler/buildServer.js +0 -50
  133. package/dist/bin/bundler/cache/plugin/Transformer.d.ts +0 -3
  134. package/dist/bin/bundler/cache/plugin/Transformer.js +0 -42
  135. package/dist/bin/bundler/client/plugins/Transformer/TransformExpress.d.ts +0 -9
  136. package/dist/bin/bundler/client/plugins/Transformer/TransformExpress.js +0 -26
  137. package/dist/bin/bundler/client/plugins/Transformer/TransformPage.d.ts +0 -29
  138. package/dist/bin/bundler/client/plugins/Transformer/TransformPage.js +0 -77
  139. package/dist/bin/bundler/client/plugins/Transformer/TransformReactContext.d.ts +0 -17
  140. package/dist/bin/bundler/client/plugins/Transformer/TransformReactContext.js +0 -101
  141. package/dist/bin/bundler/client/plugins/Transformer/transformModuleCache.d.ts +0 -15
  142. package/dist/bin/bundler/client/plugins/Transformer copy.d.ts +0 -3
  143. package/dist/bin/bundler/client/plugins/Transformer copy.js +0 -70
  144. package/dist/bin/bundler/client/plugins/VirtualDev.d.ts +0 -2
  145. package/dist/bin/bundler/client/plugins/VirtualDev.js +0 -34
  146. package/dist/bin/bundler/client/plugins/XanixReactRefresh.d.ts +0 -2
  147. package/dist/bin/bundler/client/plugins/XanixReactRefresh.js +0 -22
  148. package/dist/bin/bundler/config/defines.d.ts +0 -20
  149. package/dist/bin/bundler/config/defines.js +0 -21
  150. package/dist/bin/bundler/config/external.d.ts +0 -1
  151. package/dist/bin/bundler/config/external.js +0 -12
  152. package/dist/bin/bundler/config/loadEnv.d.ts +0 -20
  153. package/dist/bin/bundler/config/loadEnv.js +0 -48
  154. package/dist/bin/bundler/config/output.d.ts +0 -10
  155. package/dist/bin/bundler/config/output.js +0 -52
  156. package/dist/bin/bundler/externalResolver-dep.d.ts +0 -3
  157. package/dist/bin/bundler/externalResolver-dep.js +0 -203
  158. package/dist/bin/bundler/externalResolver.d.ts +0 -3
  159. package/dist/bin/bundler/externalResolver.js +0 -203
  160. package/dist/bin/bundler/plugins/TransformServer/TransformExpress.d.ts +0 -9
  161. package/dist/bin/bundler/plugins/TransformServer/TransformExpress.js +0 -26
  162. package/dist/bin/bundler/plugins/TransformServer/TransformPage.d.ts +0 -25
  163. package/dist/bin/bundler/plugins/TransformServer/TransformPage.js +0 -79
  164. package/dist/bin/bundler/plugins/TransformServer/index.d.ts +0 -3
  165. package/dist/bin/bundler/plugins/TransformServer/index.js +0 -103
  166. package/dist/bin/bundler/plugins/XanixAssets.d.ts +0 -5
  167. package/dist/bin/bundler/plugins/XanixAssets.js +0 -51
  168. package/dist/bin/bundler/plugins/XanixCacheDeps-dep.d.ts +0 -2
  169. package/dist/bin/bundler/plugins/XanixCacheDeps-dep.js +0 -150
  170. package/dist/bin/bundler/plugins/XanixCacheDeps.d.ts +0 -2
  171. package/dist/bin/bundler/plugins/XanixCacheDeps.js +0 -150
  172. package/dist/bin/bundler/plugins/XanixDocument/index.js +0 -53
  173. package/dist/bin/bundler/plugins/XanixEntryFinder/finder.d.ts +0 -11
  174. package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +0 -149
  175. package/dist/bin/bundler/plugins/XanixEntryFinder/index.d.ts +0 -6
  176. package/dist/bin/bundler/plugins/XanixEntryFinder/index.js +0 -37
  177. package/dist/bin/bundler/plugins/XanixEntryFinder-dep/finder.d.ts +0 -11
  178. package/dist/bin/bundler/plugins/XanixEntryFinder-dep/finder.js +0 -149
  179. package/dist/bin/bundler/plugins/XanixEntryFinder-dep/index.d.ts +0 -6
  180. package/dist/bin/bundler/plugins/XanixEntryFinder-dep/index.js +0 -37
  181. package/dist/bin/bundler/plugins/XanixEnv.d.ts +0 -15
  182. package/dist/bin/bundler/plugins/XanixEnv.js +0 -44
  183. package/dist/bin/bundler/plugins/XanixPageTransform/index.d.ts +0 -2
  184. package/dist/bin/bundler/plugins/XanixPageTransform/index.js +0 -62
  185. package/dist/bin/bundler/plugins/XanixPageTransform/transformer copy.d.ts +0 -18
  186. package/dist/bin/bundler/plugins/XanixPageTransform/transformer copy.js +0 -414
  187. package/dist/bin/bundler/plugins/XanixPageTransform/transformer.d.ts +0 -23
  188. package/dist/bin/bundler/plugins/XanixPageTransform/transformer.js +0 -589
  189. package/dist/bin/bundler/plugins/XanixReactRefresh copy.d.ts +0 -2
  190. package/dist/bin/bundler/plugins/XanixReactRefresh copy.js +0 -121
  191. package/dist/bin/bundler/plugins/XanixReactRefresh.d.ts +0 -2
  192. package/dist/bin/bundler/plugins/XanixReactRefresh.js +0 -170
  193. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/BuildClientCache.d.ts +0 -11
  194. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/BuildClientCache.js +0 -129
  195. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index copy.d.ts +0 -15
  196. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index copy.js +0 -228
  197. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.d.ts +0 -7
  198. package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +0 -166
  199. package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/BuildClientCache.d.ts +0 -11
  200. package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/BuildClientCache.js +0 -129
  201. package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/index.d.ts +0 -5
  202. package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/index.js +0 -26
  203. package/dist/bin/bundler/plugins/XanixResolver.d.ts +0 -11
  204. package/dist/bin/bundler/plugins/XanixResolver.js +0 -55
  205. package/dist/bin/bundler/plugins/XanixServerTransform.d.ts +0 -5
  206. package/dist/bin/bundler/plugins/XanixServerTransform.js +0 -207
  207. package/dist/bin/bundler/plugins/XanixTransform.d.ts +0 -3
  208. package/dist/bin/bundler/plugins/XanixTransform.js +0 -23
  209. package/dist/bin/bundler/plugins/XanixTsconfigAlias.d.ts +0 -19
  210. package/dist/bin/bundler/plugins/XanixTsconfigAlias.js +0 -197
  211. package/dist/bin/bundler/plugins/XanixUseServer.d.ts +0 -7
  212. package/dist/bin/bundler/plugins/XanixUseServer.js +0 -445
  213. package/dist/bin/bundler/plugins/plugins.d.ts +0 -9
  214. package/dist/bin/bundler/plugins/plugins.js +0 -37
  215. package/dist/bin/bundler/requireCache.d.ts +0 -3
  216. package/dist/bin/bundler/requireCache.js +0 -85
  217. package/dist/bin/bundler/server/plugins/ServerAction.d.ts +0 -3
  218. package/dist/bin/bundler/server/plugins/ServerAction.js +0 -9
  219. package/dist/bin/bundler/server/plugins/Transformer/ServerAction.d.ts +0 -11
  220. package/dist/bin/bundler/server/plugins/Transformer/ServerAction.js +0 -28
  221. package/dist/bin/bundler/server/plugins/Transformer/TransformExpress copy.d.ts +0 -11
  222. package/dist/bin/bundler/server/plugins/Transformer/TransformExpress copy.js +0 -22
  223. package/dist/bin/bundler/server/plugins/Transformer/TransformExpress.d.ts +0 -10
  224. package/dist/bin/bundler/server/plugins/Transformer/TransformExpress.js +0 -19
  225. package/dist/bin/bundler/server/plugins/Transformer/TransformReactContext.d.ts +0 -17
  226. package/dist/bin/bundler/server/plugins/Transformer/TransformReactContext.js +0 -101
  227. package/dist/bin/bundler/server/plugins/Transformer/TransformServerAction copy.d.ts +0 -14
  228. package/dist/bin/bundler/server/plugins/Transformer/TransformServerAction copy.js +0 -38
  229. package/dist/bin/bundler/server/types.d.ts +0 -5
  230. package/dist/bin/bundler/server/types.js +0 -1
  231. package/dist/bin/bundler/watchClient.d.ts +0 -12
  232. package/dist/bin/bundler/watchClient.js +0 -104
  233. package/dist/bin/bundler/watchServer.d.ts +0 -10
  234. package/dist/bin/bundler/watchServer.js +0 -139
  235. package/dist/bin/cli/dev/dev.d.ts +0 -2
  236. package/dist/bin/cli/dev/dev.js +0 -178
  237. package/dist/bin/cli/start/start.d.ts +0 -2
  238. package/dist/bin/cli/start/start.js +0 -27
  239. package/dist/bin/include/entry.d.ts +0 -2
  240. package/dist/bin/include/entry.js +0 -21
  241. package/dist/bin/plugins/XanixDocument/XanixDocument.d.ts +0 -2
  242. package/dist/bin/plugins/XanixDocument/XanixDocument.js +0 -50
  243. package/dist/bin/plugins/XanixDocument/index.d.ts +0 -2
  244. package/dist/bin/plugins/XanixDocument/index.js +0 -50
  245. package/dist/bin/plugins/XanixPageTransform-dep/index.d.ts +0 -2
  246. package/dist/bin/plugins/XanixPageTransform-dep/index.js +0 -62
  247. package/dist/bin/plugins/XanixPageTransform-dep/transformer.d.ts +0 -23
  248. package/dist/bin/plugins/XanixPageTransform-dep/transformer.js +0 -589
  249. package/dist/bin/plugins/XanixServerTransform.d.ts +0 -5
  250. package/dist/bin/plugins/XanixServerTransform.js +0 -207
  251. package/dist/bin/plugins/XanixUseServer.d.ts +0 -7
  252. package/dist/bin/plugins/XanixUseServer.js +0 -445
  253. package/dist/bin/plugins/plugins.d.ts +0 -8
  254. package/dist/bin/plugins/plugins.js +0 -31
  255. package/dist/components/Script.d.ts +0 -3
  256. package/dist/components/Script.js +0 -5
  257. package/dist/dev.d.ts +0 -1
  258. package/dist/dev.js +0 -25
  259. package/dist/react/createContext.d.ts +0 -3
  260. package/dist/react/createContext.js +0 -11
  261. package/dist/react/index.d.ts +0 -12
  262. package/dist/react/index.js +0 -3
  263. package/dist/server/express/Ruter.d.ts +0 -2
  264. package/dist/server/express/Ruter.js +0 -15
  265. package/dist/server/runtime/createServer.d.ts +0 -12
  266. package/dist/server/runtime/createServer.js +0 -62
  267. package/dist/server/runtime/index.d.ts +0 -3
  268. package/dist/server/runtime/index.js +0 -3
  269. package/dist/server/runtime/readManifest.d.ts +0 -14
  270. package/dist/server/runtime/readManifest.js +0 -9
  271. package/dist/server/runtime/xanixPage.d.ts +0 -11
  272. package/dist/server/runtime/xanixPage.js +0 -92
  273. /package/dist/bin/bundler/{plugins/XanixDocument/index.d.ts → client/plugins/XanixPage.d.ts} +0 -0
  274. /package/dist/bin/{cli/start/utils.d.ts → bundler/server/plugins/replacer/useServer.d.ts} +0 -0
  275. /package/dist/bin/{cli/start/utils.js → bundler/server/plugins/replacer/useServer.js} +0 -0
@@ -1,589 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs";
3
- import crypto from "node:crypto";
4
- const RUNTIME_IMPORT = "xanix/runtime";
5
- const SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".cjs"];
6
- export function normalizeFilePath(file) {
7
- return path.resolve(file).split(path.sep).join("/");
8
- }
9
- export function resolveFile(file) {
10
- const absolute = path.resolve(file);
11
- if (fs.existsSync(absolute)) {
12
- const stat = fs.statSync(absolute);
13
- if (stat.isFile()) {
14
- return absolute;
15
- }
16
- }
17
- for (const ext of SOURCE_EXTENSIONS) {
18
- const candidate = `${absolute}${ext}`;
19
- if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
20
- return path.resolve(candidate);
21
- }
22
- }
23
- if (fs.existsSync(absolute) && fs.statSync(absolute).isDirectory()) {
24
- for (const ext of SOURCE_EXTENSIONS) {
25
- const candidate = path.join(absolute, `index${ext}`);
26
- if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
27
- return path.resolve(candidate);
28
- }
29
- }
30
- }
31
- return absolute;
32
- }
33
- export function resolveComponentFile(importer, importPath) {
34
- if (!importPath.startsWith(".")) {
35
- return importPath;
36
- }
37
- const base = path.resolve(path.dirname(importer), importPath);
38
- return resolveFile(base);
39
- }
40
- export function createPageId(file) {
41
- return crypto
42
- .createHash("sha256")
43
- .update(path.normalize(file))
44
- .digest("hex")
45
- .slice(0, 12);
46
- }
47
- /* -------------------------------------------------------------------------- */
48
- /* AST helpers */
49
- /* -------------------------------------------------------------------------- */
50
- function isNode(value) {
51
- return (typeof value === "object" &&
52
- value !== null &&
53
- typeof value.type === "string");
54
- }
55
- function walk(node, visitor, parent = null, ancestors = []) {
56
- visitor(node, parent, ancestors);
57
- const nextAncestors = [...ancestors, node];
58
- for (const key of Object.keys(node)) {
59
- if (key === "parent" ||
60
- key === "loc" ||
61
- key === "range" ||
62
- key === "tokens" ||
63
- key === "comments") {
64
- continue;
65
- }
66
- const value = node[key];
67
- if (Array.isArray(value)) {
68
- for (const item of value) {
69
- if (isNode(item)) {
70
- walk(item, visitor, node, nextAncestors);
71
- }
72
- }
73
- continue;
74
- }
75
- if (isNode(value)) {
76
- walk(value, visitor, node, nextAncestors);
77
- }
78
- }
79
- }
80
- function isFunctionNode(node) {
81
- return (node.type === "FunctionDeclaration" ||
82
- node.type === "FunctionExpression" ||
83
- node.type === "ArrowFunctionExpression");
84
- }
85
- function findFunctionParent(ancestors) {
86
- for (let i = ancestors.length - 1; i >= 0; i--) {
87
- if (isFunctionNode(ancestors[i])) {
88
- return ancestors[i];
89
- }
90
- }
91
- return null;
92
- }
93
- function isMemberExpression(node) {
94
- return (!!node &&
95
- (node.type === "MemberExpression" ||
96
- node.type === "OptionalMemberExpression"));
97
- }
98
- function getMemberPropertyName(node) {
99
- if (!isMemberExpression(node)) {
100
- return null;
101
- }
102
- if (node.computed) {
103
- const property = node.property;
104
- if (property?.type === "Literal" && typeof property.value === "string") {
105
- return property.value;
106
- }
107
- return null;
108
- }
109
- if (node.property?.type === "Identifier") {
110
- return node.property.name;
111
- }
112
- return null;
113
- }
114
- function getJSXComponentName(jsx) {
115
- const name = jsx.openingElement?.name;
116
- if (!name) {
117
- return null;
118
- }
119
- if (name.type === "JSXIdentifier") {
120
- return name.name;
121
- }
122
- if (name.type === "JSXMemberExpression") {
123
- const parts = [];
124
- let current = name;
125
- while (current) {
126
- if (current.type === "JSXIdentifier") {
127
- parts.unshift(current.name);
128
- break;
129
- }
130
- if (current.type === "JSXMemberExpression") {
131
- if (current.property?.type === "JSXIdentifier") {
132
- parts.unshift(current.property.name);
133
- }
134
- current = current.object;
135
- continue;
136
- }
137
- break;
138
- }
139
- return parts.length ? parts.join(".") : null;
140
- }
141
- return null;
142
- }
143
- function getImportedName(specifier) {
144
- if (specifier.type === "ImportDefaultSpecifier") {
145
- return "default";
146
- }
147
- if (specifier.type === "ImportSpecifier") {
148
- const imported = specifier.imported;
149
- if (imported?.type === "Identifier") {
150
- return imported.name;
151
- }
152
- if (imported?.type === "Literal") {
153
- return String(imported.value);
154
- }
155
- }
156
- return null;
157
- }
158
- // function findComponentImport(
159
- // ast: AstNode,
160
- // componentName: string,
161
- // ): ComponentImport | null {
162
- // const body = ast.body ?? [];
163
- // for (const statement of body) {
164
- // if (statement.type !== "ImportDeclaration") {
165
- // continue;
166
- // }
167
- // const source = statement.source?.value;
168
- // if (typeof source !== "string") {
169
- // continue;
170
- // }
171
- // for (const specifier of statement.specifiers ?? []) {
172
- // if (!specifier.local || specifier.local.name !== componentName) {
173
- // continue;
174
- // }
175
- // const exportName = getImportedName(specifier);
176
- // if (!exportName) {
177
- // continue;
178
- // }
179
- // return {
180
- // source,
181
- // exportName,
182
- // declaration: statement,
183
- // specifier,
184
- // };
185
- // }
186
- // }
187
- // return null;
188
- // }
189
- /* -------------------------------------------------------------------------- */
190
- /* JSX -> props */
191
- /* -------------------------------------------------------------------------- */
192
- function sourceSlice(code, node) {
193
- return code.slice(node.start, node.end);
194
- }
195
- // function jsxNameToExpression(name: AstNode): string | null {
196
- // if (name.type === "JSXIdentifier") {
197
- // return name.name;
198
- // }
199
- // if (name.type === "JSXMemberExpression") {
200
- // const object = jsxNameToExpression(name.object);
201
- // const property = jsxNameToExpression(name.property);
202
- // if (!object || !property) {
203
- // return null;
204
- // }
205
- // return `${object}.${property}`;
206
- // }
207
- // return null;
208
- // }
209
- function jsxAttributeKey(attribute) {
210
- const name = attribute.name;
211
- if (name?.type === "JSXIdentifier") {
212
- return name.name;
213
- }
214
- if (name?.type === "JSXNamespacedName") {
215
- const namespace = name.namespace?.name ?? "";
216
- const local = name.name?.name ?? "";
217
- return `${namespace}:${local}`;
218
- }
219
- return "";
220
- }
221
- function jsxAttributeValue(attribute, code) {
222
- const value = attribute.value;
223
- if (!value) {
224
- return "true";
225
- }
226
- if (value.type === "Literal") {
227
- return JSON.stringify(String(value.value ?? ""));
228
- }
229
- if (value.type === "JSXExpressionContainer") {
230
- const expression = value.expression;
231
- if (!expression || expression.type === "JSXEmptyExpression") {
232
- return "undefined";
233
- }
234
- return sourceSlice(code, expression);
235
- }
236
- if (value.type === "JSXElement" || value.type === "JSXFragment") {
237
- return sourceSlice(code, value);
238
- }
239
- return sourceSlice(code, value);
240
- }
241
- function jsxAttributesToProps(jsx, code) {
242
- const properties = [];
243
- const attributes = jsx.openingElement?.attributes ?? [];
244
- for (const attribute of attributes) {
245
- if (attribute.type === "JSXSpreadAttribute") {
246
- const argument = attribute.argument;
247
- if (!argument) {
248
- continue;
249
- }
250
- properties.push(`...${sourceSlice(code, argument)}`);
251
- continue;
252
- }
253
- if (attribute.type !== "JSXAttribute") {
254
- continue;
255
- }
256
- const key = jsxAttributeKey(attribute);
257
- if (!key) {
258
- continue;
259
- }
260
- const value = jsxAttributeValue(attribute, code);
261
- const validIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
262
- const propertyKey = validIdentifier ? key : JSON.stringify(key);
263
- properties.push(`${propertyKey}: ${value}`);
264
- }
265
- return `{ ${properties.join(", ")} }`;
266
- }
267
- /* -------------------------------------------------------------------------- */
268
- /* Import editing */
269
- /* -------------------------------------------------------------------------- */
270
- function createImportRemovalEdit(declaration, specifier, code) {
271
- const specifiers = declaration.specifiers ?? [];
272
- if (specifier.start == null || specifier.end == null) {
273
- return null;
274
- }
275
- if (specifiers.length === 1) {
276
- return {
277
- start: declaration.start,
278
- end: declaration.end,
279
- content: "",
280
- };
281
- }
282
- const index = specifiers.indexOf(specifier);
283
- if (index === -1) {
284
- return null;
285
- }
286
- /*
287
- * import Foo, { Bar } from "x"
288
- * ^^^^^^^^^
289
- *
290
- * import { Foo, Bar } from "x"
291
- * ^^^
292
- */
293
- if (index === 0) {
294
- const next = specifiers[index + 1];
295
- if (next?.start != null) {
296
- return {
297
- start: specifier.start,
298
- end: next.start,
299
- content: "",
300
- };
301
- }
302
- }
303
- const previous = specifiers[index - 1];
304
- if (previous?.end != null) {
305
- return {
306
- start: previous.end,
307
- end: specifier.end,
308
- content: "",
309
- };
310
- }
311
- return null;
312
- }
313
- function hasRuntimeImport(ast, name) {
314
- for (const statement of ast.body ?? []) {
315
- if (statement.type !== "ImportDeclaration") {
316
- continue;
317
- }
318
- if (statement.source?.value !== RUNTIME_IMPORT) {
319
- continue;
320
- }
321
- for (const specifier of statement.specifiers ?? []) {
322
- if (specifier.type === "ImportSpecifier" &&
323
- specifier.imported?.type === "Identifier" &&
324
- specifier.imported.name === name) {
325
- return true;
326
- }
327
- }
328
- }
329
- return false;
330
- }
331
- function createRuntimeImportEdit(ast, name) {
332
- if (hasRuntimeImport(ast, name)) {
333
- return {
334
- start: 0,
335
- end: 0,
336
- content: "",
337
- };
338
- }
339
- /*
340
- * Keep this simple and let Rolldown/Oxc
341
- * process the import normally afterward.
342
- */
343
- return {
344
- start: 0,
345
- end: 0,
346
- content: `import { ${name} } from "${RUNTIME_IMPORT}";\n`,
347
- };
348
- }
349
- /* -------------------------------------------------------------------------- */
350
- /* Function async */
351
- /* -------------------------------------------------------------------------- */
352
- function createAsyncEdit(functionNode, code) {
353
- if (functionNode.async) {
354
- return null;
355
- }
356
- if (functionNode.start == null) {
357
- return null;
358
- }
359
- /*
360
- * Arrow:
361
- *
362
- * (req, res) => ...
363
- *
364
- * becomes:
365
- *
366
- * async (req, res) => ...
367
- *
368
- */
369
- if (functionNode.type === "ArrowFunctionExpression") {
370
- return {
371
- start: functionNode.start,
372
- end: functionNode.start,
373
- content: "async ",
374
- };
375
- }
376
- /*
377
- * Function:
378
- *
379
- * function handler(...)
380
- *
381
- * becomes:
382
- *
383
- * async function handler(...)
384
- */
385
- if (functionNode.type === "FunctionDeclaration" ||
386
- functionNode.type === "FunctionExpression") {
387
- return {
388
- start: functionNode.start,
389
- end: functionNode.start,
390
- content: "async ",
391
- };
392
- }
393
- return null;
394
- }
395
- /* -------------------------------------------------------------------------- */
396
- /* Main transformer */
397
- /* -------------------------------------------------------------------------- */
398
- export function transformer(code, id, ast) {
399
- const edits = [];
400
- const entries = [];
401
- const componentImports = new Map();
402
- /*
403
- * Cache all imports first.
404
- */
405
- for (const statement of ast.body ?? []) {
406
- if (statement.type !== "ImportDeclaration") {
407
- continue;
408
- }
409
- const source = statement.source?.value;
410
- if (typeof source !== "string") {
411
- continue;
412
- }
413
- for (const specifier of statement.specifiers ?? []) {
414
- const localName = specifier.local?.name;
415
- if (!localName) {
416
- continue;
417
- }
418
- const exportName = getImportedName(specifier);
419
- if (!exportName) {
420
- continue;
421
- }
422
- componentImports.set(localName, {
423
- source,
424
- exportName,
425
- declaration: statement,
426
- specifier,
427
- });
428
- }
429
- }
430
- const removedImportDeclarations = new Set();
431
- const transformedCalls = new Set();
432
- walk(ast, (node, _parent, ancestors) => {
433
- if (node.type !== "CallExpression") {
434
- return;
435
- }
436
- if (transformedCalls.has(node)) {
437
- return;
438
- }
439
- const callee = node.callee;
440
- if (!isMemberExpression(callee)) {
441
- return;
442
- }
443
- const method = getMemberPropertyName(callee);
444
- if (method !== "send") {
445
- return;
446
- }
447
- const argument = node.arguments?.[0];
448
- if (!argument || argument.type !== "JSXElement") {
449
- return;
450
- }
451
- const functionNode = findFunctionParent(ancestors);
452
- if (!functionNode) {
453
- return;
454
- }
455
- const params = functionNode.params ?? [];
456
- if (params.length < 2) {
457
- return;
458
- }
459
- const requestParam = params[0];
460
- const responseParam = params[1];
461
- if (requestParam?.type !== "Identifier") {
462
- return;
463
- }
464
- if (responseParam?.type !== "Identifier") {
465
- return;
466
- }
467
- const componentName = getJSXComponentName(argument);
468
- if (!componentName) {
469
- return;
470
- }
471
- /*
472
- * For:
473
- *
474
- * <Foo />
475
- *
476
- * componentName = Foo
477
- *
478
- * For:
479
- *
480
- * <UI.Page />
481
- *
482
- * this only works when the import is
483
- * represented by the same local identifier.
484
- */
485
- const componentImport = componentImports.get(componentName);
486
- if (!componentImport) {
487
- return;
488
- }
489
- const componentImportPath = componentImport.source;
490
- const componentFile = resolveComponentFile(id, componentImportPath);
491
- /*
492
- * Only local component files become
493
- * Xanix pages.
494
- */
495
- if (!path.isAbsolute(componentFile)) {
496
- return;
497
- }
498
- const normalizedFile = normalizeFilePath(componentFile);
499
- const pageId = createPageId(normalizedFile);
500
- const props = jsxAttributesToProps(argument, code);
501
- entries.push({
502
- id: pageId,
503
- name: componentName,
504
- file: normalizedFile,
505
- path: componentImportPath,
506
- export: componentImport.exportName,
507
- });
508
- /*
509
- * Remove the server-side component import.
510
- */
511
- if (!removedImportDeclarations.has(componentImport.declaration)) {
512
- const importEdit = createImportRemovalEdit(componentImport.declaration, componentImport.specifier, code);
513
- if (importEdit) {
514
- edits.push(importEdit);
515
- }
516
- removedImportDeclarations.add(componentImport.declaration);
517
- }
518
- /*
519
- * Make the containing handler async.
520
- */
521
- const asyncEdit = createAsyncEdit(functionNode, code);
522
- if (asyncEdit) {
523
- edits.push(asyncEdit);
524
- }
525
- /*
526
- * Preserve the same runtime contract
527
- * used by the old Babel implementation:
528
- *
529
- * await xanixPage({
530
- * component: async () => (
531
- * await import("./Home")
532
- * ),
533
- * pageId,
534
- * req,
535
- * res,
536
- * props
537
- * })
538
- */
539
- const pageCall = [
540
- "await xanixPage({",
541
- `component: async () => (await import(${JSON.stringify(componentImportPath)})),`,
542
- `pageId: ${JSON.stringify(pageId)},`,
543
- `req: ${requestParam.name},`,
544
- `res: ${responseParam.name},`,
545
- `props: ${props},`,
546
- "})",
547
- ].join("\n");
548
- edits.push({
549
- start: argument.start,
550
- end: argument.end,
551
- content: pageCall,
552
- });
553
- transformedCalls.add(node);
554
- });
555
- if (!entries.length) {
556
- return null;
557
- }
558
- /*
559
- * Inject xanixPage import.
560
- */
561
- const runtimeImport = createRuntimeImportEdit(ast, "xanixPage");
562
- if (runtimeImport.content) {
563
- edits.push(runtimeImport);
564
- }
565
- /*
566
- * Apply edits backwards so offsets
567
- * remain valid.
568
- */
569
- edits.sort((a, b) => b.start - a.start);
570
- let transformedCode = code;
571
- let lastStart = Number.POSITIVE_INFINITY;
572
- for (const edit of edits) {
573
- /*
574
- * Ignore overlapping edits.
575
- */
576
- if (edit.end > lastStart) {
577
- continue;
578
- }
579
- transformedCode =
580
- transformedCode.slice(0, edit.start) +
581
- edit.content +
582
- transformedCode.slice(edit.end);
583
- lastStart = edit.start;
584
- }
585
- return {
586
- code: transformedCode,
587
- entries,
588
- };
589
- }
@@ -1,2 +0,0 @@
1
- import type { Plugin } from "rollup";
2
- export default function xanixReactRefresh(WebSocketPort: number): Plugin;
@@ -1,121 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs";
3
- import { parse } from "@babel/parser";
4
- import traverse from "@babel/traverse";
5
- import generate from "@babel/generator";
6
- import * as t from "@babel/types";
7
- import { getClientRuntimeFile } from "../../include/utils.js";
8
- const root = process.cwd();
9
- export default function xanixReactRefresh(WebSocketPort) {
10
- return {
11
- name: "xanix-react-refresh",
12
- load(id) {
13
- if (path.resolve(id) !== getClientRuntimeFile()) {
14
- return null;
15
- }
16
- const code = fs.readFileSync(id, "utf8");
17
- const refreshCode = `
18
- import * as RefreshRuntime from "react-refresh/runtime";
19
-
20
- ${code}
21
-
22
- RefreshRuntime.injectIntoGlobalHook(window);
23
- window.$RefreshReg$ = RefreshRuntime.register;
24
- window.$RefreshSig$ = () => (type) => type;
25
- const ws = new WebSocket("ws://localhost:" + ${WebSocketPort});
26
-
27
-
28
- ws.onmessage = async (event) => {
29
- const files = JSON.parse(event.data);
30
-
31
- for (const file of files) {
32
- if (!file.endsWith(".js")) {
33
- continue;
34
- }
35
-
36
- const url =
37
- getImportUrl(file.replace(/\\.js$/, "")) +
38
- "?t=" +
39
- Date.now();
40
-
41
- await import(url);
42
- }
43
-
44
- RefreshRuntime.performReactRefresh();
45
- ws.send("reload")
46
- };
47
- `;
48
- return {
49
- code: refreshCode,
50
- map: null,
51
- };
52
- },
53
- transform(code, id) {
54
- if (path.resolve(id) === getClientRuntimeFile()) {
55
- return null;
56
- }
57
- if (id.includes("node_modules")) {
58
- return null;
59
- }
60
- if (!/\.(tsx?|jsx?)$/.test(id)) {
61
- return null;
62
- }
63
- const ast = parse(code, {
64
- sourceType: "module",
65
- plugins: ["typescript", "jsx"],
66
- });
67
- const registrations = [];
68
- traverse(ast, {
69
- FunctionDeclaration(path) {
70
- const node = path.node;
71
- if (!node.id) {
72
- return;
73
- }
74
- const name = node.id.name;
75
- if (!isReactComponent(name)) {
76
- return;
77
- }
78
- registrations.push(createRegistration(name, id));
79
- },
80
- VariableDeclarator(path) {
81
- const node = path.node;
82
- if (!t.isIdentifier(node.id)) {
83
- return;
84
- }
85
- const name = node.id.name;
86
- if (!isReactComponent(name)) {
87
- return;
88
- }
89
- if (!t.isArrowFunctionExpression(node.init) &&
90
- !t.isFunctionExpression(node.init)) {
91
- return;
92
- }
93
- registrations.push(createRegistration(name, id));
94
- },
95
- });
96
- if (registrations.length === 0) {
97
- return null;
98
- }
99
- ast.program.body.push(...registrations);
100
- const result = generate(ast, {
101
- sourceMaps: true,
102
- sourceFileName: id,
103
- }, code);
104
- return {
105
- code: result.code,
106
- map: result.map,
107
- };
108
- },
109
- };
110
- }
111
- function isReactComponent(name) {
112
- return /^[A-Z]/.test(name);
113
- }
114
- function createRegistration(name, filename) {
115
- const relative = path.relative(root, filename).replaceAll("\\", "/");
116
- const componentId = `${relative}:${name}`;
117
- return t.expressionStatement(t.callExpression(t.identifier("$RefreshReg$"), [
118
- t.identifier(name),
119
- t.stringLiteral(componentId),
120
- ]));
121
- }
@@ -1,2 +0,0 @@
1
- import type { Plugin } from "rolldown";
2
- export default function xanixReactRefresh(webSocketPort: number): Plugin;