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
@@ -0,0 +1,427 @@
1
+ // src/docker-compose/generated-file.ts
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
4
+
5
+ // src/docker-compose/services/define-docker-service.ts
6
+ function defineDockerService(input) {
7
+ function createPresetDefinition(service) {
8
+ return {
9
+ kind: "preset",
10
+ preset: input.preset,
11
+ service
12
+ };
13
+ }
14
+ function toServiceConfig(options = {}) {
15
+ const base = {
16
+ port: options.port ?? input.defaults.port,
17
+ healthCheck: options.healthCheck ?? input.defaults.healthCheck,
18
+ database: options.database,
19
+ user: options.user,
20
+ password: options.password,
21
+ serviceName: options.serviceName,
22
+ docker: createPresetDefinition(options.docker)
23
+ };
24
+ return input.enhanceServiceConfig ? input.enhanceServiceConfig(base, options) : base;
25
+ }
26
+ return {
27
+ preset: input.preset,
28
+ defaults: input.defaults,
29
+ build: input.build,
30
+ createPresetDefinition,
31
+ toServiceConfig
32
+ };
33
+ }
34
+
35
+ // src/docker-compose/services/shared.ts
36
+ var DEFAULT_HEALTHCHECK_SETTINGS = {
37
+ interval: "250ms",
38
+ timeout: "5s",
39
+ retries: 20
40
+ };
41
+ function getPortEnvName(portKey) {
42
+ return `${portKey.toUpperCase()}_PORT`;
43
+ }
44
+ function getDefaultPortBindings(serviceKey, config, preset) {
45
+ const envName = getPortEnvName(serviceKey);
46
+ const bindings = [];
47
+ const defaultInternalPort = preset === "postgres" ? 5432 : preset === "redis" ? 6379 : preset === "clickhouse" ? 8123 : config.port;
48
+ bindings.push(`\${${envName}:-${config.port}}:${defaultInternalPort}`);
49
+ if (config.secondaryPort !== undefined) {
50
+ const secondaryEnv = getPortEnvName(`${serviceKey}Secondary`);
51
+ const secondaryInternal = preset === "clickhouse" ? 9000 : config.secondaryPort;
52
+ bindings.push(`\${${secondaryEnv}:-${config.secondaryPort}}:${secondaryInternal}`);
53
+ }
54
+ return bindings;
55
+ }
56
+ function resolveHealthcheck(healthCheck, fallback, options) {
57
+ if (healthCheck === false)
58
+ return;
59
+ if (typeof healthCheck === "function")
60
+ return fallback;
61
+ if (!healthCheck)
62
+ return fallback;
63
+ switch (healthCheck) {
64
+ case "pg_isready":
65
+ return {
66
+ test: ["CMD-SHELL", `pg_isready -U ${options.user ?? "postgres"}`],
67
+ ...DEFAULT_HEALTHCHECK_SETTINGS
68
+ };
69
+ case "redis-cli":
70
+ return {
71
+ test: ["CMD", "redis-cli", "ping"],
72
+ ...DEFAULT_HEALTHCHECK_SETTINGS
73
+ };
74
+ case "http":
75
+ return {
76
+ test: [
77
+ "CMD-SHELL",
78
+ `wget -qO- http://127.0.0.1:${options.internalPort}/ping || exit 1`
79
+ ],
80
+ ...DEFAULT_HEALTHCHECK_SETTINGS
81
+ };
82
+ default:
83
+ return fallback;
84
+ }
85
+ }
86
+
87
+ // src/docker-compose/services/clickhouse.ts
88
+ var clickhouseDockerService = defineDockerService({
89
+ preset: "clickhouse",
90
+ defaults: {
91
+ port: 8123,
92
+ secondaryPort: 9000,
93
+ healthCheck: "http"
94
+ },
95
+ enhanceServiceConfig: (base, options) => ({
96
+ ...base,
97
+ secondaryPort: options.secondaryPort ?? 9000
98
+ }),
99
+ build: ({ serviceKey, config }) => {
100
+ const user = config.user ?? "default";
101
+ const password = config.password ?? "clickhouse";
102
+ const database = config.database ?? "default";
103
+ const defaultHealthcheck = {
104
+ test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8123/ping || exit 1"],
105
+ interval: "250ms",
106
+ timeout: "5s",
107
+ retries: 20
108
+ };
109
+ return {
110
+ service: {
111
+ image: "clickhouse/clickhouse-server:24-alpine",
112
+ ports: getDefaultPortBindings(serviceKey, config, "clickhouse"),
113
+ volumes: [`${serviceKey}_data:/var/lib/clickhouse`],
114
+ environment: {
115
+ CLICKHOUSE_USER: user,
116
+ CLICKHOUSE_PASSWORD: password,
117
+ CLICKHOUSE_DB: database
118
+ },
119
+ ulimits: {
120
+ nofile: {
121
+ soft: 262144,
122
+ hard: 262144
123
+ }
124
+ },
125
+ healthcheck: resolveHealthcheck(config.healthCheck, defaultHealthcheck, {
126
+ internalPort: 8123,
127
+ user
128
+ })
129
+ },
130
+ volume: `${serviceKey}_data`
131
+ };
132
+ }
133
+ });
134
+
135
+ // src/docker-compose/services/postgres.ts
136
+ var postgresDockerService = defineDockerService({
137
+ preset: "postgres",
138
+ defaults: {
139
+ port: 5432,
140
+ healthCheck: "pg_isready"
141
+ },
142
+ build: ({ serviceKey, config }) => {
143
+ const user = config.user ?? "postgres";
144
+ const password = config.password ?? "postgres";
145
+ const database = config.database ?? "postgres";
146
+ const defaultHealthcheck = {
147
+ test: ["CMD-SHELL", `pg_isready -U ${user}`],
148
+ interval: "250ms",
149
+ timeout: "5s",
150
+ retries: 20
151
+ };
152
+ return {
153
+ service: {
154
+ image: "pgvector/pgvector:pg16",
155
+ ports: getDefaultPortBindings(serviceKey, config, "postgres"),
156
+ volumes: [`${serviceKey}_data:/var/lib/postgresql/data`],
157
+ environment: {
158
+ POSTGRES_USER: user,
159
+ POSTGRES_PASSWORD: password,
160
+ POSTGRES_DB: database
161
+ },
162
+ healthcheck: resolveHealthcheck(config.healthCheck, defaultHealthcheck, {
163
+ internalPort: 5432,
164
+ user
165
+ })
166
+ },
167
+ volume: `${serviceKey}_data`
168
+ };
169
+ }
170
+ });
171
+
172
+ // src/docker-compose/services/redis.ts
173
+ var redisDockerService = defineDockerService({
174
+ preset: "redis",
175
+ defaults: {
176
+ port: 6379,
177
+ healthCheck: "redis-cli"
178
+ },
179
+ build: ({ serviceKey, config }) => {
180
+ const defaultHealthcheck = {
181
+ test: ["CMD", "redis-cli", "ping"],
182
+ interval: "250ms",
183
+ timeout: "5s",
184
+ retries: 20
185
+ };
186
+ return {
187
+ service: {
188
+ image: "redis:7-alpine",
189
+ ports: getDefaultPortBindings(serviceKey, config, "redis"),
190
+ healthcheck: resolveHealthcheck(config.healthCheck, defaultHealthcheck, {
191
+ internalPort: 6379
192
+ })
193
+ }
194
+ };
195
+ }
196
+ });
197
+
198
+ // src/docker-compose/services/index.ts
199
+ var PRESET_SERVICES = {
200
+ postgres: postgresDockerService,
201
+ redis: redisDockerService,
202
+ clickhouse: clickhouseDockerService
203
+ };
204
+ var service = {
205
+ postgres: postgresDockerService.toServiceConfig,
206
+ redis: redisDockerService.toServiceConfig,
207
+ clickhouse: clickhouseDockerService.toServiceConfig,
208
+ custom(options) {
209
+ return options;
210
+ }
211
+ };
212
+ function inferDockerPreset(serviceKey) {
213
+ const normalized = serviceKey.toLowerCase();
214
+ if (Object.hasOwn(PRESET_SERVICES, normalized)) {
215
+ return normalized;
216
+ }
217
+ return;
218
+ }
219
+ function buildPresetDockerService(preset, input) {
220
+ return PRESET_SERVICES[preset].build(input);
221
+ }
222
+
223
+ // src/docker-compose/model.ts
224
+ function isObject(value) {
225
+ return typeof value === "object" && value !== null && !Array.isArray(value);
226
+ }
227
+ function deepMergeNode(base, override) {
228
+ if (Array.isArray(base) || Array.isArray(override)) {
229
+ return override;
230
+ }
231
+ if (!isObject(base) || !isObject(override)) {
232
+ return override;
233
+ }
234
+ const merged = { ...base };
235
+ for (const key of Object.keys(override)) {
236
+ const baseValue = merged[key];
237
+ const overrideValue = override[key];
238
+ if (baseValue === undefined || overrideValue === undefined) {
239
+ merged[key] = overrideValue;
240
+ } else {
241
+ merged[key] = deepMergeNode(baseValue, overrideValue);
242
+ }
243
+ }
244
+ return merged;
245
+ }
246
+ function isPresetDefinition(value) {
247
+ return Boolean(value && typeof value === "object" && "kind" in value && value.kind === "preset");
248
+ }
249
+ function normalizeRawService(name, config, service2) {
250
+ const normalized = { ...service2 };
251
+ if (!normalized.ports || normalized.ports.length === 0) {
252
+ normalized.ports = getDefaultPortBindings(name, config);
253
+ }
254
+ if (config.healthCheck === false) {
255
+ delete normalized.healthcheck;
256
+ }
257
+ return normalized;
258
+ }
259
+ function normalizeServiceConfig(name, config) {
260
+ const serviceName = config.serviceName ?? name;
261
+ const rawDefinition = config.docker;
262
+ if (isPresetDefinition(rawDefinition)) {
263
+ return {
264
+ kind: "preset",
265
+ serviceName,
266
+ preset: rawDefinition.preset,
267
+ serviceOverride: rawDefinition.service
268
+ };
269
+ }
270
+ if (rawDefinition) {
271
+ const inferredPreset = inferDockerPreset(name);
272
+ if (inferredPreset) {
273
+ return {
274
+ kind: "preset",
275
+ serviceName,
276
+ preset: inferredPreset,
277
+ serviceOverride: rawDefinition
278
+ };
279
+ }
280
+ return {
281
+ kind: "raw",
282
+ serviceName,
283
+ service: normalizeRawService(name, config, rawDefinition)
284
+ };
285
+ }
286
+ const preset = inferDockerPreset(name);
287
+ if (!preset) {
288
+ throw new Error(`Service "${name}" has no docker preset and no docker definition. Add service.docker using helper or raw mode.`);
289
+ }
290
+ return {
291
+ kind: "preset",
292
+ serviceName,
293
+ preset
294
+ };
295
+ }
296
+ function resolveServiceDefinition(name, config) {
297
+ const normalized = normalizeServiceConfig(name, config);
298
+ if (normalized.kind === "raw") {
299
+ return {
300
+ serviceName: normalized.serviceName,
301
+ service: normalized.service
302
+ };
303
+ }
304
+ const { service: service2, volume } = buildPresetDockerService(normalized.preset, {
305
+ serviceKey: name,
306
+ config
307
+ });
308
+ const mergedService = normalized.serviceOverride ? deepMergeNode(service2, normalized.serviceOverride) : service2;
309
+ return {
310
+ serviceName: normalized.serviceName,
311
+ service: mergedService,
312
+ volume
313
+ };
314
+ }
315
+ function buildComposeModel(services, docker) {
316
+ const composeServices = {};
317
+ const composeVolumes = {};
318
+ for (const [name, serviceConfig] of Object.entries(services)) {
319
+ const { serviceName, service: service2, volume } = resolveServiceDefinition(name, serviceConfig);
320
+ composeServices[serviceName] = service2;
321
+ if (volume) {
322
+ composeVolumes[volume] = {};
323
+ }
324
+ }
325
+ for (const [volumeName, volume] of Object.entries(docker?.volumes ?? {})) {
326
+ composeVolumes[volumeName] = volume;
327
+ }
328
+ const document = {
329
+ services: composeServices
330
+ };
331
+ if (Object.keys(composeVolumes).length > 0) {
332
+ document.volumes = composeVolumes;
333
+ }
334
+ return document;
335
+ }
336
+
337
+ // src/docker-compose/yaml.ts
338
+ function isObject2(value) {
339
+ return typeof value === "object" && value !== null && !Array.isArray(value);
340
+ }
341
+ function formatScalar(value) {
342
+ if (value === null)
343
+ return "null";
344
+ if (typeof value === "string") {
345
+ return JSON.stringify(value);
346
+ }
347
+ return String(value);
348
+ }
349
+ function formatKey(key) {
350
+ return /^[A-Za-z_][A-Za-z0-9_-]*$/.test(key) ? key : JSON.stringify(key);
351
+ }
352
+ function sortNode(node) {
353
+ if (Array.isArray(node)) {
354
+ return node.map(sortNode);
355
+ }
356
+ if (isObject2(node)) {
357
+ const sorted = {};
358
+ for (const key of Object.keys(node).sort()) {
359
+ const value = node[key];
360
+ if (value !== undefined) {
361
+ sorted[key] = sortNode(value);
362
+ }
363
+ }
364
+ return sorted;
365
+ }
366
+ return node;
367
+ }
368
+ function stringifyNode(node, indent = 0) {
369
+ const prefix = " ".repeat(indent);
370
+ if (typeof node === "string" || typeof node === "number" || typeof node === "boolean" || node === null) {
371
+ return `${prefix}${formatScalar(node)}`;
372
+ }
373
+ if (Array.isArray(node)) {
374
+ if (node.length === 0)
375
+ return `${prefix}[]`;
376
+ return node.map((item) => {
377
+ const isNested = typeof item === "object" && item !== null;
378
+ if (!isNested) {
379
+ return `${prefix}- ${formatScalar(item)}`;
380
+ }
381
+ return `${prefix}-
382
+ ${stringifyNode(item, indent + 2)}`;
383
+ }).join(`
384
+ `);
385
+ }
386
+ const entries = Object.entries(node).filter(([, value]) => value !== undefined);
387
+ if (entries.length === 0)
388
+ return `${prefix}{}`;
389
+ return entries.map(([key, value]) => {
390
+ const formattedKey = formatKey(key);
391
+ const isNested = typeof value === "object" && value !== null;
392
+ if (!isNested) {
393
+ return `${prefix}${formattedKey}: ${formatScalar(value)}`;
394
+ }
395
+ return `${prefix}${formattedKey}:
396
+ ${stringifyNode(value, indent + 2)}`;
397
+ }).join(`
398
+ `);
399
+ }
400
+ function composeToYaml(document) {
401
+ const sorted = sortNode(document);
402
+ return `${stringifyNode(sorted)}
403
+ `;
404
+ }
405
+
406
+ // src/docker-compose/generated-file.ts
407
+ var DEFAULT_GENERATED_COMPOSE_FILE = ".buncargo/docker-compose.generated.yml";
408
+ function getGeneratedComposePath(root, docker) {
409
+ const generatedFile = docker?.generatedFile ?? DEFAULT_GENERATED_COMPOSE_FILE;
410
+ const absolutePath = isAbsolute(generatedFile) ? generatedFile : resolve(root, generatedFile);
411
+ const relativePath = relative(root, absolutePath);
412
+ const composeFileArg = relativePath && !relativePath.startsWith("..") ? relativePath : absolutePath;
413
+ return { absolutePath, composeFileArg };
414
+ }
415
+ function writeGeneratedComposeFile(root, services, docker) {
416
+ const { absolutePath, composeFileArg } = getGeneratedComposePath(root, docker);
417
+ const writeStrategy = docker?.writeStrategy ?? "always";
418
+ const shouldWrite = writeStrategy === "always" || !existsSync(absolutePath);
419
+ if (shouldWrite) {
420
+ const composeModel = buildComposeModel(services, docker);
421
+ const yaml = composeToYaml(composeModel);
422
+ mkdirSync(dirname(absolutePath), { recursive: true });
423
+ writeFileSync(absolutePath, yaml, "utf-8");
424
+ }
425
+ return composeFileArg;
426
+ }
427
+ export { service, buildComposeModel, composeToYaml, DEFAULT_GENERATED_COMPOSE_FILE, getGeneratedComposePath, writeGeneratedComposeFile };
@@ -0,0 +1,172 @@
1
+ // src/core/ports.ts
2
+ import { existsSync, readFileSync, statSync } from "node:fs";
3
+ import { basename, dirname, resolve } from "node:path";
4
+ function findMonorepoRoot(startDir) {
5
+ let dir = startDir ?? process.cwd();
6
+ while (dir !== "/") {
7
+ try {
8
+ const pkgPath = resolve(dir, "package.json");
9
+ if (existsSync(pkgPath)) {
10
+ const content = readFileSync(pkgPath, "utf-8");
11
+ const pkg = JSON.parse(content);
12
+ if (pkg.workspaces) {
13
+ return dir;
14
+ }
15
+ }
16
+ } catch {}
17
+ dir = dirname(dir);
18
+ }
19
+ return process.cwd();
20
+ }
21
+ function getWorktreeName(root) {
22
+ const monorepoRoot = root ?? findMonorepoRoot();
23
+ const gitPath = resolve(monorepoRoot, ".git");
24
+ try {
25
+ if (!existsSync(gitPath) || !statSync(gitPath).isFile())
26
+ return null;
27
+ const content = readFileSync(gitPath, "utf-8").trim();
28
+ const match = content.match(/^gitdir:\s*(.+)$/);
29
+ if (!match?.[1])
30
+ return null;
31
+ return basename(match[1]);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+ function isWorktree(root) {
37
+ return getWorktreeName(root) !== null;
38
+ }
39
+ function sanitizeProjectSuffix(value) {
40
+ return value.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
41
+ }
42
+ function getWorktreeProjectSuffix(root) {
43
+ const worktreeName = getWorktreeName(root);
44
+ if (!worktreeName)
45
+ return null;
46
+ const sanitized = sanitizeProjectSuffix(worktreeName);
47
+ return sanitized || "worktree";
48
+ }
49
+ function simpleHash(str) {
50
+ let hash = 0;
51
+ for (let i = 0;i < str.length; i++) {
52
+ const char = str.charCodeAt(i);
53
+ hash = (hash << 5) - hash + char;
54
+ hash = hash & hash;
55
+ }
56
+ return Math.abs(hash);
57
+ }
58
+ function calculatePortOffset(suffix, root) {
59
+ const worktreeName = getWorktreeName(root);
60
+ if (!worktreeName)
61
+ return 0;
62
+ const hashInput = suffix ? `${worktreeName}-${suffix}` : worktreeName;
63
+ return 10 + simpleHash(hashInput) % 90;
64
+ }
65
+ function getProjectName(prefix, suffix, root) {
66
+ const monorepoRoot = root ?? findMonorepoRoot();
67
+ const dirName = basename(monorepoRoot);
68
+ const baseName = `${prefix}-${dirName.toLowerCase().replace(/[^a-z0-9-]/g, "-")}`;
69
+ return suffix ? `${baseName}-${suffix}` : baseName;
70
+ }
71
+ function computeDevIdentity(options) {
72
+ const {
73
+ projectPrefix,
74
+ suffix,
75
+ root: providedRoot,
76
+ worktreeIsolation = true
77
+ } = options;
78
+ const root = providedRoot ?? findMonorepoRoot();
79
+ const worktree = isWorktree(root);
80
+ const worktreeSuffix = worktree && worktreeIsolation ? getWorktreeProjectSuffix(root) : null;
81
+ const projectSuffix = [suffix, worktreeSuffix].filter(Boolean).join("-") || undefined;
82
+ const projectName = getProjectName(projectPrefix, projectSuffix, root);
83
+ const portOffset = calculatePortOffset(suffix, root);
84
+ return {
85
+ worktree,
86
+ worktreeSuffix,
87
+ projectSuffix,
88
+ projectName,
89
+ portOffset
90
+ };
91
+ }
92
+ function computePorts(services, apps, offset) {
93
+ const ports = {};
94
+ for (const [name, config] of Object.entries(services)) {
95
+ ports[name] = config.port + offset;
96
+ if (config.secondaryPort) {
97
+ ports[`${name}Secondary`] = config.secondaryPort + offset;
98
+ }
99
+ }
100
+ if (apps) {
101
+ for (const [name, config] of Object.entries(apps)) {
102
+ ports[name] = config.port + offset;
103
+ }
104
+ }
105
+ return ports;
106
+ }
107
+ var SERVICE_DEFAULTS = {
108
+ postgres: { user: "postgres", password: "postgres", database: "postgres" },
109
+ postgresql: { user: "postgres", password: "postgres", database: "postgres" },
110
+ redis: { user: "", password: "", database: "" },
111
+ clickhouse: { user: "default", password: "clickhouse", database: "default" },
112
+ mysql: { user: "root", password: "root", database: "mysql" },
113
+ mongodb: { user: "", password: "", database: "" }
114
+ };
115
+ function buildServiceUrl(serviceName, ctx, config) {
116
+ const defaults = SERVICE_DEFAULTS[serviceName];
117
+ if (!defaults && !config.database)
118
+ return null;
119
+ const user = config.user ?? defaults?.user ?? "";
120
+ const password = config.password ?? defaults?.password ?? "";
121
+ const database = config.database ?? defaults?.database ?? "";
122
+ switch (serviceName) {
123
+ case "postgres":
124
+ case "postgresql":
125
+ return `postgresql://${user}:${password}@${ctx.host}:${ctx.port}/${database}`;
126
+ case "redis":
127
+ return `redis://${ctx.host}:${ctx.port}`;
128
+ case "clickhouse":
129
+ return `http://${user}:${password}@${ctx.host}:${ctx.port}/${database}`;
130
+ case "mysql":
131
+ return `mysql://${user}:${password}@${ctx.host}:${ctx.port}/${database}`;
132
+ case "mongodb":
133
+ return database ? `mongodb://${ctx.host}:${ctx.port}/${database}` : `mongodb://${ctx.host}:${ctx.port}`;
134
+ default:
135
+ return null;
136
+ }
137
+ }
138
+ function computeUrls(services, apps, ports, localIp) {
139
+ const urls = {};
140
+ const host = "localhost";
141
+ for (const [name, config] of Object.entries(services)) {
142
+ const port = ports[name];
143
+ const secondaryPort = ports[`${name}Secondary`];
144
+ if (port === undefined)
145
+ continue;
146
+ const ctx = { port, secondaryPort, host, localIp };
147
+ if (config.urlTemplate) {
148
+ urls[name] = config.urlTemplate(ctx);
149
+ } else {
150
+ const builtUrl = buildServiceUrl(name, { port, host }, {
151
+ database: config.database,
152
+ user: config.user,
153
+ password: config.password
154
+ });
155
+ if (builtUrl) {
156
+ urls[name] = builtUrl;
157
+ } else {
158
+ urls[name] = `http://${host}:${port}`;
159
+ }
160
+ }
161
+ }
162
+ if (apps) {
163
+ for (const [name, _config] of Object.entries(apps)) {
164
+ const port = ports[name];
165
+ urls[name] = `http://${host}:${port}`;
166
+ urls[`${name}Local`] = `http://${localIp}:${port}`;
167
+ }
168
+ }
169
+ return urls;
170
+ }
171
+
172
+ export { findMonorepoRoot, getWorktreeName, isWorktree, getWorktreeProjectSuffix, calculatePortOffset, getProjectName, computeDevIdentity, computePorts, computeUrls };
@@ -0,0 +1,72 @@
1
+ import {
2
+ createDevEnvironment
3
+ } from "./index-8bw1cmz4.js";
4
+
5
+ // src/loader/cache.ts
6
+ var cachedEnv = null;
7
+ function setCachedDevEnv(env) {
8
+ cachedEnv = env;
9
+ }
10
+ function getCachedDevEnv() {
11
+ return cachedEnv;
12
+ }
13
+ function clearDevEnvCache() {
14
+ cachedEnv = null;
15
+ }
16
+ // src/loader/find-config-file.ts
17
+ import { existsSync } from "node:fs";
18
+ import { dirname, join } from "node:path";
19
+ var CONFIG_FILES = [
20
+ "dev.config.ts",
21
+ "dev.config.js",
22
+ "dev-tools.config.ts",
23
+ "dev-tools.config.js"
24
+ ];
25
+ function findConfigFile(startDir) {
26
+ let currentDir = startDir;
27
+ while (true) {
28
+ for (const file of CONFIG_FILES) {
29
+ const configPath = join(currentDir, file);
30
+ if (existsSync(configPath)) {
31
+ return configPath;
32
+ }
33
+ }
34
+ const parentDir = dirname(currentDir);
35
+ if (parentDir === currentDir) {
36
+ return null;
37
+ }
38
+ currentDir = parentDir;
39
+ }
40
+ }
41
+ // src/loader/load-dev-env.ts
42
+ async function loadDevEnv(options) {
43
+ if (!options?.reload) {
44
+ const cached = getCachedDevEnv();
45
+ if (cached)
46
+ return cached;
47
+ }
48
+ const cwd = options?.cwd ?? process.cwd();
49
+ const configPath = findConfigFile(cwd);
50
+ if (configPath) {
51
+ const mod = await import(configPath);
52
+ const config = mod.default;
53
+ if (!config?.projectPrefix || !config?.services) {
54
+ throw new Error(`Invalid config in "${configPath}". Use defineDevConfig() and export as default.`);
55
+ }
56
+ const env = createDevEnvironment(config);
57
+ setCachedDevEnv(env);
58
+ return env;
59
+ }
60
+ throw new Error("No config file found. Create dev.config.ts with: export default defineDevConfig({ ... })");
61
+ }
62
+
63
+ // src/loader/index.ts
64
+ function getDevEnv() {
65
+ const env = getCachedDevEnv();
66
+ if (!env) {
67
+ throw new Error("Dev environment not loaded. Call loadDevEnv() first.");
68
+ }
69
+ return env;
70
+ }
71
+
72
+ export { clearDevEnvCache, CONFIG_FILES, findConfigFile, loadDevEnv, getDevEnv };