@opennextjs/aws 3.9.12 → 3.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,12 +72,36 @@ export type SemverOp = "=" | ">=" | "<=" | ">" | "<";
72
72
  * compareSemver("2.0.0", ">=", "1.0.0") === true
73
73
  */
74
74
  export declare function compareSemver(v1: string, operator: SemverOp, v2: string): boolean;
75
+ /**
76
+ * Check if a Next.js version is supported by the Next.js team.
77
+ * Major versions are supported for 2 years following their initial release.
78
+ *
79
+ * @param version - The Next.js version to check (semver format)
80
+ * @returns true if the version is currently supported, false otherwise
81
+ */
82
+ export declare function isNextVersionSupported(version: string): boolean;
83
+ /**
84
+ * Check if the Next.js version is supported and handle errors/warnings.
85
+ *
86
+ * Note: Exits the process with code 1 if the version is not supported.
87
+ *
88
+ * @param options - Build options containing Next.js version
89
+ * @param allowUnsupportedNextVersion - Whether to allow using an unmaintained Next.js version
90
+ */
91
+ export declare function checkNextVersionSupport(nextVersion: string, allowUnsupportedNextVersion: boolean, flagName?: string): void;
75
92
  export declare function copyOpenNextConfig(inputDir: string, outputDir: string, isEdge?: boolean): void;
76
93
  export declare function copyEnvFile(appPath: string, packagePath: string, outputPath: string): void;
94
+ /**
95
+ * Finds the path to the Next configuration file if it exists.
96
+ *
97
+ * @param appPath The directory to check for the Next config file
98
+ * @returns The full path to Next config file if it exists, undefined otherwise
99
+ */
100
+ export declare function findNextConfig({ appPath, }: Pick<BuildOptions, "appPath">): string | undefined;
77
101
  /**
78
102
  * Check we are in a Nextjs app by looking for the Nextjs config file.
79
103
  */
80
- export declare function checkRunningInsideNextjsApp(options: BuildOptions): void;
104
+ export declare function checkRunningInsideNextjsApp({ appPath, }: Pick<BuildOptions, "appPath">): void;
81
105
  export declare function printNextjsVersion(options: BuildOptions): void;
82
106
  export declare function printOpenNextVersion(options: BuildOptions): void;
83
107
  /**
@@ -269,6 +269,69 @@ export function compareSemver(v1, operator, v2) {
269
269
  throw new Error(`Unsupported operator: ${operator}`);
270
270
  }
271
271
  }
272
+ /**
273
+ * Next.js major version release dates (YYYY-MM-DD).
274
+ * Each major version is supported for 2 years from its release date.
275
+ *
276
+ * Source: https://nextjs.org/support-policy#supported-versions
277
+ *
278
+ * TODO: Update this list when new Next.js major versions are released.
279
+ * Check https://github.com/vercel/next.js/releases for release dates.
280
+ */
281
+ const NEXT_RELEASE_DATES = {
282
+ 16: "2025-10-21",
283
+ 15: "2024-10-21",
284
+ 14: "2023-10-26",
285
+ 13: "2022-10-26",
286
+ 12: "2021-10-26",
287
+ };
288
+ /**
289
+ * Check if a Next.js version is supported by the Next.js team.
290
+ * Major versions are supported for 2 years following their initial release.
291
+ *
292
+ * @param version - The Next.js version to check (semver format)
293
+ * @returns true if the version is currently supported, false otherwise
294
+ */
295
+ export function isNextVersionSupported(version) {
296
+ const match = version.match(/^\d+/);
297
+ if (!match) {
298
+ return false;
299
+ }
300
+ const releaseDateStr = NEXT_RELEASE_DATES[Number(match[0])];
301
+ if (!releaseDateStr) {
302
+ return false;
303
+ }
304
+ const releaseDate = new Date(releaseDateStr);
305
+ const supportEndDate = new Date(releaseDate);
306
+ supportEndDate.setFullYear(supportEndDate.getFullYear() + 2);
307
+ const now = new Date();
308
+ return now <= supportEndDate;
309
+ }
310
+ /**
311
+ * Check if the Next.js version is supported and handle errors/warnings.
312
+ *
313
+ * Note: Exits the process with code 1 if the version is not supported.
314
+ *
315
+ * @param options - Build options containing Next.js version
316
+ * @param allowUnsupportedNextVersion - Whether to allow using an unmaintained Next.js version
317
+ */
318
+ export function checkNextVersionSupport(nextVersion, allowUnsupportedNextVersion, flagName = "--dangerously-use-unsupported-next-version") {
319
+ const isSupported = isNextVersionSupported(nextVersion);
320
+ if (!isSupported) {
321
+ const message = `Next.js version ${nextVersion} is not supported by the Next.js team.
322
+ Major versions are supported for 2 years from their release date.
323
+ Unsupported releases may contain unpatched security vulnerabilities.
324
+ See https://nextjs.org/support-policy for more information.`;
325
+ if (allowUnsupportedNextVersion) {
326
+ logger.warn(`${message}
327
+ Continuing build due to ${flagName} flag.`);
328
+ return;
329
+ }
330
+ logger.error(`${message}
331
+ If you want to proceed anyway, use the ${flagName} flag.`);
332
+ process.exit(1);
333
+ }
334
+ }
272
335
  export function copyOpenNextConfig(inputDir, outputDir, isEdge = false) {
273
336
  // Copy open-next.config.mjs
274
337
  fs.copyFileSync(path.join(inputDir, isEdge ? "open-next.config.edge.mjs" : "open-next.config.mjs"), path.join(outputDir, "open-next.config.mjs"));
@@ -285,13 +348,20 @@ export function copyEnvFile(appPath, packagePath, outputPath) {
285
348
  fs.copyFileSync(envProdPath, path.join(baseOutputPath, ".env.production"));
286
349
  }
287
350
  }
351
+ /**
352
+ * Finds the path to the Next configuration file if it exists.
353
+ *
354
+ * @param appPath The directory to check for the Next config file
355
+ * @returns The full path to Next config file if it exists, undefined otherwise
356
+ */
357
+ export function findNextConfig({ appPath, }) {
358
+ return ["js", "cjs", "mjs", "ts"].find((ext) => fs.existsSync(path.join(appPath, `next.config.${ext}`)));
359
+ }
288
360
  /**
289
361
  * Check we are in a Nextjs app by looking for the Nextjs config file.
290
362
  */
291
- export function checkRunningInsideNextjsApp(options) {
292
- const { appPath } = options;
293
- const extension = ["js", "cjs", "mjs", "ts"].find((ext) => fs.existsSync(path.join(appPath, `next.config.${ext}`)));
294
- if (!extension) {
363
+ export function checkRunningInsideNextjsApp({ appPath, }) {
364
+ if (!findNextConfig({ appPath })) {
295
365
  logger.error("Error: next.config.js not found. Please make sure you are running this command inside a Next.js app.");
296
366
  process.exit(1);
297
367
  }
@@ -1,6 +1,7 @@
1
1
  import type { CodePatcher } from "../codePatcher.js";
2
2
  export declare const disablePreloadingRule = "\nrule:\n kind: statement_block\n inside:\n kind: if_statement\n any:\n - has:\n kind: member_expression\n pattern: this.nextConfig.experimental.preloadEntriesOnStart\n stopBy: end\n - has:\n kind: binary_expression\n pattern: appDocumentPreloading === true\n stopBy: end\nfix:\n '{}'\n";
3
3
  export declare const removeMiddlewareManifestRule = "\nrule:\n kind: statement_block\n inside:\n kind: method_definition\n has:\n kind: property_identifier\n regex: ^getMiddlewareManifest$\nfix:\n '{return null;}'\n";
4
+ export declare const emptyHandleNextImageRequestRule = "\nrule:\n kind: assignment_expression\n pattern: this.handleNextImageRequest = $VALUE\n inside:\n kind: method_definition\n stopBy: end\n has:\n kind: property_identifier\n regex: ^constructor$\n inside:\n kind: class_body\nfix:\n this.handleNextImageRequest = async (req, res, parsedUrl) => false\n";
4
5
  /**
5
6
  * Swaps the body for a throwing implementation
6
7
  *
@@ -30,6 +30,23 @@ rule:
30
30
  fix:
31
31
  '{return null;}'
32
32
  `;
33
+ // Make `handleNextImageRequest` a no-op to avoid pulling `sharp`
34
+ // Apply to Next 14, 15, and 16
35
+ export const emptyHandleNextImageRequestRule = `
36
+ rule:
37
+ kind: assignment_expression
38
+ pattern: this.handleNextImageRequest = $VALUE
39
+ inside:
40
+ kind: method_definition
41
+ stopBy: end
42
+ has:
43
+ kind: property_identifier
44
+ regex: ^constructor$
45
+ inside:
46
+ kind: class_body
47
+ fix:
48
+ this.handleNextImageRequest = async (req, res, parsedUrl) => false
49
+ `;
33
50
  /**
34
51
  * Swaps the body for a throwing implementation
35
52
  *
@@ -81,6 +98,12 @@ export const patchNextServer = {
81
98
  contentFilter: /imageOptimizer\(/,
82
99
  patchCode: createPatchCode(createEmptyBodyRule("imageOptimizer")),
83
100
  },
101
+ // Make `handleNextImageRequest` a no-op to avoid pulling `sharp` - unused in OpenNext
102
+ {
103
+ pathFilter,
104
+ contentFilter: /handleNextImageRequest/,
105
+ patchCode: createPatchCode(emptyHandleNextImageRequestRule),
106
+ },
84
107
  // Disable Next background preloading done at creation of `NextServer`
85
108
  {
86
109
  versions: ">=14.0.0",
package/dist/build.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export type PublicFiles = {
2
2
  files: string[];
3
3
  };
4
- export declare function build(openNextConfigPath?: string, nodeExternals?: string): Promise<void>;
4
+ export declare function build(openNextConfigPath?: string, nodeExternals?: string, allowUnsupportedNextVersion?: boolean): Promise<void>;
package/dist/build.js CHANGED
@@ -15,7 +15,7 @@ import * as buildHelper from "./build/helper.js";
15
15
  import { patchOriginalNextConfig } from "./build/patch/patches/index.js";
16
16
  import { printHeader, showWarningOnWindows } from "./build/utils.js";
17
17
  import logger from "./logger.js";
18
- export async function build(openNextConfigPath, nodeExternals) {
18
+ export async function build(openNextConfigPath, nodeExternals, allowUnsupportedNextVersion) {
19
19
  showWarningOnWindows();
20
20
  const baseDir = process.cwd();
21
21
  const openNextDistDir = url.fileURLToPath(new URL(".", import.meta.url));
@@ -27,6 +27,8 @@ export async function build(openNextConfigPath, nodeExternals) {
27
27
  buildHelper.checkRunningInsideNextjsApp(options);
28
28
  buildHelper.printNextjsVersion(options);
29
29
  buildHelper.printOpenNextVersion(options);
30
+ // Check Next.js version support
31
+ buildHelper.checkNextVersionSupport(options.nextVersion, allowUnsupportedNextVersion ?? false);
30
32
  // Build Next.js app
31
33
  printHeader("Building Next.js app");
32
34
  setStandaloneBuildMode(options);
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ if (command !== "build")
6
6
  const args = parseArgs();
7
7
  if (Object.keys(args).includes("--help"))
8
8
  printHelp();
9
- await build(args["--config-path"], args["--node-externals"]);
9
+ await build(args["--config-path"], args["--node-externals"], args["--dangerously-use-unsupported-next-version"] !== undefined);
10
10
  function parseArgs() {
11
11
  return process.argv.slice(2).reduce((acc, key, ind, self) => {
12
12
  if (key.startsWith("--")) {
@@ -25,14 +25,14 @@ function parseArgs() {
25
25
  }, {});
26
26
  }
27
27
  function printHelp() {
28
- console.log("Unknown command");
29
- console.log("");
30
- console.log("Usage:");
31
- console.log(" npx open-next build");
32
- console.log("You can use a custom config path here");
33
- console.log(" npx open-next build --config-path ./path/to/open-next.config.ts");
34
- console.log("You can configure externals for the esbuild compilation of the open-next.config.ts file");
35
- console.log(" npx open-next build --node-externals aws-sdk,sharp,sqlite3");
36
- console.log("");
28
+ console.log(`Unknown command
29
+
30
+ Usage:
31
+ npx open-next build
32
+ You can use a custom config path here
33
+ npx open-next build --config-path ./path/to/open-next.config.ts
34
+ You can configure externals for the esbuild compilation of the open-next.config.ts file
35
+ npx open-next build --node-externals aws-sdk,sharp,sqlite3
36
+ `);
37
37
  process.exit(1);
38
38
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "access": "public"
4
4
  },
5
5
  "name": "@opennextjs/aws",
6
- "version": "3.9.12",
6
+ "version": "3.9.14",
7
7
  "bin": {
8
8
  "open-next": "./dist/index.js"
9
9
  },
@@ -60,7 +60,7 @@
60
60
  "typescript": "5.9.3"
61
61
  },
62
62
  "peerDependencies": {
63
- "next": "^14.2.35 || ~15.0.7 || ~15.1.11 || ~15.2.8 || ~15.3.8 || ~15.4.10 || ~15.5.9 || ^16.0.10"
63
+ "next": "~15.0.8 || ~15.1.12 || ~15.2.9 || ~15.3.9 || ~15.4.11 || ~15.5.10 || ~16.0.11 || ^16.1.5"
64
64
  },
65
65
  "bugs": {
66
66
  "url": "https://github.com/opennextjs/opennextjs-aws/issues"