moonwall 1.0.0-dev.0

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 (301) hide show
  1. package/LICENSE +681 -0
  2. package/README.md +54 -0
  3. package/config_schema.json +811 -0
  4. package/dist/api/constants/accounts.d.ts +36 -0
  5. package/dist/api/constants/accounts.d.ts.map +1 -0
  6. package/dist/api/constants/accounts.js +67 -0
  7. package/dist/api/constants/chain.d.ts +134 -0
  8. package/dist/api/constants/chain.d.ts.map +1 -0
  9. package/dist/api/constants/chain.js +149 -0
  10. package/dist/api/constants/index.d.ts +4 -0
  11. package/dist/api/constants/index.d.ts.map +1 -0
  12. package/dist/api/constants/index.js +3 -0
  13. package/dist/api/constants/smartContract.d.ts +29 -0
  14. package/dist/api/constants/smartContract.d.ts.map +1 -0
  15. package/dist/api/constants/smartContract.js +118 -0
  16. package/dist/api/testing/blocks.d.ts +59 -0
  17. package/dist/api/testing/blocks.d.ts.map +1 -0
  18. package/dist/api/testing/blocks.js +147 -0
  19. package/dist/api/testing/contracts.d.ts +5 -0
  20. package/dist/api/testing/contracts.d.ts.map +1 -0
  21. package/dist/api/testing/contracts.js +32 -0
  22. package/dist/api/testing/ethers.d.ts +3 -0
  23. package/dist/api/testing/ethers.d.ts.map +1 -0
  24. package/dist/api/testing/ethers.js +38 -0
  25. package/dist/api/testing/events.d.ts +12 -0
  26. package/dist/api/testing/events.d.ts.map +1 -0
  27. package/dist/api/testing/events.js +23 -0
  28. package/dist/api/testing/extrinsics.d.ts +5 -0
  29. package/dist/api/testing/extrinsics.d.ts.map +1 -0
  30. package/dist/api/testing/extrinsics.js +10 -0
  31. package/dist/api/testing/index.d.ts +9 -0
  32. package/dist/api/testing/index.d.ts.map +1 -0
  33. package/dist/api/testing/index.js +8 -0
  34. package/dist/api/testing/jumping.d.ts +8 -0
  35. package/dist/api/testing/jumping.d.ts.map +1 -0
  36. package/dist/api/testing/jumping.js +78 -0
  37. package/dist/api/testing/providers.d.ts +18 -0
  38. package/dist/api/testing/providers.d.ts.map +1 -0
  39. package/dist/api/testing/providers.js +34 -0
  40. package/dist/api/testing/viem.d.ts +139 -0
  41. package/dist/api/testing/viem.d.ts.map +1 -0
  42. package/dist/api/testing/viem.js +247 -0
  43. package/dist/api/types/config.d.ts +609 -0
  44. package/dist/api/types/config.d.ts.map +1 -0
  45. package/dist/api/types/config.js +1 -0
  46. package/dist/api/types/context.d.ts +125 -0
  47. package/dist/api/types/context.d.ts.map +1 -0
  48. package/dist/api/types/context.js +1 -0
  49. package/dist/api/types/contracts.d.ts +66 -0
  50. package/dist/api/types/contracts.d.ts.map +1 -0
  51. package/dist/api/types/contracts.js +1 -0
  52. package/dist/api/types/eth.d.ts +3 -0
  53. package/dist/api/types/eth.d.ts.map +1 -0
  54. package/dist/api/types/eth.js +1 -0
  55. package/dist/api/types/foundations.d.ts +11 -0
  56. package/dist/api/types/foundations.d.ts.map +1 -0
  57. package/dist/api/types/foundations.js +1 -0
  58. package/dist/api/types/helpers.d.ts +7 -0
  59. package/dist/api/types/helpers.d.ts.map +1 -0
  60. package/dist/api/types/helpers.js +1 -0
  61. package/dist/api/types/index.d.ts +8 -0
  62. package/dist/api/types/index.d.ts.map +1 -0
  63. package/dist/api/types/index.js +7 -0
  64. package/dist/api/types/runner.d.ts +490 -0
  65. package/dist/api/types/runner.d.ts.map +1 -0
  66. package/dist/api/types/runner.js +1 -0
  67. package/dist/cli/cmds/components/LogViewer.d.ts +17 -0
  68. package/dist/cli/cmds/components/LogViewer.d.ts.map +1 -0
  69. package/dist/cli/cmds/components/LogViewer.js +171 -0
  70. package/dist/cli/cmds/entrypoint.d.ts +6 -0
  71. package/dist/cli/cmds/entrypoint.d.ts.map +1 -0
  72. package/dist/cli/cmds/entrypoint.js +192 -0
  73. package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.d.ts +2 -0
  74. package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.d.ts.map +1 -0
  75. package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.js +117 -0
  76. package/dist/cli/cmds/interactiveCmds/devIntCmds.d.ts +2 -0
  77. package/dist/cli/cmds/interactiveCmds/devIntCmds.d.ts.map +1 -0
  78. package/dist/cli/cmds/interactiveCmds/devIntCmds.js +103 -0
  79. package/dist/cli/cmds/interactiveCmds/index.d.ts +4 -0
  80. package/dist/cli/cmds/interactiveCmds/index.d.ts.map +1 -0
  81. package/dist/cli/cmds/interactiveCmds/index.js +3 -0
  82. package/dist/cli/cmds/interactiveCmds/zombieIntCmds.d.ts +2 -0
  83. package/dist/cli/cmds/interactiveCmds/zombieIntCmds.d.ts.map +1 -0
  84. package/dist/cli/cmds/interactiveCmds/zombieIntCmds.js +32 -0
  85. package/dist/cli/cmds/main.d.ts +2 -0
  86. package/dist/cli/cmds/main.d.ts.map +1 -0
  87. package/dist/cli/cmds/main.js +336 -0
  88. package/dist/cli/cmds/runNetwork.d.ts +3 -0
  89. package/dist/cli/cmds/runNetwork.d.ts.map +1 -0
  90. package/dist/cli/cmds/runNetwork.js +292 -0
  91. package/dist/cli/cmds/runTests.d.ts +12 -0
  92. package/dist/cli/cmds/runTests.d.ts.map +1 -0
  93. package/dist/cli/cmds/runTests.js +257 -0
  94. package/dist/cli/internal/cmdFunctions/downloader.d.ts +4 -0
  95. package/dist/cli/internal/cmdFunctions/downloader.d.ts.map +1 -0
  96. package/dist/cli/internal/cmdFunctions/downloader.js +49 -0
  97. package/dist/cli/internal/cmdFunctions/fetchArtifact.d.ts +10 -0
  98. package/dist/cli/internal/cmdFunctions/fetchArtifact.d.ts.map +1 -0
  99. package/dist/cli/internal/cmdFunctions/fetchArtifact.js +145 -0
  100. package/dist/cli/internal/cmdFunctions/index.d.ts +5 -0
  101. package/dist/cli/internal/cmdFunctions/index.d.ts.map +1 -0
  102. package/dist/cli/internal/cmdFunctions/index.js +4 -0
  103. package/dist/cli/internal/cmdFunctions/initialisation.d.ts +20 -0
  104. package/dist/cli/internal/cmdFunctions/initialisation.d.ts.map +1 -0
  105. package/dist/cli/internal/cmdFunctions/initialisation.js +150 -0
  106. package/dist/cli/internal/cmdFunctions/tempLogs.d.ts +3 -0
  107. package/dist/cli/internal/cmdFunctions/tempLogs.d.ts.map +1 -0
  108. package/dist/cli/internal/cmdFunctions/tempLogs.js +37 -0
  109. package/dist/cli/internal/commandParsers.d.ts +59 -0
  110. package/dist/cli/internal/commandParsers.d.ts.map +1 -0
  111. package/dist/cli/internal/commandParsers.js +305 -0
  112. package/dist/cli/internal/deriveTestIds.d.ts +8 -0
  113. package/dist/cli/internal/deriveTestIds.d.ts.map +1 -0
  114. package/dist/cli/internal/deriveTestIds.js +123 -0
  115. package/dist/cli/internal/effect/index.d.ts +6 -0
  116. package/dist/cli/internal/effect/index.d.ts.map +1 -0
  117. package/dist/cli/internal/effect/index.js +5 -0
  118. package/dist/cli/internal/fileCheckers.d.ts +11 -0
  119. package/dist/cli/internal/fileCheckers.d.ts.map +1 -0
  120. package/dist/cli/internal/fileCheckers.js +165 -0
  121. package/dist/cli/internal/foundations/index.d.ts +4 -0
  122. package/dist/cli/internal/foundations/index.d.ts.map +1 -0
  123. package/dist/cli/internal/foundations/index.js +4 -0
  124. package/dist/cli/internal/index.d.ts +12 -0
  125. package/dist/cli/internal/index.d.ts.map +1 -0
  126. package/dist/cli/internal/index.js +11 -0
  127. package/dist/cli/internal/launcherCommon.d.ts +4 -0
  128. package/dist/cli/internal/launcherCommon.d.ts.map +1 -0
  129. package/dist/cli/internal/launcherCommon.js +130 -0
  130. package/dist/cli/internal/localNode.d.ts +16 -0
  131. package/dist/cli/internal/localNode.d.ts.map +1 -0
  132. package/dist/cli/internal/localNode.js +362 -0
  133. package/dist/cli/internal/logging.d.ts +2 -0
  134. package/dist/cli/internal/logging.d.ts.map +1 -0
  135. package/dist/cli/internal/logging.js +26 -0
  136. package/dist/cli/internal/node.d.ts +33 -0
  137. package/dist/cli/internal/node.d.ts.map +1 -0
  138. package/dist/cli/internal/node.js +228 -0
  139. package/dist/cli/internal/processHelpers.d.ts +17 -0
  140. package/dist/cli/internal/processHelpers.d.ts.map +1 -0
  141. package/dist/cli/internal/processHelpers.js +56 -0
  142. package/dist/cli/internal/providerFactories.d.ts +48 -0
  143. package/dist/cli/internal/providerFactories.d.ts.map +1 -0
  144. package/dist/cli/internal/providerFactories.js +442 -0
  145. package/dist/cli/internal/testIdParser.d.ts +34 -0
  146. package/dist/cli/internal/testIdParser.d.ts.map +1 -0
  147. package/dist/cli/internal/testIdParser.js +167 -0
  148. package/dist/cli/lib/binariesHelpers.d.ts +15 -0
  149. package/dist/cli/lib/binariesHelpers.d.ts.map +1 -0
  150. package/dist/cli/lib/binariesHelpers.js +99 -0
  151. package/dist/cli/lib/configReader.d.ts +8 -0
  152. package/dist/cli/lib/configReader.d.ts.map +1 -0
  153. package/dist/cli/lib/configReader.js +115 -0
  154. package/dist/cli/lib/contractFunctions.d.ts +2 -0
  155. package/dist/cli/lib/contractFunctions.d.ts.map +1 -0
  156. package/dist/cli/lib/contractFunctions.js +2 -0
  157. package/dist/cli/lib/globalContext.d.ts +46 -0
  158. package/dist/cli/lib/globalContext.d.ts.map +1 -0
  159. package/dist/cli/lib/globalContext.js +710 -0
  160. package/dist/cli/lib/governanceProcedures.d.ts +27 -0
  161. package/dist/cli/lib/governanceProcedures.d.ts.map +1 -0
  162. package/dist/cli/lib/governanceProcedures.js +458 -0
  163. package/dist/cli/lib/handlers/index.d.ts +5 -0
  164. package/dist/cli/lib/handlers/index.d.ts.map +1 -0
  165. package/dist/cli/lib/handlers/index.js +5 -0
  166. package/dist/cli/lib/repoDefinitions/index.d.ts +6 -0
  167. package/dist/cli/lib/repoDefinitions/index.d.ts.map +1 -0
  168. package/dist/cli/lib/repoDefinitions/index.js +21 -0
  169. package/dist/cli/lib/repoDefinitions/moonbeam.d.ts +4 -0
  170. package/dist/cli/lib/repoDefinitions/moonbeam.d.ts.map +1 -0
  171. package/dist/cli/lib/repoDefinitions/moonbeam.js +30 -0
  172. package/dist/cli/lib/repoDefinitions/polkadot.d.ts +4 -0
  173. package/dist/cli/lib/repoDefinitions/polkadot.d.ts.map +1 -0
  174. package/dist/cli/lib/repoDefinitions/polkadot.js +11 -0
  175. package/dist/cli/lib/repoDefinitions/tanssi.d.ts +4 -0
  176. package/dist/cli/lib/repoDefinitions/tanssi.d.ts.map +1 -0
  177. package/dist/cli/lib/repoDefinitions/tanssi.js +14 -0
  178. package/dist/cli/lib/rpcFunctions.d.ts +2 -0
  179. package/dist/cli/lib/rpcFunctions.d.ts.map +1 -0
  180. package/dist/cli/lib/rpcFunctions.js +26 -0
  181. package/dist/cli/lib/runnerContext.d.ts +32 -0
  182. package/dist/cli/lib/runnerContext.d.ts.map +1 -0
  183. package/dist/cli/lib/runnerContext.js +156 -0
  184. package/dist/cli/lib/shardManager.d.ts +40 -0
  185. package/dist/cli/lib/shardManager.d.ts.map +1 -0
  186. package/dist/cli/lib/shardManager.js +80 -0
  187. package/dist/cli/lib/upgradeProcedures.d.ts +5 -0
  188. package/dist/cli/lib/upgradeProcedures.d.ts.map +1 -0
  189. package/dist/cli/lib/upgradeProcedures.js +221 -0
  190. package/dist/cli.d.ts +4 -0
  191. package/dist/cli.d.ts.map +1 -0
  192. package/dist/cli.js +3 -0
  193. package/dist/contracts/contractInteraction.d.ts +17 -0
  194. package/dist/contracts/contractInteraction.d.ts.map +1 -0
  195. package/dist/contracts/contractInteraction.js +170 -0
  196. package/dist/contracts/index.d.ts +2 -0
  197. package/dist/contracts/index.d.ts.map +1 -0
  198. package/dist/contracts/index.js +1 -0
  199. package/dist/foundations/chopsticks/handler.d.ts +3 -0
  200. package/dist/foundations/chopsticks/handler.d.ts.map +1 -0
  201. package/dist/foundations/chopsticks/handler.js +93 -0
  202. package/dist/foundations/chopsticks/helpers.d.ts +27 -0
  203. package/dist/foundations/chopsticks/helpers.d.ts.map +1 -0
  204. package/dist/foundations/chopsticks/helpers.js +133 -0
  205. package/dist/foundations/dev/handler.d.ts +3 -0
  206. package/dist/foundations/dev/handler.d.ts.map +1 -0
  207. package/dist/foundations/dev/handler.js +136 -0
  208. package/dist/foundations/dev/helpers.d.ts +27 -0
  209. package/dist/foundations/dev/helpers.d.ts.map +1 -0
  210. package/dist/foundations/dev/helpers.js +161 -0
  211. package/dist/foundations/read-only/handler.d.ts +3 -0
  212. package/dist/foundations/read-only/handler.d.ts.map +1 -0
  213. package/dist/foundations/read-only/handler.js +32 -0
  214. package/dist/foundations/zombie/handler.d.ts +3 -0
  215. package/dist/foundations/zombie/handler.d.ts.map +1 -0
  216. package/dist/foundations/zombie/handler.js +92 -0
  217. package/dist/foundations/zombie/helpers.d.ts +16 -0
  218. package/dist/foundations/zombie/helpers.d.ts.map +1 -0
  219. package/dist/foundations/zombie/helpers.js +97 -0
  220. package/dist/index.d.ts +17 -0
  221. package/dist/index.d.ts.map +1 -0
  222. package/dist/index.js +47 -0
  223. package/dist/internal/common.d.ts +3 -0
  224. package/dist/internal/common.d.ts.map +1 -0
  225. package/dist/internal/common.js +41 -0
  226. package/dist/internal/index.d.ts +4 -0
  227. package/dist/internal/index.d.ts.map +1 -0
  228. package/dist/internal/index.js +3 -0
  229. package/dist/internal/logger.d.ts +24 -0
  230. package/dist/internal/logger.d.ts.map +1 -0
  231. package/dist/internal/logger.js +66 -0
  232. package/dist/internal/logging.d.ts +7 -0
  233. package/dist/internal/logging.d.ts.map +1 -0
  234. package/dist/internal/logging.js +36 -0
  235. package/dist/moondebug.d.ts +3 -0
  236. package/dist/moondebug.d.ts.map +1 -0
  237. package/dist/moondebug.js +2 -0
  238. package/dist/services/cache/FileLock.d.ts +11 -0
  239. package/dist/services/cache/FileLock.d.ts.map +1 -0
  240. package/dist/services/cache/FileLock.js +68 -0
  241. package/dist/services/cache/StartupCacheService.d.ts +23 -0
  242. package/dist/services/cache/StartupCacheService.d.ts.map +1 -0
  243. package/dist/services/cache/StartupCacheService.js +159 -0
  244. package/dist/services/cache/index.d.ts +3 -0
  245. package/dist/services/cache/index.d.ts.map +1 -0
  246. package/dist/services/cache/index.js +2 -0
  247. package/dist/services/chopsticks/ChopsticksMultiChain.d.ts +158 -0
  248. package/dist/services/chopsticks/ChopsticksMultiChain.d.ts.map +1 -0
  249. package/dist/services/chopsticks/ChopsticksMultiChain.js +282 -0
  250. package/dist/services/chopsticks/ChopsticksService.d.ts +313 -0
  251. package/dist/services/chopsticks/ChopsticksService.d.ts.map +1 -0
  252. package/dist/services/chopsticks/ChopsticksService.js +77 -0
  253. package/dist/services/chopsticks/chopsticksConfigParser.d.ts +40 -0
  254. package/dist/services/chopsticks/chopsticksConfigParser.d.ts.map +1 -0
  255. package/dist/services/chopsticks/chopsticksConfigParser.js +201 -0
  256. package/dist/services/chopsticks/index.d.ts +5 -0
  257. package/dist/services/chopsticks/index.d.ts.map +1 -0
  258. package/dist/services/chopsticks/index.js +4 -0
  259. package/dist/services/chopsticks/launchChopsticksEffect.d.ts +225 -0
  260. package/dist/services/chopsticks/launchChopsticksEffect.d.ts.map +1 -0
  261. package/dist/services/chopsticks/launchChopsticksEffect.js +623 -0
  262. package/dist/services/config/configAccessors.d.ts +41 -0
  263. package/dist/services/config/configAccessors.d.ts.map +1 -0
  264. package/dist/services/config/configAccessors.js +149 -0
  265. package/dist/services/config/index.d.ts +2 -0
  266. package/dist/services/config/index.d.ts.map +1 -0
  267. package/dist/services/config/index.js +1 -0
  268. package/dist/services/errors.d.ts +72 -0
  269. package/dist/services/errors.d.ts.map +1 -0
  270. package/dist/services/errors.js +31 -0
  271. package/dist/services/index.d.ts +7 -0
  272. package/dist/services/index.d.ts.map +1 -0
  273. package/dist/services/index.js +6 -0
  274. package/dist/services/network/NodeReadinessService.d.ts +35 -0
  275. package/dist/services/network/NodeReadinessService.d.ts.map +1 -0
  276. package/dist/services/network/NodeReadinessService.js +120 -0
  277. package/dist/services/network/PortDiscoveryService.d.ts +22 -0
  278. package/dist/services/network/PortDiscoveryService.d.ts.map +1 -0
  279. package/dist/services/network/PortDiscoveryService.js +77 -0
  280. package/dist/services/network/RpcPortDiscoveryService.d.ts +25 -0
  281. package/dist/services/network/RpcPortDiscoveryService.d.ts.map +1 -0
  282. package/dist/services/network/RpcPortDiscoveryService.js +136 -0
  283. package/dist/services/network/index.d.ts +4 -0
  284. package/dist/services/network/index.d.ts.map +1 -0
  285. package/dist/services/network/index.js +3 -0
  286. package/dist/services/process/ProcessManagerService.d.ts +49 -0
  287. package/dist/services/process/ProcessManagerService.d.ts.map +1 -0
  288. package/dist/services/process/ProcessManagerService.js +162 -0
  289. package/dist/services/process/index.d.ts +3 -0
  290. package/dist/services/process/index.d.ts.map +1 -0
  291. package/dist/services/process/index.js +2 -0
  292. package/dist/services/process/launchNodeEffect.d.ts +40 -0
  293. package/dist/services/process/launchNodeEffect.d.ts.map +1 -0
  294. package/dist/services/process/launchNodeEffect.js +86 -0
  295. package/dist/util/functions/index.d.ts +3 -0
  296. package/dist/util/functions/index.d.ts.map +1 -0
  297. package/dist/util/functions/index.js +4 -0
  298. package/dist/util/index.d.ts +4 -0
  299. package/dist/util/index.d.ts.map +1 -0
  300. package/dist/util/index.js +2 -0
  301. package/package.json +157 -0
@@ -0,0 +1,165 @@
1
+ import fs from "node:fs";
2
+ import { execSync } from "node:child_process";
3
+ import chalk from "chalk";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { select } from "@inquirer/prompts";
7
+ export async function checkExists(path) {
8
+ const binPath = path.split(" ")[0];
9
+ const fsResult = fs.existsSync(binPath);
10
+ if (!fsResult) {
11
+ throw new Error(`No binary file found at location: ${binPath} \n Are you sure your ${chalk.bgWhiteBright.blackBright("moonwall.config.json")} file has the correct "binPath" in launchSpec?`);
12
+ }
13
+ const binArch = await getBinaryArchitecture(binPath);
14
+ const currentArch = os.arch();
15
+ if (binArch !== currentArch && binArch !== "unknown") {
16
+ throw new Error(`The binary architecture ${chalk.bgWhiteBright.blackBright(binArch)} does not match this system's architecture ${chalk.bgWhiteBright.blackBright(currentArch)}\nDownload or compile a new binary executable for ${chalk.bgWhiteBright.blackBright(currentArch)} `);
17
+ }
18
+ return true;
19
+ }
20
+ export async function downloadBinsIfMissing(binPath) {
21
+ const binName = path.basename(binPath);
22
+ const binDir = path.dirname(binPath);
23
+ const binPathExists = fs.existsSync(binPath);
24
+ if (!binPathExists && process.arch === "x64") {
25
+ const download = await select({
26
+ message: `The binary ${chalk.bgBlack.greenBright(binName)} is missing from ${chalk.bgBlack.greenBright(path.join(process.cwd(), binDir))}.\nWould you like to download it now?`,
27
+ default: true,
28
+ choices: [
29
+ { name: `Yes, download ${binName}`, value: true },
30
+ { name: "No, quit program", value: false },
31
+ ],
32
+ });
33
+ if (!download) {
34
+ process.exit(0);
35
+ }
36
+ else {
37
+ execSync(`mkdir -p ${binDir}`);
38
+ execSync(`pnpm moonwall download ${binName} latest ${binDir}`, {
39
+ stdio: "inherit",
40
+ });
41
+ }
42
+ }
43
+ else if (!binPathExists) {
44
+ console.log(`The binary: ${chalk.bgBlack.greenBright(binName)} is missing from: ${chalk.bgBlack.greenBright(path.join(process.cwd(), binDir))}`);
45
+ console.log(`Given you are running ${chalk.bgBlack.yellowBright(process.arch)} architecture, you will need to build it manually from source 🛠️`);
46
+ throw new Error("Executable binary not available");
47
+ }
48
+ }
49
+ export function checkListeningPorts(processId) {
50
+ try {
51
+ const stdOut = execSync(`lsof -p ${processId} | grep LISTEN`, {
52
+ encoding: "utf-8",
53
+ });
54
+ const binName = stdOut.split("\n")[0].split(" ")[0];
55
+ const ports = stdOut
56
+ .split("\n")
57
+ .filter(Boolean)
58
+ .map((line) => {
59
+ const port = line.split(":")[1];
60
+ return port.split(" ")[0];
61
+ });
62
+ const filtered = new Set(ports);
63
+ return { binName, processId, ports: [...filtered].sort() };
64
+ }
65
+ catch (e) {
66
+ const binName = execSync(`ps -p ${processId} -o comm=`).toString().trim();
67
+ console.log(`Process ${processId} is running which for binary ${binName}, however it is unresponsive.`);
68
+ console.log("Running Moonwall with this in the background may cause unexpected behaviour. Please manually kill the process and try running Moonwall again.");
69
+ console.log(`N.B. You can kill it with: sudo kill -9 ${processId}`);
70
+ throw new Error(e);
71
+ }
72
+ }
73
+ export function checkAlreadyRunning(binaryName) {
74
+ try {
75
+ console.log(`Checking if ${chalk.bgWhiteBright.blackBright(binaryName)} is already running...`);
76
+ // pgrep only supports 15 characters
77
+ const stdout = execSync(`pgrep -x ${[binaryName.slice(0, 14)]}`, {
78
+ encoding: "utf8",
79
+ timeout: 2000,
80
+ });
81
+ const pIdStrings = stdout.split("\n").filter(Boolean);
82
+ return pIdStrings.map((pId) => Number.parseInt(pId, 10));
83
+ }
84
+ catch (error) {
85
+ if (error.status === 1) {
86
+ return [];
87
+ }
88
+ throw error;
89
+ }
90
+ }
91
+ export async function promptAlreadyRunning(pids) {
92
+ const alreadyRunning = await select({
93
+ message: `The following processes are already running: \n${pids
94
+ .map((pid) => {
95
+ const { binName, ports } = checkListeningPorts(pid);
96
+ return `${binName} - pid: ${pid}, listenPorts: [${ports.join(", ")}]`;
97
+ })
98
+ .join("\n")}`,
99
+ default: "continue",
100
+ choices: [
101
+ { name: "🪓 Kill processes and continue", value: "kill" },
102
+ { name: "➡️ Continue (and let processes live)", value: "continue" },
103
+ { name: "🛑 Abort (and let processes live)", value: "abort" },
104
+ ],
105
+ });
106
+ switch (alreadyRunning) {
107
+ case "kill":
108
+ for (const pid of pids) {
109
+ execSync(`kill ${pid}`);
110
+ }
111
+ // pids.forEach((pid) => {
112
+ // execSync(`kill ${pid}`);
113
+ // });
114
+ break;
115
+ case "continue":
116
+ break;
117
+ case "abort":
118
+ throw new Error("Abort Signal Picked");
119
+ }
120
+ }
121
+ export function checkAccess(path) {
122
+ const binPath = path.split(" ")[0];
123
+ try {
124
+ fs.accessSync(binPath, fs.constants.X_OK);
125
+ }
126
+ catch (_err) {
127
+ console.error(`The file ${binPath} is not executable`);
128
+ throw new Error(`The file at ${binPath} , lacks execute permissions.`);
129
+ }
130
+ }
131
+ async function getBinaryArchitecture(filePath) {
132
+ return new Promise((resolve, reject) => {
133
+ const architectureMap = {
134
+ 0: "unknown",
135
+ 3: "x86",
136
+ 62: "x64",
137
+ 183: "arm64",
138
+ };
139
+ fs.open(filePath, "r", (err, fd) => {
140
+ if (err) {
141
+ reject(err);
142
+ return;
143
+ }
144
+ const buffer = Buffer.alloc(20);
145
+ fs.read(fd, buffer, 0, 20, 0, (err, _bytesRead, buffer) => {
146
+ if (err) {
147
+ reject(err);
148
+ return;
149
+ }
150
+ // if (
151
+ // buffer.readUInt8(0) !== 0x7f ||
152
+ // buffer.readUInt8(1) !== 0x45 ||
153
+ // buffer.readUInt8(2) !== 0x4c ||
154
+ // buffer.readUInt8(3) !== 0x46
155
+ // ) {
156
+ // // reject(new Error("Not an ELF file"));
157
+ // return;
158
+ // }
159
+ const e_machine = buffer.readUInt16LE(18);
160
+ const architecture = architectureMap[e_machine] || "unknown";
161
+ resolve(architecture);
162
+ });
163
+ });
164
+ });
165
+ }
@@ -0,0 +1,4 @@
1
+ export * from "../../../foundations/chopsticks/helpers.js";
2
+ export * from "../../../foundations/dev/helpers.js";
3
+ export * from "../../../foundations/zombie/helpers.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/internal/foundations/index.ts"],"names":[],"mappings":"AACA,2DAA2D;AAC3D,oDAAoD;AACpD,uDAAuD"}
@@ -0,0 +1,4 @@
1
+ // Re-export from foundations
2
+ export * from "../../../foundations/chopsticks/helpers.js";
3
+ export * from "../../../foundations/dev/helpers.js";
4
+ export * from "../../../foundations/zombie/helpers.js";
@@ -0,0 +1,12 @@
1
+ export * from "./logging.js";
2
+ export * from "./cmdFunctions/index.js";
3
+ export * from "./commandParsers.js";
4
+ export * from "./deriveTestIds.js";
5
+ export * from "./fileCheckers.js";
6
+ export * from "./foundations/index.js";
7
+ export * from "./launcherCommon.js";
8
+ export * from "./localNode.js";
9
+ export * from "./node.js";
10
+ export * from "./processHelpers.js";
11
+ export * from "./providerFactories.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,wCAAwC;AACxC,oCAAoC;AACpC,mCAAmC;AACnC,kCAAkC;AAClC,uCAAuC;AACvC,oCAAoC;AACpC,+BAA+B;AAC/B,0BAA0B;AAC1B,oCAAoC;AACpC,uCAAuC"}
@@ -0,0 +1,11 @@
1
+ export * from "./logging.js";
2
+ export * from "./cmdFunctions/index.js";
3
+ export * from "./commandParsers.js";
4
+ export * from "./deriveTestIds.js";
5
+ export * from "./fileCheckers.js";
6
+ export * from "./foundations/index.js";
7
+ export * from "./launcherCommon.js";
8
+ export * from "./localNode.js";
9
+ export * from "./node.js";
10
+ export * from "./processHelpers.js";
11
+ export * from "./providerFactories.js";
@@ -0,0 +1,4 @@
1
+ import type { Environment } from "../../api/types/index.js";
2
+ export declare function commonChecks(env: Environment): Promise<void>;
3
+ export declare function executeScript(scriptCommand: string, args?: string): Promise<void>;
4
+ //# sourceMappingURL=launcherCommon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcherCommon.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/launcherCommon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAiC;AAc5D,wBAAsB,YAAY,CAAC,GAAG,EAAE,WAAW,iBAsBlD;AAgGD,wBAAsB,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,iBAsCvE"}
@@ -0,0 +1,130 @@
1
+ import chalk from "chalk";
2
+ import { execSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { importAsyncConfig, parseZombieConfigForBins } from "../lib/configReader.js";
6
+ import { checkAlreadyRunning, downloadBinsIfMissing, promptAlreadyRunning, } from "./fileCheckers.js";
7
+ import Docker from "dockerode";
8
+ import { select } from "@inquirer/prompts";
9
+ export async function commonChecks(env) {
10
+ const globalConfig = await importAsyncConfig();
11
+ // TODO: This is begging for some Dependency Injection
12
+ if (env.foundation.type === "dev") {
13
+ await devBinCheck(env);
14
+ }
15
+ if (env.foundation.type === "zombie") {
16
+ await zombieBinCheck(env);
17
+ }
18
+ if (process.env.MOON_RUN_SCRIPTS === "true" &&
19
+ globalConfig.scriptsDir &&
20
+ env.runScripts &&
21
+ env.runScripts.length > 0) {
22
+ for (const scriptCommand of env.runScripts) {
23
+ await executeScript(scriptCommand);
24
+ }
25
+ }
26
+ }
27
+ async function zombieBinCheck(env) {
28
+ if (env.foundation.type !== "zombie") {
29
+ throw new Error("This function is only for zombie environments");
30
+ }
31
+ const bins = parseZombieConfigForBins(env.foundation.zombieSpec.configPath);
32
+ const pids = bins.flatMap((bin) => checkAlreadyRunning(bin));
33
+ pids.length === 0 || process.env.CI || (await promptAlreadyRunning(pids));
34
+ }
35
+ async function devBinCheck(env) {
36
+ if (env.foundation.type !== "dev") {
37
+ throw new Error("This function is only for dev environments");
38
+ }
39
+ if (!env.foundation.launchSpec || !env.foundation.launchSpec[0]) {
40
+ throw new Error("Dev environment requires a launchSpec configuration");
41
+ }
42
+ if (env.foundation.launchSpec[0].useDocker) {
43
+ const docker = new Docker();
44
+ const imageName = env.foundation.launchSpec[0].binPath;
45
+ console.log(`Checking if ${imageName} is running...`);
46
+ const matchingContainers = (await docker.listContainers({
47
+ filters: { ancestor: [imageName] },
48
+ })).flat();
49
+ if (matchingContainers.length === 0) {
50
+ return;
51
+ }
52
+ if (!process.env.CI) {
53
+ await promptKillContainers(matchingContainers);
54
+ return;
55
+ }
56
+ const runningContainers = matchingContainers.map(({ Id, Ports }) => ({
57
+ Id: Id.slice(0, 12),
58
+ Ports: Ports.map(({ PublicPort, PrivatePort }) => PublicPort ? `${PublicPort} -> ${PrivatePort}` : `${PrivatePort}`).join(", "),
59
+ }));
60
+ console.table(runningContainers);
61
+ throw new Error(`${imageName} is already running, aborting`);
62
+ }
63
+ const binName = path.basename(env.foundation.launchSpec[0].binPath);
64
+ const pids = checkAlreadyRunning(binName);
65
+ pids.length === 0 || process.env.CI || (await promptAlreadyRunning(pids));
66
+ await downloadBinsIfMissing(env.foundation.launchSpec[0].binPath);
67
+ }
68
+ async function promptKillContainers(matchingContainers) {
69
+ const answer = await select({
70
+ message: `The following containers are already running image ${matchingContainers[0].Image}: ${matchingContainers.map(({ Id }) => Id).join(", ")}\n Would you like to kill them?`,
71
+ choices: [
72
+ { name: "🪓 Kill containers", value: "kill" },
73
+ { name: "👋 Quit", value: "goodbye" },
74
+ ],
75
+ });
76
+ if (answer === "goodbye") {
77
+ console.log("Goodbye!");
78
+ process.exit(0);
79
+ }
80
+ if (answer === "kill") {
81
+ const docker = new Docker();
82
+ for (const { Id } of matchingContainers) {
83
+ const container = docker.getContainer(Id);
84
+ await container.stop();
85
+ await container.remove();
86
+ }
87
+ const containers = await docker.listContainers({
88
+ filters: { ancestor: matchingContainers.map(({ Image }) => Image) },
89
+ });
90
+ if (containers.length > 0) {
91
+ console.error(`The following containers are still running: ${containers.map(({ Id }) => Id).join(", ")}`);
92
+ process.exit(1);
93
+ }
94
+ return;
95
+ }
96
+ }
97
+ export async function executeScript(scriptCommand, args) {
98
+ const scriptsDir = (await importAsyncConfig()).scriptsDir;
99
+ if (!scriptsDir) {
100
+ throw new Error("No scriptsDir found in config");
101
+ }
102
+ const files = await fs.promises.readdir(scriptsDir);
103
+ try {
104
+ const script = scriptCommand.split(" ")[0];
105
+ const ext = path.extname(script);
106
+ const scriptPath = path.join(process.cwd(), scriptsDir, scriptCommand);
107
+ if (!files.includes(script)) {
108
+ throw new Error(`Script ${script} not found in ${scriptsDir}`);
109
+ }
110
+ console.log(`========== Executing script: ${chalk.bgGrey.greenBright(script)} ==========`);
111
+ const argsString = args ? ` ${args}` : "";
112
+ switch (ext) {
113
+ case ".js":
114
+ execSync(`node ${scriptPath}${argsString}`, { stdio: "inherit" });
115
+ break;
116
+ case ".ts":
117
+ execSync(`pnpm tsx ${scriptPath}${argsString}`, { stdio: "inherit" });
118
+ break;
119
+ case ".sh":
120
+ execSync(`${scriptPath}${argsString}`, { stdio: "inherit" });
121
+ break;
122
+ default:
123
+ console.log(`${ext} not supported, skipping ${script}`);
124
+ }
125
+ }
126
+ catch (err) {
127
+ console.error(`Error executing script: ${chalk.bgGrey.redBright(err)}`);
128
+ throw new Error(err);
129
+ }
130
+ }
@@ -0,0 +1,16 @@
1
+ import type { DevLaunchSpec } from "../../api/types/index.js";
2
+ import Docker from "dockerode";
3
+ import fs from "node:fs";
4
+ export declare function launchNodeLegacy(options: {
5
+ command: string;
6
+ args: string[];
7
+ name: string;
8
+ launchSpec?: DevLaunchSpec;
9
+ }): Promise<{
10
+ runningNode: Docker.Container;
11
+ fsStream: fs.WriteStream;
12
+ } | {
13
+ runningNode: import("node:child_process").ChildProcessWithoutNullStreams;
14
+ fsStream: fs.WriteStream;
15
+ }>;
16
+ //# sourceMappingURL=localNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localNode.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/localNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iCAAiC;AAE9D,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,MAAM,SAAS,CAAC;AA6FzB,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B;;;;;;GAuIA"}