Skip to content

Commit 61104a5

Browse files
committed
add suggestions
1 parent 4771dd8 commit 61104a5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/cloudflare/src/cli/args.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { mkdirSync, type Stats, statSync } from "node:fs";
22
import { resolve } from "node:path";
33
import { parseArgs } from "node:util";
44

5-
import { CacheBindingMode } from "./build/utils/index.js";
5+
import type { CacheBindingMode } from "./build/utils/index.js";
6+
import { isCacheBindingMode } from "./build/utils/index.js";
67

78
export function getArgs(): {
89
skipNextBuild: boolean;
910
skipWranglerConfigCheck: boolean;
1011
outputDir?: string;
1112
minify: boolean;
12-
populateCache?: { mode: "local" | "remote"; onlyPopulate: boolean };
13+
populateCache?: { mode: CacheBindingMode; onlyPopulate: boolean };
1314
} {
1415
const { skipBuild, skipWranglerConfigCheck, output, noMinify, populateCache, onlyPopulateCache } =
1516
parseArgs({
@@ -50,7 +51,7 @@ export function getArgs(): {
5051

5152
if (
5253
(populateCache !== undefined || onlyPopulateCache) &&
53-
(!populateCache?.length || !["local", "remote"].includes(populateCache))
54+
(!populateCache?.length || !isCacheBindingMode(populateCache))
5455
) {
5556
throw new Error(`Error: missing mode for populate cache flag, expected 'local' | 'remote'`);
5657
}
@@ -62,9 +63,7 @@ export function getArgs(): {
6263
skipWranglerConfigCheck ||
6364
["1", "true", "yes"].includes(String(process.env.SKIP_WRANGLER_CONFIG_CHECK)),
6465
minify: !noMinify,
65-
populateCache: populateCache
66-
? { mode: populateCache as CacheBindingMode, onlyPopulate: !!onlyPopulateCache }
67-
: undefined,
66+
populateCache: populateCache ? { mode: populateCache, onlyPopulate: !!onlyPopulateCache } : undefined,
6867
};
6968
}
7069

packages/cloudflare/src/cli/build/utils/populate-cache.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ export async function populateCache(opts: BuildOptions, config: OpenNextConfig,
7272
}
7373
}
7474
}
75+
76+
export function isCacheBindingMode(v: string | undefined): v is CacheBindingMode {
77+
return !!v && ["local", "remote"].includes(v);
78+
}

0 commit comments

Comments
 (0)