every-plugin 2.10.1 → 3.0.0-rc.10

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 (480) hide show
  1. package/bin/every-plugin-serve.mjs +12 -0
  2. package/bin/every-plugin.mjs +59 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +1 -2
  4. package/dist/build/artifact-names.cjs +119 -0
  5. package/dist/build/artifact-names.cjs.map +1 -0
  6. package/dist/build/artifact-names.d.cts +68 -0
  7. package/dist/build/artifact-names.d.cts.map +1 -0
  8. package/dist/build/artifact-names.d.mts +68 -0
  9. package/dist/build/artifact-names.d.mts.map +1 -0
  10. package/dist/build/artifact-names.mjs +102 -0
  11. package/dist/build/artifact-names.mjs.map +1 -0
  12. package/dist/build/contract-types.cjs +89 -0
  13. package/dist/build/contract-types.cjs.map +1 -0
  14. package/dist/build/contract-types.mjs +81 -0
  15. package/dist/build/contract-types.mjs.map +1 -0
  16. package/dist/build/rspack/build-report-plugin.cjs +37 -0
  17. package/dist/build/rspack/build-report-plugin.cjs.map +1 -0
  18. package/dist/build/rspack/build-report-plugin.d.cts +18 -0
  19. package/dist/build/rspack/build-report-plugin.d.cts.map +1 -0
  20. package/dist/build/rspack/build-report-plugin.d.mts +18 -0
  21. package/dist/build/rspack/build-report-plugin.d.mts.map +1 -0
  22. package/dist/build/rspack/build-report-plugin.mjs +37 -0
  23. package/dist/build/rspack/build-report-plugin.mjs.map +1 -0
  24. package/dist/build/rspack/chunk-completeness-plugin.cjs +59 -0
  25. package/dist/build/rspack/chunk-completeness-plugin.cjs.map +1 -0
  26. package/dist/build/rspack/chunk-completeness-plugin.mjs +59 -0
  27. package/dist/build/rspack/chunk-completeness-plugin.mjs.map +1 -0
  28. package/dist/build/rspack/compose.cjs +69 -0
  29. package/dist/build/rspack/compose.cjs.map +1 -0
  30. package/dist/build/rspack/compose.d.cts +20 -0
  31. package/dist/build/rspack/compose.d.cts.map +1 -0
  32. package/dist/build/rspack/compose.d.mts +20 -0
  33. package/dist/build/rspack/compose.d.mts.map +1 -0
  34. package/dist/build/rspack/compose.mjs +65 -0
  35. package/dist/build/rspack/compose.mjs.map +1 -0
  36. package/dist/build/rspack/fix-mf-data-uri-plugin.cjs +11 -11
  37. package/dist/build/rspack/fix-mf-data-uri-plugin.cjs.map +1 -1
  38. package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts +2 -0
  39. package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts.map +1 -1
  40. package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts +2 -0
  41. package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts.map +1 -1
  42. package/dist/build/rspack/fix-mf-data-uri-plugin.mjs +11 -10
  43. package/dist/build/rspack/fix-mf-data-uri-plugin.mjs.map +1 -1
  44. package/dist/build/rspack/generated-config.cjs +35 -0
  45. package/dist/build/rspack/generated-config.cjs.map +1 -0
  46. package/dist/build/rspack/generated-config.mjs +32 -0
  47. package/dist/build/rspack/generated-config.mjs.map +1 -0
  48. package/dist/build/rspack/index.cjs +8 -5
  49. package/dist/build/rspack/index.d.cts +5 -3
  50. package/dist/build/rspack/index.d.mts +5 -3
  51. package/dist/build/rspack/index.mjs +5 -3
  52. package/dist/build/rspack/module-federation.cjs +2 -2
  53. package/dist/build/rspack/module-federation.cjs.map +1 -1
  54. package/dist/build/rspack/module-federation.mjs +1 -1
  55. package/dist/build/rspack/module-federation.mjs.map +1 -1
  56. package/dist/build/rspack/plugin.cjs +44 -69
  57. package/dist/build/rspack/plugin.cjs.map +1 -1
  58. package/dist/build/rspack/plugin.d.cts +4 -13
  59. package/dist/build/rspack/plugin.d.cts.map +1 -1
  60. package/dist/build/rspack/plugin.d.mts +4 -13
  61. package/dist/build/rspack/plugin.d.mts.map +1 -1
  62. package/dist/build/rspack/plugin.mjs +44 -69
  63. package/dist/build/rspack/plugin.mjs.map +1 -1
  64. package/dist/build/rspack/utils.cjs +7 -5
  65. package/dist/build/rspack/utils.cjs.map +1 -1
  66. package/dist/build/rspack/utils.mjs +7 -6
  67. package/dist/build/rspack/utils.mjs.map +1 -1
  68. package/dist/build/ui/factory.cjs +88 -0
  69. package/dist/build/ui/factory.cjs.map +1 -0
  70. package/dist/build/ui/factory.d.cts +11 -0
  71. package/dist/build/ui/factory.d.cts.map +1 -0
  72. package/dist/build/ui/factory.d.mts +11 -0
  73. package/dist/build/ui/factory.d.mts.map +1 -0
  74. package/dist/build/ui/factory.mjs +80 -0
  75. package/dist/build/ui/factory.mjs.map +1 -0
  76. package/dist/build/ui/generated-config.cjs +122 -0
  77. package/dist/build/ui/generated-config.cjs.map +1 -0
  78. package/dist/build/ui/generated-config.d.cts +33 -0
  79. package/dist/build/ui/generated-config.d.cts.map +1 -0
  80. package/dist/build/ui/generated-config.d.mts +33 -0
  81. package/dist/build/ui/generated-config.d.mts.map +1 -0
  82. package/dist/build/ui/generated-config.mjs +114 -0
  83. package/dist/build/ui/generated-config.mjs.map +1 -0
  84. package/dist/build/ui/hash-artifacts-plugin.cjs +61 -0
  85. package/dist/build/ui/hash-artifacts-plugin.cjs.map +1 -0
  86. package/dist/build/ui/hash-artifacts-plugin.d.cts +20 -0
  87. package/dist/build/ui/hash-artifacts-plugin.d.cts.map +1 -0
  88. package/dist/build/ui/hash-artifacts-plugin.d.mts +20 -0
  89. package/dist/build/ui/hash-artifacts-plugin.d.mts.map +1 -0
  90. package/dist/build/ui/hash-artifacts-plugin.mjs +58 -0
  91. package/dist/build/ui/hash-artifacts-plugin.mjs.map +1 -0
  92. package/dist/build/ui/index.cjs +90 -0
  93. package/dist/build/ui/index.cjs.map +1 -0
  94. package/dist/build/ui/index.d.cts +29 -0
  95. package/dist/build/ui/index.d.cts.map +1 -0
  96. package/dist/build/ui/index.d.mts +29 -0
  97. package/dist/build/ui/index.d.mts.map +1 -0
  98. package/dist/build/ui/index.mjs +68 -0
  99. package/dist/build/ui/index.mjs.map +1 -0
  100. package/dist/build/ui/manifest-plugin.cjs +37 -0
  101. package/dist/build/ui/manifest-plugin.cjs.map +1 -0
  102. package/dist/build/ui/manifest-plugin.d.cts +19 -0
  103. package/dist/build/ui/manifest-plugin.d.cts.map +1 -0
  104. package/dist/build/ui/manifest-plugin.d.mts +19 -0
  105. package/dist/build/ui/manifest-plugin.d.mts.map +1 -0
  106. package/dist/build/ui/manifest-plugin.mjs +37 -0
  107. package/dist/build/ui/manifest-plugin.mjs.map +1 -0
  108. package/dist/build/ui/rsbuild-config.cjs +203 -0
  109. package/dist/build/ui/rsbuild-config.cjs.map +1 -0
  110. package/dist/build/ui/rsbuild-config.d.cts +45 -0
  111. package/dist/build/ui/rsbuild-config.d.cts.map +1 -0
  112. package/dist/build/ui/rsbuild-config.d.mts +45 -0
  113. package/dist/build/ui/rsbuild-config.d.mts.map +1 -0
  114. package/dist/build/ui/rsbuild-config.mjs +200 -0
  115. package/dist/build/ui/rsbuild-config.mjs.map +1 -0
  116. package/dist/build/ui/stubs.cjs +107 -0
  117. package/dist/build/ui/stubs.cjs.map +1 -0
  118. package/dist/build/ui/stubs.d.cts +25 -0
  119. package/dist/build/ui/stubs.d.cts.map +1 -0
  120. package/dist/build/ui/stubs.d.mts +25 -0
  121. package/dist/build/ui/stubs.d.mts.map +1 -0
  122. package/dist/build/ui/stubs.mjs +106 -0
  123. package/dist/build/ui/stubs.mjs.map +1 -0
  124. package/dist/cli.cjs +83 -0
  125. package/dist/cli.cjs.map +1 -0
  126. package/dist/cli.d.cts +6 -0
  127. package/dist/cli.d.cts.map +1 -0
  128. package/dist/cli.d.mts +6 -0
  129. package/dist/cli.d.mts.map +1 -0
  130. package/dist/cli.mjs +82 -0
  131. package/dist/cli.mjs.map +1 -0
  132. package/dist/client.cjs +69 -0
  133. package/dist/client.cjs.map +1 -0
  134. package/dist/client.d.cts +15 -0
  135. package/dist/client.d.cts.map +1 -0
  136. package/dist/client.d.mts +15 -0
  137. package/dist/client.d.mts.map +1 -0
  138. package/dist/client.mjs +68 -0
  139. package/dist/client.mjs.map +1 -0
  140. package/dist/dev/host.cjs +149 -0
  141. package/dist/dev/host.cjs.map +1 -0
  142. package/dist/dev/host.d.cts +32 -0
  143. package/dist/dev/host.d.cts.map +1 -0
  144. package/dist/dev/host.d.mts +32 -0
  145. package/dist/dev/host.d.mts.map +1 -0
  146. package/dist/dev/host.mjs +148 -0
  147. package/dist/dev/host.mjs.map +1 -0
  148. package/dist/dev/serve.cjs +295 -0
  149. package/dist/dev/serve.cjs.map +1 -0
  150. package/dist/dev/serve.d.cts +23 -0
  151. package/dist/dev/serve.d.cts.map +1 -0
  152. package/dist/dev/serve.d.mts +23 -0
  153. package/dist/dev/serve.d.mts.map +1 -0
  154. package/dist/dev/serve.mjs +289 -0
  155. package/dist/dev/serve.mjs.map +1 -0
  156. package/dist/dev/watch-kill.cjs +39 -0
  157. package/dist/dev/watch-kill.cjs.map +1 -0
  158. package/dist/dev/watch-kill.mjs +38 -0
  159. package/dist/dev/watch-kill.mjs.map +1 -0
  160. package/dist/effect-helpers.cjs +23 -0
  161. package/dist/effect-helpers.cjs.map +1 -0
  162. package/dist/effect-helpers.d.cts +20 -0
  163. package/dist/effect-helpers.d.cts.map +1 -0
  164. package/dist/effect-helpers.d.mts +20 -0
  165. package/dist/effect-helpers.d.mts.map +1 -0
  166. package/dist/effect-helpers.mjs +22 -0
  167. package/dist/effect-helpers.mjs.map +1 -0
  168. package/dist/errors.cjs +50 -69
  169. package/dist/errors.cjs.map +1 -1
  170. package/dist/errors.d.cts +13 -96
  171. package/dist/errors.d.cts.map +1 -1
  172. package/dist/errors.d.mts +13 -96
  173. package/dist/errors.d.mts.map +1 -1
  174. package/dist/errors.mjs +16 -34
  175. package/dist/errors.mjs.map +1 -1
  176. package/dist/identity.cjs +19 -0
  177. package/dist/identity.cjs.map +1 -0
  178. package/dist/identity.d.cts +33 -0
  179. package/dist/identity.d.cts.map +1 -0
  180. package/dist/identity.d.mts +33 -0
  181. package/dist/identity.d.mts.map +1 -0
  182. package/dist/identity.mjs +16 -0
  183. package/dist/identity.mjs.map +1 -0
  184. package/dist/index.cjs +11 -5
  185. package/dist/index.d.cts +9 -6
  186. package/dist/index.d.mts +9 -6
  187. package/dist/index.mjs +7 -4
  188. package/dist/plugin.cjs +13 -26
  189. package/dist/plugin.cjs.map +1 -1
  190. package/dist/plugin.d.cts +64 -25
  191. package/dist/plugin.d.cts.map +1 -1
  192. package/dist/plugin.d.mts +64 -25
  193. package/dist/plugin.d.mts.map +1 -1
  194. package/dist/plugin.mjs +16 -29
  195. package/dist/plugin.mjs.map +1 -1
  196. package/dist/remote-entry.cjs +102 -0
  197. package/dist/remote-entry.cjs.map +1 -0
  198. package/dist/remote-entry.d.cts +52 -0
  199. package/dist/remote-entry.d.cts.map +1 -0
  200. package/dist/remote-entry.d.mts +52 -0
  201. package/dist/remote-entry.d.mts.map +1 -0
  202. package/dist/remote-entry.mjs +98 -0
  203. package/dist/remote-entry.mjs.map +1 -0
  204. package/dist/runtime/errors.cjs +159 -33
  205. package/dist/runtime/errors.cjs.map +1 -1
  206. package/dist/runtime/errors.d.cts +64 -7
  207. package/dist/runtime/errors.d.cts.map +1 -1
  208. package/dist/runtime/errors.d.mts +64 -7
  209. package/dist/runtime/errors.d.mts.map +1 -1
  210. package/dist/runtime/errors.mjs +154 -30
  211. package/dist/runtime/errors.mjs.map +1 -1
  212. package/dist/runtime/index.cjs +95 -23
  213. package/dist/runtime/index.cjs.map +1 -1
  214. package/dist/runtime/index.d.cts +16 -0
  215. package/dist/runtime/index.d.cts.map +1 -1
  216. package/dist/runtime/index.d.mts +16 -0
  217. package/dist/runtime/index.d.mts.map +1 -1
  218. package/dist/runtime/index.mjs +98 -26
  219. package/dist/runtime/index.mjs.map +1 -1
  220. package/dist/runtime/mf-config.cjs +3 -78
  221. package/dist/runtime/mf-config.cjs.map +1 -1
  222. package/dist/runtime/mf-config.d.cts +3 -49
  223. package/dist/runtime/mf-config.d.cts.map +1 -1
  224. package/dist/runtime/mf-config.d.mts +3 -49
  225. package/dist/runtime/mf-config.d.mts.map +1 -1
  226. package/dist/runtime/mf-config.mjs +5 -78
  227. package/dist/runtime/mf-config.mjs.map +1 -1
  228. package/dist/runtime/services/module-federation.service.cjs +57 -12
  229. package/dist/runtime/services/module-federation.service.cjs.map +1 -1
  230. package/dist/runtime/services/module-federation.service.d.cts +4 -13
  231. package/dist/runtime/services/module-federation.service.d.mts +4 -13
  232. package/dist/runtime/services/module-federation.service.mjs +57 -14
  233. package/dist/runtime/services/module-federation.service.mjs.map +1 -1
  234. package/dist/runtime/services/normalize.cjs +2 -22
  235. package/dist/runtime/services/normalize.d.cts +2 -21
  236. package/dist/runtime/services/normalize.d.mts +2 -21
  237. package/dist/runtime/services/normalize.mjs +2 -21
  238. package/dist/runtime/services/plugin-lifecycle.service.cjs +9 -11
  239. package/dist/runtime/services/plugin-lifecycle.service.cjs.map +1 -1
  240. package/dist/runtime/services/plugin-lifecycle.service.d.cts +3 -16
  241. package/dist/runtime/services/plugin-lifecycle.service.d.mts +3 -16
  242. package/dist/runtime/services/plugin-lifecycle.service.mjs +10 -13
  243. package/dist/runtime/services/plugin-lifecycle.service.mjs.map +1 -1
  244. package/dist/runtime/services/plugin-loader.service.cjs +59 -30
  245. package/dist/runtime/services/plugin-loader.service.cjs.map +1 -1
  246. package/dist/runtime/services/plugin-loader.service.d.cts +6 -53
  247. package/dist/runtime/services/plugin-loader.service.d.mts +6 -53
  248. package/dist/runtime/services/plugin-loader.service.mjs +58 -31
  249. package/dist/runtime/services/plugin-loader.service.mjs.map +1 -1
  250. package/dist/runtime/services/plugin.service.cjs +10 -12
  251. package/dist/runtime/services/plugin.service.cjs.map +1 -1
  252. package/dist/runtime/services/plugin.service.d.cts +14 -36
  253. package/dist/runtime/services/plugin.service.d.cts.map +1 -1
  254. package/dist/runtime/services/plugin.service.d.mts +14 -36
  255. package/dist/runtime/services/plugin.service.d.mts.map +1 -1
  256. package/dist/runtime/services/plugin.service.mjs +14 -18
  257. package/dist/runtime/services/plugin.service.mjs.map +1 -1
  258. package/dist/runtime/services/secrets.service.cjs +12 -12
  259. package/dist/runtime/services/secrets.service.cjs.map +1 -1
  260. package/dist/runtime/services/secrets.service.d.cts +3 -15
  261. package/dist/runtime/services/secrets.service.d.mts +3 -15
  262. package/dist/runtime/services/secrets.service.mjs +12 -13
  263. package/dist/runtime/services/secrets.service.mjs.map +1 -1
  264. package/dist/runtime/services/shared-identity.cjs +40 -0
  265. package/dist/runtime/services/shared-identity.cjs.map +1 -0
  266. package/dist/runtime/services/shared-identity.mjs +38 -0
  267. package/dist/runtime/services/shared-identity.mjs.map +1 -0
  268. package/dist/runtime/validation.cjs +2 -2
  269. package/dist/runtime/validation.cjs.map +1 -1
  270. package/dist/runtime/validation.mjs +2 -2
  271. package/dist/runtime/validation.mjs.map +1 -1
  272. package/dist/shared-deps-spec.cjs +384 -0
  273. package/dist/shared-deps-spec.cjs.map +1 -0
  274. package/dist/shared-deps-spec.d.cts +182 -0
  275. package/dist/shared-deps-spec.d.cts.map +1 -0
  276. package/dist/shared-deps-spec.d.mts +182 -0
  277. package/dist/shared-deps-spec.d.mts.map +1 -0
  278. package/dist/shared-deps-spec.mjs +368 -0
  279. package/dist/shared-deps-spec.mjs.map +1 -0
  280. package/dist/types.d.cts +47 -41
  281. package/dist/types.d.cts.map +1 -1
  282. package/dist/types.d.mts +47 -41
  283. package/dist/types.d.mts.map +1 -1
  284. package/dist/ui/manifest/construct.cjs +319 -0
  285. package/dist/ui/manifest/construct.cjs.map +1 -0
  286. package/dist/ui/manifest/construct.d.cts +48 -0
  287. package/dist/ui/manifest/construct.d.cts.map +1 -0
  288. package/dist/ui/manifest/construct.d.mts +48 -0
  289. package/dist/ui/manifest/construct.d.mts.map +1 -0
  290. package/dist/ui/manifest/construct.mjs +319 -0
  291. package/dist/ui/manifest/construct.mjs.map +1 -0
  292. package/dist/ui/manifest/contract.cjs +34 -0
  293. package/dist/ui/manifest/contract.cjs.map +1 -0
  294. package/dist/ui/manifest/contract.d.cts +26 -0
  295. package/dist/ui/manifest/contract.d.cts.map +1 -0
  296. package/dist/ui/manifest/contract.d.mts +26 -0
  297. package/dist/ui/manifest/contract.d.mts.map +1 -0
  298. package/dist/ui/manifest/contract.mjs +26 -0
  299. package/dist/ui/manifest/contract.mjs.map +1 -0
  300. package/dist/ui/manifest/descriptor.cjs +64 -0
  301. package/dist/ui/manifest/descriptor.cjs.map +1 -0
  302. package/dist/ui/manifest/descriptor.d.cts +60 -0
  303. package/dist/ui/manifest/descriptor.d.cts.map +1 -0
  304. package/dist/ui/manifest/descriptor.d.mts +60 -0
  305. package/dist/ui/manifest/descriptor.d.mts.map +1 -0
  306. package/dist/ui/manifest/descriptor.mjs +61 -0
  307. package/dist/ui/manifest/descriptor.mjs.map +1 -0
  308. package/dist/ui/manifest/generator.cjs +128 -0
  309. package/dist/ui/manifest/generator.cjs.map +1 -0
  310. package/dist/ui/manifest/generator.d.cts +41 -0
  311. package/dist/ui/manifest/generator.d.cts.map +1 -0
  312. package/dist/ui/manifest/generator.d.mts +41 -0
  313. package/dist/ui/manifest/generator.d.mts.map +1 -0
  314. package/dist/ui/manifest/generator.mjs +125 -0
  315. package/dist/ui/manifest/generator.mjs.map +1 -0
  316. package/dist/ui/manifest/index.cjs +35 -0
  317. package/dist/ui/manifest/index.d.cts +9 -0
  318. package/dist/ui/manifest/index.d.mts +9 -0
  319. package/dist/ui/manifest/index.mjs +9 -0
  320. package/dist/ui/manifest/manifest-schema.cjs +97 -0
  321. package/dist/ui/manifest/manifest-schema.cjs.map +1 -0
  322. package/dist/ui/manifest/manifest-schema.d.cts +132 -0
  323. package/dist/ui/manifest/manifest-schema.d.cts.map +1 -0
  324. package/dist/ui/manifest/manifest-schema.d.mts +132 -0
  325. package/dist/ui/manifest/manifest-schema.d.mts.map +1 -0
  326. package/dist/ui/manifest/manifest-schema.mjs +90 -0
  327. package/dist/ui/manifest/manifest-schema.mjs.map +1 -0
  328. package/dist/ui/manifest/mount-registry.cjs +52 -0
  329. package/dist/ui/manifest/mount-registry.cjs.map +1 -0
  330. package/dist/ui/manifest/mount-registry.d.cts +61 -0
  331. package/dist/ui/manifest/mount-registry.d.cts.map +1 -0
  332. package/dist/ui/manifest/mount-registry.d.mts +61 -0
  333. package/dist/ui/manifest/mount-registry.d.mts.map +1 -0
  334. package/dist/ui/manifest/mount-registry.mjs +48 -0
  335. package/dist/ui/manifest/mount-registry.mjs.map +1 -0
  336. package/dist/ui/manifest/nav.cjs +13 -0
  337. package/dist/ui/manifest/nav.cjs.map +1 -0
  338. package/dist/ui/manifest/nav.d.cts +34 -0
  339. package/dist/ui/manifest/nav.d.cts.map +1 -0
  340. package/dist/ui/manifest/nav.d.mts +34 -0
  341. package/dist/ui/manifest/nav.d.mts.map +1 -0
  342. package/dist/ui/manifest/nav.mjs +13 -0
  343. package/dist/ui/manifest/nav.mjs.map +1 -0
  344. package/dist/ui/manifest/route-config.cjs +33 -0
  345. package/dist/ui/manifest/route-config.cjs.map +1 -0
  346. package/dist/ui/manifest/route-config.d.cts +40 -0
  347. package/dist/ui/manifest/route-config.d.cts.map +1 -0
  348. package/dist/ui/manifest/route-config.d.mts +40 -0
  349. package/dist/ui/manifest/route-config.d.mts.map +1 -0
  350. package/dist/ui/manifest/route-config.mjs +33 -0
  351. package/dist/ui/manifest/route-config.mjs.map +1 -0
  352. package/dist/version-manifest.cjs +77 -0
  353. package/dist/version-manifest.cjs.map +1 -0
  354. package/dist/version-manifest.d.cts +62 -0
  355. package/dist/version-manifest.d.cts.map +1 -0
  356. package/dist/version-manifest.d.mts +62 -0
  357. package/dist/version-manifest.d.mts.map +1 -0
  358. package/dist/version-manifest.mjs +75 -0
  359. package/dist/version-manifest.mjs.map +1 -0
  360. package/package.json +182 -68
  361. package/skills/plugin-client/SKILL.md +34 -9
  362. package/skills/plugin-development/SKILL.md +79 -47
  363. package/skills/plugin-testing/SKILL.md +42 -12
  364. package/src/build/artifact-names.ts +117 -0
  365. package/src/build/contract-types.ts +101 -0
  366. package/src/build/rspack/build-report-plugin.ts +34 -0
  367. package/src/build/rspack/chunk-completeness-plugin.ts +66 -0
  368. package/src/build/rspack/compose.ts +87 -0
  369. package/src/build/rspack/fix-mf-data-uri-plugin.ts +23 -12
  370. package/src/build/rspack/generated-config.ts +35 -0
  371. package/src/build/rspack/index.ts +10 -5
  372. package/src/build/rspack/module-federation.ts +1 -1
  373. package/src/build/rspack/plugin.ts +103 -105
  374. package/src/build/rspack/utils.ts +8 -2
  375. package/src/build/ui/factory.ts +96 -0
  376. package/src/build/ui/generated-config.ts +137 -0
  377. package/src/build/ui/hash-artifacts-plugin.ts +79 -0
  378. package/src/build/ui/index.ts +98 -0
  379. package/src/build/ui/manifest-plugin.ts +54 -0
  380. package/src/build/ui/rsbuild-config.ts +256 -0
  381. package/src/build/ui/stubs.ts +103 -0
  382. package/src/cli.ts +100 -0
  383. package/src/client.ts +111 -0
  384. package/src/dev/host.ts +235 -0
  385. package/src/dev/serve.ts +359 -0
  386. package/src/dev/watch-kill.ts +58 -0
  387. package/src/effect-helpers.ts +25 -0
  388. package/src/errors.ts +17 -18
  389. package/src/identity.ts +36 -0
  390. package/src/index.ts +13 -0
  391. package/src/plugin.ts +94 -91
  392. package/src/remote-entry.ts +170 -0
  393. package/src/runtime/errors.ts +229 -26
  394. package/src/runtime/index.ts +132 -43
  395. package/src/runtime/mf-config.ts +12 -107
  396. package/src/runtime/services/module-federation.service.ts +218 -117
  397. package/src/runtime/services/normalize.ts +1 -18
  398. package/src/runtime/services/plugin-lifecycle.service.ts +66 -75
  399. package/src/runtime/services/plugin-loader.service.ts +280 -209
  400. package/src/runtime/services/plugin.service.ts +61 -43
  401. package/src/runtime/services/secrets.service.ts +20 -15
  402. package/src/runtime/services/shared-identity.ts +68 -0
  403. package/src/runtime/validation.ts +5 -7
  404. package/src/shared-deps-spec.ts +478 -0
  405. package/src/types.ts +62 -50
  406. package/src/ui/manifest/construct.ts +456 -0
  407. package/src/ui/manifest/contract.ts +33 -0
  408. package/src/ui/manifest/descriptor.ts +96 -0
  409. package/src/ui/manifest/generator.ts +238 -0
  410. package/src/ui/manifest/index.ts +55 -0
  411. package/src/ui/manifest/manifest-schema.ts +107 -0
  412. package/src/ui/manifest/mount-registry.ts +50 -0
  413. package/src/ui/manifest/nav.ts +43 -0
  414. package/src/ui/manifest/route-config.ts +82 -0
  415. package/src/version-manifest.ts +106 -0
  416. package/dist/build/rspack/dev-server-middleware.cjs +0 -248
  417. package/dist/build/rspack/dev-server-middleware.cjs.map +0 -1
  418. package/dist/build/rspack/dev-server-middleware.mjs +0 -247
  419. package/dist/build/rspack/dev-server-middleware.mjs.map +0 -1
  420. package/dist/build/shared-deps.cjs +0 -83
  421. package/dist/build/shared-deps.cjs.map +0 -1
  422. package/dist/build/shared-deps.d.cts +0 -67
  423. package/dist/build/shared-deps.d.cts.map +0 -1
  424. package/dist/build/shared-deps.d.mts +0 -67
  425. package/dist/build/shared-deps.d.mts.map +0 -1
  426. package/dist/build/shared-deps.mjs +0 -79
  427. package/dist/build/shared-deps.mjs.map +0 -1
  428. package/dist/effect.cjs +0 -9
  429. package/dist/effect.d.cts +0 -1
  430. package/dist/effect.d.mts +0 -1
  431. package/dist/effect.mjs +0 -3
  432. package/dist/orpc-openapi.cjs +0 -17
  433. package/dist/orpc-openapi.d.cts +0 -2
  434. package/dist/orpc-openapi.d.mts +0 -2
  435. package/dist/orpc-openapi.mjs +0 -5
  436. package/dist/orpc.cjs +0 -46
  437. package/dist/orpc.d.cts +0 -7
  438. package/dist/orpc.d.mts +0 -7
  439. package/dist/orpc.mjs +0 -11
  440. package/dist/package.cjs +0 -23
  441. package/dist/package.cjs.map +0 -1
  442. package/dist/package.mjs +0 -17
  443. package/dist/package.mjs.map +0 -1
  444. package/dist/runtime/services/module-federation.service.d.cts.map +0 -1
  445. package/dist/runtime/services/module-federation.service.d.mts.map +0 -1
  446. package/dist/runtime/services/normalize.cjs.map +0 -1
  447. package/dist/runtime/services/normalize.d.cts.map +0 -1
  448. package/dist/runtime/services/normalize.d.mts.map +0 -1
  449. package/dist/runtime/services/normalize.mjs.map +0 -1
  450. package/dist/runtime/services/plugin-lifecycle.service.d.cts.map +0 -1
  451. package/dist/runtime/services/plugin-lifecycle.service.d.mts.map +0 -1
  452. package/dist/runtime/services/plugin-loader.service.d.cts.map +0 -1
  453. package/dist/runtime/services/plugin-loader.service.d.mts.map +0 -1
  454. package/dist/runtime/services/secrets.service.d.cts.map +0 -1
  455. package/dist/runtime/services/secrets.service.d.mts.map +0 -1
  456. package/dist/testing/index.cjs +0 -57
  457. package/dist/testing/index.cjs.map +0 -1
  458. package/dist/testing/index.d.cts +0 -54
  459. package/dist/testing/index.d.cts.map +0 -1
  460. package/dist/testing/index.d.mts +0 -54
  461. package/dist/testing/index.d.mts.map +0 -1
  462. package/dist/testing/index.mjs +0 -55
  463. package/dist/testing/index.mjs.map +0 -1
  464. package/dist/zod-core.cjs +0 -9
  465. package/dist/zod-core.d.cts +0 -1
  466. package/dist/zod-core.d.mts +0 -1
  467. package/dist/zod-core.mjs +0 -3
  468. package/dist/zod.cjs +0 -11
  469. package/dist/zod.d.cts +0 -2
  470. package/dist/zod.d.mts +0 -2
  471. package/dist/zod.mjs +0 -3
  472. package/src/build/rspack/dev-server-middleware.ts +0 -324
  473. package/src/build/shared-deps.ts +0 -102
  474. package/src/effect.ts +0 -1
  475. package/src/orpc-openapi.ts +0 -2
  476. package/src/orpc.ts +0 -9
  477. package/src/testing/index.ts +0 -87
  478. package/src/testing/mocks/module-federation.service.ts +0 -41
  479. package/src/zod-core.ts +0 -1
  480. package/src/zod.ts +0 -3
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The core ui's generated bootstrap stubs — the mechanical files an app must
3
+ * never author or edit (ADR 0023): the web MF entry, the `./Hydrate`
4
+ * bootstrap, the SSR router module, the `./compose` expose, and the ambient
5
+ * globals. Emitted into the ui source root by the framework's code-artifact
6
+ * generation pass, regenerated from the installed package version, and
7
+ * gitignored (`*.gen.*`) — never synced, never hand-maintained.
8
+ *
9
+ * The generated hydrate/SSR stubs wire the app's AUTHORED seams into the
10
+ * framework machinery: the router policy factory (`src/router.tsx`) and the
11
+ * app override exports from `src/app.ts` (`apiConnectionError`, `appLocale`).
12
+ * The seam files are scaffolded once by `bos init` and owned by the app; the
13
+ * stubs themselves carry zero app-specific content.
14
+ */
15
+
16
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
17
+ import { dirname, join } from "node:path";
18
+
19
+ export const CORE_UI_STUBS: Record<string, string> = {
20
+ "src/entry.gen.ts": `// GENERATED FILE — do not edit. Regenerated from the installed framework version
21
+ // by \`bos dev\` / \`bos build\` / \`bos typecheck\` (gitignored).
22
+ import "./styles.css";
23
+ import { runEntry } from "everything-dev/ui/entry";
24
+
25
+ runEntry(() => import("./hydrate.gen"));
26
+ `,
27
+ "src/hydrate.gen.tsx": `// GENERATED FILE — do not edit. Regenerated from the installed framework version
28
+ // by \`bos dev\` / \`bos build\` / \`bos typecheck\` (gitignored).
29
+ import "./styles.css";
30
+ import { hydrate as coreHydrate } from "everything-dev/ui/hydrate";
31
+ import { apiConnectionError } from "./app";
32
+ import { createQueryClient, createRouter } from "./router";
33
+
34
+ export function hydrate() {
35
+ return coreHydrate({
36
+ routeConfig: () => import("./routeConfig.gen"),
37
+ manifest: () => import("./manifest.gen.json"),
38
+ createRouter,
39
+ createQueryClient,
40
+ apiConnectionError,
41
+ });
42
+ }
43
+
44
+ export default hydrate;
45
+ `,
46
+ "src/router.server.gen.tsx": `// GENERATED FILE — do not edit. Regenerated from the installed framework version
47
+ // by \`bos dev\` / \`bos build\` / \`bos typecheck\` (gitignored).
48
+ import { createServerRouterModule } from "everything-dev/ui/router-server";
49
+ import { appLocale } from "./app";
50
+ import { createQueryClient, createRouter } from "./router";
51
+ import { routeTree } from "./routeTree.gen";
52
+
53
+ const routerModule = createServerRouterModule({
54
+ defaultRouteTree: routeTree,
55
+ createRouter,
56
+ createQueryClient,
57
+ locale: appLocale,
58
+ });
59
+
60
+ export default routerModule;
61
+ `,
62
+ "src/compose.gen.ts": `// GENERATED FILE — do not edit. Regenerated from the installed framework version
63
+ // by \`bos dev\` / \`bos build\` / \`bos typecheck\` (gitignored).
64
+ export type {
65
+ ConstructedTree,
66
+ ConstructInput,
67
+ ConstructPluginRef,
68
+ GateUser,
69
+ HostContext,
70
+ NavManifest,
71
+ PluginManifest,
72
+ ResolvedPlugin,
73
+ RouteConfigModule,
74
+ RouteOptionsBundle,
75
+ } from "everything-dev/ui/manifest";
76
+ export {
77
+ CORE_UI_PLUGIN_KEY,
78
+ ComposePayloadSchema,
79
+ constructTree,
80
+ } from "everything-dev/ui/manifest";
81
+ `,
82
+ "src/globals.gen.ts": `// GENERATED FILE — do not edit. Regenerated from the installed framework version
83
+ // by \`bos dev\` / \`bos build\` / \`bos typecheck\` (gitignored).
84
+ /// <reference types="@rsbuild/core/types" />
85
+ `,
86
+ };
87
+
88
+ /**
89
+ * Emits the stub set into the ui source root. Returns the stub paths whose
90
+ * content actually changed (empty when everything is already current) — the
91
+ * same-content suppression keeps dev watchers from regen loops.
92
+ */
93
+ export function emitCoreUiStubs(uiRoot: string): string[] {
94
+ const written: string[] = [];
95
+ for (const [relPath, content] of Object.entries(CORE_UI_STUBS)) {
96
+ const fullPath = join(uiRoot, relPath);
97
+ if (existsSync(fullPath) && readFileSync(fullPath, "utf-8") === content) continue;
98
+ mkdirSync(dirname(fullPath), { recursive: true });
99
+ writeFileSync(fullPath, content);
100
+ written.push(relPath);
101
+ }
102
+ return written;
103
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,100 @@
1
+ import { spawn } from "node:child_process";
2
+ import { generateContractTypes } from "./build/contract-types";
3
+ import { ensureGeneratedRspackConfig } from "./build/rspack/generated-config";
4
+ import {
5
+ ensureGeneratedCoreUiRsbuildConfig,
6
+ ensureGeneratedUiRsbuildConfig,
7
+ hasCoreUiWorkspace,
8
+ } from "./build/ui/generated-config";
9
+
10
+ function run(
11
+ cmd: string,
12
+ args: string[],
13
+ env: Record<string, string | undefined> = {},
14
+ ): Promise<void> {
15
+ return new Promise((resolve, reject) => {
16
+ const child = spawn(cmd, args, {
17
+ stdio: "inherit",
18
+ env: { ...process.env, ...env },
19
+ shell: process.platform === "win32",
20
+ });
21
+ child.on("exit", (code) =>
22
+ code === 0
23
+ ? resolve()
24
+ : reject(new Error(`${cmd} ${args.join(" ")} exited with code ${code}`)),
25
+ );
26
+ child.on("error", reject);
27
+ });
28
+ }
29
+
30
+ export async function emitContractTypes(): Promise<void> {
31
+ const status = await generateContractTypes();
32
+ if (status === "skipped") {
33
+ console.log("[every-plugin] No src/contract.ts — nothing to emit.");
34
+ } else {
35
+ console.log(`[every-plugin] Contract types ${status}.`);
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Workspace-form core ui build surface — the /api model applied to the ui:
41
+ * the generated config (or a local rsbuild.config.ts override) drives
42
+ * rsbuild; extra args pass through (`--environment web|node`).
43
+ */
44
+ async function runCoreUi(args: string[]): Promise<void> {
45
+ const generatedConfig = ensureGeneratedCoreUiRsbuildConfig();
46
+ const [command = "build", ...rest] = args;
47
+ const configArgs = generatedConfig ? ["--config", generatedConfig] : [];
48
+ await run("rsbuild", [command, ...configArgs, ...rest], {});
49
+ }
50
+
51
+ async function runRspack(): Promise<void> {
52
+ const generatedConfig = ensureGeneratedRspackConfig();
53
+
54
+ const args = generatedConfig ? ["build", "--config", generatedConfig] : ["build"];
55
+ await run("rspack", args, {});
56
+
57
+ const uiConfig = ensureGeneratedUiRsbuildConfig(process.cwd());
58
+ if (uiConfig) {
59
+ console.log("[every-plugin] Building folder-form ui source…");
60
+ await run("rsbuild", ["build", "--config", uiConfig], {});
61
+ }
62
+ }
63
+
64
+ export function runCliCommand(raw: string, args: string[] = []): Promise<void> {
65
+ const command = raw.replace(/=.*/, "");
66
+ if (command === "dev") process.env.BOS_DEV_SERVER = "1";
67
+ // The core ui workspace form routes build/dev/preview through rsbuild;
68
+ // plugin workspaces keep the rspack/dev-server surface.
69
+ if (hasCoreUiWorkspace()) {
70
+ switch (command) {
71
+ case "build":
72
+ return runCoreUi(["build", ...args]);
73
+ case "preview":
74
+ return runCoreUi(["preview", ...args]);
75
+ case "dev":
76
+ return runCoreUi(["dev", ...args]);
77
+ default:
78
+ return Promise.reject(
79
+ new Error(`Unknown every-plugin command for a core ui workspace: ${raw}`),
80
+ );
81
+ }
82
+ }
83
+ switch (command) {
84
+ case "types":
85
+ return emitContractTypes();
86
+ case "build":
87
+ case "deploy":
88
+ return runRspack();
89
+ case "dev":
90
+ return (async () => {
91
+ const { startPluginDevServer } = await import("./dev/serve");
92
+ await startPluginDevServer();
93
+ return new Promise<void>(() => {});
94
+ })();
95
+ default:
96
+ return Promise.reject(
97
+ new Error(`Unknown every-plugin command: ${raw} (expected dev|types|build|deploy)`),
98
+ );
99
+ }
100
+ }
package/src/client.ts ADDED
@@ -0,0 +1,111 @@
1
+ import { createORPCClient, onError } from "@orpc/client";
2
+ import { RPCLink } from "@orpc/client/fetch";
3
+ import type { ContractRouterClient, RouterContract } from "@orpc/contract";
4
+
5
+ export type RpcConnectionErrorCopy = () => { title: string; description: string };
6
+
7
+ export interface RpcClientConfig {
8
+ hostUrl: string;
9
+ path: `/${string}`;
10
+ connectionError?: RpcConnectionErrorCopy;
11
+ }
12
+
13
+ const RATE_LIMIT_MAX_RETRIES = 3;
14
+ const RATE_LIMIT_RETRY_CAP_MS = 2_000;
15
+ const browserClients = new Map<string, unknown>();
16
+ type FetchInput = Parameters<typeof fetch>[0];
17
+
18
+ async function fetchWithRateLimitRetry(
19
+ fetchUrl: FetchInput,
20
+ options?: RequestInit,
21
+ ): Promise<Response> {
22
+ let response = await fetch(fetchUrl, options);
23
+ for (let attempt = 1; attempt <= RATE_LIMIT_MAX_RETRIES && response.status === 429; attempt++) {
24
+ const retryAfterSeconds = Number(response.headers.get("retry-after"));
25
+ const delay =
26
+ Number.isFinite(retryAfterSeconds) && retryAfterSeconds > 0
27
+ ? Math.min(retryAfterSeconds * 1000, RATE_LIMIT_RETRY_CAP_MS)
28
+ : 100 * attempt;
29
+ await new Promise((resolve) => setTimeout(resolve, delay));
30
+ response = await fetch(fetchUrl, options);
31
+ }
32
+
33
+ return response;
34
+ }
35
+
36
+ function createRpcLink(config: RpcClientConfig, headers?: Headers) {
37
+ return new RPCLink({
38
+ origin: config.hostUrl,
39
+ url: config.path,
40
+ interceptors: [
41
+ onError((error: unknown) => {
42
+ const browserWindow = (globalThis as { window?: unknown }).window;
43
+ if (typeof browserWindow === "undefined") {
44
+ return;
45
+ }
46
+
47
+ if (error && typeof error === "object" && "message" in error) {
48
+ const message = String(error.message).toLowerCase();
49
+ if (
50
+ message.includes("fetch") ||
51
+ message.includes("network") ||
52
+ message.includes("failed to fetch")
53
+ ) {
54
+ void import("sonner")
55
+ .then(({ toast }) => {
56
+ const message = config.connectionError?.() ?? {
57
+ title: "Unable to connect to API",
58
+ description: "The API is currently unavailable. Please try again later.",
59
+ };
60
+ toast.error(message.title, {
61
+ id: "api-connection-error",
62
+ description: message.description,
63
+ });
64
+ })
65
+ .catch(() => {});
66
+ }
67
+ }
68
+ }),
69
+ ],
70
+ fetch(fetchUrl: FetchInput, options?: RequestInit) {
71
+ return fetchWithRateLimitRetry(fetchUrl, {
72
+ ...options,
73
+ credentials: "include",
74
+ headers: headers
75
+ ? { ...Object.fromEntries(headers), ...(options?.headers as Record<string, string>) }
76
+ : options?.headers,
77
+ });
78
+ },
79
+ });
80
+ }
81
+
82
+ function buildRpcClient<T extends RouterContract>(
83
+ config: RpcClientConfig,
84
+ headers?: Headers,
85
+ ): ContractRouterClient<T> {
86
+ if (!config.hostUrl) {
87
+ throw new Error("Missing runtime host URL");
88
+ }
89
+
90
+ return createORPCClient(createRpcLink(config, headers)) as ContractRouterClient<T>;
91
+ }
92
+
93
+ export function createRpcClient<T extends RouterContract = RouterContract>(
94
+ config: RpcClientConfig,
95
+ headers?: Headers,
96
+ ): ContractRouterClient<T> {
97
+ const browserWindow = (globalThis as { window?: unknown }).window;
98
+ if (typeof browserWindow !== "undefined" && !headers) {
99
+ const key = `${config.hostUrl}${config.path}`;
100
+ const memoized = browserClients.get(key);
101
+ if (memoized) {
102
+ return memoized as ContractRouterClient<T>;
103
+ }
104
+
105
+ const client = buildRpcClient<T>(config, headers);
106
+ browserClients.set(key, client);
107
+ return client;
108
+ }
109
+
110
+ return buildRpcClient<T>(config, headers);
111
+ }
@@ -0,0 +1,235 @@
1
+ import type http from "node:http";
2
+ import { createServer } from "node:http";
3
+
4
+ const corsHeaders = {
5
+ "Access-Control-Allow-Origin": "*",
6
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
7
+ "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization",
8
+ };
9
+
10
+ const applyCorsHeaders = (res: http.ServerResponse) => {
11
+ Object.entries(corsHeaders).forEach(([key, value]) => {
12
+ res.setHeader(key, value);
13
+ });
14
+ };
15
+
16
+ const sendJson = (res: http.ServerResponse, status: number, body: unknown) => {
17
+ res.statusCode = status;
18
+ res.setHeader("content-type", "application/json; charset=utf-8");
19
+ res.end(JSON.stringify(body));
20
+ };
21
+
22
+ const sendText = (res: http.ServerResponse, status: number, text: string) => {
23
+ res.statusCode = status;
24
+ res.setHeader("content-type", "text/plain; charset=utf-8");
25
+ res.end(text);
26
+ };
27
+
28
+ const pathnameOf = (req: http.IncomingMessage): string =>
29
+ ((req.url ?? "/").split("?")[0] ?? "/").replace(/\/+$/, "") || "/";
30
+
31
+ const toWebRequest = (req: http.IncomingMessage, port: number): Request => {
32
+ const url = `http://localhost:${port}${req.url}`;
33
+ return new Request(url, {
34
+ method: req.method,
35
+ headers: req.headers,
36
+ body: req.method !== "GET" && req.method !== "HEAD" ? req : undefined,
37
+ duplex: req.method !== "GET" && req.method !== "HEAD" ? "half" : undefined,
38
+ } as RequestInit);
39
+ };
40
+
41
+ const buildHostContext = (
42
+ effectContext: unknown,
43
+ webRequest: Request,
44
+ cachedRawBodyRef: { value: string | null },
45
+ ) => {
46
+ const rawClone =
47
+ webRequest.method === "GET" || webRequest.method === "HEAD" ? null : webRequest.clone();
48
+
49
+ return {
50
+ reqHeaders: webRequest.headers,
51
+ "effect/context": effectContext,
52
+ getRawBody: async (): Promise<string> => {
53
+ if (cachedRawBodyRef.value !== null) return cachedRawBodyRef.value;
54
+ if (!rawClone) {
55
+ cachedRawBodyRef.value = "";
56
+ return cachedRawBodyRef.value;
57
+ }
58
+ cachedRawBodyRef.value = await rawClone.text();
59
+ return cachedRawBodyRef.value;
60
+ },
61
+ };
62
+ };
63
+
64
+ export interface DirectModuleHostHandler {
65
+ handle(
66
+ request: Request,
67
+ options: { prefix: string; context: unknown },
68
+ ): Promise<{ response?: Response }>;
69
+ }
70
+
71
+ const handleOrpc = async (
72
+ req: http.IncomingMessage,
73
+ res: http.ServerResponse,
74
+ handler: DirectModuleHostHandler,
75
+ prefix: string,
76
+ errorLabel: string,
77
+ effectContext: unknown,
78
+ port: number,
79
+ ) => {
80
+ try {
81
+ const webRequest = toWebRequest(req, port);
82
+ const cachedRawBodyRef = { value: null as string | null };
83
+ const result = await handler.handle(webRequest, {
84
+ prefix,
85
+ context: buildHostContext(effectContext, webRequest, cachedRawBodyRef),
86
+ });
87
+
88
+ if (result.response) {
89
+ res.statusCode = result.response.status;
90
+ result.response.headers.forEach((value: string, key: string) => {
91
+ res.setHeader(key, value);
92
+ });
93
+ const text = await result.response.text();
94
+ if (!res.getHeader("content-length")) {
95
+ res.setHeader("content-length", Buffer.byteLength(text).toString());
96
+ }
97
+ res.end(text);
98
+ } else {
99
+ sendText(res, 404, "Not Found");
100
+ }
101
+ } catch (error) {
102
+ console.error(`${errorLabel} error:`, error);
103
+ sendJson(res, 500, { error: (error as Error).message });
104
+ }
105
+ };
106
+
107
+ export interface DirectModuleHostHandlers {
108
+ rpc: DirectModuleHostHandler | null;
109
+ api: DirectModuleHostHandler | null;
110
+ }
111
+
112
+ export interface DirectModuleHostOptions {
113
+ name: string;
114
+ handlers: DirectModuleHostHandlers;
115
+ effectContext: unknown;
116
+ port?: number;
117
+ version?: string;
118
+ rpcPrefix?: `/${string}`;
119
+ apiPrefix?: `/${string}`;
120
+ staticHandler?:
121
+ | ((req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void)
122
+ | null;
123
+ }
124
+
125
+ export interface DirectModuleHostHandle {
126
+ port: number;
127
+ close: () => Promise<void>;
128
+ }
129
+
130
+ export async function startDirectModuleHost(
131
+ options: DirectModuleHostOptions,
132
+ ): Promise<DirectModuleHostHandle> {
133
+ const port = options.port ?? 0;
134
+ let resolvedPort = port;
135
+ const rpcPrefix = options.rpcPrefix ?? "/api/rpc";
136
+ const apiPrefix = options.apiPrefix ?? "/api";
137
+ const staticHandler = options.staticHandler ?? null;
138
+ const resolveEffectContext: () => unknown =
139
+ typeof options.effectContext === "function"
140
+ ? (options.effectContext as () => unknown)
141
+ : () => options.effectContext;
142
+
143
+ const server = createServer((req, res) => {
144
+ applyCorsHeaders(res);
145
+ const pathname = pathnameOf(req);
146
+
147
+ if (req.method === "OPTIONS") {
148
+ res.statusCode = 200;
149
+ res.end();
150
+ return;
151
+ }
152
+
153
+ if (pathname === "/" && (req.method === "GET" || req.method === "HEAD")) {
154
+ sendJson(res, 200, {
155
+ ok: true,
156
+ module: options.name,
157
+ version: options.version,
158
+ status: options.handlers.rpc ? "ready" : "loading",
159
+ endpoints: {
160
+ health: "/health",
161
+ docs: apiPrefix,
162
+ rpc: rpcPrefix,
163
+ },
164
+ });
165
+ return;
166
+ }
167
+
168
+ if (pathname === "/health" && (req.method === "GET" || req.method === "HEAD")) {
169
+ sendText(res, 200, "OK");
170
+ return;
171
+ }
172
+
173
+ if (pathname.startsWith(`${rpcPrefix}/`)) {
174
+ if (!options.handlers.rpc) {
175
+ sendJson(res, 503, { error: "Plugin still loading..." });
176
+ return;
177
+ }
178
+ handleOrpc(
179
+ req,
180
+ res,
181
+ options.handlers.rpc,
182
+ rpcPrefix,
183
+ "RPC",
184
+ resolveEffectContext(),
185
+ resolvedPort,
186
+ ).catch(() => {});
187
+ return;
188
+ }
189
+
190
+ if (pathname === apiPrefix || pathname.startsWith(`${apiPrefix}/`)) {
191
+ if (!options.handlers.api) {
192
+ sendJson(res, 503, { error: "Plugin still loading..." });
193
+ return;
194
+ }
195
+ handleOrpc(
196
+ req,
197
+ res,
198
+ options.handlers.api,
199
+ apiPrefix,
200
+ "OpenAPI",
201
+ resolveEffectContext(),
202
+ resolvedPort,
203
+ ).catch(() => {});
204
+ return;
205
+ }
206
+
207
+ if (staticHandler) {
208
+ staticHandler(req, res, () => {
209
+ sendText(res, 404, "Not Found");
210
+ });
211
+ return;
212
+ }
213
+
214
+ sendText(res, 404, "Not Found");
215
+ });
216
+
217
+ await new Promise<void>((resolve, reject) => {
218
+ server.once("error", reject);
219
+ server.listen(port, () => resolve());
220
+ });
221
+
222
+ const address = server.address();
223
+ if (!address || typeof address === "string") {
224
+ await new Promise<void>((resolve) => server.close(() => resolve()));
225
+ throw new Error("Failed to resolve host port");
226
+ }
227
+ resolvedPort = address.port;
228
+
229
+ return {
230
+ port: resolvedPort,
231
+ close: async () => {
232
+ await new Promise<void>((resolve) => server.close(() => resolve()));
233
+ },
234
+ };
235
+ }