@@ -12,7 +12,7 @@ import type {
1212import type { IncrementalCache , TagCache } from "@opennextjs/aws/types/overrides.js" ;
1313import { globSync } from "glob" ;
1414import { tqdm } from "ts-tqdm" ;
15- import { unstable_readConfig } from "wrangler" ;
15+ import { getPlatformProxy , unstable_readConfig } from "wrangler" ;
1616
1717import {
1818 BINDING_NAME as KV_CACHE_BINDING_NAME ,
@@ -92,13 +92,14 @@ export function getCacheAssets(opts: BuildOptions): CacheAsset[] {
9292 return assets ;
9393}
9494
95- function populateR2IncrementalCache (
95+ async function populateR2IncrementalCache (
9696 options : BuildOptions ,
9797 populateCacheOptions : { target : WranglerTarget ; environment ?: string }
9898) {
9999 logger . info ( "\nPopulating R2 incremental cache..." ) ;
100100
101101 const config = unstable_readConfig ( { env : populateCacheOptions . environment } ) ;
102+ const proxy = await getPlatformProxy < CloudflareEnv > ( populateCacheOptions ) ;
102103
103104 const binding = config . r2_buckets . find ( ( { binding } ) => binding === R2_CACHE_BINDING_NAME ) ;
104105 if ( ! binding ) {
@@ -114,7 +115,7 @@ function populateR2IncrementalCache(
114115
115116 for ( const { fullPath, key, buildId, isFetch } of tqdm ( assets ) ) {
116117 const cacheKey = computeCacheKey ( key , {
117- prefix : process . env [ R2_CACHE_PREFIX_ENV_NAME ] ,
118+ prefix : proxy . env [ R2_CACHE_PREFIX_ENV_NAME ] ,
118119 buildId,
119120 cacheType : isFetch ? "fetch" : "cache" ,
120121 } ) ;
@@ -130,13 +131,14 @@ function populateR2IncrementalCache(
130131 logger . info ( `Successfully populated cache with ${ assets . length } assets` ) ;
131132}
132133
133- function populateKVIncrementalCache (
134+ async function populateKVIncrementalCache (
134135 options : BuildOptions ,
135136 populateCacheOptions : { target : WranglerTarget ; environment ?: string }
136137) {
137138 logger . info ( "\nPopulating KV incremental cache..." ) ;
138139
139140 const config = unstable_readConfig ( { env : populateCacheOptions . environment } ) ;
141+ const proxy = await getPlatformProxy < CloudflareEnv > ( populateCacheOptions ) ;
140142
141143 const binding = config . kv_namespaces . find ( ( { binding } ) => binding === KV_CACHE_BINDING_NAME ) ;
142144 if ( ! binding ) {
@@ -147,7 +149,7 @@ function populateKVIncrementalCache(
147149
148150 for ( const { fullPath, key, buildId, isFetch } of tqdm ( assets ) ) {
149151 const cacheKey = computeCacheKey ( key , {
150- prefix : process . env [ KV_CACHE_PREFIX_ENV_NAME ] ,
152+ prefix : proxy . env [ KV_CACHE_PREFIX_ENV_NAME ] ,
151153 buildId,
152154 cacheType : isFetch ? "fetch" : "cache" ,
153155 } ) ;
@@ -220,10 +222,10 @@ export async function populateCache(
220222 const name = await resolveCacheName ( incrementalCache ) ;
221223 switch ( name ) {
222224 case R2_CACHE_NAME :
223- populateR2IncrementalCache ( options , populateCacheOptions ) ;
225+ await populateR2IncrementalCache ( options , populateCacheOptions ) ;
224226 break ;
225227 case KV_CACHE_NAME :
226- populateKVIncrementalCache ( options , populateCacheOptions ) ;
228+ await populateKVIncrementalCache ( options , populateCacheOptions ) ;
227229 break ;
228230 case STATIC_ASSETS_CACHE_NAME :
229231 populateStaticAssetsIncrementalCache ( options ) ;
0 commit comments