@vinext/cloudflare 1.0.0-beta.8 → 1.0.0-beta.9
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 +9 -0
- package/dist/cache/cdn-adapter.worker.d.ts +1 -0
- package/dist/cache/cdn-adapter.worker.js +6 -4
- package/dist/cache/kv-data-adapter.d.ts +4 -0
- package/dist/cache/kv-data-adapter.js +5 -1
- package/dist/cache/response-store-adapter.d.ts +33 -0
- package/dist/cache/response-store-adapter.js +7 -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 +48 -38
- package/dist/cdn-warm.d.ts +1 -1
- package/dist/cdn-warm.js +23 -7
- package/dist/deploy-help.js +20 -14
- package/dist/deploy.d.ts +13 -5
- package/dist/deploy.js +175 -99
- package/dist/tpr.d.ts +25 -72
- package/dist/tpr.js +45 -603
- package/dist/version-deploy.js +4 -2
- package/dist/wrangler-config.d.ts +19 -0
- package/dist/wrangler-config.js +294 -0
- package/package.json +4 -8
package/dist/version-deploy.js
CHANGED
|
@@ -164,7 +164,7 @@ function isMissingWorkerVersionUploadError(error) {
|
|
|
164
164
|
return /cannot upload a new version of a Worker that does not yet exist/i.test(errorText(error));
|
|
165
165
|
}
|
|
166
166
|
function withInitialDeployRequiredMessage() {
|
|
167
|
-
return /* @__PURE__ */ new Error("
|
|
167
|
+
return /* @__PURE__ */ new Error("Version upload needs an existing Cloudflare Worker. Run `vinext-cloudflare deploy` once normally to create the Worker, then rerun the version-based deploy.");
|
|
168
168
|
}
|
|
169
169
|
function parseDeploymentVersions(value) {
|
|
170
170
|
const deployment = Array.isArray(value) ? value.at(-1) : value;
|
|
@@ -200,7 +200,9 @@ function runWranglerVersionUpload(root, options, execute = execFileSync) {
|
|
|
200
200
|
if (env) console.log(`\n Uploading Worker version for env: ${env}...`);
|
|
201
201
|
else console.log("\n Uploading Worker version for production...");
|
|
202
202
|
try {
|
|
203
|
-
|
|
203
|
+
const upload = parseWranglerVersionUploadOutput(runWranglerCommand(root, args, execute, options.verbose === true));
|
|
204
|
+
console.log(` Worker version ID: ${upload.versionId}`);
|
|
205
|
+
return upload;
|
|
204
206
|
} catch (error) {
|
|
205
207
|
if (isMissingWorkerVersionUploadError(error)) throw withInitialDeployRequiredMessage();
|
|
206
208
|
throw error;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/wrangler-config.d.ts
|
|
2
|
+
/** Narrow Wrangler config projection shared by deploy-time features. */
|
|
3
|
+
type WranglerConfig = {
|
|
4
|
+
accountId?: string;
|
|
5
|
+
kvNamespaceId?: string;
|
|
6
|
+
customDomain?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
legacyEnv?: boolean;
|
|
9
|
+
env?: Record<string, WranglerEnvironmentConfig>;
|
|
10
|
+
};
|
|
11
|
+
type WranglerEnvironmentConfig = {
|
|
12
|
+
customDomain?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Parse the Wrangler fields used by TPR and staged CDN warming.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseWranglerConfig(root: string, configPath?: string): WranglerConfig | null;
|
|
19
|
+
//#endregion
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/wrangler-config.ts
|
|
4
|
+
/** Narrow Wrangler config projection shared by deploy-time features. */
|
|
5
|
+
/**
|
|
6
|
+
* Parse the Wrangler fields used by TPR and staged CDN warming.
|
|
7
|
+
*/
|
|
8
|
+
function parseWranglerConfig(root, configPath) {
|
|
9
|
+
if (configPath) {
|
|
10
|
+
const filepath = path.resolve(root, configPath);
|
|
11
|
+
if (!fs.existsSync(filepath)) return null;
|
|
12
|
+
const content = fs.readFileSync(filepath, "utf-8");
|
|
13
|
+
if (filepath.endsWith(".toml")) return extractFromTOML(content);
|
|
14
|
+
try {
|
|
15
|
+
return extractFromJSON(JSON.parse(stripJsonCommentsAndTrailingCommas(content)));
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const filename of ["wrangler.jsonc", "wrangler.json"]) {
|
|
21
|
+
const filepath = path.join(root, filename);
|
|
22
|
+
if (fs.existsSync(filepath)) {
|
|
23
|
+
const content = fs.readFileSync(filepath, "utf-8");
|
|
24
|
+
try {
|
|
25
|
+
return extractFromJSON(JSON.parse(stripJsonCommentsAndTrailingCommas(content)));
|
|
26
|
+
} catch {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const tomlPath = path.join(root, "wrangler.toml");
|
|
32
|
+
if (fs.existsSync(tomlPath)) return extractFromTOML(fs.readFileSync(tomlPath, "utf-8"));
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Strip single-line (//), multi-line comments, and trailing commas from JSONC
|
|
37
|
+
* while preserving strings that contain comment-like text or commas.
|
|
38
|
+
*/
|
|
39
|
+
function stripJsonCommentsAndTrailingCommas(str) {
|
|
40
|
+
let result = "";
|
|
41
|
+
let inString = false;
|
|
42
|
+
let inSingleLine = false;
|
|
43
|
+
let inMultiLine = false;
|
|
44
|
+
let escapeNext = false;
|
|
45
|
+
for (let i = 0; i < str.length; i++) {
|
|
46
|
+
const ch = str[i];
|
|
47
|
+
const next = str[i + 1];
|
|
48
|
+
if (escapeNext) {
|
|
49
|
+
if (!inSingleLine && !inMultiLine) result += ch;
|
|
50
|
+
escapeNext = false;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (ch === "\\" && inString) {
|
|
54
|
+
result += ch;
|
|
55
|
+
escapeNext = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (inSingleLine) {
|
|
59
|
+
if (ch === "\n") {
|
|
60
|
+
inSingleLine = false;
|
|
61
|
+
result += ch;
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (inMultiLine) {
|
|
66
|
+
if (ch === "*" && next === "/") {
|
|
67
|
+
inMultiLine = false;
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (ch === "\"" && !inString) {
|
|
73
|
+
inString = true;
|
|
74
|
+
result += ch;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch === "\"" && inString) {
|
|
78
|
+
inString = false;
|
|
79
|
+
result += ch;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!inString && ch === "/" && next === "/") {
|
|
83
|
+
inSingleLine = true;
|
|
84
|
+
i++;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!inString && ch === "/" && next === "*") {
|
|
88
|
+
inMultiLine = true;
|
|
89
|
+
i++;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!inString && ch === "," && isJsonTrailingComma(str, i + 1)) continue;
|
|
93
|
+
result += ch;
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
function isJsonTrailingComma(str, start) {
|
|
98
|
+
for (let i = start; i < str.length; i++) {
|
|
99
|
+
const ch = str[i];
|
|
100
|
+
const next = str[i + 1];
|
|
101
|
+
if (ch === void 0) return false;
|
|
102
|
+
if (/\s/.test(ch)) continue;
|
|
103
|
+
if (ch === "/" && next === "/") {
|
|
104
|
+
i += 2;
|
|
105
|
+
while (i < str.length && str[i] !== "\n") i++;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (ch === "/" && next === "*") {
|
|
109
|
+
i += 2;
|
|
110
|
+
while (i < str.length) {
|
|
111
|
+
if (str[i] === "*" && str[i + 1] === "/") {
|
|
112
|
+
i++;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
return ch === "}" || ch === "]";
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
function extractFromJSON(config) {
|
|
124
|
+
const result = {};
|
|
125
|
+
if (typeof config.name === "string" && config.name.length > 0) result.name = config.name;
|
|
126
|
+
if (typeof config.legacy_env === "boolean") result.legacyEnv = config.legacy_env;
|
|
127
|
+
if (typeof config.account_id === "string") result.accountId = config.account_id;
|
|
128
|
+
if (Array.isArray(config.kv_namespaces)) {
|
|
129
|
+
const namespace = config.kv_namespaces.find((value) => value && typeof value === "object" && (value.binding === "VINEXT_KV_CACHE" || value.binding === "VINEXT_CACHE"));
|
|
130
|
+
if (namespace && typeof namespace.id === "string" && namespace.id !== "<your-kv-namespace-id>") result.kvNamespaceId = namespace.id;
|
|
131
|
+
}
|
|
132
|
+
const domain = extractDomainFromRoutes(config.routes) ?? extractDomainFromCustomDomains(config);
|
|
133
|
+
if (domain) result.customDomain = domain;
|
|
134
|
+
const env = extractEnvConfigs(config.env);
|
|
135
|
+
if (env) result.env = env;
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
function extractEnvConfigs(envs) {
|
|
139
|
+
if (!envs || typeof envs !== "object" || Array.isArray(envs)) return void 0;
|
|
140
|
+
const result = {};
|
|
141
|
+
for (const [envName, rawConfig] of Object.entries(envs)) {
|
|
142
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) continue;
|
|
143
|
+
const envConfig = extractEnvironmentConfig(rawConfig);
|
|
144
|
+
if (envConfig.name || envConfig.customDomain) result[envName] = envConfig;
|
|
145
|
+
}
|
|
146
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
147
|
+
}
|
|
148
|
+
function extractEnvironmentConfig(config) {
|
|
149
|
+
const result = {};
|
|
150
|
+
if (typeof config.name === "string" && config.name.length > 0) result.name = config.name;
|
|
151
|
+
const domain = extractDomainFromRoutes(config.routes) ?? extractDomainFromCustomDomains(config);
|
|
152
|
+
if (domain) result.customDomain = domain;
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
function extractDomainFromRoutes(routes) {
|
|
156
|
+
if (!Array.isArray(routes)) return null;
|
|
157
|
+
for (const route of routes) if (typeof route === "string") {
|
|
158
|
+
const domain = cleanDomain(route);
|
|
159
|
+
if (domain && !domain.includes("workers.dev")) return domain;
|
|
160
|
+
} else if (route && typeof route === "object") {
|
|
161
|
+
const r = route;
|
|
162
|
+
const pattern = typeof r.zone_name === "string" ? r.zone_name : typeof r.pattern === "string" ? r.pattern : null;
|
|
163
|
+
if (pattern) {
|
|
164
|
+
const domain = cleanDomain(pattern);
|
|
165
|
+
if (domain && !domain.includes("workers.dev")) return domain;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function extractDomainFromCustomDomains(config) {
|
|
171
|
+
if (Array.isArray(config.custom_domains)) {
|
|
172
|
+
for (const d of config.custom_domains) if (typeof d === "string" && !d.includes("workers.dev")) return cleanDomain(d);
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
/** Strip protocol and trailing wildcards from a route pattern to get a bare domain. */
|
|
177
|
+
function cleanDomain(raw) {
|
|
178
|
+
return raw.replace(/^https?:\/\//, "").replace(/\/\*$/, "").replace(/\/+$/, "").split("/")[0] || null;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Simple extraction of specific fields from wrangler.toml content.
|
|
182
|
+
* Not a full TOML parser — just enough for the fields we need.
|
|
183
|
+
*/
|
|
184
|
+
function extractFromTOML(content) {
|
|
185
|
+
const result = {};
|
|
186
|
+
const nameMatch = content.match(/^name\s*=\s*"([^"]+)"/m);
|
|
187
|
+
if (nameMatch) result.name = nameMatch[1];
|
|
188
|
+
const legacyEnvMatch = content.match(/^legacy_env\s*=\s*(true|false)\s*$/m);
|
|
189
|
+
if (legacyEnvMatch) result.legacyEnv = legacyEnvMatch[1] === "true";
|
|
190
|
+
const accountMatch = content.match(/^account_id\s*=\s*"([^"]+)"/m);
|
|
191
|
+
if (accountMatch) result.accountId = accountMatch[1];
|
|
192
|
+
for (const block of content.split(/\[\[kv_namespaces\]\]/).slice(1)) {
|
|
193
|
+
const section = block.split(/\[\[/)[0];
|
|
194
|
+
const binding = section.match(/binding\s*=\s*"([^"]+)"/)?.[1];
|
|
195
|
+
const id = section.match(/\bid\s*=\s*"([^"]+)"/)?.[1];
|
|
196
|
+
if ((binding === "VINEXT_KV_CACHE" || binding === "VINEXT_CACHE") && id && id !== "<your-kv-namespace-id>") result.kvNamespaceId = id;
|
|
197
|
+
}
|
|
198
|
+
const routeMatch = content.match(/^route\s*=\s*"([^"]+)"/m);
|
|
199
|
+
if (routeMatch) {
|
|
200
|
+
const domain = cleanDomain(routeMatch[1]);
|
|
201
|
+
if (domain && !domain.includes("workers.dev")) result.customDomain = domain;
|
|
202
|
+
}
|
|
203
|
+
if (!result.customDomain) {
|
|
204
|
+
const routeBlocks = content.split(/\[\[routes\]\]/);
|
|
205
|
+
for (let i = 1; i < routeBlocks.length; i++) {
|
|
206
|
+
const patternMatch = routeBlocks[i].split(/\[\[/)[0].match(/pattern\s*=\s*"([^"]+)"/);
|
|
207
|
+
if (patternMatch) {
|
|
208
|
+
const domain = cleanDomain(patternMatch[1]);
|
|
209
|
+
if (domain && !domain.includes("workers.dev")) {
|
|
210
|
+
result.customDomain = domain;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const env = extractEnvConfigsFromTOML(content);
|
|
217
|
+
if (env) result.env = env;
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
function extractEnvConfigsFromTOML(content) {
|
|
221
|
+
const result = {};
|
|
222
|
+
for (const section of getTomlSections(content)) {
|
|
223
|
+
const envName = section.header.match(/^env\.([^.]+)$/)?.[1];
|
|
224
|
+
if (envName) {
|
|
225
|
+
const envConfig = result[envName] ?? {};
|
|
226
|
+
const nameMatch = section.body.match(/^name\s*=\s*"([^"]+)"/m);
|
|
227
|
+
if (nameMatch) envConfig.name = nameMatch[1];
|
|
228
|
+
const domain = extractTomlScalarRouteDomain(section.body) ?? extractTomlRoutesArrayDomain(section.body);
|
|
229
|
+
if (domain) envConfig.customDomain = domain;
|
|
230
|
+
if (envConfig.name || envConfig.customDomain) result[envName] = envConfig;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const routesEnvName = section.header.match(/^env\.([^.]+)\.routes$/)?.[1];
|
|
234
|
+
if (routesEnvName) {
|
|
235
|
+
const envConfig = result[routesEnvName] ?? {};
|
|
236
|
+
const domain = extractTomlRouteBlockDomain(section.body);
|
|
237
|
+
if (domain) envConfig.customDomain = domain;
|
|
238
|
+
if (envConfig.name || envConfig.customDomain) result[routesEnvName] = envConfig;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
242
|
+
}
|
|
243
|
+
function getTomlSections(content) {
|
|
244
|
+
const sections = [];
|
|
245
|
+
let currentHeader = null;
|
|
246
|
+
let currentBody = [];
|
|
247
|
+
for (const line of content.split("\n")) {
|
|
248
|
+
const header = parseTomlSectionHeader(line);
|
|
249
|
+
if (header) {
|
|
250
|
+
if (currentHeader) sections.push({
|
|
251
|
+
header: currentHeader,
|
|
252
|
+
body: currentBody.join("\n")
|
|
253
|
+
});
|
|
254
|
+
currentHeader = header;
|
|
255
|
+
currentBody = [];
|
|
256
|
+
} else if (currentHeader) currentBody.push(line);
|
|
257
|
+
}
|
|
258
|
+
if (currentHeader) sections.push({
|
|
259
|
+
header: currentHeader,
|
|
260
|
+
body: currentBody.join("\n")
|
|
261
|
+
});
|
|
262
|
+
return sections;
|
|
263
|
+
}
|
|
264
|
+
function parseTomlSectionHeader(line) {
|
|
265
|
+
const trimmed = line.trim();
|
|
266
|
+
if (!trimmed.startsWith("[") || !trimmed.endsWith("]")) return null;
|
|
267
|
+
const isArrayHeader = trimmed.startsWith("[[") && trimmed.endsWith("]]");
|
|
268
|
+
const start = isArrayHeader ? 2 : 1;
|
|
269
|
+
const end = isArrayHeader ? trimmed.length - 2 : trimmed.length - 1;
|
|
270
|
+
const header = trimmed.slice(start, end).trim();
|
|
271
|
+
return header.length > 0 ? header : null;
|
|
272
|
+
}
|
|
273
|
+
function extractTomlScalarRouteDomain(section) {
|
|
274
|
+
const routeMatch = section.match(/^route\s*=\s*"([^"]+)"/m);
|
|
275
|
+
if (!routeMatch) return null;
|
|
276
|
+
const domain = cleanDomain(routeMatch[1]);
|
|
277
|
+
return domain && !domain.includes("workers.dev") ? domain : null;
|
|
278
|
+
}
|
|
279
|
+
function extractTomlRoutesArrayDomain(section) {
|
|
280
|
+
const routesMatch = section.match(/^routes\s*=\s*\[([\s\S]*?)\]/m);
|
|
281
|
+
if (!routesMatch) return null;
|
|
282
|
+
const patternMatch = (routesMatch[1] ?? "").match(/(?:pattern\s*=\s*)?"([^"]+)"/);
|
|
283
|
+
if (!patternMatch) return null;
|
|
284
|
+
const domain = cleanDomain(patternMatch[1]);
|
|
285
|
+
return domain && !domain.includes("workers.dev") ? domain : null;
|
|
286
|
+
}
|
|
287
|
+
function extractTomlRouteBlockDomain(section) {
|
|
288
|
+
const patternMatch = section.match(/^pattern\s*=\s*"([^"]+)"/m) ?? section.match(/^zone_name\s*=\s*"([^"]+)"/m);
|
|
289
|
+
if (!patternMatch) return null;
|
|
290
|
+
const domain = cleanDomain(patternMatch[1]);
|
|
291
|
+
return domain && !domain.includes("workers.dev") ? domain : null;
|
|
292
|
+
}
|
|
293
|
+
//#endregion
|
|
294
|
+
export { parseWranglerConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vinext/cloudflare",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "Cloudflare cache and image adapters for vinext.",
|
|
5
5
|
"homepage": "https://vinext.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,10 +30,6 @@
|
|
|
30
30
|
"types": "./dist/deploy-config.d.ts",
|
|
31
31
|
"import": "./dist/deploy-config.js"
|
|
32
32
|
},
|
|
33
|
-
"./internal/tpr": {
|
|
34
|
-
"types": "./dist/tpr.d.ts",
|
|
35
|
-
"import": "./dist/tpr.js"
|
|
36
|
-
},
|
|
37
33
|
"./internal/cdn-warm": {
|
|
38
34
|
"types": "./dist/cdn-warm.d.ts",
|
|
39
35
|
"import": "./dist/cdn-warm.js"
|
|
@@ -52,7 +48,7 @@
|
|
|
52
48
|
}
|
|
53
49
|
},
|
|
54
50
|
"dependencies": {
|
|
55
|
-
"@cloudflare/workers-response-store": "0.1.0-beta.
|
|
51
|
+
"@cloudflare/workers-response-store": "0.1.0-beta.1"
|
|
56
52
|
},
|
|
57
53
|
"devDependencies": {
|
|
58
54
|
"@types/node": "^25.9.2",
|
|
@@ -60,10 +56,10 @@
|
|
|
60
56
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.2",
|
|
61
57
|
"vite-plus": "0.3.2",
|
|
62
58
|
"vitest": "4.1.11",
|
|
63
|
-
"vinext": "1.0.0-beta.
|
|
59
|
+
"vinext": "1.0.0-beta.11"
|
|
64
60
|
},
|
|
65
61
|
"peerDependencies": {
|
|
66
|
-
"vinext": "^1.0.0-beta.
|
|
62
|
+
"vinext": "^1.0.0-beta.11"
|
|
67
63
|
},
|
|
68
64
|
"engines": {
|
|
69
65
|
"node": ">=22"
|