everything-dev 0.3.3 → 1.3.3

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 (313) hide show
  1. package/README.md +64 -0
  2. package/cli.js +10 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/api-contract.cjs +172 -0
  5. package/dist/api-contract.cjs.map +1 -0
  6. package/dist/api-contract.mjs +171 -0
  7. package/dist/api-contract.mjs.map +1 -0
  8. package/dist/api.cjs +124 -0
  9. package/dist/api.cjs.map +1 -0
  10. package/dist/api.d.cts +36 -0
  11. package/dist/api.d.cts.map +1 -0
  12. package/dist/api.d.mts +36 -0
  13. package/dist/api.d.mts.map +1 -0
  14. package/dist/api.mjs +119 -0
  15. package/dist/api.mjs.map +1 -0
  16. package/dist/app.cjs +156 -0
  17. package/dist/app.cjs.map +1 -0
  18. package/dist/app.mjs +153 -0
  19. package/dist/app.mjs.map +1 -0
  20. package/dist/cli/catalog.cjs +30 -0
  21. package/dist/cli/catalog.cjs.map +1 -0
  22. package/dist/cli/catalog.mjs +29 -0
  23. package/dist/cli/catalog.mjs.map +1 -0
  24. package/dist/cli/help.cjs +16 -0
  25. package/dist/cli/help.cjs.map +1 -0
  26. package/dist/cli/help.mjs +16 -0
  27. package/dist/cli/help.mjs.map +1 -0
  28. package/dist/cli/init.cjs +287 -0
  29. package/dist/cli/init.cjs.map +1 -0
  30. package/dist/cli/init.d.cts +36 -0
  31. package/dist/cli/init.d.cts.map +1 -0
  32. package/dist/cli/init.d.mts +36 -0
  33. package/dist/cli/init.d.mts.map +1 -0
  34. package/dist/cli/init.mjs +279 -0
  35. package/dist/cli/init.mjs.map +1 -0
  36. package/dist/cli/parse.cjs +96 -0
  37. package/dist/cli/parse.cjs.map +1 -0
  38. package/dist/cli/parse.mjs +95 -0
  39. package/dist/cli/parse.mjs.map +1 -0
  40. package/dist/cli/prompts.cjs +42 -0
  41. package/dist/cli/prompts.cjs.map +1 -0
  42. package/dist/cli/prompts.mjs +41 -0
  43. package/dist/cli/prompts.mjs.map +1 -0
  44. package/dist/cli.cjs +167 -0
  45. package/dist/cli.cjs.map +1 -0
  46. package/dist/cli.d.cts +1 -0
  47. package/dist/cli.d.mts +1 -0
  48. package/dist/cli.mjs +166 -0
  49. package/dist/cli.mjs.map +1 -0
  50. package/dist/components/dev-view.cjs +307 -0
  51. package/dist/components/dev-view.cjs.map +1 -0
  52. package/dist/components/dev-view.mjs +306 -0
  53. package/dist/components/dev-view.mjs.map +1 -0
  54. package/dist/components/streaming-view.cjs +146 -0
  55. package/dist/components/streaming-view.cjs.map +1 -0
  56. package/dist/components/streaming-view.mjs +144 -0
  57. package/dist/components/streaming-view.mjs.map +1 -0
  58. package/dist/config.cjs +280 -0
  59. package/dist/config.cjs.map +1 -0
  60. package/dist/config.d.cts +35 -0
  61. package/dist/config.d.cts.map +1 -0
  62. package/dist/config.d.mts +35 -0
  63. package/dist/config.d.mts.map +1 -0
  64. package/dist/config.mjs +266 -0
  65. package/dist/config.mjs.map +1 -0
  66. package/dist/contract.cjs +209 -0
  67. package/dist/contract.cjs.map +1 -0
  68. package/dist/contract.d.cts +490 -0
  69. package/dist/contract.d.cts.map +1 -0
  70. package/dist/contract.d.mts +490 -0
  71. package/dist/contract.d.mts.map +1 -0
  72. package/dist/contract.meta.cjs +104 -0
  73. package/dist/contract.meta.cjs.map +1 -0
  74. package/dist/contract.meta.d.cts +141 -0
  75. package/dist/contract.meta.d.cts.map +1 -0
  76. package/dist/contract.meta.d.mts +141 -0
  77. package/dist/contract.meta.d.mts.map +1 -0
  78. package/dist/contract.meta.mjs +102 -0
  79. package/dist/contract.meta.mjs.map +1 -0
  80. package/dist/contract.mjs +186 -0
  81. package/dist/contract.mjs.map +1 -0
  82. package/dist/dev-logs.cjs +53 -0
  83. package/dist/dev-logs.cjs.map +1 -0
  84. package/dist/dev-logs.mjs +51 -0
  85. package/dist/dev-logs.mjs.map +1 -0
  86. package/dist/dev-session.cjs +195 -0
  87. package/dist/dev-session.cjs.map +1 -0
  88. package/dist/dev-session.mjs +194 -0
  89. package/dist/dev-session.mjs.map +1 -0
  90. package/dist/fastkv.cjs +89 -0
  91. package/dist/fastkv.cjs.map +1 -0
  92. package/dist/fastkv.d.cts +11 -0
  93. package/dist/fastkv.d.cts.map +1 -0
  94. package/dist/fastkv.d.mts +11 -0
  95. package/dist/fastkv.d.mts.map +1 -0
  96. package/dist/fastkv.mjs +82 -0
  97. package/dist/fastkv.mjs.map +1 -0
  98. package/dist/federation.server.cjs +27 -0
  99. package/dist/federation.server.cjs.map +1 -0
  100. package/dist/federation.server.mjs +27 -0
  101. package/dist/federation.server.mjs.map +1 -0
  102. package/dist/host.cjs +367 -0
  103. package/dist/host.cjs.map +1 -0
  104. package/dist/host.d.cts +22 -0
  105. package/dist/host.d.cts.map +1 -0
  106. package/dist/host.d.mts +22 -0
  107. package/dist/host.d.mts.map +1 -0
  108. package/dist/host.mjs +364 -0
  109. package/dist/host.mjs.map +1 -0
  110. package/dist/index.cjs +122 -0
  111. package/dist/index.d.cts +7 -0
  112. package/dist/index.d.mts +7 -0
  113. package/dist/index.mjs +9 -0
  114. package/dist/integrity.cjs +39 -0
  115. package/dist/integrity.cjs.map +1 -0
  116. package/dist/integrity.d.cts +7 -0
  117. package/dist/integrity.d.cts.map +1 -0
  118. package/dist/integrity.d.mts +7 -0
  119. package/dist/integrity.d.mts.map +1 -0
  120. package/dist/integrity.mjs +35 -0
  121. package/dist/integrity.mjs.map +1 -0
  122. package/dist/internal/manifest-normalizer.cjs +140 -0
  123. package/dist/internal/manifest-normalizer.cjs.map +1 -0
  124. package/dist/internal/manifest-normalizer.mjs +138 -0
  125. package/dist/internal/manifest-normalizer.mjs.map +1 -0
  126. package/dist/mf.cjs +77 -0
  127. package/dist/mf.cjs.map +1 -0
  128. package/dist/mf.d.cts +19 -0
  129. package/dist/mf.d.cts.map +1 -0
  130. package/dist/mf.d.mts +19 -0
  131. package/dist/mf.d.mts.map +1 -0
  132. package/dist/mf.mjs +71 -0
  133. package/dist/mf.mjs.map +1 -0
  134. package/dist/near-cli.cjs +196 -0
  135. package/dist/near-cli.cjs.map +1 -0
  136. package/dist/near-cli.mjs +193 -0
  137. package/dist/near-cli.mjs.map +1 -0
  138. package/dist/network.cjs +9 -0
  139. package/dist/network.cjs.map +1 -0
  140. package/dist/network.mjs +8 -0
  141. package/dist/network.mjs.map +1 -0
  142. package/dist/orchestrator.cjs +441 -0
  143. package/dist/orchestrator.cjs.map +1 -0
  144. package/dist/orchestrator.d.cts +40 -0
  145. package/dist/orchestrator.d.cts.map +1 -0
  146. package/dist/orchestrator.d.mts +40 -0
  147. package/dist/orchestrator.d.mts.map +1 -0
  148. package/dist/orchestrator.mjs +436 -0
  149. package/dist/orchestrator.mjs.map +1 -0
  150. package/dist/plugin.cjs +830 -0
  151. package/dist/plugin.cjs.map +1 -0
  152. package/dist/plugin.d.cts +347 -0
  153. package/dist/plugin.d.cts.map +1 -0
  154. package/dist/plugin.d.mts +348 -0
  155. package/dist/plugin.d.mts.map +1 -0
  156. package/dist/plugin.mjs +827 -0
  157. package/dist/plugin.mjs.map +1 -0
  158. package/dist/process-registry.cjs +120 -0
  159. package/dist/process-registry.cjs.map +1 -0
  160. package/dist/process-registry.d.cts +25 -0
  161. package/dist/process-registry.d.cts.map +1 -0
  162. package/dist/process-registry.d.mts +25 -0
  163. package/dist/process-registry.d.mts.map +1 -0
  164. package/dist/process-registry.mjs +119 -0
  165. package/dist/process-registry.mjs.map +1 -0
  166. package/dist/sdk.cjs +61 -0
  167. package/dist/sdk.d.cts +5 -0
  168. package/dist/sdk.d.mts +5 -0
  169. package/dist/sdk.mjs +6 -0
  170. package/dist/shared.cjs +143 -0
  171. package/dist/shared.cjs.map +1 -0
  172. package/dist/shared.d.cts +33 -0
  173. package/dist/shared.d.cts.map +1 -0
  174. package/dist/shared.d.mts +33 -0
  175. package/dist/shared.d.mts.map +1 -0
  176. package/dist/shared.mjs +140 -0
  177. package/dist/shared.mjs.map +1 -0
  178. package/dist/types.cjs +160 -0
  179. package/dist/types.cjs.map +1 -0
  180. package/dist/types.d.cts +269 -0
  181. package/dist/types.d.cts.map +1 -0
  182. package/dist/types.d.mts +269 -0
  183. package/dist/types.d.mts.map +1 -0
  184. package/dist/types.mjs +144 -0
  185. package/dist/types.mjs.map +1 -0
  186. package/dist/ui/head.cjs +67 -0
  187. package/dist/ui/head.cjs.map +1 -0
  188. package/dist/ui/head.d.cts +19 -0
  189. package/dist/ui/head.d.cts.map +1 -0
  190. package/dist/ui/head.d.mts +19 -0
  191. package/dist/ui/head.d.mts.map +1 -0
  192. package/dist/ui/head.mjs +61 -0
  193. package/dist/ui/head.mjs.map +1 -0
  194. package/dist/ui/index.cjs +32 -0
  195. package/dist/ui/index.d.cts +7 -0
  196. package/dist/ui/index.d.mts +7 -0
  197. package/dist/ui/index.mjs +6 -0
  198. package/dist/ui/metadata.cjs +106 -0
  199. package/dist/ui/metadata.cjs.map +1 -0
  200. package/dist/ui/metadata.d.cts +35 -0
  201. package/dist/ui/metadata.d.cts.map +1 -0
  202. package/dist/ui/metadata.d.mts +35 -0
  203. package/dist/ui/metadata.d.mts.map +1 -0
  204. package/dist/ui/metadata.mjs +100 -0
  205. package/dist/ui/metadata.mjs.map +1 -0
  206. package/dist/ui/router.cjs +56 -0
  207. package/dist/ui/router.cjs.map +1 -0
  208. package/dist/ui/router.d.cts +11 -0
  209. package/dist/ui/router.d.cts.map +1 -0
  210. package/dist/ui/router.d.mts +11 -0
  211. package/dist/ui/router.d.mts.map +1 -0
  212. package/dist/ui/router.mjs +51 -0
  213. package/dist/ui/router.mjs.map +1 -0
  214. package/dist/ui/runtime.cjs +65 -0
  215. package/dist/ui/runtime.cjs.map +1 -0
  216. package/dist/ui/runtime.d.cts +29 -0
  217. package/dist/ui/runtime.d.cts.map +1 -0
  218. package/dist/ui/runtime.d.mts +29 -0
  219. package/dist/ui/runtime.d.mts.map +1 -0
  220. package/dist/ui/runtime.mjs +53 -0
  221. package/dist/ui/runtime.mjs.map +1 -0
  222. package/dist/ui/types.cjs +0 -0
  223. package/dist/ui/types.d.cts +52 -0
  224. package/dist/ui/types.d.cts.map +1 -0
  225. package/dist/ui/types.d.mts +52 -0
  226. package/dist/ui/types.d.mts.map +1 -0
  227. package/dist/ui/types.mjs +1 -0
  228. package/dist/utils/banner.cjs +24 -0
  229. package/dist/utils/banner.cjs.map +1 -0
  230. package/dist/utils/banner.mjs +23 -0
  231. package/dist/utils/banner.mjs.map +1 -0
  232. package/dist/utils/linkify.cjs +15 -0
  233. package/dist/utils/linkify.cjs.map +1 -0
  234. package/dist/utils/linkify.mjs +14 -0
  235. package/dist/utils/linkify.mjs.map +1 -0
  236. package/dist/utils/run.cjs +40 -0
  237. package/dist/utils/run.cjs.map +1 -0
  238. package/dist/utils/run.mjs +39 -0
  239. package/dist/utils/run.mjs.map +1 -0
  240. package/dist/utils/theme.cjs +44 -0
  241. package/dist/utils/theme.cjs.map +1 -0
  242. package/dist/utils/theme.mjs +37 -0
  243. package/dist/utils/theme.mjs.map +1 -0
  244. package/package.json +269 -80
  245. package/src/api-contract.ts +309 -0
  246. package/src/api.ts +181 -0
  247. package/src/app.ts +346 -0
  248. package/src/cli/catalog.ts +49 -0
  249. package/src/cli/help.ts +13 -0
  250. package/src/cli/init.ts +386 -0
  251. package/src/cli/parse.ts +130 -0
  252. package/src/cli/prompts.ts +64 -0
  253. package/src/cli.ts +203 -1507
  254. package/src/components/dev-view.tsx +307 -255
  255. package/src/components/streaming-view.ts +164 -128
  256. package/src/config.ts +462 -532
  257. package/src/contract.meta.ts +96 -0
  258. package/src/contract.ts +164 -561
  259. package/src/dev-logs.ts +85 -0
  260. package/src/dev-session.ts +318 -0
  261. package/src/fastkv.ts +153 -0
  262. package/src/federation.server.ts +43 -0
  263. package/src/host.ts +526 -0
  264. package/src/index.ts +6 -3
  265. package/src/integrity.ts +54 -0
  266. package/src/internal/manifest-normalizer.ts +251 -0
  267. package/src/mf.ts +105 -0
  268. package/src/near-cli.ts +284 -0
  269. package/src/network.ts +3 -0
  270. package/src/orchestrator.ts +648 -0
  271. package/src/plugin.ts +1130 -2311
  272. package/src/process-registry.ts +154 -0
  273. package/src/scripts/sync-api-contract.ts +24 -0
  274. package/src/sdk.ts +14 -0
  275. package/src/shared.ts +206 -0
  276. package/src/types.ts +152 -206
  277. package/src/ui/head.ts +34 -27
  278. package/src/ui/index.ts +3 -3
  279. package/src/ui/metadata.ts +95 -0
  280. package/src/ui/router.ts +22 -6
  281. package/src/ui/runtime.ts +55 -6
  282. package/src/ui/types.ts +24 -11
  283. package/src/utils/banner.ts +10 -6
  284. package/src/utils/run.ts +26 -27
  285. package/src/utils/theme.ts +3 -66
  286. package/src/components/monitor-view.tsx +0 -475
  287. package/src/components/status-view.tsx +0 -173
  288. package/src/lib/env.ts +0 -109
  289. package/src/lib/near-cli.ts +0 -289
  290. package/src/lib/nova.ts +0 -266
  291. package/src/lib/orchestrator.ts +0 -276
  292. package/src/lib/process-registry.ts +0 -166
  293. package/src/lib/process.ts +0 -550
  294. package/src/lib/resource-monitor/assertions.ts +0 -234
  295. package/src/lib/resource-monitor/command.ts +0 -283
  296. package/src/lib/resource-monitor/diff.ts +0 -157
  297. package/src/lib/resource-monitor/errors.ts +0 -127
  298. package/src/lib/resource-monitor/index.ts +0 -305
  299. package/src/lib/resource-monitor/platform/darwin.ts +0 -306
  300. package/src/lib/resource-monitor/platform/index.ts +0 -35
  301. package/src/lib/resource-monitor/platform/linux.ts +0 -332
  302. package/src/lib/resource-monitor/platform/windows.ts +0 -298
  303. package/src/lib/resource-monitor/snapshot.ts +0 -217
  304. package/src/lib/resource-monitor/types.ts +0 -74
  305. package/src/lib/session-recorder/errors.ts +0 -102
  306. package/src/lib/session-recorder/flows/login.ts +0 -210
  307. package/src/lib/session-recorder/index.ts +0 -361
  308. package/src/lib/session-recorder/playwright.ts +0 -257
  309. package/src/lib/session-recorder/report.ts +0 -353
  310. package/src/lib/session-recorder/server.ts +0 -268
  311. package/src/lib/session-recorder/types.ts +0 -115
  312. package/src/lib/sync.ts +0 -1
  313. package/src/ui/files.ts +0 -134
@@ -0,0 +1,35 @@
1
+ import { createHash } from "node:crypto";
2
+
3
+ //#region src/integrity.ts
4
+ function computeSriHash(content) {
5
+ return `sha384-${createHash("sha384").update(content).digest("base64")}`;
6
+ }
7
+ async function computeSriHashForUrl(url) {
8
+ try {
9
+ const entryUrl = url.endsWith("/remoteEntry.js") ? url : url.endsWith("/mf-manifest.json") ? `${url.replace(/\/mf-manifest\.json$/, "")}/remoteEntry.js` : `${url.replace(/\/$/, "")}/remoteEntry.js`;
10
+ const response = await fetch(entryUrl);
11
+ if (!response.ok) {
12
+ console.warn(`[SRI] Failed to fetch ${entryUrl}: ${response.status} ${response.statusText}`);
13
+ return null;
14
+ }
15
+ return computeSriHash(Buffer.from(await response.arrayBuffer()));
16
+ } catch (error) {
17
+ console.warn(`[SRI] Error computing integrity for ${url}:`, error instanceof Error ? error.message : error);
18
+ return null;
19
+ }
20
+ }
21
+ async function verifySriForUrl(url, expectedIntegrity) {
22
+ const entryUrl = url.endsWith("/remoteEntry.js") ? url : url.endsWith("/mf-manifest.json") ? `${url.replace(/\/mf-manifest\.json$/, "")}/remoteEntry.js` : `${url.replace(/\/$/, "")}/remoteEntry.js`;
23
+ const response = await fetch(entryUrl);
24
+ if (!response.ok) {
25
+ console.warn(`[SRI] Failed to fetch ${entryUrl} for verification: ${response.status}`);
26
+ return;
27
+ }
28
+ const computed = computeSriHash(Buffer.from(await response.arrayBuffer()));
29
+ if (computed !== expectedIntegrity) throw new Error(`[SRI] Integrity check failed for ${entryUrl}\n Expected: ${expectedIntegrity}\n Computed: ${computed}`);
30
+ console.log(`[SRI] Integrity verified for ${entryUrl}`);
31
+ }
32
+
33
+ //#endregion
34
+ export { computeSriHash, computeSriHashForUrl, verifySriForUrl };
35
+ //# sourceMappingURL=integrity.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrity.mjs","names":[],"sources":["../src/integrity.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\nexport function computeSriHash(content: string | Buffer): string {\n return `sha384-${createHash(\"sha384\").update(content).digest(\"base64\")}`;\n}\n\nexport async function computeSriHashForUrl(url: string): Promise<string | null> {\n try {\n const entryUrl = url.endsWith(\"/remoteEntry.js\")\n ? url\n : url.endsWith(\"/mf-manifest.json\")\n ? `${url.replace(/\\/mf-manifest\\.json$/, \"\")}/remoteEntry.js`\n : `${url.replace(/\\/$/, \"\")}/remoteEntry.js`;\n\n const response = await fetch(entryUrl);\n if (!response.ok) {\n console.warn(`[SRI] Failed to fetch ${entryUrl}: ${response.status} ${response.statusText}`);\n return null;\n }\n const buffer = Buffer.from(await response.arrayBuffer());\n return computeSriHash(buffer);\n } catch (error) {\n console.warn(\n `[SRI] Error computing integrity for ${url}:`,\n error instanceof Error ? error.message : error,\n );\n return null;\n }\n}\n\nexport async function verifySriForUrl(url: string, expectedIntegrity: string): Promise<void> {\n const entryUrl = url.endsWith(\"/remoteEntry.js\")\n ? url\n : url.endsWith(\"/mf-manifest.json\")\n ? `${url.replace(/\\/mf-manifest\\.json$/, \"\")}/remoteEntry.js`\n : `${url.replace(/\\/$/, \"\")}/remoteEntry.js`;\n\n const response = await fetch(entryUrl);\n if (!response.ok) {\n console.warn(`[SRI] Failed to fetch ${entryUrl} for verification: ${response.status}`);\n return;\n }\n\n const buffer = Buffer.from(await response.arrayBuffer());\n const computed = computeSriHash(buffer);\n\n if (computed !== expectedIntegrity) {\n throw new Error(\n `[SRI] Integrity check failed for ${entryUrl}\\n Expected: ${expectedIntegrity}\\n Computed: ${computed}`,\n );\n }\n\n console.log(`[SRI] Integrity verified for ${entryUrl}`);\n}\n"],"mappings":";;;AAEA,SAAgB,eAAe,SAAkC;AAC/D,QAAO,UAAU,WAAW,SAAS,CAAC,OAAO,QAAQ,CAAC,OAAO,SAAS;;AAGxE,eAAsB,qBAAqB,KAAqC;AAC9E,KAAI;EACF,MAAM,WAAW,IAAI,SAAS,kBAAkB,GAC5C,MACA,IAAI,SAAS,oBAAoB,GAC/B,GAAG,IAAI,QAAQ,wBAAwB,GAAG,CAAC,mBAC3C,GAAG,IAAI,QAAQ,OAAO,GAAG,CAAC;EAEhC,MAAM,WAAW,MAAM,MAAM,SAAS;AACtC,MAAI,CAAC,SAAS,IAAI;AAChB,WAAQ,KAAK,yBAAyB,SAAS,IAAI,SAAS,OAAO,GAAG,SAAS,aAAa;AAC5F,UAAO;;AAGT,SAAO,eADQ,OAAO,KAAK,MAAM,SAAS,aAAa,CAAC,CAC3B;UACtB,OAAO;AACd,UAAQ,KACN,uCAAuC,IAAI,IAC3C,iBAAiB,QAAQ,MAAM,UAAU,MAC1C;AACD,SAAO;;;AAIX,eAAsB,gBAAgB,KAAa,mBAA0C;CAC3F,MAAM,WAAW,IAAI,SAAS,kBAAkB,GAC5C,MACA,IAAI,SAAS,oBAAoB,GAC/B,GAAG,IAAI,QAAQ,wBAAwB,GAAG,CAAC,mBAC3C,GAAG,IAAI,QAAQ,OAAO,GAAG,CAAC;CAEhC,MAAM,WAAW,MAAM,MAAM,SAAS;AACtC,KAAI,CAAC,SAAS,IAAI;AAChB,UAAQ,KAAK,yBAAyB,SAAS,qBAAqB,SAAS,SAAS;AACtF;;CAIF,MAAM,WAAW,eADF,OAAO,KAAK,MAAM,SAAS,aAAa,CAAC,CACjB;AAEvC,KAAI,aAAa,kBACf,OAAM,IAAI,MACR,oCAAoC,SAAS,gBAAgB,kBAAkB,gBAAgB,WAChG;AAGH,SAAQ,IAAI,gCAAgC,WAAW"}
@@ -0,0 +1,140 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ let node_fs = require("node:fs");
3
+ let node_path = require("node:path");
4
+ let glob = require("glob");
5
+
6
+ //#region src/internal/manifest-normalizer.ts
7
+ const FRAMEWORK_PACKAGES = ["every-plugin", "everything-dev"];
8
+ function readJson(filePath) {
9
+ return JSON.parse((0, node_fs.readFileSync)(filePath, "utf-8"));
10
+ }
11
+ function extractExactVersion(input) {
12
+ if (!input) return null;
13
+ const match = input.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?/);
14
+ return match ? match[0] : null;
15
+ }
16
+ function writeJson(filePath, value) {
17
+ (0, node_fs.writeFileSync)(filePath, `${JSON.stringify(value, null, 2)}\n`);
18
+ }
19
+ function loadManifestNormalizationSpec(sourceRootDir) {
20
+ const rootCatalog = { ...readJson((0, node_path.join)(sourceRootDir, "package.json")).workspaces?.catalog ?? {} };
21
+ const frameworkVersions = {};
22
+ for (const packageName of FRAMEWORK_PACKAGES) {
23
+ const sourcePackagePath = (0, node_path.join)(sourceRootDir, "packages", packageName, "package.json");
24
+ const localPackagePath = (0, node_path.join)(__dirname, "..", "..", packageName, "package.json");
25
+ const packageVersion = (0, node_fs.existsSync)(sourcePackagePath) ? readJson(sourcePackagePath).version : (0, node_fs.existsSync)(localPackagePath) ? readJson(localPackagePath).version : extractExactVersion(rootCatalog[packageName]);
26
+ if (!packageVersion) throw new Error(`Could not resolve version for ${packageName}`);
27
+ frameworkVersions[packageName] = packageVersion;
28
+ rootCatalog[packageName] = `^${packageVersion}`;
29
+ }
30
+ return {
31
+ rootCatalog,
32
+ frameworkVersions
33
+ };
34
+ }
35
+ function normalizeDependencyMap(map, spec, options) {
36
+ let modified = false;
37
+ for (const [name, version] of Object.entries(map)) {
38
+ if (version === "workspace:*") {
39
+ const frameworkVersion = spec.frameworkVersions[name];
40
+ if (frameworkVersion) {
41
+ map[name] = `^${frameworkVersion}`;
42
+ modified = true;
43
+ continue;
44
+ }
45
+ if (options.removeWorkspaceDeps?.includes(name)) {
46
+ delete map[name];
47
+ modified = true;
48
+ }
49
+ continue;
50
+ }
51
+ if (options.resolveCatalogRefs && version.startsWith("catalog:")) {
52
+ const resolved = spec.rootCatalog[name];
53
+ if (resolved) {
54
+ map[name] = resolved;
55
+ modified = true;
56
+ }
57
+ }
58
+ }
59
+ return modified;
60
+ }
61
+ function normalizePackageManifest(pkg, spec, options) {
62
+ let modified = false;
63
+ for (const depField of [
64
+ "dependencies",
65
+ "devDependencies",
66
+ "peerDependencies"
67
+ ]) {
68
+ const deps = pkg[depField];
69
+ if (!deps || typeof deps !== "object") continue;
70
+ if (normalizeDependencyMap(deps, spec, options)) modified = true;
71
+ }
72
+ if (pkg.workspaces && typeof pkg.workspaces === "object") {
73
+ const workspaces = pkg.workspaces;
74
+ if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {
75
+ const nextPackages = workspaces.packages.filter((entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`));
76
+ if (nextPackages.length !== workspaces.packages.length) {
77
+ workspaces.packages = nextPackages;
78
+ modified = true;
79
+ }
80
+ }
81
+ if (workspaces.catalog && typeof workspaces.catalog === "object") for (const [name, version] of Object.entries(workspaces.catalog)) {
82
+ const resolved = spec.rootCatalog[name];
83
+ if (resolved && resolved !== version) {
84
+ workspaces.catalog[name] = resolved;
85
+ modified = true;
86
+ continue;
87
+ }
88
+ if (version === "workspace:*" && spec.frameworkVersions[name]) {
89
+ workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;
90
+ modified = true;
91
+ }
92
+ }
93
+ }
94
+ if (options.removeWorkspaces && "workspaces" in pkg) {
95
+ delete pkg.workspaces;
96
+ modified = true;
97
+ }
98
+ if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === "object") {
99
+ const scripts = pkg.scripts;
100
+ let scriptsModified = false;
101
+ for (const key of [
102
+ "prepublishOnly",
103
+ "prepack",
104
+ "prepare",
105
+ "postpack"
106
+ ]) if (key in scripts) {
107
+ delete scripts[key];
108
+ scriptsModified = true;
109
+ }
110
+ if (scriptsModified) {
111
+ modified = true;
112
+ if (Object.keys(scripts).length === 0) delete pkg.scripts;
113
+ }
114
+ }
115
+ return modified;
116
+ }
117
+ async function normalizePackageManifestsInTree(opts) {
118
+ const spec = loadManifestNormalizationSpec(opts.sourceRootDir);
119
+ const files = await (0, glob.glob)("**/package.json", {
120
+ cwd: opts.targetDir,
121
+ nodir: true,
122
+ dot: false,
123
+ absolute: true,
124
+ ignore: ["**/node_modules/**"]
125
+ });
126
+ const updatedFiles = [];
127
+ for (const filePath of files) {
128
+ const pkg = readJson(filePath);
129
+ if (normalizePackageManifest(pkg, spec, opts)) {
130
+ writeJson(filePath, pkg);
131
+ updatedFiles.push(filePath);
132
+ }
133
+ }
134
+ return updatedFiles;
135
+ }
136
+
137
+ //#endregion
138
+ exports.loadManifestNormalizationSpec = loadManifestNormalizationSpec;
139
+ exports.normalizePackageManifestsInTree = normalizePackageManifestsInTree;
140
+ //# sourceMappingURL=manifest-normalizer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-normalizer.cjs","names":[],"sources":["../../src/internal/manifest-normalizer.ts"],"sourcesContent":["import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { glob } from \"glob\";\n\nconst FRAMEWORK_PACKAGES = [\"every-plugin\", \"everything-dev\"] as const;\n\ntype PackageJson = Record<string, unknown>;\n\ntype NormalizationSpec = {\n rootCatalog: Record<string, string>;\n frameworkVersions: Record<string, string>;\n};\n\ntype NormalizeManifestOptions = {\n resolveCatalogRefs: boolean;\n excludeFrameworkWorkspaces?: boolean;\n removeWorkspaceDeps?: string[];\n removeWorkspaces?: boolean;\n removePublishScripts?: boolean;\n};\n\nexport type NormalizeTreeOptions = NormalizeManifestOptions & {\n sourceRootDir: string;\n targetDir: string;\n};\n\nfunction readJson<T>(filePath: string): T {\n return JSON.parse(readFileSync(filePath, \"utf-8\")) as T;\n}\n\nfunction extractExactVersion(input: string | undefined): string | null {\n if (!input) return null;\n const match = input.match(/\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?/);\n return match ? match[0] : null;\n}\n\nfunction writeJson(filePath: string, value: PackageJson) {\n writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {\n const rootPackage = readJson<PackageJson>(join(sourceRootDir, \"package.json\"));\n const rootCatalog = {\n ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??\n {}) as Record<string, string>),\n };\n const frameworkVersions: Record<string, string> = {};\n\n for (const packageName of FRAMEWORK_PACKAGES) {\n const sourcePackagePath = join(sourceRootDir, \"packages\", packageName, \"package.json\");\n const localPackagePath = join(import.meta.dirname, \"..\", \"..\", packageName, \"package.json\");\n const packageVersion = existsSync(sourcePackagePath)\n ? readJson<{ version: string }>(sourcePackagePath).version\n : existsSync(localPackagePath)\n ? readJson<{ version: string }>(localPackagePath).version\n : extractExactVersion(rootCatalog[packageName]);\n\n if (!packageVersion) {\n throw new Error(`Could not resolve version for ${packageName}`);\n }\n\n frameworkVersions[packageName] = packageVersion;\n rootCatalog[packageName] = `^${packageVersion}`;\n }\n\n return { rootCatalog, frameworkVersions };\n}\n\nfunction normalizeDependencyMap(\n map: Record<string, string>,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const [name, version] of Object.entries(map)) {\n if (version === \"workspace:*\") {\n const frameworkVersion = spec.frameworkVersions[name];\n if (frameworkVersion) {\n map[name] = `^${frameworkVersion}`;\n modified = true;\n continue;\n }\n\n if (options.removeWorkspaceDeps?.includes(name)) {\n delete map[name];\n modified = true;\n }\n continue;\n }\n\n if (options.resolveCatalogRefs && version.startsWith(\"catalog:\")) {\n const resolved = spec.rootCatalog[name];\n if (resolved) {\n map[name] = resolved;\n modified = true;\n }\n }\n }\n\n return modified;\n}\n\nexport function normalizePackageManifest(\n pkg: PackageJson,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const depField of [\"dependencies\", \"devDependencies\", \"peerDependencies\"]) {\n const deps = pkg[depField];\n if (!deps || typeof deps !== \"object\") continue;\n if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {\n modified = true;\n }\n }\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const workspaces = pkg.workspaces as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {\n const nextPackages = workspaces.packages.filter(\n (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),\n );\n if (nextPackages.length !== workspaces.packages.length) {\n workspaces.packages = nextPackages;\n modified = true;\n }\n }\n\n if (workspaces.catalog && typeof workspaces.catalog === \"object\") {\n for (const [name, version] of Object.entries(workspaces.catalog)) {\n const resolved = spec.rootCatalog[name];\n if (resolved && resolved !== version) {\n workspaces.catalog[name] = resolved;\n modified = true;\n continue;\n }\n\n if (version === \"workspace:*\" && spec.frameworkVersions[name]) {\n workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;\n modified = true;\n }\n }\n }\n }\n\n if (options.removeWorkspaces && \"workspaces\" in pkg) {\n delete pkg.workspaces;\n modified = true;\n }\n\n if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n let scriptsModified = false;\n for (const key of [\"prepublishOnly\", \"prepack\", \"prepare\", \"postpack\"]) {\n if (key in scripts) {\n delete scripts[key];\n scriptsModified = true;\n }\n }\n if (scriptsModified) {\n modified = true;\n if (Object.keys(scripts).length === 0) {\n delete pkg.scripts;\n }\n }\n }\n\n return modified;\n}\n\nexport async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {\n const spec = loadManifestNormalizationSpec(opts.sourceRootDir);\n const files = await glob(\"**/package.json\", {\n cwd: opts.targetDir,\n nodir: true,\n dot: false,\n absolute: true,\n ignore: [\"**/node_modules/**\"],\n });\n\n const updatedFiles: string[] = [];\n\n for (const filePath of files) {\n const pkg = readJson<PackageJson>(filePath);\n if (normalizePackageManifest(pkg, spec, opts)) {\n writeJson(filePath, pkg);\n updatedFiles.push(filePath);\n }\n }\n\n return updatedFiles;\n}\n\nfunction shouldCopyPackageFile(sourceDir: string, filePath: string) {\n const relPath = relative(sourceDir, filePath);\n if (!relPath) return true;\n const segments = relPath.split(sep);\n return !segments.includes(\"node_modules\") && !segments.includes(\"tests\");\n}\n\nexport function stageReleasePackage(opts: {\n repoRoot: string;\n packageName: string;\n outDir: string;\n}) {\n const sourceDir = join(opts.repoRoot, \"packages\", opts.packageName);\n\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(dirname(opts.outDir), { recursive: true });\n cpSync(sourceDir, opts.outDir, {\n recursive: true,\n filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),\n });\n rmSync(join(opts.outDir, \"tests\"), { recursive: true, force: true });\n\n const packageJsonPath = join(opts.outDir, \"package.json\");\n const spec = loadManifestNormalizationSpec(opts.repoRoot);\n const pkg = readJson<PackageJson>(packageJsonPath);\n\n normalizePackageManifest(pkg, spec, {\n resolveCatalogRefs: true,\n removeWorkspaces: true,\n removePublishScripts: true,\n });\n\n writeJson(packageJsonPath, pkg);\n}\n\nexport function stageReleasePackages(opts: {\n repoRoot: string;\n outDir: string;\n packageNames?: string[];\n}) {\n const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(opts.outDir, { recursive: true });\n\n for (const packageName of packageNames) {\n stageReleasePackage({\n repoRoot: opts.repoRoot,\n packageName,\n outDir: join(opts.outDir, packageName),\n });\n }\n}\n"],"mappings":";;;;;;AAIA,MAAM,qBAAqB,CAAC,gBAAgB,iBAAiB;AAsB7D,SAAS,SAAY,UAAqB;AACxC,QAAO,KAAK,gCAAmB,UAAU,QAAQ,CAAC;;AAGpD,SAAS,oBAAoB,OAA0C;AACrE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,oCAAoC;AAC9D,QAAO,QAAQ,MAAM,KAAK;;AAG5B,SAAS,UAAU,UAAkB,OAAoB;AACvD,4BAAc,UAAU,GAAG,KAAK,UAAU,OAAO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,CAAC,qBAAqB;EAC/B,CAAC;CAEF,MAAM,eAAyB,EAAE;AAEjC,MAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,MAAM,SAAsB,SAAS;AAC3C,MAAI,yBAAyB,KAAK,MAAM,KAAK,EAAE;AAC7C,aAAU,UAAU,IAAI;AACxB,gBAAa,KAAK,SAAS;;;AAI/B,QAAO"}
@@ -0,0 +1,138 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, relative } from "node:path";
3
+ import { glob } from "glob";
4
+
5
+ //#region src/internal/manifest-normalizer.ts
6
+ const FRAMEWORK_PACKAGES = ["every-plugin", "everything-dev"];
7
+ function readJson(filePath) {
8
+ return JSON.parse(readFileSync(filePath, "utf-8"));
9
+ }
10
+ function extractExactVersion(input) {
11
+ if (!input) return null;
12
+ const match = input.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?/);
13
+ return match ? match[0] : null;
14
+ }
15
+ function writeJson(filePath, value) {
16
+ writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
17
+ }
18
+ function loadManifestNormalizationSpec(sourceRootDir) {
19
+ const rootCatalog = { ...readJson(join(sourceRootDir, "package.json")).workspaces?.catalog ?? {} };
20
+ const frameworkVersions = {};
21
+ for (const packageName of FRAMEWORK_PACKAGES) {
22
+ const sourcePackagePath = join(sourceRootDir, "packages", packageName, "package.json");
23
+ const localPackagePath = join(import.meta.dirname, "..", "..", packageName, "package.json");
24
+ const packageVersion = existsSync(sourcePackagePath) ? readJson(sourcePackagePath).version : existsSync(localPackagePath) ? readJson(localPackagePath).version : extractExactVersion(rootCatalog[packageName]);
25
+ if (!packageVersion) throw new Error(`Could not resolve version for ${packageName}`);
26
+ frameworkVersions[packageName] = packageVersion;
27
+ rootCatalog[packageName] = `^${packageVersion}`;
28
+ }
29
+ return {
30
+ rootCatalog,
31
+ frameworkVersions
32
+ };
33
+ }
34
+ function normalizeDependencyMap(map, spec, options) {
35
+ let modified = false;
36
+ for (const [name, version] of Object.entries(map)) {
37
+ if (version === "workspace:*") {
38
+ const frameworkVersion = spec.frameworkVersions[name];
39
+ if (frameworkVersion) {
40
+ map[name] = `^${frameworkVersion}`;
41
+ modified = true;
42
+ continue;
43
+ }
44
+ if (options.removeWorkspaceDeps?.includes(name)) {
45
+ delete map[name];
46
+ modified = true;
47
+ }
48
+ continue;
49
+ }
50
+ if (options.resolveCatalogRefs && version.startsWith("catalog:")) {
51
+ const resolved = spec.rootCatalog[name];
52
+ if (resolved) {
53
+ map[name] = resolved;
54
+ modified = true;
55
+ }
56
+ }
57
+ }
58
+ return modified;
59
+ }
60
+ function normalizePackageManifest(pkg, spec, options) {
61
+ let modified = false;
62
+ for (const depField of [
63
+ "dependencies",
64
+ "devDependencies",
65
+ "peerDependencies"
66
+ ]) {
67
+ const deps = pkg[depField];
68
+ if (!deps || typeof deps !== "object") continue;
69
+ if (normalizeDependencyMap(deps, spec, options)) modified = true;
70
+ }
71
+ if (pkg.workspaces && typeof pkg.workspaces === "object") {
72
+ const workspaces = pkg.workspaces;
73
+ if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {
74
+ const nextPackages = workspaces.packages.filter((entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`));
75
+ if (nextPackages.length !== workspaces.packages.length) {
76
+ workspaces.packages = nextPackages;
77
+ modified = true;
78
+ }
79
+ }
80
+ if (workspaces.catalog && typeof workspaces.catalog === "object") for (const [name, version] of Object.entries(workspaces.catalog)) {
81
+ const resolved = spec.rootCatalog[name];
82
+ if (resolved && resolved !== version) {
83
+ workspaces.catalog[name] = resolved;
84
+ modified = true;
85
+ continue;
86
+ }
87
+ if (version === "workspace:*" && spec.frameworkVersions[name]) {
88
+ workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;
89
+ modified = true;
90
+ }
91
+ }
92
+ }
93
+ if (options.removeWorkspaces && "workspaces" in pkg) {
94
+ delete pkg.workspaces;
95
+ modified = true;
96
+ }
97
+ if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === "object") {
98
+ const scripts = pkg.scripts;
99
+ let scriptsModified = false;
100
+ for (const key of [
101
+ "prepublishOnly",
102
+ "prepack",
103
+ "prepare",
104
+ "postpack"
105
+ ]) if (key in scripts) {
106
+ delete scripts[key];
107
+ scriptsModified = true;
108
+ }
109
+ if (scriptsModified) {
110
+ modified = true;
111
+ if (Object.keys(scripts).length === 0) delete pkg.scripts;
112
+ }
113
+ }
114
+ return modified;
115
+ }
116
+ async function normalizePackageManifestsInTree(opts) {
117
+ const spec = loadManifestNormalizationSpec(opts.sourceRootDir);
118
+ const files = await glob("**/package.json", {
119
+ cwd: opts.targetDir,
120
+ nodir: true,
121
+ dot: false,
122
+ absolute: true,
123
+ ignore: ["**/node_modules/**"]
124
+ });
125
+ const updatedFiles = [];
126
+ for (const filePath of files) {
127
+ const pkg = readJson(filePath);
128
+ if (normalizePackageManifest(pkg, spec, opts)) {
129
+ writeJson(filePath, pkg);
130
+ updatedFiles.push(filePath);
131
+ }
132
+ }
133
+ return updatedFiles;
134
+ }
135
+
136
+ //#endregion
137
+ export { loadManifestNormalizationSpec, normalizePackageManifestsInTree };
138
+ //# sourceMappingURL=manifest-normalizer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-normalizer.mjs","names":[],"sources":["../../src/internal/manifest-normalizer.ts"],"sourcesContent":["import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { glob } from \"glob\";\n\nconst FRAMEWORK_PACKAGES = [\"every-plugin\", \"everything-dev\"] as const;\n\ntype PackageJson = Record<string, unknown>;\n\ntype NormalizationSpec = {\n rootCatalog: Record<string, string>;\n frameworkVersions: Record<string, string>;\n};\n\ntype NormalizeManifestOptions = {\n resolveCatalogRefs: boolean;\n excludeFrameworkWorkspaces?: boolean;\n removeWorkspaceDeps?: string[];\n removeWorkspaces?: boolean;\n removePublishScripts?: boolean;\n};\n\nexport type NormalizeTreeOptions = NormalizeManifestOptions & {\n sourceRootDir: string;\n targetDir: string;\n};\n\nfunction readJson<T>(filePath: string): T {\n return JSON.parse(readFileSync(filePath, \"utf-8\")) as T;\n}\n\nfunction extractExactVersion(input: string | undefined): string | null {\n if (!input) return null;\n const match = input.match(/\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?/);\n return match ? match[0] : null;\n}\n\nfunction writeJson(filePath: string, value: PackageJson) {\n writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {\n const rootPackage = readJson<PackageJson>(join(sourceRootDir, \"package.json\"));\n const rootCatalog = {\n ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??\n {}) as Record<string, string>),\n };\n const frameworkVersions: Record<string, string> = {};\n\n for (const packageName of FRAMEWORK_PACKAGES) {\n const sourcePackagePath = join(sourceRootDir, \"packages\", packageName, \"package.json\");\n const localPackagePath = join(import.meta.dirname, \"..\", \"..\", packageName, \"package.json\");\n const packageVersion = existsSync(sourcePackagePath)\n ? readJson<{ version: string }>(sourcePackagePath).version\n : existsSync(localPackagePath)\n ? readJson<{ version: string }>(localPackagePath).version\n : extractExactVersion(rootCatalog[packageName]);\n\n if (!packageVersion) {\n throw new Error(`Could not resolve version for ${packageName}`);\n }\n\n frameworkVersions[packageName] = packageVersion;\n rootCatalog[packageName] = `^${packageVersion}`;\n }\n\n return { rootCatalog, frameworkVersions };\n}\n\nfunction normalizeDependencyMap(\n map: Record<string, string>,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const [name, version] of Object.entries(map)) {\n if (version === \"workspace:*\") {\n const frameworkVersion = spec.frameworkVersions[name];\n if (frameworkVersion) {\n map[name] = `^${frameworkVersion}`;\n modified = true;\n continue;\n }\n\n if (options.removeWorkspaceDeps?.includes(name)) {\n delete map[name];\n modified = true;\n }\n continue;\n }\n\n if (options.resolveCatalogRefs && version.startsWith(\"catalog:\")) {\n const resolved = spec.rootCatalog[name];\n if (resolved) {\n map[name] = resolved;\n modified = true;\n }\n }\n }\n\n return modified;\n}\n\nexport function normalizePackageManifest(\n pkg: PackageJson,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const depField of [\"dependencies\", \"devDependencies\", \"peerDependencies\"]) {\n const deps = pkg[depField];\n if (!deps || typeof deps !== \"object\") continue;\n if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {\n modified = true;\n }\n }\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const workspaces = pkg.workspaces as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {\n const nextPackages = workspaces.packages.filter(\n (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),\n );\n if (nextPackages.length !== workspaces.packages.length) {\n workspaces.packages = nextPackages;\n modified = true;\n }\n }\n\n if (workspaces.catalog && typeof workspaces.catalog === \"object\") {\n for (const [name, version] of Object.entries(workspaces.catalog)) {\n const resolved = spec.rootCatalog[name];\n if (resolved && resolved !== version) {\n workspaces.catalog[name] = resolved;\n modified = true;\n continue;\n }\n\n if (version === \"workspace:*\" && spec.frameworkVersions[name]) {\n workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;\n modified = true;\n }\n }\n }\n }\n\n if (options.removeWorkspaces && \"workspaces\" in pkg) {\n delete pkg.workspaces;\n modified = true;\n }\n\n if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n let scriptsModified = false;\n for (const key of [\"prepublishOnly\", \"prepack\", \"prepare\", \"postpack\"]) {\n if (key in scripts) {\n delete scripts[key];\n scriptsModified = true;\n }\n }\n if (scriptsModified) {\n modified = true;\n if (Object.keys(scripts).length === 0) {\n delete pkg.scripts;\n }\n }\n }\n\n return modified;\n}\n\nexport async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {\n const spec = loadManifestNormalizationSpec(opts.sourceRootDir);\n const files = await glob(\"**/package.json\", {\n cwd: opts.targetDir,\n nodir: true,\n dot: false,\n absolute: true,\n ignore: [\"**/node_modules/**\"],\n });\n\n const updatedFiles: string[] = [];\n\n for (const filePath of files) {\n const pkg = readJson<PackageJson>(filePath);\n if (normalizePackageManifest(pkg, spec, opts)) {\n writeJson(filePath, pkg);\n updatedFiles.push(filePath);\n }\n }\n\n return updatedFiles;\n}\n\nfunction shouldCopyPackageFile(sourceDir: string, filePath: string) {\n const relPath = relative(sourceDir, filePath);\n if (!relPath) return true;\n const segments = relPath.split(sep);\n return !segments.includes(\"node_modules\") && !segments.includes(\"tests\");\n}\n\nexport function stageReleasePackage(opts: {\n repoRoot: string;\n packageName: string;\n outDir: string;\n}) {\n const sourceDir = join(opts.repoRoot, \"packages\", opts.packageName);\n\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(dirname(opts.outDir), { recursive: true });\n cpSync(sourceDir, opts.outDir, {\n recursive: true,\n filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),\n });\n rmSync(join(opts.outDir, \"tests\"), { recursive: true, force: true });\n\n const packageJsonPath = join(opts.outDir, \"package.json\");\n const spec = loadManifestNormalizationSpec(opts.repoRoot);\n const pkg = readJson<PackageJson>(packageJsonPath);\n\n normalizePackageManifest(pkg, spec, {\n resolveCatalogRefs: true,\n removeWorkspaces: true,\n removePublishScripts: true,\n });\n\n writeJson(packageJsonPath, pkg);\n}\n\nexport function stageReleasePackages(opts: {\n repoRoot: string;\n outDir: string;\n packageNames?: string[];\n}) {\n const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(opts.outDir, { recursive: true });\n\n for (const packageName of packageNames) {\n stageReleasePackage({\n repoRoot: opts.repoRoot,\n packageName,\n outDir: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,IAAI;EACpB,IAAI,kBAAkB;AACtB,OAAK,MAAM,OAAO;GAAC;GAAkB;GAAW;GAAW;GAAW,CACpE,KAAI,OAAO,SAAS;AAClB,UAAO,QAAQ;AACf,qBAAkB;;AAGtB,MAAI,iBAAiB;AACnB,cAAW;AACX,OAAI,OAAO,KAAK,QAAQ,CAAC,WAAW,EAClC,QAAO,IAAI;;;AAKjB,QAAO;;AAGT,eAAsB,gCAAgC,MAA4B;CAChF,MAAM,OAAO,8BAA8B,KAAK,cAAc;CAC9D,MAAM,QAAQ,MAAM,KAAK,mBAAmB;EAC1C,KAAK,KAAK;EACV,OAAO;EACP,KAAK;EACL,UAAU;EACV,QAAQ,CAAC,qBAAqB;EAC/B,CAAC;CAEF,MAAM,eAAyB,EAAE;AAEjC,MAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,MAAM,SAAsB,SAAS;AAC3C,MAAI,yBAAyB,KAAK,MAAM,KAAK,EAAE;AAC7C,aAAU,UAAU,IAAI;AACxB,gBAAa,KAAK,SAAS;;;AAI/B,QAAO"}
package/dist/mf.cjs ADDED
@@ -0,0 +1,77 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _module_federation_enhanced_runtime = require("@module-federation/enhanced/runtime");
4
+ let _module_federation_runtime_core = require("@module-federation/runtime-core");
5
+
6
+ //#region src/mf.ts
7
+ let mfInstance = null;
8
+ function patchManifestFetchForSsrPublicPath(mf) {
9
+ if (!mf || !mf.loaderHook?.lifecycle?.fetch?.on) return;
10
+ if (mf.__everythingDevPatchedManifestFetch === true) return;
11
+ mf.__everythingDevPatchedManifestFetch = true;
12
+ mf.loaderHook.lifecycle.fetch.on((url, init) => {
13
+ if (typeof url !== "string" || !url.endsWith("/mf-manifest.json")) return;
14
+ return fetch(url, init).then((res) => res.json()).then((json) => {
15
+ json.metaData = json.metaData ?? {};
16
+ json.metaData.ssrPublicPath = json.metaData.ssrPublicPath ?? url.replace(/\/mf-manifest\.json$/, "/");
17
+ return new Response(JSON.stringify(json), { headers: { "content-type": "application/json" } });
18
+ });
19
+ });
20
+ }
21
+ function getFederationInstance() {
22
+ if (mfInstance) return mfInstance;
23
+ const existing = (0, _module_federation_enhanced_runtime.getInstance)();
24
+ if (existing) {
25
+ mfInstance = existing;
26
+ (0, _module_federation_runtime_core.setGlobalFederationInstance)(mfInstance);
27
+ patchManifestFetchForSsrPublicPath(mfInstance);
28
+ return mfInstance;
29
+ }
30
+ mfInstance = (0, _module_federation_enhanced_runtime.createInstance)({
31
+ name: "host",
32
+ remotes: []
33
+ });
34
+ (0, _module_federation_runtime_core.setGlobalFederationInstance)(mfInstance);
35
+ patchManifestFetchForSsrPublicPath(mfInstance);
36
+ return mfInstance;
37
+ }
38
+ async function registerRemote(opts) {
39
+ const instance = getFederationInstance();
40
+ const inferType = () => {
41
+ if (opts.type) return opts.type;
42
+ if (opts.entry.endsWith("/mf-manifest.json")) return "manifest";
43
+ if (opts.entry.endsWith("/remoteEntry.js")) return "script";
44
+ return typeof window === "undefined" ? "script" : "manifest";
45
+ };
46
+ const remoteType = inferType();
47
+ instance.registerRemotes([{
48
+ name: opts.name,
49
+ entry: opts.entry,
50
+ type: remoteType
51
+ }]);
52
+ }
53
+ async function loadRemoteModule(specifier, options) {
54
+ const instance = getFederationInstance();
55
+ if (typeof window === "undefined") await instance.initializeSharing?.("default");
56
+ const mod = await instance.loadRemote(specifier, options);
57
+ if (!mod) throw new Error(`Failed to load remote module: ${specifier}`);
58
+ return mod;
59
+ }
60
+ async function ensureNodeRuntimePlugin() {
61
+ const instance = getFederationInstance();
62
+ if (typeof window !== "undefined") return;
63
+ if (instance.__nodeRuntimePluginLoaded) return;
64
+ const mod = await import("@module-federation/node/runtimePlugin");
65
+ const factory = mod?.default ?? mod;
66
+ const plugin = typeof factory === "function" ? factory() : null;
67
+ if (plugin) instance.registerPlugins([plugin]);
68
+ instance.__nodeRuntimePluginLoaded = true;
69
+ }
70
+
71
+ //#endregion
72
+ exports.ensureNodeRuntimePlugin = ensureNodeRuntimePlugin;
73
+ exports.getFederationInstance = getFederationInstance;
74
+ exports.loadRemoteModule = loadRemoteModule;
75
+ exports.patchManifestFetchForSsrPublicPath = patchManifestFetchForSsrPublicPath;
76
+ exports.registerRemote = registerRemote;
77
+ //# sourceMappingURL=mf.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mf.cjs","names":[],"sources":["../src/mf.ts"],"sourcesContent":["import { createInstance, getInstance } from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\n\ntype FederationInstance = ReturnType<typeof createInstance>;\n\nlet mfInstance: FederationInstance | null = null;\n\nexport function patchManifestFetchForSsrPublicPath(mf: FederationInstance): void {\n if (!mf || !(mf as any).loaderHook?.lifecycle?.fetch?.on) return;\n if ((mf as any).__everythingDevPatchedManifestFetch === true) return;\n (mf as any).__everythingDevPatchedManifestFetch = true;\n\n (mf as any).loaderHook.lifecycle.fetch.on((url: unknown, init: unknown) => {\n if (typeof url !== \"string\" || !url.endsWith(\"/mf-manifest.json\")) {\n return;\n }\n return fetch(url, init as any)\n .then((res) => res.json())\n .then((json: any) => {\n json.metaData = json.metaData ?? {};\n json.metaData.ssrPublicPath =\n json.metaData.ssrPublicPath ?? url.replace(/\\/mf-manifest\\.json$/, \"/\");\n return new Response(JSON.stringify(json), {\n headers: { \"content-type\": \"application/json\" },\n });\n });\n });\n}\n\nexport function getFederationInstance(): FederationInstance {\n if (mfInstance) return mfInstance;\n\n const existing = getInstance();\n if (existing) {\n mfInstance = existing as FederationInstance;\n setGlobalFederationInstance(mfInstance as any);\n patchManifestFetchForSsrPublicPath(mfInstance);\n return mfInstance;\n }\n\n mfInstance = createInstance({\n name: \"host\",\n remotes: [],\n }) as FederationInstance;\n setGlobalFederationInstance(mfInstance as any);\n patchManifestFetchForSsrPublicPath(mfInstance);\n return mfInstance;\n}\n\nexport async function registerRemote(opts: {\n name: string;\n entry: string;\n type?: \"manifest\" | \"script\";\n}): Promise<void> {\n const instance = getFederationInstance();\n\n const inferType = (): \"manifest\" | \"script\" => {\n if (opts.type) return opts.type;\n if (opts.entry.endsWith(\"/mf-manifest.json\")) return \"manifest\";\n if (opts.entry.endsWith(\"/remoteEntry.js\")) return \"script\";\n return typeof window === \"undefined\" ? \"script\" : \"manifest\";\n };\n\n const remoteType = inferType();\n\n instance.registerRemotes([\n {\n name: opts.name,\n entry: opts.entry,\n type: remoteType,\n },\n ]);\n}\n\nexport async function loadRemoteModule<T>(\n specifier: string,\n options?: { loadFactory?: boolean; from?: \"build\" | \"runtime\" },\n): Promise<T> {\n const instance = getFederationInstance();\n\n const isServer = typeof window === \"undefined\";\n if (isServer) {\n await (instance as any).initializeSharing?.(\"default\");\n }\n\n const mod = await instance.loadRemote<T>(specifier, options as any);\n if (!mod) {\n throw new Error(`Failed to load remote module: ${specifier}`);\n }\n return mod;\n}\n\nexport async function ensureNodeRuntimePlugin(): Promise<void> {\n const instance = getFederationInstance();\n if (typeof window !== \"undefined\") return;\n if ((instance as any).__nodeRuntimePluginLoaded) return;\n\n const mod: any = await import(\"@module-federation/node/runtimePlugin\");\n const factory = mod?.default ?? mod;\n const plugin = typeof factory === \"function\" ? factory() : null;\n if (plugin) {\n instance.registerPlugins([plugin]);\n }\n (instance as any).__nodeRuntimePluginLoaded = true;\n}\n"],"mappings":";;;;;;AAKA,IAAI,aAAwC;AAE5C,SAAgB,mCAAmC,IAA8B;AAC/E,KAAI,CAAC,MAAM,CAAE,GAAW,YAAY,WAAW,OAAO,GAAI;AAC1D,KAAK,GAAW,wCAAwC,KAAM;AAC9D,CAAC,GAAW,sCAAsC;AAElD,CAAC,GAAW,WAAW,UAAU,MAAM,IAAI,KAAc,SAAkB;AACzE,MAAI,OAAO,QAAQ,YAAY,CAAC,IAAI,SAAS,oBAAoB,CAC/D;AAEF,SAAO,MAAM,KAAK,KAAY,CAC3B,MAAM,QAAQ,IAAI,MAAM,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,MAAW,MAAM,OAAO;CAC9B,MAAM,UAAU,KAAK,WAAW;CAChC,MAAM,SAAS,OAAO,YAAY,aAAa,SAAS,GAAG;AAC3D,KAAI,OACF,UAAS,gBAAgB,CAAC,OAAO,CAAC;AAEpC,CAAC,SAAiB,4BAA4B"}
package/dist/mf.d.cts ADDED
@@ -0,0 +1,19 @@
1
+ import { createInstance } from "@module-federation/enhanced/runtime";
2
+
3
+ //#region src/mf.d.ts
4
+ type FederationInstance = ReturnType<typeof createInstance>;
5
+ declare function patchManifestFetchForSsrPublicPath(mf: FederationInstance): void;
6
+ declare function getFederationInstance(): FederationInstance;
7
+ declare function registerRemote(opts: {
8
+ name: string;
9
+ entry: string;
10
+ type?: "manifest" | "script";
11
+ }): Promise<void>;
12
+ declare function loadRemoteModule<T>(specifier: string, options?: {
13
+ loadFactory?: boolean;
14
+ from?: "build" | "runtime";
15
+ }): Promise<T>;
16
+ declare function ensureNodeRuntimePlugin(): Promise<void>;
17
+ //#endregion
18
+ export { ensureNodeRuntimePlugin, getFederationInstance, loadRemoteModule, patchManifestFetchForSsrPublicPath, registerRemote };
19
+ //# sourceMappingURL=mf.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mf.d.cts","names":[],"sources":["../src/mf.ts"],"mappings":";;;KAGK,kBAAA,GAAqB,UAAA,QAAkB,cAAA;AAAA,iBAI5B,kCAAA,CAAmC,EAAA,EAAI,kBAAA;AAAA,iBAsBvC,qBAAA,CAAA,GAAyB,kBAAA;AAAA,iBAoBnB,cAAA,CAAe,IAAA;EACnC,IAAA;EACA,KAAA;EACA,IAAA;AAAA,IACE,OAAA;AAAA,iBAqBkB,gBAAA,GAAA,CACpB,SAAA,UACA,OAAA;EAAY,WAAA;EAAuB,IAAA;AAAA,IAClC,OAAA,CAAQ,CAAA;AAAA,iBAeW,uBAAA,CAAA,GAA2B,OAAA"}
package/dist/mf.d.mts ADDED
@@ -0,0 +1,19 @@
1
+ import { createInstance } from "@module-federation/enhanced/runtime";
2
+
3
+ //#region src/mf.d.ts
4
+ type FederationInstance = ReturnType<typeof createInstance>;
5
+ declare function patchManifestFetchForSsrPublicPath(mf: FederationInstance): void;
6
+ declare function getFederationInstance(): FederationInstance;
7
+ declare function registerRemote(opts: {
8
+ name: string;
9
+ entry: string;
10
+ type?: "manifest" | "script";
11
+ }): Promise<void>;
12
+ declare function loadRemoteModule<T>(specifier: string, options?: {
13
+ loadFactory?: boolean;
14
+ from?: "build" | "runtime";
15
+ }): Promise<T>;
16
+ declare function ensureNodeRuntimePlugin(): Promise<void>;
17
+ //#endregion
18
+ export { ensureNodeRuntimePlugin, getFederationInstance, loadRemoteModule, patchManifestFetchForSsrPublicPath, registerRemote };
19
+ //# sourceMappingURL=mf.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mf.d.mts","names":[],"sources":["../src/mf.ts"],"mappings":";;;KAGK,kBAAA,GAAqB,UAAA,QAAkB,cAAA;AAAA,iBAI5B,kCAAA,CAAmC,EAAA,EAAI,kBAAA;AAAA,iBAsBvC,qBAAA,CAAA,GAAyB,kBAAA;AAAA,iBAoBnB,cAAA,CAAe,IAAA;EACnC,IAAA;EACA,KAAA;EACA,IAAA;AAAA,IACE,OAAA;AAAA,iBAqBkB,gBAAA,GAAA,CACpB,SAAA,UACA,OAAA;EAAY,WAAA;EAAuB,IAAA;AAAA,IAClC,OAAA,CAAQ,CAAA;AAAA,iBAeW,uBAAA,CAAA,GAA2B,OAAA"}
package/dist/mf.mjs ADDED
@@ -0,0 +1,71 @@
1
+ import { createInstance, getInstance } from "@module-federation/enhanced/runtime";
2
+ import { setGlobalFederationInstance } from "@module-federation/runtime-core";
3
+
4
+ //#region src/mf.ts
5
+ let mfInstance = null;
6
+ function patchManifestFetchForSsrPublicPath(mf) {
7
+ if (!mf || !mf.loaderHook?.lifecycle?.fetch?.on) return;
8
+ if (mf.__everythingDevPatchedManifestFetch === true) return;
9
+ mf.__everythingDevPatchedManifestFetch = true;
10
+ mf.loaderHook.lifecycle.fetch.on((url, init) => {
11
+ if (typeof url !== "string" || !url.endsWith("/mf-manifest.json")) return;
12
+ return fetch(url, init).then((res) => res.json()).then((json) => {
13
+ json.metaData = json.metaData ?? {};
14
+ json.metaData.ssrPublicPath = json.metaData.ssrPublicPath ?? url.replace(/\/mf-manifest\.json$/, "/");
15
+ return new Response(JSON.stringify(json), { headers: { "content-type": "application/json" } });
16
+ });
17
+ });
18
+ }
19
+ function getFederationInstance() {
20
+ if (mfInstance) return mfInstance;
21
+ const existing = getInstance();
22
+ if (existing) {
23
+ mfInstance = existing;
24
+ setGlobalFederationInstance(mfInstance);
25
+ patchManifestFetchForSsrPublicPath(mfInstance);
26
+ return mfInstance;
27
+ }
28
+ mfInstance = createInstance({
29
+ name: "host",
30
+ remotes: []
31
+ });
32
+ setGlobalFederationInstance(mfInstance);
33
+ patchManifestFetchForSsrPublicPath(mfInstance);
34
+ return mfInstance;
35
+ }
36
+ async function registerRemote(opts) {
37
+ const instance = getFederationInstance();
38
+ const inferType = () => {
39
+ if (opts.type) return opts.type;
40
+ if (opts.entry.endsWith("/mf-manifest.json")) return "manifest";
41
+ if (opts.entry.endsWith("/remoteEntry.js")) return "script";
42
+ return typeof window === "undefined" ? "script" : "manifest";
43
+ };
44
+ const remoteType = inferType();
45
+ instance.registerRemotes([{
46
+ name: opts.name,
47
+ entry: opts.entry,
48
+ type: remoteType
49
+ }]);
50
+ }
51
+ async function loadRemoteModule(specifier, options) {
52
+ const instance = getFederationInstance();
53
+ if (typeof window === "undefined") await instance.initializeSharing?.("default");
54
+ const mod = await instance.loadRemote(specifier, options);
55
+ if (!mod) throw new Error(`Failed to load remote module: ${specifier}`);
56
+ return mod;
57
+ }
58
+ async function ensureNodeRuntimePlugin() {
59
+ const instance = getFederationInstance();
60
+ if (typeof window !== "undefined") return;
61
+ if (instance.__nodeRuntimePluginLoaded) return;
62
+ const mod = await import("@module-federation/node/runtimePlugin");
63
+ const factory = mod?.default ?? mod;
64
+ const plugin = typeof factory === "function" ? factory() : null;
65
+ if (plugin) instance.registerPlugins([plugin]);
66
+ instance.__nodeRuntimePluginLoaded = true;
67
+ }
68
+
69
+ //#endregion
70
+ export { ensureNodeRuntimePlugin, getFederationInstance, loadRemoteModule, patchManifestFetchForSsrPublicPath, registerRemote };
71
+ //# sourceMappingURL=mf.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mf.mjs","names":[],"sources":["../src/mf.ts"],"sourcesContent":["import { createInstance, getInstance } from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\n\ntype FederationInstance = ReturnType<typeof createInstance>;\n\nlet mfInstance: FederationInstance | null = null;\n\nexport function patchManifestFetchForSsrPublicPath(mf: FederationInstance): void {\n if (!mf || !(mf as any).loaderHook?.lifecycle?.fetch?.on) return;\n if ((mf as any).__everythingDevPatchedManifestFetch === true) return;\n (mf as any).__everythingDevPatchedManifestFetch = true;\n\n (mf as any).loaderHook.lifecycle.fetch.on((url: unknown, init: unknown) => {\n if (typeof url !== \"string\" || !url.endsWith(\"/mf-manifest.json\")) {\n return;\n }\n return fetch(url, init as any)\n .then((res) => res.json())\n .then((json: any) => {\n json.metaData = json.metaData ?? {};\n json.metaData.ssrPublicPath =\n json.metaData.ssrPublicPath ?? url.replace(/\\/mf-manifest\\.json$/, \"/\");\n return new Response(JSON.stringify(json), {\n headers: { \"content-type\": \"application/json\" },\n });\n });\n });\n}\n\nexport function getFederationInstance(): FederationInstance {\n if (mfInstance) return mfInstance;\n\n const existing = getInstance();\n if (existing) {\n mfInstance = existing as FederationInstance;\n setGlobalFederationInstance(mfInstance as any);\n patchManifestFetchForSsrPublicPath(mfInstance);\n return mfInstance;\n }\n\n mfInstance = createInstance({\n name: \"host\",\n remotes: [],\n }) as FederationInstance;\n setGlobalFederationInstance(mfInstance as any);\n patchManifestFetchForSsrPublicPath(mfInstance);\n return mfInstance;\n}\n\nexport async function registerRemote(opts: {\n name: string;\n entry: string;\n type?: \"manifest\" | \"script\";\n}): Promise<void> {\n const instance = getFederationInstance();\n\n const inferType = (): \"manifest\" | \"script\" => {\n if (opts.type) return opts.type;\n if (opts.entry.endsWith(\"/mf-manifest.json\")) return \"manifest\";\n if (opts.entry.endsWith(\"/remoteEntry.js\")) return \"script\";\n return typeof window === \"undefined\" ? \"script\" : \"manifest\";\n };\n\n const remoteType = inferType();\n\n instance.registerRemotes([\n {\n name: opts.name,\n entry: opts.entry,\n type: remoteType,\n },\n ]);\n}\n\nexport async function loadRemoteModule<T>(\n specifier: string,\n options?: { loadFactory?: boolean; from?: \"build\" | \"runtime\" },\n): Promise<T> {\n const instance = getFederationInstance();\n\n const isServer = typeof window === \"undefined\";\n if (isServer) {\n await (instance as any).initializeSharing?.(\"default\");\n }\n\n const mod = await instance.loadRemote<T>(specifier, options as any);\n if (!mod) {\n throw new Error(`Failed to load remote module: ${specifier}`);\n }\n return mod;\n}\n\nexport async function ensureNodeRuntimePlugin(): Promise<void> {\n const instance = getFederationInstance();\n if (typeof window !== \"undefined\") return;\n if ((instance as any).__nodeRuntimePluginLoaded) return;\n\n const mod: any = await import(\"@module-federation/node/runtimePlugin\");\n const factory = mod?.default ?? mod;\n const plugin = typeof factory === \"function\" ? factory() : null;\n if (plugin) {\n instance.registerPlugins([plugin]);\n }\n (instance as any).__nodeRuntimePluginLoaded = true;\n}\n"],"mappings":";;;;AAKA,IAAI,aAAwC;AAE5C,SAAgB,mCAAmC,IAA8B;AAC/E,KAAI,CAAC,MAAM,CAAE,GAAW,YAAY,WAAW,OAAO,GAAI;AAC1D,KAAK,GAAW,wCAAwC,KAAM;AAC9D,CAAC,GAAW,sCAAsC;AAElD,CAAC,GAAW,WAAW,UAAU,MAAM,IAAI,KAAc,SAAkB;AACzE,MAAI,OAAO,QAAQ,YAAY,CAAC,IAAI,SAAS,oBAAoB,CAC/D;AAEF,SAAO,MAAM,KAAK,KAAY,CAC3B,MAAM,QAAQ,IAAI,MAAM,CAAC,CACzB,MAAM,SAAc;AACnB,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