@vinext/cloudflare 0.2.0 → 0.2.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.
- package/dist/cache/kv-data-adapter.runtime.js +8 -1
- package/dist/deploy.js +1 -5
- package/dist/tpr.js +26 -5
- package/package.json +2 -2
|
@@ -48,6 +48,10 @@ function readStringArrayField(ctx, field) {
|
|
|
48
48
|
if (!Array.isArray(value)) return [];
|
|
49
49
|
return value.filter((item) => typeof item === "string");
|
|
50
50
|
}
|
|
51
|
+
function readPositiveNumberField(ctx, field) {
|
|
52
|
+
const value = ctx?.[field];
|
|
53
|
+
return typeof value === "number" && value > 0 ? value : void 0;
|
|
54
|
+
}
|
|
51
55
|
function validUniqueTags(tags) {
|
|
52
56
|
const result = [];
|
|
53
57
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -141,7 +145,10 @@ var KVCacheHandler = class {
|
|
|
141
145
|
this._deleteInBackground(kvKey);
|
|
142
146
|
return null;
|
|
143
147
|
}
|
|
144
|
-
|
|
148
|
+
const now = Date.now();
|
|
149
|
+
const requestedRevalidate = readPositiveNumberField(_ctx, "revalidate");
|
|
150
|
+
const requestedRevalidateAt = requestedRevalidate === void 0 ? null : entry.lastModified + requestedRevalidate * 1e3;
|
|
151
|
+
if (entry.revalidateAt !== null && now > entry.revalidateAt || requestedRevalidateAt !== null && now > requestedRevalidateAt) return {
|
|
145
152
|
lastModified: entry.lastModified,
|
|
146
153
|
value: restoredValue,
|
|
147
154
|
cacheState: "stale",
|
package/dist/deploy.js
CHANGED
|
@@ -214,11 +214,7 @@ async function deploy(options) {
|
|
|
214
214
|
console.log(` Project: ${info.projectName}`);
|
|
215
215
|
console.log(` Router: ${info.isAppRouter ? "App Router" : "Pages Router"}`);
|
|
216
216
|
console.log(` ISR: ${info.hasISR ? "detected" : "none"}`);
|
|
217
|
-
const missingScaffolding = [
|
|
218
|
-
!info.hasViteConfig && "Vite config",
|
|
219
|
-
!info.hasWranglerConfig && "Wrangler config",
|
|
220
|
-
info.isPagesRouter && !info.hasWorkerEntry && "Worker entry"
|
|
221
|
-
].filter((value) => Boolean(value));
|
|
217
|
+
const missingScaffolding = [!info.hasViteConfig && "Vite config", !info.hasWranglerConfig && "Wrangler config"].filter((value) => Boolean(value));
|
|
222
218
|
if (missingScaffolding.length > 0) throw new Error(`Missing Cloudflare deployment setup: ${missingScaffolding.join(", ")}. Run \`vinext init --platform=cloudflare\` first.`);
|
|
223
219
|
const missingDeps = getMissingDeps(info);
|
|
224
220
|
if (missingDeps.length > 0) throw new Error(`Missing deployment dependencies: ${missingDeps.map((dependency) => dependency.name).join(", ")}. Run \`vinext init --platform=cloudflare\` first.`);
|
package/dist/tpr.js
CHANGED
|
@@ -306,6 +306,25 @@ const PRERENDER_PORT = 19384;
|
|
|
306
306
|
const SERVER_STARTUP_TIMEOUT = 3e4;
|
|
307
307
|
/** Max concurrent fetch requests during pre-rendering. */
|
|
308
308
|
const FETCH_CONCURRENCY = 10;
|
|
309
|
+
const NON_CACHEABLE_CACHE_CONTROL_RE = /\b(?:no-store|no-cache|private)\b/i;
|
|
310
|
+
function getTprHeader(headers, name) {
|
|
311
|
+
const normalizedName = name.toLowerCase();
|
|
312
|
+
for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === normalizedName) return value;
|
|
313
|
+
}
|
|
314
|
+
function hasNonCacheableCacheControl(headers) {
|
|
315
|
+
const cacheControl = getTprHeader(headers, "cache-control");
|
|
316
|
+
return cacheControl ? NON_CACHEABLE_CACHE_CONTROL_RE.test(cacheControl) : false;
|
|
317
|
+
}
|
|
318
|
+
function readTprRevalidateHeader(headers) {
|
|
319
|
+
const revalidateHeader = getTprHeader(headers, VINEXT_REVALIDATE_HEADER);
|
|
320
|
+
if (revalidateHeader === void 0) return void 0;
|
|
321
|
+
return Number(revalidateHeader);
|
|
322
|
+
}
|
|
323
|
+
function isTprCacheable(headers) {
|
|
324
|
+
if (hasNonCacheableCacheControl(headers)) return false;
|
|
325
|
+
const revalidate = readTprRevalidateHeader(headers);
|
|
326
|
+
return revalidate === void 0 || Number.isFinite(revalidate) && revalidate > 0;
|
|
327
|
+
}
|
|
309
328
|
/**
|
|
310
329
|
* Start a local production server, fetch each route to produce HTML,
|
|
311
330
|
* and return the results. Pages that fail to render are skipped.
|
|
@@ -333,11 +352,12 @@ async function prerenderRoutes(routes, root, hostDomain) {
|
|
|
333
352
|
redirect: "manual"
|
|
334
353
|
});
|
|
335
354
|
if (response.status < 400) {
|
|
336
|
-
const html = await response.text();
|
|
337
355
|
const headers = {};
|
|
338
356
|
response.headers.forEach((value, key) => {
|
|
339
357
|
if (key === "content-type" || key === "cache-control" || key === VINEXT_REVALIDATE_HEADER || key === "location") headers[key] = value;
|
|
340
358
|
});
|
|
359
|
+
if (!isTprCacheable(headers)) return;
|
|
360
|
+
const html = await response.text();
|
|
341
361
|
results.set(routePath, {
|
|
342
362
|
html,
|
|
343
363
|
status: response.status,
|
|
@@ -427,10 +447,11 @@ function buildTprKVPairs(entries, buildId, defaultRevalidateSeconds) {
|
|
|
427
447
|
const now = Date.now();
|
|
428
448
|
const pairs = [];
|
|
429
449
|
for (const [routePath, result] of entries) {
|
|
430
|
-
|
|
431
|
-
const revalidateSeconds =
|
|
432
|
-
|
|
433
|
-
const
|
|
450
|
+
if (!isTprCacheable(result.headers)) continue;
|
|
451
|
+
const revalidateSeconds = readTprRevalidateHeader(result.headers) ?? defaultRevalidateSeconds;
|
|
452
|
+
if (!Number.isFinite(revalidateSeconds) || revalidateSeconds <= 0) continue;
|
|
453
|
+
const revalidateAt = now + revalidateSeconds * 1e3;
|
|
454
|
+
const kvTtl = MAX_KV_TTL_SECONDS;
|
|
434
455
|
const tags = buildAppPageCacheTags(routePath, []);
|
|
435
456
|
const entry = {
|
|
436
457
|
value: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vinext/cloudflare",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Cloudflare adapters for vinext (KV data cache and Images-backed image optimization).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^25.9.2",
|
|
47
47
|
"vite-plus": "0.2.1",
|
|
48
|
-
"vinext": "0.2.
|
|
48
|
+
"vinext": "0.2.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"vinext": ">=0.0.0"
|