@cloudflare/vite-plugin 1.13.1 → 1.13.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/dist/index.js +155 -144
- package/dist/runner-worker/index.js +84 -56
- package/package.json +7 -7
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() {
|
|
@@ -7446,6 +7446,7 @@ var additionalModuleGlobalRE = new RegExp(
|
|
|
7446
7446
|
"g"
|
|
7447
7447
|
);
|
|
7448
7448
|
var WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
|
|
7449
|
+
var IS_ENTRY_WORKER_HEADER = "__VITE_IS_ENTRY_WORKER__";
|
|
7449
7450
|
var VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
|
|
7450
7451
|
|
|
7451
7452
|
// src/utils.ts
|
|
@@ -7463,8 +7464,8 @@ var postfixRE = /[?#].*$/;
|
|
|
7463
7464
|
function cleanUrl(url) {
|
|
7464
7465
|
return url.replace(postfixRE, "");
|
|
7465
7466
|
}
|
|
7466
|
-
function withTrailingSlash(
|
|
7467
|
-
return
|
|
7467
|
+
function withTrailingSlash(path15) {
|
|
7468
|
+
return path15.endsWith("/") ? path15 : `${path15}/`;
|
|
7468
7469
|
}
|
|
7469
7470
|
function createRequestHandler(handler) {
|
|
7470
7471
|
return async (req, res, next) => {
|
|
@@ -7554,13 +7555,14 @@ var CloudflareDevEnvironment = class extends vite.DevEnvironment {
|
|
|
7554
7555
|
});
|
|
7555
7556
|
this.#webSocketContainer = webSocketContainer;
|
|
7556
7557
|
}
|
|
7557
|
-
async initRunner(worker, workerConfig) {
|
|
7558
|
+
async initRunner(worker, workerConfig, isEntryWorker) {
|
|
7558
7559
|
this.#worker = worker;
|
|
7559
7560
|
const response = await this.#worker.fetch(
|
|
7560
7561
|
new URL(INIT_PATH, UNKNOWN_HOST),
|
|
7561
7562
|
{
|
|
7562
7563
|
headers: {
|
|
7563
7564
|
[WORKER_ENTRY_PATH_HEADER]: workerConfig.main,
|
|
7565
|
+
[IS_ENTRY_WORKER_HEADER]: String(isEntryWorker),
|
|
7564
7566
|
upgrade: "websocket"
|
|
7565
7567
|
}
|
|
7566
7568
|
}
|
|
@@ -7677,7 +7679,8 @@ function initRunners(resolvedPluginConfig, viteDevServer, miniflare2) {
|
|
|
7677
7679
|
async ([environmentName, workerConfig]) => {
|
|
7678
7680
|
debuglog2("Initializing worker:", workerConfig.name);
|
|
7679
7681
|
const worker = await miniflare2.getWorker(workerConfig.name);
|
|
7680
|
-
|
|
7682
|
+
const isEntryWorker = environmentName === resolvedPluginConfig.entryWorkerEnvironmentName;
|
|
7683
|
+
return viteDevServer.environments[environmentName].initRunner(worker, workerConfig, isEntryWorker);
|
|
7681
7684
|
}
|
|
7682
7685
|
)
|
|
7683
7686
|
);
|
|
@@ -8149,13 +8152,13 @@ var getQueryString = (params) => {
|
|
|
8149
8152
|
};
|
|
8150
8153
|
var getUrl = (config, options) => {
|
|
8151
8154
|
const encoder = config.ENCODE_PATH || encodeURI;
|
|
8152
|
-
const
|
|
8155
|
+
const path15 = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
|
|
8153
8156
|
if (options.path?.hasOwnProperty(group)) {
|
|
8154
8157
|
return encoder(String(options.path[group]));
|
|
8155
8158
|
}
|
|
8156
8159
|
return substring;
|
|
8157
8160
|
});
|
|
8158
|
-
const url = `${config.BASE}${
|
|
8161
|
+
const url = `${config.BASE}${path15}`;
|
|
8159
8162
|
if (options.query) {
|
|
8160
8163
|
return `${url}${getQueryString(options.query)}`;
|
|
8161
8164
|
}
|
|
@@ -9460,9 +9463,9 @@ function getPreviewModules(main, modulesRules) {
|
|
|
9460
9463
|
path: entryPath
|
|
9461
9464
|
},
|
|
9462
9465
|
...modulesRules.flatMap(
|
|
9463
|
-
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((
|
|
9466
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path15) => ({
|
|
9464
9467
|
type,
|
|
9465
|
-
path:
|
|
9468
|
+
path: path15
|
|
9466
9469
|
}))
|
|
9467
9470
|
)
|
|
9468
9471
|
]
|
|
@@ -15133,17 +15136,17 @@ function withTrailingSlash2(input = "", respectQueryAndFragment) {
|
|
|
15133
15136
|
if (hasTrailingSlash(input, true)) {
|
|
15134
15137
|
return input || "/";
|
|
15135
15138
|
}
|
|
15136
|
-
let
|
|
15139
|
+
let path15 = input;
|
|
15137
15140
|
let fragment = "";
|
|
15138
15141
|
const fragmentIndex = input.indexOf("#");
|
|
15139
15142
|
if (fragmentIndex >= 0) {
|
|
15140
|
-
|
|
15143
|
+
path15 = input.slice(0, fragmentIndex);
|
|
15141
15144
|
fragment = input.slice(fragmentIndex);
|
|
15142
|
-
if (!
|
|
15145
|
+
if (!path15) {
|
|
15143
15146
|
return fragment;
|
|
15144
15147
|
}
|
|
15145
15148
|
}
|
|
15146
|
-
const [s0, ...s] =
|
|
15149
|
+
const [s0, ...s] = path15.split("?");
|
|
15147
15150
|
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
15148
15151
|
}
|
|
15149
15152
|
function isNonEmptyURL(url) {
|
|
@@ -15177,8 +15180,8 @@ import path9, { dirname as dirname6 } from "node:path";
|
|
|
15177
15180
|
import v8 from "node:v8";
|
|
15178
15181
|
import { format as format2, inspect } from "node:util";
|
|
15179
15182
|
var BUILTIN_MODULES = new Set(builtinModules);
|
|
15180
|
-
function normalizeSlash(
|
|
15181
|
-
return
|
|
15183
|
+
function normalizeSlash(path15) {
|
|
15184
|
+
return path15.replace(/\\/g, "/");
|
|
15182
15185
|
}
|
|
15183
15186
|
var own$1 = {}.hasOwnProperty;
|
|
15184
15187
|
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
@@ -15291,8 +15294,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
|
15291
15294
|
* @param {string} [base]
|
|
15292
15295
|
* @param {string} [message]
|
|
15293
15296
|
*/
|
|
15294
|
-
(
|
|
15295
|
-
return `Invalid package config ${
|
|
15297
|
+
(path15, base, message) => {
|
|
15298
|
+
return `Invalid package config ${path15}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
15296
15299
|
},
|
|
15297
15300
|
Error
|
|
15298
15301
|
);
|
|
@@ -15324,8 +15327,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
|
|
|
15324
15327
|
* @param {string} base
|
|
15325
15328
|
* @param {boolean} [exactUrl]
|
|
15326
15329
|
*/
|
|
15327
|
-
(
|
|
15328
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${
|
|
15330
|
+
(path15, base, exactUrl = false) => {
|
|
15331
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path15}' imported from ${base}`;
|
|
15329
15332
|
},
|
|
15330
15333
|
Error
|
|
15331
15334
|
);
|
|
@@ -15376,8 +15379,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
|
15376
15379
|
* @param {string} extension
|
|
15377
15380
|
* @param {string} path
|
|
15378
15381
|
*/
|
|
15379
|
-
(extension,
|
|
15380
|
-
return `Unknown file extension "${extension}" for ${
|
|
15382
|
+
(extension, path15) => {
|
|
15383
|
+
return `Unknown file extension "${extension}" for ${path15}`;
|
|
15381
15384
|
},
|
|
15382
15385
|
TypeError
|
|
15383
15386
|
);
|
|
@@ -15749,9 +15752,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
15749
15752
|
);
|
|
15750
15753
|
}
|
|
15751
15754
|
}
|
|
15752
|
-
function tryStatSync(
|
|
15755
|
+
function tryStatSync(path15) {
|
|
15753
15756
|
try {
|
|
15754
|
-
return statSync2(
|
|
15757
|
+
return statSync2(path15);
|
|
15755
15758
|
} catch {
|
|
15756
15759
|
}
|
|
15757
15760
|
}
|
|
@@ -16676,8 +16679,8 @@ var nodeJsBuiltins = /* @__PURE__ */ new Set([
|
|
|
16676
16679
|
var NODEJS_MODULES_RE = new RegExp(
|
|
16677
16680
|
`^(node:)?(${builtinModules2.join("|")})$`
|
|
16678
16681
|
);
|
|
16679
|
-
function isNodeAlsModule(
|
|
16680
|
-
return /^(node:)?async_hooks$/.test(
|
|
16682
|
+
function isNodeAlsModule(path15) {
|
|
16683
|
+
return /^(node:)?async_hooks$/.test(path15);
|
|
16681
16684
|
}
|
|
16682
16685
|
function assertHasNodeJsCompat(nodeJsCompat) {
|
|
16683
16686
|
assert8(nodeJsCompat, `expected nodeJsCompat to be defined`);
|
|
@@ -16722,9 +16725,25 @@ var NodeJsCompatWarnings = class {
|
|
|
16722
16725
|
}
|
|
16723
16726
|
};
|
|
16724
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
|
+
|
|
16725
16744
|
// src/plugin-config.ts
|
|
16726
|
-
import
|
|
16727
|
-
import * as
|
|
16745
|
+
import assert11 from "node:assert";
|
|
16746
|
+
import * as path13 from "node:path";
|
|
16728
16747
|
|
|
16729
16748
|
// ../workers-shared/utils/configuration/parseStaticRouting.ts
|
|
16730
16749
|
function parseStaticRouting(input) {
|
|
@@ -16803,12 +16822,12 @@ var formatInvalidRoutes = (invalidRules) => {
|
|
|
16803
16822
|
};
|
|
16804
16823
|
|
|
16805
16824
|
// src/plugin-config.ts
|
|
16806
|
-
import * as
|
|
16825
|
+
import * as vite5 from "vite";
|
|
16807
16826
|
|
|
16808
16827
|
// src/workers-configs.ts
|
|
16809
|
-
import
|
|
16828
|
+
import assert10 from "node:assert";
|
|
16810
16829
|
import * as fs5 from "node:fs";
|
|
16811
|
-
import * as
|
|
16830
|
+
import * as path12 from "node:path";
|
|
16812
16831
|
import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
|
|
16813
16832
|
var nonApplicableWorkerConfigs = {
|
|
16814
16833
|
/**
|
|
@@ -16904,7 +16923,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
16904
16923
|
const lines2 = [
|
|
16905
16924
|
`
|
|
16906
16925
|
|
|
16907
|
-
\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:`
|
|
16908
16927
|
];
|
|
16909
16928
|
nonApplicableLines.forEach((line) => lines2.push(line));
|
|
16910
16929
|
lines2.push("");
|
|
@@ -16918,7 +16937,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
16918
16937
|
);
|
|
16919
16938
|
if (nonApplicableLines.length > 0) {
|
|
16920
16939
|
lines.push(
|
|
16921
|
-
` - (${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)}\`)` : ""}`
|
|
16922
16941
|
);
|
|
16923
16942
|
nonApplicableLines.forEach((line) => lines.push(line));
|
|
16924
16943
|
}
|
|
@@ -17010,7 +17029,7 @@ function maybeResolveMain(main, configPath) {
|
|
|
17010
17029
|
if (!ENTRY_MODULE_EXTENSIONS.some((extension) => main.endsWith(extension))) {
|
|
17011
17030
|
return main;
|
|
17012
17031
|
}
|
|
17013
|
-
const resolvedMain =
|
|
17032
|
+
const resolvedMain = path12.resolve(path12.dirname(configPath), main);
|
|
17014
17033
|
if (!fs5.existsSync(resolvedMain)) {
|
|
17015
17034
|
throw new Error(
|
|
17016
17035
|
`The provided Wrangler config main field (${resolvedMain}) doesn't point to an existing file`
|
|
@@ -17020,10 +17039,10 @@ function maybeResolveMain(main, configPath) {
|
|
|
17020
17039
|
}
|
|
17021
17040
|
function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliaryWorker = false) {
|
|
17022
17041
|
if (requestedConfigPath) {
|
|
17023
|
-
const configPath2 =
|
|
17042
|
+
const configPath2 = path12.resolve(root, requestedConfigPath);
|
|
17024
17043
|
const forAuxiliaryWorkerErrorMessage = isForAuxiliaryWorker ? " requested for one of your auxiliary workers" : "";
|
|
17025
17044
|
const errorMessagePrefix = `The provided configPath (${configPath2})${forAuxiliaryWorkerErrorMessage}`;
|
|
17026
|
-
const fileExtension =
|
|
17045
|
+
const fileExtension = path12.extname(configPath2).slice(1);
|
|
17027
17046
|
if (!allowedWranglerConfigExtensions.includes(fileExtension)) {
|
|
17028
17047
|
const foundExtensionMessage = !fileExtension ? "no extension found" : `"${fileExtension}" found`;
|
|
17029
17048
|
throw new Error(
|
|
@@ -17043,7 +17062,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
|
|
|
17043
17062
|
}
|
|
17044
17063
|
return configPath2;
|
|
17045
17064
|
}
|
|
17046
|
-
|
|
17065
|
+
assert10(
|
|
17047
17066
|
isForAuxiliaryWorker === false,
|
|
17048
17067
|
"Unexpected Error: trying to find the wrangler config for an auxiliary worker"
|
|
17049
17068
|
);
|
|
@@ -17057,7 +17076,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
|
|
|
17057
17076
|
}
|
|
17058
17077
|
function findWranglerConfig(root) {
|
|
17059
17078
|
for (const extension of allowedWranglerConfigExtensions) {
|
|
17060
|
-
const configPath =
|
|
17079
|
+
const configPath = path12.join(root, `wrangler.${extension}`);
|
|
17061
17080
|
if (fs5.existsSync(configPath)) {
|
|
17062
17081
|
return configPath;
|
|
17063
17082
|
}
|
|
@@ -17075,7 +17094,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17075
17094
|
inspectorPort: pluginConfig.inspectorPort,
|
|
17076
17095
|
experimental: pluginConfig.experimental ?? {}
|
|
17077
17096
|
};
|
|
17078
|
-
const root = userConfig.root ?
|
|
17097
|
+
const root = userConfig.root ? path13.resolve(userConfig.root) : process.cwd();
|
|
17079
17098
|
if (viteEnv.isPreview) {
|
|
17080
17099
|
return {
|
|
17081
17100
|
...shared,
|
|
@@ -17084,7 +17103,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17084
17103
|
};
|
|
17085
17104
|
}
|
|
17086
17105
|
const configPaths = /* @__PURE__ */ new Set();
|
|
17087
|
-
const { CLOUDFLARE_ENV: cloudflareEnv } =
|
|
17106
|
+
const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
|
|
17088
17107
|
viteEnv.mode,
|
|
17089
17108
|
root,
|
|
17090
17109
|
/* prefixes */
|
|
@@ -17140,7 +17159,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17140
17159
|
}
|
|
17141
17160
|
);
|
|
17142
17161
|
auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
|
|
17143
|
-
|
|
17162
|
+
assert11(
|
|
17144
17163
|
workerResolvedConfig.type === "worker",
|
|
17145
17164
|
"Unexpected error: received AssetsOnlyResult with auxiliary workers."
|
|
17146
17165
|
);
|
|
@@ -17175,26 +17194,26 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
17175
17194
|
};
|
|
17176
17195
|
}
|
|
17177
17196
|
function assertIsNotPreview(resolvedPluginConfig) {
|
|
17178
|
-
|
|
17197
|
+
assert11(
|
|
17179
17198
|
resolvedPluginConfig.type !== "preview",
|
|
17180
17199
|
`Expected "assets-only" or "workers" plugin config`
|
|
17181
17200
|
);
|
|
17182
17201
|
}
|
|
17183
17202
|
function assertIsPreview(resolvedPluginConfig) {
|
|
17184
|
-
|
|
17203
|
+
assert11(
|
|
17185
17204
|
resolvedPluginConfig.type === "preview",
|
|
17186
17205
|
`Expected "preview" plugin config`
|
|
17187
17206
|
);
|
|
17188
17207
|
}
|
|
17189
17208
|
|
|
17190
17209
|
// src/vite-config.ts
|
|
17191
|
-
import
|
|
17210
|
+
import assert12 from "node:assert";
|
|
17192
17211
|
function validateWorkerEnvironmentOptions(resolvedPluginConfig, resolvedViteConfig) {
|
|
17193
17212
|
const workerEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
|
|
17194
17213
|
const disallowedEnvironmentOptionsMap = /* @__PURE__ */ new Map();
|
|
17195
17214
|
for (const environmentName of workerEnvironmentNames) {
|
|
17196
17215
|
const environmentOptions = resolvedViteConfig.environments[environmentName];
|
|
17197
|
-
|
|
17216
|
+
assert12(
|
|
17198
17217
|
environmentOptions,
|
|
17199
17218
|
`Missing environment config for "${environmentName}"`
|
|
17200
17219
|
);
|
|
@@ -17389,46 +17408,36 @@ if (import.meta.hot) {
|
|
|
17389
17408
|
},
|
|
17390
17409
|
generateBundle(_, bundle) {
|
|
17391
17410
|
assertIsNotPreview(resolvedPluginConfig);
|
|
17392
|
-
let
|
|
17411
|
+
let outputConfig;
|
|
17393
17412
|
if (resolvedPluginConfig.type === "workers") {
|
|
17394
|
-
const
|
|
17395
|
-
if (!
|
|
17413
|
+
const inputConfig = resolvedPluginConfig.workers[this.environment.name];
|
|
17414
|
+
if (!inputConfig) {
|
|
17396
17415
|
return;
|
|
17397
17416
|
}
|
|
17398
17417
|
const entryChunk = Object.values(bundle).find(
|
|
17399
17418
|
(chunk) => chunk.type === "chunk" && chunk.isEntry && chunk.name === MAIN_ENTRY_NAME
|
|
17400
17419
|
);
|
|
17401
|
-
|
|
17420
|
+
assert13(
|
|
17402
17421
|
entryChunk,
|
|
17403
17422
|
`Expected entry chunk with name "${MAIN_ENTRY_NAME}"`
|
|
17404
17423
|
);
|
|
17405
|
-
workerConfig.main = entryChunk.fileName;
|
|
17406
|
-
workerConfig.no_bundle = true;
|
|
17407
|
-
workerConfig.rules = [
|
|
17408
|
-
{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }
|
|
17409
|
-
];
|
|
17410
17424
|
const isEntryWorker = this.environment.name === resolvedPluginConfig.entryWorkerEnvironmentName;
|
|
17411
|
-
|
|
17412
|
-
|
|
17413
|
-
|
|
17414
|
-
|
|
17415
|
-
|
|
17416
|
-
|
|
17417
|
-
|
|
17418
|
-
|
|
17419
|
-
|
|
17420
|
-
|
|
17421
|
-
path13.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
17422
|
-
path13.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
17425
|
+
outputConfig = {
|
|
17426
|
+
...inputConfig,
|
|
17427
|
+
main: entryChunk.fileName,
|
|
17428
|
+
no_bundle: true,
|
|
17429
|
+
rules: [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }],
|
|
17430
|
+
assets: isEntryWorker ? {
|
|
17431
|
+
...inputConfig.assets,
|
|
17432
|
+
directory: getAssetsDirectory(
|
|
17433
|
+
this.environment.config.build.outDir,
|
|
17434
|
+
resolvedViteConfig
|
|
17423
17435
|
)
|
|
17424
|
-
}
|
|
17425
|
-
}
|
|
17426
|
-
|
|
17427
|
-
}
|
|
17428
|
-
config = workerConfig;
|
|
17429
|
-
if (workerConfig.configPath) {
|
|
17436
|
+
} : void 0
|
|
17437
|
+
};
|
|
17438
|
+
if (inputConfig.configPath) {
|
|
17430
17439
|
const localDevVars = getLocalDevVarsForPreview(
|
|
17431
|
-
|
|
17440
|
+
inputConfig.configPath,
|
|
17432
17441
|
resolvedPluginConfig.cloudflareEnv
|
|
17433
17442
|
);
|
|
17434
17443
|
if (localDevVars) {
|
|
@@ -17440,10 +17449,13 @@ if (import.meta.hot) {
|
|
|
17440
17449
|
}
|
|
17441
17450
|
}
|
|
17442
17451
|
} else if (this.environment.name === "client") {
|
|
17443
|
-
const
|
|
17444
|
-
|
|
17445
|
-
...
|
|
17446
|
-
|
|
17452
|
+
const inputConfig = resolvedPluginConfig.config;
|
|
17453
|
+
outputConfig = {
|
|
17454
|
+
...inputConfig,
|
|
17455
|
+
assets: {
|
|
17456
|
+
...inputConfig.assets,
|
|
17457
|
+
directory: "."
|
|
17458
|
+
}
|
|
17447
17459
|
};
|
|
17448
17460
|
const filesToAssetsIgnore = ["wrangler.json", ".dev.vars"];
|
|
17449
17461
|
this.emitFile({
|
|
@@ -17452,18 +17464,17 @@ if (import.meta.hot) {
|
|
|
17452
17464
|
source: `${filesToAssetsIgnore.join("\n")}
|
|
17453
17465
|
`
|
|
17454
17466
|
});
|
|
17455
|
-
config = assetsOnlyConfig;
|
|
17456
17467
|
}
|
|
17457
|
-
if (!
|
|
17468
|
+
if (!outputConfig) {
|
|
17458
17469
|
return;
|
|
17459
17470
|
}
|
|
17460
|
-
if (
|
|
17461
|
-
|
|
17471
|
+
if (outputConfig.unsafe && Object.keys(outputConfig.unsafe).length === 0) {
|
|
17472
|
+
outputConfig.unsafe = void 0;
|
|
17462
17473
|
}
|
|
17463
17474
|
this.emitFile({
|
|
17464
17475
|
type: "asset",
|
|
17465
17476
|
fileName: "wrangler.json",
|
|
17466
|
-
source: JSON.stringify(
|
|
17477
|
+
source: JSON.stringify(outputConfig)
|
|
17467
17478
|
});
|
|
17468
17479
|
},
|
|
17469
17480
|
writeBundle() {
|
|
@@ -17530,13 +17541,13 @@ if (import.meta.hot) {
|
|
|
17530
17541
|
}
|
|
17531
17542
|
let preMiddleware;
|
|
17532
17543
|
if (resolvedPluginConfig.type === "workers") {
|
|
17533
|
-
|
|
17544
|
+
assert13(entryWorkerConfig, `No entry Worker config`);
|
|
17534
17545
|
debuglog4("Initializing the Vite module runners");
|
|
17535
17546
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
17536
17547
|
const entryWorkerName = entryWorkerConfig.name;
|
|
17537
17548
|
if (viteDevServer.httpServer) {
|
|
17538
17549
|
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
17539
|
-
|
|
17550
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17540
17551
|
const entryWorker = await miniflare.getWorker(entryWorkerName);
|
|
17541
17552
|
return entryWorker.fetch;
|
|
17542
17553
|
});
|
|
@@ -17550,12 +17561,12 @@ if (import.meta.hot) {
|
|
|
17550
17561
|
staticRouting.user_worker
|
|
17551
17562
|
);
|
|
17552
17563
|
const userWorkerHandler = createRequestHandler(async (request2) => {
|
|
17553
|
-
|
|
17564
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17554
17565
|
const userWorker = await miniflare.getWorker(entryWorkerName);
|
|
17555
17566
|
return userWorker.fetch(request2, { redirect: "manual" });
|
|
17556
17567
|
});
|
|
17557
17568
|
preMiddleware = async (req, res, next) => {
|
|
17558
|
-
|
|
17569
|
+
assert13(req.url, `req.url not defined`);
|
|
17559
17570
|
const request2 = new Request(new URL(req.url, UNKNOWN_HOST));
|
|
17560
17571
|
if (req[kRequestType] === "asset") {
|
|
17561
17572
|
next();
|
|
@@ -17604,7 +17615,7 @@ if (import.meta.hot) {
|
|
|
17604
17615
|
const cachedTransformMiddlewareIndex = middlewareStack.findIndex(
|
|
17605
17616
|
(middleware) => "name" in middleware.handle && middleware.handle.name === "viteCachedTransformMiddleware"
|
|
17606
17617
|
);
|
|
17607
|
-
|
|
17618
|
+
assert13(
|
|
17608
17619
|
cachedTransformMiddlewareIndex !== -1,
|
|
17609
17620
|
"Failed to find viteCachedTransformMiddleware"
|
|
17610
17621
|
);
|
|
@@ -17615,7 +17626,7 @@ if (import.meta.hot) {
|
|
|
17615
17626
|
}
|
|
17616
17627
|
viteDevServer.middlewares.use(
|
|
17617
17628
|
createRequestHandler(async (request2, req) => {
|
|
17618
|
-
|
|
17629
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17619
17630
|
if (req[kRequestType] === "asset") {
|
|
17620
17631
|
const assetWorker = await miniflare.getWorker(ASSET_WORKER_NAME);
|
|
17621
17632
|
return assetWorker.fetch(request2, { redirect: "manual" });
|
|
@@ -17677,12 +17688,12 @@ if (import.meta.hot) {
|
|
|
17677
17688
|
});
|
|
17678
17689
|
}
|
|
17679
17690
|
handleWebSocket(vitePreviewServer.httpServer, () => {
|
|
17680
|
-
|
|
17691
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17681
17692
|
return miniflare.dispatchFetch;
|
|
17682
17693
|
});
|
|
17683
17694
|
vitePreviewServer.middlewares.use(
|
|
17684
17695
|
createRequestHandler((request2) => {
|
|
17685
|
-
|
|
17696
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
17686
17697
|
return miniflare.dispatchFetch(request2, { redirect: "manual" });
|
|
17687
17698
|
})
|
|
17688
17699
|
);
|
|
@@ -17775,7 +17786,7 @@ if (import.meta.hot) {
|
|
|
17775
17786
|
for (const match of matches) {
|
|
17776
17787
|
magicString ??= new MagicString(code);
|
|
17777
17788
|
const [full, _, modulePath] = match;
|
|
17778
|
-
|
|
17789
|
+
assert13(
|
|
17779
17790
|
modulePath,
|
|
17780
17791
|
`Unexpected error: module path not found in reference ${full}.`
|
|
17781
17792
|
);
|
|
@@ -17789,13 +17800,13 @@ if (import.meta.hot) {
|
|
|
17789
17800
|
}
|
|
17790
17801
|
const referenceId = this.emitFile({
|
|
17791
17802
|
type: "asset",
|
|
17792
|
-
name:
|
|
17803
|
+
name: path14.basename(modulePath),
|
|
17793
17804
|
originalFileName: modulePath,
|
|
17794
17805
|
source
|
|
17795
17806
|
});
|
|
17796
17807
|
const emittedFileName = this.getFileName(referenceId);
|
|
17797
|
-
const relativePath =
|
|
17798
|
-
|
|
17808
|
+
const relativePath = vite6.normalizePath(
|
|
17809
|
+
path14.relative(path14.dirname(chunk.fileName), emittedFileName)
|
|
17799
17810
|
);
|
|
17800
17811
|
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
17801
17812
|
magicString.update(
|
|
@@ -17854,7 +17865,7 @@ if (import.meta.hot) {
|
|
|
17854
17865
|
return this.resolve(source, importer, options);
|
|
17855
17866
|
}
|
|
17856
17867
|
if (this.environment.mode === "dev") {
|
|
17857
|
-
|
|
17868
|
+
assert13(
|
|
17858
17869
|
this.environment.depsOptimizer,
|
|
17859
17870
|
"depsOptimizer is required in dev mode"
|
|
17860
17871
|
);
|
|
@@ -17937,13 +17948,13 @@ export default mod.default ?? {};
|
|
|
17937
17948
|
setup(build) {
|
|
17938
17949
|
build.onResolve(
|
|
17939
17950
|
{ filter: NODEJS_MODULES_RE },
|
|
17940
|
-
({ path:
|
|
17941
|
-
if (hasNodeJsAls(workerConfig) && isNodeAlsModule(
|
|
17951
|
+
({ path: path15, importer }) => {
|
|
17952
|
+
if (hasNodeJsAls(workerConfig) && isNodeAlsModule(path15)) {
|
|
17942
17953
|
return;
|
|
17943
17954
|
}
|
|
17944
17955
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
17945
|
-
nodeJsCompatWarnings?.registerImport(
|
|
17946
|
-
return { path:
|
|
17956
|
+
nodeJsCompatWarnings?.registerImport(path15, importer);
|
|
17957
|
+
return { path: path15, external: true };
|
|
17947
17958
|
}
|
|
17948
17959
|
);
|
|
17949
17960
|
}
|
|
@@ -18028,7 +18039,7 @@ export default mod.default ?? {};
|
|
|
18028
18039
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
18029
18040
|
}
|
|
18030
18041
|
const workerNames = resolvedPluginConfig.workers.map((worker) => {
|
|
18031
|
-
|
|
18042
|
+
assert13(worker.name, "Expected the Worker to have a name");
|
|
18032
18043
|
return worker.name;
|
|
18033
18044
|
});
|
|
18034
18045
|
vitePreviewServer.middlewares.use(DEBUG_PATH, async (_, res, next) => {
|
|
@@ -18054,11 +18065,11 @@ export default mod.default ?? {};
|
|
|
18054
18065
|
assertIsNotPreview(resolvedPluginConfig);
|
|
18055
18066
|
if (resolvedPluginConfig.type === "workers") {
|
|
18056
18067
|
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
18057
|
-
|
|
18068
|
+
assert13(entryWorkerConfig, `No entry Worker config`);
|
|
18058
18069
|
const entryWorkerName = entryWorkerConfig.name;
|
|
18059
18070
|
viteDevServer.middlewares.use("/cdn-cgi/", (req, res, next) => {
|
|
18060
18071
|
const requestHandler = createRequestHandler((request2) => {
|
|
18061
|
-
|
|
18072
|
+
assert13(miniflare, `Miniflare not defined`);
|
|
18062
18073
|
request2.headers.set(CoreHeaders.ROUTE_OVERRIDE, entryWorkerName);
|
|
18063
18074
|
return miniflare.dispatchFetch(request2, { redirect: "manual" });
|
|
18064
18075
|
});
|
|
@@ -26,6 +26,7 @@ var additionalModuleGlobalRE = new RegExp(
|
|
|
26
26
|
"g"
|
|
27
27
|
);
|
|
28
28
|
var WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
|
|
29
|
+
var IS_ENTRY_WORKER_HEADER = "__VITE_IS_ENTRY_WORKER__";
|
|
29
30
|
var VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
|
|
30
31
|
|
|
31
32
|
// src/runner-worker/env.ts
|
|
@@ -39,6 +40,29 @@ function stripInternalEnv(internalEnv) {
|
|
|
39
40
|
return userEnv;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// src/runner-worker/errors.ts
|
|
44
|
+
function reduceError(e) {
|
|
45
|
+
return {
|
|
46
|
+
name: e?.name,
|
|
47
|
+
message: e?.message ?? String(e),
|
|
48
|
+
stack: e?.stack,
|
|
49
|
+
cause: e?.cause === void 0 ? void 0 : reduceError(e.cause)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function maybeCaptureError(options, fn) {
|
|
53
|
+
if (!options.isEntryWorker || options.exportName !== "default" || options.key !== "fetch") {
|
|
54
|
+
return fn();
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return await fn();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return Response.json(reduceError(error), {
|
|
60
|
+
status: 500,
|
|
61
|
+
headers: { "MF-Experimental-Error-Stack": "true" }
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
42
66
|
// src/runner-worker/module-runner.ts
|
|
43
67
|
import { DurableObject } from "cloudflare:workers";
|
|
44
68
|
|
|
@@ -1314,17 +1338,9 @@ async function createModuleRunner(env, webSocket) {
|
|
|
1314
1338
|
{
|
|
1315
1339
|
async runInlinedModule(context, transformed, module) {
|
|
1316
1340
|
const code = `"use strict";async (${Object.keys(context).join(",")})=>{${transformed}}`;
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
Object.seal(context[ssrModuleExportsKey]);
|
|
1321
|
-
} catch (error) {
|
|
1322
|
-
if (error instanceof Error) {
|
|
1323
|
-
error.message = `Error running module "${module.url}".
|
|
1324
|
-
${error.message}.`;
|
|
1325
|
-
}
|
|
1326
|
-
throw error;
|
|
1327
|
-
}
|
|
1341
|
+
const fn = env.__VITE_UNSAFE_EVAL__.eval(code, module.id);
|
|
1342
|
+
await fn(...Object.values(context));
|
|
1343
|
+
Object.seal(context[ssrModuleExportsKey]);
|
|
1328
1344
|
},
|
|
1329
1345
|
async runExternalModule(filepath) {
|
|
1330
1346
|
if (filepath === "cloudflare:workers") {
|
|
@@ -1375,6 +1391,7 @@ var DURABLE_OBJECT_KEYS = [
|
|
|
1375
1391
|
];
|
|
1376
1392
|
var WORKFLOW_ENTRYPOINT_KEYS = ["run"];
|
|
1377
1393
|
var workerEntryPath = "";
|
|
1394
|
+
var isEntryWorker = false;
|
|
1378
1395
|
function getRpcPropertyCallableThenable(key, property) {
|
|
1379
1396
|
const fn = async function(...args) {
|
|
1380
1397
|
const maybeFn = await property;
|
|
@@ -1453,56 +1470,67 @@ function createWorkerEntrypointWrapper(exportName) {
|
|
|
1453
1470
|
}
|
|
1454
1471
|
for (const key of WORKER_ENTRYPOINT_KEYS) {
|
|
1455
1472
|
Wrapper.prototype[key] = async function(arg) {
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1473
|
+
return maybeCaptureError({ isEntryWorker, exportName, key }, async () => {
|
|
1474
|
+
if (key === "fetch") {
|
|
1475
|
+
const request = arg;
|
|
1476
|
+
const url = new URL(request.url);
|
|
1477
|
+
if (url.pathname === INIT_PATH) {
|
|
1478
|
+
const workerEntryPathHeader = request.headers.get(
|
|
1479
|
+
WORKER_ENTRY_PATH_HEADER
|
|
1480
|
+
);
|
|
1481
|
+
if (!workerEntryPathHeader) {
|
|
1482
|
+
throw new Error(
|
|
1483
|
+
`Unexpected error: "${WORKER_ENTRY_PATH_HEADER}" header not set.`
|
|
1484
|
+
);
|
|
1485
|
+
}
|
|
1486
|
+
const isEntryWorkerHeader = request.headers.get(
|
|
1487
|
+
IS_ENTRY_WORKER_HEADER
|
|
1466
1488
|
);
|
|
1489
|
+
if (!isEntryWorkerHeader) {
|
|
1490
|
+
throw new Error(
|
|
1491
|
+
`Unexpected error: "${IS_ENTRY_WORKER_HEADER}" header not set.`
|
|
1492
|
+
);
|
|
1493
|
+
}
|
|
1494
|
+
workerEntryPath = workerEntryPathHeader;
|
|
1495
|
+
isEntryWorker = isEntryWorkerHeader === "true";
|
|
1496
|
+
const stub = this.env.__VITE_RUNNER_OBJECT__.get("singleton");
|
|
1497
|
+
return stub.fetch(request);
|
|
1467
1498
|
}
|
|
1468
|
-
workerEntryPath = workerEntryPathHeader;
|
|
1469
|
-
const stub = this.env.__VITE_RUNNER_OBJECT__.get("singleton");
|
|
1470
|
-
return stub.fetch(request);
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
const exportValue = await getWorkerEntryExport(
|
|
1474
|
-
workerEntryPath,
|
|
1475
|
-
exportName
|
|
1476
|
-
);
|
|
1477
|
-
const userEnv = stripInternalEnv(this.env);
|
|
1478
|
-
if (typeof exportValue === "object" && exportValue !== null) {
|
|
1479
|
-
const maybeFn = exportValue[key];
|
|
1480
|
-
if (typeof maybeFn !== "function") {
|
|
1481
|
-
throw new TypeError(
|
|
1482
|
-
`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`
|
|
1483
|
-
);
|
|
1484
1499
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
)
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1500
|
+
const exportValue = await getWorkerEntryExport(
|
|
1501
|
+
workerEntryPath,
|
|
1502
|
+
exportName
|
|
1503
|
+
);
|
|
1504
|
+
const userEnv = stripInternalEnv(this.env);
|
|
1505
|
+
if (typeof exportValue === "object" && exportValue !== null) {
|
|
1506
|
+
const maybeFn = exportValue[key];
|
|
1507
|
+
if (typeof maybeFn !== "function") {
|
|
1508
|
+
throw new TypeError(
|
|
1509
|
+
`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
return maybeFn.call(exportValue, arg, userEnv, this.ctx);
|
|
1513
|
+
} else if (typeof exportValue === "function") {
|
|
1514
|
+
const ctor = exportValue;
|
|
1515
|
+
const instance = new ctor(this.ctx, userEnv);
|
|
1516
|
+
if (!(instance instanceof WorkerEntrypoint)) {
|
|
1517
|
+
throw new TypeError(
|
|
1518
|
+
`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`WorkerEntrypoint\`.`
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
const maybeFn = instance[key];
|
|
1522
|
+
if (typeof maybeFn !== "function") {
|
|
1523
|
+
throw new TypeError(
|
|
1524
|
+
`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` method.`
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
return maybeFn.call(instance, arg);
|
|
1528
|
+
} else {
|
|
1529
|
+
return new TypeError(
|
|
1530
|
+
`Expected "${exportName}" export of "${workerEntryPath}" to be an object or a class.`
|
|
1498
1531
|
);
|
|
1499
1532
|
}
|
|
1500
|
-
|
|
1501
|
-
} else {
|
|
1502
|
-
return new TypeError(
|
|
1503
|
-
`Expected "${exportName}" export of "${workerEntryPath}" to be an object or a class.`
|
|
1504
|
-
);
|
|
1505
|
-
}
|
|
1533
|
+
});
|
|
1506
1534
|
};
|
|
1507
1535
|
}
|
|
1508
1536
|
return Wrapper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.3",
|
|
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
|
-
"@cloudflare/unenv-preset": "2.7.
|
|
43
|
-
"miniflare": "4.
|
|
44
|
-
"wrangler": "4.
|
|
42
|
+
"@cloudflare/unenv-preset": "2.7.4",
|
|
43
|
+
"miniflare": "4.20250917.0",
|
|
44
|
+
"wrangler": "4.38.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@cloudflare/workers-types": "^4.
|
|
47
|
+
"@cloudflare/workers-types": "^4.20250917.0",
|
|
48
48
|
"@types/node": "^22.10.1",
|
|
49
49
|
"@types/ws": "^8.5.13",
|
|
50
50
|
"magic-string": "^0.30.12",
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"typescript": "^5.8.3",
|
|
54
54
|
"vite": "7.0.0",
|
|
55
55
|
"vitest": "~3.2.0",
|
|
56
|
-
"@cloudflare/containers-shared": "0.2.10",
|
|
57
56
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
57
|
+
"@cloudflare/containers-shared": "0.2.10",
|
|
58
58
|
"@cloudflare/workers-shared": "0.18.8",
|
|
59
59
|
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"vite": "^6.1.0 || ^7.0.0",
|
|
63
|
-
"wrangler": "^4.
|
|
63
|
+
"wrangler": "^4.38.0"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|