@cloudflare/vite-plugin 1.20.3 → 1.21.1

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,7 +1,7 @@
1
1
  //#region package.json
2
2
  var package_default = {
3
3
  name: "@cloudflare/vite-plugin",
4
- version: "1.20.3",
4
+ version: "1.21.1",
5
5
  description: "Cloudflare plugin for Vite",
6
6
  keywords: [
7
7
  "cloudflare",
@@ -39,12 +39,7 @@ var package_default = {
39
39
  },
40
40
  dependencies: {
41
41
  "@cloudflare/unenv-preset": "workspace:*",
42
- "@remix-run/node-fetch-server": "^0.8.0",
43
- "defu": "^6.1.4",
44
- "get-port": "^7.1.0",
45
42
  "miniflare": "workspace:*",
46
- "picocolors": "^1.1.1",
47
- "tinyglobby": "^0.2.12",
48
43
  "unenv": "2.0.0-rc.24",
49
44
  "wrangler": "workspace:*",
50
45
  "ws": "catalog:default"
@@ -56,12 +51,17 @@ var package_default = {
56
51
  "@cloudflare/workers-tsconfig": "workspace:*",
57
52
  "@cloudflare/workers-types": "catalog:default",
58
53
  "@cloudflare/workers-utils": "workspace:*",
54
+ "@remix-run/node-fetch-server": "^0.8.0",
59
55
  "@types/node": "catalog:vite-plugin",
60
56
  "@types/semver": "^7.5.1",
61
57
  "@types/ws": "^8.5.13",
58
+ "defu": "^6.1.4",
59
+ "get-port": "^7.1.0",
62
60
  "magic-string": "^0.30.12",
63
61
  "mlly": "^1.7.4",
62
+ "picocolors": "^1.1.1",
64
63
  "semver": "^7.7.1",
64
+ "tinyglobby": "^0.2.12",
65
65
  "tree-kill": "^1.2.2",
66
66
  "tsdown": "0.16.3",
67
67
  "typescript": "catalog:default",
@@ -78,4 +78,4 @@ var package_default = {
78
78
 
79
79
  //#endregion
80
80
  export { package_default as default };
81
- //# sourceMappingURL=package-ChiaOPs2.mjs.map
81
+ //# sourceMappingURL=package-BLWYKDcZ.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"package-ChiaOPs2.mjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@cloudflare/vite-plugin\",\n\t\"version\": \"1.20.3\",\n\t\"description\": \"Cloudflare plugin for Vite\",\n\t\"keywords\": [\n\t\t\"cloudflare\",\n\t\t\"workers\",\n\t\t\"cloudflare-workers\",\n\t\t\"vite\",\n\t\t\"vite-plugin\"\n\t],\n\t\"homepage\": \"https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare#readme\",\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk/issues\"\n\t},\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk.git\",\n\t\t\"directory\": \"packages/vite-plugin-cloudflare\"\n\t},\n\t\"license\": \"MIT\",\n\t\"sideEffects\": false,\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"types\": \"./dist/index.d.mts\",\n\t\t\t\"import\": \"./dist/index.mjs\"\n\t\t}\n\t},\n\t\"main\": \"./dist/index.mjs\",\n\t\"types\": \"./dist/index.d.mts\",\n\t\"files\": [\n\t\t\"dist\"\n\t],\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\n\t\t\"check:lint\": \"eslint . --max-warnings=0\",\n\t\t\"check:type\": \"tsc --build\",\n\t\t\"dev\": \"tsdown --watch\",\n\t\t\"test\": \"vitest run\",\n\t\t\"test:ci\": \"pnpm test\",\n\t\t\"test:e2e\": \"vitest run -c e2e/vitest.config.ts\",\n\t\t\"test:watch\": \"vitest\"\n\t},\n\t\"dependencies\": {\n\t\t\"@cloudflare/unenv-preset\": \"workspace:*\",\n\t\t\"@remix-run/node-fetch-server\": \"^0.8.0\",\n\t\t\"defu\": \"^6.1.4\",\n\t\t\"get-port\": \"^7.1.0\",\n\t\t\"miniflare\": \"workspace:*\",\n\t\t\"picocolors\": \"^1.1.1\",\n\t\t\"tinyglobby\": \"^0.2.12\",\n\t\t\"unenv\": \"2.0.0-rc.24\",\n\t\t\"wrangler\": \"workspace:*\",\n\t\t\"ws\": \"catalog:default\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@cloudflare/containers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/mock-npm-registry\": \"workspace:*\",\n\t\t\"@cloudflare/workers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/workers-tsconfig\": \"workspace:*\",\n\t\t\"@cloudflare/workers-types\": \"catalog:default\",\n\t\t\"@cloudflare/workers-utils\": \"workspace:*\",\n\t\t\"@types/node\": \"catalog:vite-plugin\",\n\t\t\"@types/semver\": \"^7.5.1\",\n\t\t\"@types/ws\": \"^8.5.13\",\n\t\t\"magic-string\": \"^0.30.12\",\n\t\t\"mlly\": \"^1.7.4\",\n\t\t\"semver\": \"^7.7.1\",\n\t\t\"tree-kill\": \"^1.2.2\",\n\t\t\"tsdown\": \"0.16.3\",\n\t\t\"typescript\": \"catalog:default\",\n\t\t\"vite\": \"catalog:vite-plugin\",\n\t\t\"vitest\": \"catalog:default\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"vite\": \"^6.1.0 || ^7.0.0\",\n\t\t\"wrangler\": \"workspace:^\"\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"workers-sdk\": {\n\t\t\"prerelease\": true\n\t}\n}\n"],"mappings":";sBAAA;OACS;UACG;cACI;WACH;EACX;EACA;EACA;EACA;EACA;EACA;WACW;OACJ,EACP,OAAO,oDACP;aACa;EACb,QAAQ;EACR,OAAO;EACP,aAAa;EACb;UACU;cACI;OACP;UACG,EACV,KAAK;EACJ,SAAS;EACT,UAAU;EACV,EACD;OACO;QACC;QACA,CACR,OACA;UACU;EACV,SAAS;EACT,cAAc;EACd,cAAc;EACd,OAAO;EACP,QAAQ;EACR,WAAW;EACX,YAAY;EACZ,cAAc;EACd;eACe;EACf,4BAA4B;EAC5B,gCAAgC;EAChC,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,cAAc;EACd,cAAc;EACd,SAAS;EACT,YAAY;EACZ,MAAM;EACN;kBACkB;EAClB,iCAAiC;EACjC,iCAAiC;EACjC,8BAA8B;EAC9B,gCAAgC;EAChC,6BAA6B;EAC7B,6BAA6B;EAC7B,eAAe;EACf,iBAAiB;EACjB,aAAa;EACb,gBAAgB;EAChB,QAAQ;EACR,UAAU;EACV,aAAa;EACb,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV;mBACmB;EACnB,QAAQ;EACR,YAAY;EACZ;gBACgB,EAChB,UAAU,UACV;CACD,eAAe,EACd,cAAc,MACd;CACD"}
1
+ {"version":3,"file":"package-BLWYKDcZ.mjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@cloudflare/vite-plugin\",\n\t\"version\": \"1.21.1\",\n\t\"description\": \"Cloudflare plugin for Vite\",\n\t\"keywords\": [\n\t\t\"cloudflare\",\n\t\t\"workers\",\n\t\t\"cloudflare-workers\",\n\t\t\"vite\",\n\t\t\"vite-plugin\"\n\t],\n\t\"homepage\": \"https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare#readme\",\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk/issues\"\n\t},\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk.git\",\n\t\t\"directory\": \"packages/vite-plugin-cloudflare\"\n\t},\n\t\"license\": \"MIT\",\n\t\"sideEffects\": false,\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"types\": \"./dist/index.d.mts\",\n\t\t\t\"import\": \"./dist/index.mjs\"\n\t\t}\n\t},\n\t\"main\": \"./dist/index.mjs\",\n\t\"types\": \"./dist/index.d.mts\",\n\t\"files\": [\n\t\t\"dist\"\n\t],\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\n\t\t\"check:lint\": \"eslint . --max-warnings=0\",\n\t\t\"check:type\": \"tsc --build\",\n\t\t\"dev\": \"tsdown --watch\",\n\t\t\"test\": \"vitest run\",\n\t\t\"test:ci\": \"pnpm test\",\n\t\t\"test:e2e\": \"vitest run -c e2e/vitest.config.ts\",\n\t\t\"test:watch\": \"vitest\"\n\t},\n\t\"dependencies\": {\n\t\t\"@cloudflare/unenv-preset\": \"workspace:*\",\n\t\t\"miniflare\": \"workspace:*\",\n\t\t\"unenv\": \"2.0.0-rc.24\",\n\t\t\"wrangler\": \"workspace:*\",\n\t\t\"ws\": \"catalog:default\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@cloudflare/containers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/mock-npm-registry\": \"workspace:*\",\n\t\t\"@cloudflare/workers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/workers-tsconfig\": \"workspace:*\",\n\t\t\"@cloudflare/workers-types\": \"catalog:default\",\n\t\t\"@cloudflare/workers-utils\": \"workspace:*\",\n\t\t\"@remix-run/node-fetch-server\": \"^0.8.0\",\n\t\t\"@types/node\": \"catalog:vite-plugin\",\n\t\t\"@types/semver\": \"^7.5.1\",\n\t\t\"@types/ws\": \"^8.5.13\",\n\t\t\"defu\": \"^6.1.4\",\n\t\t\"get-port\": \"^7.1.0\",\n\t\t\"magic-string\": \"^0.30.12\",\n\t\t\"mlly\": \"^1.7.4\",\n\t\t\"picocolors\": \"^1.1.1\",\n\t\t\"semver\": \"^7.7.1\",\n\t\t\"tinyglobby\": \"^0.2.12\",\n\t\t\"tree-kill\": \"^1.2.2\",\n\t\t\"tsdown\": \"0.16.3\",\n\t\t\"typescript\": \"catalog:default\",\n\t\t\"vite\": \"catalog:vite-plugin\",\n\t\t\"vitest\": \"catalog:default\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"vite\": \"^6.1.0 || ^7.0.0\",\n\t\t\"wrangler\": \"workspace:^\"\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"workers-sdk\": {\n\t\t\"prerelease\": true\n\t}\n}\n"],"mappings":";sBAAA;OACS;UACG;cACI;WACH;EACX;EACA;EACA;EACA;EACA;EACA;WACW;OACJ,EACP,OAAO,oDACP;aACa;EACb,QAAQ;EACR,OAAO;EACP,aAAa;EACb;UACU;cACI;OACP;UACG,EACV,KAAK;EACJ,SAAS;EACT,UAAU;EACV,EACD;OACO;QACC;QACA,CACR,OACA;UACU;EACV,SAAS;EACT,cAAc;EACd,cAAc;EACd,OAAO;EACP,QAAQ;EACR,WAAW;EACX,YAAY;EACZ,cAAc;EACd;eACe;EACf,4BAA4B;EAC5B,aAAa;EACb,SAAS;EACT,YAAY;EACZ,MAAM;EACN;kBACkB;EAClB,iCAAiC;EACjC,iCAAiC;EACjC,8BAA8B;EAC9B,gCAAgC;EAChC,6BAA6B;EAC7B,6BAA6B;EAC7B,gCAAgC;EAChC,eAAe;EACf,iBAAiB;EACjB,aAAa;EACb,QAAQ;EACR,YAAY;EACZ,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,UAAU;EACV,cAAc;EACd,aAAa;EACb,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV;mBACmB;EACnB,QAAQ;EACR,YAAY;EACZ;gBACgB,EAChB,UAAU,UACV;CACD,eAAe,EACd,cAAc,MACd;CACD"}
@@ -6,6 +6,8 @@ const INIT_PATH = "/__vite_plugin_cloudflare_init__";
6
6
  const GET_EXPORT_TYPES_PATH = "/__vite_plugin_cloudflare_get_export_types__";
7
7
  const WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
8
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__";
9
11
  const virtualPrefix = "virtual:cloudflare/";
10
12
  const VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
11
13
  const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;
@@ -1184,28 +1186,31 @@ function exportAll(exports, sourceModule) {
1184
1186
  */
1185
1187
  var CustomModuleRunner = class extends ModuleRunner {
1186
1188
  #env;
1187
- constructor(options, evaluator, env) {
1189
+ #environmentName;
1190
+ constructor(options, evaluator, env, environmentName) {
1188
1191
  super(options, evaluator);
1189
1192
  this.#env = env;
1193
+ this.#environmentName = environmentName;
1190
1194
  }
1191
1195
  async cachedModule(url, importer) {
1192
- const moduleId = await this.#env.__VITE_RUNNER_OBJECT__.get("singleton").getFetchedModuleId(url, importer);
1196
+ const moduleId = await this.#env.__VITE_RUNNER_OBJECT__.get("singleton").getFetchedModuleId(this.#environmentName, url, importer);
1193
1197
  const module = this.evaluatedModules.getModuleById(moduleId);
1194
1198
  if (!module) throw new Error(`Module "${moduleId}" is undefined`);
1195
1199
  return module;
1196
1200
  }
1197
1201
  };
1198
- /** Module runner instance */
1199
- let moduleRunner;
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;
1200
1206
  /**
1201
1207
  * Durable Object that creates the module runner and handles WebSocket communication with the Vite dev server.
1202
1208
  */
1203
1209
  var __VITE_RUNNER_OBJECT__ = class extends DurableObject {
1204
- /** WebSocket connection to the Vite dev server */
1205
- #webSocket;
1206
- #concurrentModuleNodePromises = /* @__PURE__ */ new Map();
1210
+ /** Per-environment state containing WebSocket and concurrent module node promises */
1211
+ #environments = /* @__PURE__ */ new Map();
1207
1212
  /**
1208
- * Handles fetch requests to initialize the module runner.
1213
+ * Handles fetch requests to initialize a module runner for an environment.
1209
1214
  * Creates a WebSocket pair for communication with the Vite dev server and initializes the ModuleRunner.
1210
1215
  * @param request - The incoming fetch request
1211
1216
  * @returns Response with WebSocket
@@ -1213,42 +1218,56 @@ var __VITE_RUNNER_OBJECT__ = class extends DurableObject {
1213
1218
  */
1214
1219
  async fetch(request) {
1215
1220
  const { pathname } = new URL(request.url);
1216
- if (pathname !== INIT_PATH) throw new Error(`__VITE_RUNNER_OBJECT__ received invalid pathname: ${pathname}`);
1217
- if (moduleRunner) throw new Error(`Module runner already initialized`);
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;
1218
1226
  const { 0: client, 1: server } = new WebSocketPair();
1219
1227
  server.accept();
1220
- this.#webSocket = server;
1221
- moduleRunner = await createModuleRunner(this.env, this.#webSocket);
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);
1222
1235
  return new Response(null, {
1223
1236
  status: 101,
1224
1237
  webSocket: client
1225
1238
  });
1226
1239
  }
1227
1240
  /**
1228
- * Sends data to the Vite dev server via the WebSocket.
1241
+ * Sends data to the Vite dev server via the WebSocket for a specific environment.
1242
+ * @param environmentName - The environment name
1229
1243
  * @param data - The data to send as a string
1230
1244
  * @throws Error if the WebSocket is not initialized
1231
1245
  */
1232
- send(data) {
1233
- if (!this.#webSocket) throw new Error(`Module runner WebSocket not initialized`);
1234
- this.#webSocket.send(data);
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);
1235
1250
  }
1236
1251
  /**
1237
1252
  * Based on the implementation of `cachedModule` from Vite's `ModuleRunner`.
1238
1253
  * Running this in the DO enables us to share promises across invocations.
1254
+ * @param environmentName - The environment name
1239
1255
  * @param url - The module URL
1240
1256
  * @param importer - The module's importer
1241
1257
  * @returns The ID of the fetched module
1242
1258
  */
1243
- async getFetchedModuleId(url, importer) {
1244
- if (!moduleRunner) throw new Error(`Module runner not initialized`);
1245
- let cached = this.#concurrentModuleNodePromises.get(url);
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);
1246
1265
  if (!cached) {
1247
1266
  const cachedModule = moduleRunner.evaluatedModules.getModuleByUrl(url);
1248
1267
  cached = moduleRunner.getModuleInformation(url, importer, cachedModule).finally(() => {
1249
- this.#concurrentModuleNodePromises.delete(url);
1268
+ environmentState.concurrentModuleNodePromises.delete(url);
1250
1269
  });
1251
- this.#concurrentModuleNodePromises.set(url, cached);
1270
+ environmentState.concurrentModuleNodePromises.set(url, cached);
1252
1271
  } else moduleRunner.debug?.("[module runner] using cached module info for", url);
1253
1272
  return (await cached).id;
1254
1273
  }
@@ -1257,9 +1276,10 @@ var __VITE_RUNNER_OBJECT__ = class extends DurableObject {
1257
1276
  * Creates a new module runner instance with a WebSocket transport.
1258
1277
  * @param env - The wrapper env
1259
1278
  * @param webSocket - WebSocket connection for communication with Vite dev server
1279
+ * @param environmentName - The name of the environment this runner is for
1260
1280
  * @returns Configured module runner instance
1261
1281
  */
1262
- async function createModuleRunner(env, webSocket) {
1282
+ async function createModuleRunner(env, webSocket, environmentName) {
1263
1283
  return new CustomModuleRunner({
1264
1284
  sourcemapInterceptor: "prepareStackTrace",
1265
1285
  transport: {
@@ -1277,11 +1297,12 @@ async function createModuleRunner(env, webSocket) {
1277
1297
  webSocket.close();
1278
1298
  },
1279
1299
  send(data) {
1280
- env.__VITE_RUNNER_OBJECT__.get("singleton").send(JSON.stringify(data));
1300
+ env.__VITE_RUNNER_OBJECT__.get("singleton").send(environmentName, JSON.stringify(data));
1281
1301
  },
1282
1302
  async invoke(data) {
1283
1303
  return await (await env.__VITE_INVOKE_MODULE__.fetch(new Request(UNKNOWN_HOST, {
1284
1304
  method: "POST",
1305
+ headers: { [ENVIRONMENT_NAME_HEADER]: environmentName },
1285
1306
  body: JSON.stringify(data)
1286
1307
  }))).json();
1287
1308
  }
@@ -1303,7 +1324,7 @@ async function createModuleRunner(env, webSocket) {
1303
1324
  }
1304
1325
  return import(filepath);
1305
1326
  }
1306
- }, env);
1327
+ }, env, environmentName);
1307
1328
  }
1308
1329
  /**
1309
1330
  * Retrieves a specific export from a Worker entry module using the module runner.
@@ -1313,6 +1334,8 @@ async function createModuleRunner(env, webSocket) {
1313
1334
  * @throws Error if the module runner has not been initialized or the module does not define the requested export
1314
1335
  */
1315
1336
  async function getWorkerEntryExport(workerEntryPath$1, exportName) {
1337
+ if (!parentEnvironmentName) throw new Error(`Parent environment not initialized`);
1338
+ const moduleRunner = moduleRunners.get(parentEnvironmentName);
1316
1339
  if (!moduleRunner) throw new Error(`Module runner not initialized`);
1317
1340
  const module = await moduleRunner.import(VIRTUAL_WORKER_ENTRY);
1318
1341
  const exportValue = typeof module === "object" && module !== null && exportName in module && module[exportName];
@@ -1320,10 +1343,25 @@ async function getWorkerEntryExport(workerEntryPath$1, exportName) {
1320
1343
  return exportValue;
1321
1344
  }
1322
1345
  async function getWorkerEntryExportTypes() {
1346
+ if (!parentEnvironmentName) throw new Error(`Parent environment not initialized`);
1347
+ const moduleRunner = moduleRunners.get(parentEnvironmentName);
1323
1348
  if (!moduleRunner) throw new Error(`Module runner not initialized`);
1324
1349
  const { getExportTypes } = await moduleRunner.import(VIRTUAL_EXPORT_TYPES);
1325
1350
  return getExportTypes(await moduleRunner.import(VIRTUAL_WORKER_ENTRY));
1326
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;
1327
1365
 
1328
1366
  //#endregion
1329
1367
  //#region src/workers/runner-worker/index.ts
@@ -1415,12 +1453,14 @@ function createWorkerEntrypointWrapper(exportName) {
1415
1453
  const request = arg;
1416
1454
  const url = new URL(request.url);
1417
1455
  if (url.pathname === INIT_PATH) {
1418
- const workerEntryPathHeader = request.headers.get(WORKER_ENTRY_PATH_HEADER);
1419
- if (!workerEntryPathHeader) throw new Error(`Unexpected error: "${WORKER_ENTRY_PATH_HEADER}" header not set.`);
1420
- const isEntryWorkerHeader = request.headers.get(IS_ENTRY_WORKER_HEADER);
1421
- if (!isEntryWorkerHeader) throw new Error(`Unexpected error: "${IS_ENTRY_WORKER_HEADER}" header not set.`);
1422
- workerEntryPath = decodeURIComponent(workerEntryPathHeader);
1423
- isEntryWorker = isEntryWorkerHeader === "true";
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
+ }
1424
1464
  return this.env.__VITE_RUNNER_OBJECT__.get("singleton").fetch(request);
1425
1465
  }
1426
1466
  if (url.pathname === GET_EXPORT_TYPES_PATH) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "1.20.3",
3
+ "version": "1.21.1",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -33,25 +33,25 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@remix-run/node-fetch-server": "^0.8.0",
37
- "defu": "^6.1.4",
38
- "get-port": "^7.1.0",
39
- "picocolors": "^1.1.1",
40
- "tinyglobby": "^0.2.12",
41
36
  "unenv": "2.0.0-rc.24",
42
37
  "ws": "8.18.0",
43
- "@cloudflare/unenv-preset": "2.9.0",
44
- "miniflare": "4.20260111.0",
45
- "wrangler": "4.59.1"
38
+ "@cloudflare/unenv-preset": "2.10.0",
39
+ "miniflare": "4.20260116.0",
40
+ "wrangler": "4.59.3"
46
41
  },
47
42
  "devDependencies": {
48
- "@cloudflare/workers-types": "^4.20260111.0",
43
+ "@cloudflare/workers-types": "^4.20260116.0",
44
+ "@remix-run/node-fetch-server": "^0.8.0",
49
45
  "@types/node": "^22.10.1",
50
46
  "@types/semver": "^7.5.1",
51
47
  "@types/ws": "^8.5.13",
48
+ "defu": "^6.1.4",
49
+ "get-port": "^7.1.0",
52
50
  "magic-string": "^0.30.12",
53
51
  "mlly": "^1.7.4",
52
+ "picocolors": "^1.1.1",
54
53
  "semver": "^7.7.1",
54
+ "tinyglobby": "^0.2.12",
55
55
  "tree-kill": "^1.2.2",
56
56
  "tsdown": "0.16.3",
57
57
  "typescript": "~5.8.3",
@@ -59,13 +59,13 @@
59
59
  "vitest": "~3.2.0",
60
60
  "@cloudflare/containers-shared": "0.8.0",
61
61
  "@cloudflare/mock-npm-registry": "0.0.0",
62
+ "@cloudflare/workers-shared": "0.18.9",
62
63
  "@cloudflare/workers-tsconfig": "0.0.0",
63
- "@cloudflare/workers-utils": "0.7.0",
64
- "@cloudflare/workers-shared": "0.18.9"
64
+ "@cloudflare/workers-utils": "0.7.1"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "vite": "^6.1.0 || ^7.0.0",
68
- "wrangler": "^4.59.1"
68
+ "wrangler": "^4.59.3"
69
69
  },
70
70
  "publishConfig": {
71
71
  "access": "public"