@cloudflare/vite-plugin 1.44.0 → 1.45.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.
@@ -4657,6 +4657,15 @@ let EntrypointType = /* @__PURE__ */ function(EntrypointType$1) {
4657
4657
  EntrypointType$1[EntrypointType$1["Inner"] = 1] = "Inner";
4658
4658
  return EntrypointType$1;
4659
4659
  }({});
4660
+ function getRequestKind(request) {
4661
+ const dest = request.headers.get("Sec-Fetch-Dest");
4662
+ if (dest) return dest === "document" || dest === "iframe" ? "navigation" : "subresource";
4663
+ const { pathname } = new URL(request.url);
4664
+ const lastSegment = pathname.slice(pathname.lastIndexOf("/") + 1);
4665
+ const dotIndex = lastSegment.lastIndexOf(".");
4666
+ if (dotIndex <= 0) return "navigation";
4667
+ return lastSegment.slice(dotIndex + 1).toLowerCase() === "html" ? "navigation" : "subresource";
4668
+ }
4660
4669
  const COMPATIBILITY_FLAG_MASKS = { assets_navigation_prefers_asset_serving: 1 };
4661
4670
  var Analytics = class {
4662
4671
  data = {};
@@ -4702,7 +4711,9 @@ var Analytics = class {
4702
4711
  this.data.version,
4703
4712
  this.data.coloRegion,
4704
4713
  this.data.cacheStatus,
4705
- this.data.cohort
4714
+ this.data.cohort,
4715
+ this.data.servedBy,
4716
+ this.data.requestKind
4706
4717
  ]
4707
4718
  });
4708
4719
  }
@@ -5127,16 +5138,20 @@ function attachCustomHeaders(request, response, configuration, env) {
5127
5138
  //#region ../workers-shared/asset-worker/src/handler.ts
5128
5139
  const REDIRECTS_VERSION = 1;
5129
5140
  const HEADERS_VERSION = 2;
5130
- const getResponseOrAssetIntent = async (request, env, configuration, exists) => {
5141
+ const getResponseOrAssetIntent = async (request, env, configuration, exists, analytics) => {
5131
5142
  const url = new URL(request.url);
5132
5143
  const { search } = url;
5133
5144
  const redirectResult = handleRedirects(env, request, configuration, url.host, url.pathname, search);
5134
- if (redirectResult instanceof Response) return redirectResult;
5145
+ if (redirectResult instanceof Response) {
5146
+ analytics?.setData({ servedBy: "redirect" });
5147
+ return redirectResult;
5148
+ }
5135
5149
  const { proxied, pathname } = redirectResult;
5136
5150
  const decodedPathname = decodePath(pathname);
5137
5151
  const intent = await getIntent(decodedPathname, request, configuration, exists);
5138
5152
  if (!intent) {
5139
5153
  const response = proxied ? new NotFoundResponse() : new NoIntentResponse();
5154
+ analytics?.setData({ servedBy: "none" });
5140
5155
  return env.JAEGER.enterSpan("no_intent", (span) => {
5141
5156
  span.setTags({
5142
5157
  decodedPathname,
@@ -5148,34 +5163,43 @@ const getResponseOrAssetIntent = async (request, env, configuration, exists) =>
5148
5163
  });
5149
5164
  }
5150
5165
  const method = request.method.toUpperCase();
5151
- if (!["GET", "HEAD"].includes(method)) return env.JAEGER.enterSpan("method_not_allowed", (span) => {
5152
- span.setTags({
5153
- method,
5154
- status: MethodNotAllowedResponse.status
5166
+ if (!["GET", "HEAD"].includes(method)) {
5167
+ analytics?.setData({ servedBy: "method-not-allowed" });
5168
+ return env.JAEGER.enterSpan("method_not_allowed", (span) => {
5169
+ span.setTags({
5170
+ method,
5171
+ status: MethodNotAllowedResponse.status
5172
+ });
5173
+ return new MethodNotAllowedResponse();
5155
5174
  });
5156
- return new MethodNotAllowedResponse();
5157
- });
5175
+ }
5158
5176
  const encodedDestination = encodePath(intent.redirect ?? decodedPathname);
5159
5177
  /**
5160
5178
  * The canonical path we serve an asset at is the decoded and re-encoded version.
5161
5179
  * Thus we need to redirect if that is different from the decoded version.
5162
5180
  * We combine this with other redirects (e.g. for html_handling) to avoid multiple redirects.
5163
5181
  */
5164
- if (encodedDestination !== pathname && intent.asset || intent.redirect) return env.JAEGER.enterSpan("redirect", (span) => {
5165
- span.setTags({
5166
- originalPath: pathname,
5167
- location: encodedDestination !== pathname ? encodedDestination : intent.redirect ?? "<unknown>",
5168
- status: TemporaryRedirectResponse.status
5182
+ if (encodedDestination !== pathname && intent.asset || intent.redirect) {
5183
+ analytics?.setData({ servedBy: "redirect" });
5184
+ return env.JAEGER.enterSpan("redirect", (span) => {
5185
+ span.setTags({
5186
+ originalPath: pathname,
5187
+ location: encodedDestination !== pathname ? encodedDestination : intent.redirect ?? "<unknown>",
5188
+ status: TemporaryRedirectResponse.status
5189
+ });
5190
+ return new TemporaryRedirectResponse(encodedDestination + search);
5169
5191
  });
5170
- return new TemporaryRedirectResponse(encodedDestination + search);
5171
- });
5172
- if (!intent.asset) return env.JAEGER.enterSpan("unknown_action", (span) => {
5173
- span.setTags({
5174
- pathname,
5175
- status: InternalServerErrorResponse.status
5192
+ }
5193
+ if (!intent.asset) {
5194
+ analytics?.setData({ servedBy: "error" });
5195
+ return env.JAEGER.enterSpan("unknown_action", (span) => {
5196
+ span.setTags({
5197
+ pathname,
5198
+ status: InternalServerErrorResponse.status
5199
+ });
5200
+ return new InternalServerErrorResponse(/* @__PURE__ */ new Error("Unknown action"));
5176
5201
  });
5177
- return new InternalServerErrorResponse(/* @__PURE__ */ new Error("Unknown action"));
5178
- });
5202
+ }
5179
5203
  return {
5180
5204
  ...intent.asset,
5181
5205
  resolver: intent.resolver
@@ -5197,13 +5221,17 @@ const resolveAssetIntentToResponse = async (assetIntent, request, env, configura
5197
5221
  const strongETag = `"${assetIntent.eTag}"`;
5198
5222
  const weakETag = `W/${strongETag}`;
5199
5223
  const ifNoneMatch = request.headers.get("If-None-Match") || "";
5200
- if ([weakETag, strongETag].includes(ifNoneMatch)) return env.JAEGER.enterSpan("matched_etag", (span) => {
5201
- span.setTags({
5202
- matchedEtag: ifNoneMatch,
5203
- status: NotModifiedResponse.status
5224
+ if ([weakETag, strongETag].includes(ifNoneMatch)) {
5225
+ analytics.setData({ servedBy: "not-modified" });
5226
+ return env.JAEGER.enterSpan("matched_etag", (span) => {
5227
+ span.setTags({
5228
+ matchedEtag: ifNoneMatch,
5229
+ status: NotModifiedResponse.status
5230
+ });
5231
+ return new NotModifiedResponse(null, { headers });
5204
5232
  });
5205
- return new NotModifiedResponse(null, { headers });
5206
- });
5233
+ }
5234
+ analytics.setData({ servedBy: servedByForResolver(assetIntent.resolver, configuration) });
5207
5235
  return env.JAEGER.enterSpan("response", (span) => {
5208
5236
  span.setTags({
5209
5237
  etag: assetIntent.eTag,
@@ -5226,9 +5254,20 @@ const canFetch = async (request, env, configuration, exists) => {
5226
5254
  return true;
5227
5255
  };
5228
5256
  const handleRequest = async (request, env, configuration, exists, getByETag, analytics) => {
5229
- const responseOrAssetIntent = await getResponseOrAssetIntent(request, env, configuration, exists);
5257
+ const responseOrAssetIntent = await getResponseOrAssetIntent(request, env, configuration, exists, analytics);
5230
5258
  return attachCustomHeaders(request, responseOrAssetIntent instanceof Response ? responseOrAssetIntent : await resolveAssetIntentToResponse(responseOrAssetIntent, request, env, configuration, getByETag, analytics), configuration, env);
5231
5259
  };
5260
+ function servedByForResolver(resolver, configuration) {
5261
+ if (resolver === "html-handling") return "asset";
5262
+ switch (configuration.not_found_handling) {
5263
+ case "single-page-application": return "spa";
5264
+ case "404-page": return "404-page";
5265
+ case "none": return "none";
5266
+ default:
5267
+ configuration.not_found_handling;
5268
+ return "error";
5269
+ }
5270
+ }
5232
5271
  const getIntent = async (pathname, request, configuration, exists, skipRedirects = false) => {
5233
5272
  switch (configuration.html_handling) {
5234
5273
  case "auto-trailing-slash": return htmlHandlingAutoTrailingSlash(pathname, request, configuration, exists, skipRedirects);
@@ -5568,6 +5607,7 @@ function handleError(sentry, analytics, err) {
5568
5607
  try {
5569
5608
  const response = new InternalServerErrorResponse(err);
5570
5609
  if (sentry) sentry.captureException(err);
5610
+ analytics.setData({ servedBy: "error" });
5571
5611
  if (err instanceof Error) analytics.setData({ error: err.message });
5572
5612
  return response;
5573
5613
  } catch (e) {
@@ -5586,7 +5626,7 @@ function submitMetrics(analytics, performance, startTimeMs) {
5586
5626
 
5587
5627
  //#endregion
5588
5628
  //#region ../workers-shared/asset-worker/src/utils/kv.ts
5589
- async function getAssetWithMetadataFromKV(assetsKVNamespace, assetKey, sentry, retries = 1) {
5629
+ async function getAssetWithMetadataFromKV(assetsKVNamespace, assetKey, sentry, retries = 3) {
5590
5630
  let attempts = 0;
5591
5631
  while (attempts <= retries) try {
5592
5632
  const asset = await assetsKVNamespace.getWithMetadata(assetKey, {
@@ -5702,7 +5742,8 @@ async function runFetchRequest(request, env, ctx, exists, getByETag, cohort) {
5702
5742
  compatibilityFlags: config.compatibility_flags,
5703
5743
  userAgent,
5704
5744
  entrypoint: EntrypointType.Inner,
5705
- cohort: cohort ?? "unknown"
5745
+ cohort: cohort ?? "unknown",
5746
+ requestKind: getRequestKind(request)
5706
5747
  });
5707
5748
  return await env.JAEGER.enterSpan("handleRequest", async (span) => {
5708
5749
  span.setTags({
@@ -5726,7 +5767,8 @@ var AssetWorkerInner = class extends WorkerEntrypoint {
5726
5767
  this.env.JAEGER ??= mockJaegerBinding();
5727
5768
  const traceContext = this.ctx.props?.traceContext ?? null;
5728
5769
  const cohort = this.ctx.version?.cohort;
5729
- const response = await this.env.JAEGER.runWithSpanContext(traceContext, () => runFetchRequest(request, this.env, this.ctx, this.unstable_exists.bind(this), this.unstable_getByETag.bind(this), cohort));
5770
+ const runRequest = () => runFetchRequest(request, this.env, this.ctx, this.unstable_exists.bind(this), this.unstable_getByETag.bind(this), cohort);
5771
+ const response = traceContext ? await this.env.JAEGER.runWithSpanContext(traceContext, runRequest) : await runRequest();
5730
5772
  if (response instanceof Response) return response;
5731
5773
  throw new Error("AssetWorkerInner fetch returned non-Response value.");
5732
5774
  }
@@ -6241,33 +6241,35 @@ function renderLimitedResponse(req) {
6241
6241
 
6242
6242
  //#endregion
6243
6243
  //#region ../workers-shared/router-worker/src/worker.ts
6244
- var worker_default = { async fetch(request, env, ctx) {
6245
- const loopbackCtx = ctx;
6246
- const analytics = new Analytics(env.ANALYTICS);
6247
- let inner;
6248
- try {
6249
- if (env.COLO_METADATA && env.VERSION_METADATA && env.CONFIG) {
6250
- const url = new URL(request.url);
6251
- analytics.setData({
6252
- accountId: env.CONFIG.account_id,
6253
- scriptId: env.CONFIG.script_id,
6254
- coloId: env.COLO_METADATA.coloId,
6255
- metalId: env.COLO_METADATA.metalId,
6256
- coloTier: env.COLO_METADATA.coloTier,
6257
- coloRegion: env.COLO_METADATA.coloRegion,
6258
- hostname: url.hostname,
6259
- version: env.VERSION_METADATA.tag
6260
- });
6244
+ var RouterOuterEntrypoint = class extends WorkerEntrypoint {
6245
+ async fetch(request) {
6246
+ const loopbackCtx = this.ctx;
6247
+ const analytics = new Analytics(this.env.ANALYTICS);
6248
+ let inner;
6249
+ try {
6250
+ if (this.env.COLO_METADATA && this.env.VERSION_METADATA && this.env.CONFIG) {
6251
+ const url = new URL(request.url);
6252
+ analytics.setData({
6253
+ accountId: this.env.CONFIG.account_id,
6254
+ scriptId: this.env.CONFIG.script_id,
6255
+ coloId: this.env.COLO_METADATA.coloId,
6256
+ metalId: this.env.COLO_METADATA.metalId,
6257
+ coloTier: this.env.COLO_METADATA.coloTier,
6258
+ coloRegion: this.env.COLO_METADATA.coloRegion,
6259
+ hostname: url.hostname,
6260
+ version: this.env.VERSION_METADATA.tag
6261
+ });
6262
+ }
6263
+ inner = loopbackCtx.exports.RouterInnerEntrypoint({ props: {} });
6264
+ } catch (err) {
6265
+ setupSentry(request, this.ctx, this.env.SENTRY_DSN, this.env.SENTRY_ACCESS_CLIENT_ID, this.env.SENTRY_ACCESS_CLIENT_SECRET, this.env.COLO_METADATA, this.env.VERSION_METADATA, this.env.CONFIG?.account_id, this.env.CONFIG?.script_id)?.captureException(err);
6266
+ if (err instanceof Error) analytics.setData({ error: err.message });
6267
+ analytics.write();
6268
+ throw err;
6261
6269
  }
6262
- inner = loopbackCtx.exports.RouterInnerEntrypoint({ props: {} });
6263
- } catch (err) {
6264
- setupSentry(request, ctx, env.SENTRY_DSN, env.SENTRY_ACCESS_CLIENT_ID, env.SENTRY_ACCESS_CLIENT_SECRET, env.COLO_METADATA, env.VERSION_METADATA, env.CONFIG?.account_id, env.CONFIG?.script_id)?.captureException(err);
6265
- if (err instanceof Error) analytics.setData({ error: err.message });
6266
- analytics.write();
6267
- throw err;
6270
+ return inner.fetch(request);
6268
6271
  }
6269
- return inner.fetch(request);
6270
- } };
6272
+ };
6271
6273
  var RouterInnerEntrypoint = class extends WorkerEntrypoint {
6272
6274
  async fetch(request) {
6273
6275
  let sentry;
@@ -6391,6 +6393,7 @@ var RouterInnerEntrypoint = class extends WorkerEntrypoint {
6391
6393
  }
6392
6394
  }
6393
6395
  };
6396
+ var worker_default = RouterInnerEntrypoint;
6394
6397
  /**
6395
6398
  * Check if the Content Type is allowed for the the `_next/image` endpoint.
6396
6399
  *
@@ -6408,4 +6411,4 @@ function shouldBlockContentType(response) {
6408
6411
  }
6409
6412
 
6410
6413
  //#endregion
6411
- export { RouterInnerEntrypoint, worker_default as default };
6414
+ export { RouterInnerEntrypoint, RouterOuterEntrypoint, worker_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "1.44.0",
3
+ "version": "1.45.1",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -45,13 +45,14 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "unenv": "2.0.0-rc.24",
48
+ "workerd": "1.20260714.1",
48
49
  "ws": "8.21.0",
49
50
  "@cloudflare/unenv-preset": "2.16.1",
50
- "miniflare": "4.20260708.1",
51
- "wrangler": "4.110.0"
51
+ "wrangler": "4.112.0",
52
+ "miniflare": "4.20260714.0"
52
53
  },
53
54
  "devDependencies": {
54
- "@cloudflare/workers-types": "^5.20260708.1",
55
+ "@cloudflare/workers-types": "^5.20260714.1",
55
56
  "@remix-run/node-fetch-server": "^0.8.0",
56
57
  "@types/node": "22.15.17",
57
58
  "@types/semver": "^7.5.1",
@@ -71,16 +72,17 @@
71
72
  "vite": "8.0.13",
72
73
  "vite-legacy": "npm:vite@7.1.12",
73
74
  "vitest": "4.1.0",
75
+ "@cloudflare/config": "0.2.1",
74
76
  "@cloudflare/containers-shared": "0.16.0",
77
+ "@cloudflare/runtime-types": "0.0.3",
75
78
  "@cloudflare/mock-npm-registry": "0.0.0",
76
- "@cloudflare/workers-shared": "0.19.7",
77
- "@cloudflare/config": "0.0.0",
79
+ "@cloudflare/workers-shared": "0.19.9",
78
80
  "@cloudflare/workers-tsconfig": "0.0.0",
79
- "@cloudflare/workers-utils": "0.26.0"
81
+ "@cloudflare/workers-utils": "0.27.0"
80
82
  },
81
83
  "peerDependencies": {
82
84
  "vite": "^6.1.0 || ^7.0.0 || ^8.0.0",
83
- "wrangler": "^4.110.0"
85
+ "wrangler": "^4.112.0"
84
86
  },
85
87
  "workers-sdk": {
86
88
  "prerelease": true
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-BmIyCmGP.mjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@cloudflare/vite-plugin\",\n\t\"version\": \"1.44.0\",\n\t\"description\": \"Cloudflare plugin for Vite\",\n\t\"keywords\": [\n\t\t\"cloudflare\",\n\t\t\"cloudflare-workers\",\n\t\t\"vite\",\n\t\t\"vite-plugin\",\n\t\t\"workers\"\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\"license\": \"MIT\",\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\"bin\": {\n\t\t\"cf-vite\": \"./bin/cf-vite\"\n\t},\n\t\"files\": [\n\t\t\"bin\",\n\t\t\"dist\"\n\t],\n\t\"type\": \"module\",\n\t\"sideEffects\": false,\n\t\"main\": \"./dist/index.mjs\",\n\t\"types\": \"./dist/index.d.mts\",\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\t\"./experimental-config\": {\n\t\t\t\"types\": \"./dist/experimental-config.d.mts\",\n\t\t\t\"import\": \"./dist/experimental-config.mjs\"\n\t\t}\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\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/config\": \"workspace:*\",\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:default\",\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\"open\": \"catalog:default\",\n\t\t\"picocolors\": \"^1.1.1\",\n\t\t\"qr\": \"^0.6.0\",\n\t\t\"semver\": \"^7.7.1\",\n\t\t\"tinyglobby\": \"catalog:default\",\n\t\t\"tree-kill\": \"catalog:default\",\n\t\t\"tsdown\": \"0.16.3\",\n\t\t\"typescript\": \"catalog:default\",\n\t\t\"vite\": \"catalog:default\",\n\t\t\"vite-legacy\": \"npm:vite@7.1.12\",\n\t\t\"vitest\": \"catalog:default\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"vite\": \"^6.1.0 || ^7.0.0 || ^8.0.0\",\n\t\t\"wrangler\": \"workspace:^\"\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;UACU;aACG;EACb,QAAQ;EACR,OAAO;EACP,aAAa;EACb;MACM,EACN,WAAW,iBACX;QACQ,CACR,OACA,OACA;OACO;cACO;OACP;QACC;UACE;EACV,KAAK;GACJ,SAAS;GACT,UAAU;GACV;EACD,yBAAyB;GACxB,SAAS;GACT,UAAU;GACV;EACD;gBACgB,EAChB,UAAU,UACV;UACU;EACV,SAAS;EACT,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,sBAAsB;EACtB,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,QAAQ;EACR,cAAc;EACd,MAAM;EACN,UAAU;EACV,cAAc;EACd,aAAa;EACb,UAAU;EACV,cAAc;EACd,QAAQ;EACR,eAAe;EACf,UAAU;EACV;mBACmB;EACnB,QAAQ;EACR,YAAY;EACZ;CACD,eAAe,EACd,cAAc,MACd;CACD"}