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