@opennextjs/aws 3.9.0 → 3.9.2

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.
@@ -22,7 +22,7 @@ export declare const RoutesManifest: {
22
22
  locales: string[];
23
23
  };
24
24
  export declare const ConfigHeaders: import("../../types/next-types").Header[] | undefined;
25
- export declare const PrerenderManifest: import("../../types/next-types").PrerenderManifest;
25
+ export declare const PrerenderManifest: import("../../types/next-types").PrerenderManifest | undefined;
26
26
  export declare const PagesManifest: Record<string, string>;
27
27
  export declare const AppPathsManifestKeys: string[];
28
28
  export declare const MiddlewareManifest: import("../../types/next-types").MiddlewareManifest;
@@ -22,3 +22,5 @@ export const AppPathRoutesManifest =
22
22
  /* @__PURE__ */ loadAppPathRoutesManifest(NEXT_DIR);
23
23
  export const FunctionsConfigManifest =
24
24
  /* @__PURE__ */ loadFunctionsConfigManifest(NEXT_DIR);
25
+ process.env.NEXT_BUILD_ID = BuildId;
26
+ process.env.NEXT_PREVIEW_MODE_ID = PrerenderManifest?.preview?.previewModeId;
@@ -24,7 +24,7 @@ export declare function loadRoutesManifest(nextDir: string): {
24
24
  locales: string[];
25
25
  };
26
26
  export declare function loadConfigHeaders(nextDir: string): import("../../types/next-types").Header[] | undefined;
27
- export declare function loadPrerenderManifest(nextDir: string): PrerenderManifest;
27
+ export declare function loadPrerenderManifest(nextDir: string): PrerenderManifest | undefined;
28
28
  export declare function loadAppPathsManifest(nextDir: string): Record<string, string>;
29
29
  export declare function loadAppPathRoutesManifest(nextDir: string): Record<string, string>;
30
30
  export declare function loadAppPathsManifestKeys(nextDir: string): string[];
@@ -60,6 +60,9 @@ export function loadConfigHeaders(nextDir) {
60
60
  }
61
61
  export function loadPrerenderManifest(nextDir) {
62
62
  const filePath = path.join(nextDir, "prerender-manifest.json");
63
+ if (!fs.existsSync(filePath)) {
64
+ return undefined;
65
+ }
63
66
  const json = fs.readFileSync(filePath, "utf-8");
64
67
  return JSON.parse(json);
65
68
  }
@@ -1,12 +1,8 @@
1
- // We load every config here so that they are only loaded once
2
- // and during cold starts
3
- import { BuildId } from "./config/index.js";
4
1
  import { createMainHandler } from "../core/createMainHandler.js";
5
2
  import { setNodeEnv } from "./util.js";
6
3
  // We load every config here so that they are only loaded once
7
4
  // and during cold starts
8
5
  setNodeEnv();
9
- setBuildIdEnv();
10
6
  setNextjsServerWorkingDirectory();
11
7
  // Because next is messing with fetch, we have to make sure that we use an untouched version of fetch
12
8
  globalThis.internalFetch = fetch;
@@ -22,8 +18,3 @@ function setNextjsServerWorkingDirectory() {
22
18
  // See https://opennext.js.org/aws/v2/advanced/workaround#workaround-set-nextserver-working-directory-aws-specific
23
19
  process.chdir(__dirname);
24
20
  }
25
- function setBuildIdEnv() {
26
- // This allows users to access the CloudFront invalidating path when doing on-demand
27
- // invalidations. ie. `/_next/data/${process.env.NEXT_BUILD_ID}/foo.json`
28
- process.env.NEXT_BUILD_ID = BuildId;
29
- }
@@ -10,7 +10,7 @@ interface CopyTracedFilesOptions {
10
10
  export declare function getManifests(nextDir: string): {
11
11
  buildId: string;
12
12
  config: import("../types/next-types.js").NextConfig;
13
- prerenderManifest: import("../types/next-types.js").PrerenderManifest;
13
+ prerenderManifest: import("../types/next-types.js").PrerenderManifest | undefined;
14
14
  pagesManifest: Record<string, string>;
15
15
  appPathsManifest: Record<string, string>;
16
16
  middlewareManifest: import("../types/next-types.js").MiddlewareManifest;
@@ -22,7 +22,7 @@ export declare function copyTracedFiles({ buildOutputPath, packagePath, outputDi
22
22
  manifests: {
23
23
  buildId: string;
24
24
  config: import("../types/next-types.js").NextConfig;
25
- prerenderManifest: import("../types/next-types.js").PrerenderManifest;
25
+ prerenderManifest: import("../types/next-types.js").PrerenderManifest | undefined;
26
26
  pagesManifest: Record<string, string>;
27
27
  appPathsManifest: Record<string, string>;
28
28
  middlewareManifest: import("../types/next-types.js").MiddlewareManifest;
@@ -252,7 +252,7 @@ File ${serverPath} does not exist
252
252
  const staticFiles = Object.values(pagesManifest);
253
253
  // Then we need to get all fallback: true dynamic routes html
254
254
  const locales = config.i18n?.locales;
255
- Object.values(prerenderManifest.dynamicRoutes).forEach((route) => {
255
+ Object.values(prerenderManifest?.dynamicRoutes ?? {}).forEach((route) => {
256
256
  if (typeof route.fallback === "string") {
257
257
  if (locales) {
258
258
  locales.forEach((locale) => {
@@ -23,7 +23,7 @@ const NEXT_PRERENDER_HEADER = "x-nextjs-prerender";
23
23
  const NEXT_POSTPONED_HEADER = "x-nextjs-postponed";
24
24
  async function computeCacheControl(path, body, host, revalidate, lastModified) {
25
25
  let finalRevalidate = CACHE_ONE_YEAR;
26
- const existingRoute = Object.entries(PrerenderManifest.routes).find((p) => p[0] === path)?.[1];
26
+ const existingRoute = Object.entries(PrerenderManifest?.routes ?? {}).find((p) => p[0] === path)?.[1];
27
27
  if (revalidate === undefined && existingRoute) {
28
28
  finalRevalidate =
29
29
  existingRoute.initialRevalidateSeconds === false
@@ -202,8 +202,8 @@ export async function cacheInterceptor(event) {
202
202
  // Then we decode the path params
203
203
  localizedPath = decodePathParams(localizedPath);
204
204
  debug("Checking cache for", localizedPath, PrerenderManifest);
205
- const isISR = Object.keys(PrerenderManifest.routes).includes(localizedPath ?? "/") ||
206
- Object.values(PrerenderManifest.dynamicRoutes).some((dr) => new RegExp(dr.routeRegex).test(localizedPath));
205
+ const isISR = Object.keys(PrerenderManifest?.routes ?? {}).includes(localizedPath ?? "/") ||
206
+ Object.values(PrerenderManifest?.dynamicRoutes ?? {}).some((dr) => new RegExp(dr.routeRegex).test(localizedPath));
207
207
  debug("isISR", isISR);
208
208
  if (isISR) {
209
209
  try {
@@ -23,7 +23,7 @@ export declare function handleRewrites<T extends RewriteDefinition>(event: Inter
23
23
  };
24
24
  export declare function handleRedirects(event: InternalEvent, redirects: RedirectDefinition[]): InternalResult | undefined;
25
25
  export declare function fixDataPage(internalEvent: InternalEvent, buildId: string): InternalEvent | InternalResult;
26
- export declare function handleFallbackFalse(internalEvent: InternalEvent, prerenderManifest: PrerenderManifest): {
26
+ export declare function handleFallbackFalse(internalEvent: InternalEvent, prerenderManifest?: PrerenderManifest): {
27
27
  event: InternalEvent;
28
28
  isISR: boolean;
29
29
  };
@@ -294,7 +294,7 @@ export function fixDataPage(internalEvent, buildId) {
294
294
  }
295
295
  export function handleFallbackFalse(internalEvent, prerenderManifest) {
296
296
  const { rawPath } = internalEvent;
297
- const { dynamicRoutes, routes } = prerenderManifest;
297
+ const { dynamicRoutes = {}, routes = {} } = prerenderManifest ?? {};
298
298
  const prerenderedFallbackRoutes = Object.entries(dynamicRoutes).filter(([, { fallback }]) => fallback === false);
299
299
  const routeFallback = prerenderedFallbackRoutes.some(([, { routeRegex }]) => {
300
300
  const routeRegexExp = new RegExp(routeRegex);
@@ -25,7 +25,7 @@ export async function handleMiddleware(internalEvent, initialSearch, middlewareL
25
25
  // The `x-prerender-revalidate` header is set at build time and should be safe to trust
26
26
  if (headers["x-isr"] &&
27
27
  headers["x-prerender-revalidate"] ===
28
- PrerenderManifest.preview.previewModeId)
28
+ PrerenderManifest?.preview?.previewModeId)
29
29
  return internalEvent;
30
30
  // We only need the normalizedPath to check if the middleware should run
31
31
  const normalizedPath = localizePath(internalEvent);
@@ -16,10 +16,19 @@ export function isExternal(url, host) {
16
16
  if (!url)
17
17
  return false;
18
18
  const pattern = /^https?:\/\//;
19
+ if (!pattern.test(url))
20
+ return false;
19
21
  if (host) {
20
- return pattern.test(url) && !url.includes(host);
22
+ try {
23
+ const parsedUrl = new URL(url);
24
+ return parsedUrl.host !== host;
25
+ }
26
+ catch {
27
+ // If URL parsing fails, fall back to substring check
28
+ return !url.includes(host);
29
+ }
21
30
  }
22
- return pattern.test(url);
31
+ return true;
23
32
  }
24
33
  export function convertFromQueryString(query) {
25
34
  if (query === "")
@@ -144,8 +144,8 @@ ${contents}
144
144
  export const FunctionsConfigManifest = ${JSON.stringify(FunctionsConfigManifest)};
145
145
  export const PagesManifest = ${JSON.stringify(PagesManifest)};
146
146
 
147
-
148
147
  process.env.NEXT_BUILD_ID = BuildId;
148
+ process.env.NEXT_PREVIEW_MODE_ID = PrerenderManifest?.preview?.previewModeId;
149
149
  `;
150
150
  return { contents };
151
151
  });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "access": "public"
4
4
  },
5
5
  "name": "@opennextjs/aws",
6
- "version": "3.9.0",
6
+ "version": "3.9.2",
7
7
  "bin": {
8
8
  "open-next": "./dist/index.js"
9
9
  },
@@ -59,6 +59,9 @@
59
59
  "tsc-alias": "^1.8.16",
60
60
  "typescript": "5.9.3"
61
61
  },
62
+ "peerDependencies": {
63
+ "next": "<15 || ~15.4.8 || ~15.5.7 || ^16.0.7"
64
+ },
62
65
  "bugs": {
63
66
  "url": "https://github.com/opennextjs/opennextjs-aws/issues"
64
67
  },