@cloudflare/vite-plugin 1.20.0 → 1.20.2
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/index.mjs
CHANGED
|
@@ -12,10 +12,10 @@ import { version } from "vite";
|
|
|
12
12
|
import * as fs$1 from "node:fs";
|
|
13
13
|
import fs, { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
14
14
|
import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
|
|
15
|
-
import
|
|
15
|
+
import process2 from "node:process";
|
|
16
16
|
import os from "node:os";
|
|
17
17
|
import { defu } from "defu";
|
|
18
|
-
import { getCloudflarePreset } from "@cloudflare/unenv-preset";
|
|
18
|
+
import { getCloudflarePreset, nonPrefixedNodeModules } from "@cloudflare/unenv-preset";
|
|
19
19
|
import v8 from "node:v8";
|
|
20
20
|
import { defineEnv } from "unenv";
|
|
21
21
|
import * as fsp from "node:fs/promises";
|
|
@@ -1557,6 +1557,7 @@ function toMiniflareRequest(request$1) {
|
|
|
1557
1557
|
signal: request$1.signal
|
|
1558
1558
|
});
|
|
1559
1559
|
}
|
|
1560
|
+
const isRolldown = "rolldownVersion" in vite;
|
|
1560
1561
|
|
|
1561
1562
|
//#endregion
|
|
1562
1563
|
//#region src/export-types.ts
|
|
@@ -4428,7 +4429,7 @@ function checkType(type) {
|
|
|
4428
4429
|
__name(checkType, "checkType");
|
|
4429
4430
|
var matchType = /* @__PURE__ */ __name((type, stat) => type === void 0 || stat[typeMappings[type]](), "matchType");
|
|
4430
4431
|
var toPath = /* @__PURE__ */ __name((urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath, "toPath");
|
|
4431
|
-
function locatePathSync(paths, { cwd =
|
|
4432
|
+
function locatePathSync(paths, { cwd = process2.cwd(), type = "file", allowSymlinks = true } = {}) {
|
|
4432
4433
|
checkType(type);
|
|
4433
4434
|
cwd = toPath(cwd);
|
|
4434
4435
|
const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
|
|
@@ -6838,6 +6839,14 @@ function validateContainerApp(envName, topLevelName, configPath) {
|
|
|
6838
6839
|
if (!isRequiredProperty(key, "public_key", "string")) diagnostics.errors.push(`${fieldPath}.public_key must be a string`);
|
|
6839
6840
|
if (!key.public_key.toLowerCase().startsWith("ssh-ed25519")) diagnostics.errors.push(`${fieldPath}.public_key is a unsupported key type. Please provide a ED25519 public key.`);
|
|
6840
6841
|
}
|
|
6842
|
+
if (validateOptionalProperty(diagnostics, field, "constraints", containerAppOptional.constraints, "object") && containerAppOptional.constraints) {
|
|
6843
|
+
const constraints = containerAppOptional.constraints;
|
|
6844
|
+
if ("tier" in constraints) {
|
|
6845
|
+
diagnostics.warnings.push(`"constraints.tier" has been deprecated in favor of "constraints.tiers". Please update your configuration to use "constraints.tiers" instead.`);
|
|
6846
|
+
if ("tiers" in constraints) diagnostics.errors.push(`${field}.constraints.tier and ${field}.constraints.tiers cannot both be set`);
|
|
6847
|
+
}
|
|
6848
|
+
validateOptionalTypedArray(diagnostics, `${field}.constraints.tiers`, constraints.tiers, "number");
|
|
6849
|
+
}
|
|
6841
6850
|
if (typeof containerAppOptional.instance_type === "string") {
|
|
6842
6851
|
validateOptionalProperty(diagnostics, field, "instance_type", containerAppOptional.instance_type, "string", ALLOWED_INSTANCE_TYPES);
|
|
6843
6852
|
if (containerAppOptional.instance_type === "dev") diagnostics.warnings.push(`The "dev" instance_type has been renamed to "lite" and will be removed in a subsequent version. Please update your configuration to use "lite" instead.`);
|
|
@@ -13282,10 +13291,10 @@ const doubleSlashRegEx = /[/\\]{2}/;
|
|
|
13282
13291
|
* @param {boolean} isTarget
|
|
13283
13292
|
*/
|
|
13284
13293
|
function emitInvalidSegmentDeprecation(target$1, request$1, match, packageJsonUrl, internal, base, isTarget) {
|
|
13285
|
-
if (
|
|
13294
|
+
if (process2.noDeprecation) return;
|
|
13286
13295
|
const pjsonPath = fileURLToPath(packageJsonUrl);
|
|
13287
13296
|
const double = doubleSlashRegEx.exec(isTarget ? target$1 : request$1) !== null;
|
|
13288
|
-
|
|
13297
|
+
process2.emitWarning(`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target$1}" for module request "${request$1}" ${request$1 === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}.`, "DeprecationWarning", "DEP0166");
|
|
13289
13298
|
}
|
|
13290
13299
|
/**
|
|
13291
13300
|
* @param {URL} url
|
|
@@ -13295,13 +13304,13 @@ function emitInvalidSegmentDeprecation(target$1, request$1, match, packageJsonUr
|
|
|
13295
13304
|
* @returns {void}
|
|
13296
13305
|
*/
|
|
13297
13306
|
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
13298
|
-
if (
|
|
13307
|
+
if (process2.noDeprecation) return;
|
|
13299
13308
|
if (defaultGetFormatWithoutErrors(url, { parentURL: base.href }) !== "module") return;
|
|
13300
13309
|
const urlPath = fileURLToPath(url.href);
|
|
13301
13310
|
const packagePath = fileURLToPath(new URL$1(".", packageJsonUrl));
|
|
13302
13311
|
const basePath = fileURLToPath(base);
|
|
13303
|
-
if (!main)
|
|
13304
|
-
else if (path4.resolve(packagePath, main) !== urlPath)
|
|
13312
|
+
if (!main) process2.emitWarning(`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
|
|
13313
|
+
else if (path4.resolve(packagePath, main) !== urlPath) process2.emitWarning(`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
|
|
13305
13314
|
}
|
|
13306
13315
|
/**
|
|
13307
13316
|
* @param {string} path
|
|
@@ -13601,11 +13610,11 @@ function isConditionalExportsMainSugar(exports$1, packageJsonUrl, base) {
|
|
|
13601
13610
|
* @param {URL} base
|
|
13602
13611
|
*/
|
|
13603
13612
|
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
13604
|
-
if (
|
|
13613
|
+
if (process2.noDeprecation) return;
|
|
13605
13614
|
const pjsonPath = fileURLToPath(pjsonUrl);
|
|
13606
13615
|
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
13607
13616
|
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
13608
|
-
|
|
13617
|
+
process2.emitWarning(`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`, "DeprecationWarning", "DEP0155");
|
|
13609
13618
|
}
|
|
13610
13619
|
/**
|
|
13611
13620
|
* @param {URL} packageJsonUrl
|
|
@@ -14035,11 +14044,6 @@ function hasNodeJsCompat(workerConfig) {
|
|
|
14035
14044
|
function hasNodeJsAls(workerConfig) {
|
|
14036
14045
|
return workerConfig !== void 0 && getNodeCompat(workerConfig.compatibility_date, workerConfig.compatibility_flags ?? []).mode === "als";
|
|
14037
14046
|
}
|
|
14038
|
-
/**
|
|
14039
|
-
* All the Node.js modules including their `node:...` aliases.
|
|
14040
|
-
*/
|
|
14041
|
-
const nodeJsBuiltins = new Set([...builtinModules, ...builtinModules.map((m) => `node:${m}`)]);
|
|
14042
|
-
const NODEJS_MODULES_RE = /* @__PURE__ */ new RegExp(`^(node:)?(${builtinModules.join("|")})$`);
|
|
14043
14047
|
function isNodeAlsModule(modulePath) {
|
|
14044
14048
|
return /^(?:node:)?async_hooks$/.test(modulePath);
|
|
14045
14049
|
}
|
|
@@ -21420,6 +21424,22 @@ const defaultConditions = [
|
|
|
21420
21424
|
"browser"
|
|
21421
21425
|
];
|
|
21422
21426
|
const target = "es2024";
|
|
21427
|
+
const rollupOptions = {
|
|
21428
|
+
input: { [MAIN_ENTRY_NAME]: VIRTUAL_WORKER_ENTRY },
|
|
21429
|
+
preserveEntrySignatures: "strict"
|
|
21430
|
+
};
|
|
21431
|
+
const resolveExtensions = [
|
|
21432
|
+
".mjs",
|
|
21433
|
+
".js",
|
|
21434
|
+
".mts",
|
|
21435
|
+
".ts",
|
|
21436
|
+
".jsx",
|
|
21437
|
+
".tsx",
|
|
21438
|
+
".json",
|
|
21439
|
+
".cjs",
|
|
21440
|
+
".cts",
|
|
21441
|
+
".ctx"
|
|
21442
|
+
];
|
|
21423
21443
|
function createCloudflareEnvironmentOptions({ workerConfig, userConfig, mode, environmentName, isEntryWorker, hasNodeJsCompat: hasNodeJsCompat$1 }) {
|
|
21424
21444
|
const define$1 = getProcessEnvReplacements(hasNodeJsCompat$1, mode);
|
|
21425
21445
|
return {
|
|
@@ -21442,35 +21462,34 @@ function createCloudflareEnvironmentOptions({ workerConfig, userConfig, mode, en
|
|
|
21442
21462
|
outDir: getOutputDirectory(userConfig, environmentName),
|
|
21443
21463
|
copyPublicDir: false,
|
|
21444
21464
|
ssr: true,
|
|
21445
|
-
|
|
21446
|
-
|
|
21447
|
-
|
|
21448
|
-
|
|
21449
|
-
}
|
|
21465
|
+
...isRolldown ? { rolldownOptions: {
|
|
21466
|
+
...rollupOptions,
|
|
21467
|
+
platform: "neutral",
|
|
21468
|
+
resolve: { extensions: resolveExtensions }
|
|
21469
|
+
} } : { rollupOptions }
|
|
21450
21470
|
},
|
|
21451
21471
|
optimizeDeps: {
|
|
21452
21472
|
noDiscovery: false,
|
|
21453
21473
|
ignoreOutdatedRequests: true,
|
|
21454
21474
|
entries: vite.normalizePath(workerConfig.main),
|
|
21455
21475
|
exclude: [...cloudflareBuiltInModules],
|
|
21456
|
-
|
|
21476
|
+
...isRolldown ? { rolldownOptions: {
|
|
21477
|
+
platform: "neutral",
|
|
21478
|
+
resolve: {
|
|
21479
|
+
conditionNames: [...defaultConditions, "development"],
|
|
21480
|
+
extensions: resolveExtensions
|
|
21481
|
+
},
|
|
21482
|
+
transform: {
|
|
21483
|
+
target,
|
|
21484
|
+
define: define$1
|
|
21485
|
+
}
|
|
21486
|
+
} } : { esbuildOptions: {
|
|
21457
21487
|
platform: "neutral",
|
|
21458
|
-
target,
|
|
21459
21488
|
conditions: [...defaultConditions, "development"],
|
|
21460
|
-
resolveExtensions
|
|
21461
|
-
|
|
21462
|
-
".js",
|
|
21463
|
-
".mts",
|
|
21464
|
-
".ts",
|
|
21465
|
-
".jsx",
|
|
21466
|
-
".tsx",
|
|
21467
|
-
".json",
|
|
21468
|
-
".cjs",
|
|
21469
|
-
".cts",
|
|
21470
|
-
".ctx"
|
|
21471
|
-
],
|
|
21489
|
+
resolveExtensions,
|
|
21490
|
+
target,
|
|
21472
21491
|
define: define$1
|
|
21473
|
-
}
|
|
21492
|
+
} }
|
|
21474
21493
|
},
|
|
21475
21494
|
keepProcessEnv: true
|
|
21476
21495
|
};
|
|
@@ -22099,17 +22118,17 @@ const getQueryString = (params) => {
|
|
|
22099
22118
|
const append = (key, value) => {
|
|
22100
22119
|
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
22101
22120
|
};
|
|
22102
|
-
const process$
|
|
22121
|
+
const process$1 = (key, value) => {
|
|
22103
22122
|
if (isDefined(value)) if (Array.isArray(value)) value.forEach((v) => {
|
|
22104
|
-
process$
|
|
22123
|
+
process$1(key, v);
|
|
22105
22124
|
});
|
|
22106
22125
|
else if (typeof value === "object") Object.entries(value).forEach(([k, v]) => {
|
|
22107
|
-
process$
|
|
22126
|
+
process$1(`${key}[${k}]`, v);
|
|
22108
22127
|
});
|
|
22109
22128
|
else append(key, value);
|
|
22110
22129
|
};
|
|
22111
22130
|
Object.entries(params).forEach(([key, value]) => {
|
|
22112
|
-
process$
|
|
22131
|
+
process$1(key, value);
|
|
22113
22132
|
});
|
|
22114
22133
|
if (qs.length > 0) return `?${qs.join("&")}`;
|
|
22115
22134
|
return "";
|
|
@@ -22127,13 +22146,13 @@ const getUrl = (config, options) => {
|
|
|
22127
22146
|
const getFormData = (options) => {
|
|
22128
22147
|
if (options.formData) {
|
|
22129
22148
|
const formData = new FormData();
|
|
22130
|
-
const process$
|
|
22149
|
+
const process$1 = async (key, value) => {
|
|
22131
22150
|
if (isString(value)) formData.append(key, value);
|
|
22132
22151
|
else formData.append(key, JSON.stringify(value));
|
|
22133
22152
|
};
|
|
22134
22153
|
Object.entries(options.formData).filter(([_, value]) => isDefined(value)).forEach(([key, value]) => {
|
|
22135
|
-
if (Array.isArray(value)) value.forEach((v) => process$
|
|
22136
|
-
else process$
|
|
22154
|
+
if (Array.isArray(value)) value.forEach((v) => process$1(key, v));
|
|
22155
|
+
else process$1(key, value);
|
|
22137
22156
|
});
|
|
22138
22157
|
return formData;
|
|
22139
22158
|
}
|
|
@@ -23458,7 +23477,16 @@ const nodeJsCompatPlugin = createPlugin("nodejs-compat", (ctx) => {
|
|
|
23458
23477
|
const nodeJsCompat = ctx.getNodeJsCompat(name);
|
|
23459
23478
|
if (nodeJsCompat) return {
|
|
23460
23479
|
resolve: { builtins: [...nodeJsCompat.externals] },
|
|
23461
|
-
optimizeDeps: { exclude: [
|
|
23480
|
+
optimizeDeps: { exclude: [
|
|
23481
|
+
...nonPrefixedNodeModules,
|
|
23482
|
+
...nonPrefixedNodeModules.map((module$2) => `node:${module$2}`),
|
|
23483
|
+
...[
|
|
23484
|
+
"node:sea",
|
|
23485
|
+
"node:sqlite",
|
|
23486
|
+
"node:test",
|
|
23487
|
+
"node:test/reporters"
|
|
23488
|
+
]
|
|
23489
|
+
] }
|
|
23462
23490
|
};
|
|
23463
23491
|
},
|
|
23464
23492
|
applyToEnvironment(environment) {
|
|
@@ -23509,15 +23537,35 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
|
|
|
23509
23537
|
exitCallback$1 = () => {
|
|
23510
23538
|
for (const nodeJsCompatWarnings of nodeJsCompatWarningsMap.values()) nodeJsCompatWarnings.renderWarnings();
|
|
23511
23539
|
};
|
|
23540
|
+
function resolveId(environmentName, source, importer) {
|
|
23541
|
+
const workerConfig = ctx.getWorkerConfig(environmentName);
|
|
23542
|
+
const nodeJsCompat = ctx.getNodeJsCompat(environmentName);
|
|
23543
|
+
if (workerConfig && !nodeJsCompat) {
|
|
23544
|
+
if (hasNodeJsAls(workerConfig) && isNodeAlsModule(source)) return;
|
|
23545
|
+
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
23546
|
+
if (source.startsWith("node:") || nonPrefixedNodeModules.includes(source)) {
|
|
23547
|
+
nodeJsCompatWarnings?.registerImport(source, importer);
|
|
23548
|
+
return {
|
|
23549
|
+
id: source,
|
|
23550
|
+
external: true
|
|
23551
|
+
};
|
|
23552
|
+
}
|
|
23553
|
+
}
|
|
23554
|
+
}
|
|
23512
23555
|
return {
|
|
23513
23556
|
enforce: "pre",
|
|
23514
23557
|
configEnvironment(environmentName) {
|
|
23515
23558
|
const workerConfig = ctx.getWorkerConfig(environmentName);
|
|
23516
23559
|
const nodeJsCompat = ctx.getNodeJsCompat(environmentName);
|
|
23517
|
-
if (workerConfig && !nodeJsCompat) return { optimizeDeps: {
|
|
23560
|
+
if (workerConfig && !nodeJsCompat) return { optimizeDeps: { ...isRolldown ? { rolldownOptions: { plugins: [{
|
|
23561
|
+
name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
|
|
23562
|
+
resolveId(source, importer) {
|
|
23563
|
+
return resolveId(environmentName, source, importer);
|
|
23564
|
+
}
|
|
23565
|
+
}] } } : { esbuildOptions: { plugins: [{
|
|
23518
23566
|
name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
|
|
23519
23567
|
setup(build) {
|
|
23520
|
-
build.onResolve({ filter:
|
|
23568
|
+
build.onResolve({ filter: /* @__PURE__ */ new RegExp(`^(${nonPrefixedNodeModules.join("|")}|node:.+)$`) }, ({ path, importer }) => {
|
|
23521
23569
|
if (hasNodeJsAls(workerConfig) && isNodeAlsModule(path)) return;
|
|
23522
23570
|
nodeJsCompatWarningsMap.get(workerConfig)?.registerImport(path, importer);
|
|
23523
23571
|
return {
|
|
@@ -23526,7 +23574,7 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
|
|
|
23526
23574
|
};
|
|
23527
23575
|
});
|
|
23528
23576
|
}
|
|
23529
|
-
}] } } };
|
|
23577
|
+
}] } } } };
|
|
23530
23578
|
},
|
|
23531
23579
|
configResolved(resolvedViteConfig) {
|
|
23532
23580
|
for (const environmentName of Object.keys(resolvedViteConfig.environments)) {
|
|
@@ -23535,20 +23583,11 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
|
|
|
23535
23583
|
if (workerConfig && !nodeJsCompat) nodeJsCompatWarningsMap.set(workerConfig, new NodeJsCompatWarnings(environmentName, resolvedViteConfig));
|
|
23536
23584
|
}
|
|
23537
23585
|
},
|
|
23586
|
+
applyToEnvironment(environment) {
|
|
23587
|
+
return ctx.getWorkerConfig(environment.name) !== void 0 && !ctx.getNodeJsCompat(environment.name);
|
|
23588
|
+
},
|
|
23538
23589
|
async resolveId(source, importer) {
|
|
23539
|
-
|
|
23540
|
-
const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
|
|
23541
|
-
if (workerConfig && !nodeJsCompat) {
|
|
23542
|
-
if (hasNodeJsAls(workerConfig) && isNodeAlsModule(source)) return;
|
|
23543
|
-
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
23544
|
-
if (nodeJsBuiltins.has(source)) {
|
|
23545
|
-
nodeJsCompatWarnings?.registerImport(source, importer);
|
|
23546
|
-
return {
|
|
23547
|
-
id: source,
|
|
23548
|
-
external: true
|
|
23549
|
-
};
|
|
23550
|
-
}
|
|
23551
|
-
}
|
|
23590
|
+
return resolveId(this.environment.name, source, importer);
|
|
23552
23591
|
}
|
|
23553
23592
|
};
|
|
23554
23593
|
});
|