@cloudflare/vite-plugin 2.0.0-rc.2 → 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.
- package/README.md +12 -0
- package/dist/agent-hint-D03l5fox.mjs +460 -0
- package/dist/cloudflare-environment-BXKjrGi6.mjs +6996 -0
- package/dist/debug-DE5egPIY.mjs +14127 -0
- package/dist/dev-N174-pC7.mjs +132 -0
- package/dist/index.d.mts +26 -14
- package/dist/index.mjs +1222 -72175
- package/dist/misc-variables-6mf5dDi6-D3ykvtRq.mjs +487 -0
- package/dist/{package-ymw0HTMv.mjs → package-CQSyfSeK.mjs} +1 -1
- package/dist/preview-BB3ia074.mjs +45 -0
- package/dist/request-handler-BwLtd_Pc.mjs +263 -0
- package/dist/rolldown-runtime-kJ_i4yPo.mjs +26 -0
- package/dist/shortcuts-DCY2Yy2A.mjs +656 -0
- package/dist/tunnel-DPLA6vii.mjs +47436 -0
- package/dist/websockets-CTOLzpsa.mjs +2484 -0
- package/dist/workers/runner-worker/index.js +15 -11
- package/package.json +13 -13
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
//#region ../workers-utils/dist/errors.mjs
|
|
5
|
+
/**
|
|
6
|
+
* Base class for errors where the user has done something wrong. These are not
|
|
7
|
+
* reported to Sentry. API errors are intentionally *not* `UserError`s, and are
|
|
8
|
+
* reported to Sentry. This will help us understand which API errors need better
|
|
9
|
+
* messaging.
|
|
10
|
+
*/
|
|
11
|
+
var UserError = class extends Error {
|
|
12
|
+
telemetryMessage;
|
|
13
|
+
constructor(message, options) {
|
|
14
|
+
super(message, options);
|
|
15
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
16
|
+
this.telemetryMessage = typeof options?.telemetryMessage === "string" ? options.telemetryMessage : options?.telemetryMessage ? message : void 0;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var FatalError = class extends UserError {
|
|
20
|
+
code;
|
|
21
|
+
constructor(message, options) {
|
|
22
|
+
super(message, options);
|
|
23
|
+
this.code = options.code;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region ../workers-utils/dist/esm-Cme_8Aa5.mjs
|
|
28
|
+
function dedent(templ) {
|
|
29
|
+
var values = [];
|
|
30
|
+
for (var _i = 1; _i < arguments.length; _i++) values[_i - 1] = arguments[_i];
|
|
31
|
+
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
32
|
+
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
33
|
+
var indentLengths = strings.reduce(function(arr, str) {
|
|
34
|
+
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
35
|
+
if (matches) return arr.concat(matches.map(function(match) {
|
|
36
|
+
var _a;
|
|
37
|
+
var _b;
|
|
38
|
+
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
39
|
+
}));
|
|
40
|
+
return arr;
|
|
41
|
+
}, []);
|
|
42
|
+
if (indentLengths.length) {
|
|
43
|
+
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
|
|
44
|
+
strings = strings.map(function(str) {
|
|
45
|
+
return str.replace(pattern_1, "\n");
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
strings[0] = strings[0].replace(/^\r?\n/, "");
|
|
49
|
+
var string = strings[0];
|
|
50
|
+
values.forEach(function(value, i) {
|
|
51
|
+
var endentations = string.match(/(?:^|\n)( *)$/);
|
|
52
|
+
var endentation = endentations ? endentations[1] : "";
|
|
53
|
+
var indentedValue = value;
|
|
54
|
+
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map(function(str, i) {
|
|
55
|
+
return i === 0 ? str : "" + endentation + str;
|
|
56
|
+
}).join("\n");
|
|
57
|
+
string += indentedValue + strings[i + 1];
|
|
58
|
+
});
|
|
59
|
+
return string;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region ../workers-utils/dist/fs-helpers.mjs
|
|
63
|
+
/**
|
|
64
|
+
* Returns whether the given path is a directory
|
|
65
|
+
*
|
|
66
|
+
* Note: this function never throws; if the path does not exist or is inaccessible, it returns false.
|
|
67
|
+
*
|
|
68
|
+
* @param path The file system path to check
|
|
69
|
+
* @returns `true` if the path is a directory, `false` otherwise
|
|
70
|
+
*/
|
|
71
|
+
function isDirectory(path) {
|
|
72
|
+
return fs.statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Synchronously and recursively remove a directory, with retries for Windows compatibility.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link removeDir} for the async version and rationale.
|
|
78
|
+
*
|
|
79
|
+
* @param dirPath The directory path to remove
|
|
80
|
+
* @throws If the removal fails after retries, an error will be thrown
|
|
81
|
+
*/
|
|
82
|
+
function removeDirSync(dirPath) {
|
|
83
|
+
fs.rmSync(dirPath, {
|
|
84
|
+
recursive: true,
|
|
85
|
+
force: true,
|
|
86
|
+
maxRetries: 5,
|
|
87
|
+
retryDelay: 100
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region ../workers-utils/dist/global-wrangler-config-path-BTVRPIuP.mjs
|
|
92
|
+
/**
|
|
93
|
+
* @module
|
|
94
|
+
*
|
|
95
|
+
* A small, pure-ESM, dependency-free reimplementation of the subset of
|
|
96
|
+
* [`xdg-app-paths`](https://www.npmjs.com/package/xdg-app-paths) that this
|
|
97
|
+
* repository relies on.
|
|
98
|
+
*
|
|
99
|
+
* `xdg-app-paths` (and its `xdg-portable` / `os-paths` dependencies) ship as
|
|
100
|
+
* CommonJS. When the consuming package is bundled to ESM (e.g. via a bundler
|
|
101
|
+
* or when a downstream consumer runs through Vite), the CJS `require()` calls are
|
|
102
|
+
* shimmed and throw at runtime ("Dynamic require of 'path' is not supported").
|
|
103
|
+
* Vendoring the resolution logic here keeps the behaviour identical while
|
|
104
|
+
* remaining pure ESM.
|
|
105
|
+
*
|
|
106
|
+
* The path resolution intentionally mirrors `xdg-app-paths@8` →
|
|
107
|
+
* `xdg-portable@10` → `os-paths@7` exactly so that the resolved config/cache
|
|
108
|
+
* directories (which hold, amongst other things, Wrangler's auth credentials)
|
|
109
|
+
* do not change for existing users.
|
|
110
|
+
*
|
|
111
|
+
* ---
|
|
112
|
+
*
|
|
113
|
+
* This implementation is adapted from `xdg-app-paths`, `xdg-portable` and
|
|
114
|
+
* `os-paths` (https://github.com/rivy/js.xdg-app-paths), published under the
|
|
115
|
+
* MIT License:
|
|
116
|
+
*
|
|
117
|
+
* Copyright (c) Roy Ivy III <rivy.dev@gmail.com>
|
|
118
|
+
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
119
|
+
*
|
|
120
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
121
|
+
* copy of this software and associated documentation files (the "Software"),
|
|
122
|
+
* to deal in the Software without restriction, including without limitation
|
|
123
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
124
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
125
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
126
|
+
*
|
|
127
|
+
* The above copyright notice and this permission notice shall be included in
|
|
128
|
+
* all copies or substantial portions of the Software.
|
|
129
|
+
*
|
|
130
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
131
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
132
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
133
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
134
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
135
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
136
|
+
* DEALINGS IN THE SOFTWARE.
|
|
137
|
+
*/
|
|
138
|
+
function isWindows() {
|
|
139
|
+
return /^win/i.test(process.platform);
|
|
140
|
+
}
|
|
141
|
+
function isMacOS() {
|
|
142
|
+
return /^darwin$/i.test(process.platform);
|
|
143
|
+
}
|
|
144
|
+
function isNonEmpty(value) {
|
|
145
|
+
return !!value;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Read an OS/XDG environment variable. Accessed dynamically (mirroring
|
|
149
|
+
* `xdg-portable`'s `env.get()`) so these process-level variables don't need to
|
|
150
|
+
* be declared as build inputs (`turbo/no-undeclared-env-vars`) — they are not
|
|
151
|
+
* Wrangler configuration variables.
|
|
152
|
+
*/
|
|
153
|
+
function getEnv(name) {
|
|
154
|
+
return process.env[name];
|
|
155
|
+
}
|
|
156
|
+
/** Mirrors `os-paths`' `normalizePath`. */
|
|
157
|
+
function normalizePath(p) {
|
|
158
|
+
return p ? path.normalize(path.join(p, ".")) : void 0;
|
|
159
|
+
}
|
|
160
|
+
/** Mirrors `os-paths`' `home()`. */
|
|
161
|
+
function homeDir() {
|
|
162
|
+
if (isWindows()) return normalizePath([
|
|
163
|
+
os.homedir(),
|
|
164
|
+
getEnv("USERPROFILE"),
|
|
165
|
+
getEnv("HOME"),
|
|
166
|
+
getEnv("HOMEDRIVE") || getEnv("HOMEPATH") ? path.join(getEnv("HOMEDRIVE") ?? "", getEnv("HOMEPATH") ?? "") : void 0
|
|
167
|
+
].find(isNonEmpty));
|
|
168
|
+
return normalizePath(os.homedir() || getEnv("HOME"));
|
|
169
|
+
}
|
|
170
|
+
function joinToBase(base, segments) {
|
|
171
|
+
return base ? path.join(base, ...segments) : void 0;
|
|
172
|
+
}
|
|
173
|
+
/** Mirrors `os-paths`' `temp()`. */
|
|
174
|
+
function tempDir() {
|
|
175
|
+
if (isWindows()) {
|
|
176
|
+
const fallback = "C:\\Temp";
|
|
177
|
+
const found = [
|
|
178
|
+
() => os.tmpdir(),
|
|
179
|
+
() => getEnv("TEMP"),
|
|
180
|
+
() => getEnv("TMP"),
|
|
181
|
+
() => joinToBase(getEnv("LOCALAPPDATA"), ["Temp"]),
|
|
182
|
+
() => joinToBase(homeDir(), [
|
|
183
|
+
"AppData",
|
|
184
|
+
"Local",
|
|
185
|
+
"Temp"
|
|
186
|
+
]),
|
|
187
|
+
() => joinToBase(getEnv("ALLUSERSPROFILE"), ["Temp"]),
|
|
188
|
+
() => joinToBase(getEnv("SystemRoot"), ["Temp"]),
|
|
189
|
+
() => joinToBase(getEnv("windir"), ["Temp"]),
|
|
190
|
+
() => joinToBase(getEnv("SystemDrive"), ["\\", "Temp"])
|
|
191
|
+
].find((fn) => isNonEmpty(fn()));
|
|
192
|
+
return found && normalizePath(found()) || fallback;
|
|
193
|
+
}
|
|
194
|
+
return normalizePath([
|
|
195
|
+
os.tmpdir(),
|
|
196
|
+
getEnv("TMPDIR"),
|
|
197
|
+
getEnv("TEMP"),
|
|
198
|
+
getEnv("TMP")
|
|
199
|
+
].find(isNonEmpty)) || "/tmp";
|
|
200
|
+
}
|
|
201
|
+
/** Mirrors `xdg-portable`'s `baseDir()`. */
|
|
202
|
+
function baseDir() {
|
|
203
|
+
return homeDir() || tempDir();
|
|
204
|
+
}
|
|
205
|
+
/** Mirrors `xdg-portable`'s `valOrPath()`. */
|
|
206
|
+
function valOrPath(value, segments) {
|
|
207
|
+
return value || path.join(...segments);
|
|
208
|
+
}
|
|
209
|
+
function windowsAppData() {
|
|
210
|
+
return valOrPath(getEnv("APPDATA"), [
|
|
211
|
+
baseDir(),
|
|
212
|
+
"AppData",
|
|
213
|
+
"Roaming"
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
function windowsLocalAppData() {
|
|
217
|
+
return valOrPath(getEnv("LOCALAPPDATA"), [
|
|
218
|
+
baseDir(),
|
|
219
|
+
"AppData",
|
|
220
|
+
"Local"
|
|
221
|
+
]);
|
|
222
|
+
}
|
|
223
|
+
/** XDG config base directory (`xdg-portable`'s `config()`). */
|
|
224
|
+
function xdgConfig() {
|
|
225
|
+
if (isMacOS()) return valOrPath(getEnv("XDG_CONFIG_HOME"), [
|
|
226
|
+
baseDir(),
|
|
227
|
+
"Library",
|
|
228
|
+
"Preferences"
|
|
229
|
+
]);
|
|
230
|
+
if (isWindows()) return valOrPath(getEnv("XDG_CONFIG_HOME"), [windowsAppData(), "xdg.config"]);
|
|
231
|
+
return valOrPath(getEnv("XDG_CONFIG_HOME"), [baseDir(), ".config"]);
|
|
232
|
+
}
|
|
233
|
+
/** XDG cache base directory (`xdg-portable`'s `cache()`). */
|
|
234
|
+
function xdgCache() {
|
|
235
|
+
if (isMacOS()) return valOrPath(getEnv("XDG_CACHE_HOME"), [
|
|
236
|
+
baseDir(),
|
|
237
|
+
"Library",
|
|
238
|
+
"Caches"
|
|
239
|
+
]);
|
|
240
|
+
if (isWindows()) return valOrPath(getEnv("XDG_CACHE_HOME"), [windowsLocalAppData(), "xdg.cache"]);
|
|
241
|
+
return valOrPath(getEnv("XDG_CACHE_HOME"), [baseDir(), ".cache"]);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Resolve XDG-compliant application paths for the given application name.
|
|
245
|
+
*
|
|
246
|
+
* Equivalent to `xdgAppPaths(name)` with the default `isolated: true`, i.e. the
|
|
247
|
+
* application name is appended as the final path segment.
|
|
248
|
+
*/
|
|
249
|
+
function xdgAppPaths(name) {
|
|
250
|
+
const segment = path.parse(name).name;
|
|
251
|
+
return {
|
|
252
|
+
config: () => path.join(xdgConfig(), segment),
|
|
253
|
+
cache: () => path.join(xdgCache(), segment)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Resolve the global config directory for a Cloudflare CLI.
|
|
258
|
+
*
|
|
259
|
+
* Defaults to wrangler's directory (`.wrangler`) so existing callers are
|
|
260
|
+
* unaffected, but accepts an `appName` so other first-party CLIs (e.g. `cf`)
|
|
261
|
+
* can reuse the same XDG-compliant resolution under their own namespace.
|
|
262
|
+
*/
|
|
263
|
+
function getGlobalConfigPath({ appName = "wrangler", leadingDot = true, useLegacyHomeDir = true } = {}) {
|
|
264
|
+
const dirName = `${leadingDot ? "." : ""}${appName}`;
|
|
265
|
+
const configDir = xdgAppPaths(dirName).config();
|
|
266
|
+
if (useLegacyHomeDir) {
|
|
267
|
+
const legacyConfigDir = path.join(os.homedir(), dirName);
|
|
268
|
+
if (isDirectory(legacyConfigDir)) return legacyConfigDir;
|
|
269
|
+
}
|
|
270
|
+
return configDir;
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region ../workers-utils/dist/docker-path-WT3Hp50l.mjs
|
|
274
|
+
function getBooleanEnvironmentVariableFactory(options) {
|
|
275
|
+
return () => {
|
|
276
|
+
if (!(options.variableName in process.env) || process.env[options.variableName] === void 0) return typeof options.defaultValue === "function" ? options.defaultValue() : options.defaultValue;
|
|
277
|
+
switch (process.env[options.variableName]?.toLowerCase()) {
|
|
278
|
+
case "true": return true;
|
|
279
|
+
case "false": return false;
|
|
280
|
+
default: throw new UserError(`Expected ${options.variableName} to be "true" or "false", but got ${JSON.stringify(process.env[options.variableName])}`, { telemetryMessage: false });
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function getEnvironmentVariableFactory({ variableName, deprecatedName, choices, defaultValue }) {
|
|
285
|
+
let hasWarned = false;
|
|
286
|
+
return () => {
|
|
287
|
+
if (variableName in process.env) return getProcessEnv(variableName, choices);
|
|
288
|
+
if (deprecatedName && deprecatedName in process.env) {
|
|
289
|
+
if (!hasWarned) {
|
|
290
|
+
hasWarned = true;
|
|
291
|
+
console.warn(`Using "${deprecatedName}" environment variable. This is deprecated. Please use "${variableName}", instead.`);
|
|
292
|
+
}
|
|
293
|
+
return getProcessEnv(deprecatedName, choices);
|
|
294
|
+
}
|
|
295
|
+
return defaultValue?.();
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Get the value of an environment variable and check it is one of the choices.
|
|
300
|
+
*/
|
|
301
|
+
function getProcessEnv(variableName, choices) {
|
|
302
|
+
assertOneOf(choices, process.env[variableName]);
|
|
303
|
+
return process.env[variableName];
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Assert `value` is one of a list of `choices`.
|
|
307
|
+
*/
|
|
308
|
+
function assertOneOf(choices, value) {
|
|
309
|
+
if (Array.isArray(choices) && !choices.includes(value)) throw new UserError(`Expected ${JSON.stringify(value)} to be one of ${JSON.stringify(choices)}`, { telemetryMessage: false });
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Returns the configured path to the Docker binary.
|
|
313
|
+
*
|
|
314
|
+
* @returns The value of `WRANGLER_DOCKER_BIN`, or `docker` when unset.
|
|
315
|
+
*/
|
|
316
|
+
const getDockerPath = getEnvironmentVariableFactory({
|
|
317
|
+
variableName: "WRANGLER_DOCKER_BIN",
|
|
318
|
+
defaultValue() {
|
|
319
|
+
return "docker";
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
getEnvironmentVariableFactory({
|
|
323
|
+
variableName: "WRANGLER_C3_COMMAND",
|
|
324
|
+
defaultValue: () => "create cloudflare"
|
|
325
|
+
});
|
|
326
|
+
getEnvironmentVariableFactory({ variableName: "DO_NOT_TRACK" });
|
|
327
|
+
/**
|
|
328
|
+
* Set `WRANGLER_API_ENVIRONMENT` environment variable to "staging" to tell Wrangler to hit the staging APIs rather than production.
|
|
329
|
+
*/
|
|
330
|
+
const getCloudflareApiEnvironmentFromEnv = getEnvironmentVariableFactory({
|
|
331
|
+
variableName: "WRANGLER_API_ENVIRONMENT",
|
|
332
|
+
defaultValue: () => "production",
|
|
333
|
+
choices: ["production", "staging"]
|
|
334
|
+
});
|
|
335
|
+
/** Used for commands that explicitly do not support compliance regions other than "public" */
|
|
336
|
+
const COMPLIANCE_REGION_CONFIG_PUBLIC = { compliance_region: "public" };
|
|
337
|
+
/**
|
|
338
|
+
* Used for commands where there is no configuration available and
|
|
339
|
+
* we rely upon the CLOUDFLARE_COMPLIANCE_REGION environment variable
|
|
340
|
+
* to determine the compliance region.
|
|
341
|
+
*/
|
|
342
|
+
const COMPLIANCE_REGION_CONFIG_UNKNOWN = { compliance_region: void 0 };
|
|
343
|
+
const getCloudflareComplianceRegionFromEnv = getEnvironmentVariableFactory({
|
|
344
|
+
variableName: "CLOUDFLARE_COMPLIANCE_REGION",
|
|
345
|
+
choices: ["public", "fedramp_high"]
|
|
346
|
+
});
|
|
347
|
+
/**
|
|
348
|
+
* Set `CLOUDFLARE_COMPLIANCE_REGION` environment variable to "fedramp_high"
|
|
349
|
+
* or set the `compliance_region` property in the Wrangler configuration
|
|
350
|
+
* to tell Wrangler to run in FedRAMP High compliance region mode, rather than "public" mode.
|
|
351
|
+
*/
|
|
352
|
+
const getCloudflareComplianceRegion = (complianceConfig) => {
|
|
353
|
+
const complianceRegionFromEnv = getCloudflareComplianceRegionFromEnv();
|
|
354
|
+
if (complianceRegionFromEnv !== void 0 && complianceConfig?.compliance_region !== void 0 && complianceRegionFromEnv !== complianceConfig.compliance_region) throw new UserError(dedent`
|
|
355
|
+
The compliance region has been set to different values in two places:
|
|
356
|
+
- \`CLOUDFLARE_COMPLIANCE_REGION\` environment variable: \`${complianceRegionFromEnv}\`
|
|
357
|
+
- \`compliance_region\` configuration property: \`${complianceConfig.compliance_region}\`
|
|
358
|
+
`, { telemetryMessage: false });
|
|
359
|
+
return complianceRegionFromEnv || complianceConfig?.compliance_region || "public";
|
|
360
|
+
};
|
|
361
|
+
const getCloudflareApiBaseUrlFromEnv = getEnvironmentVariableFactory({
|
|
362
|
+
variableName: "CLOUDFLARE_API_BASE_URL",
|
|
363
|
+
deprecatedName: "CF_API_BASE_URL"
|
|
364
|
+
});
|
|
365
|
+
/**
|
|
366
|
+
* `CLOUDFLARE_API_BASE_URL` specifies the URL to the Cloudflare API.
|
|
367
|
+
*
|
|
368
|
+
* If this environment variable is not set, it will default to a URL computed from the
|
|
369
|
+
* Cloudflare compliance region and the API environment.
|
|
370
|
+
*/
|
|
371
|
+
const getCloudflareApiBaseUrl = (complianceConfig) => getCloudflareApiBaseUrlFromEnv() ?? `https://api${getComplianceRegionSubdomain(complianceConfig)}${getStagingSubdomain()}.cloudflare.com/client/v4`;
|
|
372
|
+
/**
|
|
373
|
+
* Compute the subdomain for the compliance region.
|
|
374
|
+
*/
|
|
375
|
+
function getComplianceRegionSubdomain(complianceConfig) {
|
|
376
|
+
return getCloudflareComplianceRegion(complianceConfig) === "fedramp_high" ? ".fed" : "";
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Compute the subdomain for the staging environment.
|
|
380
|
+
*/
|
|
381
|
+
function getStagingSubdomain() {
|
|
382
|
+
return getCloudflareApiEnvironmentFromEnv() === "staging" ? ".staging" : "";
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* `WRANGLER_LOG_SANITIZE` specifies whether we sanitize debug logs.
|
|
386
|
+
*
|
|
387
|
+
* By default we do, since debug logs could be added to GitHub issues and shouldn't include sensitive information.
|
|
388
|
+
*/
|
|
389
|
+
const getSanitizeLogs = getBooleanEnvironmentVariableFactory({
|
|
390
|
+
variableName: "WRANGLER_LOG_SANITIZE",
|
|
391
|
+
defaultValue: true
|
|
392
|
+
});
|
|
393
|
+
getEnvironmentVariableFactory({ variableName: "WRANGLER_OUTPUT_FILE_DIRECTORY" });
|
|
394
|
+
getEnvironmentVariableFactory({ variableName: "WRANGLER_OUTPUT_FILE_PATH" });
|
|
395
|
+
getEnvironmentVariableFactory({ variableName: "WRANGLER_CI_MATCH_TAG" });
|
|
396
|
+
/**
|
|
397
|
+
* `WRANGLER_CI_OVERRIDE_NAME` specifies a Worker name
|
|
398
|
+
*
|
|
399
|
+
* If this is set, Wrangler will override the Worker name with this one
|
|
400
|
+
*/
|
|
401
|
+
const getCIOverrideName = getEnvironmentVariableFactory({ variableName: "WRANGLER_CI_OVERRIDE_NAME" });
|
|
402
|
+
getEnvironmentVariableFactory({ variableName: "WRANGLER_CI_OVERRIDE_NETWORK_MODE_HOST" });
|
|
403
|
+
getEnvironmentVariableFactory({
|
|
404
|
+
variableName: "WRANGLER_CI_GENERATE_PREVIEW_ALIAS",
|
|
405
|
+
defaultValue: () => "false",
|
|
406
|
+
choices: ["true", "false"]
|
|
407
|
+
});
|
|
408
|
+
getEnvironmentVariableFactory({ variableName: "WORKERS_CI_BRANCH" });
|
|
409
|
+
getEnvironmentVariableFactory({ variableName: "WRANGLER_BUILD_CONDITIONS" });
|
|
410
|
+
getEnvironmentVariableFactory({ variableName: "WRANGLER_BUILD_PLATFORM" });
|
|
411
|
+
getEnvironmentVariableFactory({
|
|
412
|
+
variableName: "WRANGLER_REGISTRY_PATH",
|
|
413
|
+
defaultValue() {
|
|
414
|
+
return path.join(getGlobalConfigPath(), "registry");
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
getEnvironmentVariableFactory({ variableName: "WRANGLER_D1_EXTRA_LOCATION_CHOICES" });
|
|
418
|
+
const getTraceHeader = getEnvironmentVariableFactory({ variableName: "WRANGLER_TRACE_ID" });
|
|
419
|
+
getEnvironmentVariableFactory({ variableName: "CLOUDFLARE_ENV" });
|
|
420
|
+
getEnvironmentVariableFactory({ variableName: "OPEN_NEXT_DEPLOY" });
|
|
421
|
+
/**
|
|
422
|
+
* `X_LOCAL_EXPLORER` enables the local explorer UI at /cdn-cgi/local/explorer.
|
|
423
|
+
*/
|
|
424
|
+
const getLocalExplorerEnabledFromEnv = getBooleanEnvironmentVariableFactory({
|
|
425
|
+
variableName: "X_LOCAL_EXPLORER",
|
|
426
|
+
defaultValue: true
|
|
427
|
+
});
|
|
428
|
+
/**
|
|
429
|
+
* Experimental opt-in to extend Miniflare's `/cdn-cgi/` Host and Origin allowlist
|
|
430
|
+
* with Vite's resolved `server.allowedHosts` or `preview.allowedHosts`.
|
|
431
|
+
*
|
|
432
|
+
* Defaults to `false`. Enable only when every listed host should have access to
|
|
433
|
+
* Local Explorer APIs. Vite's `allowedHosts: true` retains the default allowlist.
|
|
434
|
+
*/
|
|
435
|
+
const getLocalExplorerUseViteAllowedHostsFromEnv = getBooleanEnvironmentVariableFactory({
|
|
436
|
+
variableName: "X_LOCAL_EXPLORER_USE_VITE_ALLOWED_HOSTS",
|
|
437
|
+
defaultValue: false
|
|
438
|
+
});
|
|
439
|
+
/**
|
|
440
|
+
* `X_LOCAL_OBSERVABILITY` turns on local-dev observability capture. Both
|
|
441
|
+
* `wrangler dev` and the Vite plugin read it and pass it through as the one
|
|
442
|
+
* `unsafeObservability` Miniflare option, which makes core attach the trace
|
|
443
|
+
* collector to each user worker.
|
|
444
|
+
*
|
|
445
|
+
* Defaults to `true` so the Local Explorer's Observability tab captures traces
|
|
446
|
+
* and logs out of the box. Set `X_LOCAL_OBSERVABILITY=false` to opt out — for
|
|
447
|
+
* example if the extra per-worker services (collector + streaming tail) cause
|
|
448
|
+
* trouble in a multi-process dev-registry setup.
|
|
449
|
+
*/
|
|
450
|
+
const getLocalObservabilityEnabledFromEnv = getBooleanEnvironmentVariableFactory({
|
|
451
|
+
variableName: "X_LOCAL_OBSERVABILITY",
|
|
452
|
+
defaultValue: true
|
|
453
|
+
});
|
|
454
|
+
/**
|
|
455
|
+
* `X_BROWSER_HEADFUL` opens the browser in headful (visible) mode when using the
|
|
456
|
+
* Browser Run API in local development.
|
|
457
|
+
*
|
|
458
|
+
* Set to "true" to enable:
|
|
459
|
+
*
|
|
460
|
+
* ```sh
|
|
461
|
+
* X_BROWSER_HEADFUL=true vite dev
|
|
462
|
+
* ```
|
|
463
|
+
*
|
|
464
|
+
* Note: when using `@cloudflare/playwright`, two Chrome windows may appear — the initial blank
|
|
465
|
+
* page and the one created by `browser.newPage()`. This is expected due to how Playwright handles
|
|
466
|
+
* browser contexts via CDP.
|
|
467
|
+
*/
|
|
468
|
+
const getBrowserRenderingHeadfulFromEnv = getBooleanEnvironmentVariableFactory({
|
|
469
|
+
variableName: "X_BROWSER_HEADFUL",
|
|
470
|
+
defaultValue: false
|
|
471
|
+
});
|
|
472
|
+
getEnvironmentVariableFactory({ variableName: "CLOUDFLARE_CF_FETCH_PATH" });
|
|
473
|
+
/**
|
|
474
|
+
* `WRANGLER_CACHE_DIR` specifies a custom directory for Wrangler's cache files.
|
|
475
|
+
* This overrides the default `node_modules/.cache/wrangler` location.
|
|
476
|
+
* Useful for Yarn PnP or projects without node_modules.
|
|
477
|
+
*/
|
|
478
|
+
const getWranglerCacheDirFromEnv = getEnvironmentVariableFactory({ variableName: "WRANGLER_CACHE_DIR" });
|
|
479
|
+
/**
|
|
480
|
+
* `CLOUDFLARED_PATH` specifies a custom path to a cloudflared binary.
|
|
481
|
+
*
|
|
482
|
+
* If set, Wrangler will use this cloudflared binary instead of downloading one.
|
|
483
|
+
* The path must point to an existing executable file.
|
|
484
|
+
*/
|
|
485
|
+
const getCloudflaredPathFromEnv = getEnvironmentVariableFactory({ variableName: "CLOUDFLARED_PATH" });
|
|
486
|
+
//#endregion
|
|
487
|
+
export { UserError as S, getDockerPath as _, getCloudflareApiBaseUrl as a, removeDirSync as b, getCloudflaredPathFromEnv as c, getLocalExplorerUseViteAllowedHostsFromEnv as d, getLocalObservabilityEnabledFromEnv as f, getBooleanEnvironmentVariableFactory as g, getWranglerCacheDirFromEnv as h, getCIOverrideName as i, getComplianceRegionSubdomain as l, getTraceHeader as m, COMPLIANCE_REGION_CONFIG_UNKNOWN as n, getCloudflareApiEnvironmentFromEnv as o, getSanitizeLogs as p, getBrowserRenderingHeadfulFromEnv as r, getCloudflareComplianceRegion as s, COMPLIANCE_REGION_CONFIG_PUBLIC as t, getLocalExplorerEnabledFromEnv as u, getEnvironmentVariableFactory as v, FatalError as x, getGlobalConfigPath as y };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { r as __toESM } from "./rolldown-runtime-kJ_i4yPo.mjs";
|
|
2
|
+
import { _ as getDockerPath } from "./misc-variables-6mf5dDi6-D3ykvtRq.mjs";
|
|
3
|
+
import { c as require_picocolors, f as assertIsPreview } from "./tunnel-DPLA6vii.mjs";
|
|
4
|
+
import { u as prepareContainerImagesForCfConfig } from "./debug-DE5egPIY.mjs";
|
|
5
|
+
import { r as getPreviewMiniflareOptions, t as handleWebSocket } from "./websockets-CTOLzpsa.mjs";
|
|
6
|
+
import { createRequestHandler } from "./request-handler-BwLtd_Pc.mjs";
|
|
7
|
+
import { buildPublicUrl } from "miniflare";
|
|
8
|
+
//#region src/plugins/preview.ts
|
|
9
|
+
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
10
|
+
/** Configure the Cloudflare runtime for Vite preview. */
|
|
11
|
+
async function configurePreviewServer(ctx, vitePreviewServer) {
|
|
12
|
+
assertIsPreview(ctx);
|
|
13
|
+
const closePreviewServer = vitePreviewServer.close.bind(vitePreviewServer);
|
|
14
|
+
vitePreviewServer.close = async () => {
|
|
15
|
+
await Promise.all([ctx.disposeMiniflare(), closePreviewServer()]);
|
|
16
|
+
};
|
|
17
|
+
const { miniflareOptions, containerOptions } = await getPreviewMiniflareOptions(ctx, vitePreviewServer);
|
|
18
|
+
await ctx.startOrUpdateMiniflare(miniflareOptions);
|
|
19
|
+
if (containerOptions !== void 0) {
|
|
20
|
+
vitePreviewServer.config.logger.info(import_picocolors.default.dim(import_picocolors.default.yellow("∷ Preparing Containers for local preview...\n")));
|
|
21
|
+
await prepareContainerImagesForCfConfig({
|
|
22
|
+
dockerPath: getDockerPath(),
|
|
23
|
+
containerOptions,
|
|
24
|
+
settings: ctx.resolvedPluginConfig.settings,
|
|
25
|
+
logger: vitePreviewServer.config.logger
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (vitePreviewServer.httpServer) vitePreviewServer.httpServer.on("listening", () => {
|
|
29
|
+
const addr = vitePreviewServer.httpServer?.address();
|
|
30
|
+
if (typeof addr === "object" && addr !== null) {
|
|
31
|
+
const serverConfig = vitePreviewServer.config.preview;
|
|
32
|
+
ctx.miniflare.publicUrl = buildPublicUrl({
|
|
33
|
+
hostname: typeof serverConfig.host === "string" ? serverConfig.host : void 0,
|
|
34
|
+
port: addr.port,
|
|
35
|
+
secure: !!serverConfig.https
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
handleWebSocket(vitePreviewServer.httpServer, ctx.miniflare);
|
|
40
|
+
vitePreviewServer.middlewares.use(createRequestHandler((request) => {
|
|
41
|
+
return ctx.miniflare.dispatchFetch(request, { redirect: "manual" });
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { configurePreviewServer };
|