xanix 1.0.19 → 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,166 +0,0 @@
1
- import path from "node:path";
2
- import { rolldown } from "rolldown";
3
- import { createRequire } from "node:module";
4
- import { tsconfigPathsMatcher } from "../XanixTsconfigAlias.js";
5
- import fs from "node:fs";
6
- import loadEnv from "../../config/loadEnv.js";
7
- import { pathToFileURL } from "node:url";
8
- const require = createRequire(import.meta.url);
9
- const cacheDir = path.join(process.cwd(), ".xanix/cache");
10
- const cached = new Map();
11
- const makeFilename = (id) => id.replace(/[\/\\]/g, "-").replaceAll("@", "");
12
- const makeEsmShim = async (resolved) => {
13
- let namedExports = [];
14
- let hasDefault = false;
15
- try {
16
- const mod = await import(pathToFileURL(resolved).href);
17
- hasDefault =
18
- mod &&
19
- (typeof mod === "object" || typeof mod === "function") &&
20
- "default" in mod;
21
- namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
22
- }
23
- catch (err) {
24
- console.warn(`[cache-deps] failed to inspect ${resolved}:`, err);
25
- }
26
- const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
27
- lines.push(hasDefault ? `export default __mod.default;` : `export default __mod;`);
28
- for (const exportName of namedExports) {
29
- if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
30
- lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
31
- }
32
- }
33
- return lines.join("\n");
34
- };
35
- const resolveDependency = (id) => {
36
- try {
37
- return require.resolve(id);
38
- }
39
- catch {
40
- // Try common extension substitutions.
41
- const candidates = [
42
- id.replace(/\.js$/, ".mjs"),
43
- id.replace(/\.js$/, ".cjs"),
44
- `${id}.mjs`,
45
- `${id}.cjs`,
46
- ];
47
- for (const candidate of candidates) {
48
- try {
49
- return require.resolve(candidate);
50
- }
51
- catch { }
52
- }
53
- throw new Error(`Cannot resolve dependency: ${id}`);
54
- }
55
- };
56
- const XanixCache = ({ cacheDir = "./.xanix/cache", define, }) => {
57
- const dependencyMap = new Map();
58
- const plugins = {
59
- name: "XanixCache",
60
- buildStart() {
61
- dependencyMap.clear();
62
- },
63
- watchChange() {
64
- dependencyMap.clear();
65
- },
66
- async resolveId(id) {
67
- if (id.startsWith(".") ||
68
- path.isAbsolute(id) ||
69
- id === "virtual:xanix-document" ||
70
- tsconfigPathsMatcher(id)) {
71
- return null;
72
- }
73
- try {
74
- let info = dependencyMap.get(id);
75
- if (!info) {
76
- const resolved = resolveDependency(id);
77
- console.log(resolved);
78
- info = {
79
- filename: `${makeFilename(id)}.js`,
80
- code: await makeEsmShim(resolved),
81
- resolved,
82
- };
83
- dependencyMap.set(id, info);
84
- }
85
- return {
86
- id: `/.xanix/cache/${info.filename}`,
87
- external: true,
88
- };
89
- }
90
- catch (error) { }
91
- return null;
92
- },
93
- async generateBundle() {
94
- const manifestPath = path.resolve(cacheDir, "cache-manifest.json");
95
- const currentManifest = fs.existsSync(manifestPath)
96
- ? JSON.parse(fs.readFileSync(manifestPath, "utf-8"))
97
- : {};
98
- let changed = false;
99
- const inputs = {};
100
- const manifest = {};
101
- for (const id of dependencyMap.keys()) {
102
- if (!currentManifest[id] ||
103
- currentManifest[id].resolved !== dependencyMap.get(id)?.resolved) {
104
- changed = true;
105
- }
106
- inputs[makeFilename(id)] = `dep:${id}`;
107
- manifest[id] = {
108
- filename: dependencyMap.get(id)?.filename,
109
- resolved: dependencyMap.get(id)?.resolved,
110
- };
111
- }
112
- if (!changed) {
113
- return;
114
- }
115
- const bundle = await rolldown({
116
- input: inputs,
117
- treeshake: true,
118
- tsconfig: true,
119
- resolve: {
120
- extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
121
- conditionNames: ["browser", "import", "module", "default"],
122
- },
123
- transform: {
124
- target: "es2022",
125
- jsx: {
126
- runtime: "automatic",
127
- },
128
- define: await loadEnv({
129
- mode: "development",
130
- isClient: true,
131
- }),
132
- },
133
- plugins: [
134
- {
135
- name: "generate",
136
- resolveId(id) {
137
- if (id.startsWith("dep:")) {
138
- return id;
139
- }
140
- return null;
141
- },
142
- async load(id) {
143
- if (id.startsWith("dep:")) {
144
- const code = dependencyMap.get(id.replace("dep:", ""))?.code;
145
- return code;
146
- }
147
- return null;
148
- },
149
- },
150
- ],
151
- });
152
- await bundle.write({
153
- dir: cacheDir,
154
- format: "esm",
155
- exports: "auto",
156
- sourcemap: true,
157
- codeSplitting: true,
158
- entryFileNames: `[name].js`,
159
- });
160
- await bundle.close();
161
- fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
162
- },
163
- };
164
- return plugins;
165
- };
166
- export default XanixCache;
@@ -1,11 +0,0 @@
1
- import { XanixClientEntry } from "../../../types";
2
- export type DependencyInfo = {
3
- source: string;
4
- resolved: string;
5
- packageName: string;
6
- };
7
- export type CacheMetadata = Map<string, {
8
- file: string;
9
- }>;
10
- declare const BuildClientCache: (entries: XanixClientEntry[], metadata?: CacheMetadata) => Promise<CacheMetadata>;
11
- export default BuildClientCache;
@@ -1,129 +0,0 @@
1
- import path from "node:path";
2
- import { rollup } from "rollup";
3
- import { build } from "esbuild";
4
- import { builtinModules, createRequire } from "node:module";
5
- import { getClientRuntimeFile } from "../../../include/utils.js";
6
- import outdirs from "../../../../outdirs.js";
7
- import { xanixCachePlugins } from "../plugins.js";
8
- import defines from "../../config/defines.js";
9
- import { pathToFileURL } from "node:url";
10
- import external from "../../config/external.js";
11
- const require = createRequire(import.meta.url);
12
- const nodeBuiltins = new Set(builtinModules.flatMap((id) => [id, `node:${id}`]));
13
- const GenerateGraph = async (entries) => {
14
- const collector = new Map();
15
- const input = [];
16
- for (const entry of entries) {
17
- input.push(entry.file);
18
- }
19
- input.push(getClientRuntimeFile());
20
- const bundle = await rollup({
21
- input,
22
- plugins: [...xanixCachePlugins()],
23
- external(id) {
24
- if (nodeBuiltins.has(id)) {
25
- return true;
26
- }
27
- if (!external(id)) {
28
- return false;
29
- }
30
- collector.set(id, {
31
- source: id,
32
- resolved: require.resolve(id, {
33
- paths: [process.cwd()],
34
- }),
35
- packageName: id,
36
- });
37
- return true;
38
- },
39
- });
40
- await bundle.close();
41
- return collector;
42
- };
43
- // Wraps each CJS dep in a virtual ESM file that re-exports named exports detected via require()
44
- const makeCjsWrapperPlugin = (wrappers) => ({
45
- name: "cjs-named-exports",
46
- setup(build) {
47
- build.onResolve({ filter: /\?cjs-wrapper$/ }, (args) => ({
48
- path: args.path,
49
- namespace: "cjs-wrapper",
50
- }));
51
- build.onLoad({ filter: /.*/, namespace: "cjs-wrapper" }, (args) => {
52
- const contents = wrappers.get(args.path);
53
- return { contents, resolveDir: process.cwd() };
54
- });
55
- },
56
- });
57
- const buildWrappers = async (input) => {
58
- const wrappers = new Map();
59
- const wrappedInput = {};
60
- for (const [name, resolved] of Object.entries(input)) {
61
- const key = `${name}?cjs-wrapper`;
62
- let namedExports = [];
63
- let hasDefault = false;
64
- try {
65
- // Node: inspect the actual module
66
- const mod = await import(pathToFileURL(resolved).href);
67
- hasDefault =
68
- mod &&
69
- (typeof mod === "object" || typeof mod === "function") &&
70
- "default" in mod;
71
- namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
72
- }
73
- catch (err) {
74
- console.log(`Failed to inspect ${name}:`, err);
75
- }
76
- // esbuild: use a normal filesystem path
77
- const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
78
- if (hasDefault) {
79
- lines.push(`export default __mod.default;`);
80
- }
81
- else {
82
- lines.push(`export default __mod;`);
83
- }
84
- for (const exportName of namedExports) {
85
- if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
86
- lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
87
- }
88
- }
89
- wrappers.set(key, lines.join("\n"));
90
- wrappedInput[name] = key;
91
- }
92
- return {
93
- wrappers,
94
- wrappedInput,
95
- };
96
- };
97
- const bundleDeps = async (input, outdir) => {
98
- const { wrappers, wrappedInput } = await buildWrappers(input);
99
- await build({
100
- entryPoints: wrappedInput,
101
- bundle: true,
102
- splitting: true,
103
- format: "esm",
104
- target: "es2022",
105
- outdir,
106
- entryNames: "[name]",
107
- chunkNames: "chunks/[hash]",
108
- platform: "browser",
109
- sourcemap: true,
110
- define: defines({ mode: "development", isClient: true }),
111
- plugins: [makeCjsWrapperPlugin(wrappers)],
112
- });
113
- };
114
- // const metadata: CacheMetadata = new Map();
115
- const BuildClientCache = async (entries, metadata = new Map()) => {
116
- const input = {};
117
- const dependencies = await GenerateGraph(entries);
118
- for (const dependency of dependencies.values()) {
119
- const entryName = dependency.source.replace(/^@/, "").replace(/\//g, "-");
120
- input[entryName] = dependency.resolved;
121
- metadata.set(dependency.source, {
122
- file: `${entryName}.js`,
123
- });
124
- }
125
- const cacheDir = path.resolve(outdirs.server, "cache");
126
- await bundleDeps(input, cacheDir);
127
- return metadata;
128
- };
129
- export default BuildClientCache;
@@ -1,5 +0,0 @@
1
- import { XanixClientEntry } from "../../../types";
2
- import type { Plugin } from "rollup";
3
- import { CacheMetadata } from "./BuildClientCache.js";
4
- declare function XanixResolveCacheDeps(metadata: CacheMetadata, entries: XanixClientEntry[]): Plugin;
5
- export default XanixResolveCacheDeps;
@@ -1,26 +0,0 @@
1
- import path from "node:path";
2
- import BuildCache from "./BuildClientCache.js";
3
- import outdirs from "../../../../outdirs.js";
4
- function XanixResolveCacheDeps(metadata, entries) {
5
- return {
6
- name: "xanix:cached-deps",
7
- async resolveId(source) {
8
- if (source.startsWith(".") || path.isAbsolute(source)) {
9
- return null;
10
- }
11
- const dependency = metadata.get(source);
12
- if (dependency) {
13
- return { id: `/${outdirs.cache}/${dependency.file}`, external: true };
14
- }
15
- const buildCache = await BuildCache(entries);
16
- const newDependency = buildCache.get(source);
17
- if (newDependency) {
18
- return {
19
- id: `/${outdirs.cache}/${newDependency.file}`,
20
- external: true,
21
- };
22
- }
23
- },
24
- };
25
- }
26
- export default XanixResolveCacheDeps;
@@ -1,11 +0,0 @@
1
- import type { Plugin } from "rollup";
2
- export interface OxcResolverOptions {
3
- extensions?: string[];
4
- conditionNames?: string[];
5
- mainFields?: string[];
6
- aliasFields?: string[];
7
- tsconfig?: string;
8
- symlinks?: boolean;
9
- }
10
- declare function XanixResolver(options?: OxcResolverOptions): Plugin;
11
- export default XanixResolver;
@@ -1,55 +0,0 @@
1
- import { ResolverFactory } from "oxc-resolver";
2
- function XanixResolver(options = {}) {
3
- const resolver = new ResolverFactory({
4
- extensions: options.extensions ?? [
5
- ".mjs",
6
- ".js",
7
- ".json",
8
- ".ts",
9
- ".tsx",
10
- ".jsx",
11
- ],
12
- conditionNames: options.conditionNames ?? [
13
- "node",
14
- "import",
15
- "module",
16
- "default",
17
- ],
18
- mainFields: options.mainFields ?? ["module", "main"],
19
- aliasFields: options.aliasFields ?? [],
20
- symlinks: options.symlinks ?? true,
21
- tsconfig: options.tsconfig
22
- ? {
23
- configFile: options.tsconfig,
24
- }
25
- : undefined,
26
- });
27
- return {
28
- name: "xanix-oxc-resolver",
29
- resolveId(source, importer, options) {
30
- if (!importer) {
31
- return null;
32
- }
33
- if (source.startsWith("\0") || source.startsWith("virtual:")) {
34
- return null;
35
- }
36
- try {
37
- const result = resolver.resolveFileSync(importer, source);
38
- if (!result.path) {
39
- return null;
40
- }
41
- return {
42
- id: result.path,
43
- external: false,
44
- };
45
- }
46
- catch {
47
- if (options?.isEntry) {
48
- return null;
49
- }
50
- return null;
51
- }
52
- },
53
- };
54
- }
55
- export default XanixResolver;
@@ -1,5 +0,0 @@
1
- import type { Plugin } from "rolldown";
2
- export interface XanixServerTransformOptions {
3
- mode: "watch" | "start";
4
- }
5
- export default function XanixServerTransform(options: XanixServerTransformOptions): Plugin;
@@ -1,207 +0,0 @@
1
- const RUNTIME_IMPORT = "xanix/runtime";
2
- function isIdentifier(node, name) {
3
- if (!node || node.type !== "Identifier") {
4
- return false;
5
- }
6
- return name === undefined || node.name === name;
7
- }
8
- function isCallExpression(node) {
9
- return node?.type === "CallExpression";
10
- }
11
- function isMemberExpression(node) {
12
- return (node?.type === "MemberExpression" ||
13
- node?.type === "OptionalMemberExpression");
14
- }
15
- function getMemberPropertyName(node) {
16
- if (!isMemberExpression(node)) {
17
- return null;
18
- }
19
- if (node.computed) {
20
- if (node.property?.type === "Literal" &&
21
- typeof node.property.value === "string") {
22
- return node.property.value;
23
- }
24
- return null;
25
- }
26
- if (node.property?.type === "Identifier") {
27
- return node.property.name;
28
- }
29
- return null;
30
- }
31
- function walk(node, callback, parent = null) {
32
- callback(node, parent);
33
- for (const key of Object.keys(node)) {
34
- if (key === "parent" ||
35
- key === "loc" ||
36
- key === "range" ||
37
- key === "tokens" ||
38
- key === "comments") {
39
- continue;
40
- }
41
- const value = node[key];
42
- if (Array.isArray(value)) {
43
- for (const item of value) {
44
- if (item && typeof item === "object") {
45
- if (typeof item.type === "string") {
46
- walk(item, callback, node);
47
- }
48
- }
49
- }
50
- continue;
51
- }
52
- if (value && typeof value === "object" && typeof value.type === "string") {
53
- walk(value, callback, node);
54
- }
55
- }
56
- }
57
- function findExpressServer(ast) {
58
- const expressApps = new Map();
59
- /*
60
- * Find:
61
- *
62
- * const app = express();
63
- */
64
- walk(ast, (node) => {
65
- if (node.type !== "VariableDeclarator") {
66
- return;
67
- }
68
- if (!isIdentifier(node.id)) {
69
- return;
70
- }
71
- if (!isCallExpression(node.init)) {
72
- return;
73
- }
74
- if (!isIdentifier(node.init.callee, "express")) {
75
- return;
76
- }
77
- expressApps.set(node.id.name, node);
78
- });
79
- if (!expressApps.size) {
80
- return null;
81
- }
82
- /*
83
- * Find:
84
- *
85
- * app.listen(...)
86
- */
87
- let result = null;
88
- walk(ast, (node) => {
89
- if (result) {
90
- return;
91
- }
92
- if (node.type !== "CallExpression") {
93
- return;
94
- }
95
- const callee = node.callee;
96
- if (!isMemberExpression(callee)) {
97
- return;
98
- }
99
- if (getMemberPropertyName(callee) !== "listen") {
100
- return;
101
- }
102
- if (!isIdentifier(callee.object)) {
103
- return;
104
- }
105
- const declarator = expressApps.get(callee.object.name);
106
- if (!declarator) {
107
- return;
108
- }
109
- result = {
110
- appName: callee.object.name,
111
- declarator,
112
- };
113
- });
114
- return result;
115
- }
116
- function hasRuntimeImport(ast) {
117
- for (const statement of ast.body ?? []) {
118
- if (statement.type !== "ImportDeclaration") {
119
- continue;
120
- }
121
- if (statement.source?.value !== RUNTIME_IMPORT) {
122
- continue;
123
- }
124
- for (const specifier of statement.specifiers ?? []) {
125
- if (specifier.type === "ImportSpecifier" &&
126
- specifier.imported?.type === "Identifier" &&
127
- specifier.imported.name === "createXanixServer") {
128
- return true;
129
- }
130
- }
131
- }
132
- return false;
133
- }
134
- function createRuntimeImport(ast) {
135
- if (hasRuntimeImport(ast)) {
136
- return "";
137
- }
138
- return `import { createXanixServer } from "${RUNTIME_IMPORT}";\n`;
139
- }
140
- function getLanguage(id) {
141
- const file = id.split("?")[0];
142
- if (file.endsWith(".tsx")) {
143
- return "tsx";
144
- }
145
- if (file.endsWith(".ts")) {
146
- return "ts";
147
- }
148
- if (file.endsWith(".jsx")) {
149
- return "jsx";
150
- }
151
- return "js";
152
- }
153
- export default function XanixServerTransform(options) {
154
- return {
155
- name: "xanix-server-transform",
156
- transform: {
157
- filter: {
158
- id: /^(?!.*(?:node_modules[\\/])).*\.[cm]?[jt]sx?$/,
159
- },
160
- handler(code, id) {
161
- /*
162
- * IMPORTANT:
163
- *
164
- * This is Rolldown's parser.
165
- * No Babel parser.
166
- */
167
- let ast;
168
- try {
169
- ast = this.parse(code, {
170
- lang: getLanguage(id),
171
- });
172
- }
173
- catch {
174
- return null;
175
- }
176
- const server = findExpressServer(ast);
177
- if (!server) {
178
- return null;
179
- }
180
- const init = server.declarator.init;
181
- if (!init ||
182
- !isCallExpression(init) ||
183
- !isIdentifier(init.callee, "express")) {
184
- return null;
185
- }
186
- if (init.start == null || init.end == null) {
187
- return null;
188
- }
189
- const replacement = `createXanixServer({ mode: ${JSON.stringify(options.mode)} })`;
190
- /*
191
- * We only need one source replacement.
192
- *
193
- * If you're using Rolldown native MagicString,
194
- * perform the overwrite there.
195
- */
196
- const importCode = createRuntimeImport(ast);
197
- const before = code.slice(0, init.start);
198
- const after = code.slice(init.end);
199
- const transformed = importCode + before + replacement + after;
200
- return {
201
- code: transformed,
202
- map: null,
203
- };
204
- },
205
- },
206
- };
207
- }
@@ -1,3 +0,0 @@
1
- import type { Plugin } from "rollup";
2
- declare function xanixTransform(): Plugin;
3
- export default xanixTransform;
@@ -1,23 +0,0 @@
1
- import { transform } from "oxc-transform";
2
- function xanixTransform() {
3
- return {
4
- name: "xanix-transform",
5
- async transform(code, id) {
6
- if (!id.endsWith(".tsx")) {
7
- return null;
8
- }
9
- const result = await transform(id, code, {
10
- lang: "tsx",
11
- sourcemap: true,
12
- jsx: {
13
- runtime: "automatic",
14
- },
15
- });
16
- return {
17
- code: result.code,
18
- map: result.map,
19
- };
20
- },
21
- };
22
- }
23
- export default xanixTransform;
@@ -1,19 +0,0 @@
1
- import type { Plugin } from "rolldown";
2
- /**
3
- * Check whether an import matches a tsconfig path alias.
4
- *
5
- * Examples:
6
- *
7
- * @db
8
- * @db/index
9
- * @db/user
10
- *
11
- * with:
12
- *
13
- * "@db/*": ["./src/db/*"]
14
- */
15
- export declare function tsconfigPathsMatcher(id: string): boolean;
16
- /**
17
- * Rollup plugin.
18
- */
19
- export default function xanixTsconfigAlias(): Plugin;