Skip to content

Commit 4c798da

Browse files
committed
fixup! proposal
1 parent b7e76ae commit 4c798da

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

.changeset/lucky-places-occur.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@opennextjs/cloudflare": patch
33
---
44

5-
fix: deprecate usage of the `--configPath` flag for the Wrangler config, in favour of the `--config` flag.
5+
refactor: deprecate usage of the `--configPath` flag for the Wrangler config, in favour of the `--config` flag.

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,27 @@ export async function getLatestCompatDate(): Promise<string | undefined> {
8888
}
8989

9090
/**
91-
* Creates a config file for the user if it doesn't exist, but only after asking for the user's confirmation.
91+
* Creates a `open-next.config.ts` file for the user if it doesn't exist, but only after asking for the user's confirmation.
9292
*
9393
* If the user refuses an error is thrown (since the file is mandatory).
9494
*
95-
* @param configPath The path to the config file, relative to the source directory
9695
* @param sourceDir The source directory for the project
96+
* @return The path to the created source file
9797
*/
98-
export async function createOpenNextConfigIfNotExistent(
99-
configPath: string,
100-
sourceDir: string
101-
): Promise<void> {
102-
const openNextConfigPath = join(sourceDir, configPath);
98+
export async function createOpenNextConfigIfNotExistent(sourceDir: string): Promise<string> {
99+
const openNextConfigPath = join(sourceDir, "open-next.config.ts");
103100

104101
if (!existsSync(openNextConfigPath)) {
105102
const answer = await askConfirmation(
106-
`Missing required \`${configPath}\` file, do you want to create one?`
103+
"Missing required `open-next.config.ts` file, do you want to create one?"
107104
);
108105

109106
if (!answer) {
110-
throw new Error(`The \`${configPath}\` file is required, aborting!`);
107+
throw new Error("The `open-next.config.ts` file is required, aborting!");
111108
}
112109

113110
cpSync(join(getPackageTemplatesDirPath(), "open-next.config.ts"), openNextConfigPath);
114111
}
112+
113+
return openNextConfigPath;
115114
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function buildCommand(
2222
skipNextBuild: boolean;
2323
noMinify: boolean;
2424
skipWranglerConfigCheck: boolean;
25-
openNextConfigPath: string;
25+
openNextConfigPath: string | undefined;
2626
}>
2727
): Promise<void> {
2828
printHeaders("build");
@@ -69,8 +69,7 @@ export function addBuildCommand<T extends yargs.Argv>(y: T) {
6969
})
7070
.option("openNextConfigPath", {
7171
type: "string",
72-
default: "open-next.config.ts",
73-
desc: "Path to OpenNext configuration file, relative to the source directory",
72+
desc: "Path to the OpenNext configuration file",
7473
}),
7574
(args) => buildCommand(withWranglerPassthroughArgs(args))
7675
);

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,27 @@ export function printHeaders(command: string) {
3333
}
3434

3535
/**
36-
* Compile the OpenNext config, and ensure it is for Cloudflare.
36+
* Compile the OpenNext config.
3737
*
38+
* When users do not specify a custom config file (using `----openNextConfigPath`),
39+
* the CLI will offer to create one.
40+
*
41+
* When users specify a custom config file but it doesn't exist, we throw an Error.
42+
*
43+
* @param configPath Optional path to the config file. Absolute or relative to cwd.
3844
* @returns OpenNext config.
3945
*/
40-
export async function compileConfig(configPath: string) {
41-
await createOpenNextConfigIfNotExistent(configPath, nextAppDir);
46+
export async function compileConfig(configPath: string | undefined) {
47+
if (configPath && !existsSync(configPath)) {
48+
throw new Error(`Custom config file not found at ${configPath}`);
49+
}
50+
51+
if (!configPath) {
52+
configPath = await createOpenNextConfigIfNotExistent(nextAppDir);
53+
}
4254

43-
const { config, buildDir } = await compileOpenNextConfig(nextAppDir, configPath, { compileEdge: true });
55+
// TODO: remove the hack passing the `configPath` as the `baseDir` when https://github.com/opennextjs/opennextjs-aws/pull/972 is merged
56+
const { config, buildDir } = await compileOpenNextConfig(configPath, "", { compileEdge: true });
4457
ensureCloudflareConfig(config);
4558

4659
return { config, buildDir };

0 commit comments

Comments
 (0)