@cloudflare/vite-plugin 1.13.1 → 1.13.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.js +5 -2
- package/dist/runner-worker/index.js +84 -56
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -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
|
|
@@ -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
|
);
|
|
@@ -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.2",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"unenv": "2.0.0-rc.21",
|
|
41
41
|
"ws": "8.18.0",
|
|
42
42
|
"@cloudflare/unenv-preset": "2.7.3",
|
|
43
|
-
"miniflare": "4.
|
|
44
|
-
"wrangler": "4.37.
|
|
43
|
+
"miniflare": "4.20250913.0",
|
|
44
|
+
"wrangler": "4.37.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@cloudflare/workers-types": "^4.
|
|
47
|
+
"@cloudflare/workers-types": "^4.20250913.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.37.
|
|
63
|
+
"wrangler": "^4.37.1"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|