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,251 @@
1
+ import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, relative, sep } from "node:path";
3
+ import { glob } from "glob";
4
+
5
+ const FRAMEWORK_PACKAGES = ["every-plugin", "everything-dev"] as const;
6
+
7
+ type PackageJson = Record<string, unknown>;
8
+
9
+ type NormalizationSpec = {
10
+ rootCatalog: Record<string, string>;
11
+ frameworkVersions: Record<string, string>;
12
+ };
13
+
14
+ type NormalizeManifestOptions = {
15
+ resolveCatalogRefs: boolean;
16
+ excludeFrameworkWorkspaces?: boolean;
17
+ removeWorkspaceDeps?: string[];
18
+ removeWorkspaces?: boolean;
19
+ removePublishScripts?: boolean;
20
+ };
21
+
22
+ export type NormalizeTreeOptions = NormalizeManifestOptions & {
23
+ sourceRootDir: string;
24
+ targetDir: string;
25
+ };
26
+
27
+ function readJson<T>(filePath: string): T {
28
+ return JSON.parse(readFileSync(filePath, "utf-8")) as T;
29
+ }
30
+
31
+ function extractExactVersion(input: string | undefined): string | null {
32
+ if (!input) return null;
33
+ const match = input.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?/);
34
+ return match ? match[0] : null;
35
+ }
36
+
37
+ function writeJson(filePath: string, value: PackageJson) {
38
+ writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
39
+ }
40
+
41
+ export function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {
42
+ const rootPackage = readJson<PackageJson>(join(sourceRootDir, "package.json"));
43
+ const rootCatalog = {
44
+ ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??
45
+ {}) as Record<string, string>),
46
+ };
47
+ const frameworkVersions: Record<string, string> = {};
48
+
49
+ for (const packageName of FRAMEWORK_PACKAGES) {
50
+ const sourcePackagePath = join(sourceRootDir, "packages", packageName, "package.json");
51
+ const localPackagePath = join(import.meta.dirname, "..", "..", packageName, "package.json");
52
+ const packageVersion = existsSync(sourcePackagePath)
53
+ ? readJson<{ version: string }>(sourcePackagePath).version
54
+ : existsSync(localPackagePath)
55
+ ? readJson<{ version: string }>(localPackagePath).version
56
+ : extractExactVersion(rootCatalog[packageName]);
57
+
58
+ if (!packageVersion) {
59
+ throw new Error(`Could not resolve version for ${packageName}`);
60
+ }
61
+
62
+ frameworkVersions[packageName] = packageVersion;
63
+ rootCatalog[packageName] = `^${packageVersion}`;
64
+ }
65
+
66
+ return { rootCatalog, frameworkVersions };
67
+ }
68
+
69
+ function normalizeDependencyMap(
70
+ map: Record<string, string>,
71
+ spec: NormalizationSpec,
72
+ options: NormalizeManifestOptions,
73
+ ) {
74
+ let modified = false;
75
+
76
+ for (const [name, version] of Object.entries(map)) {
77
+ if (version === "workspace:*") {
78
+ const frameworkVersion = spec.frameworkVersions[name];
79
+ if (frameworkVersion) {
80
+ map[name] = `^${frameworkVersion}`;
81
+ modified = true;
82
+ continue;
83
+ }
84
+
85
+ if (options.removeWorkspaceDeps?.includes(name)) {
86
+ delete map[name];
87
+ modified = true;
88
+ }
89
+ continue;
90
+ }
91
+
92
+ if (options.resolveCatalogRefs && version.startsWith("catalog:")) {
93
+ const resolved = spec.rootCatalog[name];
94
+ if (resolved) {
95
+ map[name] = resolved;
96
+ modified = true;
97
+ }
98
+ }
99
+ }
100
+
101
+ return modified;
102
+ }
103
+
104
+ export function normalizePackageManifest(
105
+ pkg: PackageJson,
106
+ spec: NormalizationSpec,
107
+ options: NormalizeManifestOptions,
108
+ ) {
109
+ let modified = false;
110
+
111
+ for (const depField of ["dependencies", "devDependencies", "peerDependencies"]) {
112
+ const deps = pkg[depField];
113
+ if (!deps || typeof deps !== "object") continue;
114
+ if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {
115
+ modified = true;
116
+ }
117
+ }
118
+
119
+ if (pkg.workspaces && typeof pkg.workspaces === "object") {
120
+ const workspaces = pkg.workspaces as {
121
+ packages?: string[];
122
+ catalog?: Record<string, string>;
123
+ };
124
+
125
+ if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {
126
+ const nextPackages = workspaces.packages.filter(
127
+ (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),
128
+ );
129
+ if (nextPackages.length !== workspaces.packages.length) {
130
+ workspaces.packages = nextPackages;
131
+ modified = true;
132
+ }
133
+ }
134
+
135
+ if (workspaces.catalog && typeof workspaces.catalog === "object") {
136
+ for (const [name, version] of Object.entries(workspaces.catalog)) {
137
+ const resolved = spec.rootCatalog[name];
138
+ if (resolved && resolved !== version) {
139
+ workspaces.catalog[name] = resolved;
140
+ modified = true;
141
+ continue;
142
+ }
143
+
144
+ if (version === "workspace:*" && spec.frameworkVersions[name]) {
145
+ workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;
146
+ modified = true;
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ if (options.removeWorkspaces && "workspaces" in pkg) {
153
+ delete pkg.workspaces;
154
+ modified = true;
155
+ }
156
+
157
+ if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === "object") {
158
+ const scripts = pkg.scripts as Record<string, string>;
159
+ let scriptsModified = false;
160
+ for (const key of ["prepublishOnly", "prepack", "prepare", "postpack"]) {
161
+ if (key in scripts) {
162
+ delete scripts[key];
163
+ scriptsModified = true;
164
+ }
165
+ }
166
+ if (scriptsModified) {
167
+ modified = true;
168
+ if (Object.keys(scripts).length === 0) {
169
+ delete pkg.scripts;
170
+ }
171
+ }
172
+ }
173
+
174
+ return modified;
175
+ }
176
+
177
+ export async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {
178
+ const spec = loadManifestNormalizationSpec(opts.sourceRootDir);
179
+ const files = await glob("**/package.json", {
180
+ cwd: opts.targetDir,
181
+ nodir: true,
182
+ dot: false,
183
+ absolute: true,
184
+ ignore: ["**/node_modules/**"],
185
+ });
186
+
187
+ const updatedFiles: string[] = [];
188
+
189
+ for (const filePath of files) {
190
+ const pkg = readJson<PackageJson>(filePath);
191
+ if (normalizePackageManifest(pkg, spec, opts)) {
192
+ writeJson(filePath, pkg);
193
+ updatedFiles.push(filePath);
194
+ }
195
+ }
196
+
197
+ return updatedFiles;
198
+ }
199
+
200
+ function shouldCopyPackageFile(sourceDir: string, filePath: string) {
201
+ const relPath = relative(sourceDir, filePath);
202
+ if (!relPath) return true;
203
+ const segments = relPath.split(sep);
204
+ return !segments.includes("node_modules") && !segments.includes("tests");
205
+ }
206
+
207
+ export function stageReleasePackage(opts: {
208
+ repoRoot: string;
209
+ packageName: string;
210
+ outDir: string;
211
+ }) {
212
+ const sourceDir = join(opts.repoRoot, "packages", opts.packageName);
213
+
214
+ rmSync(opts.outDir, { recursive: true, force: true });
215
+ mkdirSync(dirname(opts.outDir), { recursive: true });
216
+ cpSync(sourceDir, opts.outDir, {
217
+ recursive: true,
218
+ filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),
219
+ });
220
+ rmSync(join(opts.outDir, "tests"), { recursive: true, force: true });
221
+
222
+ const packageJsonPath = join(opts.outDir, "package.json");
223
+ const spec = loadManifestNormalizationSpec(opts.repoRoot);
224
+ const pkg = readJson<PackageJson>(packageJsonPath);
225
+
226
+ normalizePackageManifest(pkg, spec, {
227
+ resolveCatalogRefs: true,
228
+ removeWorkspaces: true,
229
+ removePublishScripts: true,
230
+ });
231
+
232
+ writeJson(packageJsonPath, pkg);
233
+ }
234
+
235
+ export function stageReleasePackages(opts: {
236
+ repoRoot: string;
237
+ outDir: string;
238
+ packageNames?: string[];
239
+ }) {
240
+ const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];
241
+ rmSync(opts.outDir, { recursive: true, force: true });
242
+ mkdirSync(opts.outDir, { recursive: true });
243
+
244
+ for (const packageName of packageNames) {
245
+ stageReleasePackage({
246
+ repoRoot: opts.repoRoot,
247
+ packageName,
248
+ outDir: join(opts.outDir, packageName),
249
+ });
250
+ }
251
+ }
package/src/mf.ts ADDED
@@ -0,0 +1,105 @@
1
+ import { createInstance, getInstance } from "@module-federation/enhanced/runtime";
2
+ import { setGlobalFederationInstance } from "@module-federation/runtime-core";
3
+
4
+ type FederationInstance = ReturnType<typeof createInstance>;
5
+
6
+ let mfInstance: FederationInstance | null = null;
7
+
8
+ export function patchManifestFetchForSsrPublicPath(mf: FederationInstance): void {
9
+ if (!mf || !(mf as any).loaderHook?.lifecycle?.fetch?.on) return;
10
+ if ((mf as any).__everythingDevPatchedManifestFetch === true) return;
11
+ (mf as any).__everythingDevPatchedManifestFetch = true;
12
+
13
+ (mf as any).loaderHook.lifecycle.fetch.on((url: unknown, init: unknown) => {
14
+ if (typeof url !== "string" || !url.endsWith("/mf-manifest.json")) {
15
+ return;
16
+ }
17
+ return fetch(url, init as any)
18
+ .then((res) => res.json())
19
+ .then((json: any) => {
20
+ json.metaData = json.metaData ?? {};
21
+ json.metaData.ssrPublicPath =
22
+ json.metaData.ssrPublicPath ?? url.replace(/\/mf-manifest\.json$/, "/");
23
+ return new Response(JSON.stringify(json), {
24
+ headers: { "content-type": "application/json" },
25
+ });
26
+ });
27
+ });
28
+ }
29
+
30
+ export function getFederationInstance(): FederationInstance {
31
+ if (mfInstance) return mfInstance;
32
+
33
+ const existing = getInstance();
34
+ if (existing) {
35
+ mfInstance = existing as FederationInstance;
36
+ setGlobalFederationInstance(mfInstance as any);
37
+ patchManifestFetchForSsrPublicPath(mfInstance);
38
+ return mfInstance;
39
+ }
40
+
41
+ mfInstance = createInstance({
42
+ name: "host",
43
+ remotes: [],
44
+ }) as FederationInstance;
45
+ setGlobalFederationInstance(mfInstance as any);
46
+ patchManifestFetchForSsrPublicPath(mfInstance);
47
+ return mfInstance;
48
+ }
49
+
50
+ export async function registerRemote(opts: {
51
+ name: string;
52
+ entry: string;
53
+ type?: "manifest" | "script";
54
+ }): Promise<void> {
55
+ const instance = getFederationInstance();
56
+
57
+ const inferType = (): "manifest" | "script" => {
58
+ if (opts.type) return opts.type;
59
+ if (opts.entry.endsWith("/mf-manifest.json")) return "manifest";
60
+ if (opts.entry.endsWith("/remoteEntry.js")) return "script";
61
+ return typeof window === "undefined" ? "script" : "manifest";
62
+ };
63
+
64
+ const remoteType = inferType();
65
+
66
+ instance.registerRemotes([
67
+ {
68
+ name: opts.name,
69
+ entry: opts.entry,
70
+ type: remoteType,
71
+ },
72
+ ]);
73
+ }
74
+
75
+ export async function loadRemoteModule<T>(
76
+ specifier: string,
77
+ options?: { loadFactory?: boolean; from?: "build" | "runtime" },
78
+ ): Promise<T> {
79
+ const instance = getFederationInstance();
80
+
81
+ const isServer = typeof window === "undefined";
82
+ if (isServer) {
83
+ await (instance as any).initializeSharing?.("default");
84
+ }
85
+
86
+ const mod = await instance.loadRemote<T>(specifier, options as any);
87
+ if (!mod) {
88
+ throw new Error(`Failed to load remote module: ${specifier}`);
89
+ }
90
+ return mod;
91
+ }
92
+
93
+ export async function ensureNodeRuntimePlugin(): Promise<void> {
94
+ const instance = getFederationInstance();
95
+ if (typeof window !== "undefined") return;
96
+ if ((instance as any).__nodeRuntimePluginLoaded) return;
97
+
98
+ const mod: any = await import("@module-federation/node/runtimePlugin");
99
+ const factory = mod?.default ?? mod;
100
+ const plugin = typeof factory === "function" ? factory() : null;
101
+ if (plugin) {
102
+ instance.registerPlugins([plugin]);
103
+ }
104
+ (instance as any).__nodeRuntimePluginLoaded = true;
105
+ }
@@ -0,0 +1,284 @@
1
+ import { spawn } from "node:child_process";
2
+ import { generateKeyPairSync } from "node:crypto";
3
+ import { Effect } from "effect";
4
+
5
+ export interface NearTransactionConfig {
6
+ account: string;
7
+ contract: string;
8
+ method: string;
9
+ argsBase64: string;
10
+ network?: "mainnet" | "testnet";
11
+ privateKey?: string;
12
+ gas?: string;
13
+ deposit?: string;
14
+ }
15
+
16
+ export interface NearTransactionResult {
17
+ success: boolean;
18
+ txHash?: string;
19
+ error?: string;
20
+ }
21
+
22
+ export interface NearKeyPair {
23
+ publicKey: string;
24
+ privateKey: string;
25
+ }
26
+
27
+ export interface FunctionCallAccessKeyConfig {
28
+ account: string;
29
+ contract: string;
30
+ allowance: string;
31
+ functionNames: string[];
32
+ network?: "mainnet" | "testnet";
33
+ }
34
+
35
+ const NEAR_CLI_VERSION = "0.23.5";
36
+ const INSTALLER_URL = `https://github.com/near/near-cli-rs/releases/download/v${NEAR_CLI_VERSION}/near-cli-rs-installer.sh`;
37
+ const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
38
+
39
+ export class NearCliNotFoundError extends Error {
40
+ readonly _tag = "NearCliNotFoundError";
41
+ constructor() {
42
+ super("NEAR CLI not found");
43
+ }
44
+ }
45
+
46
+ export class NearCliInstallError extends Error {
47
+ readonly _tag = "NearCliInstallError";
48
+ constructor(message: string) {
49
+ super(`Failed to install NEAR CLI: ${message}`);
50
+ }
51
+ }
52
+
53
+ export class NearTransactionError extends Error {
54
+ readonly _tag = "NearTransactionError";
55
+ }
56
+
57
+ function base64UrlToBytes(input: string): Uint8Array {
58
+ const normalized = input.replace(/-/g, "+").replace(/_/g, "/");
59
+ return new Uint8Array(Buffer.from(normalized, "base64"));
60
+ }
61
+
62
+ function base58Encode(input: Uint8Array): string {
63
+ if (input.length === 0) return "";
64
+
65
+ const digits: number[] = [0];
66
+ for (const byte of input) {
67
+ let carry = byte;
68
+ for (let i = 0; i < digits.length; i++) {
69
+ carry += digits[i]! << 8;
70
+ digits[i] = carry % 58;
71
+ carry = Math.floor(carry / 58);
72
+ }
73
+ while (carry > 0) {
74
+ digits.push(carry % 58);
75
+ carry = Math.floor(carry / 58);
76
+ }
77
+ }
78
+
79
+ let output = "";
80
+ for (const byte of input) {
81
+ if (byte === 0) output += BASE58_ALPHABET[0];
82
+ else break;
83
+ }
84
+
85
+ for (let i = digits.length - 1; i >= 0; i--) {
86
+ output += BASE58_ALPHABET[digits[i]!]!;
87
+ }
88
+
89
+ return output;
90
+ }
91
+
92
+ export function generateNearKeyPair(): NearKeyPair {
93
+ const { publicKey, privateKey } = generateKeyPairSync("ed25519");
94
+ const publicJwk = publicKey.export({ format: "jwk" }) as JsonWebKey;
95
+ const privateJwk = privateKey.export({ format: "jwk" }) as JsonWebKey;
96
+
97
+ if (!publicJwk.x || !privateJwk.d) {
98
+ throw new Error("Failed to generate NEAR keypair");
99
+ }
100
+
101
+ const publicBytes = base64UrlToBytes(publicJwk.x);
102
+ const privateSeed = base64UrlToBytes(privateJwk.d);
103
+ const secretBytes = new Uint8Array(privateSeed.length + publicBytes.length);
104
+ secretBytes.set(privateSeed, 0);
105
+ secretBytes.set(publicBytes, privateSeed.length);
106
+
107
+ return {
108
+ publicKey: `ed25519:${base58Encode(publicBytes)}`,
109
+ privateKey: `ed25519:${base58Encode(secretBytes)}`,
110
+ };
111
+ }
112
+
113
+ const checkNearCliInstalled = Effect.tryPromise({
114
+ try: async () => {
115
+ return await new Promise<boolean>((resolve) => {
116
+ const proc = spawn("near", ["--version"], { stdio: "pipe" });
117
+ proc.on("close", (code) => resolve(code === 0));
118
+ proc.on("error", () => resolve(false));
119
+ });
120
+ },
121
+ catch: () => new Error("Failed to check NEAR CLI"),
122
+ });
123
+
124
+ const installNearCli = Effect.tryPromise({
125
+ try: async () => {
126
+ return await new Promise<void>((resolve, reject) => {
127
+ const proc = spawn(
128
+ "sh",
129
+ ["-c", `curl --proto '=https' --tlsv1.2 -LsSf ${INSTALLER_URL} | sh`],
130
+ {
131
+ stdio: "inherit",
132
+ },
133
+ );
134
+
135
+ proc.on("close", (code) => {
136
+ if (code === 0) resolve();
137
+ else reject(new NearCliInstallError(`Installer exited with code ${code}`));
138
+ });
139
+ proc.on("error", (err) => reject(new NearCliInstallError(err.message)));
140
+ });
141
+ },
142
+ catch: (error) => error as Error,
143
+ });
144
+
145
+ async function runNearCommand(args: string[]): Promise<void> {
146
+ await new Promise<void>((resolve, reject) => {
147
+ const proc = spawn("near", args, {
148
+ stdio: "inherit",
149
+ });
150
+
151
+ proc.on("close", (code) => {
152
+ if (code === 0) resolve();
153
+ else reject(new Error(`near ${args.join(" ")} failed with exit code ${code}`));
154
+ });
155
+
156
+ proc.on("error", (err) => reject(new Error(err.message)));
157
+ });
158
+ }
159
+
160
+ export const ensureNearCli = Effect.gen(function* () {
161
+ const isInstalled = yield* checkNearCliInstalled;
162
+ if (isInstalled) return;
163
+
164
+ if (process.env.BOS_INSTALL_NEAR_CLI === "true") {
165
+ yield* installNearCli;
166
+ return;
167
+ }
168
+
169
+ console.log();
170
+ console.log(" NEAR CLI not found");
171
+
172
+ console.log();
173
+ console.log(` To install manually: curl --proto '=https' --tlsv1.2 -LsSf ${INSTALLER_URL} | sh`);
174
+ console.log();
175
+ yield* Effect.fail(new NearCliNotFoundError());
176
+ });
177
+
178
+ export const executeTransaction = (
179
+ config: NearTransactionConfig,
180
+ ): Effect.Effect<NearTransactionResult, Error> =>
181
+ Effect.gen(function* () {
182
+ const gas = (config.gas || "300Tgas").replace(/\s+/g, "");
183
+ const deposit = (config.deposit || "0NEAR").replace(/\s+/g, "");
184
+ const network = config.network || (config.account.endsWith(".testnet") ? "testnet" : "mainnet");
185
+
186
+ const args = [
187
+ "contract",
188
+ "call-function",
189
+ "as-transaction",
190
+ config.contract,
191
+ config.method,
192
+ "base64-args",
193
+ config.argsBase64,
194
+ "prepaid-gas",
195
+ gas,
196
+ "attached-deposit",
197
+ deposit,
198
+ "sign-as",
199
+ config.account,
200
+ "network-config",
201
+ network,
202
+ ];
203
+
204
+ if (config.privateKey) {
205
+ args.push("sign-with-plaintext-private-key", config.privateKey, "send");
206
+ } else {
207
+ args.push("sign-with-keychain", "send");
208
+ }
209
+
210
+ const output = yield* Effect.tryPromise({
211
+ try: async () => {
212
+ return await new Promise<string>((resolve, reject) => {
213
+ const proc = spawn("near", args, { stdio: ["inherit", "pipe", "pipe"] });
214
+
215
+ let stdout = "";
216
+ let stderr = "";
217
+
218
+ proc.stdout?.on("data", (data) => {
219
+ const text = data.toString();
220
+ stdout += text;
221
+ process.stdout.write(text);
222
+ });
223
+
224
+ proc.stderr?.on("data", (data) => {
225
+ const text = data.toString();
226
+ stderr += text;
227
+ });
228
+
229
+ proc.on("close", (code) => {
230
+ const combined = `${stdout}\n${stderr}`;
231
+ const txHashMatch =
232
+ combined.match(/Transaction ID:\s*([A-Za-z0-9]+)/i) ||
233
+ combined.match(/([A-HJ-NP-Za-km-z1-9]{43,44})/);
234
+ const softSuccess =
235
+ Boolean(txHashMatch?.[1]) &&
236
+ /CodeDoesNotExist/i.test(combined) &&
237
+ /Transaction failed/i.test(combined);
238
+
239
+ if (code === 0 || softSuccess) resolve(combined);
240
+ else reject(new NearTransactionError(stderr || `Transaction failed with code ${code}`));
241
+ });
242
+
243
+ proc.on("error", (err) => reject(new NearTransactionError(err.message)));
244
+ });
245
+ },
246
+ catch: (error) => error as Error,
247
+ });
248
+
249
+ const txHashMatch =
250
+ output.match(/Transaction ID:\s*([A-Za-z0-9]+)/i) ||
251
+ output.match(/([A-HJ-NP-Za-km-z1-9]{43,44})/);
252
+
253
+ return {
254
+ success: true,
255
+ txHash: txHashMatch?.[1] || "unknown",
256
+ };
257
+ });
258
+
259
+ export async function addFunctionCallAccessKey(
260
+ config: FunctionCallAccessKeyConfig,
261
+ ): Promise<NearKeyPair> {
262
+ const keyPair = generateNearKeyPair();
263
+ const args = [
264
+ "account",
265
+ "add-key",
266
+ config.account,
267
+ "grant-function-call-access",
268
+ "--allowance",
269
+ config.allowance,
270
+ "--contract-account-id",
271
+ config.contract,
272
+ "--function-names",
273
+ config.functionNames.join(", "),
274
+ "use-manually-provided-public-key",
275
+ keyPair.publicKey,
276
+ "network-config",
277
+ config.network || (config.account.endsWith(".testnet") ? "testnet" : "mainnet"),
278
+ "sign-with-keychain",
279
+ "send",
280
+ ];
281
+
282
+ await runNearCommand(args);
283
+ return keyPair;
284
+ }
package/src/network.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function getNetworkIdForAccount(account: string): "mainnet" | "testnet" {
2
+ return account.endsWith(".testnet") ? "testnet" : "mainnet";
3
+ }