@cloudflare/vite-plugin 1.39.2 → 1.40.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.
- package/dist/dist-MawCthRW.mjs +5414 -0
- package/dist/dist-MawCthRW.mjs.map +1 -0
- package/dist/experimental-config.d.mts +1434 -0
- package/dist/experimental-config.d.mts.map +1 -0
- package/dist/experimental-config.mjs +202 -0
- package/dist/experimental-config.mjs.map +1 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +186 -30
- package/dist/index.mjs.map +1 -1
- package/dist/{package-CKVuH4BM.mjs → package-Bo9FlzHY.mjs} +13 -6
- package/dist/package-Bo9FlzHY.mjs.map +1 -0
- package/package.json +11 -6
- package/dist/package-CKVuH4BM.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import { URL as URL$1, URLSearchParams as URLSearchParams$1, fileURLToPath, path
|
|
|
19
19
|
import * as fsp from "node:fs/promises";
|
|
20
20
|
import fs, { constants as constants$1 } from "node:fs/promises";
|
|
21
21
|
import * as timersPromises from "node:timers/promises";
|
|
22
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
22
23
|
import { getCloudflarePreset, nonPrefixedNodeModules } from "@cloudflare/unenv-preset";
|
|
23
24
|
import process$1 from "node:process";
|
|
24
25
|
import v8 from "node:v8";
|
|
@@ -1504,7 +1505,7 @@ async function assertWranglerVersion() {
|
|
|
1504
1505
|
* The default compatibility date to use when the user omits one.
|
|
1505
1506
|
* This value is injected at build time and remains fixed for each release.
|
|
1506
1507
|
*/
|
|
1507
|
-
const DEFAULT_COMPAT_DATE = "2026-06-
|
|
1508
|
+
const DEFAULT_COMPAT_DATE = "2026-06-04";
|
|
1508
1509
|
|
|
1509
1510
|
//#endregion
|
|
1510
1511
|
//#region ../../node_modules/.pnpm/@remix-run+node-fetch-server@0.8.0/node_modules/@remix-run/node-fetch-server/dist/node-fetch-server.js
|
|
@@ -1580,11 +1581,6 @@ const VITE_PROXY_WORKER_NAME = "__vite_proxy_worker__";
|
|
|
1580
1581
|
const PROXY_SHARED_SECRET = randomUUID();
|
|
1581
1582
|
const kRequestType = Symbol("kRequestType");
|
|
1582
1583
|
|
|
1583
|
-
//#endregion
|
|
1584
|
-
//#region ../workers-utils/dist/chunk-OZQVB3L3.mjs
|
|
1585
|
-
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
1586
|
-
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
1587
|
-
|
|
1588
1584
|
//#endregion
|
|
1589
1585
|
//#region ../workers-utils/dist/chunk-DCOBXSFB.mjs
|
|
1590
1586
|
var __create = Object.create;
|
|
@@ -1626,7 +1622,7 @@ var __toESM = (mod$1, isNodeMode, target$1) => (target$1 = mod$1 != null ? __cre
|
|
|
1626
1622
|
}) : target$1, mod$1));
|
|
1627
1623
|
|
|
1628
1624
|
//#endregion
|
|
1629
|
-
//#region ../workers-utils/dist/chunk-
|
|
1625
|
+
//#region ../workers-utils/dist/chunk-ULVYGN52.mjs
|
|
1630
1626
|
var UserError = class extends Error {
|
|
1631
1627
|
static {
|
|
1632
1628
|
__name(this, "UserError");
|
|
@@ -3893,6 +3889,8 @@ function removeBOMAndValidate(buffer$1, file2) {
|
|
|
3893
3889
|
return content;
|
|
3894
3890
|
}
|
|
3895
3891
|
__name(removeBOMAndValidate, "removeBOMAndValidate");
|
|
3892
|
+
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
3893
|
+
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
3896
3894
|
function absolute(input, root) {
|
|
3897
3895
|
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
3898
3896
|
}
|
|
@@ -15919,7 +15917,7 @@ var require_snapshot_utils = /* @__PURE__ */ __commonJS$1({ "../../node_modules/
|
|
|
15919
15917
|
var require_snapshot_recorder = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/undici@7.24.8/node_modules/undici/lib/mock/snapshot-recorder.js": ((exports, module) => {
|
|
15920
15918
|
const { writeFile, readFile, mkdir } = __require$2("node:fs/promises");
|
|
15921
15919
|
const { dirname: dirname$2, resolve: resolve$3 } = __require$2("node:path");
|
|
15922
|
-
const { setTimeout: setTimeout$
|
|
15920
|
+
const { setTimeout: setTimeout$2, clearTimeout: clearTimeout$1 } = __require$2("node:timers");
|
|
15923
15921
|
const { InvalidArgumentError: InvalidArgumentError$6, UndiciError: UndiciError$1 } = require_errors();
|
|
15924
15922
|
const { hashId, isUrlExcludedFactory, normalizeHeaders: normalizeHeaders$4, createHeaderFilters } = require_snapshot_utils();
|
|
15925
15923
|
/**
|
|
@@ -16297,7 +16295,7 @@ var require_snapshot_recorder = /* @__PURE__ */ __commonJS$1({ "../../node_modul
|
|
|
16297
16295
|
* Schedules a flush (debounced to avoid excessive writes)
|
|
16298
16296
|
*/
|
|
16299
16297
|
#scheduleFlush() {
|
|
16300
|
-
this.#flushTimeout = setTimeout$
|
|
16298
|
+
this.#flushTimeout = setTimeout$2(() => {
|
|
16301
16299
|
this.saveSnapshots().catch(() => {});
|
|
16302
16300
|
if (this.#autoFlush) this.#flushTimeout?.refresh();
|
|
16303
16301
|
else this.#flushTimeout = null;
|
|
@@ -27301,7 +27299,7 @@ var defaultWranglerConfig = {
|
|
|
27301
27299
|
vectorize: [],
|
|
27302
27300
|
ai_search_namespaces: [],
|
|
27303
27301
|
ai_search: [],
|
|
27304
|
-
|
|
27302
|
+
websearch: void 0,
|
|
27305
27303
|
agent_memory: [],
|
|
27306
27304
|
hyperdrive: [],
|
|
27307
27305
|
workflows: [],
|
|
@@ -31352,7 +31350,7 @@ var friendlyBindingNames = {
|
|
|
31352
31350
|
vectorize: "Vectorize Index",
|
|
31353
31351
|
ai_search_namespaces: "AI Search Namespace",
|
|
31354
31352
|
ai_search: "AI Search Instance",
|
|
31355
|
-
|
|
31353
|
+
websearch: "Web Search",
|
|
31356
31354
|
agent_memory: "Agent Memory",
|
|
31357
31355
|
hyperdrive: "Hyperdrive Config",
|
|
31358
31356
|
r2_buckets: "R2 Bucket",
|
|
@@ -31405,7 +31403,7 @@ var bindingTypeFriendlyNames = {
|
|
|
31405
31403
|
vectorize: "Vectorize Index",
|
|
31406
31404
|
ai_search_namespace: "AI Search Namespace",
|
|
31407
31405
|
ai_search: "AI Search Instance",
|
|
31408
|
-
|
|
31406
|
+
websearch: "Web Search",
|
|
31409
31407
|
agent_memory: "Agent Memory",
|
|
31410
31408
|
hyperdrive: "Hyperdrive Config",
|
|
31411
31409
|
service: "Worker",
|
|
@@ -31747,8 +31745,16 @@ function normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv) {
|
|
|
31747
31745
|
return inheritable(diagnostics, topLevelEnv, mutateEmptyStringRouteValue(diagnostics, rawEnv), "route", isRoute, void 0);
|
|
31748
31746
|
}
|
|
31749
31747
|
__name(normalizeAndValidateRoute, "normalizeAndValidateRoute");
|
|
31750
|
-
function validateRoutes(diagnostics, topLevelEnv, rawEnv) {
|
|
31751
|
-
|
|
31748
|
+
function validateRoutes(diagnostics, topLevelEnv, rawEnv, envName) {
|
|
31749
|
+
const result = inheritable(diagnostics, topLevelEnv, rawEnv, "routes", all(isRouteArray, isMutuallyExclusiveWith(rawEnv, "route")), void 0);
|
|
31750
|
+
if (topLevelEnv !== void 0 && envName !== void 0 && rawEnv.routes === void 0) {
|
|
31751
|
+
const customDomainRoutes = topLevelEnv.routes?.filter((r2) => typeof r2 === "object" && r2 !== null && r2.custom_domain === true);
|
|
31752
|
+
if (customDomainRoutes && customDomainRoutes.length > 0) {
|
|
31753
|
+
const customDomains = customDomainRoutes.map((r2) => r2.pattern).join(", ");
|
|
31754
|
+
diagnostics.warnings.push(`The "env.${envName}" environment inherits the top-level \`routes\` configuration, which includes the custom domain(s): ${customDomains}. Deploying this environment will reassign these custom domains away from the top-level Worker. Add \`"routes": []\` to "env.${envName}" to prevent inheritance, or copy the route configuration from the top level to hide this warning.`);
|
|
31755
|
+
}
|
|
31756
|
+
}
|
|
31757
|
+
return result;
|
|
31752
31758
|
}
|
|
31753
31759
|
__name(validateRoutes, "validateRoutes");
|
|
31754
31760
|
function normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv) {
|
|
@@ -31838,7 +31844,7 @@ function normalizeAndValidateEnvironment(diagnostics, configPath, rawEnv, isDisp
|
|
|
31838
31844
|
if (topLevelEnv === void 0 || rawConfig?.unsafe === void 0) experimental(diagnostics, rawEnv, "unsafe");
|
|
31839
31845
|
const route = normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv);
|
|
31840
31846
|
const account_id = inheritableInWranglerEnvironments(diagnostics, useServiceEnvironments, topLevelEnv, mutateEmptyStringAccountIDValue(diagnostics, rawEnv), "account_id", isString$2, void 0, void 0);
|
|
31841
|
-
const routes = validateRoutes(diagnostics, topLevelEnv, rawEnv);
|
|
31847
|
+
const routes = validateRoutes(diagnostics, topLevelEnv, rawEnv, topLevelEnv === void 0 ? void 0 : envName);
|
|
31842
31848
|
const workers_dev = inheritable(diagnostics, topLevelEnv, rawEnv, "workers_dev", isBoolean, void 0);
|
|
31843
31849
|
const preview_urls = inheritable(diagnostics, topLevelEnv, rawEnv, "preview_urls", isBoolean, void 0);
|
|
31844
31850
|
const build$8 = normalizeAndValidateBuild(diagnostics, rawEnv, rawEnv.build ?? topLevelEnv?.build ?? {}, configPath);
|
|
@@ -31883,7 +31889,7 @@ function normalizeAndValidateEnvironment(diagnostics, configPath, rawEnv, isDisp
|
|
|
31883
31889
|
vectorize: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "vectorize", validateBindingArray(envName, validateVectorizeBinding), []),
|
|
31884
31890
|
ai_search_namespaces: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "ai_search_namespaces", validateBindingArray(envName, validateAISearchNamespaceBinding), []),
|
|
31885
31891
|
ai_search: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "ai_search", validateBindingArray(envName, validateAISearchBinding), []),
|
|
31886
|
-
|
|
31892
|
+
websearch: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "websearch", validateNamedSimpleBinding(envName), void 0),
|
|
31887
31893
|
agent_memory: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "agent_memory", validateBindingArray(envName, validateAgentMemoryBinding), []),
|
|
31888
31894
|
hyperdrive: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "hyperdrive", validateBindingArray(envName, validateHyperdriveBinding), []),
|
|
31889
31895
|
services: notInheritable(diagnostics, topLevelEnv, rawConfig, rawEnv, envName, "services", validateBindingArray(envName, validateServiceBinding), []),
|
|
@@ -32352,7 +32358,7 @@ var validateUnsafeBinding = /* @__PURE__ */ __name((diagnostics, field, value) =
|
|
|
32352
32358
|
"ai",
|
|
32353
32359
|
"ai_search_namespace",
|
|
32354
32360
|
"ai_search",
|
|
32355
|
-
"
|
|
32361
|
+
"websearch",
|
|
32356
32362
|
"agent_memory",
|
|
32357
32363
|
"kv_namespace",
|
|
32358
32364
|
"durable_object_namespace",
|
|
@@ -32784,12 +32790,17 @@ var validateD1Binding = /* @__PURE__ */ __name((diagnostics, field, value) => {
|
|
|
32784
32790
|
isValid2 = false;
|
|
32785
32791
|
}
|
|
32786
32792
|
if (!isRemoteValid(value, field, diagnostics)) isValid2 = false;
|
|
32793
|
+
if (!isOptionalProperty(value, "migrations_pattern", "string")) {
|
|
32794
|
+
diagnostics.errors.push(`"${field}" bindings should, optionally, have a string "migrations_pattern" field but got ${JSON.stringify(value)}.`);
|
|
32795
|
+
isValid2 = false;
|
|
32796
|
+
}
|
|
32787
32797
|
validateAdditionalProperties(diagnostics, field, Object.keys(value), [
|
|
32788
32798
|
"binding",
|
|
32789
32799
|
"database_id",
|
|
32790
32800
|
"database_internal_env",
|
|
32791
32801
|
"database_name",
|
|
32792
32802
|
"migrations_dir",
|
|
32803
|
+
"migrations_pattern",
|
|
32793
32804
|
"migrations_table",
|
|
32794
32805
|
"preview_database_id",
|
|
32795
32806
|
"remote"
|
|
@@ -33658,7 +33669,7 @@ var BINDING_LOCAL_SUPPORT = {
|
|
|
33658
33669
|
flagship: "DO-NOT-USE-this-resource-will-never-have-a-local-simulator",
|
|
33659
33670
|
vpc_service: "DO-NOT-USE-this-resource-will-never-have-a-local-simulator",
|
|
33660
33671
|
vpc_network: "DO-NOT-USE-this-resource-will-never-have-a-local-simulator",
|
|
33661
|
-
|
|
33672
|
+
websearch: "DO-NOT-USE-this-resource-will-never-have-a-local-simulator",
|
|
33662
33673
|
agent_memory: "DO-NOT-USE-this-resource-will-never-have-a-local-simulator"
|
|
33663
33674
|
};
|
|
33664
33675
|
function getBindingLocalSupport(type) {
|
|
@@ -34616,6 +34627,53 @@ async function fetchLatestNpmVersion(name, version$2) {
|
|
|
34616
34627
|
};
|
|
34617
34628
|
}
|
|
34618
34629
|
__name(fetchLatestNpmVersion, "fetchLatestNpmVersion");
|
|
34630
|
+
var MAX_ATTEMPTS = 3;
|
|
34631
|
+
async function retryOnAPIFailure(action, logger, backoff = 0, attempts = MAX_ATTEMPTS, abortSignal) {
|
|
34632
|
+
try {
|
|
34633
|
+
return await action();
|
|
34634
|
+
} catch (err) {
|
|
34635
|
+
if (err instanceof APIError) {
|
|
34636
|
+
if (!err.isRetryable()) throw err;
|
|
34637
|
+
} else if (err instanceof DOMException && err.name === "TimeoutError");
|
|
34638
|
+
else if (!(err instanceof TypeError)) throw err;
|
|
34639
|
+
logger.debug(`Retrying API call after error...`);
|
|
34640
|
+
logger.debug(err);
|
|
34641
|
+
if (attempts <= 1) throw err;
|
|
34642
|
+
await setTimeout$1(backoff, void 0, { signal: abortSignal });
|
|
34643
|
+
return retryOnAPIFailure(action, logger, backoff + 1e3, attempts - 1, abortSignal);
|
|
34644
|
+
}
|
|
34645
|
+
}
|
|
34646
|
+
__name(retryOnAPIFailure, "retryOnAPIFailure");
|
|
34647
|
+
function formatTime(duration) {
|
|
34648
|
+
return `(${(duration / 1e3).toFixed(2)} sec)`;
|
|
34649
|
+
}
|
|
34650
|
+
__name(formatTime, "formatTime");
|
|
34651
|
+
function getHostFromRoute(route) {
|
|
34652
|
+
let host;
|
|
34653
|
+
if (typeof route === "string") host = getHostFromUrl(route);
|
|
34654
|
+
else if (typeof route === "object") {
|
|
34655
|
+
host = getHostFromUrl(route.pattern);
|
|
34656
|
+
if (host === void 0 && "zone_name" in route) host = getHostFromUrl(route.zone_name);
|
|
34657
|
+
}
|
|
34658
|
+
return host;
|
|
34659
|
+
}
|
|
34660
|
+
__name(getHostFromRoute, "getHostFromRoute");
|
|
34661
|
+
function getZoneFromRoute(route) {
|
|
34662
|
+
if (typeof route === "object" && "zone_name" in route && route.zone_name) return route.zone_name;
|
|
34663
|
+
return getHostFromRoute(route);
|
|
34664
|
+
}
|
|
34665
|
+
__name(getZoneFromRoute, "getZoneFromRoute");
|
|
34666
|
+
function getHostFromUrl(urlLike) {
|
|
34667
|
+
if (urlLike.startsWith("*/") || urlLike.startsWith("http://*/") || urlLike.startsWith("https://*/")) return;
|
|
34668
|
+
urlLike = urlLike.replace(/\*(\.)?/g, "");
|
|
34669
|
+
if (!(urlLike.startsWith("http://") || urlLike.startsWith("https://"))) urlLike = "http://" + urlLike;
|
|
34670
|
+
try {
|
|
34671
|
+
return new URL(urlLike).host;
|
|
34672
|
+
} catch {
|
|
34673
|
+
return;
|
|
34674
|
+
}
|
|
34675
|
+
}
|
|
34676
|
+
__name(getHostFromUrl, "getHostFromUrl");
|
|
34619
34677
|
|
|
34620
34678
|
//#endregion
|
|
34621
34679
|
//#region ../../node_modules/.pnpm/get-port@7.1.0/node_modules/get-port/index.js
|
|
@@ -43899,16 +43957,17 @@ const nullableNonApplicable = [
|
|
|
43899
43957
|
"site",
|
|
43900
43958
|
"tsconfig"
|
|
43901
43959
|
];
|
|
43902
|
-
|
|
43960
|
+
/**
|
|
43961
|
+
* Apply the Vite-specific sanitization to a normalized Worker config, tracking
|
|
43962
|
+
* any fields that are non-applicable when running under Vite.
|
|
43963
|
+
*/
|
|
43964
|
+
function processNormalizedWorkerConfig(normalized) {
|
|
43903
43965
|
const nonApplicable = {
|
|
43904
43966
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
43905
43967
|
notRelevant: /* @__PURE__ */ new Set(),
|
|
43906
43968
|
notSupportedOnAuxiliary: /* @__PURE__ */ new Set()
|
|
43907
43969
|
};
|
|
43908
|
-
const config =
|
|
43909
|
-
config: configPath,
|
|
43910
|
-
env: env$1
|
|
43911
|
-
}, { preserveOriginalMain: true });
|
|
43970
|
+
const config = normalized;
|
|
43912
43971
|
const raw = structuredClone(config);
|
|
43913
43972
|
nullableNonApplicable.forEach((prop) => {
|
|
43914
43973
|
if (config[prop] !== void 0) {
|
|
@@ -43928,6 +43987,24 @@ function readWorkerConfig(configPath, env$1) {
|
|
|
43928
43987
|
config
|
|
43929
43988
|
};
|
|
43930
43989
|
}
|
|
43990
|
+
function readWorkerConfig(configPath, env$1) {
|
|
43991
|
+
return processNormalizedWorkerConfig(wrangler.unstable_readConfig({
|
|
43992
|
+
config: configPath,
|
|
43993
|
+
env: env$1
|
|
43994
|
+
}, { preserveOriginalMain: true }));
|
|
43995
|
+
}
|
|
43996
|
+
/**
|
|
43997
|
+
* Normalise a `RawConfig` produced in-memory (for example by
|
|
43998
|
+
* `convertToWranglerConfig` from `@cloudflare/config`) using the same
|
|
43999
|
+
* validation pipeline as on-disk Wrangler config files, then apply the
|
|
44000
|
+
* Vite-specific sanitization.
|
|
44001
|
+
*/
|
|
44002
|
+
function readWorkerConfigFromRaw(rawConfig) {
|
|
44003
|
+
const { config, diagnostics } = normalizeAndValidateConfig(rawConfig, void 0, void 0, {}, true);
|
|
44004
|
+
if (diagnostics.hasWarnings()) console.warn(diagnostics.renderWarnings());
|
|
44005
|
+
if (diagnostics.hasErrors()) throw new Error(diagnostics.renderErrors());
|
|
44006
|
+
return processNormalizedWorkerConfig(config);
|
|
44007
|
+
}
|
|
43931
44008
|
function getWarningForWorkersConfigs(configs) {
|
|
43932
44009
|
if (!("auxiliaryWorkers" in configs) || configs.auxiliaryWorkers.length === 0) {
|
|
43933
44010
|
const nonApplicableLines = getWorkerNonApplicableWarnLines(configs.entryWorker, ` - `);
|
|
@@ -44081,6 +44158,11 @@ const allowedWranglerConfigExtensions = [
|
|
|
44081
44158
|
|
|
44082
44159
|
//#endregion
|
|
44083
44160
|
//#region src/plugin-config.ts
|
|
44161
|
+
function normalizeNewConfig(option) {
|
|
44162
|
+
if (option === void 0 || option === false) return;
|
|
44163
|
+
if (option === true) return { types: { generate: true } };
|
|
44164
|
+
return { types: { generate: option.types?.generate ?? true } };
|
|
44165
|
+
}
|
|
44084
44166
|
function filterEntryWorkerConfig(config) {
|
|
44085
44167
|
const { topLevelName: _topLevelName, name: _name,...filteredConfig } = config;
|
|
44086
44168
|
return filteredConfig;
|
|
@@ -44098,7 +44180,8 @@ function resolveWorkerConfig(options) {
|
|
|
44098
44180
|
let workerConfig;
|
|
44099
44181
|
let raw;
|
|
44100
44182
|
let nonApplicable;
|
|
44101
|
-
if (options.
|
|
44183
|
+
if (options.rawConfigOverride) ({raw, config: workerConfig, nonApplicable} = readWorkerConfigFromRaw(options.rawConfigOverride));
|
|
44184
|
+
else if (options.configPath) ({raw, config: workerConfig, nonApplicable} = readWorkerConfigFromFile(options.configPath, options.env, { visitedConfigPaths: options.visitedConfigPaths }));
|
|
44102
44185
|
else {
|
|
44103
44186
|
workerConfig = { ...wrangler.unstable_defaultWranglerConfig };
|
|
44104
44187
|
raw = structuredClone(workerConfig);
|
|
@@ -44126,7 +44209,8 @@ function resolveWorkerConfig(options) {
|
|
|
44126
44209
|
env: options.env
|
|
44127
44210
|
});
|
|
44128
44211
|
}
|
|
44129
|
-
function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
44212
|
+
async function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
44213
|
+
const resolvedNewConfig = normalizeNewConfig(pluginConfig.experimental?.newConfig);
|
|
44130
44214
|
const shared = {
|
|
44131
44215
|
persistState: pluginConfig.persistState ?? true,
|
|
44132
44216
|
inspectorPort: pluginConfig.inspectorPort,
|
|
@@ -44134,7 +44218,10 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
44134
44218
|
autoStart: pluginConfig.tunnel?.autoStart ?? false,
|
|
44135
44219
|
name: pluginConfig.tunnel?.name
|
|
44136
44220
|
},
|
|
44137
|
-
experimental: {
|
|
44221
|
+
experimental: {
|
|
44222
|
+
headersAndRedirectsDevModeSupport: pluginConfig.experimental?.headersAndRedirectsDevModeSupport,
|
|
44223
|
+
newConfig: resolvedNewConfig
|
|
44224
|
+
}
|
|
44138
44225
|
};
|
|
44139
44226
|
const root = userConfig.root ? nodePath.resolve(userConfig.root) : process.cwd();
|
|
44140
44227
|
const prefixedEnv = vite.loadEnv(viteEnv.mode, root, ["CLOUDFLARE_", "WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_"]);
|
|
@@ -44149,12 +44236,28 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
44149
44236
|
const configPaths = /* @__PURE__ */ new Set();
|
|
44150
44237
|
const cloudflareEnv = prefixedEnv.CLOUDFLARE_ENV;
|
|
44151
44238
|
const validateAndAddEnvironmentName = createEnvironmentNameValidator();
|
|
44239
|
+
let configPath;
|
|
44240
|
+
let rawConfigOverride;
|
|
44241
|
+
if (resolvedNewConfig) {
|
|
44242
|
+
if (pluginConfig.configPath) throw new Error("`configPath` cannot be used together with `experimental.newConfig`. Configure the entry Worker via `cloudflare.config.ts` instead.");
|
|
44243
|
+
if (pluginConfig.auxiliaryWorkers?.length) throw new Error("`auxiliaryWorkers` are not yet supported when `experimental.newConfig` is enabled.");
|
|
44244
|
+
const result = await loadNewConfig({
|
|
44245
|
+
root,
|
|
44246
|
+
mode: viteEnv.mode,
|
|
44247
|
+
generateTypes: resolvedNewConfig.types.generate
|
|
44248
|
+
});
|
|
44249
|
+
configPath = result.configPath;
|
|
44250
|
+
rawConfigOverride = result.rawConfig;
|
|
44251
|
+
configPaths.add(result.configPath);
|
|
44252
|
+
for (const dep of result.dependencies) configPaths.add(dep);
|
|
44253
|
+
} else configPath = getValidatedWranglerConfigPath(root, pluginConfig.configPath ?? prefixedEnv.CLOUDFLARE_VITE_WRANGLER_CONFIG_PATH);
|
|
44152
44254
|
const entryWorkerResolvedConfig = resolveWorkerConfig({
|
|
44153
44255
|
root,
|
|
44154
|
-
configPath:
|
|
44256
|
+
configPath: resolvedNewConfig ? void 0 : configPath,
|
|
44155
44257
|
env: cloudflareEnv,
|
|
44156
44258
|
configCustomizer: pluginConfig.config,
|
|
44157
|
-
visitedConfigPaths: configPaths
|
|
44259
|
+
visitedConfigPaths: configPaths,
|
|
44260
|
+
rawConfigOverride
|
|
44158
44261
|
});
|
|
44159
44262
|
const environmentNameToWorkerMap = /* @__PURE__ */ new Map();
|
|
44160
44263
|
const environmentNameToChildEnvironmentNamesMap = /* @__PURE__ */ new Map();
|
|
@@ -44264,6 +44367,59 @@ function resolveWorker(workerConfig, devOnly) {
|
|
|
44264
44367
|
devOnly
|
|
44265
44368
|
};
|
|
44266
44369
|
}
|
|
44370
|
+
const NEW_CONFIG_FILENAME = "cloudflare.config.ts";
|
|
44371
|
+
const TYPES_OUTPUT_FILENAME = "worker-configuration.d.ts";
|
|
44372
|
+
const EXPERIMENTAL_CONFIG_PKG = "@cloudflare/vite-plugin/experimental-config";
|
|
44373
|
+
/**
|
|
44374
|
+
* Load and convert a `cloudflare.config.ts` file via `@cloudflare/config`. Returns
|
|
44375
|
+
* the resulting Wrangler `RawConfig`, the absolute path of the loaded file,
|
|
44376
|
+
* and the set of files imported while resolving the config (for watch-mode).
|
|
44377
|
+
*
|
|
44378
|
+
* If `generateTypes` is true, also writes `worker-configuration.d.ts` next to
|
|
44379
|
+
* the config when the generated content differs from what's already on disk.
|
|
44380
|
+
*/
|
|
44381
|
+
async function loadNewConfig(options) {
|
|
44382
|
+
const configPath = nodePath.resolve(options.root, NEW_CONFIG_FILENAME);
|
|
44383
|
+
if (!fs$1.existsSync(configPath)) throw new Error(`\`experimental.newConfig\` is enabled but no \`${NEW_CONFIG_FILENAME}\` was found at ${configPath}.`);
|
|
44384
|
+
const { loadConfig, ConfigSchema, convertToWranglerConfig, generateTypes: generateTypesFn, resolveWorkerDefinition } = await import("./dist-MawCthRW.mjs");
|
|
44385
|
+
const { config: rawExport, dependencies } = await loadConfig(configPath);
|
|
44386
|
+
const resolved = await resolveWorkerDefinition(rawExport, { mode: options.mode });
|
|
44387
|
+
const parsed = ConfigSchema.safeParse(resolved);
|
|
44388
|
+
if (!parsed.success) throw new Error(`Invalid \`${NEW_CONFIG_FILENAME}\`:\n${parsed.error.message}`);
|
|
44389
|
+
const rawConfig = convertToWranglerConfig(parsed.data);
|
|
44390
|
+
if (options.generateTypes) writeWorkerConfigurationDts({
|
|
44391
|
+
root: options.root,
|
|
44392
|
+
configPath,
|
|
44393
|
+
generateTypes: generateTypesFn
|
|
44394
|
+
});
|
|
44395
|
+
return {
|
|
44396
|
+
rawConfig,
|
|
44397
|
+
configPath,
|
|
44398
|
+
dependencies
|
|
44399
|
+
};
|
|
44400
|
+
}
|
|
44401
|
+
/**
|
|
44402
|
+
* Write `worker-configuration.d.ts` to the project root using
|
|
44403
|
+
* `@cloudflare/config`'s `generateTypes`, targeting the vite-plugin's
|
|
44404
|
+
* `experimental-config` subpath (so users don't need a direct dependency on
|
|
44405
|
+
* `@cloudflare/config`).
|
|
44406
|
+
*
|
|
44407
|
+
* Reads the existing file first and only writes if the content differs, to
|
|
44408
|
+
* avoid touching mtimes unnecessarily.
|
|
44409
|
+
*/
|
|
44410
|
+
function writeWorkerConfigurationDts(options) {
|
|
44411
|
+
const outputPath = nodePath.resolve(options.root, TYPES_OUTPUT_FILENAME);
|
|
44412
|
+
const relativeConfigPath = "./" + nodePath.relative(options.root, options.configPath);
|
|
44413
|
+
const content = options.generateTypes({
|
|
44414
|
+
configPath: relativeConfigPath,
|
|
44415
|
+
packageName: EXPERIMENTAL_CONFIG_PKG
|
|
44416
|
+
});
|
|
44417
|
+
let existing;
|
|
44418
|
+
try {
|
|
44419
|
+
existing = fs$1.readFileSync(outputPath, "utf8");
|
|
44420
|
+
} catch {}
|
|
44421
|
+
if (existing !== content) fs$1.writeFileSync(outputPath, content);
|
|
44422
|
+
}
|
|
44267
44423
|
|
|
44268
44424
|
//#endregion
|
|
44269
44425
|
//#region ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
@@ -57097,8 +57253,8 @@ function cloudflare(pluginConfig = {}) {
|
|
|
57097
57253
|
{
|
|
57098
57254
|
name: "vite-plugin-cloudflare",
|
|
57099
57255
|
sharedDuringBuild: true,
|
|
57100
|
-
config(userConfig, env$1) {
|
|
57101
|
-
ctx.setResolvedPluginConfig(resolvePluginConfig(pluginConfig, userConfig, env$1));
|
|
57256
|
+
async config(userConfig, env$1) {
|
|
57257
|
+
ctx.setResolvedPluginConfig(await resolvePluginConfig(pluginConfig, userConfig, env$1));
|
|
57102
57258
|
if (env$1.command === "build") process.env.CLOUDFLARE_VITE_BUILD = "true";
|
|
57103
57259
|
},
|
|
57104
57260
|
async configureServer(viteDevServer) {
|