Skip to content

Commit 89ce96b

Browse files
authored
fix: wrangler config not passed to cache population (#814)
1 parent b7771f1 commit 89ce96b

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

.changeset/icy-ends-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: wrangler config not passed to cache population

examples/overrides/d1-tag-next/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"build:worker": "pnpm opennextjs-cloudflare build",
11-
"preview:worker": "pnpm opennextjs-cloudflare preview",
10+
"build:worker": "pnpm opennextjs-cloudflare build --skipWranglerConfigCheck",
11+
"preview:worker": "pnpm opennextjs-cloudflare preview --config wrangler.e2e.jsonc",
1212
"preview": "pnpm build:worker && pnpm preview:worker",
1313
"e2e": "playwright test -c e2e/playwright.config.ts"
1414
},

examples/overrides/d1-tag-next/wrangler.jsonc renamed to examples/overrides/d1-tag-next/wrangler.e2e.jsonc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
77
"assets": {
88
"directory": ".open-next/assets",
9-
"binding": "ASSETS"
9+
"binding": "ASSETS",
1010
},
1111
"vars": {
12-
"APP_VERSION": "1.2.345"
12+
"APP_VERSION": "1.2.345",
1313
},
1414
"kv_namespaces": [
1515
{
1616
"binding": "NEXT_INC_CACHE_KV",
17-
"id": "<BINDING_ID>"
18-
}
17+
"id": "<BINDING_ID>",
18+
},
1919
],
2020
"d1_databases": [
2121
{
2222
"binding": "NEXT_TAG_CACHE_D1",
2323
"database_id": "NEXT_TAG_CACHE_D1",
24-
"database_name": "NEXT_TAG_CACHE_D1"
25-
}
26-
]
24+
"database_name": "NEXT_TAG_CACHE_D1",
25+
},
26+
],
2727
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,14 @@ async function populateR2IncrementalCache(
146146
quoteShellMeta(normalizePath(path.join(bucket, cacheKey))),
147147
`--file ${quoteShellMeta(fullPath)}`,
148148
],
149-
// NOTE: R2 does not support the environment flag and results in the following error:
150-
// Incorrect type for the 'cacheExpiry' field on 'HttpMetadata': the provided value is not of type 'date'.
151-
{ target: populateCacheOptions.target, logging: "error" }
149+
{
150+
target: populateCacheOptions.target,
151+
configPath: populateCacheOptions.configPath,
152+
// R2 does not support the environment flag and results in the following error:
153+
// Incorrect type for the 'cacheExpiry' field on 'HttpMetadata': the provided value is not of type 'date'.
154+
environment: undefined,
155+
logging: "error",
156+
}
152157
);
153158
}
154159
logger.info(`Successfully populated cache with ${assets.length} assets`);
@@ -193,7 +198,9 @@ async function populateKVIncrementalCache(
193198
writeFileSync(chunkPath, JSON.stringify(kvMapping));
194199

195200
runWrangler(options, ["kv bulk put", quoteShellMeta(chunkPath), `--binding ${KV_CACHE_BINDING_NAME}`], {
196-
...populateCacheOptions,
201+
target: populateCacheOptions.target,
202+
environment: populateCacheOptions.environment,
203+
configPath: populateCacheOptions.configPath,
197204
logging: "error",
198205
});
199206

@@ -222,7 +229,12 @@ function populateD1TagCache(
222229
D1_TAG_BINDING_NAME,
223230
`--command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);"`,
224231
],
225-
{ ...populateCacheOptions, logging: "error" }
232+
{
233+
target: populateCacheOptions.target,
234+
environment: populateCacheOptions.environment,
235+
configPath: populateCacheOptions.configPath,
236+
logging: "error",
237+
}
226238
);
227239

228240
logger.info("\nSuccessfully created D1 table");

packages/cloudflare/src/cli/utils/run-wrangler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type WranglerTarget = "local" | "remote";
1111
type WranglerOptions = {
1212
target?: WranglerTarget;
1313
environment?: string;
14+
configPath?: string;
1415
logging?: "all" | "error";
1516
};
1617

@@ -65,6 +66,7 @@ export function runWrangler(options: BuildOptions, args: string[], wranglerOpts:
6566
[
6667
...args,
6768
wranglerOpts.environment && `--env ${wranglerOpts.environment}`,
69+
wranglerOpts.configPath && `--config ${wranglerOpts.configPath}`,
6870
wranglerOpts.target === "remote" && "--remote",
6971
wranglerOpts.target === "local" && "--local",
7072
].filter((v): v is string => !!v)

0 commit comments

Comments
 (0)