@opennextjs/aws 3.2.1 → 3.2.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.
- package/README.md +15 -1
- package/dist/adapters/cache.d.ts +0 -23
- package/dist/adapters/cache.js +10 -12
- package/dist/adapters/config/index.js +1 -1
- package/dist/adapters/config/util.js +2 -2
- package/dist/adapters/dynamo-provider.js +3 -5
- package/dist/adapters/edge-adapter.d.ts +0 -3
- package/dist/adapters/edge-adapter.js +43 -38
- package/dist/adapters/image-optimization-adapter.js +4 -4
- package/dist/adapters/logger.d.ts +0 -3
- package/dist/adapters/logger.js +3 -5
- package/dist/adapters/middleware.js +42 -18
- package/dist/adapters/plugins/image-optimization/image-optimization.d.ts +0 -3
- package/dist/adapters/plugins/image-optimization/image-optimization.replacement.d.ts +0 -3
- package/dist/adapters/revalidate.js +2 -2
- package/dist/adapters/server-adapter.d.ts +0 -3
- package/dist/adapters/server-adapter.js +3 -1
- package/dist/adapters/util.js +2 -2
- package/dist/build/bundleNextServer.d.ts +3 -1
- package/dist/build/bundleNextServer.js +3 -3
- package/dist/build/compileConfig.js +1 -1
- package/dist/build/copyTracedFiles.js +14 -25
- package/dist/build/createAssets.js +35 -26
- package/dist/build/createImageOptimizationBundle.js +1 -1
- package/dist/build/createMiddleware.js +7 -2
- package/dist/build/createRevalidationBundle.js +1 -1
- package/dist/build/createServerBundle.js +23 -29
- package/dist/build/createWarmerBundle.js +1 -1
- package/dist/build/edge/createEdgeBundle.d.ts +7 -3
- package/dist/build/edge/createEdgeBundle.js +12 -5
- package/dist/build/generateOutput.js +7 -13
- package/dist/build/helper.d.ts +22 -4
- package/dist/build/helper.js +26 -12
- package/dist/build/installDeps.js +1 -1
- package/dist/build/patch/patchedAsyncStorage.js +1 -1
- package/dist/build/utils.js +3 -2
- package/dist/build/validateConfig.js +1 -0
- package/dist/core/createGenericHandler.d.ts +2 -4
- package/dist/core/createGenericHandler.js +1 -2
- package/dist/core/createMainHandler.d.ts +0 -17
- package/dist/core/createMainHandler.js +5 -4
- package/dist/core/edgeFunctionHandler.d.ts +1 -51
- package/dist/core/patchAsyncStorage.js +5 -6
- package/dist/core/requestHandler.js +98 -89
- package/dist/core/require-hooks.js +8 -7
- package/dist/core/resolve.d.ts +13 -7
- package/dist/core/resolve.js +29 -35
- package/dist/core/routing/cacheInterceptor.js +12 -13
- package/dist/core/routing/i18n/accept-header.js +3 -2
- package/dist/core/routing/matcher.d.ts +2 -4
- package/dist/core/routing/matcher.js +17 -26
- package/dist/core/routing/middleware.js +17 -16
- package/dist/core/routing/util.d.ts +0 -13
- package/dist/core/routing/util.js +25 -87
- package/dist/core/routingHandler.d.ts +2 -0
- package/dist/core/routingHandler.js +30 -12
- package/dist/core/util.js +5 -3
- package/dist/helpers/withSST.d.ts +1 -1
- package/dist/http/openNextResponse.d.ts +5 -9
- package/dist/http/openNextResponse.js +29 -31
- package/dist/http/request.d.ts +0 -3
- package/dist/http/request.js +4 -2
- package/dist/http/util.d.ts +1 -1
- package/dist/http/util.js +8 -12
- package/dist/minimize-js.js +19 -19
- package/dist/overrides/converters/aws-apigw-v1.d.ts +2 -2
- package/dist/overrides/converters/aws-apigw-v1.js +2 -1
- package/dist/overrides/converters/aws-apigw-v2.d.ts +2 -2
- package/dist/overrides/converters/aws-apigw-v2.js +6 -7
- package/dist/overrides/converters/aws-cloudfront.d.ts +2 -2
- package/dist/overrides/converters/aws-cloudfront.js +11 -30
- package/dist/overrides/converters/dummy.d.ts +1 -1
- package/dist/overrides/converters/edge.d.ts +2 -1
- package/dist/overrides/converters/edge.js +11 -15
- package/dist/overrides/converters/node.d.ts +1 -1
- package/dist/overrides/converters/node.js +1 -1
- package/dist/overrides/converters/sqs-revalidate.d.ts +1 -1
- package/dist/overrides/imageLoader/dummy.d.ts +1 -1
- package/dist/overrides/imageLoader/host.d.ts +1 -1
- package/dist/overrides/imageLoader/s3.d.ts +1 -1
- package/dist/overrides/imageLoader/s3.js +1 -1
- package/dist/overrides/incrementalCache/dummy.d.ts +1 -1
- package/dist/overrides/incrementalCache/s3-lite.d.ts +1 -1
- package/dist/overrides/incrementalCache/s3-lite.js +15 -19
- package/dist/overrides/incrementalCache/s3.d.ts +1 -1
- package/dist/overrides/incrementalCache/s3.js +1 -1
- package/dist/overrides/originResolver/dummy.d.ts +1 -1
- package/dist/overrides/originResolver/pattern-env.d.ts +1 -1
- package/dist/overrides/originResolver/pattern-env.js +10 -11
- package/dist/overrides/proxyExternalRequest/dummy.d.ts +3 -0
- package/dist/overrides/proxyExternalRequest/dummy.js +7 -0
- package/dist/overrides/proxyExternalRequest/fetch.d.ts +3 -0
- package/dist/overrides/proxyExternalRequest/fetch.js +25 -0
- package/dist/overrides/proxyExternalRequest/node.d.ts +3 -0
- package/dist/overrides/proxyExternalRequest/node.js +67 -0
- package/dist/overrides/queue/dummy.d.ts +1 -1
- package/dist/overrides/queue/sqs-lite.d.ts +1 -1
- package/dist/overrides/queue/sqs-lite.js +7 -9
- package/dist/overrides/queue/sqs.d.ts +1 -1
- package/dist/overrides/queue/sqs.js +1 -1
- package/dist/overrides/tagCache/constants.js +2 -2
- package/dist/overrides/tagCache/dummy.d.ts +1 -1
- package/dist/overrides/tagCache/dynamodb-lite.d.ts +1 -1
- package/dist/overrides/tagCache/dynamodb-lite.js +10 -12
- package/dist/overrides/tagCache/dynamodb.d.ts +1 -1
- package/dist/overrides/tagCache/dynamodb.js +2 -2
- package/dist/overrides/warmer/aws-lambda.d.ts +1 -1
- package/dist/overrides/warmer/dummy.d.ts +1 -1
- package/dist/overrides/wrappers/aws-lambda-streaming.d.ts +2 -2
- package/dist/overrides/wrappers/aws-lambda.d.ts +2 -2
- package/dist/overrides/wrappers/cloudflare.d.ts +2 -1
- package/dist/overrides/wrappers/cloudflare.js +20 -2
- package/dist/overrides/wrappers/dummy.d.ts +2 -2
- package/dist/overrides/wrappers/node.d.ts +2 -2
- package/dist/overrides/wrappers/node.js +3 -3
- package/dist/plugins/edge.js +6 -5
- package/dist/plugins/replacement.js +2 -2
- package/dist/plugins/resolve.d.ts +3 -1
- package/dist/plugins/resolve.js +4 -1
- package/dist/types/aws-lambda.d.ts +2 -5
- package/dist/types/cache.d.ts +0 -2
- package/dist/types/global.d.ts +188 -0
- package/dist/types/next-types.d.ts +1 -3
- package/dist/types/open-next.d.ts +15 -41
- package/dist/types/overrides.d.ts +87 -0
- package/dist/utils/promise.d.ts +3 -0
- package/dist/utils/promise.js +44 -0
- package/dist/utils/stream.d.ts +0 -1
- package/package.json +2 -2
- package/dist/overrides/incrementalCache/types.d.ts +0 -34
- package/dist/overrides/queue/types.d.ts +0 -12
- package/dist/overrides/tagCache/types.d.ts +0 -11
- package/dist/overrides/tagCache/types.js +0 -1
- /package/dist/{overrides/incrementalCache/types.js → types/global.js} +0 -0
- /package/dist/{overrides/queue/types.js → types/overrides.js} +0 -0
|
@@ -4,17 +4,22 @@ import { isBinaryContentType } from "../adapters/binary.js";
|
|
|
4
4
|
import logger from "../logger.js";
|
|
5
5
|
import * as buildHelper from "./helper.js";
|
|
6
6
|
export function createStaticAssets(options) {
|
|
7
|
-
logger.info(
|
|
7
|
+
logger.info("Bundling static assets...");
|
|
8
8
|
const { appBuildOutputPath, appPublicPath, outputDir, appPath } = options;
|
|
9
9
|
// Create output folder
|
|
10
10
|
const outputPath = path.join(outputDir, "assets");
|
|
11
11
|
fs.mkdirSync(outputPath, { recursive: true });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Next.js outputs assets into multiple files. Copy into the same directory.
|
|
14
|
+
*
|
|
15
|
+
* Copy over:
|
|
16
|
+
* - .next/BUILD_ID => BUILD_ID
|
|
17
|
+
* - .next/static => _next/static
|
|
18
|
+
* - public/* => *
|
|
19
|
+
* - app/favicon.ico or src/app/favicon.ico => favicon.ico
|
|
20
|
+
*
|
|
21
|
+
* Note: BUILD_ID is used by the SST infra.
|
|
22
|
+
*/
|
|
18
23
|
fs.copyFileSync(path.join(appBuildOutputPath, ".next/BUILD_ID"), path.join(outputPath, "BUILD_ID"));
|
|
19
24
|
fs.cpSync(path.join(appBuildOutputPath, ".next/static"), path.join(outputPath, "_next", "static"), { recursive: true });
|
|
20
25
|
if (fs.existsSync(appPublicPath)) {
|
|
@@ -24,7 +29,9 @@ export function createStaticAssets(options) {
|
|
|
24
29
|
? "src/app"
|
|
25
30
|
: "app";
|
|
26
31
|
const faviconPath = path.join(appPath, appSrcPath, "favicon.ico");
|
|
27
|
-
if
|
|
32
|
+
// We need to check if the favicon is either a file or directory.
|
|
33
|
+
// If it's a directory, we assume it's a route handler and ignore it.
|
|
34
|
+
if (fs.existsSync(faviconPath) && fs.lstatSync(faviconPath).isFile()) {
|
|
28
35
|
fs.copyFileSync(faviconPath, path.join(outputPath, "favicon.ico"));
|
|
29
36
|
}
|
|
30
37
|
}
|
|
@@ -35,7 +42,7 @@ export function createStaticAssets(options) {
|
|
|
35
42
|
* @returns Whether tag cache is used.
|
|
36
43
|
*/
|
|
37
44
|
export function createCacheAssets(options) {
|
|
38
|
-
logger.info(
|
|
45
|
+
logger.info("Bundling cache assets...");
|
|
39
46
|
const { appBuildOutputPath, outputDir } = options;
|
|
40
47
|
const packagePath = path.relative(options.monorepoRoot, appBuildOutputPath);
|
|
41
48
|
const buildId = buildHelper.getBuildId(appBuildOutputPath);
|
|
@@ -49,27 +56,29 @@ export function createCacheAssets(options) {
|
|
|
49
56
|
.forEach((dir) => fs.cpSync(dir, outputPath, { recursive: true }));
|
|
50
57
|
// Remove non-cache files
|
|
51
58
|
const htmlPages = buildHelper.getHtmlPages(dotNextPath);
|
|
52
|
-
buildHelper.removeFiles(outputPath, (
|
|
53
|
-
|
|
54
|
-
(
|
|
59
|
+
buildHelper.removeFiles(outputPath, ({ relativePath }) => relativePath.endsWith(".js") ||
|
|
60
|
+
relativePath.endsWith(".js.nft.json") ||
|
|
61
|
+
(relativePath.endsWith(".html") && htmlPages.has(relativePath)));
|
|
55
62
|
// Merge cache files into a single file
|
|
56
63
|
const cacheFilesPath = {};
|
|
57
|
-
buildHelper.traverseFiles(outputPath, () => true, (
|
|
58
|
-
const ext = path.extname(
|
|
64
|
+
buildHelper.traverseFiles(outputPath, () => true, ({ absolutePath }) => {
|
|
65
|
+
const ext = path.extname(absolutePath);
|
|
59
66
|
switch (ext) {
|
|
60
67
|
case ".meta":
|
|
61
68
|
case ".html":
|
|
62
69
|
case ".json":
|
|
63
70
|
case ".body":
|
|
64
|
-
case ".rsc":
|
|
65
|
-
const newFilePath =
|
|
66
|
-
.substring(0,
|
|
67
|
-
.replace(/\.prefetch$/, "")
|
|
71
|
+
case ".rsc": {
|
|
72
|
+
const newFilePath = absolutePath
|
|
73
|
+
.substring(0, absolutePath.length - ext.length)
|
|
74
|
+
.replace(/\.prefetch$/, "")
|
|
75
|
+
.concat(".cache");
|
|
68
76
|
cacheFilesPath[newFilePath] = {
|
|
69
|
-
[ext.slice(1)]:
|
|
77
|
+
[ext.slice(1)]: absolutePath,
|
|
70
78
|
...cacheFilesPath[newFilePath],
|
|
71
79
|
};
|
|
72
80
|
break;
|
|
81
|
+
}
|
|
73
82
|
case ".map":
|
|
74
83
|
break;
|
|
75
84
|
default:
|
|
@@ -106,8 +115,8 @@ export function createCacheAssets(options) {
|
|
|
106
115
|
const metaFiles = [];
|
|
107
116
|
// Compute dynamodb cache data
|
|
108
117
|
// Traverse files inside cache to find all meta files and cache tags associated with them
|
|
109
|
-
buildHelper.traverseFiles(outputPath, (
|
|
110
|
-
const fileContent = fs.readFileSync(
|
|
118
|
+
buildHelper.traverseFiles(outputPath, ({ absolutePath }) => absolutePath.endsWith(".meta"), ({ absolutePath, relativePath }) => {
|
|
119
|
+
const fileContent = fs.readFileSync(absolutePath, "utf8");
|
|
111
120
|
const fileData = JSON.parse(fileContent);
|
|
112
121
|
if (fileData.headers?.["x-next-cache-tags"]) {
|
|
113
122
|
fileData.headers["x-next-cache-tags"]
|
|
@@ -117,7 +126,7 @@ export function createCacheAssets(options) {
|
|
|
117
126
|
metaFiles.push({
|
|
118
127
|
tag: { S: path.posix.join(buildId, tag.trim()) },
|
|
119
128
|
path: {
|
|
120
|
-
S: path.posix.join(buildId,
|
|
129
|
+
S: path.posix.join(buildId, relativePath.replace(".meta", "")),
|
|
121
130
|
},
|
|
122
131
|
// We don't care about the revalidation time here, we just need to make sure it's there
|
|
123
132
|
revalidatedAt: { N: "1" },
|
|
@@ -131,14 +140,14 @@ export function createCacheAssets(options) {
|
|
|
131
140
|
const fetchOutputPath = path.join(outputDir, "cache", "__fetch", buildId);
|
|
132
141
|
fs.mkdirSync(fetchOutputPath, { recursive: true });
|
|
133
142
|
fs.cpSync(fetchCachePath, fetchOutputPath, { recursive: true });
|
|
134
|
-
buildHelper.traverseFiles(fetchCachePath, () => true, (
|
|
135
|
-
const fileContent = fs.readFileSync(
|
|
143
|
+
buildHelper.traverseFiles(fetchCachePath, () => true, ({ absolutePath, relativePath }) => {
|
|
144
|
+
const fileContent = fs.readFileSync(absolutePath, "utf8");
|
|
136
145
|
const fileData = JSON.parse(fileContent);
|
|
137
146
|
fileData?.tags?.forEach((tag) => {
|
|
138
147
|
metaFiles.push({
|
|
139
148
|
tag: { S: path.posix.join(buildId, tag) },
|
|
140
149
|
path: {
|
|
141
|
-
S: path.posix.join(buildId,
|
|
150
|
+
S: path.posix.join(buildId, relativePath),
|
|
142
151
|
},
|
|
143
152
|
revalidatedAt: { N: "1" },
|
|
144
153
|
});
|
|
@@ -156,6 +165,6 @@ export function createCacheAssets(options) {
|
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
167
|
// We need to remove files later because we need the metafiles for dynamodb tags cache
|
|
159
|
-
buildHelper.removeFiles(outputPath, (
|
|
168
|
+
buildHelper.removeFiles(outputPath, ({ relativePath }) => !relativePath.endsWith(".cache"));
|
|
160
169
|
return { useTagCache };
|
|
161
170
|
}
|
|
@@ -8,7 +8,7 @@ import * as buildHelper from "./helper.js";
|
|
|
8
8
|
import { installDependencies } from "./installDeps.js";
|
|
9
9
|
const require = createRequire(import.meta.url);
|
|
10
10
|
export async function createImageOptimizationBundle(options) {
|
|
11
|
-
logger.info(
|
|
11
|
+
logger.info("Bundling image optimization function...");
|
|
12
12
|
const { appBuildOutputPath, config, outputDir } = options;
|
|
13
13
|
// Create output folder
|
|
14
14
|
const outputPath = path.join(outputDir, "image-optimization-function");
|
|
@@ -11,7 +11,7 @@ import { installDependencies } from "./installDeps.js";
|
|
|
11
11
|
* @param forceOnlyBuildOnce force to build only once.
|
|
12
12
|
*/
|
|
13
13
|
export async function createMiddleware(options, { forceOnlyBuildOnce = false } = {}) {
|
|
14
|
-
logger.info(
|
|
14
|
+
logger.info("Bundling middleware function...");
|
|
15
15
|
const { appBuildOutputPath, config, outputDir } = options;
|
|
16
16
|
// Get middleware manifest
|
|
17
17
|
const middlewareManifest = JSON.parse(fs.readFileSync(path.join(appBuildOutputPath, ".next/server/middleware-manifest.json"), "utf8"));
|
|
@@ -27,11 +27,15 @@ export async function createMiddleware(options, { forceOnlyBuildOnce = false } =
|
|
|
27
27
|
outfile: path.join(outputPath, "handler.mjs"),
|
|
28
28
|
middlewareInfo,
|
|
29
29
|
options,
|
|
30
|
-
overrides:
|
|
30
|
+
overrides: {
|
|
31
|
+
...config.middleware.override,
|
|
32
|
+
originResolver: config.middleware.originResolver,
|
|
33
|
+
},
|
|
31
34
|
defaultConverter: "aws-cloudfront",
|
|
32
35
|
includeCache: config.dangerous?.enableCacheInterception,
|
|
33
36
|
additionalExternals: config.edgeExternals,
|
|
34
37
|
onlyBuildOnce: forceOnlyBuildOnce === true,
|
|
38
|
+
name: "middleware",
|
|
35
39
|
});
|
|
36
40
|
installDependencies(outputPath, config.middleware?.install);
|
|
37
41
|
}
|
|
@@ -42,6 +46,7 @@ export async function createMiddleware(options, { forceOnlyBuildOnce = false } =
|
|
|
42
46
|
middlewareInfo,
|
|
43
47
|
options,
|
|
44
48
|
onlyBuildOnce: true,
|
|
49
|
+
name: "middleware",
|
|
45
50
|
});
|
|
46
51
|
}
|
|
47
52
|
}
|
|
@@ -5,7 +5,7 @@ import { openNextResolvePlugin } from "../plugins/resolve.js";
|
|
|
5
5
|
import * as buildHelper from "./helper.js";
|
|
6
6
|
import { installDependencies } from "./installDeps.js";
|
|
7
7
|
export async function createRevalidationBundle(options) {
|
|
8
|
-
logger.info(
|
|
8
|
+
logger.info("Bundling revalidation function...");
|
|
9
9
|
const { appBuildOutputPath, config, outputDir } = options;
|
|
10
10
|
// Create output folder
|
|
11
11
|
const outputPath = path.join(outputDir, "revalidation-function");
|
|
@@ -42,28 +42,22 @@ export async function createServerBundle(options) {
|
|
|
42
42
|
// Find app dir routes
|
|
43
43
|
if (fs.existsSync(path.join(serverPath, "app"))) {
|
|
44
44
|
const appPath = path.join(serverPath, "app");
|
|
45
|
-
buildHelper.traverseFiles(appPath, (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
remainingRoutes.add(route);
|
|
50
|
-
}
|
|
45
|
+
buildHelper.traverseFiles(appPath, ({ relativePath }) => relativePath.endsWith("page.js") || relativePath.endsWith("route.js"), ({ relativePath }) => {
|
|
46
|
+
const route = `app/${relativePath.replace(/\.js$/, "")}`;
|
|
47
|
+
if (!foundRoutes.has(route)) {
|
|
48
|
+
remainingRoutes.add(route);
|
|
51
49
|
}
|
|
52
|
-
|
|
53
|
-
}, () => { });
|
|
50
|
+
});
|
|
54
51
|
}
|
|
55
52
|
// Find pages dir routes
|
|
56
53
|
if (fs.existsSync(path.join(serverPath, "pages"))) {
|
|
57
54
|
const pagePath = path.join(serverPath, "pages");
|
|
58
|
-
buildHelper.traverseFiles(pagePath, (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
remainingRoutes.add(route);
|
|
63
|
-
}
|
|
55
|
+
buildHelper.traverseFiles(pagePath, ({ relativePath }) => relativePath.endsWith(".js"), ({ relativePath }) => {
|
|
56
|
+
const route = `pages/${relativePath.replace(/\.js$/, "")}`;
|
|
57
|
+
if (!foundRoutes.has(route)) {
|
|
58
|
+
remainingRoutes.add(route);
|
|
64
59
|
}
|
|
65
|
-
|
|
66
|
-
}, () => { });
|
|
60
|
+
});
|
|
67
61
|
}
|
|
68
62
|
// Generate default function
|
|
69
63
|
await generateBundle("default", options, {
|
|
@@ -94,7 +88,9 @@ async function generateBundle(name, options, fnOptions) {
|
|
|
94
88
|
// Bundle next server if necessary
|
|
95
89
|
const isBundled = fnOptions.experimentalBundledNextServer ?? false;
|
|
96
90
|
if (isBundled) {
|
|
97
|
-
await bundleNextServer(path.join(outputPath, packagePath), appPath
|
|
91
|
+
await bundleNextServer(path.join(outputPath, packagePath), appPath, {
|
|
92
|
+
debug: options.debug,
|
|
93
|
+
});
|
|
98
94
|
}
|
|
99
95
|
// Copy middleware
|
|
100
96
|
if (!config.middleware?.external) {
|
|
@@ -132,20 +128,16 @@ async function generateBundle(name, options, fnOptions) {
|
|
|
132
128
|
...(disableNextPrebundledReact ? ["requireHooks"] : []),
|
|
133
129
|
...(disableRouting ? ["trustHostHeader"] : []),
|
|
134
130
|
...(!isBefore13413 ? ["requestHandlerHost"] : []),
|
|
135
|
-
...(
|
|
136
|
-
|
|
131
|
+
...(isAfter141
|
|
132
|
+
? ["experimentalIncrementalCacheHandler"]
|
|
133
|
+
: ["stableIncrementalCache"]),
|
|
137
134
|
],
|
|
138
135
|
}),
|
|
139
136
|
openNextResolvePlugin({
|
|
140
137
|
fnName: name,
|
|
141
|
-
overrides
|
|
138
|
+
overrides,
|
|
142
139
|
}),
|
|
143
140
|
];
|
|
144
|
-
if (plugins && plugins.length > 0) {
|
|
145
|
-
logger.debug(`Applying plugins:: [${plugins
|
|
146
|
-
.map(({ name }) => name)
|
|
147
|
-
.join(",")}] for Next version: ${options.nextVersion}`);
|
|
148
|
-
}
|
|
149
141
|
const outfileExt = fnOptions.runtime === "deno" ? "ts" : "mjs";
|
|
150
142
|
await buildHelper.esbuildAsync({
|
|
151
143
|
entryPoints: [
|
|
@@ -167,9 +159,11 @@ async function generateBundle(name, options, fnOptions) {
|
|
|
167
159
|
},
|
|
168
160
|
plugins,
|
|
169
161
|
alias: {
|
|
170
|
-
|
|
171
|
-
?
|
|
172
|
-
|
|
162
|
+
...(isBundled
|
|
163
|
+
? {
|
|
164
|
+
"next/dist/server/next-server.js": "./next-server.runtime.prod.js",
|
|
165
|
+
}
|
|
166
|
+
: {}),
|
|
173
167
|
},
|
|
174
168
|
}, options);
|
|
175
169
|
if (isMonorepo) {
|
|
@@ -217,7 +211,7 @@ function addMonorepoEntrypoint(outputPath, packagePath) {
|
|
|
217
211
|
fs.writeFileSync(path.join(outputPath, "index.mjs"), [`export * from "./${packagePosixPath}/index.mjs";`].join(""));
|
|
218
212
|
}
|
|
219
213
|
async function minifyServerBundle(outputDir) {
|
|
220
|
-
logger.info(
|
|
214
|
+
logger.info("Minimizing server function...");
|
|
221
215
|
await minifyAll(outputDir, {
|
|
222
216
|
compress_json: true,
|
|
223
217
|
mangle: true,
|
|
@@ -5,7 +5,7 @@ import { openNextResolvePlugin } from "../plugins/resolve.js";
|
|
|
5
5
|
import * as buildHelper from "./helper.js";
|
|
6
6
|
import { installDependencies } from "./installDeps.js";
|
|
7
7
|
export async function createWarmerBundle(options) {
|
|
8
|
-
logger.info(
|
|
8
|
+
logger.info("Bundling warmer function...");
|
|
9
9
|
const { config, outputDir } = options;
|
|
10
10
|
// Create output folder
|
|
11
11
|
const outputPath = path.join(outputDir, "warmer-function");
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import type { MiddlewareInfo } from "../../types/next-types";
|
|
2
|
-
import type { IncludedConverter, OverrideOptions, SplittedFunctionOptions } from "../../types/open-next";
|
|
2
|
+
import type { IncludedConverter, IncludedOriginResolver, LazyLoadedOverride, OverrideOptions, SplittedFunctionOptions } from "../../types/open-next";
|
|
3
|
+
import type { OriginResolver } from "../../types/overrides.js";
|
|
3
4
|
import type { BuildOptions } from "../helper.js";
|
|
4
5
|
interface BuildEdgeBundleOptions {
|
|
5
6
|
middlewareInfo?: MiddlewareInfo;
|
|
6
7
|
entrypoint: string;
|
|
7
8
|
outfile: string;
|
|
8
9
|
options: BuildOptions;
|
|
9
|
-
overrides?: OverrideOptions
|
|
10
|
+
overrides?: OverrideOptions & {
|
|
11
|
+
originResolver?: LazyLoadedOverride<OriginResolver> | IncludedOriginResolver;
|
|
12
|
+
};
|
|
10
13
|
defaultConverter?: IncludedConverter;
|
|
11
14
|
additionalInject?: string;
|
|
12
15
|
includeCache?: boolean;
|
|
13
16
|
additionalExternals?: string[];
|
|
14
17
|
onlyBuildOnce?: boolean;
|
|
18
|
+
name: string;
|
|
15
19
|
}
|
|
16
|
-
export declare function buildEdgeBundle({ middlewareInfo, entrypoint, outfile, options, defaultConverter, overrides, additionalInject, includeCache, additionalExternals, onlyBuildOnce, }: BuildEdgeBundleOptions): Promise<void>;
|
|
20
|
+
export declare function buildEdgeBundle({ middlewareInfo, entrypoint, outfile, options, defaultConverter, overrides, additionalInject, includeCache, additionalExternals, onlyBuildOnce, name, }: BuildEdgeBundleOptions): Promise<void>;
|
|
17
21
|
export declare function generateEdgeBundle(name: string, options: BuildOptions, fnOptions: SplittedFunctionOptions): Promise<void>;
|
|
18
22
|
export {};
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { mkdirSync } from "node:fs";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
import { build } from "esbuild";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
5
|
import logger from "../../logger.js";
|
|
6
6
|
import { openNextEdgePlugins } from "../../plugins/edge.js";
|
|
7
7
|
import { openNextReplacementPlugin } from "../../plugins/replacement.js";
|
|
8
8
|
import { openNextResolvePlugin } from "../../plugins/resolve.js";
|
|
9
9
|
import { copyOpenNextConfig, esbuildAsync } from "../helper.js";
|
|
10
|
-
export async function buildEdgeBundle({ middlewareInfo, entrypoint, outfile, options, defaultConverter, overrides, additionalInject, includeCache, additionalExternals, onlyBuildOnce, }) {
|
|
10
|
+
export async function buildEdgeBundle({ middlewareInfo, entrypoint, outfile, options, defaultConverter, overrides, additionalInject, includeCache, additionalExternals, onlyBuildOnce, name, }) {
|
|
11
11
|
const isInCloudfare = typeof overrides?.wrapper === "string"
|
|
12
12
|
? overrides.wrapper === "cloudflare"
|
|
13
13
|
: (await overrides?.wrapper?.())?.edgeRuntime;
|
|
14
14
|
await esbuildAsync({
|
|
15
15
|
entryPoints: [entrypoint],
|
|
16
|
-
// inject: ,
|
|
17
16
|
bundle: true,
|
|
18
17
|
outfile,
|
|
19
18
|
external: ["node:*", "next", "@aws-sdk/*"],
|
|
@@ -41,7 +40,14 @@ export async function buildEdgeBundle({ middlewareInfo, entrypoint, outfile, opt
|
|
|
41
40
|
: "sqs-lite",
|
|
42
41
|
}
|
|
43
42
|
: {}),
|
|
43
|
+
originResolver: typeof overrides?.originResolver === "string"
|
|
44
|
+
? overrides.originResolver
|
|
45
|
+
: "pattern-env",
|
|
46
|
+
proxyExternalRequest: typeof overrides?.proxyExternalRequest === "string"
|
|
47
|
+
? overrides.proxyExternalRequest
|
|
48
|
+
: "node",
|
|
44
49
|
},
|
|
50
|
+
fnName: name,
|
|
45
51
|
}),
|
|
46
52
|
openNextReplacementPlugin({
|
|
47
53
|
name: "externalMiddlewareOverrides",
|
|
@@ -95,7 +101,7 @@ globalThis.AsyncLocalStorage = AsyncLocalStorage;
|
|
|
95
101
|
outfile,
|
|
96
102
|
allowOverwrite: true,
|
|
97
103
|
bundle: true,
|
|
98
|
-
minify:
|
|
104
|
+
minify: !options.debug,
|
|
99
105
|
platform: "node",
|
|
100
106
|
format: "esm",
|
|
101
107
|
conditions: ["workerd", "worker", "browser"],
|
|
@@ -141,5 +147,6 @@ export async function generateEdgeBundle(name, options, fnOptions) {
|
|
|
141
147
|
options,
|
|
142
148
|
overrides: fnOptions.override,
|
|
143
149
|
additionalExternals: options.config.edgeExternals,
|
|
150
|
+
name,
|
|
144
151
|
});
|
|
145
152
|
}
|
|
@@ -6,15 +6,11 @@ async function canStream(opts) {
|
|
|
6
6
|
if (!opts.override?.wrapper) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return opts.override.wrapper === "aws-lambda-streaming";
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
const wrapper = await opts.override.wrapper();
|
|
15
|
-
return wrapper.supportStreaming;
|
|
16
|
-
}
|
|
9
|
+
if (typeof opts.override.wrapper === "string") {
|
|
10
|
+
return opts.override.wrapper === "aws-lambda-streaming";
|
|
17
11
|
}
|
|
12
|
+
const wrapper = await opts.override.wrapper();
|
|
13
|
+
return wrapper.supportStreaming;
|
|
18
14
|
}
|
|
19
15
|
async function extractOverrideName(defaultName, override) {
|
|
20
16
|
if (!override) {
|
|
@@ -23,10 +19,8 @@ async function extractOverrideName(defaultName, override) {
|
|
|
23
19
|
if (typeof override === "string") {
|
|
24
20
|
return override;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return overrideModule.name;
|
|
29
|
-
}
|
|
22
|
+
const overrideModule = await override();
|
|
23
|
+
return overrideModule.name;
|
|
30
24
|
}
|
|
31
25
|
async function extractOverrideFn(override) {
|
|
32
26
|
if (!override) {
|
|
@@ -190,7 +184,7 @@ export async function generateOutput(options) {
|
|
|
190
184
|
edgeFunction: isExternalMiddleware ? "middleware" : undefined,
|
|
191
185
|
});
|
|
192
186
|
behaviors.push({
|
|
193
|
-
pattern: "*",
|
|
187
|
+
pattern: "*", // This is the default behavior
|
|
194
188
|
origin: "default",
|
|
195
189
|
edgeFunction: isExternalMiddleware ? "middleware" : undefined,
|
|
196
190
|
});
|
package/dist/build/helper.d.ts
CHANGED
|
@@ -19,15 +19,33 @@ export declare function normalizeOptions(config: OpenNextConfig, distDir: string
|
|
|
19
19
|
};
|
|
20
20
|
export declare function esbuildSync(esbuildOptions: ESBuildOptions, options: BuildOptions): void;
|
|
21
21
|
export declare function esbuildAsync(esbuildOptions: ESBuildOptions, options: BuildOptions): Promise<void>;
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Type of the parameter of `traverseFiles` callbacks
|
|
24
|
+
*/
|
|
25
|
+
export type TraversePath = {
|
|
26
|
+
absolutePath: string;
|
|
27
|
+
relativePath: string;
|
|
28
|
+
};
|
|
23
29
|
/**
|
|
24
30
|
* Recursively traverse files in a directory and call `callbackFn` when `conditionFn` returns true
|
|
31
|
+
*
|
|
32
|
+
* The callbacks are passed both the absolute and relative (to root) path to files.
|
|
33
|
+
*
|
|
25
34
|
* @param root - Root directory to search
|
|
26
|
-
* @param conditionFn - Called to determine if `callbackFn` should be called
|
|
27
|
-
* @param callbackFn - Called when `conditionFn` returns true
|
|
35
|
+
* @param conditionFn - Called to determine if `callbackFn` should be called.
|
|
36
|
+
* @param callbackFn - Called when `conditionFn` returns true.
|
|
28
37
|
* @param searchingDir - Directory to search (used for recursion)
|
|
29
38
|
*/
|
|
30
|
-
export declare function traverseFiles(root: string, conditionFn: (
|
|
39
|
+
export declare function traverseFiles(root: string, conditionFn: (paths: TraversePath) => boolean, callbackFn: (paths: TraversePath) => void, searchingDir?: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Recursively delete files.
|
|
42
|
+
*
|
|
43
|
+
* @see `traverseFiles`.
|
|
44
|
+
*
|
|
45
|
+
* @param root Root directory to search.
|
|
46
|
+
* @param conditionFn Predicate used to delete the files.
|
|
47
|
+
*/
|
|
48
|
+
export declare function removeFiles(root: string, conditionFn: (paths: TraversePath) => boolean): void;
|
|
31
49
|
export declare function getHtmlPages(dotNextPath: string): Set<string>;
|
|
32
50
|
export declare function getBuildId(dotNextPath: string): string;
|
|
33
51
|
export declare function getOpenNextVersion(): string;
|
package/dist/build/helper.js
CHANGED
|
@@ -74,7 +74,7 @@ export function esbuildSync(esbuildOptions, options) {
|
|
|
74
74
|
format: "esm",
|
|
75
75
|
platform: "node",
|
|
76
76
|
bundle: true,
|
|
77
|
-
minify: debug
|
|
77
|
+
minify: !debug,
|
|
78
78
|
mainFields: ["module", "main"],
|
|
79
79
|
sourcemap: debug ? "inline" : false,
|
|
80
80
|
sourcesContent: false,
|
|
@@ -101,7 +101,7 @@ export async function esbuildAsync(esbuildOptions, options) {
|
|
|
101
101
|
format: "esm",
|
|
102
102
|
platform: "node",
|
|
103
103
|
bundle: true,
|
|
104
|
-
minify: debug
|
|
104
|
+
minify: !debug,
|
|
105
105
|
mainFields: ["module", "main"],
|
|
106
106
|
sourcemap: debug ? "inline" : false,
|
|
107
107
|
sourcesContent: false,
|
|
@@ -125,28 +125,40 @@ export async function esbuildAsync(esbuildOptions, options) {
|
|
|
125
125
|
throw new Error(`There was a problem bundling ${esbuildOptions.entryPoints[0]}.`);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
export function removeFiles(root, conditionFn, searchingDir = "") {
|
|
129
|
-
traverseFiles(root, conditionFn, (filePath) => fs.rmSync(filePath, { force: true }), searchingDir);
|
|
130
|
-
}
|
|
131
128
|
/**
|
|
132
129
|
* Recursively traverse files in a directory and call `callbackFn` when `conditionFn` returns true
|
|
130
|
+
*
|
|
131
|
+
* The callbacks are passed both the absolute and relative (to root) path to files.
|
|
132
|
+
*
|
|
133
133
|
* @param root - Root directory to search
|
|
134
|
-
* @param conditionFn - Called to determine if `callbackFn` should be called
|
|
135
|
-
* @param callbackFn - Called when `conditionFn` returns true
|
|
134
|
+
* @param conditionFn - Called to determine if `callbackFn` should be called.
|
|
135
|
+
* @param callbackFn - Called when `conditionFn` returns true.
|
|
136
136
|
* @param searchingDir - Directory to search (used for recursion)
|
|
137
137
|
*/
|
|
138
138
|
export function traverseFiles(root, conditionFn, callbackFn, searchingDir = "") {
|
|
139
139
|
fs.readdirSync(path.join(root, searchingDir)).forEach((file) => {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
const relativePath = path.join(searchingDir, file);
|
|
141
|
+
const absolutePath = path.join(root, relativePath);
|
|
142
|
+
if (fs.statSync(absolutePath).isDirectory()) {
|
|
143
|
+
traverseFiles(root, conditionFn, callbackFn, relativePath);
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
145
|
-
if (conditionFn(
|
|
146
|
-
callbackFn(
|
|
146
|
+
if (conditionFn({ absolutePath, relativePath })) {
|
|
147
|
+
callbackFn({ absolutePath, relativePath });
|
|
147
148
|
}
|
|
148
149
|
});
|
|
149
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Recursively delete files.
|
|
153
|
+
*
|
|
154
|
+
* @see `traverseFiles`.
|
|
155
|
+
*
|
|
156
|
+
* @param root Root directory to search.
|
|
157
|
+
* @param conditionFn Predicate used to delete the files.
|
|
158
|
+
*/
|
|
159
|
+
export function removeFiles(root, conditionFn) {
|
|
160
|
+
traverseFiles(root, conditionFn, ({ absolutePath }) => fs.rmSync(absolutePath, { force: true }));
|
|
161
|
+
}
|
|
150
162
|
export function getHtmlPages(dotNextPath) {
|
|
151
163
|
// Get a list of HTML pages
|
|
152
164
|
//
|
|
@@ -187,9 +199,11 @@ export function compareSemver(v1, v2) {
|
|
|
187
199
|
if (v1 === "latest")
|
|
188
200
|
return 1;
|
|
189
201
|
if (/^[^\d]/.test(v1)) {
|
|
202
|
+
// biome-ignore lint/style/noParameterAssign:
|
|
190
203
|
v1 = v1.substring(1);
|
|
191
204
|
}
|
|
192
205
|
if (/^[^\d]/.test(v2)) {
|
|
206
|
+
// biome-ignore lint/style/noParameterAssign:
|
|
193
207
|
v2 = v2.substring(1);
|
|
194
208
|
}
|
|
195
209
|
const [major1, minor1, patch1] = v1.split(".").map(Number);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { execSync } from "child_process";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
5
|
import logger from "../logger.js";
|
|
6
6
|
export function installDependencies(outputDir, installOptions) {
|
|
7
7
|
try {
|
package/dist/build/utils.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
2
|
import logger from "../logger.js";
|
|
3
3
|
export function printHeader(header) {
|
|
4
|
+
// biome-ignore lint/style/noParameterAssign:
|
|
4
5
|
header = `OpenNext — ${header}`;
|
|
5
6
|
logger.info([
|
|
6
7
|
"",
|
|
7
|
-
"
|
|
8
|
+
`┌${"─".repeat(header.length + 2)}┐`,
|
|
8
9
|
`│ ${header} │`,
|
|
9
|
-
"
|
|
10
|
+
`└${"─".repeat(header.length + 2)}┘`,
|
|
10
11
|
"",
|
|
11
12
|
].join("\n"));
|
|
12
13
|
}
|
|
@@ -9,6 +9,7 @@ const compatibilityMatrix = {
|
|
|
9
9
|
"aws-lambda-streaming": ["aws-apigw-v2"],
|
|
10
10
|
cloudflare: ["edge"],
|
|
11
11
|
node: ["node"],
|
|
12
|
+
dummy: [],
|
|
12
13
|
};
|
|
13
14
|
function validateFunctionOptions(fnOptions) {
|
|
14
15
|
if (fnOptions.runtime === "edge" && fnOptions.experimentalBundledNextServer) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { BaseEventOrResult, InternalEvent, InternalResult
|
|
2
|
-
|
|
3
|
-
var openNextConfig: Partial<OpenNextConfig>;
|
|
4
|
-
}
|
|
1
|
+
import type { BaseEventOrResult, InternalEvent, InternalResult } from "../types/open-next";
|
|
2
|
+
import type { OpenNextHandler } from "../types/overrides";
|
|
5
3
|
type HandlerType = "imageOptimization" | "revalidate" | "warmer" | "middleware" | "initializationFunction";
|
|
6
4
|
type GenericHandler<Type extends HandlerType, E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult> = {
|
|
7
5
|
handler: OpenNextHandler<E, R>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { debug } from "../adapters/logger";
|
|
2
2
|
import { resolveConverter, resolveWrapper } from "./resolve";
|
|
3
3
|
export async function createGenericHandler(handler) {
|
|
4
|
-
//
|
|
5
|
-
// @ts-expect-error
|
|
4
|
+
// @ts-expect-error `./open-next.config.mjs` exists only in the build output
|
|
6
5
|
const config = await import("./open-next.config.mjs").then((m) => m.default);
|
|
7
6
|
globalThis.openNextConfig = config;
|
|
8
7
|
const override = config[handler.type]
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
-
import type { DetachedPromiseRunner } from "../utils/promise";
|
|
4
|
-
import type { IncrementalCache } from "../overrides/incrementalCache/types";
|
|
5
|
-
import type { Queue } from "../overrides/queue/types";
|
|
6
|
-
declare global {
|
|
7
|
-
var queue: Queue;
|
|
8
|
-
var incrementalCache: IncrementalCache;
|
|
9
|
-
var fnName: string | undefined;
|
|
10
|
-
var serverId: string;
|
|
11
|
-
var __als: AsyncLocalStorage<{
|
|
12
|
-
requestId: string;
|
|
13
|
-
pendingPromiseRunner: DetachedPromiseRunner;
|
|
14
|
-
isISRRevalidation?: boolean;
|
|
15
|
-
mergeHeadersPriority?: "middleware" | "handler";
|
|
16
|
-
}>;
|
|
17
|
-
}
|
|
18
1
|
export declare function createMainHandler(): Promise<(...args: any[]) => any>;
|