@cloudflare/vite-plugin 2.0.0-rc.1 → 2.0.0-rc.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.
@@ -0,0 +1,656 @@
1
+ import { r as __toESM } from "./rolldown-runtime-kJ_i4yPo.mjs";
2
+ import { M as printBindings, V as convertConfigToBindings, c as require_picocolors, n as isTunnelOpen, r as toggleTunnel, t as extendTunnelExpiry } from "./tunnel-DPLA6vii.mjs";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import { fileURLToPath } from "node:url";
6
+ import os from "node:os";
7
+ import { promisify } from "node:util";
8
+ import process$1 from "node:process";
9
+ import { Buffer } from "node:buffer";
10
+ import fs$1, { constants as constants$1 } from "node:fs/promises";
11
+ import childProcess, { execFile } from "node:child_process";
12
+ import { convertToWranglerConfig } from "@cloudflare/config";
13
+ import { CorePaths, getDefaultDevRegistryPath, getWorkerRegistry } from "miniflare";
14
+ //#region ../../node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js
15
+ let isDockerCached;
16
+ function hasDockerEnv() {
17
+ try {
18
+ fs.statSync("/.dockerenv");
19
+ return true;
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+ function hasDockerCGroup() {
25
+ try {
26
+ return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+ function isDocker() {
32
+ if (isDockerCached === void 0) isDockerCached = hasDockerEnv() || hasDockerCGroup();
33
+ return isDockerCached;
34
+ }
35
+ //#endregion
36
+ //#region ../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
37
+ let cachedResult;
38
+ const hasContainerEnv = () => {
39
+ try {
40
+ fs.statSync("/run/.containerenv");
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ };
46
+ function isInsideContainer() {
47
+ if (cachedResult === void 0) cachedResult = hasContainerEnv() || isDocker();
48
+ return cachedResult;
49
+ }
50
+ //#endregion
51
+ //#region ../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
52
+ const isWsl = () => {
53
+ if (process$1.platform !== "linux") return false;
54
+ if (os.release().toLowerCase().includes("microsoft")) {
55
+ if (isInsideContainer()) return false;
56
+ return true;
57
+ }
58
+ try {
59
+ return fs.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isInsideContainer() : false;
60
+ } catch {
61
+ return false;
62
+ }
63
+ };
64
+ var is_wsl_default = process$1.env.__IS_WSL_TEST__ ? isWsl : isWsl();
65
+ //#endregion
66
+ //#region ../../node_modules/.pnpm/powershell-utils@0.1.0/node_modules/powershell-utils/index.js
67
+ const execFile$2 = promisify(childProcess.execFile);
68
+ const powerShellPath$1 = () => `${process$1.env.SYSTEMROOT || process$1.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
69
+ const executePowerShell = async (command, options = {}) => {
70
+ const { powerShellPath: psPath, ...execFileOptions } = options;
71
+ const encodedCommand = executePowerShell.encodeCommand(command);
72
+ return execFile$2(psPath ?? powerShellPath$1(), [...executePowerShell.argumentsPrefix, encodedCommand], {
73
+ encoding: "utf8",
74
+ ...execFileOptions
75
+ });
76
+ };
77
+ executePowerShell.argumentsPrefix = [
78
+ "-NoProfile",
79
+ "-NonInteractive",
80
+ "-ExecutionPolicy",
81
+ "Bypass",
82
+ "-EncodedCommand"
83
+ ];
84
+ executePowerShell.encodeCommand = (command) => Buffer.from(command, "utf16le").toString("base64");
85
+ executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
86
+ //#endregion
87
+ //#region ../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/utilities.js
88
+ function parseMountPointFromConfig(content) {
89
+ for (const line of content.split("\n")) {
90
+ if (/^\s*#/.test(line)) continue;
91
+ const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
92
+ if (!match) continue;
93
+ return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, "");
94
+ }
95
+ }
96
+ //#endregion
97
+ //#region ../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js
98
+ const execFile$1 = promisify(childProcess.execFile);
99
+ const wslDrivesMountPoint = (() => {
100
+ const defaultMountPoint = "/mnt/";
101
+ let mountPoint;
102
+ return async function() {
103
+ if (mountPoint) return mountPoint;
104
+ const configFilePath = "/etc/wsl.conf";
105
+ let isConfigFileExists = false;
106
+ try {
107
+ await fs$1.access(configFilePath, constants$1.F_OK);
108
+ isConfigFileExists = true;
109
+ } catch {}
110
+ if (!isConfigFileExists) return defaultMountPoint;
111
+ const parsedMountPoint = parseMountPointFromConfig(await fs$1.readFile(configFilePath, { encoding: "utf8" }));
112
+ if (parsedMountPoint === void 0) return defaultMountPoint;
113
+ mountPoint = parsedMountPoint;
114
+ mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
115
+ return mountPoint;
116
+ };
117
+ })();
118
+ const powerShellPathFromWsl = async () => {
119
+ return `${await wslDrivesMountPoint()}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
120
+ };
121
+ const powerShellPath = is_wsl_default ? powerShellPathFromWsl : powerShellPath$1;
122
+ let canAccessPowerShellPromise;
123
+ const canAccessPowerShell = async () => {
124
+ canAccessPowerShellPromise ??= (async () => {
125
+ try {
126
+ const psPath = await powerShellPath();
127
+ await fs$1.access(psPath, constants$1.X_OK);
128
+ return true;
129
+ } catch {
130
+ return false;
131
+ }
132
+ })();
133
+ return canAccessPowerShellPromise;
134
+ };
135
+ const wslDefaultBrowser = async () => {
136
+ const psPath = await powerShellPath();
137
+ const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
138
+ const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
139
+ return stdout.trim();
140
+ };
141
+ const convertWslPathToWindows = async (path) => {
142
+ if (/^[a-z]+:\/\//i.test(path)) return path;
143
+ try {
144
+ const { stdout } = await execFile$1("wslpath", ["-aw", path], { encoding: "utf8" });
145
+ return stdout.trim();
146
+ } catch {
147
+ return path;
148
+ }
149
+ };
150
+ //#endregion
151
+ //#region ../../node_modules/.pnpm/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js
152
+ function defineLazyProperty(object, propertyName, valueGetter) {
153
+ const define = (value) => Object.defineProperty(object, propertyName, {
154
+ value,
155
+ enumerable: true,
156
+ writable: true
157
+ });
158
+ Object.defineProperty(object, propertyName, {
159
+ configurable: true,
160
+ enumerable: true,
161
+ get() {
162
+ const result = valueGetter();
163
+ define(result);
164
+ return result;
165
+ },
166
+ set(value) {
167
+ define(value);
168
+ }
169
+ });
170
+ return object;
171
+ }
172
+ //#endregion
173
+ //#region ../../node_modules/.pnpm/default-browser-id@5.0.1/node_modules/default-browser-id/index.js
174
+ const execFileAsync$3 = promisify(execFile);
175
+ async function defaultBrowserId() {
176
+ if (process$1.platform !== "darwin") throw new Error("macOS only");
177
+ const { stdout } = await execFileAsync$3("defaults", [
178
+ "read",
179
+ "com.apple.LaunchServices/com.apple.launchservices.secure",
180
+ "LSHandlers"
181
+ ]);
182
+ const browserId = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout)?.groups.id ?? "com.apple.Safari";
183
+ if (browserId === "com.apple.safari") return "com.apple.Safari";
184
+ return browserId;
185
+ }
186
+ //#endregion
187
+ //#region ../../node_modules/.pnpm/run-applescript@7.1.0/node_modules/run-applescript/index.js
188
+ const execFileAsync$2 = promisify(execFile);
189
+ async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
190
+ if (process$1.platform !== "darwin") throw new Error("macOS only");
191
+ const outputArguments = humanReadableOutput ? [] : ["-ss"];
192
+ const execOptions = {};
193
+ if (signal) execOptions.signal = signal;
194
+ const { stdout } = await execFileAsync$2("osascript", [
195
+ "-e",
196
+ script,
197
+ outputArguments
198
+ ], execOptions);
199
+ return stdout.trim();
200
+ }
201
+ //#endregion
202
+ //#region ../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
203
+ async function bundleName(bundleId) {
204
+ return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
205
+ }
206
+ //#endregion
207
+ //#region ../../node_modules/.pnpm/default-browser@5.4.0/node_modules/default-browser/windows.js
208
+ const execFileAsync$1 = promisify(execFile);
209
+ const windowsBrowserProgIds = {
210
+ MSEdgeHTM: {
211
+ name: "Edge",
212
+ id: "com.microsoft.edge"
213
+ },
214
+ MSEdgeBHTML: {
215
+ name: "Edge Beta",
216
+ id: "com.microsoft.edge.beta"
217
+ },
218
+ MSEdgeDHTML: {
219
+ name: "Edge Dev",
220
+ id: "com.microsoft.edge.dev"
221
+ },
222
+ AppXq0fevzme2pys62n3e0fbqa7peapykr8v: {
223
+ name: "Edge",
224
+ id: "com.microsoft.edge.old"
225
+ },
226
+ ChromeHTML: {
227
+ name: "Chrome",
228
+ id: "com.google.chrome"
229
+ },
230
+ ChromeBHTML: {
231
+ name: "Chrome Beta",
232
+ id: "com.google.chrome.beta"
233
+ },
234
+ ChromeDHTML: {
235
+ name: "Chrome Dev",
236
+ id: "com.google.chrome.dev"
237
+ },
238
+ ChromiumHTM: {
239
+ name: "Chromium",
240
+ id: "org.chromium.Chromium"
241
+ },
242
+ BraveHTML: {
243
+ name: "Brave",
244
+ id: "com.brave.Browser"
245
+ },
246
+ BraveBHTML: {
247
+ name: "Brave Beta",
248
+ id: "com.brave.Browser.beta"
249
+ },
250
+ BraveDHTML: {
251
+ name: "Brave Dev",
252
+ id: "com.brave.Browser.dev"
253
+ },
254
+ BraveSSHTM: {
255
+ name: "Brave Nightly",
256
+ id: "com.brave.Browser.nightly"
257
+ },
258
+ FirefoxURL: {
259
+ name: "Firefox",
260
+ id: "org.mozilla.firefox"
261
+ },
262
+ OperaStable: {
263
+ name: "Opera",
264
+ id: "com.operasoftware.Opera"
265
+ },
266
+ VivaldiHTM: {
267
+ name: "Vivaldi",
268
+ id: "com.vivaldi.Vivaldi"
269
+ },
270
+ "IE.HTTP": {
271
+ name: "Internet Explorer",
272
+ id: "com.microsoft.ie"
273
+ }
274
+ };
275
+ const _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
276
+ var UnknownBrowserError = class extends Error {};
277
+ async function defaultBrowser$1(_execFileAsync = execFileAsync$1) {
278
+ const { stdout } = await _execFileAsync("reg", [
279
+ "QUERY",
280
+ " HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
281
+ "/v",
282
+ "ProgId"
283
+ ]);
284
+ const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
285
+ if (!match) throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
286
+ const { id } = match.groups;
287
+ const browser = windowsBrowserProgIds[id];
288
+ if (!browser) throw new UnknownBrowserError(`Unknown browser ID: ${id}`);
289
+ return browser;
290
+ }
291
+ //#endregion
292
+ //#region ../../node_modules/.pnpm/default-browser@5.4.0/node_modules/default-browser/index.js
293
+ const execFileAsync = promisify(execFile);
294
+ const titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
295
+ async function defaultBrowser() {
296
+ if (process$1.platform === "darwin") {
297
+ const id = await defaultBrowserId();
298
+ return {
299
+ name: await bundleName(id),
300
+ id
301
+ };
302
+ }
303
+ if (process$1.platform === "linux") {
304
+ const { stdout } = await execFileAsync("xdg-mime", [
305
+ "query",
306
+ "default",
307
+ "x-scheme-handler/http"
308
+ ]);
309
+ const id = stdout.trim();
310
+ return {
311
+ name: titleize(id.replace(/.desktop$/, "").replace("-", " ")),
312
+ id
313
+ };
314
+ }
315
+ if (process$1.platform === "win32") return defaultBrowser$1();
316
+ throw new Error("Only macOS, Linux, and Windows are supported");
317
+ }
318
+ //#endregion
319
+ //#region ../../node_modules/.pnpm/is-in-ssh@1.0.0/node_modules/is-in-ssh/index.js
320
+ const isInSsh = Boolean(process$1.env.SSH_CONNECTION || process$1.env.SSH_CLIENT || process$1.env.SSH_TTY);
321
+ //#endregion
322
+ //#region ../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js
323
+ const fallbackAttemptSymbol = Symbol("fallbackAttempt");
324
+ const __dirname = import.meta.url ? path.dirname(fileURLToPath(import.meta.url)) : "";
325
+ const localXdgOpenPath = path.join(__dirname, "xdg-open");
326
+ const { platform, arch: arch$1 } = process$1;
327
+ const tryEachApp = async (apps, opener) => {
328
+ if (apps.length === 0) return;
329
+ const errors = [];
330
+ for (const app of apps) try {
331
+ return await opener(app);
332
+ } catch (error) {
333
+ errors.push(error);
334
+ }
335
+ throw new AggregateError(errors, "Failed to open in all supported apps");
336
+ };
337
+ const baseOpen = async (options) => {
338
+ options = {
339
+ wait: false,
340
+ background: false,
341
+ newInstance: false,
342
+ allowNonzeroExitCode: false,
343
+ ...options
344
+ };
345
+ const isFallbackAttempt = options[fallbackAttemptSymbol] === true;
346
+ delete options[fallbackAttemptSymbol];
347
+ if (Array.isArray(options.app)) return tryEachApp(options.app, (singleApp) => baseOpen({
348
+ ...options,
349
+ app: singleApp,
350
+ [fallbackAttemptSymbol]: true
351
+ }));
352
+ let { name: app, arguments: appArguments = [] } = options.app ?? {};
353
+ appArguments = [...appArguments];
354
+ if (Array.isArray(app)) return tryEachApp(app, (appName) => baseOpen({
355
+ ...options,
356
+ app: {
357
+ name: appName,
358
+ arguments: appArguments
359
+ },
360
+ [fallbackAttemptSymbol]: true
361
+ }));
362
+ if (app === "browser" || app === "browserPrivate") {
363
+ const ids = {
364
+ "com.google.chrome": "chrome",
365
+ "google-chrome.desktop": "chrome",
366
+ "com.brave.browser": "brave",
367
+ "org.mozilla.firefox": "firefox",
368
+ "firefox.desktop": "firefox",
369
+ "com.microsoft.msedge": "edge",
370
+ "com.microsoft.edge": "edge",
371
+ "com.microsoft.edgemac": "edge",
372
+ "microsoft-edge.desktop": "edge",
373
+ "com.apple.safari": "safari"
374
+ };
375
+ const flags = {
376
+ chrome: "--incognito",
377
+ brave: "--incognito",
378
+ firefox: "--private-window",
379
+ edge: "--inPrivate"
380
+ };
381
+ let browser;
382
+ if (is_wsl_default) {
383
+ const progId = await wslDefaultBrowser();
384
+ browser = _windowsBrowserProgIdMap.get(progId) ?? {};
385
+ } else browser = await defaultBrowser();
386
+ if (browser.id in ids) {
387
+ const browserName = ids[browser.id.toLowerCase()];
388
+ if (app === "browserPrivate") {
389
+ if (browserName === "safari") throw new Error("Safari doesn't support opening in private mode via command line");
390
+ appArguments.push(flags[browserName]);
391
+ }
392
+ return baseOpen({
393
+ ...options,
394
+ app: {
395
+ name: apps[browserName],
396
+ arguments: appArguments
397
+ }
398
+ });
399
+ }
400
+ throw new Error(`${browser.name} is not supported as a default browser`);
401
+ }
402
+ let command;
403
+ const cliArguments = [];
404
+ const childProcessOptions = {};
405
+ let shouldUseWindowsInWsl = false;
406
+ if (is_wsl_default && !isInsideContainer() && !isInSsh && !app) shouldUseWindowsInWsl = await canAccessPowerShell();
407
+ if (platform === "darwin") {
408
+ command = "open";
409
+ if (options.wait) cliArguments.push("--wait-apps");
410
+ if (options.background) cliArguments.push("--background");
411
+ if (options.newInstance) cliArguments.push("--new");
412
+ if (app) cliArguments.push("-a", app);
413
+ } else if (platform === "win32" || shouldUseWindowsInWsl) {
414
+ command = await powerShellPath();
415
+ cliArguments.push(...executePowerShell.argumentsPrefix);
416
+ if (!is_wsl_default) childProcessOptions.windowsVerbatimArguments = true;
417
+ if (is_wsl_default && options.target) options.target = await convertWslPathToWindows(options.target);
418
+ const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
419
+ if (options.wait) encodedArguments.push("-Wait");
420
+ if (app) {
421
+ encodedArguments.push(executePowerShell.escapeArgument(app));
422
+ if (options.target) appArguments.push(options.target);
423
+ } else if (options.target) encodedArguments.push(executePowerShell.escapeArgument(options.target));
424
+ if (appArguments.length > 0) {
425
+ appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
426
+ encodedArguments.push("-ArgumentList", appArguments.join(","));
427
+ }
428
+ options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
429
+ if (!options.wait) childProcessOptions.stdio = "ignore";
430
+ } else {
431
+ if (app) command = app;
432
+ else {
433
+ const isBundled = !__dirname || __dirname === "/";
434
+ let exeLocalXdgOpen = false;
435
+ try {
436
+ await fs$1.access(localXdgOpenPath, constants$1.X_OK);
437
+ exeLocalXdgOpen = true;
438
+ } catch {}
439
+ command = process$1.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen) ? "xdg-open" : localXdgOpenPath;
440
+ }
441
+ if (appArguments.length > 0) cliArguments.push(...appArguments);
442
+ if (!options.wait) {
443
+ childProcessOptions.stdio = "ignore";
444
+ childProcessOptions.detached = true;
445
+ }
446
+ }
447
+ if (platform === "darwin" && appArguments.length > 0) cliArguments.push("--args", ...appArguments);
448
+ if (options.target) cliArguments.push(options.target);
449
+ const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
450
+ if (options.wait) return new Promise((resolve, reject) => {
451
+ subprocess.once("error", reject);
452
+ subprocess.once("close", (exitCode) => {
453
+ if (!options.allowNonzeroExitCode && exitCode !== 0) {
454
+ reject(/* @__PURE__ */ new Error(`Exited with code ${exitCode}`));
455
+ return;
456
+ }
457
+ resolve(subprocess);
458
+ });
459
+ });
460
+ if (isFallbackAttempt) return new Promise((resolve, reject) => {
461
+ subprocess.once("error", reject);
462
+ subprocess.once("spawn", () => {
463
+ subprocess.once("close", (exitCode) => {
464
+ subprocess.off("error", reject);
465
+ if (exitCode !== 0) {
466
+ reject(/* @__PURE__ */ new Error(`Exited with code ${exitCode}`));
467
+ return;
468
+ }
469
+ subprocess.unref();
470
+ resolve(subprocess);
471
+ });
472
+ });
473
+ });
474
+ subprocess.unref();
475
+ return new Promise((resolve, reject) => {
476
+ subprocess.once("error", reject);
477
+ subprocess.once("spawn", () => {
478
+ subprocess.off("error", reject);
479
+ resolve(subprocess);
480
+ });
481
+ });
482
+ };
483
+ const open = (target, options) => {
484
+ if (typeof target !== "string") throw new TypeError("Expected a `target`");
485
+ return baseOpen({
486
+ ...options,
487
+ target
488
+ });
489
+ };
490
+ function detectArchBinary(binary) {
491
+ if (typeof binary === "string" || Array.isArray(binary)) return binary;
492
+ const { [arch$1]: archBinary } = binary;
493
+ if (!archBinary) throw new Error(`${arch$1} is not supported`);
494
+ return archBinary;
495
+ }
496
+ function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
497
+ if (wsl && is_wsl_default) return detectArchBinary(wsl);
498
+ if (!platformBinary) throw new Error(`${platform} is not supported`);
499
+ return detectArchBinary(platformBinary);
500
+ }
501
+ const apps = {
502
+ browser: "browser",
503
+ browserPrivate: "browserPrivate"
504
+ };
505
+ defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
506
+ darwin: "google chrome",
507
+ win32: "chrome",
508
+ linux: [
509
+ "google-chrome",
510
+ "google-chrome-stable",
511
+ "chromium",
512
+ "chromium-browser"
513
+ ]
514
+ }, { wsl: {
515
+ ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
516
+ x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
517
+ } }));
518
+ defineLazyProperty(apps, "brave", () => detectPlatformBinary({
519
+ darwin: "brave browser",
520
+ win32: "brave",
521
+ linux: ["brave-browser", "brave"]
522
+ }, { wsl: {
523
+ ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
524
+ x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
525
+ } }));
526
+ defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
527
+ darwin: "firefox",
528
+ win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
529
+ linux: "firefox"
530
+ }, { wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe" }));
531
+ defineLazyProperty(apps, "edge", () => detectPlatformBinary({
532
+ darwin: "microsoft edge",
533
+ win32: "msedge",
534
+ linux: ["microsoft-edge", "microsoft-edge-dev"]
535
+ }, { wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" }));
536
+ defineLazyProperty(apps, "safari", () => detectPlatformBinary({ darwin: "Safari" }));
537
+ //#endregion
538
+ //#region src/plugins/shortcuts.ts
539
+ var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
540
+ function addShortcuts(server, ctx) {
541
+ if (!process.stdin.isTTY) return;
542
+ const registryPath = getDefaultDevRegistryPath();
543
+ const printBindingsShortcut = {
544
+ key: "b",
545
+ description: "list configured Cloudflare bindings",
546
+ action: (viteServer) => {
547
+ viteServer.config.logger.info("");
548
+ const workerConfigs = ctx.allWorkerConfigs;
549
+ for (const workerConfig of workerConfigs) {
550
+ const wranglerConfig = convertToWranglerConfig({
551
+ worker: workerConfig,
552
+ containers: []
553
+ });
554
+ const bindings = convertConfigToBindings({
555
+ ...wranglerConfig,
556
+ durable_objects: wranglerConfig.durable_objects === void 0 ? void 0 : {
557
+ ...wranglerConfig.durable_objects,
558
+ bindings: wranglerConfig.durable_objects.bindings ?? []
559
+ }
560
+ }, { usePreviewIds: true });
561
+ printBindings(bindings, {
562
+ tailConsumers: wranglerConfig.tail_consumers,
563
+ streamingTailConsumers: wranglerConfig.streaming_tail_consumers,
564
+ containers: getWorkerContainersForDisplay({
565
+ workerConfig,
566
+ containers: ctx.resolvedPluginConfig.containers
567
+ }),
568
+ warnIfNoBindings: true,
569
+ isMultiWorker: workerConfigs.length > 1,
570
+ name: workerConfig.name ?? "Your Worker",
571
+ registry: getWorkerRegistry(registryPath),
572
+ remoteBindingsDisabled: !ctx.resolvedPluginConfig.remoteBindings,
573
+ log: (message) => viteServer.config.logger.info(message)
574
+ });
575
+ }
576
+ }
577
+ };
578
+ const openExplorerShortcut = {
579
+ key: "e",
580
+ description: "open local explorer",
581
+ action: async (viteServer) => {
582
+ const url = viteServer.resolvedUrls?.local[0];
583
+ if (!url) {
584
+ viteServer.config.logger.warn("No local URL available");
585
+ return;
586
+ }
587
+ const explorerUrl = new URL(CorePaths.EXPLORER, url).href;
588
+ (await open(explorerUrl)).on("error", () => {
589
+ viteServer.config.logger.warn("Failed to open browser, the local explorer can be accessed at " + explorerUrl);
590
+ });
591
+ }
592
+ };
593
+ const toggleTunnelShortcut = {
594
+ key: "t",
595
+ description: "start or close tunnel",
596
+ action: () => {
597
+ toggleTunnel(server, ctx).catch((error) => {
598
+ const message = error instanceof Error ? error.message : String(error);
599
+ server.config.logger.error(import_picocolors.default.red(`Error: ${message}`));
600
+ });
601
+ }
602
+ };
603
+ const extendTunnelExpiryShortcut = {
604
+ key: "a",
605
+ description: "extend tunnel by 1 hour",
606
+ action: () => {
607
+ extendTunnelExpiry();
608
+ }
609
+ };
610
+ const bindCLIShortcuts = server.bindCLIShortcuts.bind(server);
611
+ server.bindCLIShortcuts = (options) => {
612
+ if (server.httpServer && process.stdin.isTTY && !process.env.CI && options?.print) {
613
+ if (ctx.allWorkerConfigs.length > 0) server.config.logger.info(import_picocolors.default.dim(import_picocolors.default.green(" ➜")) + import_picocolors.default.dim(" press ") + import_picocolors.default.bold(`${printBindingsShortcut.key} + enter`) + import_picocolors.default.dim(` to ${printBindingsShortcut.description}`));
614
+ server.config.logger.info(import_picocolors.default.dim(import_picocolors.default.green(" ➜")) + import_picocolors.default.dim(" press ") + import_picocolors.default.bold(`${openExplorerShortcut.key} + enter`) + import_picocolors.default.dim(` to ${openExplorerShortcut.description}`));
615
+ server.config.logger.info(import_picocolors.default.dim(import_picocolors.default.green(" ➜")) + import_picocolors.default.dim(" press ") + import_picocolors.default.bold(`${toggleTunnelShortcut.key} + enter`) + import_picocolors.default.dim(` to ${isTunnelOpen() ? "close tunnel" : "start tunnel"}`));
616
+ }
617
+ bindCLIShortcuts(options);
618
+ };
619
+ server.bindCLIShortcuts({ customShortcuts: [
620
+ printBindingsShortcut,
621
+ openExplorerShortcut,
622
+ toggleTunnelShortcut,
623
+ extendTunnelExpiryShortcut
624
+ ] });
625
+ }
626
+ /**
627
+ * Creates the small legacy display shape consumed by `printBindings` directly
628
+ * from input Container definitions and Worker export links.
629
+ */
630
+ function getWorkerContainersForDisplay(options) {
631
+ const containersByName = new Map(options.containers.map((container) => [container.name, container]));
632
+ const displayContainers = [];
633
+ for (const [className, workerExport] of Object.entries(options.workerConfig.exports ?? {})) {
634
+ if (workerExport.type !== "durable-object" || !("container" in workerExport) || workerExport.container === void 0) continue;
635
+ const container = containersByName.get(workerExport.container);
636
+ if (container === void 0) continue;
637
+ if (container.schedulingPolicy === "durable-object") {
638
+ displayContainers.push({
639
+ name: container.name,
640
+ class_name: className,
641
+ scheduling_policy: "durable_object"
642
+ });
643
+ continue;
644
+ }
645
+ const image = container.image;
646
+ displayContainers.push({
647
+ name: container.name,
648
+ class_name: className,
649
+ image: "dockerfile" in image ? image.dockerfile : "reference" in image ? image.reference : image.localReference,
650
+ scheduling_policy: container.schedulingPolicy
651
+ });
652
+ }
653
+ return displayContainers;
654
+ }
655
+ //#endregion
656
+ export { addShortcuts };