Skip to content

Commit 4279043

Browse files
authored
Check for supported Next version (#1092)
1 parent 397f035 commit 4279043

7 files changed

Lines changed: 34 additions & 11 deletions

File tree

.changeset/six-walls-feel.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
Check for supported Next version
6+
7+
The build will now error for unsupported Next version which may contain unpatched security vulnerabilities.
8+
You can bypass the check using the `--dangerouslyUseUnsupportedNextVersion` flag.

examples/playground14/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "next build",
99
"start": "next start",
1010
"lint": "next lint",
11-
"build:worker": "pnpm opennextjs-cloudflare build",
11+
"build:worker": "pnpm opennextjs-cloudflare build --dangerouslyUseUnsupportedNextVersion",
1212
"preview:worker": "pnpm opennextjs-cloudflare preview",
1313
"preview": "pnpm build:worker && pnpm preview:worker",
1414
"e2e": "playwright test -c e2e/playwright.config.ts",

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"dependencies": {
5555
"@ast-grep/napi": "0.40.0",
5656
"@dotenvx/dotenvx": "catalog:",
57-
"@opennextjs/aws": "3.9.12",
57+
"@opennextjs/aws": "3.9.13",
5858
"cloudflare": "^4.4.1",
5959
"enquirer": "^2.4.1",
6060
"glob": "catalog:",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export async function build(
3434
options: buildHelper.BuildOptions,
3535
config: OpenNextConfig,
3636
projectOpts: ProjectOptions,
37-
wranglerConfig: Unstable_Config
37+
wranglerConfig: Unstable_Config,
38+
allowUnsupportedNextVersions: boolean
3839
): Promise<void> {
3940
// Do not minify the code so that we can apply string replacement patch.
4041
options.minify = false;
@@ -44,6 +45,11 @@ export async function build(
4445
logger.info(`App directory: ${options.appPath}`);
4546
buildHelper.printNextjsVersion(options);
4647
await ensureNextjsVersionSupported(options);
48+
buildHelper.checkNextVersionSupport(
49+
options.nextVersion,
50+
allowUnsupportedNextVersions,
51+
`--dangerouslyUseUnsupportedNextVersion`
52+
);
4753
const { aws, cloudflare } = getVersion();
4854
logger.info(`@opennextjs/cloudflare version: ${cloudflare}`);
4955
logger.info(`@opennextjs/aws version: ${aws}`);

packages/cloudflare/src/cli/build/utils/version.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { createRequire } from "node:module";
22
import { join } from "node:path";
33
import { fileURLToPath, URL } from "node:url";
44

5-
export function getVersion() {
5+
/**
6+
* Returns the version of the Cloudflare package and its AWS dependency.
7+
*/
8+
export function getVersion(): { cloudflare: string; aws: string } {
69
const require = createRequire(import.meta.url);
710
const __dirname = fileURLToPath(new URL(".", import.meta.url));
811
const pkgJson = require(join(__dirname, "../../../../package.json"));

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async function buildCommand(
2424
noMinify: boolean;
2525
skipWranglerConfigCheck: boolean;
2626
openNextConfigPath: string | undefined;
27+
dangerouslyUseUnsupportedNextVersion: boolean;
2728
}>
2829
): Promise<void> {
2930
printHeaders("build");
@@ -42,7 +43,7 @@ async function buildCommand(
4243

4344
const wranglerConfig = await readWranglerConfig(args);
4445

45-
await buildImpl(options, config, projectOpts, wranglerConfig);
46+
await buildImpl(options, config, projectOpts, wranglerConfig, args.dangerouslyUseUnsupportedNextVersion);
4647
}
4748

4849
/**
@@ -75,6 +76,11 @@ export function addBuildCommand<T extends yargs.Argv>(y: T) {
7576
.option("openNextConfigPath", {
7677
type: "string",
7778
desc: "Path to the OpenNext configuration file",
79+
})
80+
.option("dangerouslyUseUnsupportedNextVersion", {
81+
type: "boolean",
82+
default: false,
83+
desc: "Allow using unsupported Next.js versions",
7884
}),
7985
(args) => buildCommand(withWranglerPassthroughArgs(args))
8086
);

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)