@cloudflare/vite-plugin 1.27.0 → 1.28.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.
package/dist/index.d.mts CHANGED
@@ -40,6 +40,10 @@ declare const nonApplicableWorkerConfigs: {
40
40
  * application they lose their purpose/meaning)
41
41
  */
42
42
  readonly notRelevant: readonly ["base_dir", "build", "find_additional_modules", "no_bundle", "preserve_file_names", "rules", "site", "tsconfig"];
43
+ /**
44
+ * Configs that are only supported on the entry worker and will be ignored on auxiliary workers
45
+ */
46
+ readonly notSupportedOnAuxiliary: readonly ["assets"];
43
47
  };
44
48
  //#endregion
45
49
  //#region src/plugin-config.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils.ts","../src/workers-configs.ts","../src/plugin-config.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;ACgDK,KDOO,OCPP,CAAA,CAAA,CAAA,GDOoB,OCPpB,CDO4B,CCP5B,EAAA,SAA8B,CAAA;;;;AAA9B,KAjBO,YAAA,GAAe,IAiBtB,CAjB2B,eAiBG,EAAU,MAjBU,mBAiBV,CAA0B;KAAlE,8BAAA,UAAwC;KAExC,mBAAA,GACF,oCACA;KAEE,iCAAA,SACE;AC/BP,KDiCK,8BAAA,GACJ,8BClCuB,CAAA,aAAA,CAAA,CAAA,MAAA,CAAA;AAA8B;AAE5B;AAI0B;AAS1C,cDwBG,0BCtBJ,EAAA;EAGJ;AAEyB;AAMU;EAQnC,SAAA,cAAA,EAAsB;IAChB,SAAA,KAAA,EAAA;MAAR,SAAA,eAAA,EAAA,eAAA;MAES,SAAA,QAAA,EAAA,2DAAA;IACG,CAAA;IAED,SAAA,MAAA,EAAA;MACa,SAAA,eAAA,EAAA,QAAA;MAEX,SAAA,QAAA,EAAA,oDAAA;IAAR,CAAA;IAAO,SAAA,MAAA,EAAA;MAEE,SAAa,eAAA,EAAA,cAAA;MACV,SAAA,QAAA,EAAA,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ACJ,YADI;EACJ,aAAA,CAAA,EAAA,MAAA,GAAA,KAAA;EAGA,cAAA,CAAA,EAAA,OAAA;EALsB,YAAA,CAAA,EAKtB,YALsB;;AAQrB,UAAA,wBAAA,SAAiC,YAAR,CAAA;EACnB,YAAA,EAAR,OAAQ,CAAA,YAAA,CAAA,cAAA,CAAA,CAAA;EAAR,IAAA,EACR,OADQ,CACA,YADA,CAAA,MAAA,CAAA,CAAA;EACA,kBAAA,EACM,OADN,CACc,YADd,CAAA,oBAAA,CAAA,CAAA;;;;;AF1Bf;;;;ACxBA;;AAAuD,iBEevC,UAAA,CFfuC,YAAA,CAAA,EEed,YFfc,CAAA,EEeM,IAAA,CAAK,MFfX,EAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils.ts","../src/workers-configs.ts","../src/plugin-config.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;ACsDK,KDCO,OCDP,CAAA,CAAA,CAAA,GDCoB,OCDpB,CDC4B,CCD5B,EAAA,SAA8B,CAAA;;;;AAA9B,KAvBO,YAAA,GAAe,IAuBtB,CAvB2B,eAuBG,EAAU,MAvBU,mBAuBV,CAA0B;KAAlE,8BAAA,UAAwC;KAExC,mBAAA,GACF,oCACA;AClCH,KDoCK,iCAAA,GCpCmB,MDqCjB,8BCrCiB,CAAA,gBAAA,CAAA;AAA8B,KDuCjD,8BAAA,GACJ,8BCtCyB,CAAA,aAAA,CAAA,CAAA,MAAA,CAAA;AAAA;AAI0B;AAKQ;AASvD,cDyBQ,0BCxBV,EAAA;EAGO;AAI8B;AAGH;EAM1B,SAAA,cAAA,EAAA;IAAR,SAAA,KAAA,EAAA;MAES,SAAA,eAAA,EAAA,eAAA;MACG,SAAA,QAAA,EAAA,2DAAA;IAED,CAAA;IACa,SAAA,MAAA,EAAA;MAEX,SAAA,eAAA,EAAA,QAAA;MAAR,SAAA,QAAA,EAAA,oDAAA;IAAO,CAAA;IAEE,SAAA,MAAa,EAAA;MACV,SAAA,eA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AA,CAAA;AAAO,UAEE,YAAA,SAAqB,iBAFvB,CAAA;EAEE,gBAAa,CAAA,EACV,qBADU,EAAA;EACV,YAAA,CAAA,EACJ,YADI;EACJ,aAAA,CAAA,EAAA,MAAA,GAAA,KAAA;EAGA,cAAA,CAAA,EAAA,OAAA;EALsB,YAAA,CAAA,EAKtB,YALsB;;AAQrB,UAAA,wBAAA,SAAiC,YAAR,CAAA;EACnB,YAAA,EAAR,OAAQ,CAAA,YAAA,CAAA,cAAA,CAAA,CAAA;EAAR,IAAA,EACR,OADQ,CACA,YADA,CAAA,MAAA,CAAA,CAAA;EACA,kBAAA,EACM,OADN,CACc,YADd,CAAA,oBAAA,CAAA,CAAA;;;;;AF1Bf;;;;ACxBA;;AAAuD,iBEevC,UAAA,CFfuC,YAAA,CAAA,EEed,YFfc,CAAA,EEeM,IAAA,CAAK,MFfX,EAAA"}
package/dist/index.mjs CHANGED
@@ -14332,7 +14332,8 @@ const nonApplicableWorkerConfigs = {
14332
14332
  "rules",
14333
14333
  "site",
14334
14334
  "tsconfig"
14335
- ]
14335
+ ],
14336
+ notSupportedOnAuxiliary: ["assets"]
14336
14337
  };
14337
14338
  /**
14338
14339
  * The non applicable configs that can be and default to `undefined`
@@ -14350,7 +14351,8 @@ const nullableNonApplicable = [
14350
14351
  function readWorkerConfig(configPath, env$1) {
14351
14352
  const nonApplicable = {
14352
14353
  replacedByVite: /* @__PURE__ */ new Set(),
14353
- notRelevant: /* @__PURE__ */ new Set()
14354
+ notRelevant: /* @__PURE__ */ new Set(),
14355
+ notSupportedOnAuxiliary: /* @__PURE__ */ new Set()
14354
14356
  };
14355
14357
  const config = wrangler.unstable_readConfig({
14356
14358
  config: configPath,
@@ -14386,7 +14388,7 @@ function getWarningForWorkersConfigs(configs) {
14386
14388
  }
14387
14389
  const lines = [];
14388
14390
  const processWorkerConfig = (workerConfig, isEntryWorker = false) => {
14389
- const nonApplicableLines = getWorkerNonApplicableWarnLines(workerConfig, ` - `);
14391
+ const nonApplicableLines = getWorkerNonApplicableWarnLines(workerConfig, ` - `, { isAuxiliary: !isEntryWorker });
14390
14392
  if (nonApplicableLines.length > 0) {
14391
14393
  lines.push(` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${nodePath.relative("", workerConfig.config.configPath)}\`)` : ""}`);
14392
14394
  nonApplicableLines.forEach((line) => lines.push(line));
@@ -14401,11 +14403,12 @@ function getWarningForWorkersConfigs(configs) {
14401
14403
  ""
14402
14404
  ].join("\n");
14403
14405
  }
14404
- function getWorkerNonApplicableWarnLines(workerConfig, linePrefix) {
14406
+ function getWorkerNonApplicableWarnLines(workerConfig, linePrefix, options) {
14405
14407
  const lines = [];
14406
- const { replacedByVite, notRelevant } = workerConfig.nonApplicable;
14408
+ const { replacedByVite, notRelevant, notSupportedOnAuxiliary } = workerConfig.nonApplicable;
14407
14409
  for (const config of replacedByVite) lines.push(`${linePrefix}\`${config}\` which is replaced by Vite's \`${nonApplicableWorkerConfigs.replacedByVite[config].viteReplacement}\` (docs: ${nonApplicableWorkerConfigs.replacedByVite[config].viteDocs})`);
14408
14410
  if (notRelevant.size > 0) lines.push(`${linePrefix}${[...notRelevant].map((config) => `\`${config}\``).join(", ")} which ${notRelevant.size > 1 ? "are" : "is"} not relevant in the context of a Vite project`);
14411
+ if (options?.isAuxiliary && notSupportedOnAuxiliary.size > 0) lines.push(`${linePrefix}${[...notSupportedOnAuxiliary].map((config) => `\`${config}\``).join(", ")} which ${notSupportedOnAuxiliary.size > 1 ? "are" : "is"} not supported for auxiliary workers`);
14409
14412
  return lines;
14410
14413
  }
14411
14414
  function isReplacedByVite(configName) {
@@ -14550,7 +14553,8 @@ function resolveWorkerConfig(options) {
14550
14553
  raw = structuredClone(workerConfig);
14551
14554
  nonApplicable = {
14552
14555
  replacedByVite: /* @__PURE__ */ new Set(),
14553
- notRelevant: /* @__PURE__ */ new Set()
14556
+ notRelevant: /* @__PURE__ */ new Set(),
14557
+ notSupportedOnAuxiliary: /* @__PURE__ */ new Set()
14554
14558
  };
14555
14559
  }
14556
14560
  workerConfig = "entryWorkerConfig" in options ? customizeWorkerConfig({
@@ -14651,6 +14655,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14651
14655
  entryWorkerConfig: entryWorkerResolvedConfig.config,
14652
14656
  visitedConfigPaths: configPaths
14653
14657
  });
14658
+ if (workerResolvedConfig.config.assets) workerResolvedConfig.nonApplicable.notSupportedOnAuxiliary.add("assets");
14654
14659
  auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
14655
14660
  const workerEnvironmentName = auxiliaryWorker.viteEnvironment?.name ?? workerNameToEnvironmentName(workerResolvedConfig.config.topLevelName);
14656
14661
  validateAndAddEnvironmentName(workerEnvironmentName);
@@ -15792,6 +15797,34 @@ function createModuleReference(type, id) {
15792
15797
  return `__CLOUDFLARE_MODULE__${type}__${id}__CLOUDFLARE_MODULE__`;
15793
15798
  }
15794
15799
 
15800
+ //#endregion
15801
+ //#region src/plugins/cdn-cgi.ts
15802
+ /**
15803
+ * Plugin to forward `/cdn-cgi/` routes to Miniflare in development
15804
+ * We handle specified routes rather than using a catch all so that users can add their own routes using Vite's proxy functionality
15805
+ */
15806
+ const cdnCgiPlugin = createPlugin("cdn-cgi", (ctx) => {
15807
+ return {
15808
+ enforce: "pre",
15809
+ async configureServer(viteDevServer) {
15810
+ const entryWorkerConfig = ctx.entryWorkerConfig;
15811
+ if (!entryWorkerConfig) return;
15812
+ const entryWorkerName = entryWorkerConfig.name;
15813
+ const requestHandler = createRequestHandler((request$1) => {
15814
+ request$1.headers.set(CoreHeaders.ROUTE_OVERRIDE, entryWorkerName);
15815
+ return ctx.miniflare.dispatchFetch(request$1, { redirect: "manual" });
15816
+ });
15817
+ viteDevServer.middlewares.use(async (req, res, next) => {
15818
+ const url = req.originalUrl ?? "";
15819
+ const isLocalExplorer = url === "/cdn-cgi/explorer" || url.startsWith("/cdn-cgi/explorer/") || url.startsWith("/cdn-cgi/explorer?");
15820
+ const isTriggerHandler = url.startsWith("/cdn-cgi/handler/");
15821
+ if (isLocalExplorer || isTriggerHandler) await requestHandler(req, res, next);
15822
+ else next();
15823
+ });
15824
+ }
15825
+ };
15826
+ });
15827
+
15795
15828
  //#endregion
15796
15829
  //#region ../workers-shared/utils/configuration/constructConfiguration.ts
15797
15830
  function constructRedirects({ redirects, redirectsFile, logger }) {
@@ -23172,7 +23205,7 @@ async function cleanupDuplicateImageTags(dockerPath, imageTag) {
23172
23205
 
23173
23206
  //#endregion
23174
23207
  //#region ../containers-shared/src/images.ts
23175
- const DEFAULT_CONTAINER_EGRESS_INTERCEPTOR_IMAGE = "cloudflare/proxy-everything:3f5e832@sha256:816255f5b6ebdc2cdcddb578d803121e7ee9cfe178442da07725d75a66cdcf37";
23208
+ const DEFAULT_CONTAINER_EGRESS_INTERCEPTOR_IMAGE = "cloudflare/proxy-everything:233db0f@sha256:f159d9e1b0f28bc01bd106f38d62479c018d050e3f95b365c5f9b5f83f60df82";
23176
23209
  function getEgressInterceptorImage() {
23177
23210
  return process.env.MINIFLARE_CONTAINER_EGRESS_IMAGE ?? DEFAULT_CONTAINER_EGRESS_INTERCEPTOR_IMAGE;
23178
23211
  }
@@ -26260,8 +26293,12 @@ function handleWebSocket(httpServer, miniflare, entryWorkerName) {
26260
26293
  const nodeWebSocket = new WebSocketServer({ noServer: true });
26261
26294
  httpServer.on("upgrade", async (request$1, socket, head) => {
26262
26295
  socket.on("error", () => socket.destroy());
26263
- const url = new URL(request$1.url ?? "", UNKNOWN_HOST);
26264
- if (request$1.headers["sec-websocket-protocol"]?.startsWith("vite")) return;
26296
+ const rawHost = request$1.headers.host ?? UNKNOWN_HOST;
26297
+ const base = /^https?:\/\//i.test(rawHost) ? rawHost : `http://${rawHost}`;
26298
+ const url = new URL(request$1.url ?? "", base);
26299
+ const isViteRequest = request$1.headers["sec-websocket-protocol"]?.startsWith("vite");
26300
+ const isSandboxRequest = hasSandboxOrigin(url.origin);
26301
+ if (isViteRequest && !isSandboxRequest) return;
26265
26302
  const headers = createHeaders(request$1);
26266
26303
  if (entryWorkerName) headers.set(CoreHeaders.ROUTE_OVERRIDE, entryWorkerName);
26267
26304
  const workerWebSocket = (await miniflare.dispatchFetch(url, {
@@ -26278,6 +26315,20 @@ function handleWebSocket(httpServer, miniflare, entryWorkerName) {
26278
26315
  });
26279
26316
  });
26280
26317
  }
26318
+ /**
26319
+ * Matches the origin of a Sandbox SDK preview URL.
26320
+ * See: https://developers.cloudflare.com/sandbox/concepts/preview-urls/
26321
+ *
26322
+ * Pattern: https?://<port(4+ digits)>-<id(no dots)>-<token>.localhost
26323
+ *
26324
+ * IMPORTANT: The token segment is [a-z0-9_]+ (no hyphens) to prevent ReDoS — two adjacent
26325
+ * [^.]+ groups separated by - cause quadratic backtracking on hyphen-heavy input. Tokens are
26326
+ * documented as letters/digits/underscores only.
26327
+ */
26328
+ const SANDBOX_ORIGIN_REGEXP = /^https?:\/\/\d{4,}-[^.]+-[a-z0-9_]+\.localhost(:\d+)?$/i;
26329
+ function hasSandboxOrigin(origin) {
26330
+ return SANDBOX_ORIGIN_REGEXP.test(origin);
26331
+ }
26281
26332
 
26282
26333
  //#endregion
26283
26334
  //#region src/plugins/dev.ts
@@ -26690,27 +26741,6 @@ function addBindingsShortcut(server, ctx) {
26690
26741
  server.bindCLIShortcuts({ customShortcuts: [printBindingsShortcut] });
26691
26742
  }
26692
26743
 
26693
- //#endregion
26694
- //#region src/plugins/trigger-handlers.ts
26695
- /**
26696
- * Plugin to forward `/cdn-cgi/handler/*` routes to trigger handlers in development
26697
- */
26698
- const triggerHandlersPlugin = createPlugin("trigger-handlers", (ctx) => {
26699
- return {
26700
- enforce: "pre",
26701
- async configureServer(viteDevServer) {
26702
- const entryWorkerConfig = ctx.entryWorkerConfig;
26703
- if (!entryWorkerConfig) return;
26704
- const entryWorkerName = entryWorkerConfig.name;
26705
- const requestHandler = createRequestHandler((request$1) => {
26706
- request$1.headers.set(CoreHeaders.ROUTE_OVERRIDE, entryWorkerName);
26707
- return ctx.miniflare.dispatchFetch(request$1, { redirect: "manual" });
26708
- });
26709
- viteDevServer.middlewares.use("/cdn-cgi/handler/", requestHandler);
26710
- }
26711
- };
26712
- });
26713
-
26714
26744
  //#endregion
26715
26745
  //#region src/plugins/wasm.ts
26716
26746
  const wasmInitRE = /\.wasm\?init$/;
@@ -26782,7 +26812,7 @@ function cloudflare(pluginConfig = {}) {
26782
26812
  previewPlugin(ctx),
26783
26813
  shortcutsPlugin(ctx),
26784
26814
  debugPlugin(ctx),
26785
- triggerHandlersPlugin(ctx),
26815
+ cdnCgiPlugin(ctx),
26786
26816
  virtualModulesPlugin(ctx),
26787
26817
  virtualClientFallbackPlugin(ctx),
26788
26818
  outputConfigPlugin(ctx),