@cloudflare/vite-plugin 1.13.2 → 1.13.4
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.js +156 -147
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -248,17 +248,17 @@ var require_ignore = __commonJS({
|
|
|
248
248
|
var throwError = (message, Ctor) => {
|
|
249
249
|
throw new Ctor(message);
|
|
250
250
|
};
|
|
251
|
-
var checkPath = (
|
|
252
|
-
if (!isString2(
|
|
251
|
+
var checkPath = (path15, originalPath, doThrow) => {
|
|
252
|
+
if (!isString2(path15)) {
|
|
253
253
|
return doThrow(
|
|
254
254
|
`path must be a string, but got \`${originalPath}\``,
|
|
255
255
|
TypeError
|
|
256
256
|
);
|
|
257
257
|
}
|
|
258
|
-
if (!
|
|
258
|
+
if (!path15) {
|
|
259
259
|
return doThrow(`path must not be empty`, TypeError);
|
|
260
260
|
}
|
|
261
|
-
if (checkPath.isNotRelative(
|
|
261
|
+
if (checkPath.isNotRelative(path15)) {
|
|
262
262
|
const r2 = "`path.relative()`d";
|
|
263
263
|
return doThrow(
|
|
264
264
|
`path should be a ${r2} string, but got "${originalPath}"`,
|
|
@@ -267,7 +267,7 @@ var require_ignore = __commonJS({
|
|
|
267
267
|
}
|
|
268
268
|
return true;
|
|
269
269
|
};
|
|
270
|
-
var isNotRelative = (
|
|
270
|
+
var isNotRelative = (path15) => REGEX_TEST_INVALID_PATH.test(path15);
|
|
271
271
|
checkPath.isNotRelative = isNotRelative;
|
|
272
272
|
checkPath.convert = (p) => p;
|
|
273
273
|
var Ignore = class {
|
|
@@ -326,7 +326,7 @@ var require_ignore = __commonJS({
|
|
|
326
326
|
// setting `checkUnignored` to `false` could reduce additional
|
|
327
327
|
// path matching.
|
|
328
328
|
// @returns {TestResult} true if a file is ignored
|
|
329
|
-
_testOne(
|
|
329
|
+
_testOne(path15, checkUnignored) {
|
|
330
330
|
let ignored = false;
|
|
331
331
|
let unignored = false;
|
|
332
332
|
this._rules.forEach((rule) => {
|
|
@@ -334,7 +334,7 @@ var require_ignore = __commonJS({
|
|
|
334
334
|
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
|
335
335
|
return;
|
|
336
336
|
}
|
|
337
|
-
const matched = rule.regex.test(
|
|
337
|
+
const matched = rule.regex.test(path15);
|
|
338
338
|
if (matched) {
|
|
339
339
|
ignored = !negative;
|
|
340
340
|
unignored = negative;
|
|
@@ -347,24 +347,24 @@ var require_ignore = __commonJS({
|
|
|
347
347
|
}
|
|
348
348
|
// @returns {TestResult}
|
|
349
349
|
_test(originalPath, cache2, checkUnignored, slices) {
|
|
350
|
-
const
|
|
350
|
+
const path15 = originalPath && checkPath.convert(originalPath);
|
|
351
351
|
checkPath(
|
|
352
|
-
|
|
352
|
+
path15,
|
|
353
353
|
originalPath,
|
|
354
354
|
this._allowRelativePaths ? RETURN_FALSE : throwError
|
|
355
355
|
);
|
|
356
|
-
return this._t(
|
|
356
|
+
return this._t(path15, cache2, checkUnignored, slices);
|
|
357
357
|
}
|
|
358
|
-
_t(
|
|
359
|
-
if (
|
|
360
|
-
return cache2[
|
|
358
|
+
_t(path15, cache2, checkUnignored, slices) {
|
|
359
|
+
if (path15 in cache2) {
|
|
360
|
+
return cache2[path15];
|
|
361
361
|
}
|
|
362
362
|
if (!slices) {
|
|
363
|
-
slices =
|
|
363
|
+
slices = path15.split(SLASH);
|
|
364
364
|
}
|
|
365
365
|
slices.pop();
|
|
366
366
|
if (!slices.length) {
|
|
367
|
-
return cache2[
|
|
367
|
+
return cache2[path15] = this._testOne(path15, checkUnignored);
|
|
368
368
|
}
|
|
369
369
|
const parent = this._t(
|
|
370
370
|
slices.join(SLASH) + SLASH,
|
|
@@ -372,24 +372,24 @@ var require_ignore = __commonJS({
|
|
|
372
372
|
checkUnignored,
|
|
373
373
|
slices
|
|
374
374
|
);
|
|
375
|
-
return cache2[
|
|
375
|
+
return cache2[path15] = parent.ignored ? parent : this._testOne(path15, checkUnignored);
|
|
376
376
|
}
|
|
377
|
-
ignores(
|
|
378
|
-
return this._test(
|
|
377
|
+
ignores(path15) {
|
|
378
|
+
return this._test(path15, this._ignoreCache, false).ignored;
|
|
379
379
|
}
|
|
380
380
|
createFilter() {
|
|
381
|
-
return (
|
|
381
|
+
return (path15) => !this.ignores(path15);
|
|
382
382
|
}
|
|
383
383
|
filter(paths) {
|
|
384
384
|
return makeArray(paths).filter(this.createFilter());
|
|
385
385
|
}
|
|
386
386
|
// @returns {TestResult}
|
|
387
|
-
test(
|
|
388
|
-
return this._test(
|
|
387
|
+
test(path15) {
|
|
388
|
+
return this._test(path15, this._testCache, true);
|
|
389
389
|
}
|
|
390
390
|
};
|
|
391
391
|
var factory = (options) => new Ignore(options);
|
|
392
|
-
var isPathValid = (
|
|
392
|
+
var isPathValid = (path15) => checkPath(path15 && checkPath.convert(path15), path15, RETURN_FALSE);
|
|
393
393
|
factory.isPathValid = isPathValid;
|
|
394
394
|
factory.default = factory;
|
|
395
395
|
module.exports = factory;
|
|
@@ -400,15 +400,15 @@ var require_ignore = __commonJS({
|
|
|
400
400
|
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
401
401
|
checkPath.convert = makePosix;
|
|
402
402
|
const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
403
|
-
checkPath.isNotRelative = (
|
|
403
|
+
checkPath.isNotRelative = (path15) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path15) || isNotRelative(path15);
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
});
|
|
407
407
|
|
|
408
408
|
// src/index.ts
|
|
409
|
-
import
|
|
409
|
+
import assert13 from "node:assert";
|
|
410
410
|
import * as fsp2 from "node:fs/promises";
|
|
411
|
-
import * as
|
|
411
|
+
import * as path14 from "node:path";
|
|
412
412
|
import * as util3 from "node:util";
|
|
413
413
|
|
|
414
414
|
// ../containers-shared/src/utils.ts
|
|
@@ -685,8 +685,8 @@ for (let i = 0; i < chars.length; i++) {
|
|
|
685
685
|
intToChar[i] = c;
|
|
686
686
|
charToInt[c] = i;
|
|
687
687
|
}
|
|
688
|
-
function encodeInteger(builder, num,
|
|
689
|
-
let delta = num -
|
|
688
|
+
function encodeInteger(builder, num, relative9) {
|
|
689
|
+
let delta = num - relative9;
|
|
690
690
|
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
691
691
|
do {
|
|
692
692
|
let clamped = delta & 31;
|
|
@@ -1741,7 +1741,7 @@ var MagicString = class _MagicString {
|
|
|
1741
1741
|
// src/index.ts
|
|
1742
1742
|
import { CoreHeaders, Miniflare } from "miniflare";
|
|
1743
1743
|
import colors4 from "picocolors";
|
|
1744
|
-
import * as
|
|
1744
|
+
import * as vite6 from "vite";
|
|
1745
1745
|
|
|
1746
1746
|
// src/constants.ts
|
|
1747
1747
|
var ROUTER_WORKER_NAME = "__router-worker__";
|
|
@@ -1927,11 +1927,11 @@ ${invalidHeaderRulesList}`
|
|
|
1927
1927
|
}
|
|
1928
1928
|
|
|
1929
1929
|
// ../workers-shared/utils/configuration/validateURL.ts
|
|
1930
|
-
var extractPathname = (
|
|
1931
|
-
if (!
|
|
1932
|
-
|
|
1930
|
+
var extractPathname = (path15 = "/", includeSearch, includeHash) => {
|
|
1931
|
+
if (!path15.startsWith("/")) {
|
|
1932
|
+
path15 = `/${path15}`;
|
|
1933
1933
|
}
|
|
1934
|
-
const url = new URL(`//${
|
|
1934
|
+
const url = new URL(`//${path15}`, "relative://");
|
|
1935
1935
|
return `${url.pathname}${includeSearch ? url.search : ""}${includeHash ? url.hash : ""}`;
|
|
1936
1936
|
};
|
|
1937
1937
|
var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
|
|
@@ -1964,8 +1964,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
|
|
|
1964
1964
|
if (!token.startsWith("/") && onlyRelative) {
|
|
1965
1965
|
token = `/${token}`;
|
|
1966
1966
|
}
|
|
1967
|
-
const
|
|
1968
|
-
if (
|
|
1967
|
+
const path15 = PATH_REGEX.exec(token);
|
|
1968
|
+
if (path15) {
|
|
1969
1969
|
try {
|
|
1970
1970
|
return [extractPathname(token, includeSearch, includeHash), void 0];
|
|
1971
1971
|
} catch {
|
|
@@ -2026,7 +2026,7 @@ function parseHeaders(input, {
|
|
|
2026
2026
|
});
|
|
2027
2027
|
}
|
|
2028
2028
|
}
|
|
2029
|
-
const [
|
|
2029
|
+
const [path15, pathError] = validateUrl(line, false, true);
|
|
2030
2030
|
if (pathError) {
|
|
2031
2031
|
invalid.push({
|
|
2032
2032
|
line,
|
|
@@ -2037,7 +2037,7 @@ function parseHeaders(input, {
|
|
|
2037
2037
|
continue;
|
|
2038
2038
|
}
|
|
2039
2039
|
rule = {
|
|
2040
|
-
path:
|
|
2040
|
+
path: path15,
|
|
2041
2041
|
line,
|
|
2042
2042
|
headers: {},
|
|
2043
2043
|
unsetHeaders: []
|
|
@@ -3385,12 +3385,12 @@ var Mime = class {
|
|
|
3385
3385
|
}
|
|
3386
3386
|
return this;
|
|
3387
3387
|
}
|
|
3388
|
-
getType(
|
|
3389
|
-
if (typeof
|
|
3388
|
+
getType(path15) {
|
|
3389
|
+
if (typeof path15 !== "string")
|
|
3390
3390
|
return null;
|
|
3391
|
-
const last =
|
|
3391
|
+
const last = path15.replace(/^.*[/\\]/s, "").toLowerCase();
|
|
3392
3392
|
const ext = last.replace(/^.*\./s, "").toLowerCase();
|
|
3393
|
-
const hasPath = last.length <
|
|
3393
|
+
const hasPath = last.length < path15.length;
|
|
3394
3394
|
const hasDot = ext.length < last.length - 1;
|
|
3395
3395
|
if (!hasDot && hasPath)
|
|
3396
3396
|
return null;
|
|
@@ -3792,8 +3792,8 @@ function getErrorMap() {
|
|
|
3792
3792
|
return overrideErrorMap;
|
|
3793
3793
|
}
|
|
3794
3794
|
var makeIssue = (params) => {
|
|
3795
|
-
const { data: data2, path:
|
|
3796
|
-
const fullPath = [...
|
|
3795
|
+
const { data: data2, path: path15, errorMaps, issueData } = params;
|
|
3796
|
+
const fullPath = [...path15, ...issueData.path || []];
|
|
3797
3797
|
const fullIssue = {
|
|
3798
3798
|
...issueData,
|
|
3799
3799
|
path: fullPath
|
|
@@ -3892,11 +3892,11 @@ var errorUtil;
|
|
|
3892
3892
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
3893
3893
|
})(errorUtil || (errorUtil = {}));
|
|
3894
3894
|
var ParseInputLazyPath = class {
|
|
3895
|
-
constructor(parent, value,
|
|
3895
|
+
constructor(parent, value, path15, key) {
|
|
3896
3896
|
this._cachedPath = [];
|
|
3897
3897
|
this.parent = parent;
|
|
3898
3898
|
this.data = value;
|
|
3899
|
-
this._path =
|
|
3899
|
+
this._path = path15;
|
|
3900
3900
|
this._key = key;
|
|
3901
3901
|
}
|
|
3902
3902
|
get path() {
|
|
@@ -7464,8 +7464,8 @@ var postfixRE = /[?#].*$/;
|
|
|
7464
7464
|
function cleanUrl(url) {
|
|
7465
7465
|
return url.replace(postfixRE, "");
|
|
7466
7466
|
}
|
|
7467
|
-
function withTrailingSlash(
|
|
7468
|
-
return
|
|
7467
|
+
function withTrailingSlash(path15) {
|
|
7468
|
+
return path15.endsWith("/") ? path15 : `${path15}/`;
|
|
7469
7469
|
}
|
|
7470
7470
|
function createRequestHandler(handler) {
|
|
7471
7471
|
return async (req, res, next) => {
|
|
@@ -8152,13 +8152,13 @@ var getQueryString = (params) => {
|
|
|
8152
8152
|
};
|
|
8153
8153
|
var getUrl = (config, options) => {
|
|
8154
8154
|
const encoder = config.ENCODE_PATH || encodeURI;
|
|
8155
|
-
const
|
|
8155
|
+
const path15 = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
|
|
8156
8156
|
if (options.path?.hasOwnProperty(group)) {
|
|
8157
8157
|
return encoder(String(options.path[group]));
|
|
8158
8158
|
}
|
|
8159
8159
|
return substring;
|
|
8160
8160
|
});
|
|
8161
|
-
const url = `${config.BASE}${
|
|
8161
|
+
const url = `${config.BASE}${path15}`;
|
|
8162
8162
|
if (options.query) {
|
|
8163
8163
|
return `${url}${getQueryString(options.query)}`;
|
|
8164
8164
|
}
|
|
@@ -9463,9 +9463,9 @@ function getPreviewModules(main, modulesRules) {
|
|
|
9463
9463
|
path: entryPath
|
|
9464
9464
|
},
|
|
9465
9465
|
...modulesRules.flatMap(
|
|
9466
|
-
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((
|
|
9466
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path15) => ({
|
|
9467
9467
|
type,
|
|
9468
|
-
path:
|
|
9468
|
+
path: path15
|
|
9469
9469
|
}))
|
|
9470
9470
|
)
|
|
9471
9471
|
]
|
|
@@ -15136,17 +15136,17 @@ function withTrailingSlash2(input = "", respectQueryAndFragment) {
|
|
|
15136
15136
|
if (hasTrailingSlash(input, true)) {
|
|
15137
15137
|
return input || "/";
|
|
15138
15138
|
}
|
|
15139
|
-
let
|
|
15139
|
+
let path15 = input;
|
|
15140
15140
|
let fragment = "";
|
|
15141
15141
|
const fragmentIndex = input.indexOf("#");
|
|
15142
15142
|
if (fragmentIndex >= 0) {
|
|
15143
|
-
|
|
15143
|
+
path15 = input.slice(0, fragmentIndex);
|
|
15144
15144
|
fragment = input.slice(fragmentIndex);
|
|
15145
|
-
if (!
|
|
15145
|
+
if (!path15) {
|
|
15146
15146
|
return fragment;
|
|
15147
15147
|
}
|
|
15148
15148
|
}
|
|
15149
|
-
const [s0, ...s] =
|
|
15149
|
+
const [s0, ...s] = path15.split("?");
|
|
15150
15150
|
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
15151
15151
|
}
|
|
15152
15152
|
function isNonEmptyURL(url) {
|
|
@@ -15180,8 +15180,8 @@ import path9, { dirname as dirname6 } from "node:path";
|
|
|
15180
15180
|
import v8 from "node:v8";
|
|
15181
15181
|
import { format as format2, inspect } from "node:util";
|
|
15182
15182
|
var BUILTIN_MODULES = new Set(builtinModules);
|
|
15183
|
-
function normalizeSlash(
|
|
15184
|
-
return
|
|
15183
|
+
function normalizeSlash(path15) {
|
|
15184
|
+
return path15.replace(/\\/g, "/");
|
|
15185
15185
|
}
|
|
15186
15186
|
var own$1 = {}.hasOwnProperty;
|
|
15187
15187
|
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
@@ -15294,8 +15294,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
|
15294
15294
|
* @param {string} [base]
|
|
15295
15295
|
* @param {string} [message]
|
|
15296
15296
|
*/
|
|
15297
|
-
(
|
|
15298
|
-
return `Invalid package config ${
|
|
15297
|
+
(path15, base, message) => {
|
|
15298
|
+
return `Invalid package config ${path15}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
15299
15299
|
},
|
|
15300
15300
|
Error
|
|
15301
15301
|
);
|
|
@@ -15327,8 +15327,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
|
|
|
15327
15327
|
* @param {string} base
|
|
15328
15328
|
* @param {boolean} [exactUrl]
|
|
15329
15329
|
*/
|
|
15330
|
-
(
|
|
15331
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${
|
|
15330
|
+
(path15, base, exactUrl = false) => {
|
|
15331
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path15}' imported from ${base}`;
|
|
15332
15332
|
},
|
|
15333
15333
|
Error
|
|
15334
15334
|
);
|
|
@@ -15379,8 +15379,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
|
15379
15379
|
* @param {string} extension
|
|
15380
15380
|
* @param {string} path
|
|
15381
15381
|
*/
|
|
15382
|
-
(extension,
|
|
15383
|
-
return `Unknown file extension "${extension}" for ${
|
|
15382
|
+
(extension, path15) => {
|
|
15383
|
+
return `Unknown file extension "${extension}" for ${path15}`;
|
|
15384
15384
|
},
|
|
15385
15385
|
TypeError
|
|
15386
15386
|
);
|
|
@@ -15752,9 +15752,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
15752
15752
|
);
|
|
15753
15753
|
}
|
|
15754
15754
|
}
|
|
15755
|
-
function tryStatSync(
|
|
15755
|
+
function tryStatSync(path15) {
|
|
15756
15756
|
try {
|
|
15757
|
-
return statSync2(
|
|
15757
|
+
return statSync2(path15);
|
|
15758
15758
|
} catch {
|
|
15759
15759
|
}
|
|
15760
15760
|
}
|
|
@@ -16679,8 +16679,8 @@ var nodeJsBuiltins = /* @__PURE__ */ new Set([
|
|
|
16679
16679
|
var NODEJS_MODULES_RE = new RegExp(
|
|
16680
16680
|
`^(node:)?(${builtinModules2.join("|")})$`
|
|
16681
16681
|
);
|
|
16682
|
-
function isNodeAlsModule(
|
|
16683
|
-
return /^(node:)?async_hooks$/.test(
|
|
16682
|
+
function isNodeAlsModule(path15) {
|
|
16683
|
+
return /^(node:)?async_hooks$/.test(path15);
|
|
16684
16684
|
}
|
|
16685
16685
|
function assertHasNodeJsCompat(nodeJsCompat) {
|
|
16686
16686
|
assert8(nodeJsCompat, `expected nodeJsCompat to be defined`);
|
|
@@ -16725,9 +16725,25 @@ var NodeJsCompatWarnings = class {
|
|
|
16725
16725
|
}
|
|
16726
16726
|
};
|
|
16727
16727
|
|
|
16728
|
+
// src/output-config.ts
|
|
16729
|
+
import assert9 from "node:assert";
|
|
16730
|
+
import * as path11 from "node:path";
|
|
16731
|
+
import "vite";
|
|
16732
|
+
function getAssetsDirectory(workerOutputDirectory, resolvedViteConfig) {
|
|
16733
|
+
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
16734
|
+
assert9(
|
|
16735
|
+
clientOutputDirectory,
|
|
16736
|
+
"Unexpected error: client output directory is undefined"
|
|
16737
|
+
);
|
|
16738
|
+
return path11.relative(
|
|
16739
|
+
path11.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
16740
|
+
path11.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
16741
|
+
);
|
|
16742
|
+
}
|
|
16743
|
+
|
|
16728
16744
|
// src/plugin-config.ts
|
|
16729
|
-
import
|
|
16730
|
-
import * as
|
|
16745
|
+
import assert11 from "node:assert";
|
|
16746
|
+
import * as path13 from "node:path";
|
|
16731
16747
|
|
|
16732
16748
|
// ../workers-shared/utils/configuration/parseStaticRouting.ts
|
|
16733
16749
|
function parseStaticRouting(input) {
|
|
@@ -16806,12 +16822,12 @@ var formatInvalidRoutes = (invalidRules) => {
|
|
|
16806
16822
|
};
|
|
16807
16823
|
|
|
16808
16824
|
// src/plugin-config.ts
|
|
16809
|
-
import * as
|
|
16825
|
+
import * as vite5 from "vite";
|
|
16810
16826
|
|
|
16811
16827
|
// src/workers-configs.ts
|
|
16812
|
-
import
|
|
16828
|
+
import assert10 from "node:assert";
|
|
16813
16829
|
import * as fs5 from "node:fs";
|
|
16814
|
-
import * as
|
|
16830
|
+
import * as path12 from "node:path";
|
|
16815
16831
|
import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
|
|
16816
16832
|
var nonApplicableWorkerConfigs = {
|
|
16817
16833
|
/**
|
|
@@ -16907,7 +16923,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
16907
16923
|
const lines2 = [
|
|
16908
16924
|
`
|
|
16909
16925
|
|
|
16910
|
-
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${
|
|
16926
|
+
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path12.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
|
|
16911
16927
|
];
|
|
16912
16928
|
nonApplicableLines.forEach((line) => lines2.push(line));
|
|
16913
16929
|
lines2.push("");
|
|
@@ -16921,7 +16937,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
16921
16937
|
);
|
|
16922
16938
|
if (nonApplicableLines.length > 0) {
|
|
16923
16939
|
lines.push(
|
|
16924
|
-
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${
|
|
16940
|
+
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path12.relative("", workerConfig.config.configPath)}\`)` : ""}`
|
|
16925
16941
|
);
|
|
16926
16942
|
nonApplicableLines.forEach((line) => lines.push(line));
|
|
16927
16943
|
}
|
|
@@ -17013,7 +17029,7 @@ function maybeResolveMain(main, configPath) {
|
|
|
17013
17029
|
if (!ENTRY_MODULE_EXTENSIONS.some((extension) => main.endsWith(extension))) {
|
|
17014
17030
|
return main;
|
|
17015
17031
|
}
|
|
17016
|
-
const resolvedMain =
|
|
17032
|
+
const resolvedMain = path12.resolve(path12.dirname(configPath), main);
|
|
17017
17033
|
if (!fs5.existsSync(resolvedMain)) {
|
|
17018
17034
|
throw new Error(
|
|
17019
17035
|
`The provided Wrangler config main field (${resolvedMain}) doesn't point to an existing file`
|
|
@@ -17023,10 +17039,10 @@ function maybeResolveMain(main, configPath) {
|
|
|
17023
17039
|
}
|
|
17024
17040
|
function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliaryWorker = false) {
|
|
17025
17041
|
if (requestedConfigPath) {
|
|
17026
|
-
const configPath2 =
|
|
17042
|
+
const configPath2 = path12.resolve(root, requestedConfigPath);
|
|
17027
17043
|
const forAuxiliaryWorkerErrorMessage = isForAuxiliaryWorker ? " requested for one of your auxiliary workers" : "";
|
|
17028
17044
|
const errorMessagePrefix = `The provided configPath (${configPath2})${forAuxiliaryWorkerErrorMessage}`;
|
|
17029
|
-
const fileExtension =
|
|
17045
|
+
const fileExtension = path12.extname(configPath2).slice(1);
|
|
17030
17046
|
if (!allowedWranglerConfigExtensions.includes(fileExtension)) {
|
|
17031
17047
|
const foundExtensionMessage = !fileExtension ? "no extension found" : `"${fileExtension}" found`;
|
|
17032
17048
|
throw new Error(
|
|
@@ -17046,7 +17062,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
|
|
|
17046
17062
|
}
|
|
17047
17063
|
return configPath2;
|
|
17048
17064
|
}
|
|
17049
|
-
|
|
17065
|
+
assert10(
|
|
17050
17066
|
isForAuxiliaryWorker === false,
|
|
17051
17067
|
"Unexpected Error: trying to find the wrangler config for an auxiliary worker"
|
|
17052
17068
|
);
|
|
@@ -17060,7 +17076,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
|
|
|
17060
17076
|
}
|
|
17061
17077
|
function findWranglerConfig(root) {
|
|
17062
17078
|
for (const extension of allowedWranglerConfigExtensions) {
|
|
17063
|
-
const configPath =
|
|
17079
|
+
const configPath = path12.join(root, `wrangler.${extension}`);
|
|
17064
17080
|
if (fs5.existsSync(configPath)) {
|
|
17065
17081
|
return configPath;
|
|
17066
17082
|
}
|
|
@@ -17078,7 +17094,13 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17078
17094
|
inspectorPort: pluginConfig.inspectorPort,
|
|
17079
17095
|
experimental: pluginConfig.experimental ?? {}
|
|
17080
17096
|
};
|
|
17081
|
-
const root = userConfig.root ?
|
|
17097
|
+
const root = userConfig.root ? path13.resolve(userConfig.root) : process.cwd();
|
|
17098
|
+
const prefixedEnv = vite5.loadEnv(viteEnv.mode, root, [
|
|
17099
|
+
"CLOUDFLARE_",
|
|
17100
|
+
// TODO: Remove deprecated WRANGLER prefix support in next major version
|
|
17101
|
+
"WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_"
|
|
17102
|
+
]);
|
|
17103
|
+
Object.assign(process.env, prefixedEnv);
|
|
17082
17104
|
if (viteEnv.isPreview) {
|
|
17083
17105
|
return {
|
|
17084
17106
|
...shared,
|
|
@@ -17087,12 +17109,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17087
17109
|
};
|
|
17088
17110
|
}
|
|
17089
17111
|
const configPaths = /* @__PURE__ */ new Set();
|
|
17090
|
-
const
|
|
17091
|
-
viteEnv.mode,
|
|
17092
|
-
root,
|
|
17093
|
-
/* prefixes */
|
|
17094
|
-
""
|
|
17095
|
-
);
|
|
17112
|
+
const cloudflareEnv = prefixedEnv.CLOUDFLARE_ENV;
|
|
17096
17113
|
const entryWorkerConfigPath = getValidatedWranglerConfigPath(
|
|
17097
17114
|
root,
|
|
17098
17115
|
pluginConfig.configPath
|
|
@@ -17143,7 +17160,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17143
17160
|
}
|
|
17144
17161
|
);
|
|
17145
17162
|
auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
|
|
17146
|
-
|
|
17163
|
+
assert11(
|
|
17147
17164
|
workerResolvedConfig.type === "worker",
|
|
17148
17165
|
"Unexpected error: received AssetsOnlyResult with auxiliary workers."
|
|
17149
17166
|
);
|
|
@@ -17178,26 +17195,26 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17178
17195
|
};
|
|
17179
17196
|
}
|
|
17180
17197
|
function assertIsNotPreview(resolvedPluginConfig) {
|
|
17181
|
-
|
|
17198
|
+
assert11(
|
|
17182
17199
|
resolvedPluginConfig.type !== "preview",
|
|
17183
17200
|
`Expected "assets-only" or "workers" plugin config`
|
|
17184
17201
|
);
|
|
17185
17202
|
}
|
|
17186
17203
|
function assertIsPreview(resolvedPluginConfig) {
|
|
17187
|
-
|
|
17204
|
+
assert11(
|
|
17188
17205
|
resolvedPluginConfig.type === "preview",
|
|
17189
17206
|
`Expected "preview" plugin config`
|
|
17190
17207
|
);
|
|
17191
17208
|
}
|
|
17192
17209
|
|
|
17193
17210
|
// src/vite-config.ts
|
|
17194
|
-
import
|
|
17211
|
+
import assert12 from "node:assert";
|
|
17195
17212
|
function validateWorkerEnvironmentOptions(resolvedPluginConfig, resolvedViteConfig) {
|
|
17196
17213
|
const workerEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
|
|
17197
17214
|
const disallowedEnvironmentOptionsMap = /* @__PURE__ */ new Map();
|
|
17198
17215
|
for (const environmentName of workerEnvironmentNames) {
|
|
17199
17216
|
const environmentOptions = resolvedViteConfig.environments[environmentName];
|
|
17200
|
-
|
|
17217
|
+
assert12(
|
|
17201
17218
|
environmentOptions,
|
|
17202
17219
|
`Missing environment config for "${environmentName}"`
|
|
17203
17220
|
);
|
|
@@ -17392,46 +17409,36 @@ if (import.meta.hot) {
|
|
|
17392
17409
|
},
|
|
17393
17410
|
generateBundle(_, bundle) {
|
|
17394
17411
|
assertIsNotPreview(resolvedPluginConfig);
|
|
17395
|
-
let
|
|
17412
|
+
let outputConfig;
|
|
17396
17413
|
if (resolvedPluginConfig.type === "workers") {
|
|
17397
|
-
const
|
|
17398
|
-
if (!
|
|
17414
|
+
const inputConfig = resolvedPluginConfig.workers[this.environment.name];
|
|
17415
|
+
if (!inputConfig) {
|
|
17399
17416
|
return;
|
|
17400
17417
|
}
|
|
17401
17418
|
const entryChunk = Object.values(bundle).find(
|
|
17402
17419
|
(chunk) => chunk.type === "chunk" && chunk.isEntry && chunk.name === MAIN_ENTRY_NAME
|
|
17403
17420
|
);
|
|
17404
|
-
|
|
17421
|
+
assert13(
|
|
17405
17422
|
entryChunk,
|
|
17406
17423
|
`Expected entry chunk with name "${MAIN_ENTRY_NAME}"`
|
|
17407
17424
|
);
|
|
17408
|
-
workerConfig.main = entryChunk.fileName;
|
|
17409
|
-
workerConfig.no_bundle = true;
|
|
17410
|
-
workerConfig.rules = [
|
|
17411
|
-
{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }
|
|
17412
|
-
];
|
|
17413
17425
|
const isEntryWorker = this.environment.name === resolvedPluginConfig.entryWorkerEnvironmentName;
|
|
17414
|
-
|
|
17415
|
-
|
|
17416
|
-
|
|
17417
|
-
|
|
17418
|
-
|
|
17419
|
-
|
|
17420
|
-
|
|
17421
|
-
|
|
17422
|
-
|
|
17423
|
-
|
|
17424
|
-
path13.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
17425
|
-
path13.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
17426
|
+
outputConfig = {
|
|
17427
|
+
...inputConfig,
|
|
17428
|
+
main: entryChunk.fileName,
|
|
17429
|
+
no_bundle: true,
|
|
17430
|
+
rules: [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }],
|
|
17431
|
+
assets: isEntryWorker ? {
|
|
17432
|
+
...inputConfig.assets,
|
|
17433
|
+
directory: getAssetsDirectory(
|
|
17434
|
+
this.environment.config.build.outDir,
|
|
17435
|
+
resolvedViteConfig
|
|
17426
17436
|
)
|
|
17427
|
-
}
|
|
17428
|
-
}
|
|
17429
|
-
|
|
17430
|
-
}
|
|
17431
|
-
config = workerConfig;
|
|
17432
|
-
if (workerConfig.configPath) {
|
|
17437
|
+
} : void 0
|
|
17438
|
+
};
|
|
17439
|
+
if (inputConfig.configPath) {
|
|
17433
17440
|
const localDevVars = getLocalDevVarsForPreview(
|
|
17434
|
-
|
|
17441
|
+
inputConfig.configPath,
|
|
17435
17442
|
resolvedPluginConfig.cloudflareEnv
|
|
17436
17443
|
);
|
|
17437
17444
|
if (localDevVars) {
|
|
@@ -17443,10 +17450,13 @@ if (import.meta.hot) {
|
|
|
17443
17450
|
}
|
|
17444
17451
|
}
|
|
17445
17452
|
} else if (this.environment.name === "client") {
|
|
17446
|
-
const
|
|
17447
|
-
|
|
17448
|
-
...
|
|
17449
|
-
|
|
17453
|
+
const inputConfig = resolvedPluginConfig.config;
|
|
17454
|
+
outputConfig = {
|
|
17455
|
+
...inputConfig,
|
|
17456
|
+
assets: {
|
|
17457
|
+
...inputConfig.assets,
|
|
17458
|
+
directory: "."
|
|
17459
|
+
}
|
|
17450
17460
|
};
|
|
17451
17461
|
const filesToAssetsIgnore = ["wrangler.json", ".dev.vars"];
|
|
17452
17462
|
this.emitFile({
|
|
@@ -17455,18 +17465,17 @@ if (import.meta.hot) {
|
|
|
17455
17465
|
source: `${filesToAssetsIgnore.join("\n")}
|
|
17456
17466
|
`
|
|
17457
17467
|
});
|
|
17458
|
-
config = assetsOnlyConfig;
|
|
17459
17468
|
}
|
|
17460
|
-
if (!
|
|
17469
|
+
if (!outputConfig) {
|
|
17461
17470
|
return;
|
|
17462
17471
|
}
|
|
17463
|
-
if (
|
|
17464
|
-
|
|
17472
|
+
if (outputConfig.unsafe && Object.keys(outputConfig.unsafe).length === 0) {
|
|
17473
|
+
outputConfig.unsafe = void 0;
|
|
17465
17474
|
}
|
|
17466
17475
|
this.emitFile({
|
|
17467
17476
|
type: "asset",
|
|
17468
17477
|
fileName: "wrangler.json",
|
|
17469
|
-
source: JSON.stringify(
|
|
17478
|
+
source: JSON.stringify(outputConfig)
|
|
17470
17479
|
});
|
|
17471
17480
|
},
|
|
17472
17481
|
writeBundle() {
|
|
@@ -17533,13 +17542,13 @@ if (import.meta.hot) {
|
|
|
17533
17542
|
}
|
|
17534
17543
|
let preMiddleware;
|
|
17535
17544
|
if (resolvedPluginConfig.type === "workers") {
|
|
17536
|
-
|
|
17545
|
+
assert13(entryWorkerConfig, `No entry Worker config`);
|
|
17537
17546
|
debuglog4("Initializing the Vite module runners");
|
|
17538
17547
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
17539
17548
|
const entryWorkerName = entryWorkerConfig.name;
|
|
17540
17549
|
if (viteDevServer.httpServer) {
|
|
17541
17550
|
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
17542
|
-
|
|
17551
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17543
17552
|
const entryWorker = await miniflare.getWorker(entryWorkerName);
|
|
17544
17553
|
return entryWorker.fetch;
|
|
17545
17554
|
});
|
|
@@ -17553,12 +17562,12 @@ if (import.meta.hot) {
|
|
|
17553
17562
|
staticRouting.user_worker
|
|
17554
17563
|
);
|
|
17555
17564
|
const userWorkerHandler = createRequestHandler(async (request2) => {
|
|
17556
|
-
|
|
17565
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17557
17566
|
const userWorker = await miniflare.getWorker(entryWorkerName);
|
|
17558
17567
|
return userWorker.fetch(request2, { redirect: "manual" });
|
|
17559
17568
|
});
|
|
17560
17569
|
preMiddleware = async (req, res, next) => {
|
|
17561
|
-
|
|
17570
|
+
assert13(req.url, `req.url not defined`);
|
|
17562
17571
|
const request2 = new Request(new URL(req.url, UNKNOWN_HOST));
|
|
17563
17572
|
if (req[kRequestType] === "asset") {
|
|
17564
17573
|
next();
|
|
@@ -17607,7 +17616,7 @@ if (import.meta.hot) {
|
|
|
17607
17616
|
const cachedTransformMiddlewareIndex = middlewareStack.findIndex(
|
|
17608
17617
|
(middleware) => "name" in middleware.handle && middleware.handle.name === "viteCachedTransformMiddleware"
|
|
17609
17618
|
);
|
|
17610
|
-
|
|
17619
|
+
assert13(
|
|
17611
17620
|
cachedTransformMiddlewareIndex !== -1,
|
|
17612
17621
|
"Failed to find viteCachedTransformMiddleware"
|
|
17613
17622
|
);
|
|
@@ -17618,7 +17627,7 @@ if (import.meta.hot) {
|
|
|
17618
17627
|
}
|
|
17619
17628
|
viteDevServer.middlewares.use(
|
|
17620
17629
|
createRequestHandler(async (request2, req) => {
|
|
17621
|
-
|
|
17630
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17622
17631
|
if (req[kRequestType] === "asset") {
|
|
17623
17632
|
const assetWorker = await miniflare.getWorker(ASSET_WORKER_NAME);
|
|
17624
17633
|
return assetWorker.fetch(request2, { redirect: "manual" });
|
|
@@ -17680,12 +17689,12 @@ if (import.meta.hot) {
|
|
|
17680
17689
|
});
|
|
17681
17690
|
}
|
|
17682
17691
|
handleWebSocket(vitePreviewServer.httpServer, () => {
|
|
17683
|
-
|
|
17692
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17684
17693
|
return miniflare.dispatchFetch;
|
|
17685
17694
|
});
|
|
17686
17695
|
vitePreviewServer.middlewares.use(
|
|
17687
17696
|
createRequestHandler((request2) => {
|
|
17688
|
-
|
|
17697
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17689
17698
|
return miniflare.dispatchFetch(request2, { redirect: "manual" });
|
|
17690
17699
|
})
|
|
17691
17700
|
);
|
|
@@ -17778,7 +17787,7 @@ if (import.meta.hot) {
|
|
|
17778
17787
|
for (const match of matches) {
|
|
17779
17788
|
magicString ??= new MagicString(code);
|
|
17780
17789
|
const [full, _, modulePath] = match;
|
|
17781
|
-
|
|
17790
|
+
assert13(
|
|
17782
17791
|
modulePath,
|
|
17783
17792
|
`Unexpected error: module path not found in reference ${full}.`
|
|
17784
17793
|
);
|
|
@@ -17792,13 +17801,13 @@ if (import.meta.hot) {
|
|
|
17792
17801
|
}
|
|
17793
17802
|
const referenceId = this.emitFile({
|
|
17794
17803
|
type: "asset",
|
|
17795
|
-
name:
|
|
17804
|
+
name: path14.basename(modulePath),
|
|
17796
17805
|
originalFileName: modulePath,
|
|
17797
17806
|
source
|
|
17798
17807
|
});
|
|
17799
17808
|
const emittedFileName = this.getFileName(referenceId);
|
|
17800
|
-
const relativePath =
|
|
17801
|
-
|
|
17809
|
+
const relativePath = vite6.normalizePath(
|
|
17810
|
+
path14.relative(path14.dirname(chunk.fileName), emittedFileName)
|
|
17802
17811
|
);
|
|
17803
17812
|
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
17804
17813
|
magicString.update(
|
|
@@ -17857,7 +17866,7 @@ if (import.meta.hot) {
|
|
|
17857
17866
|
return this.resolve(source, importer, options);
|
|
17858
17867
|
}
|
|
17859
17868
|
if (this.environment.mode === "dev") {
|
|
17860
|
-
|
|
17869
|
+
assert13(
|
|
17861
17870
|
this.environment.depsOptimizer,
|
|
17862
17871
|
"depsOptimizer is required in dev mode"
|
|
17863
17872
|
);
|
|
@@ -17940,13 +17949,13 @@ export default mod.default ?? {};
|
|
|
17940
17949
|
setup(build) {
|
|
17941
17950
|
build.onResolve(
|
|
17942
17951
|
{ filter: NODEJS_MODULES_RE },
|
|
17943
|
-
({ path:
|
|
17944
|
-
if (hasNodeJsAls(workerConfig) && isNodeAlsModule(
|
|
17952
|
+
({ path: path15, importer }) => {
|
|
17953
|
+
if (hasNodeJsAls(workerConfig) && isNodeAlsModule(path15)) {
|
|
17945
17954
|
return;
|
|
17946
17955
|
}
|
|
17947
17956
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
17948
|
-
nodeJsCompatWarnings?.registerImport(
|
|
17949
|
-
return { path:
|
|
17957
|
+
nodeJsCompatWarnings?.registerImport(path15, importer);
|
|
17958
|
+
return { path: path15, external: true };
|
|
17950
17959
|
}
|
|
17951
17960
|
);
|
|
17952
17961
|
}
|
|
@@ -18031,7 +18040,7 @@ export default mod.default ?? {};
|
|
|
18031
18040
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
18032
18041
|
}
|
|
18033
18042
|
const workerNames = resolvedPluginConfig.workers.map((worker) => {
|
|
18034
|
-
|
|
18043
|
+
assert13(worker.name, "Expected the Worker to have a name");
|
|
18035
18044
|
return worker.name;
|
|
18036
18045
|
});
|
|
18037
18046
|
vitePreviewServer.middlewares.use(DEBUG_PATH, async (_, res, next) => {
|
|
@@ -18057,11 +18066,11 @@ export default mod.default ?? {};
|
|
|
18057
18066
|
assertIsNotPreview(resolvedPluginConfig);
|
|
18058
18067
|
if (resolvedPluginConfig.type === "workers") {
|
|
18059
18068
|
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
18060
|
-
|
|
18069
|
+
assert13(entryWorkerConfig, `No entry Worker config`);
|
|
18061
18070
|
const entryWorkerName = entryWorkerConfig.name;
|
|
18062
18071
|
viteDevServer.middlewares.use("/cdn-cgi/", (req, res, next) => {
|
|
18063
18072
|
const requestHandler = createRequestHandler((request2) => {
|
|
18064
|
-
|
|
18073
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
18065
18074
|
request2.headers.set(CoreHeaders.ROUTE_OVERRIDE, entryWorkerName);
|
|
18066
18075
|
return miniflare.dispatchFetch(request2, { redirect: "manual" });
|
|
18067
18076
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.4",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"tinyglobby": "^0.2.12",
|
|
40
40
|
"unenv": "2.0.0-rc.21",
|
|
41
41
|
"ws": "8.18.0",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"wrangler": "4.
|
|
42
|
+
"miniflare": "4.20250923.0",
|
|
43
|
+
"@cloudflare/unenv-preset": "2.7.4",
|
|
44
|
+
"wrangler": "4.39.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@cloudflare/workers-types": "^4.
|
|
47
|
+
"@cloudflare/workers-types": "^4.20250923.0",
|
|
48
48
|
"@types/node": "^22.10.1",
|
|
49
49
|
"@types/ws": "^8.5.13",
|
|
50
50
|
"magic-string": "^0.30.12",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"vite": "^6.1.0 || ^7.0.0",
|
|
63
|
-
"wrangler": "^4.
|
|
63
|
+
"wrangler": "^4.39.0"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|