@cloudflare/vite-plugin 1.29.0 → 1.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,88 +1,4 @@
1
- import { DurableObject, WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
2
-
3
- //#region src/shared.ts
4
- const UNKNOWN_HOST = "http://localhost";
5
- const INIT_PATH = "/__vite_plugin_cloudflare_init__";
6
- const GET_EXPORT_TYPES_PATH = "/__vite_plugin_cloudflare_get_export_types__";
7
- const WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
8
- const IS_ENTRY_WORKER_HEADER = "__VITE_IS_ENTRY_WORKER__";
9
- const ENVIRONMENT_NAME_HEADER = "__VITE_ENVIRONMENT_NAME__";
10
- const IS_PARENT_ENVIRONMENT_HEADER = "__VITE_IS_PARENT_ENVIRONMENT__";
11
- const virtualPrefix = "virtual:cloudflare/";
12
- const VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
13
- const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;
14
-
15
- //#endregion
16
- //#region src/workers/runner-worker/env.ts
17
- /**
18
- * Strips internal properties from the `env` object, returning only the user-defined properties.
19
- * @param internalEnv - The full wrapper env, including internal properties
20
- * @returns The user-defined env
21
- */
22
- function stripInternalEnv(internalEnv) {
23
- const { __VITE_RUNNER_OBJECT__: __VITE_RUNNER_OBJECT__$1, __VITE_INVOKE_MODULE__, __VITE_UNSAFE_EVAL__,...userEnv } = internalEnv;
24
- return userEnv;
25
- }
26
-
27
- //#endregion
28
- //#region src/workers/runner-worker/errors.ts
29
- /**
30
- * Converts an error to an object that can be be serialized and revived by Miniflare.
31
- * Copied from `packages/wrangler/templates/middleware/middleware-miniflare3-json-error.ts`
32
- */
33
- function reduceError(e) {
34
- return {
35
- name: e?.name,
36
- message: e?.message ?? String(e),
37
- stack: e?.stack,
38
- cause: e?.cause === void 0 ? void 0 : reduceError(e.cause)
39
- };
40
- }
41
- /**
42
- * Captures errors in the `fetch` handler of the default export of the entry Worker.
43
- * These are returned as a JSON response that is revived by Miniflare.
44
- * See comment in `/packages/wrangler/src/deployment-bundle/bundle.ts` for more info.
45
- */
46
- async function maybeCaptureError(options, fn) {
47
- if (!options.isEntryWorker || options.exportName !== "default" || options.key !== "fetch") return fn();
48
- try {
49
- return await fn();
50
- } catch (error) {
51
- return Response.json(reduceError(error), {
52
- status: 500,
53
- headers: { "MF-Experimental-Error-Stack": "true" }
54
- });
55
- }
56
- }
57
-
58
- //#endregion
59
- //#region src/workers/runner-worker/keys.ts
60
- /** Keys that should be ignored during RPC property access */
61
- const IGNORED_KEYS = ["self"];
62
- /** Available methods for `WorkerEntrypoint` class */
63
- const WORKER_ENTRYPOINT_KEYS = [
64
- "email",
65
- "fetch",
66
- "queue",
67
- "tail",
68
- "tailStream",
69
- "test",
70
- "trace",
71
- "scheduled"
72
- ];
73
- /** Available methods for `DurableObject` class */
74
- const DURABLE_OBJECT_KEYS = [
75
- "alarm",
76
- "fetch",
77
- "webSocketClose",
78
- "webSocketError",
79
- "webSocketMessage"
80
- ];
81
- /** Available methods for `WorkflowEntrypoint` classes */
82
- const WORKFLOW_ENTRYPOINT_KEYS = ["run"];
83
-
84
- //#endregion
85
- //#region ../../node_modules/.pnpm/vite@7.1.12_@types+node@20.19.9_jiti@2.6.1_lightningcss@1.30.2_tsx@4.21.0_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js
1
+ //#region ../../node_modules/.pnpm/vite@7.1.12_@types+node@20.19.9_jiti@2.6.1_lightningcss@1.32.0_tsx@4.21.0_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js
86
2
  let SOURCEMAPPING_URL = "sourceMa";
87
3
  SOURCEMAPPING_URL += "ppingURL";
88
4
  const isWindows = typeof process < "u" && process.platform === "win32";
@@ -1007,6 +923,24 @@ export async function resolve(specifier, context, nextResolve) {
1007
923
  }
1008
924
 
1009
925
  `;
926
+ async function createImportMetaResolver() {
927
+ let module;
928
+ try {
929
+ module = (await import("node:module")).Module;
930
+ } catch {
931
+ return;
932
+ }
933
+ if (module?.register) {
934
+ try {
935
+ let hookModuleContent = `data:text/javascript,${encodeURI(customizationHooksModule)}`;
936
+ module.register(hookModuleContent);
937
+ } catch (e) {
938
+ if ("code" in e && e.code === "ERR_NETWORK_IMPORT_DISALLOWED") return;
939
+ throw e;
940
+ }
941
+ return (specifier, importer) => import.meta.resolve(`${customizationHookNamespace}${JSON.stringify([specifier, importer])}`);
942
+ }
943
+ }
1010
944
  const envProxy = new Proxy({}, { get(_, p) {
1011
945
  throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
1012
946
  } });
@@ -1025,6 +959,19 @@ function createDefaultImportMeta(modulePath) {
1025
959
  }
1026
960
  };
1027
961
  }
962
+ let importMetaResolverCache;
963
+ async function createNodeImportMeta(modulePath) {
964
+ let defaultMeta = createDefaultImportMeta(modulePath), href = defaultMeta.url;
965
+ importMetaResolverCache ??= createImportMetaResolver();
966
+ let importMetaResolver = await importMetaResolverCache;
967
+ return {
968
+ ...defaultMeta,
969
+ main: !1,
970
+ resolve(id, parent) {
971
+ return (importMetaResolver ?? defaultMeta.resolve)(id, parent ?? href);
972
+ }
973
+ };
974
+ }
1028
975
  var ModuleRunner = class {
1029
976
  evaluatedModules;
1030
977
  hmrClient;
@@ -1179,389 +1126,4 @@ function exportAll(exports, sourceModule) {
1179
1126
  }
1180
1127
 
1181
1128
  //#endregion
1182
- //#region src/workers/runner-worker/module-runner.ts
1183
- /**
1184
- * Custom `ModuleRunner`.
1185
- * The `cachedModule` method is overridden to ensure compatibility with the Workers runtime.
1186
- */
1187
- var CustomModuleRunner = class extends ModuleRunner {
1188
- #env;
1189
- #environmentName;
1190
- constructor(options, evaluator, env, environmentName) {
1191
- super(options, evaluator);
1192
- this.#env = env;
1193
- this.#environmentName = environmentName;
1194
- }
1195
- async cachedModule(url, importer) {
1196
- const moduleId = await this.#env.__VITE_RUNNER_OBJECT__.get("singleton").getFetchedModuleId(this.#environmentName, url, importer);
1197
- const module = this.evaluatedModules.getModuleById(moduleId);
1198
- if (!module) throw new Error(`Module "${moduleId}" is undefined`);
1199
- return module;
1200
- }
1201
- };
1202
- /** Module runner instances keyed by environment name */
1203
- const moduleRunners = /* @__PURE__ */ new Map();
1204
- /** The parent environment name (set explicitly via IS_PARENT_ENVIRONMENT_HEADER) */
1205
- let parentEnvironmentName;
1206
- /**
1207
- * Durable Object that creates the module runner and handles WebSocket communication with the Vite dev server.
1208
- */
1209
- var __VITE_RUNNER_OBJECT__ = class extends DurableObject {
1210
- /** Per-environment state containing WebSocket and concurrent module node promises */
1211
- #environments = /* @__PURE__ */ new Map();
1212
- /**
1213
- * Handles fetch requests to initialize a module runner for an environment.
1214
- * Creates a WebSocket pair for communication with the Vite dev server and initializes the ModuleRunner.
1215
- * @param request - The incoming fetch request
1216
- * @returns Response with WebSocket
1217
- * @throws Error if the path is invalid or the module runner is already initialized
1218
- */
1219
- async fetch(request) {
1220
- const { pathname } = new URL(request.url);
1221
- if (pathname !== INIT_PATH) throw new Error(`__VITE_RUNNER_OBJECT__ received invalid pathname: "${pathname}"`);
1222
- const environmentName = request.headers.get(ENVIRONMENT_NAME_HEADER);
1223
- if (!environmentName) throw new Error(`__VITE_RUNNER_OBJECT__ received request without "${ENVIRONMENT_NAME_HEADER}" header`);
1224
- if (moduleRunners.has(environmentName)) throw new Error(`Module runner already initialized for environment: "${environmentName}"`);
1225
- if (request.headers.get(IS_PARENT_ENVIRONMENT_HEADER) === "true") parentEnvironmentName = environmentName;
1226
- const { 0: client, 1: server } = new WebSocketPair();
1227
- server.accept();
1228
- const environmentState = {
1229
- webSocket: server,
1230
- concurrentModuleNodePromises: /* @__PURE__ */ new Map()
1231
- };
1232
- this.#environments.set(environmentName, environmentState);
1233
- const moduleRunner = await createModuleRunner(this.env, environmentState.webSocket, environmentName);
1234
- moduleRunners.set(environmentName, moduleRunner);
1235
- return new Response(null, {
1236
- status: 101,
1237
- webSocket: client
1238
- });
1239
- }
1240
- /**
1241
- * Sends data to the Vite dev server via the WebSocket for a specific environment.
1242
- * @param environmentName - The environment name
1243
- * @param data - The data to send as a string
1244
- * @throws Error if the WebSocket is not initialized
1245
- */
1246
- send(environmentName, data) {
1247
- const environmentState = this.#environments.get(environmentName);
1248
- if (!environmentState) throw new Error(`Module runner WebSocket not initialized for environment: "${environmentName}"`);
1249
- environmentState.webSocket.send(data);
1250
- }
1251
- /**
1252
- * Based on the implementation of `cachedModule` from Vite's `ModuleRunner`.
1253
- * Running this in the DO enables us to share promises across invocations.
1254
- * @param environmentName - The environment name
1255
- * @param url - The module URL
1256
- * @param importer - The module's importer
1257
- * @returns The ID of the fetched module
1258
- */
1259
- async getFetchedModuleId(environmentName, url, importer) {
1260
- const moduleRunner = moduleRunners.get(environmentName);
1261
- if (!moduleRunner) throw new Error(`Module runner not initialized for environment: "${environmentName}"`);
1262
- const environmentState = this.#environments.get(environmentName);
1263
- if (!environmentState) throw new Error(`Environment state not found for environment: "${environmentName}"`);
1264
- let cached = environmentState.concurrentModuleNodePromises.get(url);
1265
- if (!cached) {
1266
- const cachedModule = moduleRunner.evaluatedModules.getModuleByUrl(url);
1267
- cached = moduleRunner.getModuleInformation(url, importer, cachedModule).finally(() => {
1268
- environmentState.concurrentModuleNodePromises.delete(url);
1269
- });
1270
- environmentState.concurrentModuleNodePromises.set(url, cached);
1271
- } else moduleRunner.debug?.("[module runner] using cached module info for", url);
1272
- return (await cached).id;
1273
- }
1274
- };
1275
- /**
1276
- * Creates a new module runner instance with a WebSocket transport.
1277
- * @param env - The wrapper env
1278
- * @param webSocket - WebSocket connection for communication with Vite dev server
1279
- * @param environmentName - The name of the environment this runner is for
1280
- * @returns Configured module runner instance
1281
- */
1282
- async function createModuleRunner(env, webSocket, environmentName) {
1283
- return new CustomModuleRunner({
1284
- sourcemapInterceptor: "prepareStackTrace",
1285
- transport: {
1286
- connect({ onMessage }) {
1287
- webSocket.addEventListener("message", async ({ data }) => {
1288
- onMessage(JSON.parse(data.toString()));
1289
- });
1290
- onMessage({
1291
- type: "custom",
1292
- event: "vite:ws:connect",
1293
- data: { webSocket }
1294
- });
1295
- },
1296
- disconnect() {
1297
- webSocket.close();
1298
- },
1299
- send(data) {
1300
- env.__VITE_RUNNER_OBJECT__.get("singleton").send(environmentName, JSON.stringify(data));
1301
- },
1302
- async invoke(data) {
1303
- return await (await env.__VITE_INVOKE_MODULE__.fetch(new Request(UNKNOWN_HOST, {
1304
- method: "POST",
1305
- headers: { [ENVIRONMENT_NAME_HEADER]: environmentName },
1306
- body: JSON.stringify(data)
1307
- }))).json();
1308
- }
1309
- },
1310
- hmr: true
1311
- }, {
1312
- async runInlinedModule(context, transformed, module) {
1313
- const code = `"use strict";async (${Object.keys(context).join(",")})=>{${transformed}}`;
1314
- await env.__VITE_UNSAFE_EVAL__.eval(code, module.id)(...Object.values(context));
1315
- Object.seal(context[ssrModuleExportsKey]);
1316
- },
1317
- async runExternalModule(filepath) {
1318
- if (filepath === "cloudflare:workers") {
1319
- const originalCloudflareWorkersModule = await import("cloudflare:workers");
1320
- return Object.seal({
1321
- ...originalCloudflareWorkersModule,
1322
- env: stripInternalEnv(originalCloudflareWorkersModule.env)
1323
- });
1324
- }
1325
- return import(filepath);
1326
- }
1327
- }, env, environmentName);
1328
- }
1329
- /**
1330
- * Retrieves a specific export from a Worker entry module using the module runner.
1331
- * @param workerEntryPath - Path to the Worker entry module
1332
- * @param exportName - Name of the export to retrieve
1333
- * @returns The requested export value
1334
- * @throws Error if the module runner has not been initialized or the module does not define the requested export
1335
- */
1336
- async function getWorkerEntryExport(workerEntryPath$1, exportName) {
1337
- if (!parentEnvironmentName) throw new Error(`Parent environment not initialized`);
1338
- const moduleRunner = moduleRunners.get(parentEnvironmentName);
1339
- if (!moduleRunner) throw new Error(`Module runner not initialized`);
1340
- const module = await moduleRunner.import(VIRTUAL_WORKER_ENTRY);
1341
- const exportValue = typeof module === "object" && module !== null && exportName in module && module[exportName];
1342
- if (!exportValue) throw new Error(`"${workerEntryPath$1}" does not define a "${exportName}" export.`);
1343
- return exportValue;
1344
- }
1345
- async function getWorkerEntryExportTypes() {
1346
- if (!parentEnvironmentName) throw new Error(`Parent environment not initialized`);
1347
- const moduleRunner = moduleRunners.get(parentEnvironmentName);
1348
- if (!moduleRunner) throw new Error(`Module runner not initialized`);
1349
- const { getExportTypes } = await moduleRunner.import(VIRTUAL_EXPORT_TYPES);
1350
- return getExportTypes(await moduleRunner.import(VIRTUAL_WORKER_ENTRY));
1351
- }
1352
- /**
1353
- * Imports a module from a specific environment's module runner.
1354
- * @param environmentName - The name of the environment to import from
1355
- * @param id - The module ID to import
1356
- * @returns The imported module
1357
- * @throws Error if the environment's module runner has not been initialized
1358
- */
1359
- async function importFromEnvironment(environmentName, id) {
1360
- const moduleRunner = moduleRunners.get(environmentName);
1361
- if (!moduleRunner) throw new Error(`Module runner not initialized for environment: "${environmentName}". Do you need to set \`childEnvironments: ["${environmentName}"]\` in the plugin config?`);
1362
- return moduleRunner.import(id);
1363
- }
1364
- globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ = importFromEnvironment;
1365
-
1366
- //#endregion
1367
- //#region src/workers/runner-worker/index.ts
1368
- /** The path to the Worker entry file. We store it in the module scope so that it is easily accessible in error messages etc.. */
1369
- let workerEntryPath = "";
1370
- let isEntryWorker = false;
1371
- /**
1372
- * Creates a callable thenable that is used to access the properties of an RPC target.
1373
- * It can be both awaited and invoked as a function.
1374
- * This enables RPC properties to be used both as promises and callable functions.
1375
- * @param key - The property key name used for error messages
1376
- * @param property - The promise that resolves to the property value
1377
- * @returns A callable thenable that implements both Promise and function interfaces
1378
- */
1379
- function getRpcPropertyCallableThenable(key, property) {
1380
- const fn = async function(...args) {
1381
- const maybeFn = await property;
1382
- if (typeof maybeFn !== "function") throw new TypeError(`"${key}" is not a function.`);
1383
- return maybeFn(...args);
1384
- };
1385
- fn.then = (onFulfilled, onRejected) => property.then(onFulfilled, onRejected);
1386
- fn.catch = (onRejected) => property.catch(onRejected);
1387
- fn.finally = (onFinally) => property.finally(onFinally);
1388
- return fn;
1389
- }
1390
- /**
1391
- * Retrieves an RPC property from a constructor prototype, ensuring it exists on the prototype rather than the instance to maintain RPC compatibility.
1392
- * @param ctor - The constructor function (`WorkerEntrypoint` or `DurableObject`)
1393
- * @param instance - The instance to bind methods to
1394
- * @param key - The property key to retrieve
1395
- * @returns The property value from the prototype
1396
- * @throws TypeError if the property doesn't exist on the prototype
1397
- */
1398
- function getRpcProperty(ctor, instance, key) {
1399
- if (!Reflect.has(ctor.prototype, key)) {
1400
- if (Reflect.has(instance, key)) throw new TypeError([
1401
- `The RPC receiver's prototype does not implement "${key}", but the receiver instance does.`,
1402
- "Only properties and methods defined on the prototype can be accessed over RPC.",
1403
- `Ensure properties are declared as \`get ${key}() { ... }\` instead of \`${key} = ...\`,`,
1404
- `and methods are declared as \`${key}() { ... }\` instead of \`${key} = () => { ... }\`.`
1405
- ].join("\n"));
1406
- throw new TypeError(`The RPC receiver does not implement "${key}".`);
1407
- }
1408
- return Reflect.get(ctor.prototype, key, instance);
1409
- }
1410
- /**
1411
- * Retrieves an RPC property from a `WorkerEntrypoint` export, creating an instance and returning the bound method or property value.
1412
- * @param exportName - The name of the `WorkerEntrypoint` export
1413
- * @param key - The property key to access on the `WorkerEntrypoint` instance
1414
- * @returns The property value, with methods bound to the instance
1415
- * @throws TypeError if the export is not a `WorkerEntrypoint` subclass
1416
- */
1417
- async function getWorkerEntrypointRpcProperty(exportName, key) {
1418
- const ctor = await getWorkerEntryExport(workerEntryPath, exportName);
1419
- const userEnv = stripInternalEnv(this.env);
1420
- const expectedWorkerEntrypointMessage = `Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`WorkerEntrypoint\` for RPC.`;
1421
- if (typeof ctor !== "function") throw new TypeError(expectedWorkerEntrypointMessage);
1422
- const instance = new ctor(this.ctx, userEnv);
1423
- if (!(instance instanceof WorkerEntrypoint)) throw new TypeError(expectedWorkerEntrypointMessage);
1424
- const value = getRpcProperty(ctor, instance, key);
1425
- if (typeof value === "function") return value.bind(instance);
1426
- return value;
1427
- }
1428
- /**
1429
- * Creates a proxy wrapper for `WorkerEntrypoint` classes that enables RPC functionality.
1430
- * The wrapper intercepts property access and delegates to the user code, handling both direct method calls and RPC property access.
1431
- * @param exportName - The name of the `WorkerEntrypoint` export to wrap
1432
- * @returns A `WorkerEntrypoint` constructor that acts as a proxy to the user code
1433
- */
1434
- function createWorkerEntrypointWrapper(exportName) {
1435
- class Wrapper extends WorkerEntrypoint {
1436
- constructor(ctx, env) {
1437
- super(ctx, env);
1438
- return new Proxy(this, { get(target, key, receiver) {
1439
- const value = Reflect.get(target, key, receiver);
1440
- if (value !== void 0) return value;
1441
- if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || DURABLE_OBJECT_KEYS.includes(key)) return;
1442
- return getRpcPropertyCallableThenable(key, getWorkerEntrypointRpcProperty.call(receiver, exportName, key));
1443
- } });
1444
- }
1445
- }
1446
- for (const key of WORKER_ENTRYPOINT_KEYS) Wrapper.prototype[key] = async function(arg) {
1447
- return maybeCaptureError({
1448
- isEntryWorker,
1449
- exportName,
1450
- key
1451
- }, async () => {
1452
- if (key === "fetch") {
1453
- const request = arg;
1454
- const url = new URL(request.url);
1455
- if (url.pathname === INIT_PATH) {
1456
- if (request.headers.get(IS_PARENT_ENVIRONMENT_HEADER) === "true") {
1457
- const workerEntryPathHeader = request.headers.get(WORKER_ENTRY_PATH_HEADER);
1458
- if (!workerEntryPathHeader) throw new Error(`Unexpected error: "${WORKER_ENTRY_PATH_HEADER}" header not set.`);
1459
- const isEntryWorkerHeader = request.headers.get(IS_ENTRY_WORKER_HEADER);
1460
- if (!isEntryWorkerHeader) throw new Error(`Unexpected error: "${IS_ENTRY_WORKER_HEADER}" header not set.`);
1461
- workerEntryPath = decodeURIComponent(workerEntryPathHeader);
1462
- isEntryWorker = isEntryWorkerHeader === "true";
1463
- }
1464
- return this.env.__VITE_RUNNER_OBJECT__.get("singleton").fetch(request);
1465
- }
1466
- if (url.pathname === GET_EXPORT_TYPES_PATH) {
1467
- const workerEntryExportTypes = await getWorkerEntryExportTypes();
1468
- return Response.json(workerEntryExportTypes);
1469
- }
1470
- }
1471
- const exportValue = await getWorkerEntryExport(workerEntryPath, exportName);
1472
- const userEnv = stripInternalEnv(this.env);
1473
- if (typeof exportValue === "object" && exportValue !== null) {
1474
- const maybeFn = exportValue[key];
1475
- if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`);
1476
- return maybeFn.call(exportValue, arg, userEnv, this.ctx);
1477
- } else if (typeof exportValue === "function") {
1478
- const instance = new exportValue(this.ctx, userEnv);
1479
- if (!(instance instanceof WorkerEntrypoint)) throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`WorkerEntrypoint\`.`);
1480
- const maybeFn = instance[key];
1481
- if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` method.`);
1482
- return maybeFn.call(instance, arg);
1483
- } else return /* @__PURE__ */ new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be an object or a class.`);
1484
- });
1485
- };
1486
- return Wrapper;
1487
- }
1488
- /** Symbol key for storing the `DurableObject` instance */
1489
- const kInstance = Symbol("kInstance");
1490
- /** Symbol key for the instance initialization method */
1491
- const kEnsureInstance = Symbol("kEnsureInstance");
1492
- /**
1493
- * Retrieves an RPC property from a `DurableObject` export, ensuring an instance is properly initialized and returning the bound method or property value.
1494
- * @param exportName - The name of the `DurableObject` export
1495
- * @param key - The property key to access on the `DurableObject` instance
1496
- * @returns The property value, with methods bound to the instance
1497
- * @throws TypeError if the export is not a `DurableObject` subclass
1498
- */
1499
- async function getDurableObjectRpcProperty(exportName, key) {
1500
- const { ctor, instance } = await this[kEnsureInstance]();
1501
- if (!(instance instanceof DurableObject)) throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`DurableObject\` for RPC.`);
1502
- const value = getRpcProperty(ctor, instance, key);
1503
- if (typeof value === "function") return value.bind(instance);
1504
- return value;
1505
- }
1506
- /**
1507
- * Creates a proxy wrapper for `DurableObject` classes that enables RPC functionality.
1508
- * The wrapper manages instance lifecycle and delegates method calls to the user code, handling both direct method calls and RPC property access.
1509
- * @param exportName - The name of the `DurableObject` export to wrap
1510
- * @returns A `DurableObject` constructor that acts as a proxy to the user code
1511
- */
1512
- function createDurableObjectWrapper(exportName) {
1513
- class Wrapper extends DurableObject {
1514
- [kInstance];
1515
- constructor(ctx, env) {
1516
- super(ctx, env);
1517
- return new Proxy(this, { get(target, key, receiver) {
1518
- const value = Reflect.get(target, key, receiver);
1519
- if (value !== void 0) return value;
1520
- if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || WORKER_ENTRYPOINT_KEYS.includes(key)) return;
1521
- return getRpcPropertyCallableThenable(key, getDurableObjectRpcProperty.call(receiver, exportName, key));
1522
- } });
1523
- }
1524
- async [kEnsureInstance]() {
1525
- const ctor = await getWorkerEntryExport(workerEntryPath, exportName);
1526
- if (typeof ctor !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`DurableObject\`.`);
1527
- if (!this[kInstance] || this[kInstance].ctor !== ctor) {
1528
- const userEnv = stripInternalEnv(this.env);
1529
- this[kInstance] = {
1530
- ctor,
1531
- instance: new ctor(this.ctx, userEnv)
1532
- };
1533
- await this.ctx.blockConcurrencyWhile(async () => {});
1534
- }
1535
- return this[kInstance];
1536
- }
1537
- }
1538
- for (const key of DURABLE_OBJECT_KEYS) Wrapper.prototype[key] = async function(...args) {
1539
- const { instance } = await this[kEnsureInstance]();
1540
- const maybeFn = instance[key];
1541
- if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`);
1542
- return maybeFn.apply(instance, args);
1543
- };
1544
- return Wrapper;
1545
- }
1546
- /**
1547
- * Creates a proxy wrapper for `WorkflowEntrypoint` classes.
1548
- * The wrapper delegates method calls to the user code.
1549
- * @param exportName - The name of the `WorkflowEntrypoint` export to wrap
1550
- * @returns A `WorkflowEntrypoint` constructor that acts as a proxy to the user code
1551
- */
1552
- function createWorkflowEntrypointWrapper(exportName) {
1553
- class Wrapper extends WorkflowEntrypoint {}
1554
- for (const key of WORKFLOW_ENTRYPOINT_KEYS) Wrapper.prototype[key] = async function(...args) {
1555
- const ctor = await getWorkerEntryExport(workerEntryPath, exportName);
1556
- const userEnv = stripInternalEnv(this.env);
1557
- const instance = new ctor(this.ctx, userEnv);
1558
- if (!(instance instanceof WorkflowEntrypoint)) throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`WorkflowEntrypoint\`.`);
1559
- const maybeFn = instance[key];
1560
- if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`);
1561
- return maybeFn.apply(instance, args);
1562
- };
1563
- return Wrapper;
1564
- }
1565
-
1566
- //#endregion
1567
- export { __VITE_RUNNER_OBJECT__, createDurableObjectWrapper, createWorkerEntrypointWrapper, createWorkflowEntrypointWrapper };
1129
+ export { ESModulesEvaluator, EvaluatedModules, ModuleRunner, createDefaultImportMeta, createNodeImportMeta, createWebSocketModuleRunnerTransport, normalizeModuleId, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };