Skip to content

Commit 5d1d2c9

Browse files
fixup! create a wrangler.toml file for the user in case one is not already present
fix broken logic and add way to opt out of wrangler config check
1 parent 5046cb0 commit 5d1d2c9

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

packages/cloudflare/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ declare global {
33
interface ProcessEnv {
44
__NEXT_PRIVATE_STANDALONE_CONFIG?: string;
55
SKIP_NEXT_APP_BUILD?: string;
6+
SKIP_WRANGLER_CONFIG_CHECK?: string;
67
NEXT_PRIVATE_DEBUG_CACHE?: string;
78
OPEN_NEXT_ORIGIN: string;
89
NODE_ENV?: string;

packages/cloudflare/src/cli/args.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { parseArgs } from "node:util";
44

55
export function getArgs(): {
66
skipNextBuild: boolean;
7+
skipWranglerConfigCheck: boolean;
78
outputDir?: string;
89
minify: boolean;
910
} {
10-
const { skipBuild, output, noMinify } = parseArgs({
11+
const { skipBuild, skipWranglerConfigCheck, output, noMinify } = parseArgs({
1112
options: {
1213
skipBuild: {
1314
type: "boolean",
@@ -22,6 +23,10 @@ export function getArgs(): {
2223
type: "boolean",
2324
default: false,
2425
},
26+
skipWranglerConfigCheck: {
27+
type: "boolean",
28+
default: false,
29+
},
2530
},
2631
allowPositionals: false,
2732
}).values;
@@ -35,6 +40,9 @@ export function getArgs(): {
3540
return {
3641
outputDir,
3742
skipNextBuild: skipBuild || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD)),
43+
skipWranglerConfigCheck:
44+
skipWranglerConfigCheck ||
45+
["1", "true", "yes"].includes(String(process.env.SKIP_WRANGLER_CONFIG_CHECK)),
3846
minify: !noMinify,
3947
};
4048
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export async function build(projectOpts: ProjectOptions): Promise<void> {
3737
const require = createRequire(import.meta.url);
3838
const openNextDistDir = dirname(require.resolve("@opennextjs/aws/index.js"));
3939

40-
await createWranglerConfigIfNotExistent(projectOpts);
41-
4240
await createOpenNextConfigIfNotExistent(projectOpts);
4341

4442
const { config, buildDir } = await compileOpenNextConfig(baseDir);
@@ -103,6 +101,10 @@ export async function build(projectOpts: ProjectOptions): Promise<void> {
103101
// TODO: rely on options only.
104102
await bundleServer(projConfig, options);
105103

104+
if (!projectOpts.skipWranglerConfigCheck) {
105+
await createWranglerConfigIfNotExistent(projectOpts);
106+
}
107+
106108
logger.info("OpenNext build complete.");
107109
}
108110

@@ -200,10 +202,17 @@ async function createWranglerConfigIfNotExistent(projectOpts: ProjectOptions): P
200202

201203
const wranglerConfigPath = join(projectOpts.sourceDir, "wrangler.jsonc");
202204

203-
const answer = await askConfirmation("Missing required Wrangler config file, do you want to create one?");
205+
const answer = await askConfirmation(
206+
"No `wrangler.(toml|json|jsonc)` config file found, do you want to create one?"
207+
);
204208

205209
if (!answer) {
206-
console.warn("No Wrangler config file created");
210+
console.warn(
211+
"No Wrangler config file created" +
212+
"\n" +
213+
"(to avoid this check use the `--skipWranglerConfigCheck` flag or set a `SKIP_WRANGLER_CONFIG_CHECK` environment variable to `yes`)"
214+
);
215+
return;
207216
}
208217

209218
const wranglerConfigTemplate = readFileSync(

packages/cloudflare/src/cli/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ export type ProjectOptions = {
114114
outputDir: string;
115115
// Whether the Next.js build should be skipped (i.e. if the `.next` dir is already built)
116116
skipNextBuild: boolean;
117+
// Whether the check to see if a wrangler config file exists should be skipped
118+
skipWranglerConfigCheck: boolean;
117119
// Whether minification of the worker should be enabled
118120
minify: boolean;
119121
};

packages/cloudflare/src/cli/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { build } from "./build/index.js";
66

77
const nextAppDir = process.cwd();
88

9-
const { skipNextBuild, outputDir, minify } = getArgs();
9+
const { skipNextBuild, skipWranglerConfigCheck, outputDir, minify } = getArgs();
1010

1111
await build({
1212
sourceDir: nextAppDir,
1313
outputDir: resolve(outputDir ?? nextAppDir, ".open-next"),
1414
skipNextBuild,
15+
skipWranglerConfigCheck,
1516
minify,
1617
});

0 commit comments

Comments
 (0)