Skip to content
Closed
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
7 changes: 7 additions & 0 deletions .changeset/fresh-hoops-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@opennextjs/cloudflare": patch
---

feature: Add `config` options to `populateCache` command

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.
3 changes: 2 additions & 1 deletion packages/cloudflare/src/cli/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BuildOptions } from "@opennextjs/aws/build/helper.js";

import type { OpenNextConfig } from "../../api/config.js";
import { DEPLOYMENT_MAPPING_ENV_NAME } from "../templates/skew-protection.js";
import { getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
import { getWranglerConfigFlag, getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
import { getEnvFromPlatformProxy, quoteShellMeta } from "./helpers.js";
import { populateCache } from "./populate-cache.js";
import { getDeploymentMapping } from "./skew-protection.js";
Expand All @@ -22,6 +22,7 @@ export async function deploy(
await populateCache(options, config, {
target: "remote",
environment: getWranglerEnvironmentFlag(deployOptions.passthroughArgs),
config: getWranglerConfigFlag(deployOptions.passthroughArgs),
cacheChunkSize: deployOptions.cacheChunkSize,
});

Expand Down
26 changes: 21 additions & 5 deletions packages/cloudflare/src/cli/commands/populate-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ export function getCacheAssets(opts: BuildOptions): CacheAsset[] {

async function populateR2IncrementalCache(
options: BuildOptions,
populateCacheOptions: { target: WranglerTarget; environment?: string }
populateCacheOptions: { target: WranglerTarget; environment?: string; config?: string }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please extract the type to top level?
(Maybe add a comment here that the cacheChunkSize is not used)

) {
logger.info("\nPopulating R2 incremental cache...");

const config = unstable_readConfig({ env: populateCacheOptions.environment });
const config = unstable_readConfig({
env: populateCacheOptions.environment,
config: populateCacheOptions.config,
});

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

async function populateKVIncrementalCache(
options: BuildOptions,
populateCacheOptions: { target: WranglerTarget; environment?: string; cacheChunkSize?: number }
populateCacheOptions: {
target: WranglerTarget;
environment?: string;
config?: string;
cacheChunkSize?: number;
}
) {
logger.info("\nPopulating KV incremental cache...");

const config = unstable_readConfig({ env: populateCacheOptions.environment });
const config = unstable_readConfig({
env: populateCacheOptions.environment,
config: populateCacheOptions.config,
});

const binding = config.kv_namespaces.find(({ binding }) => binding === KV_CACHE_BINDING_NAME);
if (!binding) {
Expand Down Expand Up @@ -229,7 +240,12 @@ function populateStaticAssetsIncrementalCache(options: BuildOptions) {
export async function populateCache(
options: BuildOptions,
config: OpenNextConfig,
populateCacheOptions: { target: WranglerTarget; environment?: string; cacheChunkSize?: number }
populateCacheOptions: {
target: WranglerTarget;
environment?: string;
config?: string;
cacheChunkSize?: number;
}
) {
const { incrementalCache, tagCache } = config.default.override ?? {};

Expand Down
3 changes: 2 additions & 1 deletion packages/cloudflare/src/cli/commands/preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BuildOptions } from "@opennextjs/aws/build/helper.js";

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

export async function preview(
Expand All @@ -12,6 +12,7 @@ export async function preview(
await populateCache(options, config, {
target: "local",
environment: getWranglerEnvironmentFlag(previewOptions.passthroughArgs),
config: getWranglerConfigFlag(previewOptions.passthroughArgs),
cacheChunkSize: previewOptions.cacheChunkSize,
});

Expand Down
3 changes: 2 additions & 1 deletion packages/cloudflare/src/cli/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BuildOptions } from "@opennextjs/aws/build/helper.js";

import type { OpenNextConfig } from "../../api/config.js";
import { DEPLOYMENT_MAPPING_ENV_NAME } from "../templates/skew-protection.js";
import { getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
import { getWranglerConfigFlag, getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
import { getEnvFromPlatformProxy, quoteShellMeta } from "./helpers.js";
import { populateCache } from "./populate-cache.js";
import { getDeploymentMapping } from "./skew-protection.js";
Expand All @@ -22,6 +22,7 @@ export async function upload(
await populateCache(options, config, {
target: "remote",
environment: getWranglerEnvironmentFlag(uploadOptions.passthroughArgs),
config: getWranglerConfigFlag(uploadOptions.passthroughArgs),
cacheChunkSize: uploadOptions.cacheChunkSize,
});

Expand Down