@opennextjs/aws 3.1.6 → 3.2.0

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.
Files changed (144) hide show
  1. package/README.md +27 -22
  2. package/dist/adapters/binary.js +2 -0
  3. package/dist/adapters/cache.d.ts +3 -2
  4. package/dist/adapters/cache.js +2 -2
  5. package/dist/adapters/config/util.d.ts +2 -2
  6. package/dist/adapters/image-optimization-adapter.d.ts +2 -2
  7. package/dist/adapters/middleware.js +5 -52
  8. package/dist/adapters/plugins/image-optimization/image-optimization.d.ts +7 -4
  9. package/dist/adapters/plugins/image-optimization/image-optimization.js +2 -3
  10. package/dist/adapters/plugins/image-optimization/image-optimization.replacement.d.ts +3 -0
  11. package/dist/adapters/plugins/image-optimization/image-optimization.replacement.js +4 -7
  12. package/dist/adapters/warmer-function.js +2 -67
  13. package/dist/build/buildNextApp.d.ts +3 -0
  14. package/dist/build/buildNextApp.js +19 -0
  15. package/dist/build/bundleNextServer.js +2 -2
  16. package/dist/build/compileCache.d.ts +9 -0
  17. package/dist/build/compileCache.js +30 -0
  18. package/dist/build/compileConfig.d.ts +17 -3
  19. package/dist/build/compileConfig.js +56 -34
  20. package/dist/build/compileTagCacheProvider.d.ts +2 -0
  21. package/dist/build/compileTagCacheProvider.js +26 -0
  22. package/dist/build/createAssets.d.ts +11 -0
  23. package/dist/build/createAssets.js +161 -0
  24. package/dist/build/createImageOptimizationBundle.d.ts +2 -0
  25. package/dist/build/createImageOptimizationBundle.js +79 -0
  26. package/dist/build/createMiddleware.d.ts +10 -0
  27. package/dist/build/createMiddleware.js +55 -0
  28. package/dist/build/createRevalidationBundle.d.ts +2 -0
  29. package/dist/build/createRevalidationBundle.js +35 -0
  30. package/dist/build/createServerBundle.d.ts +2 -2
  31. package/dist/build/createServerBundle.js +27 -26
  32. package/dist/build/createWarmerBundle.d.ts +2 -0
  33. package/dist/build/createWarmerBundle.js +44 -0
  34. package/dist/build/edge/createEdgeBundle.d.ts +3 -3
  35. package/dist/build/edge/createEdgeBundle.js +3 -5
  36. package/dist/build/helper.d.ts +22 -5
  37. package/dist/build/helper.js +42 -11
  38. package/dist/build/installDeps.d.ts +2 -0
  39. package/dist/build/installDeps.js +36 -0
  40. package/dist/build/utils.d.ts +5 -0
  41. package/dist/build/utils.js +22 -0
  42. package/dist/build/validateConfig.d.ts +1 -1
  43. package/dist/build.d.ts +0 -4
  44. package/dist/build.js +26 -486
  45. package/dist/core/createMainHandler.d.ts +3 -3
  46. package/dist/core/requestHandler.d.ts +2 -2
  47. package/dist/core/requestHandler.js +1 -1
  48. package/dist/core/resolve.d.ts +13 -4
  49. package/dist/core/resolve.js +30 -5
  50. package/dist/core/routing/cacheInterceptor.d.ts +1 -1
  51. package/dist/core/routing/i18n/index.d.ts +1 -1
  52. package/dist/core/routing/i18n/index.js +3 -0
  53. package/dist/core/routing/matcher.d.ts +2 -1
  54. package/dist/core/routing/matcher.js +1 -1
  55. package/dist/core/routing/middleware.d.ts +6 -2
  56. package/dist/core/routing/middleware.js +7 -4
  57. package/dist/core/routing/util.d.ts +3 -2
  58. package/dist/core/routing/util.js +9 -3
  59. package/dist/core/routingHandler.d.ts +1 -1
  60. package/dist/helpers/withCloudflare.d.ts +1 -1
  61. package/dist/helpers/withSST.d.ts +1 -1
  62. package/dist/http/openNextResponse.d.ts +10 -2
  63. package/dist/http/openNextResponse.js +27 -0
  64. package/dist/http/request.d.ts +1 -0
  65. package/dist/http/util.d.ts +1 -1
  66. package/dist/{converters → overrides/converters}/aws-apigw-v1.d.ts +1 -1
  67. package/dist/{converters → overrides/converters}/aws-apigw-v1.js +2 -2
  68. package/dist/{converters → overrides/converters}/aws-apigw-v2.d.ts +1 -1
  69. package/dist/{converters → overrides/converters}/aws-apigw-v2.js +4 -4
  70. package/dist/{converters → overrides/converters}/aws-cloudfront.d.ts +1 -1
  71. package/dist/{converters → overrides/converters}/aws-cloudfront.js +6 -7
  72. package/dist/{converters → overrides/converters}/dummy.d.ts +1 -1
  73. package/dist/overrides/converters/edge.d.ts +6 -0
  74. package/dist/{converters → overrides/converters}/edge.js +1 -1
  75. package/dist/{converters → overrides/converters}/node.d.ts +1 -1
  76. package/dist/{converters → overrides/converters}/node.js +1 -1
  77. package/dist/overrides/converters/sqs-revalidate.d.ts +4 -0
  78. package/dist/overrides/imageLoader/dummy.d.ts +3 -0
  79. package/dist/overrides/imageLoader/dummy.js +8 -0
  80. package/dist/overrides/imageLoader/host.d.ts +1 -1
  81. package/dist/overrides/imageLoader/s3.d.ts +1 -1
  82. package/dist/overrides/incrementalCache/dummy.d.ts +3 -0
  83. package/dist/overrides/incrementalCache/dummy.js +13 -0
  84. package/dist/{cache/incremental → overrides/incrementalCache}/s3-lite.d.ts +1 -1
  85. package/dist/{cache/incremental → overrides/incrementalCache}/s3.d.ts +1 -1
  86. package/dist/{cache/incremental → overrides/incrementalCache}/types.d.ts +1 -1
  87. package/dist/overrides/originResolver/dummy.d.ts +3 -0
  88. package/dist/overrides/originResolver/dummy.js +7 -0
  89. package/dist/overrides/originResolver/pattern-env.d.ts +3 -0
  90. package/dist/overrides/originResolver/pattern-env.js +39 -0
  91. package/dist/overrides/queue/dummy.d.ts +3 -0
  92. package/dist/overrides/queue/dummy.js +7 -0
  93. package/dist/{queue → overrides/queue}/sqs-lite.d.ts +1 -1
  94. package/dist/{queue → overrides/queue}/sqs-lite.js +3 -3
  95. package/dist/{queue → overrides/queue}/sqs.d.ts +1 -1
  96. package/dist/{queue → overrides/queue}/sqs.js +1 -1
  97. package/dist/overrides/tagCache/dummy.d.ts +3 -0
  98. package/dist/overrides/tagCache/dummy.js +17 -0
  99. package/dist/{cache/tag → overrides/tagCache}/dynamodb-lite.d.ts +1 -1
  100. package/dist/{cache/tag → overrides/tagCache}/dynamodb-lite.js +1 -1
  101. package/dist/{cache/tag → overrides/tagCache}/dynamodb.d.ts +1 -1
  102. package/dist/{cache/tag → overrides/tagCache}/dynamodb.js +1 -1
  103. package/dist/overrides/warmer/aws-lambda.d.ts +3 -0
  104. package/dist/overrides/warmer/aws-lambda.js +59 -0
  105. package/dist/overrides/warmer/dummy.d.ts +3 -0
  106. package/dist/overrides/warmer/dummy.js +7 -0
  107. package/dist/overrides/wrappers/aws-lambda-streaming.d.ts +7 -0
  108. package/dist/{wrappers → overrides/wrappers}/aws-lambda-streaming.js +1 -1
  109. package/dist/overrides/wrappers/aws-lambda.d.ts +7 -0
  110. package/dist/{wrappers → overrides/wrappers}/cloudflare.d.ts +2 -2
  111. package/dist/overrides/wrappers/dummy.d.ts +7 -0
  112. package/dist/overrides/wrappers/dummy.js +6 -0
  113. package/dist/overrides/wrappers/node.d.ts +7 -0
  114. package/dist/{wrappers → overrides/wrappers}/node.js +1 -1
  115. package/dist/plugins/edge.d.ts +2 -2
  116. package/dist/plugins/replacement.d.ts +1 -1
  117. package/dist/plugins/resolve.d.ts +4 -2
  118. package/dist/plugins/resolve.js +32 -20
  119. package/dist/types/aws-lambda.d.ts +3 -2
  120. package/dist/{cache/next-types.d.ts → types/cache.d.ts} +1 -0
  121. package/dist/types/next-types.d.ts +3 -1
  122. package/dist/types/open-next.d.ts +39 -13
  123. package/package.json +2 -2
  124. package/dist/converters/edge.d.ts +0 -6
  125. package/dist/converters/sqs-revalidate.d.ts +0 -4
  126. package/dist/wrappers/aws-lambda-streaming.d.ts +0 -7
  127. package/dist/wrappers/aws-lambda.d.ts +0 -7
  128. package/dist/wrappers/node.d.ts +0 -7
  129. /package/dist/{converters → overrides/converters}/dummy.js +0 -0
  130. /package/dist/{converters → overrides/converters}/sqs-revalidate.js +0 -0
  131. /package/dist/{converters → overrides/converters}/utils.d.ts +0 -0
  132. /package/dist/{converters → overrides/converters}/utils.js +0 -0
  133. /package/dist/{cache/incremental → overrides/incrementalCache}/s3-lite.js +0 -0
  134. /package/dist/{cache/incremental → overrides/incrementalCache}/s3.js +0 -0
  135. /package/dist/{cache/incremental → overrides/incrementalCache}/types.js +0 -0
  136. /package/dist/{queue → overrides/queue}/types.d.ts +0 -0
  137. /package/dist/{cache/tag → overrides/queue}/types.js +0 -0
  138. /package/dist/{cache/tag → overrides/tagCache}/constants.d.ts +0 -0
  139. /package/dist/{cache/tag → overrides/tagCache}/constants.js +0 -0
  140. /package/dist/{cache/tag → overrides/tagCache}/types.d.ts +0 -0
  141. /package/dist/{queue → overrides/tagCache}/types.js +0 -0
  142. /package/dist/{wrappers → overrides/wrappers}/aws-lambda.js +0 -0
  143. /package/dist/{wrappers → overrides/wrappers}/cloudflare.js +0 -0
  144. /package/dist/{cache/next-types.js → types/cache.js} +0 -0
@@ -1,12 +1,12 @@
1
1
  import fs from "node:fs";
2
- import { createRequire as topLevelCreateRequire } from "node:module";
2
+ import { createRequire } from "node:module";
3
3
  import path from "node:path";
4
4
  import url from "node:url";
5
- import { build as buildAsync, buildSync, } from "esbuild";
5
+ import { build as buildAsync, buildSync } from "esbuild";
6
6
  import logger from "../logger.js";
7
- const require = topLevelCreateRequire(import.meta.url);
7
+ const require = createRequire(import.meta.url);
8
8
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
9
- export function normalizeOptions(config) {
9
+ 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");
@@ -26,14 +26,16 @@ export function normalizeOptions(config) {
26
26
  appPackageJsonPath,
27
27
  appPath,
28
28
  appPublicPath: path.join(appPath, "public"),
29
+ buildDir: path.join(outputDir, ".build"),
29
30
  config,
30
31
  debug: Boolean(process.env.OPEN_NEXT_DEBUG) ?? false,
31
32
  monorepoRoot,
32
33
  nextVersion: getNextVersion(appPath),
33
34
  openNextVersion: getOpenNextVersion(),
35
+ openNextDistDir: distDir,
34
36
  outputDir,
35
37
  packager,
36
- tempDir: path.join(outputDir, ".build"),
38
+ tempBuildDir,
37
39
  };
38
40
  }
39
41
  function findMonorepoRoot(appPath) {
@@ -56,6 +58,7 @@ function findMonorepoRoot(appPath) {
56
58
  // note: a lock file (package-lock.json, yarn.lock, or pnpm-lock.yaml) is
57
59
  // not found in the app's directory or any of its parent directories.
58
60
  // We are going to assume that the app is not part of a monorepo.
61
+ logger.warn("No lockfile found");
59
62
  return { root: appPath, packager: "npm" };
60
63
  }
61
64
  function findNextPackageJsonPath(appPath, root) {
@@ -158,10 +161,7 @@ export function getHtmlPages(dotNextPath) {
158
161
  return Object.entries(JSON.parse(manifest))
159
162
  .filter(([_, value]) => value.endsWith(".html"))
160
163
  .map(([_, value]) => value.replace(/^pages\//, ""))
161
- .reduce((acc, page) => {
162
- acc.add(page);
163
- return acc;
164
- }, new Set());
164
+ .reduce((acc, page) => acc.add(page), new Set());
165
165
  }
166
166
  export function getBuildId(dotNextPath) {
167
167
  return fs
@@ -200,9 +200,9 @@ export function compareSemver(v1, v2) {
200
200
  return minor1 - minor2;
201
201
  return patch1 - patch2;
202
202
  }
203
- export function copyOpenNextConfig(tempDir, outputPath, isEdge = false) {
203
+ export function copyOpenNextConfig(inputDir, outputDir, isEdge = false) {
204
204
  // Copy open-next.config.mjs
205
- fs.copyFileSync(path.join(tempDir, isEdge ? "open-next.config.edge.mjs" : "open-next.config.mjs"), path.join(outputPath, "open-next.config.mjs"));
205
+ fs.copyFileSync(path.join(inputDir, isEdge ? "open-next.config.edge.mjs" : "open-next.config.mjs"), path.join(outputDir, "open-next.config.mjs"));
206
206
  }
207
207
  export function copyEnvFile(appPath, packagePath, outputPath) {
208
208
  const baseAppPath = path.join(appPath, ".next/standalone", packagePath);
@@ -216,3 +216,34 @@ export function copyEnvFile(appPath, packagePath, outputPath) {
216
216
  fs.copyFileSync(envProdPath, path.join(baseOutputPath, ".env.production"));
217
217
  }
218
218
  }
219
+ /**
220
+ * Check we are in a Nextjs app by looking for the Nextjs config file.
221
+ */
222
+ export function checkRunningInsideNextjsApp(options) {
223
+ const { appPath } = options;
224
+ const extension = ["js", "cjs", "mjs", "ts"].find((ext) => fs.existsSync(path.join(appPath, `next.config.${ext}`)));
225
+ if (!extension) {
226
+ logger.error("Error: next.config.js not found. Please make sure you are running this command inside a Next.js app.");
227
+ process.exit(1);
228
+ }
229
+ }
230
+ export function printNextjsVersion(options) {
231
+ logger.info(`Next.js version : ${options.nextVersion}`);
232
+ }
233
+ export function printOpenNextVersion(options) {
234
+ logger.info(`OpenNext v${options.openNextVersion}`);
235
+ }
236
+ /**
237
+ * Populates the build directory with the compiled configuration files.
238
+ *
239
+ * We need to get the build relative to the cwd to find the compiled config.
240
+ * This is needed for the case where the app is a single-version monorepo
241
+ * and the package.json is in the root of the monorepo where the build is in
242
+ * the app directory, but the compiled config is in the root of the monorepo.
243
+ */
244
+ export function initOutputDir(options) {
245
+ fs.rmSync(options.outputDir, { recursive: true, force: true });
246
+ const { buildDir } = options;
247
+ fs.mkdirSync(buildDir, { recursive: true });
248
+ fs.cpSync(options.tempBuildDir, buildDir, { recursive: true });
249
+ }
@@ -0,0 +1,2 @@
1
+ import type { InstallOptions } from "../types/open-next";
2
+ export declare function installDependencies(outputDir: string, installOptions?: InstallOptions): void;
@@ -0,0 +1,36 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { execSync } from "child_process";
5
+ import logger from "../logger.js";
6
+ export function installDependencies(outputDir, installOptions) {
7
+ try {
8
+ if (!installOptions) {
9
+ return;
10
+ }
11
+ const name = outputDir.split("/").pop();
12
+ // First we create a tempDir
13
+ const tempInstallDir = fs.mkdtempSync(path.join(os.tmpdir(), `open-next-install-${name}`));
14
+ logger.info(`Installing dependencies for ${name}...`);
15
+ // We then need to run install in the tempDir
16
+ // We don't install in the output dir directly because it could contain a package.json, and npm would then try to reinstall not complete deps from tracing the files
17
+ const installCommand = `npm install --arch=${installOptions.arch ?? "arm64"} --platform=linux --target=${installOptions.nodeVersion ?? "18"} --libc=${installOptions.libc ?? "glibc"} ${installOptions.packages.join(" ")}`;
18
+ execSync(installCommand, {
19
+ stdio: "pipe",
20
+ cwd: tempInstallDir,
21
+ env: {
22
+ ...process.env,
23
+ SHARP_IGNORE_GLOBAL_LIBVIPS: "1",
24
+ },
25
+ });
26
+ // Copy the node_modules to the outputDir
27
+ fs.cpSync(path.join(tempInstallDir, "node_modules"), path.join(outputDir, "node_modules"), { recursive: true, force: true, dereference: true });
28
+ // Cleanup tempDir
29
+ fs.rmSync(tempInstallDir, { recursive: true, force: true });
30
+ logger.info(`Dependencies installed for ${name}`);
31
+ }
32
+ catch (e) {
33
+ logger.error(e.stdout.toString());
34
+ logger.error("Could not install dependencies");
35
+ }
36
+ }
@@ -0,0 +1,5 @@
1
+ export declare function printHeader(header: string): void;
2
+ /**
3
+ * Displays a warning on windows platform.
4
+ */
5
+ export declare function showWarningOnWindows(): void;
@@ -0,0 +1,22 @@
1
+ import os from "node:os";
2
+ import logger from "../logger.js";
3
+ export function printHeader(header) {
4
+ header = `OpenNext — ${header}`;
5
+ logger.info([
6
+ "",
7
+ "┌" + "─".repeat(header.length + 2) + "┐",
8
+ `│ ${header} │`,
9
+ "└" + "─".repeat(header.length + 2) + "┘",
10
+ "",
11
+ ].join("\n"));
12
+ }
13
+ /**
14
+ * Displays a warning on windows platform.
15
+ */
16
+ export function showWarningOnWindows() {
17
+ if (os.platform() !== "win32")
18
+ return;
19
+ logger.warn("OpenNext is not fully compatible with Windows.");
20
+ logger.warn("For optimal performance, it is recommended to use Windows Subsystem for Linux (WSL).");
21
+ logger.warn("While OpenNext may function on Windows, it could encounter unpredictable failures during runtime.");
22
+ }
@@ -1,2 +1,2 @@
1
- import { OpenNextConfig } from "../types/open-next";
1
+ import type { OpenNextConfig } from "../types/open-next";
2
2
  export declare function validateConfig(config: OpenNextConfig): void;
package/dist/build.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- import { BuildOptions } from "./build/helper.js";
2
1
  export type PublicFiles = {
3
2
  files: string[];
4
3
  };
5
4
  export declare function build(openNextConfigPath?: string, nodeExternals?: string): Promise<void>;
6
- /***************************/
7
- /***************************/
8
- export declare function compileCache(options: BuildOptions, format?: "cjs" | "esm"): string;