@vinext/cloudflare 1.0.0-beta.1 → 1.0.0-beta.11
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 +193 -1
- package/dist/cache/cdn-adapter-config.d.ts +31 -0
- package/dist/cache/cdn-adapter-config.js +95 -0
- package/dist/cache/cdn-adapter.d.ts +48 -15
- package/dist/cache/cdn-adapter.js +50 -13
- package/dist/cache/cdn-adapter.runtime.d.ts +26 -4
- package/dist/cache/cdn-adapter.runtime.js +150 -37
- package/dist/cache/cdn-adapter.worker.d.ts +31 -0
- package/dist/cache/cdn-adapter.worker.js +373 -0
- package/dist/cache/cdn-build-id.d.ts +6 -0
- package/dist/cache/cdn-build-id.js +9 -0
- package/dist/cache/config.d.ts +137 -0
- package/dist/cache/config.js +87 -0
- package/dist/cache/kv-data-adapter.d.ts +32 -8
- package/dist/cache/kv-data-adapter.js +5 -1
- package/dist/cache/kv-data-adapter.runtime.d.ts +45 -13
- package/dist/cache/kv-data-adapter.runtime.js +132 -52
- package/dist/cache/kv-key.d.ts +15 -0
- package/dist/cache/kv-key.js +43 -0
- package/dist/cache/response-store-adapter.d.ts +73 -0
- package/dist/cache/response-store-adapter.js +64 -0
- package/dist/cache/response-store-adapter.self-contained.worker.d.ts +18 -0
- package/dist/cache/response-store-adapter.self-contained.worker.js +12 -0
- package/dist/cache/response-store-adapter.service-binding.worker.d.ts +16 -0
- package/dist/cache/response-store-adapter.service-binding.worker.js +11 -0
- package/dist/cache/response-store-adapter.worker.d.ts +14 -0
- package/dist/cache/response-store-adapter.worker.js +278 -0
- package/dist/cache/response-store-cdn.runtime.d.ts +5 -0
- package/dist/cache/response-store-cdn.runtime.js +41 -0
- package/dist/cache/response-store-data.runtime.d.ts +34 -0
- package/dist/cache/response-store-data.runtime.js +300 -0
- package/dist/cacheability-artifact.d.ts +10 -0
- package/dist/cacheability-artifact.js +215 -0
- package/dist/cacheability-manifest-limits.d.ts +4 -0
- package/dist/cacheability-manifest-limits.js +7 -0
- package/dist/cacheability-probe.d.ts +49 -0
- package/dist/cacheability-probe.js +660 -0
- package/dist/cdn-warm.d.ts +110 -12
- package/dist/cdn-warm.js +880 -82
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +15 -1
- package/dist/deploy-config.d.ts +14 -11
- package/dist/deploy-config.js +24 -5
- package/dist/deploy-help.d.ts +3 -4
- package/dist/deploy-help.js +65 -22
- package/dist/deploy.d.ts +139 -42
- package/dist/deploy.js +946 -132
- package/dist/images/images-optimizer.d.ts +5 -5
- package/dist/images/images-optimizer.runtime.d.ts +1 -5
- package/dist/prerender-kv-populate.d.ts +3 -4
- package/dist/prerender-kv-populate.js +51 -18
- package/dist/tpr.d.ts +34 -70
- package/dist/tpr.js +50 -603
- package/dist/utils/cache-control-metadata.d.ts +3 -4
- package/dist/version-deploy.d.ts +46 -17
- package/dist/version-deploy.js +151 -14
- package/dist/version-headers.d.ts +2 -0
- package/dist/version-headers.js +2 -0
- package/dist/worker-deployment-url.d.ts +9 -0
- package/dist/worker-deployment-url.js +45 -0
- package/dist/workers-dev-url.d.ts +2 -3
- package/dist/wrangler-config.d.ts +19 -0
- package/dist/wrangler-config.js +294 -0
- package/dist/wrangler-version-metadata.d.ts +7 -0
- package/dist/wrangler-version-metadata.js +9 -0
- package/package.json +21 -11
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* so the Cloudflare adapters stay self-contained (these mirror the equivalent
|
|
6
6
|
* helpers in the vinext core).
|
|
7
7
|
*/
|
|
8
|
-
declare function isUnknownRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
-
declare function readCacheControlNumberField(ctx: Record<string, unknown> | undefined, field: string): number | undefined;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { isUnknownRecord, readCacheControlNumberField };
|
|
8
|
+
export declare function isUnknownRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
+
export declare function readCacheControlNumberField(ctx: Record<string, unknown> | undefined, field: string): number | undefined;
|
|
10
|
+
//#endregion
|
package/dist/version-deploy.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { parseWorkersDevUrl } from "./workers-dev-url.js";
|
|
2
2
|
import { DeployOptions } from "./deploy.js";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
|
-
|
|
5
4
|
//#region src/version-deploy.d.ts
|
|
6
|
-
type WranglerVersionUploadResult = {
|
|
5
|
+
export type WranglerVersionUploadResult = {
|
|
7
6
|
versionId: string;
|
|
8
7
|
previewUrl: string | null;
|
|
8
|
+
workerName: string | null;
|
|
9
9
|
output: string;
|
|
10
10
|
};
|
|
11
|
-
type WranglerVersionDeployResult = {
|
|
11
|
+
export type WranglerVersionDeployResult = {
|
|
12
12
|
deployedUrl: string | null;
|
|
13
13
|
output: string;
|
|
14
14
|
};
|
|
15
|
-
type WranglerVersionTraffic = {
|
|
15
|
+
export type WranglerVersionTraffic = {
|
|
16
16
|
versionId: string;
|
|
17
17
|
percentage: number;
|
|
18
18
|
};
|
|
19
|
-
type WranglerDeploymentStatus = {
|
|
19
|
+
export type WranglerDeploymentStatus = {
|
|
20
|
+
deploymentId: string | null;
|
|
20
21
|
versions: WranglerVersionTraffic[];
|
|
21
22
|
output: string;
|
|
22
23
|
};
|
|
@@ -24,20 +25,48 @@ type WranglerVersionArgs = {
|
|
|
24
25
|
args: string[];
|
|
25
26
|
env: string | undefined;
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
type CfVersionArgs = {
|
|
29
|
+
args: string[];
|
|
30
|
+
mode: string | undefined;
|
|
31
|
+
};
|
|
32
|
+
export declare function readBuildOutputWorkerName(root: string): string;
|
|
33
|
+
export declare function parseVersionId(output: string): string | null;
|
|
34
|
+
export declare function parseUploadedWorkerName(output: string): string | null;
|
|
35
|
+
export declare function parseWranglerVersionUploadOutput(output: string): WranglerVersionUploadResult;
|
|
36
|
+
export declare function buildWranglerVersionUploadArgs(options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose"> & {
|
|
30
37
|
previewAlias?: string;
|
|
31
38
|
}): WranglerVersionArgs;
|
|
32
|
-
declare function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
declare function
|
|
36
|
-
declare function
|
|
39
|
+
export declare function buildCfVersionUploadArgs(options: Pick<DeployOptions, "preview" | "env"> & {
|
|
40
|
+
previewAlias?: string;
|
|
41
|
+
}): CfVersionArgs;
|
|
42
|
+
export declare function buildWranglerVersionDeployArgs(versionTraffic: readonly WranglerVersionTraffic[], options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose">): WranglerVersionArgs;
|
|
43
|
+
export declare function buildWranglerDeploymentsStatusArgs(options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose">): WranglerVersionArgs;
|
|
44
|
+
export declare function buildWranglerTriggersDeployArgs(options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose">): WranglerVersionArgs;
|
|
45
|
+
export declare function parseWranglerDeploymentStatusOutput(output: string): WranglerDeploymentStatus;
|
|
46
|
+
/** The first entry is the deployment currently serving traffic. */
|
|
47
|
+
export declare function parseCfDeploymentStatusOutput(output: string): WranglerDeploymentStatus;
|
|
48
|
+
export declare function runCfDeploymentStatus(root: string, options: {
|
|
49
|
+
name: string;
|
|
50
|
+
env?: string;
|
|
51
|
+
verbose?: boolean;
|
|
52
|
+
}, execute?: typeof execFileSync): WranglerDeploymentStatus;
|
|
53
|
+
export declare function runCfVersionDeploy(root: string, versionTraffic: readonly WranglerVersionTraffic[], options: {
|
|
54
|
+
name: string;
|
|
55
|
+
env?: string;
|
|
56
|
+
verbose?: boolean;
|
|
57
|
+
}, _phase?: "stage" | "promote-warmed" | "promote-uploaded", execute?: typeof execFileSync): WranglerVersionDeployResult;
|
|
58
|
+
export declare function runCfTriggersDeploy(root: string, options: {
|
|
59
|
+
env?: string;
|
|
60
|
+
verbose?: boolean;
|
|
61
|
+
}, execute?: typeof execFileSync): WranglerVersionDeployResult;
|
|
62
|
+
export declare function runWranglerVersionUpload(root: string, options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose"> & {
|
|
63
|
+
previewAlias?: string;
|
|
64
|
+
}, execute?: typeof execFileSync): WranglerVersionUploadResult;
|
|
65
|
+
export declare function runCfVersionUpload(root: string, options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose"> & {
|
|
37
66
|
previewAlias?: string;
|
|
38
67
|
}, execute?: typeof execFileSync): WranglerVersionUploadResult;
|
|
39
|
-
declare function runWranglerVersionDeploy(root: string, versionTraffic: readonly WranglerVersionTraffic[], options: Pick<DeployOptions, "preview" | "env" | "name" | "config">, phase?: "stage" | "promote-warmed" | "promote-uploaded", execute?: typeof execFileSync): WranglerVersionDeployResult;
|
|
40
|
-
declare function runWranglerDeploymentStatus(root: string, options: Pick<DeployOptions, "preview" | "env" | "name" | "config">, execute?: typeof execFileSync): WranglerDeploymentStatus;
|
|
41
|
-
declare function runWranglerTriggersDeploy(root: string, options: Pick<DeployOptions, "preview" | "env" | "name" | "config">, execute?: typeof execFileSync): WranglerVersionDeployResult;
|
|
68
|
+
export declare function runWranglerVersionDeploy(root: string, versionTraffic: readonly WranglerVersionTraffic[], options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose">, phase?: "stage" | "promote-warmed" | "promote-uploaded", execute?: typeof execFileSync): WranglerVersionDeployResult;
|
|
69
|
+
export declare function runWranglerDeploymentStatus(root: string, options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose">, execute?: typeof execFileSync): WranglerDeploymentStatus;
|
|
70
|
+
export declare function runWranglerTriggersDeploy(root: string, options: Pick<DeployOptions, "preview" | "env" | "name" | "config" | "verbose">, execute?: typeof execFileSync): WranglerVersionDeployResult;
|
|
42
71
|
//#endregion
|
|
43
|
-
export {
|
|
72
|
+
export { parseWorkersDevUrl };
|
package/dist/version-deploy.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { parseWorkersDevUrl } from "./workers-dev-url.js";
|
|
2
|
-
import {
|
|
2
|
+
import { parseCdnWarmupDeploymentUrl } from "./worker-deployment-url.js";
|
|
3
|
+
import { buildNodeCliInvocation, resolveCfBin, resolveWranglerBin, validateWranglerEnvName } from "./deploy.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
3
6
|
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
8
|
//#region src/version-deploy.ts
|
|
5
9
|
function isRecord(value) {
|
|
6
10
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
11
|
}
|
|
12
|
+
function readBuildOutputWorkerName(root) {
|
|
13
|
+
const configPath = path.join(root, ".cloudflare", "output", "v0", "workers", "default", "worker.config.json");
|
|
14
|
+
let config;
|
|
15
|
+
try {
|
|
16
|
+
config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
17
|
+
} catch (cause) {
|
|
18
|
+
throw new Error("Could not read the generated Cloudflare Build Output config. Rebuild the app before deploying.", { cause });
|
|
19
|
+
}
|
|
20
|
+
const name = isRecord(config) ? config.name : void 0;
|
|
21
|
+
if (typeof name !== "string" || name.length === 0) throw new Error("The generated Cloudflare Build Output config does not declare a Worker name.");
|
|
22
|
+
return name;
|
|
23
|
+
}
|
|
8
24
|
function parseJsonObject(output) {
|
|
9
25
|
const trimmed = output.trim();
|
|
10
26
|
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return null;
|
|
@@ -56,16 +72,24 @@ function findPreviewUrlInUploadJson(parsed) {
|
|
|
56
72
|
]);
|
|
57
73
|
}
|
|
58
74
|
function parseVersionId(output) {
|
|
59
|
-
|
|
75
|
+
const versionIdPattern = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
|
|
76
|
+
const labeledVersionId = output.match(new RegExp(`Worker\\s+Version\\s+ID\\s*:\\s*(${versionIdPattern})\\b`, "i"))?.[1];
|
|
77
|
+
if (labeledVersionId) return labeledVersionId;
|
|
78
|
+
return output.match(new RegExp(`\\b${versionIdPattern}\\b`))?.[0] ?? null;
|
|
79
|
+
}
|
|
80
|
+
function parseUploadedWorkerName(output) {
|
|
81
|
+
return stripVTControlCharacters(output).match(/^\s*(?:[│|]\s*)?Uploaded\s+(\S+)\s+\(\d+(?:\.\d+)?\s+sec\)\s*$/im)?.[1] ?? null;
|
|
60
82
|
}
|
|
61
83
|
function parseWranglerVersionUploadOutput(output) {
|
|
62
84
|
const parsed = parseJsonObject(output);
|
|
63
85
|
const versionId = findVersionIdInUploadJson(parsed) ?? parseVersionId(output);
|
|
64
86
|
const previewUrl = findPreviewUrlInUploadJson(parsed) ?? parseWorkersDevUrl(output);
|
|
87
|
+
const workerName = parseUploadedWorkerName(output);
|
|
65
88
|
if (!versionId) throw new Error("Could not detect Worker version ID from `wrangler versions upload` output.");
|
|
66
89
|
return {
|
|
67
90
|
versionId,
|
|
68
91
|
previewUrl,
|
|
92
|
+
workerName,
|
|
69
93
|
output
|
|
70
94
|
};
|
|
71
95
|
}
|
|
@@ -81,6 +105,21 @@ function buildWranglerVersionUploadArgs(options) {
|
|
|
81
105
|
env
|
|
82
106
|
};
|
|
83
107
|
}
|
|
108
|
+
function buildCfVersionUploadArgs(options) {
|
|
109
|
+
const mode = options.env || (options.preview ? "preview" : void 0);
|
|
110
|
+
const args = [
|
|
111
|
+
"workers",
|
|
112
|
+
"versions",
|
|
113
|
+
"create",
|
|
114
|
+
"--prebuilt"
|
|
115
|
+
];
|
|
116
|
+
if (mode) args.push("--mode", validateWranglerEnvName(mode));
|
|
117
|
+
if (options.previewAlias) args.push("--preview-alias", options.previewAlias);
|
|
118
|
+
return {
|
|
119
|
+
args,
|
|
120
|
+
mode
|
|
121
|
+
};
|
|
122
|
+
}
|
|
84
123
|
function buildWranglerVersionDeployArgs(versionTraffic, options) {
|
|
85
124
|
const args = [
|
|
86
125
|
"versions",
|
|
@@ -123,8 +162,9 @@ function buildWranglerTriggersDeployArgs(options) {
|
|
|
123
162
|
env
|
|
124
163
|
};
|
|
125
164
|
}
|
|
126
|
-
function runWranglerCommand(root, args, execute = execFileSync) {
|
|
127
|
-
const
|
|
165
|
+
function runWranglerCommand(root, args, execute = execFileSync, verbose = false) {
|
|
166
|
+
const wranglerBin = resolveWranglerBin(root);
|
|
167
|
+
const invocation = buildNodeCliInvocation(wranglerBin, args);
|
|
128
168
|
const execOpts = {
|
|
129
169
|
cwd: root,
|
|
130
170
|
stdio: "pipe",
|
|
@@ -132,7 +172,18 @@ function runWranglerCommand(root, args, execute = execFileSync) {
|
|
|
132
172
|
shell: false
|
|
133
173
|
};
|
|
134
174
|
const output = execute(invocation.file, invocation.args, execOpts);
|
|
135
|
-
if (output.trim()) for (const line of output.trim().split("\n")) console.log(` ${line}`);
|
|
175
|
+
if (verbose && output.trim()) for (const line of output.trim().split("\n")) console.log(` ${line}`);
|
|
176
|
+
return output;
|
|
177
|
+
}
|
|
178
|
+
function runCfCommand(root, args, execute = execFileSync, verbose = false) {
|
|
179
|
+
const invocation = buildNodeCliInvocation(resolveCfBin(root), args);
|
|
180
|
+
const output = execute(invocation.file, invocation.args, {
|
|
181
|
+
cwd: root,
|
|
182
|
+
stdio: "pipe",
|
|
183
|
+
encoding: "utf-8",
|
|
184
|
+
shell: false
|
|
185
|
+
});
|
|
186
|
+
if (verbose && output.trim()) for (const line of output.trim().split("\n")) console.log(` ${line}`);
|
|
136
187
|
return output;
|
|
137
188
|
}
|
|
138
189
|
function errorText(error) {
|
|
@@ -154,7 +205,7 @@ function isMissingWorkerVersionUploadError(error) {
|
|
|
154
205
|
return /cannot upload a new version of a Worker that does not yet exist/i.test(errorText(error));
|
|
155
206
|
}
|
|
156
207
|
function withInitialDeployRequiredMessage() {
|
|
157
|
-
return /* @__PURE__ */ new Error("
|
|
208
|
+
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.");
|
|
158
209
|
}
|
|
159
210
|
function parseDeploymentVersions(value) {
|
|
160
211
|
const deployment = Array.isArray(value) ? value.at(-1) : value;
|
|
@@ -176,16 +227,100 @@ function parseWranglerDeploymentStatusOutput(output) {
|
|
|
176
227
|
const parsed = parseJsonObject(output);
|
|
177
228
|
if (!parsed) throw new Error("Could not parse `wrangler deployments status --json` output.");
|
|
178
229
|
return {
|
|
230
|
+
deploymentId: findStringInRecord(Array.isArray(parsed) ? parsed.at(-1) : parsed, [
|
|
231
|
+
"id",
|
|
232
|
+
"deployment_id",
|
|
233
|
+
"deploymentId"
|
|
234
|
+
]),
|
|
179
235
|
versions: parseDeploymentVersions(parsed),
|
|
180
236
|
output
|
|
181
237
|
};
|
|
182
238
|
}
|
|
239
|
+
/** The first entry is the deployment currently serving traffic. */
|
|
240
|
+
function parseCfDeploymentStatusOutput(output) {
|
|
241
|
+
const parsed = parseJsonObject(output);
|
|
242
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.deployments) || !parsed.deployments.length) throw new Error("Could not parse the active deployment from `cf workers deployments list` output.");
|
|
243
|
+
const current = parsed.deployments[0];
|
|
244
|
+
const deploymentId = findStringInRecord(current, [
|
|
245
|
+
"id",
|
|
246
|
+
"deployment_id",
|
|
247
|
+
"deploymentId"
|
|
248
|
+
]);
|
|
249
|
+
const versions = parseDeploymentVersions(current);
|
|
250
|
+
if (!deploymentId || !versions.length) throw new Error("The active `cf workers deployments list` entry is missing its ID or versions.");
|
|
251
|
+
return {
|
|
252
|
+
deploymentId,
|
|
253
|
+
versions,
|
|
254
|
+
output
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function runCfDeploymentStatus(root, options, execute = execFileSync) {
|
|
258
|
+
return parseCfDeploymentStatusOutput(runCfCommand(root, [
|
|
259
|
+
"workers",
|
|
260
|
+
"deployments",
|
|
261
|
+
"list",
|
|
262
|
+
"--worker",
|
|
263
|
+
options.name,
|
|
264
|
+
...options.env ? ["--mode", validateWranglerEnvName(options.env)] : []
|
|
265
|
+
], execute, options.verbose));
|
|
266
|
+
}
|
|
267
|
+
function runCfVersionDeploy(root, versionTraffic, options, _phase = "promote-uploaded", execute = execFileSync) {
|
|
268
|
+
const versions = versionTraffic.map(({ versionId, percentage }) => ({
|
|
269
|
+
version_id: versionId,
|
|
270
|
+
percentage
|
|
271
|
+
}));
|
|
272
|
+
const output = runCfCommand(root, [
|
|
273
|
+
"workers",
|
|
274
|
+
"deployments",
|
|
275
|
+
"create",
|
|
276
|
+
"--worker",
|
|
277
|
+
options.name,
|
|
278
|
+
"--strategy",
|
|
279
|
+
"percentage",
|
|
280
|
+
"--versions",
|
|
281
|
+
JSON.stringify(versions),
|
|
282
|
+
...options.env ? ["--mode", validateWranglerEnvName(options.env)] : []
|
|
283
|
+
], execute, options.verbose);
|
|
284
|
+
return {
|
|
285
|
+
deployedUrl: parseWorkersDevUrl(output),
|
|
286
|
+
output
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function runCfTriggersDeploy(root, options, execute = execFileSync) {
|
|
290
|
+
const output = runCfCommand(root, [
|
|
291
|
+
"workers",
|
|
292
|
+
"triggers",
|
|
293
|
+
"deploy",
|
|
294
|
+
"--prebuilt",
|
|
295
|
+
...options.env ? ["--mode", validateWranglerEnvName(options.env)] : []
|
|
296
|
+
], execute, options.verbose);
|
|
297
|
+
return {
|
|
298
|
+
deployedUrl: parseCdnWarmupDeploymentUrl(output),
|
|
299
|
+
output
|
|
300
|
+
};
|
|
301
|
+
}
|
|
183
302
|
function runWranglerVersionUpload(root, options, execute = execFileSync) {
|
|
184
303
|
const { args, env } = buildWranglerVersionUploadArgs(options);
|
|
185
304
|
if (env) console.log(`\n Uploading Worker version for env: ${env}...`);
|
|
186
305
|
else console.log("\n Uploading Worker version for production...");
|
|
187
306
|
try {
|
|
188
|
-
|
|
307
|
+
const upload = parseWranglerVersionUploadOutput(runWranglerCommand(root, args, execute, options.verbose === true));
|
|
308
|
+
console.log(` Worker version ID: ${upload.versionId}`);
|
|
309
|
+
return upload;
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (isMissingWorkerVersionUploadError(error)) throw withInitialDeployRequiredMessage();
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function runCfVersionUpload(root, options, execute = execFileSync) {
|
|
316
|
+
const workerName = readBuildOutputWorkerName(root);
|
|
317
|
+
const { args, mode } = buildCfVersionUploadArgs(options);
|
|
318
|
+
console.log(mode ? `\n Uploading Worker Build Output in mode: ${mode}...` : "\n Uploading Worker Build Output...");
|
|
319
|
+
try {
|
|
320
|
+
return {
|
|
321
|
+
...parseWranglerVersionUploadOutput(runCfCommand(root, args, execute, options.verbose === true)),
|
|
322
|
+
workerName
|
|
323
|
+
};
|
|
189
324
|
} catch (error) {
|
|
190
325
|
if (isMissingWorkerVersionUploadError(error)) throw withInitialDeployRequiredMessage();
|
|
191
326
|
throw error;
|
|
@@ -197,7 +332,7 @@ function runWranglerVersionDeploy(root, versionTraffic, options, phase = "promot
|
|
|
197
332
|
if (phase === "stage") console.log(`\n Staging uploaded Worker version at 0% for CDN warmup in ${target}...`);
|
|
198
333
|
else if (phase === "promote-warmed") console.log(`\n Promoting warmed Worker version to ${target}...`);
|
|
199
334
|
else console.log(`\n Promoting uploaded Worker version to ${target}...`);
|
|
200
|
-
const output = runWranglerCommand(root, args, execute);
|
|
335
|
+
const output = runWranglerCommand(root, args, execute, options.verbose === true);
|
|
201
336
|
return {
|
|
202
337
|
deployedUrl: parseWorkersDevUrl(output),
|
|
203
338
|
output
|
|
@@ -205,19 +340,21 @@ function runWranglerVersionDeploy(root, versionTraffic, options, phase = "promot
|
|
|
205
340
|
}
|
|
206
341
|
function runWranglerDeploymentStatus(root, options, execute = execFileSync) {
|
|
207
342
|
const { args, env } = buildWranglerDeploymentsStatusArgs(options);
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
343
|
+
if (options.verbose) {
|
|
344
|
+
if (env) console.log(`\n Reading current Worker deployment for env: ${env}...`);
|
|
345
|
+
else console.log("\n Reading current Worker deployment...");
|
|
346
|
+
}
|
|
347
|
+
return parseWranglerDeploymentStatusOutput(runWranglerCommand(root, args, execute, options.verbose === true));
|
|
211
348
|
}
|
|
212
349
|
function runWranglerTriggersDeploy(root, options, execute = execFileSync) {
|
|
213
350
|
const { args, env } = buildWranglerTriggersDeployArgs(options);
|
|
214
351
|
if (env) console.log(`\n Applying Worker triggers for env: ${env}...`);
|
|
215
352
|
else console.log("\n Applying Worker triggers...");
|
|
216
|
-
const output = runWranglerCommand(root, args, execute);
|
|
353
|
+
const output = runWranglerCommand(root, args, execute, options.verbose === true);
|
|
217
354
|
return {
|
|
218
|
-
deployedUrl:
|
|
355
|
+
deployedUrl: parseCdnWarmupDeploymentUrl(output),
|
|
219
356
|
output
|
|
220
357
|
};
|
|
221
358
|
}
|
|
222
359
|
//#endregion
|
|
223
|
-
export { buildWranglerDeploymentsStatusArgs, buildWranglerTriggersDeployArgs, buildWranglerVersionDeployArgs, buildWranglerVersionUploadArgs, parseVersionId, parseWorkersDevUrl, parseWranglerDeploymentStatusOutput, parseWranglerVersionUploadOutput, runWranglerDeploymentStatus, runWranglerTriggersDeploy, runWranglerVersionDeploy, runWranglerVersionUpload };
|
|
360
|
+
export { buildCfVersionUploadArgs, buildWranglerDeploymentsStatusArgs, buildWranglerTriggersDeployArgs, buildWranglerVersionDeployArgs, buildWranglerVersionUploadArgs, parseCfDeploymentStatusOutput, parseUploadedWorkerName, parseVersionId, parseWorkersDevUrl, parseWranglerDeploymentStatusOutput, parseWranglerVersionUploadOutput, readBuildOutputWorkerName, runCfDeploymentStatus, runCfTriggersDeploy, runCfVersionDeploy, runCfVersionUpload, runWranglerDeploymentStatus, runWranglerTriggersDeploy, runWranglerVersionDeploy, runWranglerVersionUpload };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/worker-deployment-url.d.ts
|
|
2
|
+
export declare function parseWorkerDeploymentUrl(output: string): string | null;
|
|
3
|
+
/**
|
|
4
|
+
* Parse the concrete hostname that Wrangler reports after applying Worker
|
|
5
|
+
* triggers. Catch-all routes are valid warmup targets even though they are not
|
|
6
|
+
* canonical deployment URLs for general CLI reporting.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseCdnWarmupDeploymentUrl(output: string): string | null;
|
|
9
|
+
//#endregion
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { parseWorkersDevUrl } from "./workers-dev-url.js";
|
|
2
|
+
//#region src/worker-deployment-url.ts
|
|
3
|
+
function parseWorkerDeploymentUrl(output) {
|
|
4
|
+
return parseWorkersDevUrl(output) ?? parseCustomDomainUrl(output);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Parse the concrete hostname that Wrangler reports after applying Worker
|
|
8
|
+
* triggers. Catch-all routes are valid warmup targets even though they are not
|
|
9
|
+
* canonical deployment URLs for general CLI reporting.
|
|
10
|
+
*/
|
|
11
|
+
function parseCdnWarmupDeploymentUrl(output) {
|
|
12
|
+
return parseCustomDomainUrl(output) ?? parseCatchAllWorkerRouteOrigin(output) ?? parseWorkersDevUrl(output);
|
|
13
|
+
}
|
|
14
|
+
function parseCatchAllWorkerRouteOrigin(output) {
|
|
15
|
+
for (const line of output.split(/\r?\n/)) {
|
|
16
|
+
const route = line.trim().split(/\s+/, 1)[0];
|
|
17
|
+
if (!route || !route.endsWith("/*")) continue;
|
|
18
|
+
try {
|
|
19
|
+
const url = new URL(route.includes("://") ? route : `https://${route}`);
|
|
20
|
+
if (url.protocol !== "https:" && url.protocol !== "http:" || url.hostname.includes("*") || url.username !== "" || url.password !== "" || url.port !== "" || url.pathname !== "/*" || url.search !== "" || url.hash !== "") continue;
|
|
21
|
+
return url.origin;
|
|
22
|
+
} catch {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function parseCustomDomainUrl(output) {
|
|
29
|
+
for (const line of output.split(/\r?\n/)) {
|
|
30
|
+
const match = /^\s*(\S+)\s+\(custom domain(?: - zone (?:id|name): [^)]+)?\)(?: \[([^\]\r\n]+)\])?\s*$/.exec(line);
|
|
31
|
+
const hostname = match?.[1];
|
|
32
|
+
if (!hostname) continue;
|
|
33
|
+
if (match[2]?.split(",").some((flag) => flag.trim() === "disabled")) continue;
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(`https://${hostname}`);
|
|
36
|
+
if (url.username !== "" || url.password !== "" || url.port !== "" || url.pathname !== "/" || url.search !== "" || url.hash !== "") continue;
|
|
37
|
+
return url.origin;
|
|
38
|
+
} catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { parseCdnWarmupDeploymentUrl, parseWorkerDeploymentUrl };
|
|
@@ -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
|