Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions packages/cloudflare/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ function parseNonNegativeIntegerArg(raw: string, flag: string): number {
return parsed;
}

const MAX_NODE_TIMER_DELAY_MS = 2_147_483_647;

function validatePromotionDelay(value: number, raw = String(value)): number {
if (!Number.isInteger(value) || value < 0) {
throw new Error(`--warm-cdn-promotion-delay expects a non-negative integer, but got "${raw}".`);
}
if (value > MAX_NODE_TIMER_DELAY_MS) {
throw new Error(
`--warm-cdn-promotion-delay must not exceed ${MAX_NODE_TIMER_DELAY_MS} milliseconds, but got "${raw}".`,
);
}
return value;
}

function formatUnknownError(error: unknown): string {
if (error instanceof Error && error.message) return error.message;
return String(error);
Expand Down Expand Up @@ -230,9 +244,12 @@ export function parseDeployArgs(args: string[]) {
warmCdnPromotionDelay:
values["warm-cdn-promotion-delay"] === undefined
? undefined
: parseNonNegativeIntegerArg(
: validatePromotionDelay(
parseNonNegativeIntegerArg(
values["warm-cdn-promotion-delay"],
"--warm-cdn-promotion-delay",
),
values["warm-cdn-promotion-delay"],
"--warm-cdn-promotion-delay",
),
warmCdnIncludeFallbacks: values["warm-cdn-include-fallbacks"],
experimentalTPR: values["experimental-tpr"],
Expand Down Expand Up @@ -586,6 +603,9 @@ export async function deployWithCdnWarmup(
"deploymentId" | "expectedBuildId" | "expectedRscBuildId" | "loadingShellPaths" | "rscPaths"
>,
): Promise<string> {
if (options.warmCdnPromotionDelay !== undefined) {
validatePromotionDelay(options.warmCdnPromotionDelay);
}
if (options.warmCdnStrict && paths.length > 0 && options.expectedBuildId === undefined) {
throw new Error(
"Strict CDN HTML warmup requires a CDN adapter that declares build-identity response headers. " +
Expand Down Expand Up @@ -1043,6 +1063,7 @@ export async function deploy(options: DeployOptions): Promise<void> {
await emitPrerenderPathManifest({
root: info.root,
nextConfig,
buildIdentity: hasBuildIdentityHeader ? "response-header" : undefined,
responseVary: hasStrictResponseVary ? "verbatim" : undefined,
routeRootConfig: viteConfigMetadata.routeRootConfig,
});
Expand Down
Loading
Loading