@opennextjs/aws 3.2.0 → 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 +1 -23
- package/dist/adapters/cache.js +22 -18
- 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 +3 -3
- package/dist/build/copyTracedFiles.js +16 -27
- package/dist/build/createAssets.js +35 -26
- package/dist/build/createImageOptimizationBundle.js +4 -1
- package/dist/build/createMiddleware.d.ts +4 -4
- package/dist/build/createMiddleware.js +16 -19
- package/dist/build/createRevalidationBundle.js +1 -1
- package/dist/build/createServerBundle.js +34 -45
- package/dist/build/createWarmerBundle.js +1 -1
- package/dist/build/edge/createEdgeBundle.d.ts +9 -7
- package/dist/build/edge/createEdgeBundle.js +19 -14
- 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 +12 -2
- 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 +6 -7
- package/dist/core/createMainHandler.d.ts +0 -17
- package/dist/core/createMainHandler.js +10 -9
- 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 +29 -31
- package/dist/core/routing/middleware.js +22 -18
- package/dist/core/routing/util.d.ts +0 -13
- package/dist/core/routing/util.js +32 -91
- 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 +5 -1
- package/dist/overrides/converters/edge.js +16 -17
- 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 +21 -3
- 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.d.ts +3 -2
- package/dist/plugins/edge.js +33 -34
- package/dist/plugins/replacement.d.ts +1 -1
- package/dist/plugins/replacement.js +5 -6
- 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 +24 -45
- 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/adapters/plugins/without-routing/requestHandler.d.ts +0 -2
- package/dist/adapters/plugins/without-routing/requestHandler.js +0 -10
- 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
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
import path from "node:path";
|
|
2
3
|
import { AwsClient } from "aws4fetch";
|
|
3
|
-
import path from "path";
|
|
4
4
|
import { RecoverableError } from "../../utils/error";
|
|
5
5
|
import { customFetchClient } from "../../utils/fetch";
|
|
6
6
|
import { debug, error } from "../../adapters/logger";
|
|
7
7
|
import { chunk, parseNumberFromEnv } from "../../adapters/util";
|
|
8
|
-
import {
|
|
8
|
+
import { MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT, getDynamoBatchWriteCommandConcurrency, } from "./constants";
|
|
9
9
|
let awsClient = null;
|
|
10
10
|
const getAwsClient = () => {
|
|
11
11
|
const { CACHE_BUCKET_REGION } = process.env;
|
|
12
12
|
if (awsClient) {
|
|
13
13
|
return awsClient;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return awsClient;
|
|
24
|
-
}
|
|
15
|
+
awsClient = new AwsClient({
|
|
16
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
17
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
18
|
+
sessionToken: process.env.AWS_SESSION_TOKEN,
|
|
19
|
+
region: CACHE_BUCKET_REGION,
|
|
20
|
+
retries: parseNumberFromEnv(process.env.AWS_SDK_S3_MAX_ATTEMPTS),
|
|
21
|
+
});
|
|
22
|
+
return awsClient;
|
|
25
23
|
};
|
|
26
24
|
const awsFetch = (body, type = "query") => {
|
|
27
25
|
const { CACHE_BUCKET_REGION } = process.env;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { BatchWriteItemCommand, DynamoDBClient, QueryCommand, } from "@aws-sdk/client-dynamodb";
|
|
2
|
-
import path from "path";
|
|
3
3
|
import { awsLogger, debug, error } from "../../adapters/logger";
|
|
4
4
|
import { chunk, parseNumberFromEnv } from "../../adapters/util";
|
|
5
|
-
import {
|
|
5
|
+
import { MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT, getDynamoBatchWriteCommandConcurrency, } from "./constants";
|
|
6
6
|
const { CACHE_BUCKET_REGION, CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;
|
|
7
7
|
function parseDynamoClientConfigFromEnv() {
|
|
8
8
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { WrapperHandler } from "../../types/
|
|
1
|
+
import type { WrapperHandler } from "../../types/overrides";
|
|
2
2
|
declare const _default: {
|
|
3
|
-
wrapper: WrapperHandler
|
|
3
|
+
wrapper: WrapperHandler;
|
|
4
4
|
name: string;
|
|
5
5
|
supportStreaming: boolean;
|
|
6
6
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { WrapperHandler } from "../../types/
|
|
1
|
+
import type { WrapperHandler } from "../../types/overrides";
|
|
2
2
|
declare const _default: {
|
|
3
|
-
wrapper: WrapperHandler
|
|
3
|
+
wrapper: WrapperHandler;
|
|
4
4
|
name: string;
|
|
5
5
|
supportStreaming: boolean;
|
|
6
6
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { InternalEvent, InternalResult
|
|
1
|
+
import type { InternalEvent, InternalResult } from "../../types/open-next";
|
|
2
|
+
import type { WrapperHandler } from "../../types/overrides";
|
|
2
3
|
import type { MiddlewareOutputEvent } from "../../core/routingHandler";
|
|
3
4
|
declare const _default: {
|
|
4
5
|
wrapper: WrapperHandler<InternalEvent, InternalResult | ({
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
const
|
|
1
|
+
const cfPropNameToHeaderName = {
|
|
2
|
+
city: "x-open-next-city",
|
|
3
|
+
country: "x-open-next-country",
|
|
4
|
+
regionCode: "x-open-next-region",
|
|
5
|
+
latitude: "x-open-next-latitude",
|
|
6
|
+
longitude: "x-open-next-longitude",
|
|
7
|
+
};
|
|
8
|
+
const handler = async (handler, converter) => async (request, env, ctx) => {
|
|
2
9
|
globalThis.process = process;
|
|
10
|
+
globalThis.openNextWaitUntil = ctx.waitUntil.bind(ctx);
|
|
3
11
|
// Set the environment variables
|
|
4
|
-
//
|
|
12
|
+
// Cloudflare suggests to not override the process.env object but instead apply the values to it
|
|
5
13
|
for (const [key, value] of Object.entries(env)) {
|
|
6
14
|
if (typeof value === "string") {
|
|
7
15
|
process.env[key] = value;
|
|
8
16
|
}
|
|
9
17
|
}
|
|
10
|
-
const internalEvent = await converter.convertFrom(
|
|
18
|
+
const internalEvent = await converter.convertFrom(request);
|
|
19
|
+
// Retrieve geo information from the cloudflare request
|
|
20
|
+
// See https://developers.cloudflare.com/workers/runtime-apis/request
|
|
21
|
+
// Note: This code could be moved to a cloudflare specific converter when one is created.
|
|
22
|
+
const cfProperties = request.cf;
|
|
23
|
+
for (const [propName, headerName] of Object.entries(cfPropNameToHeaderName)) {
|
|
24
|
+
const propValue = cfProperties[propName];
|
|
25
|
+
if (propValue !== null) {
|
|
26
|
+
internalEvent.headers[headerName] = propValue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
11
29
|
const response = await handler(internalEvent);
|
|
12
30
|
const result = await converter.convertTo(response);
|
|
13
31
|
return result;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { WrapperHandler } from "../../types/
|
|
1
|
+
import type { WrapperHandler } from "../../types/overrides";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
name: string;
|
|
4
|
-
handler: WrapperHandler
|
|
4
|
+
handler: WrapperHandler;
|
|
5
5
|
supportStreaming: boolean;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { WrapperHandler } from "../../types/
|
|
1
|
+
import type { WrapperHandler } from "../../types/overrides";
|
|
2
2
|
declare const _default: {
|
|
3
|
-
wrapper: WrapperHandler
|
|
3
|
+
wrapper: WrapperHandler;
|
|
4
4
|
name: string;
|
|
5
5
|
supportStreaming: boolean;
|
|
6
6
|
};
|
|
@@ -28,9 +28,9 @@ const wrapper = async (handler, converter) => {
|
|
|
28
28
|
await new Promise((resolve) => {
|
|
29
29
|
server.on("listening", () => {
|
|
30
30
|
const cleanup = (code) => {
|
|
31
|
-
debug(
|
|
31
|
+
debug("Closing server");
|
|
32
32
|
server.close(() => {
|
|
33
|
-
debug(
|
|
33
|
+
debug("Server closed");
|
|
34
34
|
process.exit(code);
|
|
35
35
|
});
|
|
36
36
|
};
|
|
@@ -41,7 +41,7 @@ const wrapper = async (handler, converter) => {
|
|
|
41
41
|
process.on("SIGTERM", () => cleanup(0));
|
|
42
42
|
resolve();
|
|
43
43
|
});
|
|
44
|
-
server.listen(parseInt(process.env.PORT ?? "3000", 10));
|
|
44
|
+
server.listen(Number.parseInt(process.env.PORT ?? "3000", 10));
|
|
45
45
|
});
|
|
46
46
|
server.on("error", (err) => {
|
|
47
47
|
error(err);
|
package/dist/plugins/edge.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import type { MiddlewareInfo } from "../types/next-types.js";
|
|
|
3
3
|
export interface IPluginSettings {
|
|
4
4
|
nextDir: string;
|
|
5
5
|
edgeFunctionHandlerPath?: string;
|
|
6
|
-
middlewareInfo
|
|
6
|
+
middlewareInfo?: MiddlewareInfo;
|
|
7
7
|
isInCloudfare?: boolean;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* @param opts.nextDir - The path to the .next directory
|
|
11
11
|
* @param opts.edgeFunctionHandlerPath - The path to the edgeFunctionHandler.js file that we'll use to bundle the routing
|
|
12
|
-
* @param opts.
|
|
12
|
+
* @param opts.middlewareInfo - Information about the middleware
|
|
13
|
+
* @param opts.isInCloudfare - Whether the code runs on the cloudflare runtime
|
|
13
14
|
* @returns
|
|
14
15
|
*/
|
|
15
16
|
export declare function openNextEdgePlugins({ nextDir, edgeFunctionHandlerPath, middlewareInfo, isInCloudfare, }: IPluginSettings): Plugin;
|
package/dist/plugins/edge.js
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import chalk from "chalk";
|
|
3
4
|
import { loadAppPathsManifestKeys, loadBuildId, loadConfig, loadConfigHeaders, loadHtmlPages, loadMiddlewareManifest, loadPrerenderManifest, loadRoutesManifest, } from "../adapters/config/util.js";
|
|
5
|
+
import logger from "../logger.js";
|
|
4
6
|
/**
|
|
5
7
|
* @param opts.nextDir - The path to the .next directory
|
|
6
8
|
* @param opts.edgeFunctionHandlerPath - The path to the edgeFunctionHandler.js file that we'll use to bundle the routing
|
|
7
|
-
* @param opts.
|
|
9
|
+
* @param opts.middlewareInfo - Information about the middleware
|
|
10
|
+
* @param opts.isInCloudfare - Whether the code runs on the cloudflare runtime
|
|
8
11
|
* @returns
|
|
9
12
|
*/
|
|
10
13
|
export function openNextEdgePlugins({ nextDir, edgeFunctionHandlerPath, middlewareInfo, isInCloudfare, }) {
|
|
11
|
-
const entryFiles = middlewareInfo
|
|
12
|
-
const routes =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const entryFiles = middlewareInfo?.files.map((file) => path.join(nextDir, file)) ?? [];
|
|
15
|
+
const routes = middlewareInfo
|
|
16
|
+
? [
|
|
17
|
+
{
|
|
18
|
+
name: middlewareInfo.name || "/",
|
|
19
|
+
page: middlewareInfo.page,
|
|
20
|
+
regex: middlewareInfo.matchers.map((m) => m.regexp),
|
|
21
|
+
},
|
|
22
|
+
]
|
|
23
|
+
: [];
|
|
24
|
+
const wasmFiles = middlewareInfo?.wasm ?? [];
|
|
20
25
|
return {
|
|
21
26
|
name: "opennext-edge",
|
|
22
27
|
setup(build) {
|
|
28
|
+
logger.debug(chalk.blue("OpenNext Edge plugin"));
|
|
23
29
|
if (edgeFunctionHandlerPath) {
|
|
24
30
|
// If we bundle the routing, we need to resolve the middleware
|
|
25
31
|
build.onResolve({ filter: /\.\/middleware.mjs/g }, () => {
|
|
@@ -44,12 +50,10 @@ export function openNextEdgePlugins({ nextDir, edgeFunctionHandlerPath, middlewa
|
|
|
44
50
|
});
|
|
45
51
|
// we convert the imports we tagged with the node-built-in-modules namespace so that instead of `require("node:*")`
|
|
46
52
|
// they import from `export * from "node:*";`
|
|
47
|
-
build.onLoad({ filter: /.*/, namespace: "node-built-in-modules" }, ({ path }) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
+
build.onLoad({ filter: /.*/, namespace: "node-built-in-modules" }, ({ path }) => ({
|
|
54
|
+
contents: `export * from '${path}'`,
|
|
55
|
+
loader: "js",
|
|
56
|
+
}));
|
|
53
57
|
// We inject the entry files into the edgeFunctionHandler
|
|
54
58
|
build.onLoad({ filter: /\/edgeFunctionHandler.js/g }, async (args) => {
|
|
55
59
|
let contents = readFileSync(args.path, "utf-8");
|
|
@@ -59,7 +63,7 @@ globalThis.self = globalThis;
|
|
|
59
63
|
globalThis._ROUTES = ${JSON.stringify(routes)};
|
|
60
64
|
|
|
61
65
|
${isInCloudfare
|
|
62
|
-
?
|
|
66
|
+
? ""
|
|
63
67
|
: `
|
|
64
68
|
import {readFileSync} from "node:fs";
|
|
65
69
|
import path from "node:path";
|
|
@@ -97,7 +101,7 @@ if(!globalThis.Crypto) {
|
|
|
97
101
|
globalThis.Crypto = webcrypto.Crypto
|
|
98
102
|
}
|
|
99
103
|
// We also need to polyfill URLPattern
|
|
100
|
-
if (!globalThis.URLPattern) {
|
|
104
|
+
if (!globalThis.URLPattern) {
|
|
101
105
|
await import("urlpattern-polyfill");
|
|
102
106
|
}
|
|
103
107
|
`}
|
|
@@ -106,8 +110,8 @@ ${wasmFiles
|
|
|
106
110
|
? `import ${file.name} from './wasm/${file.name}.wasm';`
|
|
107
111
|
: `const ${file.name} = readFileSync(path.join(__dirname,'/wasm/${file.name}.wasm'));`)
|
|
108
112
|
.join("\n")}
|
|
109
|
-
${entryFiles
|
|
110
|
-
${contents}
|
|
113
|
+
${entryFiles.map((file) => `require("${file}");`).join("\n")}
|
|
114
|
+
${contents}
|
|
111
115
|
`;
|
|
112
116
|
return {
|
|
113
117
|
contents,
|
|
@@ -123,19 +127,17 @@ ${contents}
|
|
|
123
127
|
const AppPathsManifestKeys = loadAppPathsManifestKeys(nextDir);
|
|
124
128
|
const MiddlewareManifest = loadMiddlewareManifest(nextDir);
|
|
125
129
|
const contents = `
|
|
126
|
-
import path from "path";
|
|
127
|
-
|
|
130
|
+
import path from "node:path";
|
|
131
|
+
|
|
128
132
|
import { debug } from "../logger";
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
133
|
+
|
|
134
|
+
globalThis.__dirname ??= "";
|
|
135
|
+
|
|
134
136
|
export const NEXT_DIR = path.join(__dirname, ".next");
|
|
135
137
|
export const OPEN_NEXT_DIR = path.join(__dirname, ".open-next");
|
|
136
|
-
|
|
138
|
+
|
|
137
139
|
debug({ NEXT_DIR, OPEN_NEXT_DIR });
|
|
138
|
-
|
|
140
|
+
|
|
139
141
|
export const NextConfig = ${JSON.stringify(NextConfig)};
|
|
140
142
|
export const BuildId = ${JSON.stringify(BuildId)};
|
|
141
143
|
export const HtmlPages = ${JSON.stringify(HtmlPages)};
|
|
@@ -146,11 +148,8 @@ ${contents}
|
|
|
146
148
|
export const MiddlewareManifest = ${JSON.stringify(MiddlewareManifest)};
|
|
147
149
|
|
|
148
150
|
process.env.NEXT_BUILD_ID = BuildId;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
contents,
|
|
153
|
-
};
|
|
151
|
+
`;
|
|
152
|
+
return { contents };
|
|
154
153
|
});
|
|
155
154
|
},
|
|
156
155
|
};
|
|
@@ -11,7 +11,7 @@ const importPattern = /\/\/#import([\s\S]*?)\n\/\/#endImport/gm;
|
|
|
11
11
|
* deletes: ["id1"],
|
|
12
12
|
* })
|
|
13
13
|
*
|
|
14
|
-
* To inject
|
|
14
|
+
* To inject arbitrary code by using (import at top of file):
|
|
15
15
|
*
|
|
16
16
|
* //#import
|
|
17
17
|
*
|
|
@@ -46,12 +46,11 @@ export function openNextReplacementPlugin({ target, replacements, deletes, name,
|
|
|
46
46
|
await Promise.all([
|
|
47
47
|
...(deletes ?? []).map(async (id) => {
|
|
48
48
|
const pattern = new RegExp(`\/\/#override (${id})\n([\\s\\S]*?)\/\/#endOverride`);
|
|
49
|
-
logger.debug(chalk.blue(`
|
|
49
|
+
logger.debug(chalk.blue(`OpenNext Replacement plugin ${name}`), `Delete override ${id}`);
|
|
50
50
|
contents = contents.replace(pattern, "");
|
|
51
51
|
}),
|
|
52
|
-
...(replacements ?? []).map(async (
|
|
53
|
-
const
|
|
54
|
-
const replacementFile = await readFile(p, "utf-8");
|
|
52
|
+
...(replacements ?? []).map(async (filename) => {
|
|
53
|
+
const replacementFile = await readFile(filename, "utf-8");
|
|
55
54
|
const matches = replacementFile.matchAll(overridePattern);
|
|
56
55
|
const importMatch = replacementFile.match(importPattern);
|
|
57
56
|
const addedImport = importMatch ? importMatch[0] : "";
|
|
@@ -60,7 +59,7 @@ export function openNextReplacementPlugin({ target, replacements, deletes, name,
|
|
|
60
59
|
const replacement = match[2];
|
|
61
60
|
const id = match[1];
|
|
62
61
|
const pattern = new RegExp(`\/\/#override (${id})\n([\\s\\S]*?)\/\/#endOverride`, "g");
|
|
63
|
-
logger.debug(chalk.blue(`Open-next replacement plugin ${name}`),
|
|
62
|
+
logger.debug(chalk.blue(`Open-next replacement plugin ${name}`), `Apply override ${id} from ${filename}`);
|
|
64
63
|
contents = contents.replace(pattern, replacement);
|
|
65
64
|
}
|
|
66
65
|
}),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from "esbuild";
|
|
2
|
-
import type { DefaultOverrideOptions,
|
|
2
|
+
import type { DefaultOverrideOptions, IncludedImageLoader, IncludedOriginResolver, IncludedWarmer, LazyLoadedOverride, OverrideOptions } from "../types/open-next";
|
|
3
|
+
import type { ImageLoader, OriginResolver, Warmer } from "../types/overrides";
|
|
3
4
|
export interface IPluginSettings {
|
|
4
5
|
overrides?: {
|
|
5
6
|
wrapper?: DefaultOverrideOptions<any, any>["wrapper"];
|
|
@@ -10,6 +11,7 @@ export interface IPluginSettings {
|
|
|
10
11
|
imageLoader?: LazyLoadedOverride<ImageLoader> | IncludedImageLoader;
|
|
11
12
|
originResolver?: LazyLoadedOverride<OriginResolver> | IncludedOriginResolver;
|
|
12
13
|
warmer?: LazyLoadedOverride<Warmer> | IncludedWarmer;
|
|
14
|
+
proxyExternalRequest?: OverrideOptions["proxyExternalRequest"];
|
|
13
15
|
};
|
|
14
16
|
fnName?: string;
|
|
15
17
|
}
|
package/dist/plugins/resolve.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import chalk from "chalk";
|
|
2
3
|
import logger from "../logger.js";
|
|
3
4
|
function getOverrideOrDummy(override) {
|
|
4
5
|
if (typeof override === "string") {
|
|
@@ -17,6 +18,7 @@ const nameToFolder = {
|
|
|
17
18
|
imageLoader: "imageLoader",
|
|
18
19
|
originResolver: "originResolver",
|
|
19
20
|
warmer: "warmer",
|
|
21
|
+
proxyExternalRequest: "proxyExternalRequest",
|
|
20
22
|
};
|
|
21
23
|
const defaultOverrides = {
|
|
22
24
|
wrapper: "aws-lambda",
|
|
@@ -27,6 +29,7 @@ const defaultOverrides = {
|
|
|
27
29
|
imageLoader: "s3",
|
|
28
30
|
originResolver: "pattern-env",
|
|
29
31
|
warmer: "aws-lambda",
|
|
32
|
+
proxyExternalRequest: "node",
|
|
30
33
|
};
|
|
31
34
|
/**
|
|
32
35
|
* @param opts.overrides - The name of the overrides to use
|
|
@@ -36,7 +39,7 @@ export function openNextResolvePlugin({ overrides, fnName, }) {
|
|
|
36
39
|
return {
|
|
37
40
|
name: "opennext-resolve",
|
|
38
41
|
setup(build) {
|
|
39
|
-
logger.debug(
|
|
42
|
+
logger.debug(chalk.blue("OpenNext Resolve plugin"), fnName ? `for ${fnName}` : "");
|
|
40
43
|
build.onLoad({ filter: /core(\/|\\)resolve\.js/g }, async (args) => {
|
|
41
44
|
let contents = readFileSync(args.path, "utf-8");
|
|
42
45
|
const overridesEntries = Object.entries(overrides ?? {});
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
4
2
|
import type { APIGatewayProxyEventV2, Context } from "aws-lambda";
|
|
5
|
-
import type { Writable } from "stream";
|
|
6
3
|
export interface ResponseStream extends Writable {
|
|
7
4
|
getBufferedData(): Buffer;
|
|
8
5
|
setContentType(contentType: string): void;
|
|
@@ -15,7 +12,7 @@ interface Metadata {
|
|
|
15
12
|
declare global {
|
|
16
13
|
namespace awslambda {
|
|
17
14
|
function streamifyResponse(handler: Handler): Handler;
|
|
18
|
-
|
|
15
|
+
namespace HttpResponseStream {
|
|
19
16
|
function from(res: Writable, metadata: Metadata): ResponseStream;
|
|
20
17
|
}
|
|
21
18
|
}
|
package/dist/types/cache.d.ts
CHANGED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import type { OutgoingHttpHeaders } from "node:http";
|
|
3
|
+
import type { IncrementalCache, ProxyExternalRequest, Queue, TagCache } from "./overrides";
|
|
4
|
+
import type { DetachedPromiseRunner } from "../utils/promise";
|
|
5
|
+
import type { OpenNextConfig } from "./open-next";
|
|
6
|
+
export interface RequestData {
|
|
7
|
+
geo?: {
|
|
8
|
+
city?: string;
|
|
9
|
+
country?: string;
|
|
10
|
+
region?: string;
|
|
11
|
+
latitude?: string;
|
|
12
|
+
longitude?: string;
|
|
13
|
+
};
|
|
14
|
+
headers: OutgoingHttpHeaders;
|
|
15
|
+
ip?: string;
|
|
16
|
+
method: string;
|
|
17
|
+
nextConfig?: {
|
|
18
|
+
basePath?: string;
|
|
19
|
+
i18n?: any;
|
|
20
|
+
trailingSlash?: boolean;
|
|
21
|
+
};
|
|
22
|
+
page?: {
|
|
23
|
+
name?: string;
|
|
24
|
+
params?: {
|
|
25
|
+
[key: string]: string | string[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
url: string;
|
|
29
|
+
body?: ReadableStream<Uint8Array>;
|
|
30
|
+
signal: AbortSignal;
|
|
31
|
+
}
|
|
32
|
+
interface Entries {
|
|
33
|
+
[k: string]: {
|
|
34
|
+
default: (props: {
|
|
35
|
+
page: string;
|
|
36
|
+
request: RequestData;
|
|
37
|
+
}) => Promise<{
|
|
38
|
+
response: Response;
|
|
39
|
+
waitUntil: Promise<void>;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface EdgeRoute {
|
|
44
|
+
name: string;
|
|
45
|
+
page: string;
|
|
46
|
+
regex: string[];
|
|
47
|
+
}
|
|
48
|
+
interface OpenNextRequestContext {
|
|
49
|
+
requestId: string;
|
|
50
|
+
pendingPromiseRunner: DetachedPromiseRunner;
|
|
51
|
+
isISRRevalidation?: boolean;
|
|
52
|
+
mergeHeadersPriority?: "middleware" | "handler";
|
|
53
|
+
}
|
|
54
|
+
declare global {
|
|
55
|
+
/**
|
|
56
|
+
* The cache adapter for incremental static regeneration.
|
|
57
|
+
* Only available in main functions or in the external middleware with `enableCacheInterception` set to `true`.
|
|
58
|
+
* Defined in `createMainHandler` or in `adapter/middleware.ts`.
|
|
59
|
+
*/
|
|
60
|
+
var incrementalCache: IncrementalCache;
|
|
61
|
+
/**
|
|
62
|
+
* The cache adapter for the tag cache.
|
|
63
|
+
* Only available in main functions, the initializationFunction or in the external middleware with `enableCacheInterception` set to `true`.
|
|
64
|
+
* Defined in `createMainHandler` or in `adapter/middleware.ts`.
|
|
65
|
+
*/
|
|
66
|
+
var tagCache: TagCache;
|
|
67
|
+
/**
|
|
68
|
+
* A boolean that indicates if the DynamoDB cache is disabled.
|
|
69
|
+
* TODO: Remove this, we already have access to the config file
|
|
70
|
+
* Defined in esbuild banner for the cache adapter.
|
|
71
|
+
*/
|
|
72
|
+
var disableDynamoDBCache: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* A boolean that indicates if the incremental cache is disabled.
|
|
75
|
+
* TODO: Remove this, we already have access to the config file
|
|
76
|
+
* Defined in esbuild banner for the cache adapter.
|
|
77
|
+
*/
|
|
78
|
+
var disableIncrementalCache: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* An object that contains the last modified time of the pages.
|
|
81
|
+
* Only available in main functions.
|
|
82
|
+
* TODO: Integrate this directly in the AsyncLocalStorage context
|
|
83
|
+
* Defined in `createMainHandler`.
|
|
84
|
+
*/
|
|
85
|
+
var lastModified: Record<string, number>;
|
|
86
|
+
/**
|
|
87
|
+
* A boolean that indicates if Next is V15 or higher.
|
|
88
|
+
* Only available in the cache adapter.
|
|
89
|
+
* Defined in the esbuild banner for the cache adapter.
|
|
90
|
+
*/
|
|
91
|
+
var isNextAfter15: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* A boolean that indicates if the runtime is Edge.
|
|
94
|
+
* Only available in `edge` runtime functions (i.e. external middleware or function with edge runtime).
|
|
95
|
+
* Defined in the `edge-adapter.ts`.
|
|
96
|
+
*/
|
|
97
|
+
var isEdgeRuntime: true;
|
|
98
|
+
/**
|
|
99
|
+
* A boolean that indicates if we are running in debug mode.
|
|
100
|
+
* Available in all functions.
|
|
101
|
+
* Defined in the esbuild banner.
|
|
102
|
+
*/
|
|
103
|
+
var openNextDebug: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* The fetch function that should be used to make requests during the execution of the function.
|
|
106
|
+
* Used to bypass Next intercepting and caching the fetch calls. Only available in main functions.
|
|
107
|
+
* Defined in the `server-adapter.ts` and in `adapters/middleware.ts`.
|
|
108
|
+
*/
|
|
109
|
+
var internalFetch: typeof fetch;
|
|
110
|
+
/**
|
|
111
|
+
* The Open Next configuration object.
|
|
112
|
+
* Available in all functions.
|
|
113
|
+
* Defined in the `createMainHandler` or in the `createGenericHandler`.
|
|
114
|
+
*/
|
|
115
|
+
var openNextConfig: Partial<OpenNextConfig>;
|
|
116
|
+
/**
|
|
117
|
+
* The name of the function that is currently being executed.
|
|
118
|
+
* Only available in main functions.
|
|
119
|
+
* Defined in the `createMainHandler`.
|
|
120
|
+
*/
|
|
121
|
+
var fnName: string | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* The unique identifier of the server.
|
|
124
|
+
* Only available in main functions.
|
|
125
|
+
* Defined in the `createMainHandler`.
|
|
126
|
+
*/
|
|
127
|
+
var serverId: string;
|
|
128
|
+
/**
|
|
129
|
+
* The AsyncLocalStorage instance that is used to store the request context.
|
|
130
|
+
* Only available in main, middleware and edge functions.
|
|
131
|
+
* TODO: should be available everywhere in the future.
|
|
132
|
+
* Defined in `requestHandler.ts`, `middleware.ts` and `edge-adapter.ts`.
|
|
133
|
+
*/
|
|
134
|
+
var __openNextAls: AsyncLocalStorage<OpenNextRequestContext>;
|
|
135
|
+
/**
|
|
136
|
+
* The function that is used to run background tasks even after the response has been sent.
|
|
137
|
+
* This one is defined by the wrapper function as most of them don't need or support this feature.
|
|
138
|
+
* If not present, all the awaiting promises will be resolved before sending the response.
|
|
139
|
+
*/
|
|
140
|
+
var openNextWaitUntil: ((promise: Promise<void>) => void) | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* The entries object that contains the functions that are available in the function.
|
|
143
|
+
* Only available in edge runtime functions.
|
|
144
|
+
* Defined in the esbuild edge plugin.
|
|
145
|
+
*/
|
|
146
|
+
var _ENTRIES: Entries;
|
|
147
|
+
/**
|
|
148
|
+
* The routes object that contains the routes that are available in the function.
|
|
149
|
+
* Only available in edge runtime functions.
|
|
150
|
+
* Defined in the esbuild edge plugin.
|
|
151
|
+
*/
|
|
152
|
+
var _ROUTES: EdgeRoute[];
|
|
153
|
+
/**
|
|
154
|
+
* A map that is used in the edge runtime.
|
|
155
|
+
* Only available in edge runtime functions.
|
|
156
|
+
*/
|
|
157
|
+
var __storage__: Map<unknown, unknown>;
|
|
158
|
+
/**
|
|
159
|
+
* AsyncContext available globally in the edge runtime.
|
|
160
|
+
* Only available in edge runtime functions.
|
|
161
|
+
*/
|
|
162
|
+
var AsyncContext: any;
|
|
163
|
+
/**
|
|
164
|
+
* AsyncLocalStorage available globally in the edge runtime.
|
|
165
|
+
* Only available in edge runtime functions.
|
|
166
|
+
* Defined in createEdgeBundle.
|
|
167
|
+
*/
|
|
168
|
+
var AsyncLocalStorage: any;
|
|
169
|
+
/**
|
|
170
|
+
* The version of the Open Next runtime.
|
|
171
|
+
* Available everywhere.
|
|
172
|
+
* Defined in the esbuild banner.
|
|
173
|
+
*/
|
|
174
|
+
var openNextVersion: string;
|
|
175
|
+
/**
|
|
176
|
+
* The queue that is used to handle ISR revalidation requests.
|
|
177
|
+
* Only available in main functions and in the external middleware with `enableCacheInterception` set to `true`.
|
|
178
|
+
* Defined in `createMainHandler` or in `adapter/middleware.ts`.
|
|
179
|
+
*/
|
|
180
|
+
var queue: Queue;
|
|
181
|
+
/**
|
|
182
|
+
* The function that is used when resolving external rewrite requests.
|
|
183
|
+
* Only available in main functions
|
|
184
|
+
* Defined in `createMainHandler`.
|
|
185
|
+
*/
|
|
186
|
+
var proxyExternalRequest: ProxyExternalRequest;
|
|
187
|
+
}
|
|
188
|
+
export {};
|
|
@@ -151,7 +151,5 @@ export type Options = {
|
|
|
151
151
|
buildId: string;
|
|
152
152
|
isExternalRewrite?: boolean;
|
|
153
153
|
};
|
|
154
|
-
export
|
|
155
|
-
(req: IncomingMessage, res: OpenNextNodeResponse, options: Options): Promise<OpenNextNodeResponse | undefined>;
|
|
156
|
-
}
|
|
154
|
+
export type PluginHandler = (req: IncomingMessage, res: OpenNextNodeResponse, options: Options) => Promise<OpenNextNodeResponse | undefined>;
|
|
157
155
|
export {};
|