buncargo 3.2.0 → 3.2.3
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.
- package/dist/cli/bin.js +5 -5
- package/dist/cli/index.js +2 -2
- package/dist/environment/index.js +2 -2
- package/dist/index-bycj26kj.js +72 -0
- package/dist/index-mf4vjhm3.js +362 -0
- package/dist/index-n5g93an7.js +250 -0
- package/dist/index-n6z0qw70.js +666 -0
- package/dist/index.js +4 -4
- package/dist/loader/index.js +3 -3
- package/package.json +1 -1
- package/src/core/tunnel.ts +20 -8
package/dist/cli/bin.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import {
|
|
3
3
|
runCli
|
|
4
|
-
} from "../index-
|
|
4
|
+
} from "../index-n5g93an7.js";
|
|
5
5
|
import {
|
|
6
6
|
loadDevEnv
|
|
7
|
-
} from "../index-
|
|
8
|
-
import"../index-
|
|
7
|
+
} from "../index-bycj26kj.js";
|
|
8
|
+
import"../index-n6z0qw70.js";
|
|
9
9
|
import"../index-d8tyv5se.js";
|
|
10
10
|
import"../index-c0dr6mcv.js";
|
|
11
11
|
import"../index-fb29934k.js";
|
|
12
12
|
import"../index-5t9jxqm0.js";
|
|
13
|
-
import"../index-
|
|
13
|
+
import"../index-mf4vjhm3.js";
|
|
14
14
|
import"../index-mam0bcyz.js";
|
|
15
15
|
import"../index-mm412dkp.js";
|
|
16
16
|
import"../index-t0fj6gg1.js";
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
var require_package = __commonJS((exports, module) => {
|
|
24
24
|
module.exports = {
|
|
25
25
|
name: "buncargo",
|
|
26
|
-
version: "3.2.
|
|
26
|
+
version: "3.2.3",
|
|
27
27
|
description: "A Bun-powered development environment CLI for managing Docker Compose services, dev servers, and environment variables",
|
|
28
28
|
type: "module",
|
|
29
29
|
module: "./dist/index.js",
|
package/dist/cli/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
getFlagValue,
|
|
3
3
|
hasFlag,
|
|
4
4
|
runCli
|
|
5
|
-
} from "../index-
|
|
6
|
-
import"../index-
|
|
5
|
+
} from "../index-n5g93an7.js";
|
|
6
|
+
import"../index-mf4vjhm3.js";
|
|
7
7
|
import"../index-mam0bcyz.js";
|
|
8
8
|
import"../index-mm412dkp.js";
|
|
9
9
|
import"../index-qnx9j3qa.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createDevEnvironment
|
|
3
|
-
} from "../index-
|
|
3
|
+
} from "../index-n6z0qw70.js";
|
|
4
4
|
import"../index-d8tyv5se.js";
|
|
5
5
|
import"../index-c0dr6mcv.js";
|
|
6
6
|
import"../index-fb29934k.js";
|
|
7
7
|
import"../index-5t9jxqm0.js";
|
|
8
|
-
import"../index-
|
|
8
|
+
import"../index-mf4vjhm3.js";
|
|
9
9
|
import"../index-mam0bcyz.js";
|
|
10
10
|
import"../index-mm412dkp.js";
|
|
11
11
|
import"../index-t0fj6gg1.js";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDevEnvironment
|
|
3
|
+
} from "./index-n6z0qw70.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 };
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
// src/core/quick-tunnel/index.ts
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
|
|
5
|
+
// src/core/quick-tunnel/cloudflared-process.ts
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
// src/core/quick-tunnel/constants.ts
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
var CLOUDFLARED_VERSION = process.env.CLOUDFLARED_VERSION || "2023.10.0";
|
|
12
|
+
var RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";
|
|
13
|
+
var cloudflaredBinPath = path.join(tmpdir(), "buncargo-cloudflared", process.platform === "win32" ? `cloudflared.${CLOUDFLARED_VERSION}.exe` : `cloudflared.${CLOUDFLARED_VERSION}`);
|
|
14
|
+
var cloudflaredNotice = `
|
|
15
|
+
\uD83D\uDD25 Your installation of cloudflared software constitutes a symbol of your signature
|
|
16
|
+
indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.
|
|
17
|
+
|
|
18
|
+
❯ License: \`https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/\`
|
|
19
|
+
❯ Terms: \`https://www.cloudflare.com/terms/\`
|
|
20
|
+
❯ Privacy Policy: \`https://www.cloudflare.com/privacypolicy/\`
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
// src/core/quick-tunnel/cloudflared-process.ts
|
|
24
|
+
var urlRegex = /\|\s+(https?:\/\/\S+)/;
|
|
25
|
+
function startCloudflaredTunnel(options) {
|
|
26
|
+
const args = ["tunnel"];
|
|
27
|
+
for (const [key, value] of Object.entries(options)) {
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
args.push(`${key}`, value);
|
|
30
|
+
} else if (typeof value === "number") {
|
|
31
|
+
args.push(`${key}`, value.toString());
|
|
32
|
+
} else if (value === null) {
|
|
33
|
+
args.push(`${key}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (args.length === 1) {
|
|
37
|
+
args.push("--url", "localhost:8080");
|
|
38
|
+
}
|
|
39
|
+
const child = spawn(cloudflaredBinPath, args, {
|
|
40
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
41
|
+
});
|
|
42
|
+
if (process.env.DEBUG) {
|
|
43
|
+
child.stdout?.pipe(process.stdout);
|
|
44
|
+
child.stderr?.pipe(process.stderr);
|
|
45
|
+
}
|
|
46
|
+
let settled = false;
|
|
47
|
+
let urlResolver;
|
|
48
|
+
let urlRejector;
|
|
49
|
+
const url = new Promise((resolve, reject) => {
|
|
50
|
+
urlResolver = (v) => {
|
|
51
|
+
if (!settled) {
|
|
52
|
+
settled = true;
|
|
53
|
+
resolve(v);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
urlRejector = (e) => {
|
|
57
|
+
if (!settled) {
|
|
58
|
+
settled = true;
|
|
59
|
+
reject(e);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
const parser = (data) => {
|
|
64
|
+
const str = data.toString();
|
|
65
|
+
const urlMatch = str.match(urlRegex);
|
|
66
|
+
if (urlMatch) {
|
|
67
|
+
urlResolver(urlMatch[1] ?? "");
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
child.stdout?.on("data", parser).on("error", urlRejector);
|
|
71
|
+
child.stderr?.on("data", parser).on("error", urlRejector);
|
|
72
|
+
child.on("exit", (code, signal) => {
|
|
73
|
+
if (!settled) {
|
|
74
|
+
urlRejector(new Error(`cloudflared exited before a tunnel URL was parsed (code=${code}, signal=${signal ?? "none"})`));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
child.on("error", urlRejector);
|
|
78
|
+
const stop = () => child.kill("SIGINT");
|
|
79
|
+
return { url, child, stop };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/core/quick-tunnel/install.ts
|
|
83
|
+
import { execSync } from "node:child_process";
|
|
84
|
+
import fs from "node:fs";
|
|
85
|
+
import https from "node:https";
|
|
86
|
+
import path2 from "node:path";
|
|
87
|
+
var LINUX_URL = {
|
|
88
|
+
arm64: "cloudflared-linux-arm64",
|
|
89
|
+
arm: "cloudflared-linux-arm",
|
|
90
|
+
x64: "cloudflared-linux-amd64",
|
|
91
|
+
ia32: "cloudflared-linux-386"
|
|
92
|
+
};
|
|
93
|
+
var MACOS_URL = {
|
|
94
|
+
arm64: "cloudflared-darwin-amd64.tgz",
|
|
95
|
+
x64: "cloudflared-darwin-amd64.tgz"
|
|
96
|
+
};
|
|
97
|
+
var WINDOWS_URL = {
|
|
98
|
+
x64: "cloudflared-windows-amd64.exe",
|
|
99
|
+
ia32: "cloudflared-windows-386.exe"
|
|
100
|
+
};
|
|
101
|
+
function resolveBase(version) {
|
|
102
|
+
if (version === "latest") {
|
|
103
|
+
return `${RELEASE_BASE}latest/download/`;
|
|
104
|
+
}
|
|
105
|
+
return `${RELEASE_BASE}download/${version}/`;
|
|
106
|
+
}
|
|
107
|
+
function installCloudflared(to = cloudflaredBinPath, version = CLOUDFLARED_VERSION) {
|
|
108
|
+
switch (process.platform) {
|
|
109
|
+
case "linux": {
|
|
110
|
+
return installLinux(to, version);
|
|
111
|
+
}
|
|
112
|
+
case "darwin": {
|
|
113
|
+
return installMacos(to, version);
|
|
114
|
+
}
|
|
115
|
+
case "win32": {
|
|
116
|
+
return installWindows(to, version);
|
|
117
|
+
}
|
|
118
|
+
default: {
|
|
119
|
+
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function installLinux(to, version = CLOUDFLARED_VERSION) {
|
|
124
|
+
const file = LINUX_URL[process.arch];
|
|
125
|
+
if (file === undefined) {
|
|
126
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
127
|
+
}
|
|
128
|
+
await download(resolveBase(version) + file, to);
|
|
129
|
+
fs.chmodSync(to, 493);
|
|
130
|
+
return to;
|
|
131
|
+
}
|
|
132
|
+
async function installMacos(to, version = CLOUDFLARED_VERSION) {
|
|
133
|
+
const file = MACOS_URL[process.arch];
|
|
134
|
+
if (file === undefined) {
|
|
135
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
136
|
+
}
|
|
137
|
+
await download(resolveBase(version) + file, `${to}.tgz`);
|
|
138
|
+
if (process.env.DEBUG) {
|
|
139
|
+
console.log(`Extracting to ${to}`);
|
|
140
|
+
}
|
|
141
|
+
execSync(`tar -xzf ${path2.basename(`${to}.tgz`)}`, {
|
|
142
|
+
cwd: path2.dirname(to)
|
|
143
|
+
});
|
|
144
|
+
fs.unlinkSync(`${to}.tgz`);
|
|
145
|
+
fs.renameSync(`${path2.dirname(to)}/cloudflared`, to);
|
|
146
|
+
return to;
|
|
147
|
+
}
|
|
148
|
+
async function installWindows(to, version = CLOUDFLARED_VERSION) {
|
|
149
|
+
const file = WINDOWS_URL[process.arch];
|
|
150
|
+
if (file === undefined) {
|
|
151
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
152
|
+
}
|
|
153
|
+
await download(resolveBase(version) + file, to);
|
|
154
|
+
return to;
|
|
155
|
+
}
|
|
156
|
+
function download(url, to, redirect = 0) {
|
|
157
|
+
if (redirect === 0) {
|
|
158
|
+
if (process.env.DEBUG) {
|
|
159
|
+
console.log(`Downloading ${url} to ${to}`);
|
|
160
|
+
}
|
|
161
|
+
} else if (process.env.DEBUG) {
|
|
162
|
+
console.log(`Redirecting to ${url}`);
|
|
163
|
+
}
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
if (!fs.existsSync(path2.dirname(to))) {
|
|
166
|
+
fs.mkdirSync(path2.dirname(to), { recursive: true });
|
|
167
|
+
}
|
|
168
|
+
let done = true;
|
|
169
|
+
const file = fs.createWriteStream(to);
|
|
170
|
+
const request = https.get(url, (res) => {
|
|
171
|
+
if (res.statusCode === 302 && res.headers.location !== undefined) {
|
|
172
|
+
const redirection = res.headers.location;
|
|
173
|
+
done = false;
|
|
174
|
+
file.close(() => {
|
|
175
|
+
download(redirection, to, redirect + 1).then(resolve, reject);
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
res.pipe(file);
|
|
180
|
+
});
|
|
181
|
+
file.on("finish", () => {
|
|
182
|
+
if (done) {
|
|
183
|
+
file.close(() => {
|
|
184
|
+
resolve(to);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
request.on("error", (err) => {
|
|
189
|
+
fs.unlink(to, () => {
|
|
190
|
+
reject(err);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
file.on("error", (err) => {
|
|
194
|
+
fs.unlink(to, () => {
|
|
195
|
+
reject(err);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
request.end();
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/core/quick-tunnel/index.ts
|
|
203
|
+
function resolvedLocalUrl(opts) {
|
|
204
|
+
return opts.url ?? `${opts.protocol || "http"}://${opts.hostname ?? "localhost"}:${opts.port ?? 3000}`;
|
|
205
|
+
}
|
|
206
|
+
function envAcceptsCloudflareNotice() {
|
|
207
|
+
const v = process.env.BUNCARGO_ACCEPT_CLOUDFLARE_NOTICE;
|
|
208
|
+
const u = process.env.UNTUN_ACCEPT_CLOUDFLARE_NOTICE;
|
|
209
|
+
return v === "1" || v === "true" || u === "1" || u === "true";
|
|
210
|
+
}
|
|
211
|
+
async function promptInstallCloudflared() {
|
|
212
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return new Promise((resolve) => {
|
|
216
|
+
const rl = createInterface({
|
|
217
|
+
input: process.stdin,
|
|
218
|
+
output: process.stdout
|
|
219
|
+
});
|
|
220
|
+
rl.question("Do you agree with the above terms and wish to install the binary from GitHub? (y/N) ", (answer) => {
|
|
221
|
+
rl.close();
|
|
222
|
+
resolve(/^y(es)?$/i.test(answer.trim()));
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
async function startQuickTunnel(opts) {
|
|
227
|
+
const url = resolvedLocalUrl(opts);
|
|
228
|
+
console.log(`Starting cloudflared tunnel to ${url}`);
|
|
229
|
+
if (!existsSync(cloudflaredBinPath)) {
|
|
230
|
+
console.log(cloudflaredNotice);
|
|
231
|
+
const canInstall = opts.acceptCloudflareNotice || envAcceptsCloudflareNotice() || await promptInstallCloudflared();
|
|
232
|
+
if (!canInstall) {
|
|
233
|
+
console.error("Skipping tunnel setup.");
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
await installCloudflared();
|
|
237
|
+
}
|
|
238
|
+
const cfArgs = { "--url": url };
|
|
239
|
+
if (!opts.verifyTLS) {
|
|
240
|
+
cfArgs["--no-tls-verify"] = null;
|
|
241
|
+
}
|
|
242
|
+
const tunnel = startCloudflaredTunnel(cfArgs);
|
|
243
|
+
const cleanup = async () => {
|
|
244
|
+
tunnel.stop();
|
|
245
|
+
};
|
|
246
|
+
return {
|
|
247
|
+
getURL: async () => await tunnel.url,
|
|
248
|
+
close: cleanup
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/core/tunnel.ts
|
|
253
|
+
function parseExposeNames(exposeValue) {
|
|
254
|
+
if (exposeValue === undefined)
|
|
255
|
+
return null;
|
|
256
|
+
const names = exposeValue.split(",").map((name) => name.trim()).filter(Boolean);
|
|
257
|
+
return new Set(names);
|
|
258
|
+
}
|
|
259
|
+
async function resolvePublicUrl(tunnel) {
|
|
260
|
+
if (typeof tunnel.getURL === "function") {
|
|
261
|
+
return await tunnel.getURL();
|
|
262
|
+
}
|
|
263
|
+
return tunnel.url ?? tunnel.publicUrl ?? tunnel.tunnelUrl ?? null;
|
|
264
|
+
}
|
|
265
|
+
function toCloseFn(tunnel) {
|
|
266
|
+
const close = tunnel.close ?? tunnel.stop ?? tunnel.destroy;
|
|
267
|
+
if (!close)
|
|
268
|
+
return async () => {};
|
|
269
|
+
return async () => {
|
|
270
|
+
await close();
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function resolveExposeTargets(env, exposeValue) {
|
|
274
|
+
const requestedNames = parseExposeNames(exposeValue);
|
|
275
|
+
const knownTargets = new Map;
|
|
276
|
+
const enabledTargets = new Map;
|
|
277
|
+
for (const [name, config] of Object.entries(env.services)) {
|
|
278
|
+
const port = env.ports[name];
|
|
279
|
+
if (port === undefined)
|
|
280
|
+
continue;
|
|
281
|
+
const target = { kind: "service", name, port };
|
|
282
|
+
knownTargets.set(name, target);
|
|
283
|
+
if (config.expose === true) {
|
|
284
|
+
enabledTargets.set(name, target);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
for (const [name, config] of Object.entries(env.apps)) {
|
|
288
|
+
const port = env.ports[name];
|
|
289
|
+
if (port === undefined)
|
|
290
|
+
continue;
|
|
291
|
+
const target = { kind: "app", name, port };
|
|
292
|
+
knownTargets.set(name, target);
|
|
293
|
+
if (config.expose === true) {
|
|
294
|
+
enabledTargets.set(name, target);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (requestedNames === null) {
|
|
298
|
+
return {
|
|
299
|
+
targets: Array.from(enabledTargets.values()),
|
|
300
|
+
unknownNames: [],
|
|
301
|
+
notEnabledNames: []
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const unknownNames = [];
|
|
305
|
+
const notEnabledNames = [];
|
|
306
|
+
const targets = [];
|
|
307
|
+
for (const name of requestedNames) {
|
|
308
|
+
if (!knownTargets.has(name)) {
|
|
309
|
+
unknownNames.push(name);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const enabledTarget = enabledTargets.get(name);
|
|
313
|
+
if (!enabledTarget) {
|
|
314
|
+
notEnabledNames.push(name);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
targets.push(enabledTarget);
|
|
318
|
+
}
|
|
319
|
+
return { targets, unknownNames, notEnabledNames };
|
|
320
|
+
}
|
|
321
|
+
async function startPublicTunnels(targets, options = {}) {
|
|
322
|
+
const start = options.start ?? ((input) => startQuickTunnel(input));
|
|
323
|
+
const settled = await Promise.allSettled(targets.map(async (target) => {
|
|
324
|
+
const localUrl = `http://localhost:${target.port}`;
|
|
325
|
+
const tunnel = await start({
|
|
326
|
+
url: localUrl
|
|
327
|
+
});
|
|
328
|
+
if (tunnel === undefined) {
|
|
329
|
+
throw new Error(`Tunnel for "${target.name}" could not be started (cloudflared missing or install declined)`);
|
|
330
|
+
}
|
|
331
|
+
const publicUrl = await resolvePublicUrl(tunnel);
|
|
332
|
+
if (!publicUrl) {
|
|
333
|
+
throw new Error(`Tunnel for "${target.name}" did not provide a public URL`);
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
kind: target.kind,
|
|
337
|
+
name: target.name,
|
|
338
|
+
localUrl,
|
|
339
|
+
publicUrl,
|
|
340
|
+
close: toCloseFn(tunnel)
|
|
341
|
+
};
|
|
342
|
+
}));
|
|
343
|
+
const tunnels = [];
|
|
344
|
+
const errors = [];
|
|
345
|
+
for (const result of settled) {
|
|
346
|
+
if (result.status === "fulfilled") {
|
|
347
|
+
tunnels.push(result.value);
|
|
348
|
+
} else {
|
|
349
|
+
errors.push(result.reason);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (errors.length > 0) {
|
|
353
|
+
await stopPublicTunnels(tunnels);
|
|
354
|
+
throw errors[0];
|
|
355
|
+
}
|
|
356
|
+
return tunnels;
|
|
357
|
+
}
|
|
358
|
+
async function stopPublicTunnels(tunnels) {
|
|
359
|
+
await Promise.allSettled(tunnels.map((tunnel) => tunnel.close()));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export { resolveExposeTargets, startPublicTunnels, stopPublicTunnels };
|