@@ -12,7 +12,7 @@ import type {
12
12
import type { IncrementalCache , TagCache } from "@opennextjs/aws/types/overrides.js" ;
13
13
import { globSync } from "glob" ;
14
14
import { tqdm } from "ts-tqdm" ;
15
- import { unstable_readConfig } from "wrangler" ;
15
+ import { getPlatformProxy , unstable_readConfig } from "wrangler" ;
16
16
17
17
import {
18
18
BINDING_NAME as KV_CACHE_BINDING_NAME ,
@@ -92,13 +92,14 @@ export function getCacheAssets(opts: BuildOptions): CacheAsset[] {
92
92
return assets ;
93
93
}
94
94
95
- function populateR2IncrementalCache (
95
+ async function populateR2IncrementalCache (
96
96
options : BuildOptions ,
97
97
populateCacheOptions : { target : WranglerTarget ; environment ?: string }
98
98
) {
99
99
logger . info ( "\nPopulating R2 incremental cache..." ) ;
100
100
101
101
const config = unstable_readConfig ( { env : populateCacheOptions . environment } ) ;
102
+ const proxy = await getPlatformProxy < CloudflareEnv > ( populateCacheOptions ) ;
102
103
103
104
const binding = config . r2_buckets . find ( ( { binding } ) => binding === R2_CACHE_BINDING_NAME ) ;
104
105
if ( ! binding ) {
@@ -114,7 +115,7 @@ function populateR2IncrementalCache(
114
115
115
116
for ( const { fullPath, key, buildId, isFetch } of tqdm ( assets ) ) {
116
117
const cacheKey = computeCacheKey ( key , {
117
- prefix : process . env [ R2_CACHE_PREFIX_ENV_NAME ] ,
118
+ prefix : proxy . env [ R2_CACHE_PREFIX_ENV_NAME ] ,
118
119
buildId,
119
120
cacheType : isFetch ? "fetch" : "cache" ,
120
121
} ) ;
@@ -130,13 +131,14 @@ function populateR2IncrementalCache(
130
131
logger . info ( `Successfully populated cache with ${ assets . length } assets` ) ;
131
132
}
132
133
133
- function populateKVIncrementalCache (
134
+ async function populateKVIncrementalCache (
134
135
options : BuildOptions ,
135
136
populateCacheOptions : { target : WranglerTarget ; environment ?: string }
136
137
) {
137
138
logger . info ( "\nPopulating KV incremental cache..." ) ;
138
139
139
140
const config = unstable_readConfig ( { env : populateCacheOptions . environment } ) ;
141
+ const proxy = await getPlatformProxy < CloudflareEnv > ( populateCacheOptions ) ;
140
142
141
143
const binding = config . kv_namespaces . find ( ( { binding } ) => binding === KV_CACHE_BINDING_NAME ) ;
142
144
if ( ! binding ) {
@@ -147,7 +149,7 @@ function populateKVIncrementalCache(
147
149
148
150
for ( const { fullPath, key, buildId, isFetch } of tqdm ( assets ) ) {
149
151
const cacheKey = computeCacheKey ( key , {
150
- prefix : process . env [ KV_CACHE_PREFIX_ENV_NAME ] ,
152
+ prefix : proxy . env [ KV_CACHE_PREFIX_ENV_NAME ] ,
151
153
buildId,
152
154
cacheType : isFetch ? "fetch" : "cache" ,
153
155
} ) ;
@@ -220,10 +222,10 @@ export async function populateCache(
220
222
const name = await resolveCacheName ( incrementalCache ) ;
221
223
switch ( name ) {
222
224
case R2_CACHE_NAME :
223
- populateR2IncrementalCache ( options , populateCacheOptions ) ;
225
+ await populateR2IncrementalCache ( options , populateCacheOptions ) ;
224
226
break ;
225
227
case KV_CACHE_NAME :
226
- populateKVIncrementalCache ( options , populateCacheOptions ) ;
228
+ await populateKVIncrementalCache ( options , populateCacheOptions ) ;
227
229
break ;
228
230
case STATIC_ASSETS_CACHE_NAME :
229
231
populateStaticAssetsIncrementalCache ( options ) ;
0 commit comments