buncargo 1.0.29 → 3.2.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 (246) hide show
  1. package/dist/bin.d.ts +1 -12
  2. package/dist/bin.js +261 -253
  3. package/dist/cli/bin.d.ts +13 -0
  4. package/dist/cli/bin.js +317 -0
  5. package/dist/cli/commands/help.d.ts +1 -0
  6. package/dist/cli/commands/runtime.d.ts +5 -0
  7. package/dist/cli/commands/version.d.ts +1 -0
  8. package/dist/cli/index.d.ts +1 -0
  9. package/dist/cli/index.js +14 -0
  10. package/dist/cli/run-cli.d.ts +30 -0
  11. package/dist/cli.d.ts +1 -22
  12. package/dist/cli.js +5 -13
  13. package/dist/config/config.d.ts +1 -0
  14. package/dist/config/define-config.d.ts +13 -0
  15. package/dist/config/index.d.ts +3 -0
  16. package/dist/config/index.js +15 -0
  17. package/dist/config/merge-configs.d.ts +3 -0
  18. package/dist/config/validate-config.d.ts +3 -0
  19. package/dist/config.d.ts +1 -72
  20. package/dist/config.js +12 -12
  21. package/dist/core/docker.d.ts +1 -83
  22. package/dist/core/docker.js +35 -32
  23. package/dist/core/index.d.ts +1 -1
  24. package/dist/core/index.js +123 -118
  25. package/dist/core/network.js +2 -2
  26. package/dist/core/ports.js +1 -1
  27. package/dist/core/process.js +1 -1
  28. package/dist/core/quick-tunnel/cloudflared-process.d.ts +10 -0
  29. package/dist/core/quick-tunnel/constants.d.ts +9 -0
  30. package/dist/core/quick-tunnel/index.d.ts +17 -0
  31. package/dist/core/quick-tunnel/install.d.ts +1 -0
  32. package/dist/core/tunnel.d.ts +34 -0
  33. package/dist/core/utils.js +2 -2
  34. package/dist/core/watchdog-runner.js +45 -42
  35. package/dist/core/watchdog.d.ts +1 -0
  36. package/dist/core/watchdog.js +4 -2
  37. package/dist/docker/index.d.ts +1 -0
  38. package/dist/docker/index.js +38 -0
  39. package/dist/docker/runtime.d.ts +87 -0
  40. package/dist/docker/runtime.js +37 -0
  41. package/dist/docker-compose/compose.d.ts +1 -0
  42. package/dist/docker-compose/generated-file.d.ts +7 -0
  43. package/dist/docker-compose/index.d.ts +3 -0
  44. package/dist/docker-compose/index.js +15 -0
  45. package/dist/docker-compose/model.d.ts +6 -0
  46. package/dist/docker-compose/services/clickhouse.d.ts +16 -0
  47. package/dist/docker-compose/services/define-docker-service.d.ts +41 -0
  48. package/dist/docker-compose/services/index.d.ts +23 -0
  49. package/dist/docker-compose/services/index.js +17 -0
  50. package/dist/docker-compose/services/postgres.d.ts +12 -0
  51. package/dist/docker-compose/services/redis.d.ts +12 -0
  52. package/dist/docker-compose/services/shared.d.ts +7 -0
  53. package/dist/docker-compose/yaml.d.ts +2 -0
  54. package/dist/environment/create-dev-environment.d.ts +23 -0
  55. package/dist/environment/index.d.ts +1 -0
  56. package/dist/environment/index.js +15 -0
  57. package/dist/environment/logging.d.ts +17 -0
  58. package/dist/environment/only-apps.d.ts +10 -0
  59. package/dist/environment/seeding.d.ts +9 -0
  60. package/dist/environment.d.ts +1 -23
  61. package/dist/environment.js +12 -14
  62. package/dist/index-045jksh5.js +147 -0
  63. package/dist/index-08wa79cs.js +125 -117
  64. package/dist/index-0kxnae3z.js +335 -0
  65. package/dist/index-1mdrf7nz.js +51 -43
  66. package/dist/index-1yvbwj4k.js +262 -242
  67. package/dist/index-23ev345g.js +475 -0
  68. package/dist/index-2ckr49sf.js +228 -0
  69. package/dist/index-2f47khe5.js +376 -369
  70. package/dist/index-2fr3g85b.js +220 -183
  71. package/dist/index-38xnzpa6.js +450 -0
  72. package/dist/index-3eyrdxw9.js +577 -0
  73. package/dist/index-3h3dhtf2.js +51 -43
  74. package/dist/index-42x95209.js +51 -43
  75. package/dist/index-4gp0az1g.js +145 -0
  76. package/dist/index-4xrxh8yv.js +72 -0
  77. package/dist/index-5aq985p4.js +250 -0
  78. package/dist/index-5gmws6ah.js +181 -0
  79. package/dist/index-5hka0tff.js +78 -76
  80. package/dist/index-5rfqps4b.js +3 -0
  81. package/dist/index-5t9jxqm0.js +428 -0
  82. package/dist/index-6c1w1xk5.js +101 -0
  83. package/dist/index-6cmex7m5.js +72 -0
  84. package/dist/index-6d6x175r.js +572 -0
  85. package/dist/index-6fm7mvwj.js +118 -97
  86. package/dist/index-6srpc523.js +127 -128
  87. package/dist/index-731rzzfp.js +157 -142
  88. package/dist/index-75y4cg2z.js +51 -43
  89. package/dist/index-7ja4ywyj.js +126 -127
  90. package/dist/index-7v19es2e.js +666 -0
  91. package/dist/index-8bw1cmz4.js +531 -0
  92. package/dist/index-8hbbj1mp.js +120 -121
  93. package/dist/index-8xj2p5n5.js +118 -97
  94. package/dist/index-9wyhzw0h.js +574 -0
  95. package/dist/index-ag90ry8t.js +576 -0
  96. package/dist/index-bj79tw5w.js +0 -0
  97. package/dist/index-bnk6nr0g.js +73 -0
  98. package/dist/index-brbbzyks.js +72 -0
  99. package/dist/index-byeqyjrz.js +72 -0
  100. package/dist/index-c0dr6mcv.js +123 -0
  101. package/dist/index-cty0bcry.js +235 -218
  102. package/dist/index-d8tyv5se.js +228 -0
  103. package/dist/index-d9efy0n4.js +176 -150
  104. package/dist/index-enj4zdma.js +574 -0
  105. package/dist/index-etfmqjjf.js +427 -0
  106. package/dist/index-fb29934k.js +172 -0
  107. package/dist/index-g50jw1yf.js +72 -0
  108. package/dist/index-g6eb5wdw.js +118 -117
  109. package/dist/index-ggq3yryx.js +99 -95
  110. package/dist/index-h70tce00.js +177 -0
  111. package/dist/index-hkxtfqtc.js +333 -0
  112. package/dist/index-k370bech.js +72 -0
  113. package/dist/index-kf3dhser.js +146 -143
  114. package/dist/index-ma6tgdb2.js +500 -0
  115. package/dist/index-mam0bcyz.js +123 -0
  116. package/dist/index-mm412dkp.js +274 -0
  117. package/dist/index-n8v18aeb.js +0 -0
  118. package/dist/index-ndnmnsej.js +378 -371
  119. package/dist/index-p8wty0e2.js +389 -379
  120. package/dist/index-qa8akv6y.js +666 -0
  121. package/dist/index-qfphr2fd.js +78 -76
  122. package/dist/index-qqmms8rs.js +51 -43
  123. package/dist/index-qw4093g2.js +51 -43
  124. package/dist/index-qzwpzjbx.js +121 -122
  125. package/dist/index-segbnm0h.js +146 -143
  126. package/dist/index-t0fj6gg1.js +112 -0
  127. package/dist/index-thdkwnv7.js +122 -0
  128. package/dist/index-tjbx2r2t.js +270 -0
  129. package/dist/index-tjqw9vtj.js +62 -54
  130. package/dist/index-vbpb89jy.js +248 -0
  131. package/dist/index-vg55rq0y.js +250 -0
  132. package/dist/index-vhs88xhe.js +99 -95
  133. package/dist/index-vs81yaks.js +244 -0
  134. package/dist/index-w8zxnjka.js +249 -0
  135. package/dist/index-wk2na3t9.js +385 -375
  136. package/dist/index-wz9x8g7z.js +383 -373
  137. package/dist/index-x249gyde.js +388 -378
  138. package/dist/index-x54nbgs7.js +355 -0
  139. package/dist/index-xkvd0nsd.js +187 -0
  140. package/dist/index-yedqxm1z.js +80 -0
  141. package/dist/index-yz4jfz7z.js +338 -0
  142. package/dist/index-zfjzzjkf.js +240 -199
  143. package/dist/index.d.ts +12 -8
  144. package/dist/index.js +56 -34
  145. package/dist/lint.d.ts +1 -46
  146. package/dist/lint.js +3 -7
  147. package/dist/loader/cache.d.ts +4 -0
  148. package/dist/loader/find-config-file.d.ts +2 -0
  149. package/dist/loader/index.d.ts +5 -0
  150. package/dist/loader/index.js +24 -0
  151. package/dist/loader/load-dev-env.d.ts +5 -0
  152. package/dist/loader/loader.d.ts +1 -0
  153. package/dist/loader.d.ts +1 -45
  154. package/dist/loader.js +22 -20
  155. package/dist/prisma/index.d.ts +1 -0
  156. package/dist/prisma/prisma.d.ts +29 -0
  157. package/dist/prisma.d.ts +1 -29
  158. package/dist/prisma.js +6 -10
  159. package/dist/src/bin.js +309 -0
  160. package/dist/src/cli.js +5 -0
  161. package/dist/src/config.js +15 -0
  162. package/dist/src/core/docker.js +38 -0
  163. package/dist/src/core/index.js +130 -0
  164. package/dist/src/core/network.js +9 -0
  165. package/dist/src/core/ports.js +23 -0
  166. package/dist/src/core/process.js +31 -0
  167. package/dist/src/core/utils.js +11 -0
  168. package/dist/src/core/watchdog-runner.js +69 -0
  169. package/dist/src/core/watchdog.js +28 -0
  170. package/dist/src/docker/runtime.js +37 -0
  171. package/dist/src/docker-compose/index.js +16 -0
  172. package/dist/src/docker-compose/services/index.js +17 -0
  173. package/dist/src/environment.js +12 -0
  174. package/dist/src/index.js +122 -0
  175. package/dist/src/lint.js +3 -0
  176. package/dist/src/loader.js +25 -0
  177. package/dist/src/prisma.js +6 -0
  178. package/dist/src/types.js +0 -0
  179. package/dist/typecheck/index.d.ts +1 -0
  180. package/dist/typecheck/index.js +7 -0
  181. package/dist/typecheck/typecheck.d.ts +46 -0
  182. package/dist/types/all-types.d.ts +544 -0
  183. package/dist/types/cli.d.ts +1 -0
  184. package/dist/types/config.d.ts +6 -0
  185. package/dist/types/docker.d.ts +15 -0
  186. package/dist/types/environment.d.ts +8 -0
  187. package/dist/types/hooks.d.ts +9 -0
  188. package/dist/types/index.d.ts +1 -0
  189. package/dist/types/index.js +0 -0
  190. package/dist/types/prisma.d.ts +1 -0
  191. package/dist/types.d.ts +1 -399
  192. package/package.json +55 -48
  193. package/readme.md +365 -109
  194. package/src/cli/bin.ts +77 -0
  195. package/src/cli/commands/help.ts +39 -0
  196. package/src/cli/commands/runtime.ts +72 -0
  197. package/src/cli/commands/version.ts +4 -0
  198. package/src/cli/index.ts +1 -0
  199. package/{cli.ts → src/cli/run-cli.ts} +114 -10
  200. package/src/config/define-config.ts +30 -0
  201. package/src/config/index.ts +3 -0
  202. package/src/config/merge-configs.ts +33 -0
  203. package/src/config/validate-config.ts +136 -0
  204. package/{core → src/core}/index.ts +2 -2
  205. package/{core → src/core}/ports.ts +5 -2
  206. package/{core → src/core}/process.ts +6 -2
  207. package/src/core/quick-tunnel/cloudflared-process.ts +83 -0
  208. package/src/core/quick-tunnel/constants.ts +31 -0
  209. package/src/core/quick-tunnel/index.ts +96 -0
  210. package/src/core/quick-tunnel/install.ts +160 -0
  211. package/src/core/tunnel.ts +165 -0
  212. package/{core → src/core}/utils.ts +1 -0
  213. package/{core → src/core}/watchdog.ts +5 -1
  214. package/src/docker/index.ts +1 -0
  215. package/{core/docker.ts → src/docker/runtime.ts} +11 -4
  216. package/src/docker-compose/generated-file.ts +45 -0
  217. package/src/docker-compose/index.ts +7 -0
  218. package/src/docker-compose/model.ts +197 -0
  219. package/src/docker-compose/services/clickhouse.ts +79 -0
  220. package/src/docker-compose/services/define-docker-service.ts +109 -0
  221. package/src/docker-compose/services/index.ts +67 -0
  222. package/src/docker-compose/services/postgres.ts +60 -0
  223. package/src/docker-compose/services/redis.ts +48 -0
  224. package/src/docker-compose/services/shared.ts +79 -0
  225. package/src/docker-compose/yaml.ts +88 -0
  226. package/{environment.ts → src/environment/create-dev-environment.ts} +214 -141
  227. package/src/environment/index.ts +1 -0
  228. package/src/environment/logging.ts +115 -0
  229. package/src/environment/only-apps.ts +34 -0
  230. package/src/environment/seeding.ts +57 -0
  231. package/{index.ts → src/index.ts} +52 -20
  232. package/src/loader/cache.ts +23 -0
  233. package/src/loader/find-config-file.ts +29 -0
  234. package/src/loader/index.ts +17 -0
  235. package/src/loader/load-dev-env.ts +38 -0
  236. package/src/prisma/index.ts +1 -0
  237. package/{prisma.ts → src/prisma/prisma.ts} +4 -2
  238. package/src/typecheck/index.ts +1 -0
  239. package/{types.ts → src/types/all-types.ts} +186 -8
  240. package/src/types/index.ts +1 -0
  241. package/bin.ts +0 -192
  242. package/config.ts +0 -194
  243. package/loader.ts +0 -126
  244. /package/{core → src/core}/network.ts +0 -0
  245. /package/{core → src/core}/watchdog-runner.ts +0 -0
  246. /package/{lint.ts → src/typecheck/typecheck.ts} +0 -0
@@ -1,132 +1,133 @@
1
+ // cli.ts
2
+ import { spawn } from "node:child_process";
1
3
  import {
2
- spawnWatchdog,
3
- startHeartbeat,
4
- stopHeartbeat
4
+ spawnWatchdog,
5
+ startHeartbeat,
6
+ stopHeartbeat,
5
7
  } from "./index-vhs88xhe.js";
6
8
 
7
- // cli.ts
8
- import { spawn } from "node:child_process";
9
9
  async function runCli(env, options = {}) {
10
- const {
11
- args = process.argv.slice(2),
12
- watchdog = true,
13
- watchdogTimeout = 10,
14
- devServersCommand
15
- } = options;
16
- env.logInfo();
17
- if (args.includes("--down")) {
18
- await env.stop();
19
- process.exit(0);
20
- }
21
- if (args.includes("--reset")) {
22
- await env.stop({ removeVolumes: true });
23
- process.exit(0);
24
- }
25
- const running = await env.isRunning();
26
- if (running) {
27
- console.log("✓ Containers already running");
28
- } else {
29
- await env.start({ startServers: false, wait: true });
30
- }
31
- if (args.includes("--migrate")) {
32
- console.log("");
33
- console.log("✅ Migrations applied successfully");
34
- process.exit(0);
35
- }
36
- if (args.includes("--seed")) {
37
- console.log("\uD83C\uDF31 Running seeders...");
38
- const result = await env.exec("bun run run:seeder", {
39
- throwOnError: false
40
- });
41
- if (result.exitCode !== 0) {
42
- console.error("❌ Seeding failed");
43
- process.exit(1);
44
- }
45
- console.log("");
46
- console.log("✅ Seeding complete");
47
- process.exit(0);
48
- }
49
- if (args.includes("--up-only")) {
50
- console.log("");
51
- console.log("✅ Containers started. Environment ready.");
52
- console.log("");
53
- process.exit(0);
54
- }
55
- if (watchdog) {
56
- await spawnWatchdog(env.projectName, env.root, {
57
- timeoutMinutes: watchdogTimeout,
58
- verbose: true
59
- });
60
- startHeartbeat(env.projectName);
61
- }
62
- const command = devServersCommand ?? buildDevServersCommand(env.apps);
63
- if (!command) {
64
- console.log("✅ Containers ready. No apps configured.");
65
- await new Promise(() => {});
66
- return;
67
- }
68
- console.log("");
69
- console.log("\uD83D\uDD27 Starting dev servers...");
70
- console.log("");
71
- await runCommand(command, env.root, env.buildEnvVars());
72
- stopHeartbeat();
10
+ const {
11
+ args = process.argv.slice(2),
12
+ watchdog = true,
13
+ watchdogTimeout = 10,
14
+ devServersCommand,
15
+ } = options;
16
+ env.logInfo();
17
+ if (args.includes("--down")) {
18
+ await env.stop();
19
+ process.exit(0);
20
+ }
21
+ if (args.includes("--reset")) {
22
+ await env.stop({ removeVolumes: true });
23
+ process.exit(0);
24
+ }
25
+ const running = await env.isRunning();
26
+ if (running) {
27
+ console.log("✓ Containers already running");
28
+ } else {
29
+ await env.start({ startServers: false, wait: true });
30
+ }
31
+ if (args.includes("--migrate")) {
32
+ console.log("");
33
+ console.log("✅ Migrations applied successfully");
34
+ process.exit(0);
35
+ }
36
+ if (args.includes("--seed")) {
37
+ console.log("\uD83C\uDF31 Running seeders...");
38
+ const result = await env.exec("bun run run:seeder", {
39
+ throwOnError: false,
40
+ });
41
+ if (result.exitCode !== 0) {
42
+ console.error("❌ Seeding failed");
43
+ process.exit(1);
44
+ }
45
+ console.log("");
46
+ console.log("✅ Seeding complete");
47
+ process.exit(0);
48
+ }
49
+ if (args.includes("--up-only")) {
50
+ console.log("");
51
+ console.log("✅ Containers started. Environment ready.");
52
+ console.log("");
53
+ process.exit(0);
54
+ }
55
+ if (watchdog) {
56
+ await spawnWatchdog(env.projectName, env.root, {
57
+ timeoutMinutes: watchdogTimeout,
58
+ verbose: true,
59
+ });
60
+ startHeartbeat(env.projectName);
61
+ }
62
+ const command = devServersCommand ?? buildDevServersCommand(env.apps);
63
+ if (!command) {
64
+ console.log("✅ Containers ready. No apps configured.");
65
+ await new Promise(() => {});
66
+ return;
67
+ }
68
+ console.log("");
69
+ console.log("\uD83D\uDD27 Starting dev servers...");
70
+ console.log("");
71
+ await runCommand(command, env.root, env.buildEnvVars());
72
+ stopHeartbeat();
73
73
  }
74
74
  function buildDevServersCommand(apps) {
75
- const appEntries = Object.entries(apps);
76
- if (appEntries.length === 0)
77
- return null;
78
- const commands = [];
79
- const names = [];
80
- const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
81
- for (const [name, config] of appEntries) {
82
- names.push(name);
83
- const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
84
- commands.push(`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim());
85
- }
86
- const namesArg = `-n ${names.join(",")}`;
87
- const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
88
- const commandsArg = commands.join(" ");
89
- return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
75
+ const appEntries = Object.entries(apps);
76
+ if (appEntries.length === 0) return null;
77
+ const commands = [];
78
+ const names = [];
79
+ const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
80
+ for (const [name, config] of appEntries) {
81
+ names.push(name);
82
+ const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
83
+ commands.push(
84
+ `"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim(),
85
+ );
86
+ }
87
+ const namesArg = `-n ${names.join(",")}`;
88
+ const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
89
+ const commandsArg = commands.join(" ");
90
+ return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
90
91
  }
91
92
  function runCommand(command, cwd, envVars) {
92
- return new Promise((resolve, reject) => {
93
- const proc = spawn(command, [], {
94
- cwd,
95
- env: { ...process.env, ...envVars },
96
- stdio: "inherit",
97
- shell: true
98
- });
99
- proc.on("close", (code) => {
100
- if (code === 0 || code === null) {
101
- resolve();
102
- } else {
103
- reject(new Error(`Command exited with code ${code}`));
104
- }
105
- });
106
- proc.on("error", reject);
107
- const cleanup = () => {
108
- proc.kill("SIGTERM");
109
- };
110
- process.on("SIGINT", cleanup);
111
- process.on("SIGTERM", cleanup);
112
- });
93
+ return new Promise((resolve, reject) => {
94
+ const proc = spawn(command, [], {
95
+ cwd,
96
+ env: { ...process.env, ...envVars },
97
+ stdio: "inherit",
98
+ shell: true,
99
+ });
100
+ proc.on("close", (code) => {
101
+ if (code === 0 || code === null) {
102
+ resolve();
103
+ } else {
104
+ reject(new Error(`Command exited with code ${code}`));
105
+ }
106
+ });
107
+ proc.on("error", reject);
108
+ const cleanup = () => {
109
+ proc.kill("SIGTERM");
110
+ };
111
+ process.on("SIGINT", cleanup);
112
+ process.on("SIGTERM", cleanup);
113
+ });
113
114
  }
114
115
  function hasFlag(args, flag) {
115
- return args.includes(flag);
116
+ return args.includes(flag);
116
117
  }
117
118
  function getFlagValue(args, flag) {
118
- const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
119
- if (prefixed) {
120
- return prefixed.split("=")[1];
121
- }
122
- const index = args.indexOf(flag);
123
- if (index !== -1 && index + 1 < args.length) {
124
- const nextArg = args[index + 1];
125
- if (nextArg !== undefined && !nextArg.startsWith("-")) {
126
- return nextArg;
127
- }
128
- }
129
- return;
119
+ const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
120
+ if (prefixed) {
121
+ return prefixed.split("=")[1];
122
+ }
123
+ const index = args.indexOf(flag);
124
+ if (index !== -1 && index + 1 < args.length) {
125
+ const nextArg = args[index + 1];
126
+ if (nextArg !== undefined && !nextArg.startsWith("-")) {
127
+ return nextArg;
128
+ }
129
+ }
130
+ return;
130
131
  }
131
132
 
132
133
  export { runCli, hasFlag, getFlagValue };
@@ -1,120 +1,124 @@
1
- import {
2
- isProcessAlive
3
- } from "./index-1yvbwj4k.js";
4
-
5
1
  // core/watchdog.ts
6
2
  import { spawn } from "node:child_process";
7
3
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
4
+ import { isProcessAlive } from "./index-1yvbwj4k.js";
5
+
8
6
  function getHeartbeatFile(projectName) {
9
- return `/tmp/${projectName}-heartbeat`;
7
+ return `/tmp/${projectName}-heartbeat`;
10
8
  }
11
9
  function getWatchdogPidFile(projectName) {
12
- return `/tmp/${projectName}-watchdog.pid`;
10
+ return `/tmp/${projectName}-watchdog.pid`;
13
11
  }
14
12
  var heartbeatInterval = null;
15
13
  function startHeartbeat(projectName, intervalMs = 30000) {
16
- const heartbeatFile = getHeartbeatFile(projectName);
17
- writeFileSync(heartbeatFile, Date.now().toString());
18
- heartbeatInterval = setInterval(() => {
19
- writeFileSync(heartbeatFile, Date.now().toString());
20
- }, intervalMs);
14
+ const heartbeatFile = getHeartbeatFile(projectName);
15
+ writeFileSync(heartbeatFile, Date.now().toString());
16
+ heartbeatInterval = setInterval(() => {
17
+ writeFileSync(heartbeatFile, Date.now().toString());
18
+ }, intervalMs);
21
19
  }
22
20
  function stopHeartbeat() {
23
- if (heartbeatInterval) {
24
- clearInterval(heartbeatInterval);
25
- heartbeatInterval = null;
26
- }
21
+ if (heartbeatInterval) {
22
+ clearInterval(heartbeatInterval);
23
+ heartbeatInterval = null;
24
+ }
27
25
  }
28
26
  function readHeartbeat(projectName) {
29
- const heartbeatFile = getHeartbeatFile(projectName);
30
- try {
31
- if (!existsSync(heartbeatFile))
32
- return null;
33
- const content = readFileSync(heartbeatFile, "utf-8");
34
- const timestamp = parseInt(content, 10);
35
- return Number.isNaN(timestamp) ? null : timestamp;
36
- } catch {
37
- return null;
38
- }
27
+ const heartbeatFile = getHeartbeatFile(projectName);
28
+ try {
29
+ if (!existsSync(heartbeatFile)) return null;
30
+ const content = readFileSync(heartbeatFile, "utf-8");
31
+ const timestamp = parseInt(content, 10);
32
+ return Number.isNaN(timestamp) ? null : timestamp;
33
+ } catch {
34
+ return null;
35
+ }
39
36
  }
40
37
  function removeHeartbeatFile(projectName) {
41
- const heartbeatFile = getHeartbeatFile(projectName);
42
- try {
43
- unlinkSync(heartbeatFile);
44
- } catch {}
38
+ const heartbeatFile = getHeartbeatFile(projectName);
39
+ try {
40
+ unlinkSync(heartbeatFile);
41
+ } catch {}
45
42
  }
46
43
  function isWatchdogRunning(projectName) {
47
- const pidFile = getWatchdogPidFile(projectName);
48
- try {
49
- if (!existsSync(pidFile))
50
- return false;
51
- const content = readFileSync(pidFile, "utf-8");
52
- const pid = parseInt(content, 10);
53
- if (Number.isNaN(pid))
54
- return false;
55
- return isProcessAlive(pid);
56
- } catch {
57
- return false;
58
- }
44
+ const pidFile = getWatchdogPidFile(projectName);
45
+ try {
46
+ if (!existsSync(pidFile)) return false;
47
+ const content = readFileSync(pidFile, "utf-8");
48
+ const pid = parseInt(content, 10);
49
+ if (Number.isNaN(pid)) return false;
50
+ return isProcessAlive(pid);
51
+ } catch {
52
+ return false;
53
+ }
59
54
  }
60
55
  function getWatchdogPid(projectName) {
61
- const pidFile = getWatchdogPidFile(projectName);
62
- try {
63
- if (!existsSync(pidFile))
64
- return null;
65
- const content = readFileSync(pidFile, "utf-8");
66
- const pid = parseInt(content, 10);
67
- if (Number.isNaN(pid))
68
- return null;
69
- if (!isProcessAlive(pid))
70
- return null;
71
- return pid;
72
- } catch {
73
- return null;
74
- }
56
+ const pidFile = getWatchdogPidFile(projectName);
57
+ try {
58
+ if (!existsSync(pidFile)) return null;
59
+ const content = readFileSync(pidFile, "utf-8");
60
+ const pid = parseInt(content, 10);
61
+ if (Number.isNaN(pid)) return null;
62
+ if (!isProcessAlive(pid)) return null;
63
+ return pid;
64
+ } catch {
65
+ return null;
66
+ }
75
67
  }
76
68
  async function spawnWatchdog(projectName, root, options = {}) {
77
- const { timeoutMinutes = 10, verbose = true, composeFile } = options;
78
- const existingPid = getWatchdogPid(projectName);
79
- if (existingPid) {
80
- if (verbose)
81
- console.log(`✓ Watchdog already running (PID: ${existingPid})`);
82
- return;
83
- }
84
- const pidFile = getWatchdogPidFile(projectName);
85
- try {
86
- unlinkSync(pidFile);
87
- } catch {}
88
- const watchdogScript = new URL("./watchdog-runner.ts", import.meta.url).pathname;
89
- const proc = spawn("bun", ["run", watchdogScript], {
90
- cwd: root,
91
- detached: true,
92
- stdio: "ignore",
93
- env: {
94
- ...process.env,
95
- WATCHDOG_PROJECT_NAME: projectName,
96
- WATCHDOG_HEARTBEAT_FILE: getHeartbeatFile(projectName),
97
- WATCHDOG_PID_FILE: pidFile,
98
- WATCHDOG_TIMEOUT_MS: String(timeoutMinutes * 60 * 1000),
99
- WATCHDOG_COMPOSE_ARG: composeFile ? `-f ${composeFile}` : ""
100
- }
101
- });
102
- proc.unref();
103
- if (verbose && proc.pid) {
104
- console.log(`✓ Watchdog started (PID: ${proc.pid})`);
105
- }
69
+ const { timeoutMinutes = 10, verbose = true, composeFile } = options;
70
+ const existingPid = getWatchdogPid(projectName);
71
+ if (existingPid) {
72
+ if (verbose)
73
+ console.log(`✓ Watchdog already running (PID: ${existingPid})`);
74
+ return;
75
+ }
76
+ const pidFile = getWatchdogPidFile(projectName);
77
+ try {
78
+ unlinkSync(pidFile);
79
+ } catch {}
80
+ const watchdogScript = new URL("./watchdog-runner.ts", import.meta.url)
81
+ .pathname;
82
+ const proc = spawn("bun", ["run", watchdogScript], {
83
+ cwd: root,
84
+ detached: true,
85
+ stdio: "ignore",
86
+ env: {
87
+ ...process.env,
88
+ WATCHDOG_PROJECT_NAME: projectName,
89
+ WATCHDOG_HEARTBEAT_FILE: getHeartbeatFile(projectName),
90
+ WATCHDOG_PID_FILE: pidFile,
91
+ WATCHDOG_TIMEOUT_MS: String(timeoutMinutes * 60 * 1000),
92
+ WATCHDOG_COMPOSE_ARG: composeFile ? `-f ${composeFile}` : "",
93
+ },
94
+ });
95
+ proc.unref();
96
+ if (verbose && proc.pid) {
97
+ console.log(`✓ Watchdog started (PID: ${proc.pid})`);
98
+ }
106
99
  }
107
100
  function stopWatchdog(projectName) {
108
- const pid = getWatchdogPid(projectName);
109
- if (pid) {
110
- try {
111
- process.kill(pid, "SIGTERM");
112
- } catch {}
113
- }
114
- const pidFile = getWatchdogPidFile(projectName);
115
- try {
116
- unlinkSync(pidFile);
117
- } catch {}
101
+ const pid = getWatchdogPid(projectName);
102
+ if (pid) {
103
+ try {
104
+ process.kill(pid, "SIGTERM");
105
+ } catch {}
106
+ }
107
+ const pidFile = getWatchdogPidFile(projectName);
108
+ try {
109
+ unlinkSync(pidFile);
110
+ } catch {}
118
111
  }
119
112
 
120
- export { getHeartbeatFile, getWatchdogPidFile, startHeartbeat, stopHeartbeat, readHeartbeat, removeHeartbeatFile, isWatchdogRunning, getWatchdogPid, spawnWatchdog, stopWatchdog };
113
+ export {
114
+ getHeartbeatFile,
115
+ getWatchdogPidFile,
116
+ startHeartbeat,
117
+ stopHeartbeat,
118
+ readHeartbeat,
119
+ removeHeartbeatFile,
120
+ isWatchdogRunning,
121
+ getWatchdogPid,
122
+ spawnWatchdog,
123
+ stopWatchdog,
124
+ };
@@ -0,0 +1,177 @@
1
+ // src/typecheck/typecheck.ts
2
+ import { execSync } from "node:child_process";
3
+ import { readFileSync, unlinkSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import fg from "fast-glob";
6
+ var DEFAULT_PATTERNS = ["apps/*", "packages/*", "modules"];
7
+ var DEFAULT_CONCURRENCY = 1;
8
+ var CORRUPTED_CACHE_PATTERNS = [
9
+ "all goroutines are asleep - deadlock",
10
+ "fatal error:",
11
+ "panic:",
12
+ "github.com/microsoft/typescript-go"
13
+ ];
14
+ function isCorruptedCacheError(output) {
15
+ return CORRUPTED_CACHE_PATTERNS.some((pattern) => output.includes(pattern));
16
+ }
17
+ async function clearTsBuildInfo(workspace, verbose) {
18
+ if (verbose) {
19
+ console.log(`\uD83E\uDDF9 Clearing corrupted tsbuildinfo cache for ${workspace}...`);
20
+ }
21
+ try {
22
+ const tsbuildInfoFiles = await fg(`${workspace}/**/*.tsbuildinfo`, {
23
+ absolute: true
24
+ });
25
+ for (const file of tsbuildInfoFiles) {
26
+ try {
27
+ unlinkSync(file);
28
+ } catch {}
29
+ }
30
+ const cacheFiles = await fg(`${workspace}/**/.cache/tsbuildinfo.json`, {
31
+ absolute: true
32
+ });
33
+ for (const file of cacheFiles) {
34
+ try {
35
+ unlinkSync(file);
36
+ } catch {}
37
+ }
38
+ } catch {}
39
+ }
40
+ async function countTypeScriptFiles(pkgPath, root) {
41
+ const files = await fg(`${pkgPath}/**/*.{ts,tsx}`, {
42
+ cwd: root,
43
+ ignore: ["**/node_modules/**"]
44
+ });
45
+ return files.length;
46
+ }
47
+ function formatErrorOutput(output) {
48
+ return output.split(`
49
+ `).map((line) => {
50
+ return line.replace(/\.\.\/\.\.\/packages\/modules\//g, "").replace(/\((\d+),(\d+)\):?/g, ":$1:$2 -");
51
+ }).join(`
52
+ `).trim();
53
+ }
54
+ async function runSingleTypecheck(workspace, fileCount, root, verbose, isRetry = false) {
55
+ const startTime = performance.now();
56
+ if (verbose) {
57
+ console.log(`Running typecheck in ${workspace} (${fileCount} files)${isRetry ? " (retry)" : ""}...`);
58
+ }
59
+ const workspacePath = join(root, workspace);
60
+ let success = false;
61
+ let stdout = "";
62
+ let stderr = "";
63
+ try {
64
+ const output = execSync("bun run typecheck", {
65
+ cwd: workspacePath,
66
+ encoding: "utf-8",
67
+ stdio: ["pipe", "pipe", "pipe"]
68
+ });
69
+ stdout = output ?? "";
70
+ success = true;
71
+ } catch (error) {
72
+ const execError = error;
73
+ stdout = execError.stdout ?? "";
74
+ stderr = execError.stderr ?? "";
75
+ success = false;
76
+ }
77
+ const duration = Number(((performance.now() - startTime) / 1000).toFixed(2));
78
+ let errorOutput;
79
+ if (!success) {
80
+ const parts = [stdout.trim(), stderr.trim()].filter(Boolean);
81
+ errorOutput = parts.length > 0 ? parts.join(`
82
+ `) : undefined;
83
+ if (!isRetry && errorOutput && isCorruptedCacheError(errorOutput)) {
84
+ await clearTsBuildInfo(workspacePath, verbose);
85
+ return runSingleTypecheck(workspace, fileCount, root, verbose, true);
86
+ }
87
+ }
88
+ return { workspace, duration, success, fileCount, errorOutput };
89
+ }
90
+ async function discoverWorkspaces(patterns, root) {
91
+ const workspaces = [];
92
+ for (const pattern of patterns) {
93
+ const matches = await fg(`${pattern}/package.json`, { cwd: root });
94
+ for (const match of matches) {
95
+ const pkgPath = match.replace("/package.json", "");
96
+ try {
97
+ const pkgJsonContent = readFileSync(join(root, match), "utf-8");
98
+ const pkgJson = JSON.parse(pkgJsonContent);
99
+ if (pkgJson.scripts?.typecheck) {
100
+ const fileCount = await countTypeScriptFiles(pkgPath, root);
101
+ workspaces.push({ path: pkgPath, fileCount });
102
+ }
103
+ } catch {}
104
+ }
105
+ }
106
+ workspaces.sort((a, b) => a.fileCount - b.fileCount);
107
+ return workspaces;
108
+ }
109
+ async function runWorkspaceTypecheck(options = {}) {
110
+ const {
111
+ root = process.cwd(),
112
+ patterns = DEFAULT_PATTERNS,
113
+ concurrency = DEFAULT_CONCURRENCY,
114
+ verbose = true
115
+ } = options;
116
+ const workspaces = await discoverWorkspaces(patterns, root);
117
+ if (workspaces.length === 0) {
118
+ if (verbose) {
119
+ console.log("No workspaces with typecheck script found.");
120
+ }
121
+ return {
122
+ success: true,
123
+ totalDuration: 0,
124
+ totalFiles: 0,
125
+ workspaceCount: 0,
126
+ results: []
127
+ };
128
+ }
129
+ const totalStartTime = performance.now();
130
+ if (verbose) {
131
+ console.log(`Running typecheck across ${workspaces.length} workspaces with concurrency limit of ${concurrency}...
132
+ `);
133
+ }
134
+ const results = [];
135
+ const running = new Set;
136
+ for (let i = 0;i < workspaces.length; i++) {
137
+ const { path, fileCount } = workspaces[i];
138
+ const promise = runSingleTypecheck(path, fileCount, root, verbose).then((result) => {
139
+ results[i] = result;
140
+ running.delete(promise);
141
+ if (verbose) {
142
+ const icon = result.success ? "✅" : "❌";
143
+ const log = result.success ? console.log : console.error;
144
+ log(`${icon} ${result.workspace} (${result.fileCount} files) ${result.success ? "completed" : "failed"} in ${result.duration.toFixed(2)}s`);
145
+ if (!result.success && result.errorOutput) {
146
+ console.error(`
147
+ ${formatErrorOutput(result.errorOutput)}`);
148
+ }
149
+ }
150
+ });
151
+ running.add(promise);
152
+ if (running.size >= concurrency) {
153
+ await Promise.race(running);
154
+ }
155
+ }
156
+ await Promise.all(running);
157
+ const totalDuration = Number(((performance.now() - totalStartTime) / 1000).toFixed(2));
158
+ const totalFiles = workspaces.reduce((sum, w) => sum + w.fileCount, 0);
159
+ const success = results.every((r) => r.success);
160
+ if (verbose) {
161
+ if (success) {
162
+ console.log(`
163
+ All typecheck checks passed! Total time: ${totalDuration}s (${totalFiles} files)`);
164
+ } else {
165
+ console.error(`
166
+ Typecheck failed. Total time: ${totalDuration}s`);
167
+ }
168
+ }
169
+ return {
170
+ success,
171
+ totalDuration,
172
+ totalFiles,
173
+ workspaceCount: workspaces.length,
174
+ results
175
+ };
176
+ }
177
+ export { runWorkspaceTypecheck };