@vinext/cloudflare 1.0.0-beta.8 → 1.0.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/README.md +174 -37
- package/dist/cache/cdn-adapter-config.d.ts +2 -1
- package/dist/cache/cdn-adapter-config.js +13 -5
- package/dist/cache/cdn-adapter.d.ts +5 -56
- package/dist/cache/cdn-adapter.js +3 -61
- package/dist/cache/cdn-adapter.runtime.d.ts +1 -0
- package/dist/cache/cdn-adapter.runtime.js +17 -3
- package/dist/cache/cdn-adapter.worker.d.ts +1 -0
- package/dist/cache/cdn-adapter.worker.js +6 -4
- package/dist/cache/cdn-build-id.d.ts +1 -1
- package/dist/cache/cdn-build-id.js +1 -1
- package/dist/cache/config.d.ts +137 -0
- package/dist/cache/config.js +87 -0
- package/dist/cache/kv-data-adapter.d.ts +5 -1
- package/dist/cache/kv-data-adapter.js +6 -2
- package/dist/cache/kv-data-adapter.runtime.js +13 -9
- package/dist/cache/kv-key.d.ts +7 -4
- package/dist/cache/kv-key.js +16 -5
- package/dist/cache/response-store-adapter.d.ts +36 -0
- package/dist/cache/response-store-adapter.js +26 -1
- package/dist/cache/response-store-adapter.self-contained.worker.d.ts +1 -0
- package/dist/cache/response-store-adapter.self-contained.worker.js +3 -1
- package/dist/cache/response-store-adapter.service-binding.worker.d.ts +1 -0
- package/dist/cache/response-store-adapter.service-binding.worker.js +3 -1
- package/dist/cache/response-store-adapter.worker.d.ts +1 -1
- package/dist/cache/response-store-adapter.worker.js +148 -81
- package/dist/cache/response-store-cdn.runtime.js +1 -0
- package/dist/cache/response-store-data.runtime.js +53 -31
- package/dist/cache/static-assets-adapter.build.d.ts +6 -0
- package/dist/cache/static-assets-adapter.build.js +65 -0
- package/dist/cache/static-assets-adapter.d.ts +27 -0
- package/dist/cache/static-assets-adapter.js +26 -0
- package/dist/cache/static-assets-adapter.runtime.d.ts +26 -0
- package/dist/cache/static-assets-adapter.runtime.js +77 -0
- package/dist/cache/static-assets-adapter.shared.d.ts +12 -0
- package/dist/cache/static-assets-adapter.shared.js +4 -0
- package/dist/cache/workers-cache-cdn-adapter.d.ts +58 -0
- package/dist/cache/workers-cache-cdn-adapter.js +65 -0
- package/dist/cacheability-artifact.d.ts +7 -1
- package/dist/cacheability-artifact.js +60 -21
- package/dist/cacheability-probe.d.ts +2 -0
- package/dist/cacheability-probe.js +107 -13
- package/dist/cdn-warm.d.ts +2 -1
- package/dist/cdn-warm.js +25 -8
- package/dist/deploy-config.d.ts +3 -8
- package/dist/deploy-config.js +5 -23
- package/dist/deploy-help.js +58 -47
- package/dist/deploy.d.ts +31 -21
- package/dist/deploy.js +501 -286
- package/dist/tpr.d.ts +29 -72
- package/dist/tpr.js +52 -601
- package/dist/version-deploy.d.ts +27 -0
- package/dist/version-deploy.js +125 -5
- package/dist/wrangler-config.d.ts +19 -0
- package/dist/wrangler-config.js +294 -0
- package/dist/wrangler-version-metadata.js +1 -1
- package/package.json +16 -9
- package/dist/prerender-kv-populate.d.ts +0 -24
- package/dist/prerender-kv-populate.js +0 -153
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { createKvKeySpace } from "./cache/kv-key.js";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { getRenderedAppRoutes, getRenderedMetadataRoutes, readPrerenderManifest } from "vinext/internal/server/prerender-manifest";
|
|
5
|
-
import { appIsrCacheKey } from "vinext/internal/server/isr-cache";
|
|
6
|
-
import { buildAppPageCacheTags, buildAppRouteCacheTags } from "vinext/internal/server/app-page-cache";
|
|
7
|
-
import { normalizePregeneratedPathname } from "vinext/internal/server/pregenerated-concrete-paths";
|
|
8
|
-
import { getAppRouteOutputPath, getOutputPath, getRscOutputPath } from "vinext/internal/utils/prerender-output-paths";
|
|
9
|
-
//#region src/prerender-kv-populate.ts
|
|
10
|
-
/**
|
|
11
|
-
* Deploy-time KV population for App Router prerendered artifacts.
|
|
12
|
-
*
|
|
13
|
-
* Reads `dist/server/vinext-prerender.json` and `dist/server/prerendered-routes/*`,
|
|
14
|
-
* converts rendered App Router HTML/RSC artifacts into the same serialized
|
|
15
|
-
* KVCacheEntry shape written by KVCacheHandler.set(), and returns Wrangler KV
|
|
16
|
-
* bulk import records for deploy-time upload.
|
|
17
|
-
*/
|
|
18
|
-
/** Default KV expiration TTL used by KVCacheHandler for revalidating entries. */
|
|
19
|
-
const DEFAULT_KV_TTL_SECONDS = 2592e3;
|
|
20
|
-
function resolveContainedFile(rootDir, relativePath) {
|
|
21
|
-
const resolvedRoot = path.resolve(rootDir);
|
|
22
|
-
const resolvedFile = path.resolve(resolvedRoot, relativePath);
|
|
23
|
-
const relative = path.relative(resolvedRoot, resolvedFile);
|
|
24
|
-
if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) throw new Error(`[vinext] Refusing to read prerender artifact outside ${resolvedRoot}`);
|
|
25
|
-
return resolvedFile;
|
|
26
|
-
}
|
|
27
|
-
function formatUnknownError(error) {
|
|
28
|
-
if (error instanceof Error && error.message) return error.message;
|
|
29
|
-
return String(error);
|
|
30
|
-
}
|
|
31
|
-
function buildCacheEntry(value, tags, now, revalidateSeconds, expireSeconds, staleSeconds) {
|
|
32
|
-
const cacheControl = revalidateSeconds === void 0 ? void 0 : {
|
|
33
|
-
revalidate: revalidateSeconds,
|
|
34
|
-
...expireSeconds === void 0 ? {} : { expire: expireSeconds },
|
|
35
|
-
...staleSeconds === void 0 ? {} : { stale: staleSeconds }
|
|
36
|
-
};
|
|
37
|
-
return JSON.stringify({
|
|
38
|
-
value,
|
|
39
|
-
tags,
|
|
40
|
-
lastModified: now,
|
|
41
|
-
revalidateAt: revalidateSeconds === void 0 ? null : now + revalidateSeconds * 1e3,
|
|
42
|
-
expireAt: expireSeconds === void 0 ? null : now + expireSeconds * 1e3,
|
|
43
|
-
...cacheControl ? { cacheControl } : {}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function buildMetadata(tags) {
|
|
47
|
-
const metadata = { tags };
|
|
48
|
-
return JSON.stringify(metadata).length <= 1024 ? metadata : void 0;
|
|
49
|
-
}
|
|
50
|
-
function buildPrerenderKVPairs(serverDir, options) {
|
|
51
|
-
const manifestPath = path.join(serverDir, "vinext-prerender.json");
|
|
52
|
-
const manifest = readPrerenderManifest(manifestPath);
|
|
53
|
-
if (!manifest?.buildId || !Array.isArray(manifest.routes)) return {
|
|
54
|
-
routeCount: 0,
|
|
55
|
-
pairs: []
|
|
56
|
-
};
|
|
57
|
-
const prerenderDir = path.join(serverDir, "prerendered-routes");
|
|
58
|
-
if (!fs.existsSync(prerenderDir)) return {
|
|
59
|
-
routeCount: 0,
|
|
60
|
-
pairs: []
|
|
61
|
-
};
|
|
62
|
-
const pairs = [];
|
|
63
|
-
const now = options?.now ?? Date.now();
|
|
64
|
-
const ttlSeconds = options?.ttlSeconds ?? DEFAULT_KV_TTL_SECONDS;
|
|
65
|
-
const trailingSlash = manifest.trailingSlash ?? false;
|
|
66
|
-
const keySpace = createKvKeySpace(options?.appPrefix);
|
|
67
|
-
let routeCount = 0;
|
|
68
|
-
for (const route of getRenderedAppRoutes(manifest.routes)) {
|
|
69
|
-
const artifactPathname = route.path ?? route.route;
|
|
70
|
-
const cachePathname = normalizePregeneratedPathname(artifactPathname);
|
|
71
|
-
let htmlPath;
|
|
72
|
-
let rscPath;
|
|
73
|
-
try {
|
|
74
|
-
htmlPath = resolveContainedFile(prerenderDir, getOutputPath(artifactPathname, trailingSlash));
|
|
75
|
-
rscPath = resolveContainedFile(prerenderDir, getRscOutputPath(artifactPathname));
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.warn(`[vinext] Skipping prerender KV seed for ${artifactPathname}: ${formatUnknownError(error)}`);
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (!fs.existsSync(htmlPath)) continue;
|
|
81
|
-
if (typeof route.revalidate === "number" && route.revalidate <= 0) continue;
|
|
82
|
-
const revalidateSeconds = typeof route.revalidate === "number" ? route.revalidate : void 0;
|
|
83
|
-
const expireSeconds = typeof route.expire === "number" ? route.expire : void 0;
|
|
84
|
-
const staleSeconds = typeof route.stale === "number" && route.stale >= 0 ? route.stale : void 0;
|
|
85
|
-
const expirationTtl = revalidateSeconds === void 0 ? void 0 : ttlSeconds;
|
|
86
|
-
const tags = buildAppPageCacheTags(cachePathname, route.tags ?? []);
|
|
87
|
-
const metadata = buildMetadata(tags);
|
|
88
|
-
const htmlKey = appIsrCacheKey(cachePathname, "html", manifest.buildId);
|
|
89
|
-
const rscKey = appIsrCacheKey(cachePathname, "rsc", manifest.buildId);
|
|
90
|
-
pairs.push({
|
|
91
|
-
key: keySpace.entryKey(htmlKey),
|
|
92
|
-
value: buildCacheEntry({
|
|
93
|
-
kind: "APP_PAGE",
|
|
94
|
-
html: fs.readFileSync(htmlPath, "utf-8"),
|
|
95
|
-
headers: route.headers
|
|
96
|
-
}, tags, now, revalidateSeconds, expireSeconds, staleSeconds),
|
|
97
|
-
...expirationTtl !== void 0 ? { expiration_ttl: expirationTtl } : {},
|
|
98
|
-
...metadata ? { metadata } : {}
|
|
99
|
-
});
|
|
100
|
-
if (fs.existsSync(rscPath)) {
|
|
101
|
-
const rscData = fs.readFileSync(rscPath).toString("base64");
|
|
102
|
-
pairs.push({
|
|
103
|
-
key: keySpace.entryKey(rscKey),
|
|
104
|
-
value: buildCacheEntry({
|
|
105
|
-
kind: "APP_PAGE",
|
|
106
|
-
html: "",
|
|
107
|
-
rscData
|
|
108
|
-
}, tags, now, revalidateSeconds, expireSeconds, staleSeconds),
|
|
109
|
-
...expirationTtl !== void 0 ? { expiration_ttl: expirationTtl } : {},
|
|
110
|
-
...metadata ? { metadata } : {}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
routeCount++;
|
|
114
|
-
}
|
|
115
|
-
for (const route of getRenderedMetadataRoutes(manifest.routes)) {
|
|
116
|
-
const pathname = route.path ?? route.route;
|
|
117
|
-
let artifactPath;
|
|
118
|
-
try {
|
|
119
|
-
artifactPath = resolveContainedFile(prerenderDir, getAppRouteOutputPath(pathname));
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.warn(`[vinext] Skipping metadata prerender KV seed for ${pathname}: ${formatUnknownError(error)}`);
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
if (!fs.existsSync(artifactPath)) continue;
|
|
125
|
-
const cachePathname = normalizePregeneratedPathname(pathname);
|
|
126
|
-
if (typeof route.revalidate === "number" && route.revalidate <= 0) continue;
|
|
127
|
-
const revalidateSeconds = typeof route.revalidate === "number" ? route.revalidate : void 0;
|
|
128
|
-
const expireSeconds = typeof route.expire === "number" ? route.expire : void 0;
|
|
129
|
-
const staleSeconds = typeof route.stale === "number" && route.stale >= 0 ? route.stale : void 0;
|
|
130
|
-
const expirationTtl = revalidateSeconds === void 0 ? void 0 : ttlSeconds;
|
|
131
|
-
const tags = buildAppRouteCacheTags(cachePathname, route.tags ?? [], route.routeSegments ?? []);
|
|
132
|
-
const metadata = buildMetadata(tags);
|
|
133
|
-
const routeKey = appIsrCacheKey(cachePathname, "route", manifest.buildId);
|
|
134
|
-
pairs.push({
|
|
135
|
-
key: keySpace.entryKey(routeKey),
|
|
136
|
-
value: buildCacheEntry({
|
|
137
|
-
kind: "APP_ROUTE",
|
|
138
|
-
body: fs.readFileSync(artifactPath).toString("base64"),
|
|
139
|
-
headers: route.headers ?? {},
|
|
140
|
-
status: route.responseStatus ?? 200
|
|
141
|
-
}, tags, now, revalidateSeconds, expireSeconds, staleSeconds),
|
|
142
|
-
...expirationTtl !== void 0 ? { expiration_ttl: expirationTtl } : {},
|
|
143
|
-
...metadata ? { metadata } : {}
|
|
144
|
-
});
|
|
145
|
-
routeCount++;
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
routeCount,
|
|
149
|
-
pairs
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
//#endregion
|
|
153
|
-
export { buildPrerenderKVPairs };
|