buncargo 3.0.0 → 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 (43) hide show
  1. package/dist/cli/bin.js +10 -8
  2. package/dist/cli/index.js +2 -2
  3. package/dist/cli/run-cli.d.ts +10 -2
  4. package/dist/core/quick-tunnel/cloudflared-process.d.ts +10 -0
  5. package/dist/core/quick-tunnel/constants.d.ts +9 -0
  6. package/dist/core/quick-tunnel/index.d.ts +17 -0
  7. package/dist/core/quick-tunnel/install.d.ts +1 -0
  8. package/dist/core/tunnel.d.ts +3 -2
  9. package/dist/environment/index.js +2 -2
  10. package/dist/environment/logging.d.ts +6 -6
  11. package/dist/environment/only-apps.d.ts +10 -0
  12. package/dist/index-3eyrdxw9.js +577 -0
  13. package/dist/index-5aq985p4.js +250 -0
  14. package/dist/index-6cmex7m5.js +72 -0
  15. package/dist/index-6d6x175r.js +572 -0
  16. package/dist/index-7v19es2e.js +666 -0
  17. package/dist/index-9wyhzw0h.js +574 -0
  18. package/dist/index-ag90ry8t.js +576 -0
  19. package/dist/index-byeqyjrz.js +72 -0
  20. package/dist/index-enj4zdma.js +574 -0
  21. package/dist/index-k370bech.js +72 -0
  22. package/dist/index-qa8akv6y.js +666 -0
  23. package/dist/index-vg55rq0y.js +250 -0
  24. package/dist/index-vs81yaks.js +244 -0
  25. package/dist/index-x54nbgs7.js +355 -0
  26. package/dist/index-yz4jfz7z.js +338 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +9 -8
  29. package/dist/loader/index.js +3 -3
  30. package/dist/types/all-types.d.ts +46 -3
  31. package/package.json +147 -145
  32. package/readme.md +16 -0
  33. package/src/cli/run-cli.ts +27 -12
  34. package/src/core/quick-tunnel/cloudflared-process.ts +83 -0
  35. package/src/core/quick-tunnel/constants.ts +31 -0
  36. package/src/core/quick-tunnel/index.ts +96 -0
  37. package/src/core/quick-tunnel/install.ts +160 -0
  38. package/src/core/tunnel.ts +22 -8
  39. package/src/environment/create-dev-environment.ts +123 -13
  40. package/src/environment/logging.ts +34 -20
  41. package/src/environment/only-apps.ts +34 -0
  42. package/src/index.ts +3 -0
  43. package/src/types/all-types.ts +56 -3
@@ -0,0 +1,576 @@
1
+ import {
2
+ spawnWatchdog,
3
+ startHeartbeat,
4
+ stopHeartbeat
5
+ } from "./index-mam0bcyz.js";
6
+ import {
7
+ killProcessesOnAppPorts
8
+ } from "./index-mm412dkp.js";
9
+
10
+ // src/core/quick-tunnel/index.ts
11
+ import { existsSync } from "node:fs";
12
+ import { createInterface } from "node:readline";
13
+
14
+ // src/core/quick-tunnel/cloudflared-process.ts
15
+ import { spawn } from "node:child_process";
16
+
17
+ // src/core/quick-tunnel/constants.ts
18
+ import { tmpdir } from "node:os";
19
+ import path from "node:path";
20
+ var CLOUDFLARED_VERSION = process.env.CLOUDFLARED_VERSION || "2023.10.0";
21
+ var RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";
22
+ var cloudflaredBinPath = path.join(tmpdir(), "buncargo-cloudflared", process.platform === "win32" ? `cloudflared.${CLOUDFLARED_VERSION}.exe` : `cloudflared.${CLOUDFLARED_VERSION}`);
23
+ var cloudflaredNotice = `
24
+ \uD83D\uDD25 Your installation of cloudflared software constitutes a symbol of your signature
25
+ indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.
26
+
27
+ ❯ License: \`https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/\`
28
+ ❯ Terms: \`https://www.cloudflare.com/terms/\`
29
+ ❯ Privacy Policy: \`https://www.cloudflare.com/privacypolicy/\`
30
+ `;
31
+
32
+ // src/core/quick-tunnel/cloudflared-process.ts
33
+ var urlRegex = /\|\s+(https?:\/\/\S+)/;
34
+ function startCloudflaredTunnel(options) {
35
+ const args = ["tunnel"];
36
+ for (const [key, value] of Object.entries(options)) {
37
+ if (typeof value === "string") {
38
+ args.push(`${key}`, value);
39
+ } else if (typeof value === "number") {
40
+ args.push(`${key}`, value.toString());
41
+ } else if (value === null) {
42
+ args.push(`${key}`);
43
+ }
44
+ }
45
+ if (args.length === 1) {
46
+ args.push("--url", "localhost:8080");
47
+ }
48
+ const child = spawn(cloudflaredBinPath, args, {
49
+ stdio: ["ignore", "pipe", "pipe"]
50
+ });
51
+ if (process.env.DEBUG) {
52
+ child.stdout?.pipe(process.stdout);
53
+ child.stderr?.pipe(process.stderr);
54
+ }
55
+ let urlResolver;
56
+ let urlRejector;
57
+ const url = new Promise((resolve, reject) => {
58
+ urlResolver = resolve;
59
+ urlRejector = reject;
60
+ });
61
+ const parser = (data) => {
62
+ const str = data.toString();
63
+ const urlMatch = str.match(urlRegex);
64
+ if (urlMatch) {
65
+ urlResolver(urlMatch[1] ?? "");
66
+ }
67
+ };
68
+ child.stdout?.on("data", parser).on("error", urlRejector);
69
+ child.stderr?.on("data", parser).on("error", urlRejector);
70
+ const stop = () => child.kill("SIGINT");
71
+ return { url, child, stop };
72
+ }
73
+
74
+ // src/core/quick-tunnel/install.ts
75
+ import { execSync } from "node:child_process";
76
+ import fs from "node:fs";
77
+ import https from "node:https";
78
+ import path2 from "node:path";
79
+ var LINUX_URL = {
80
+ arm64: "cloudflared-linux-arm64",
81
+ arm: "cloudflared-linux-arm",
82
+ x64: "cloudflared-linux-amd64",
83
+ ia32: "cloudflared-linux-386"
84
+ };
85
+ var MACOS_URL = {
86
+ arm64: "cloudflared-darwin-amd64.tgz",
87
+ x64: "cloudflared-darwin-amd64.tgz"
88
+ };
89
+ var WINDOWS_URL = {
90
+ x64: "cloudflared-windows-amd64.exe",
91
+ ia32: "cloudflared-windows-386.exe"
92
+ };
93
+ function resolveBase(version) {
94
+ if (version === "latest") {
95
+ return `${RELEASE_BASE}latest/download/`;
96
+ }
97
+ return `${RELEASE_BASE}download/${version}/`;
98
+ }
99
+ function installCloudflared(to = cloudflaredBinPath, version = CLOUDFLARED_VERSION) {
100
+ switch (process.platform) {
101
+ case "linux": {
102
+ return installLinux(to, version);
103
+ }
104
+ case "darwin": {
105
+ return installMacos(to, version);
106
+ }
107
+ case "win32": {
108
+ return installWindows(to, version);
109
+ }
110
+ default: {
111
+ throw new Error(`Unsupported platform: ${process.platform}`);
112
+ }
113
+ }
114
+ }
115
+ async function installLinux(to, version = CLOUDFLARED_VERSION) {
116
+ const file = LINUX_URL[process.arch];
117
+ if (file === undefined) {
118
+ throw new Error(`Unsupported architecture: ${process.arch}`);
119
+ }
120
+ await download(resolveBase(version) + file, to);
121
+ fs.chmodSync(to, 493);
122
+ return to;
123
+ }
124
+ async function installMacos(to, version = CLOUDFLARED_VERSION) {
125
+ const file = MACOS_URL[process.arch];
126
+ if (file === undefined) {
127
+ throw new Error(`Unsupported architecture: ${process.arch}`);
128
+ }
129
+ await download(resolveBase(version) + file, `${to}.tgz`);
130
+ if (process.env.DEBUG) {
131
+ console.log(`Extracting to ${to}`);
132
+ }
133
+ execSync(`tar -xzf ${path2.basename(`${to}.tgz`)}`, {
134
+ cwd: path2.dirname(to)
135
+ });
136
+ fs.unlinkSync(`${to}.tgz`);
137
+ fs.renameSync(`${path2.dirname(to)}/cloudflared`, to);
138
+ return to;
139
+ }
140
+ async function installWindows(to, version = CLOUDFLARED_VERSION) {
141
+ const file = WINDOWS_URL[process.arch];
142
+ if (file === undefined) {
143
+ throw new Error(`Unsupported architecture: ${process.arch}`);
144
+ }
145
+ await download(resolveBase(version) + file, to);
146
+ return to;
147
+ }
148
+ function download(url, to, redirect = 0) {
149
+ if (redirect === 0) {
150
+ if (process.env.DEBUG) {
151
+ console.log(`Downloading ${url} to ${to}`);
152
+ }
153
+ } else if (process.env.DEBUG) {
154
+ console.log(`Redirecting to ${url}`);
155
+ }
156
+ return new Promise((resolve, reject) => {
157
+ if (!fs.existsSync(path2.dirname(to))) {
158
+ fs.mkdirSync(path2.dirname(to), { recursive: true });
159
+ }
160
+ let done = true;
161
+ const file = fs.createWriteStream(to);
162
+ const request = https.get(url, (res) => {
163
+ if (res.statusCode === 302 && res.headers.location !== undefined) {
164
+ const redirection = res.headers.location;
165
+ done = false;
166
+ file.close(() => {
167
+ download(redirection, to, redirect + 1).then(resolve, reject);
168
+ });
169
+ return;
170
+ }
171
+ res.pipe(file);
172
+ });
173
+ file.on("finish", () => {
174
+ if (done) {
175
+ file.close(() => {
176
+ resolve(to);
177
+ });
178
+ }
179
+ });
180
+ request.on("error", (err) => {
181
+ fs.unlink(to, () => {
182
+ reject(err);
183
+ });
184
+ });
185
+ file.on("error", (err) => {
186
+ fs.unlink(to, () => {
187
+ reject(err);
188
+ });
189
+ });
190
+ request.end();
191
+ });
192
+ }
193
+
194
+ // src/core/quick-tunnel/index.ts
195
+ function resolvedLocalUrl(opts) {
196
+ return opts.url ?? `${opts.protocol || "http"}://${opts.hostname ?? "localhost"}:${opts.port ?? 3000}`;
197
+ }
198
+ function envAcceptsCloudflareNotice() {
199
+ const v = process.env.BUNCARGO_ACCEPT_CLOUDFLARE_NOTICE;
200
+ const u = process.env.UNTUN_ACCEPT_CLOUDFLARE_NOTICE;
201
+ return v === "1" || v === "true" || u === "1" || u === "true";
202
+ }
203
+ async function promptInstallCloudflared() {
204
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
205
+ return false;
206
+ }
207
+ return new Promise((resolve) => {
208
+ const rl = createInterface({
209
+ input: process.stdin,
210
+ output: process.stdout
211
+ });
212
+ rl.question("Do you agree with the above terms and wish to install the binary from GitHub? (y/N) ", (answer) => {
213
+ rl.close();
214
+ resolve(/^y(es)?$/i.test(answer.trim()));
215
+ });
216
+ });
217
+ }
218
+ async function startQuickTunnel(opts) {
219
+ const url = resolvedLocalUrl(opts);
220
+ console.log(`Starting cloudflared tunnel to ${url}`);
221
+ if (!existsSync(cloudflaredBinPath)) {
222
+ console.log(cloudflaredNotice);
223
+ const canInstall = opts.acceptCloudflareNotice || envAcceptsCloudflareNotice() || await promptInstallCloudflared();
224
+ if (!canInstall) {
225
+ console.error("Skipping tunnel setup.");
226
+ return;
227
+ }
228
+ await installCloudflared();
229
+ }
230
+ const argEntries = [["--url", url]];
231
+ if (!opts.verifyTLS) {
232
+ argEntries.push(["--no-tls-verify", ""]);
233
+ }
234
+ const tunnel = startCloudflaredTunnel(Object.fromEntries(argEntries));
235
+ const cleanup = async () => {
236
+ tunnel.stop();
237
+ };
238
+ return {
239
+ getURL: async () => await tunnel.url,
240
+ close: cleanup
241
+ };
242
+ }
243
+
244
+ // src/core/tunnel.ts
245
+ function parseExposeNames(exposeValue) {
246
+ if (exposeValue === undefined)
247
+ return null;
248
+ const names = exposeValue.split(",").map((name) => name.trim()).filter(Boolean);
249
+ return new Set(names);
250
+ }
251
+ async function resolvePublicUrl(tunnel) {
252
+ if (typeof tunnel.getURL === "function") {
253
+ return await tunnel.getURL();
254
+ }
255
+ return tunnel.url ?? tunnel.publicUrl ?? tunnel.tunnelUrl ?? null;
256
+ }
257
+ function toCloseFn(tunnel) {
258
+ const close = tunnel.close ?? tunnel.stop ?? tunnel.destroy;
259
+ if (!close)
260
+ return async () => {};
261
+ return async () => {
262
+ await close();
263
+ };
264
+ }
265
+ function resolveExposeTargets(env, exposeValue) {
266
+ const requestedNames = parseExposeNames(exposeValue);
267
+ const knownTargets = new Map;
268
+ const enabledTargets = new Map;
269
+ for (const [name, config] of Object.entries(env.services)) {
270
+ const port = env.ports[name];
271
+ if (port === undefined)
272
+ continue;
273
+ const target = { kind: "service", name, port };
274
+ knownTargets.set(name, target);
275
+ if (config.expose === true) {
276
+ enabledTargets.set(name, target);
277
+ }
278
+ }
279
+ for (const [name, config] of Object.entries(env.apps)) {
280
+ const port = env.ports[name];
281
+ if (port === undefined)
282
+ continue;
283
+ const target = { kind: "app", name, port };
284
+ knownTargets.set(name, target);
285
+ if (config.expose === true) {
286
+ enabledTargets.set(name, target);
287
+ }
288
+ }
289
+ if (requestedNames === null) {
290
+ return {
291
+ targets: Array.from(enabledTargets.values()),
292
+ unknownNames: [],
293
+ notEnabledNames: []
294
+ };
295
+ }
296
+ const unknownNames = [];
297
+ const notEnabledNames = [];
298
+ const targets = [];
299
+ for (const name of requestedNames) {
300
+ if (!knownTargets.has(name)) {
301
+ unknownNames.push(name);
302
+ continue;
303
+ }
304
+ const enabledTarget = enabledTargets.get(name);
305
+ if (!enabledTarget) {
306
+ notEnabledNames.push(name);
307
+ continue;
308
+ }
309
+ targets.push(enabledTarget);
310
+ }
311
+ return { targets, unknownNames, notEnabledNames };
312
+ }
313
+ async function startPublicTunnels(targets, options = {}) {
314
+ const start = options.start ?? ((input) => startQuickTunnel(input));
315
+ const tunnels = [];
316
+ try {
317
+ for (const target of targets) {
318
+ const localUrl = `http://localhost:${target.port}`;
319
+ const tunnel = await start({
320
+ url: localUrl
321
+ });
322
+ if (tunnel === undefined) {
323
+ throw new Error(`Tunnel for "${target.name}" could not be started (cloudflared missing or install declined)`);
324
+ }
325
+ const publicUrl = await resolvePublicUrl(tunnel);
326
+ if (!publicUrl) {
327
+ throw new Error(`Tunnel for "${target.name}" did not provide a public URL`);
328
+ }
329
+ tunnels.push({
330
+ kind: target.kind,
331
+ name: target.name,
332
+ localUrl,
333
+ publicUrl,
334
+ close: toCloseFn(tunnel)
335
+ });
336
+ }
337
+ return tunnels;
338
+ } catch (error) {
339
+ await stopPublicTunnels(tunnels);
340
+ throw error;
341
+ }
342
+ }
343
+ async function stopPublicTunnels(tunnels) {
344
+ await Promise.allSettled(tunnels.map((tunnel) => tunnel.close()));
345
+ }
346
+
347
+ // src/cli/run-cli.ts
348
+ import { spawn as spawn2 } from "node:child_process";
349
+ var ACCEPTED_FLAGS = [
350
+ "--help",
351
+ "--down",
352
+ "--reset",
353
+ "--migrate",
354
+ "--seed",
355
+ "--up-only",
356
+ "--expose"
357
+ ];
358
+ function printHelp() {
359
+ console.log(`
360
+ Usage: buncargo dev [options]
361
+
362
+ Options:
363
+ --help Show this help message
364
+ --down Stop all containers
365
+ --reset Stop containers and remove volumes (fresh start)
366
+ --migrate Run migrations and exit
367
+ --seed Run migrations and seeders, then exit
368
+ --up-only Start containers and run migrations, then exit (no dev servers)
369
+ --expose Expose configured targets via public quick tunnels
370
+
371
+ Examples:
372
+ bun dev Start dev environment with all services
373
+ bun dev --seed Run migrations and seed the database
374
+ bun dev --down Stop all containers
375
+ bun dev --reset Stop containers and remove all data
376
+ bun dev --expose Expose all targets with expose: true
377
+ bun dev --expose=api,web Expose specific targets
378
+ `);
379
+ }
380
+ function getUnknownFlags(args) {
381
+ return args.filter((arg) => arg.startsWith("--") && !ACCEPTED_FLAGS.includes(arg.includes("=") ? arg.split("=")[0] : arg));
382
+ }
383
+ async function runCli(env, options = {}) {
384
+ const {
385
+ args = process.argv.slice(2),
386
+ watchdog = true,
387
+ watchdogTimeout = 10,
388
+ devServersCommand
389
+ } = options;
390
+ const exposeRequested = hasFlag(args, "--expose") || args.some((arg) => arg.startsWith("--expose="));
391
+ const exposeValue = getFlagValue(args, "--expose");
392
+ let tunnels = [];
393
+ async function cleanupTunnels() {
394
+ env.clearPublicUrls();
395
+ if (tunnels.length === 0)
396
+ return;
397
+ await stopPublicTunnels(tunnels);
398
+ tunnels = [];
399
+ }
400
+ if (args.includes("--help")) {
401
+ printHelp();
402
+ process.exit(0);
403
+ }
404
+ const unknownFlags = getUnknownFlags(args);
405
+ if (unknownFlags.length > 0) {
406
+ console.error(`❌ Unknown flag${unknownFlags.length > 1 ? "s" : ""}: ${unknownFlags.join(", ")}`);
407
+ console.error("");
408
+ printHelp();
409
+ process.exit(1);
410
+ }
411
+ if (args.includes("--down")) {
412
+ env.logInfo();
413
+ await cleanupTunnels();
414
+ await env.stop();
415
+ process.exit(0);
416
+ }
417
+ if (args.includes("--reset")) {
418
+ env.logInfo();
419
+ await cleanupTunnels();
420
+ await env.stop({ removeVolumes: true });
421
+ process.exit(0);
422
+ }
423
+ const skipSeed = args.includes("--seed");
424
+ await env.start({
425
+ startServers: false,
426
+ wait: true,
427
+ skipSeed,
428
+ skipEnvironmentLog: exposeRequested
429
+ });
430
+ if (exposeRequested) {
431
+ const { targets, unknownNames, notEnabledNames } = resolveExposeTargets(env, exposeValue);
432
+ if (unknownNames.length > 0) {
433
+ console.error(`❌ Unknown expose target${unknownNames.length > 1 ? "s" : ""}: ${unknownNames.join(", ")}`);
434
+ await cleanupTunnels();
435
+ process.exit(1);
436
+ }
437
+ if (notEnabledNames.length > 0) {
438
+ console.error(`❌ Target${notEnabledNames.length > 1 ? "s" : ""} missing expose: true: ${notEnabledNames.join(", ")}`);
439
+ console.error(" Mark these in dev.config.ts with expose: true or remove them from --expose.");
440
+ await cleanupTunnels();
441
+ process.exit(1);
442
+ }
443
+ if (targets.length === 0) {
444
+ console.error("❌ No expose targets selected. Add expose: true to services/apps or pass names with --expose=<name>.");
445
+ await cleanupTunnels();
446
+ process.exit(1);
447
+ }
448
+ tunnels = await startPublicTunnels(targets);
449
+ env.setPublicUrls(Object.fromEntries(tunnels.map((tunnel) => [tunnel.name, tunnel.publicUrl])));
450
+ env.logInfo("Dev Environment", tunnels);
451
+ }
452
+ if (args.includes("--migrate")) {
453
+ console.log("");
454
+ console.log("✅ Migrations applied successfully");
455
+ await cleanupTunnels();
456
+ process.exit(0);
457
+ }
458
+ if (args.includes("--seed")) {
459
+ console.log("\uD83C\uDF31 Running seeders...");
460
+ const result = await env.exec("bun run run:seeder", {
461
+ throwOnError: false
462
+ });
463
+ if (result.exitCode !== 0) {
464
+ console.error("❌ Seeding failed");
465
+ if (result.stderr) {
466
+ console.error(result.stderr);
467
+ }
468
+ if (result.stdout) {
469
+ console.error(result.stdout);
470
+ }
471
+ await cleanupTunnels();
472
+ process.exit(1);
473
+ }
474
+ console.log("");
475
+ console.log("✅ Seeding complete");
476
+ await cleanupTunnels();
477
+ process.exit(0);
478
+ }
479
+ if (args.includes("--up-only")) {
480
+ console.log("");
481
+ console.log("✅ Containers started. Environment ready.");
482
+ console.log("");
483
+ await cleanupTunnels();
484
+ process.exit(0);
485
+ }
486
+ if (watchdog) {
487
+ await spawnWatchdog(env.projectName, env.root, {
488
+ timeoutMinutes: watchdogTimeout,
489
+ verbose: true,
490
+ composeFile: env.composeFile
491
+ });
492
+ startHeartbeat(env.projectName);
493
+ }
494
+ const command = devServersCommand ?? buildDevServersCommand(env.apps);
495
+ if (!command) {
496
+ console.log("✅ Containers ready. No apps configured.");
497
+ await new Promise(() => {});
498
+ await cleanupTunnels();
499
+ return;
500
+ }
501
+ await killProcessesOnAppPorts(env.apps, env.ports);
502
+ console.log("");
503
+ console.log("\uD83D\uDD27 Starting dev servers...");
504
+ console.log("");
505
+ await runCommand(command, env.root, env.buildEnvVars(), {
506
+ onSignal: async () => {
507
+ await cleanupTunnels();
508
+ stopHeartbeat();
509
+ }
510
+ });
511
+ stopHeartbeat();
512
+ await cleanupTunnels();
513
+ }
514
+ function buildDevServersCommand(apps) {
515
+ const appEntries = Object.entries(apps);
516
+ if (appEntries.length === 0)
517
+ return null;
518
+ const commands = [];
519
+ const names = [];
520
+ const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
521
+ for (const [name, config] of appEntries) {
522
+ names.push(name);
523
+ const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
524
+ commands.push(`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim());
525
+ }
526
+ const namesArg = `-n ${names.join(",")}`;
527
+ const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
528
+ const commandsArg = commands.join(" ");
529
+ return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
530
+ }
531
+ function runCommand(command, cwd, envVars, options = {}) {
532
+ const { onSignal } = options;
533
+ return new Promise((resolve, reject) => {
534
+ const proc = spawn2(command, [], {
535
+ cwd,
536
+ env: { ...process.env, ...envVars },
537
+ stdio: "inherit",
538
+ shell: true
539
+ });
540
+ proc.on("close", (code) => {
541
+ if (code === 0 || code === null) {
542
+ resolve();
543
+ } else {
544
+ reject(new Error(`Command exited with code ${code}`));
545
+ }
546
+ });
547
+ proc.on("error", reject);
548
+ const cleanup = () => {
549
+ if (onSignal) {
550
+ onSignal();
551
+ }
552
+ proc.kill("SIGTERM");
553
+ };
554
+ process.on("SIGINT", cleanup);
555
+ process.on("SIGTERM", cleanup);
556
+ });
557
+ }
558
+ function hasFlag(args, flag) {
559
+ return args.includes(flag);
560
+ }
561
+ function getFlagValue(args, flag) {
562
+ const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
563
+ if (prefixed) {
564
+ return prefixed.split("=")[1];
565
+ }
566
+ const index = args.indexOf(flag);
567
+ if (index !== -1 && index + 1 < args.length) {
568
+ const nextArg = args[index + 1];
569
+ if (nextArg !== undefined && !nextArg.startsWith("-")) {
570
+ return nextArg;
571
+ }
572
+ }
573
+ return;
574
+ }
575
+
576
+ export { resolveExposeTargets, startPublicTunnels, stopPublicTunnels, runCli, hasFlag, getFlagValue };
@@ -0,0 +1,72 @@
1
+ import {
2
+ createDevEnvironment
3
+ } from "./index-7v19es2e.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 };