@opennextjs/aws 3.9.9 → 3.9.11

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.
@@ -123,7 +123,7 @@ async function generateBundle(name, options, fnOptions, codeCustomization) {
123
123
  patches.patchFetchCacheForISR,
124
124
  patches.patchUnstableCacheForISR,
125
125
  patches.patchNextServer,
126
- patches.patchEnvVars,
126
+ patches.getEnvVarsPatch(options),
127
127
  patches.patchBackgroundRevalidation,
128
128
  patches.patchUseCacheForISR,
129
129
  patches.patchNodeEnvironment,
@@ -15,9 +15,20 @@ export declare function normalizeOptions(config: OpenNextConfig, distDir: string
15
15
  openNextVersion: string;
16
16
  openNextDistDir: string;
17
17
  outputDir: string;
18
- packager: "bun" | "npm" | "yarn" | "pnpm";
18
+ packager: "npm" | "pnpm" | "yarn" | "bun";
19
19
  tempBuildDir: string;
20
20
  };
21
+ /**
22
+ * Given the path to a project this function detects the project's repository root (whether the project is in a simple
23
+ * repository or a monorepo) as well as the package manager being used.
24
+ *
25
+ * @param appPath The project's path
26
+ * @returns An object containing the root of the project's repo/monorepo as well as the package manager that it uses.
27
+ */
28
+ export declare function findPackagerAndRoot(appPath: string): {
29
+ root: string;
30
+ packager: "npm" | "pnpm" | "yarn" | "bun";
31
+ };
21
32
  export declare function esbuildSync(esbuildOptions: ESBuildOptions, options: BuildOptions): void;
22
33
  export declare function esbuildAsync(esbuildOptions: ESBuildOptions, options: BuildOptions): Promise<void>;
23
34
  /**
@@ -83,3 +94,12 @@ export declare function initOutputDir(options: BuildOptions): void;
83
94
  */
84
95
  export declare function isEdgeRuntime(overrides: DefaultOverrideOptions | undefined): Promise<boolean | undefined>;
85
96
  export declare function getPackagePath(options: BuildOptions): string;
97
+ /**
98
+ * Returns the Next.js runtime used: "webpack" or "turbopack"
99
+ *
100
+ * Must be called after building the Next.js app.
101
+ *
102
+ * @param options
103
+ * @returns the Next.js runtime used: "webpack" or "turbopack"
104
+ */
105
+ export declare function getBundlerRuntime(options: BuildOptions): "webpack" | "turbopack";
@@ -10,7 +10,7 @@ export function normalizeOptions(config, distDir, tempBuildDir) {
10
10
  const appPath = path.join(process.cwd(), config.appPath || ".");
11
11
  const buildOutputPath = path.join(process.cwd(), config.buildOutputPath || ".");
12
12
  const outputDir = path.join(buildOutputPath, ".open-next");
13
- const { root: monorepoRoot, packager } = findMonorepoRoot(path.join(process.cwd(), config.appPath || "."));
13
+ const { root: monorepoRoot, packager } = findPackagerAndRoot(path.join(process.cwd(), config.appPath || "."));
14
14
  let appPackageJsonPath;
15
15
  if (config.packageJsonPath) {
16
16
  const _pkgPath = path.join(process.cwd(), config.packageJsonPath);
@@ -41,7 +41,14 @@ export function normalizeOptions(config, distDir, tempBuildDir) {
41
41
  tempBuildDir,
42
42
  };
43
43
  }
44
- function findMonorepoRoot(appPath) {
44
+ /**
45
+ * Given the path to a project this function detects the project's repository root (whether the project is in a simple
46
+ * repository or a monorepo) as well as the package manager being used.
47
+ *
48
+ * @param appPath The project's path
49
+ * @returns An object containing the root of the project's repo/monorepo as well as the package manager that it uses.
50
+ */
51
+ export function findPackagerAndRoot(appPath) {
45
52
  let currentPath = appPath;
46
53
  while (currentPath !== "/") {
47
54
  const found = [
@@ -324,3 +331,21 @@ export async function isEdgeRuntime(overrides) {
324
331
  export function getPackagePath(options) {
325
332
  return path.relative(options.monorepoRoot, options.appBuildOutputPath);
326
333
  }
334
+ /**
335
+ * Returns the Next.js runtime used: "webpack" or "turbopack"
336
+ *
337
+ * Must be called after building the Next.js app.
338
+ *
339
+ * @param options
340
+ * @returns the Next.js runtime used: "webpack" or "turbopack"
341
+ */
342
+ export function getBundlerRuntime(options) {
343
+ const dotNextPath = path.join(options.appPath, ".next");
344
+ if (fs.existsSync(path.join(dotNextPath, "server/webpack-runtime.js"))) {
345
+ return "webpack";
346
+ }
347
+ if (fs.existsSync(path.join(dotNextPath, "server/chunks/[turbopack]_runtime.js"))) {
348
+ return "turbopack";
349
+ }
350
+ throw new Error("Unable to determine Next.js runtime (webpack or turbopack)");
351
+ }
@@ -1,4 +1,4 @@
1
- export { envVarRuleCreator, patchEnvVars } from "./patchEnvVar.js";
1
+ export { getEnvVarsPatch } from "./patchEnvVar.js";
2
2
  export { patchNextServer } from "./patchNextServer.js";
3
3
  export { patchFetchCacheForISR, patchUnstableCacheForISR, patchUseCacheForISR, } from "./patchFetchCacheISR.js";
4
4
  export { patchFetchCacheSetMissingWaitUntil } from "./patchFetchCacheWaitUntil.js";
@@ -1,4 +1,4 @@
1
- export { envVarRuleCreator, patchEnvVars } from "./patchEnvVar.js";
1
+ export { getEnvVarsPatch } from "./patchEnvVar.js";
2
2
  export { patchNextServer } from "./patchNextServer.js";
3
3
  export { patchFetchCacheForISR, patchUnstableCacheForISR, patchUseCacheForISR, } from "./patchFetchCacheISR.js";
4
4
  export { patchFetchCacheSetMissingWaitUntil } from "./patchFetchCacheWaitUntil.js";
@@ -1,3 +1,4 @@
1
+ import * as buildHelper from "../../helper.js";
1
2
  import type { CodePatcher } from "../codePatcher";
2
3
  /**
3
4
  * Creates a rule to replace `process.env.${envVar}` by `value` in the condition of if statements
@@ -7,4 +8,4 @@ import type { CodePatcher } from "../codePatcher";
7
8
  * @returns
8
9
  */
9
10
  export declare const envVarRuleCreator: (envVar: string, value: string) => string;
10
- export declare const patchEnvVars: CodePatcher;
11
+ export declare function getEnvVarsPatch(BuildOptions: buildHelper.BuildOptions): CodePatcher;
@@ -1,3 +1,4 @@
1
+ import * as buildHelper from "../../helper.js";
1
2
  import { createPatchCode } from "../astCodePatcher.js";
2
3
  /**
3
4
  * Creates a rule to replace `process.env.${envVar}` by `value` in the condition of if statements
@@ -18,29 +19,32 @@ rule:
18
19
  fix:
19
20
  '${value}'
20
21
  `;
21
- export const patchEnvVars = {
22
- name: "patch-env-vars",
23
- patches: [
24
- // This patch will set the `NEXT_RUNTIME` env var to "node" to avoid loading unnecessary edge deps at runtime
25
- {
26
- versions: ">=15.0.0",
27
- pathFilter: /module\.compiled\.js$/,
28
- contentFilter: /process\.env\.NEXT_RUNTIME/,
29
- patchCode: createPatchCode(envVarRuleCreator("NEXT_RUNTIME", '"node"')),
30
- },
31
- // This patch will set `NODE_ENV` to production to avoid loading unnecessary dev deps at runtime
32
- {
33
- versions: ">=15.0.0",
34
- pathFilter: /(module\.compiled|react\/index|react\/jsx-runtime|react-dom\/index)\.js$/,
35
- contentFilter: /process\.env\.NODE_ENV/,
36
- patchCode: createPatchCode(envVarRuleCreator("NODE_ENV", '"production"')),
37
- },
38
- // This patch will set `TURBOPACK` env to false to avoid loading turbopack related deps at runtime
39
- {
40
- versions: ">=15.0.0",
41
- pathFilter: /module\.compiled\.js$/,
42
- contentFilter: /process\.env\.TURBOPACK/,
43
- patchCode: createPatchCode(envVarRuleCreator("TURBOPACK", "false")),
44
- },
45
- ],
46
- };
22
+ export function getEnvVarsPatch(BuildOptions) {
23
+ const isTurbopack = buildHelper.getBundlerRuntime(BuildOptions) === "turbopack";
24
+ return {
25
+ name: "patch-env-vars",
26
+ patches: [
27
+ // This patch will set the `NEXT_RUNTIME` env var to "node" to avoid loading unnecessary edge deps at runtime
28
+ {
29
+ versions: ">=15.0.0",
30
+ pathFilter: /module\.compiled\.js$/,
31
+ contentFilter: /process\.env\.NEXT_RUNTIME/,
32
+ patchCode: createPatchCode(envVarRuleCreator("NEXT_RUNTIME", '"node"')),
33
+ },
34
+ // This patch will set `NODE_ENV` to production to avoid loading unnecessary dev deps at runtime
35
+ {
36
+ versions: ">=15.0.0",
37
+ pathFilter: /(module\.compiled|react\/index|react\/jsx-runtime|react-dom\/index)\.js$/,
38
+ contentFilter: /process\.env\.NODE_ENV/,
39
+ patchCode: createPatchCode(envVarRuleCreator("NODE_ENV", '"production"')),
40
+ },
41
+ // This patch will set `TURBOPACK` env to false to avoid loading turbopack related deps at runtime
42
+ {
43
+ versions: ">=15.0.0",
44
+ pathFilter: /module\.compiled\.js$/,
45
+ contentFilter: /process\.env\.TURBOPACK/,
46
+ patchCode: createPatchCode(envVarRuleCreator("TURBOPACK", JSON.stringify(isTurbopack))),
47
+ },
48
+ ],
49
+ };
50
+ }
@@ -1,10 +1,12 @@
1
1
  import * as buildHelper from "../../helper.js";
2
2
  /**
3
- * Next 16.1+ removes `skipTrailingSlashRedirect` from the config in `required-server-files.json`.
3
+ * Next 16.1.0-16.1.4 has missing fields in `required-server-files.json`:
4
+ * - `skipTrailingSlashRedirect`
5
+ * - `serverExternalPackages`
4
6
  *
5
- * This patch adds it back in by compiling and importing the user's `next.config.js` file.
7
+ * This patch adds them back in by compiling and importing the user's `next.config.js` file.
6
8
  *
7
- * It is a regression in https://github.com/vercel/next.js/pull/86830
8
- * TODO(#1082): revisit when Next is fixed
9
+ * It is a regression in https://github.com/vercel/next.js/pull/86830 (16.1.0)
10
+ * Fixed in https://github.com/vercel/next.js/pull/88733 (16.1.4)
9
11
  */
10
12
  export declare function patchOriginalNextConfig(options: buildHelper.BuildOptions): Promise<void>;
@@ -4,15 +4,18 @@ import { build } from "esbuild";
4
4
  import { inlineRequireResolvePlugin } from "../../../plugins/inline-require-resolve.js";
5
5
  import * as buildHelper from "../../helper.js";
6
6
  /**
7
- * Next 16.1+ removes `skipTrailingSlashRedirect` from the config in `required-server-files.json`.
7
+ * Next 16.1.0-16.1.4 has missing fields in `required-server-files.json`:
8
+ * - `skipTrailingSlashRedirect`
9
+ * - `serverExternalPackages`
8
10
  *
9
- * This patch adds it back in by compiling and importing the user's `next.config.js` file.
11
+ * This patch adds them back in by compiling and importing the user's `next.config.js` file.
10
12
  *
11
- * It is a regression in https://github.com/vercel/next.js/pull/86830
12
- * TODO(#1082): revisit when Next is fixed
13
+ * It is a regression in https://github.com/vercel/next.js/pull/86830 (16.1.0)
14
+ * Fixed in https://github.com/vercel/next.js/pull/88733 (16.1.4)
13
15
  */
14
16
  export async function patchOriginalNextConfig(options) {
15
- if (buildHelper.compareSemver(options.nextVersion, "<", "16.1.0")) {
17
+ if (buildHelper.compareSemver(options.nextVersion, "<", "16.1.0") ||
18
+ buildHelper.compareSemver(options.nextVersion, ">=", "16.1.4")) {
16
19
  return;
17
20
  }
18
21
  // The manifests in both `.next` and `.next/standalone` folders
@@ -22,9 +25,10 @@ export async function patchOriginalNextConfig(options) {
22
25
  if (fs.existsSync(manifestPath)) {
23
26
  const manifest = JSON.parse(await fs.promises.readFile(manifestPath, "utf-8"));
24
27
  if (manifest.config.skipTrailingSlashRedirect === undefined) {
25
- const { skipTrailingSlashRedirect } = await importNextConfigFromSource(options);
28
+ const { skipTrailingSlashRedirect, serverExternalPackages } = await importNextConfigFromSource(options);
26
29
  manifest.config.skipTrailingSlashRedirect =
27
30
  skipTrailingSlashRedirect ?? false;
31
+ manifest.config.serverExternalPackages = serverExternalPackages ?? [];
28
32
  await fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2), "utf-8");
29
33
  if (fs.existsSync(manifestStandalonePath)) {
30
34
  await fs.promises.writeFile(manifestStandalonePath, JSON.stringify(manifest, null, 2), "utf-8");
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "access": "public"
4
4
  },
5
5
  "name": "@opennextjs/aws",
6
- "version": "3.9.9",
6
+ "version": "3.9.11",
7
7
  "bin": {
8
8
  "open-next": "./dist/index.js"
9
9
  },