@cloudflare/vite-plugin 1.43.3 → 1.45.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/chunk-DDRU76YD-DhDoQvwV.mjs +64 -0
- package/dist/chunk-DDRU76YD-DhDoQvwV.mjs.map +1 -0
- package/dist/experimental-config.d.mts +4 -1
- package/dist/experimental-config.d.mts.map +1 -1
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +980 -373
- package/dist/index.mjs.map +1 -1
- package/dist/open-BCHIM4MY-d5tZGA6D.mjs +529 -0
- package/dist/open-BCHIM4MY-d5tZGA6D.mjs.map +1 -0
- package/dist/{package-5Lw4BalW.mjs → package-CkGeuVVA.mjs} +4 -2
- package/dist/package-CkGeuVVA.mjs.map +1 -0
- package/dist/workers/asset-worker/index.js +71 -30
- package/package.json +11 -9
- package/dist/package-5Lw4BalW.mjs.map +0 -1
|
@@ -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)
|
|
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))
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
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
|
-
|
|
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)
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
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
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
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
|
-
|
|
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))
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -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({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.45.0",
|
|
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.20260710.1",
|
|
48
49
|
"ws": "8.21.0",
|
|
49
50
|
"@cloudflare/unenv-preset": "2.16.1",
|
|
50
|
-
"miniflare": "4.
|
|
51
|
-
"wrangler": "4.
|
|
51
|
+
"miniflare": "4.20260710.0",
|
|
52
|
+
"wrangler": "4.111.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@cloudflare/workers-types": "^5.
|
|
55
|
+
"@cloudflare/workers-types": "^5.20260710.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",
|
|
74
|
-
"@cloudflare/config": "0.
|
|
75
|
+
"@cloudflare/config": "0.2.0",
|
|
75
76
|
"@cloudflare/containers-shared": "0.16.0",
|
|
76
77
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
77
|
-
"@cloudflare/
|
|
78
|
-
"@cloudflare/workers-
|
|
79
|
-
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
78
|
+
"@cloudflare/runtime-types": "0.0.2",
|
|
79
|
+
"@cloudflare/workers-shared": "0.19.8",
|
|
80
|
+
"@cloudflare/workers-tsconfig": "0.0.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.
|
|
85
|
+
"wrangler": "^4.111.0"
|
|
84
86
|
},
|
|
85
87
|
"workers-sdk": {
|
|
86
88
|
"prerelease": true
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package-5Lw4BalW.mjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@cloudflare/vite-plugin\",\n\t\"version\": \"1.43.3\",\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"}
|