@opennextjs/aws 3.5.1 → 3.5.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.
@@ -2,9 +2,21 @@ import url from "node:url";
2
2
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, readlinkSync, statSync, symlinkSync, writeFileSync, } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { loadConfig, loadPrerenderManifest } from "../adapters/config/util.js";
5
+ import { getCrossPlatformPathRegex } from "../utils/regex.js";
5
6
  import logger from "../logger.js";
6
7
  import { MIDDLEWARE_TRACE_FILE } from "./constant.js";
7
8
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
9
+ //TODO: we need to figure which packages we could safely remove
10
+ const EXCLUDED_PACKAGES = [
11
+ "caniuse-lite",
12
+ "sharp",
13
+ // This seems to be only in Next 15
14
+ // Some of sharp deps are under the @img scope
15
+ "@img",
16
+ ];
17
+ function isExcluded(srcPath) {
18
+ return EXCLUDED_PACKAGES.some((excluded) => srcPath.match(getCrossPlatformPathRegex(`/node_modules/${excluded}/`)));
19
+ }
8
20
  function copyPatchFile(outputDir) {
9
21
  const patchFile = path.join(__dirname, "patch", "patchedAsyncStorage.js");
10
22
  const outputPatchFile = path.join(outputDir, "patchedAsyncStorage.cjs");
@@ -119,11 +131,8 @@ File ${fullFilePath} does not exist
119
131
  });
120
132
  //Actually copy the files
121
133
  filesToCopy.forEach((to, from) => {
122
- if (
123
- //TODO: we need to figure which packages we could safely remove
124
- from.includes(path.join("node_modules", "caniuse-lite")) ||
125
- // from.includes("jest-worker") || This ones seems necessary for next 12
126
- from.includes(path.join("node_modules", "sharp"))) {
134
+ // We don't want to copy excluded packages (i.e sharp)
135
+ if (isExcluded(from)) {
127
136
  return;
128
137
  }
129
138
  mkdirSync(path.dirname(to), { recursive: true });
@@ -3,12 +3,12 @@ import type { InternalEvent, InternalResult } from "../../types/open-next";
3
3
  export declare function getNextConfigHeaders(event: InternalEvent, configHeaders?: Header[] | undefined): Record<string, string | undefined>;
4
4
  export declare function handleRewrites<T extends RewriteDefinition>(event: InternalEvent, rewrites: T[]): {
5
5
  internalEvent: {
6
+ query: Record<string, string | string[]>;
6
7
  rawPath: string;
7
8
  url: string;
8
9
  method: string;
9
10
  body?: Buffer;
10
11
  headers: Record<string, string>;
11
- query: Record<string, string | string[]>;
12
12
  cookies: Record<string, string>;
13
13
  remoteAddress: string;
14
14
  type: "core";
@@ -145,10 +145,17 @@ export function handleRewrites(event, rewrites) {
145
145
  rewrittenHost = unescapeRegex(toDestinationHost(params));
146
146
  rewrittenQuery = unescapeRegex(toDestinationQuery(params));
147
147
  }
148
+ // We need to strip the locale from the path if it's a local api route
149
+ if (NextConfig.i18n && !isExternalRewrite) {
150
+ const strippedPathLocale = rewrittenPath.replace(new RegExp(`^/(${NextConfig.i18n.locales.join("|")})`), "");
151
+ if (strippedPathLocale.startsWith("/api/")) {
152
+ rewrittenPath = strippedPathLocale;
153
+ }
154
+ }
148
155
  rewrittenUrl = isExternalRewrite
149
156
  ? `${protocol}//${rewrittenHost}${rewrittenPath}`
150
157
  : new URL(rewrittenPath, event.url).href;
151
- // Should we merge the query params or use only the ones from the rewrite?
158
+ // We merge query params from the source and the destination
152
159
  finalQuery = {
153
160
  ...query,
154
161
  ...convertFromQueryString(rewrittenQuery),
@@ -159,6 +166,7 @@ export function handleRewrites(event, rewrites) {
159
166
  return {
160
167
  internalEvent: {
161
168
  ...event,
169
+ query: finalQuery,
162
170
  rawPath: new URL(rewrittenUrl).pathname,
163
171
  url: rewrittenUrl,
164
172
  },
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "access": "public"
4
4
  },
5
5
  "name": "@opennextjs/aws",
6
- "version": "3.5.1",
6
+ "version": "3.5.2",
7
7
  "bin": {
8
8
  "open-next": "./dist/index.js"
9
9
  },