Skip to content

Commit ea348db

Browse files
committed
feat: add config flag support for deploy, preview, and upload commands
1 parent e0f39b6 commit ea348db

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

.changeset/fresh-hoops-relax.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
feature: Add `config` options to `populateCache` command
6+
7+
This change adds the `config` option to the `populateCache` command in the Cloudflare CLI. This allows users to specify a custom Wrangler configuration file when populating the cache, enhancing flexibility and usability.

packages/cloudflare/src/cli/commands/deploy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BuildOptions } from "@opennextjs/aws/build/helper.js";
22

33
import type { OpenNextConfig } from "../../api/config.js";
44
import { DEPLOYMENT_MAPPING_ENV_NAME } from "../templates/skew-protection.js";
5-
import { getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
5+
import { getWranglerConfigFlag, getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
66
import { getEnvFromPlatformProxy, quoteShellMeta } from "./helpers.js";
77
import { populateCache } from "./populate-cache.js";
88
import { getDeploymentMapping } from "./skew-protection.js";
@@ -22,6 +22,7 @@ export async function deploy(
2222
await populateCache(options, config, {
2323
target: "remote",
2424
environment: getWranglerEnvironmentFlag(deployOptions.passthroughArgs),
25+
config: getWranglerConfigFlag(deployOptions.passthroughArgs),
2526
cacheChunkSize: deployOptions.cacheChunkSize,
2627
});
2728

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ export function getCacheAssets(opts: BuildOptions): CacheAsset[] {
9696

9797
async function populateR2IncrementalCache(
9898
options: BuildOptions,
99-
populateCacheOptions: { target: WranglerTarget; environment?: string }
99+
populateCacheOptions: { target: WranglerTarget; environment?: string; config?: string }
100100
) {
101101
logger.info("\nPopulating R2 incremental cache...");
102102

103-
const config = unstable_readConfig({ env: populateCacheOptions.environment });
103+
const config = unstable_readConfig({
104+
env: populateCacheOptions.environment,
105+
config: populateCacheOptions.config,
106+
});
104107

105108
const binding = config.r2_buckets.find(({ binding }) => binding === R2_CACHE_BINDING_NAME);
106109
if (!binding) {
@@ -140,11 +143,19 @@ async function populateR2IncrementalCache(
140143

141144
async function populateKVIncrementalCache(
142145
options: BuildOptions,
143-
populateCacheOptions: { target: WranglerTarget; environment?: string; cacheChunkSize?: number }
146+
populateCacheOptions: {
147+
target: WranglerTarget;
148+
environment?: string;
149+
config?: string;
150+
cacheChunkSize?: number;
151+
}
144152
) {
145153
logger.info("\nPopulating KV incremental cache...");
146154

147-
const config = unstable_readConfig({ env: populateCacheOptions.environment });
155+
const config = unstable_readConfig({
156+
env: populateCacheOptions.environment,
157+
config: populateCacheOptions.config,
158+
});
148159

149160
const binding = config.kv_namespaces.find(({ binding }) => binding === KV_CACHE_BINDING_NAME);
150161
if (!binding) {
@@ -229,7 +240,12 @@ function populateStaticAssetsIncrementalCache(options: BuildOptions) {
229240
export async function populateCache(
230241
options: BuildOptions,
231242
config: OpenNextConfig,
232-
populateCacheOptions: { target: WranglerTarget; environment?: string; cacheChunkSize?: number }
243+
populateCacheOptions: {
244+
target: WranglerTarget;
245+
environment?: string;
246+
config?: string;
247+
cacheChunkSize?: number;
248+
}
233249
) {
234250
const { incrementalCache, tagCache } = config.default.override ?? {};
235251

packages/cloudflare/src/cli/commands/preview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BuildOptions } from "@opennextjs/aws/build/helper.js";
22

33
import type { OpenNextConfig } from "../../api/config.js";
4-
import { getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
4+
import { getWranglerConfigFlag, getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
55
import { populateCache } from "./populate-cache.js";
66

77
export async function preview(
@@ -12,6 +12,7 @@ export async function preview(
1212
await populateCache(options, config, {
1313
target: "local",
1414
environment: getWranglerEnvironmentFlag(previewOptions.passthroughArgs),
15+
config: getWranglerConfigFlag(previewOptions.passthroughArgs),
1516
cacheChunkSize: previewOptions.cacheChunkSize,
1617
});
1718

packages/cloudflare/src/cli/commands/upload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BuildOptions } from "@opennextjs/aws/build/helper.js";
22

33
import type { OpenNextConfig } from "../../api/config.js";
44
import { DEPLOYMENT_MAPPING_ENV_NAME } from "../templates/skew-protection.js";
5-
import { getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
5+
import { getWranglerConfigFlag, getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
66
import { getEnvFromPlatformProxy, quoteShellMeta } from "./helpers.js";
77
import { populateCache } from "./populate-cache.js";
88
import { getDeploymentMapping } from "./skew-protection.js";
@@ -22,6 +22,7 @@ export async function upload(
2222
await populateCache(options, config, {
2323
target: "remote",
2424
environment: getWranglerEnvironmentFlag(uploadOptions.passthroughArgs),
25+
config: getWranglerConfigFlag(uploadOptions.passthroughArgs),
2526
cacheChunkSize: uploadOptions.cacheChunkSize,
2627
});
2728

0 commit comments

Comments
 (0)