Skip to content

Commit 728ad99

Browse files
james-elicxvicb
andauthored
feat: support for a custom OpenNext config path (#862)
Co-authored-by: Victor Berchet <[email protected]>
1 parent dc76d6e commit 728ad99

File tree

11 files changed

+85
-34
lines changed

11 files changed

+85
-34
lines changed

.changeset/lucky-places-occur.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+
refactor: deprecate usage of the `--configPath` flag for the Wrangler config, in favour of the `--config` flag.

.changeset/real-bats-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": minor
3+
---
4+
5+
feat: support for a custom OpenNext config path with the `--openNextConfigPath` flag
File renamed without changes.

examples/overrides/r2-incremental-cache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"build:worker": "pnpm opennextjs-cloudflare build",
10+
"build:worker": "pnpm opennextjs-cloudflare build --openNextConfigPath=./.custom-config/my-opennext-config.ts",
1111
"preview:worker": "pnpm opennextjs-cloudflare preview",
1212
"preview": "pnpm build:worker && pnpm preview:worker",
1313
"e2e": "playwright test -c e2e/playwright.config.ts"

packages/cloudflare/src/cli/build/utils/create-config-files.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ export async function getLatestCompatDate(): Promise<string | undefined> {
9393
* If the user refuses an error is thrown (since the file is mandatory).
9494
*
9595
* @param sourceDir The source directory for the project
96+
* @return The path to the created source file
9697
*/
97-
export async function createOpenNextConfigIfNotExistent(sourceDir: string): Promise<void> {
98+
export async function createOpenNextConfigIfNotExistent(sourceDir: string): Promise<string> {
9899
const openNextConfigPath = join(sourceDir, "open-next.config.ts");
99100

100101
if (!existsSync(openNextConfigPath)) {
@@ -108,4 +109,6 @@ export async function createOpenNextConfigIfNotExistent(sourceDir: string): Prom
108109

109110
cpSync(join(getPackageTemplatesDirPath(), "open-next.config.ts"), openNextConfigPath);
110111
}
112+
113+
return openNextConfigPath;
111114
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ async function buildCommand(
2222
skipNextBuild: boolean;
2323
noMinify: boolean;
2424
skipWranglerConfigCheck: boolean;
25+
openNextConfigPath: string | undefined;
2526
}>
2627
): Promise<void> {
2728
printHeaders("build");
2829

29-
const { config, buildDir } = await compileConfig();
30+
const { config, buildDir } = await compileConfig(args.openNextConfigPath);
3031
const options = getNormalizedOptions(config, buildDir);
3132

3233
const wranglerConfig = readWranglerConfig(args);
@@ -65,6 +66,10 @@ export function addBuildCommand<T extends yargs.Argv>(y: T) {
6566
type: "boolean",
6667
default: ["1", "true", "yes"].includes(String(process.env.SKIP_WRANGLER_CONFIG_CHECK)),
6768
desc: "Skip checking for a Wrangler config",
69+
})
70+
.option("openNextConfigPath", {
71+
type: "string",
72+
desc: "Path to the OpenNext configuration file",
6873
}),
6974
(args) => buildCommand(withWranglerPassthroughArgs(args))
7075
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function deployCommand(args: WithWranglerArgs<{ cacheChunkSize: num
2828
const wranglerConfig = readWranglerConfig(args);
2929

3030
const envVars = await getEnvFromPlatformProxy({
31-
configPath: args.configPath,
31+
configPath: args.wranglerConfigPath,
3232
environment: args.env,
3333
});
3434

@@ -37,7 +37,7 @@ export async function deployCommand(args: WithWranglerArgs<{ cacheChunkSize: num
3737
await populateCache(options, config, wranglerConfig, {
3838
target: "remote",
3939
environment: args.env,
40-
configPath: args.configPath,
40+
wranglerConfigPath: args.wranglerConfigPath,
4141
cacheChunkSize: args.cacheChunkSize,
4242
});
4343

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function getCacheAssets(opts: BuildOptions): CacheAsset[] {
107107
type PopulateCacheOptions = {
108108
target: WranglerTarget;
109109
environment?: string;
110-
configPath?: string;
110+
wranglerConfigPath?: string;
111111
cacheChunkSize?: number;
112112
};
113113

@@ -148,7 +148,7 @@ async function populateR2IncrementalCache(
148148
],
149149
{
150150
target: populateCacheOptions.target,
151-
configPath: populateCacheOptions.configPath,
151+
configPath: populateCacheOptions.wranglerConfigPath,
152152
// R2 does not support the environment flag and results in the following error:
153153
// Incorrect type for the 'cacheExpiry' field on 'HttpMetadata': the provided value is not of type 'date'.
154154
environment: undefined,
@@ -200,7 +200,7 @@ async function populateKVIncrementalCache(
200200
runWrangler(options, ["kv bulk put", quoteShellMeta(chunkPath), `--binding ${KV_CACHE_BINDING_NAME}`], {
201201
target: populateCacheOptions.target,
202202
environment: populateCacheOptions.environment,
203-
configPath: populateCacheOptions.configPath,
203+
configPath: populateCacheOptions.wranglerConfigPath,
204204
logging: "error",
205205
});
206206

@@ -232,7 +232,7 @@ function populateD1TagCache(
232232
{
233233
target: populateCacheOptions.target,
234234
environment: populateCacheOptions.environment,
235-
configPath: populateCacheOptions.configPath,
235+
configPath: populateCacheOptions.wranglerConfigPath,
236236
logging: "error",
237237
}
238238
);
@@ -313,7 +313,7 @@ async function populateCacheCommand(
313313
await populateCache(options, config, wranglerConfig, {
314314
target,
315315
environment: args.env,
316-
configPath: args.configPath,
316+
wranglerConfigPath: args.wranglerConfigPath,
317317
cacheChunkSize: args.cacheChunkSize,
318318
});
319319
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function previewCommand(args: WithWranglerArgs<{ cacheChunkSize: nu
2727
await populateCache(options, config, wranglerConfig, {
2828
target: "local",
2929
environment: args.env,
30-
configPath: args.configPath,
30+
wranglerConfigPath: args.wranglerConfigPath,
3131
cacheChunkSize: args.cacheChunkSize,
3232
});
3333

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function uploadCommand(args: WithWranglerArgs<{ cacheChunkSize: num
2828
const wranglerConfig = readWranglerConfig(args);
2929

3030
const envVars = await getEnvFromPlatformProxy({
31-
configPath: args.configPath,
31+
configPath: args.wranglerConfigPath,
3232
environment: args.env,
3333
});
3434

@@ -37,7 +37,7 @@ export async function uploadCommand(args: WithWranglerArgs<{ cacheChunkSize: num
3737
await populateCache(options, config, wranglerConfig, {
3838
target: "remote",
3939
environment: args.env,
40-
configPath: args.configPath,
40+
wranglerConfigPath: args.wranglerConfigPath,
4141
cacheChunkSize: args.cacheChunkSize,
4242
});
4343

0 commit comments

Comments
 (0)