[next] support maxDuration in Next.js deployments (#10069)

Follow up PR to
8703c55f9f
which reads the newly created function config manifest and patches in
the options for resource creation.

---------

Co-authored-by: Steven <steven@ceriously.com>
This commit is contained in:
Florentin / 珞辰
2023-07-14 15:27:06 +02:00
committed by GitHub
parent a91bde5287
commit cae60155f3
11 changed files with 150 additions and 3 deletions

View File

@@ -1397,6 +1397,7 @@ const LAMBDA_RESERVED_COMPRESSED_SIZE = 250 * KIB;
export async function getPageLambdaGroups({
entryPath,
config,
functionsConfigManifest,
pages,
prerenderRoutes,
pageTraces,
@@ -1410,6 +1411,7 @@ export async function getPageLambdaGroups({
}: {
entryPath: string;
config: Config;
functionsConfigManifest?: FunctionsConfigManifestV1;
pages: string[];
prerenderRoutes: Set<string>;
pageTraces: {
@@ -1436,16 +1438,26 @@ export async function getPageLambdaGroups({
let opts: { memory?: number; maxDuration?: number } = {};
if (
functionsConfigManifest &&
functionsConfigManifest.functions[routeName]
) {
opts = functionsConfigManifest.functions[routeName];
}
if (config && config.functions) {
const sourceFile = await getSourceFilePathFromPage({
workPath: entryPath,
page,
pageExtensions,
});
opts = await getLambdaOptionsFromFunction({
const vercelConfigOpts = await getLambdaOptionsFromFunction({
sourceFile,
config,
});
opts = { ...vercelConfigOpts, ...opts };
}
let matchingGroup = groups.find(group => {
@@ -2388,6 +2400,16 @@ export {
getSourceFilePathFromPage,
};
export type FunctionsConfigManifestV1 = {
version: 1;
functions: Record<
string,
{
maxDuration?: number;
}
>;
};
type MiddlewareManifest = MiddlewareManifestV1 | MiddlewareManifestV2;
interface MiddlewareManifestV1 {
@@ -2731,6 +2753,37 @@ export async function getMiddlewareBundle({
};
}
/**
* Attempts to read the functions config manifest from the pre-defined
* location. If the manifest can't be found it will resolve to
* undefined.
*/
export async function getFunctionsConfigManifest(
entryPath: string,
outputDirectory: string
): Promise<FunctionsConfigManifestV1 | undefined> {
const functionConfigManifestPath = path.join(
entryPath,
outputDirectory,
'./server/functions-config-manifest.json'
);
const hasManifest = await fs
.access(functionConfigManifestPath)
.then(() => true)
.catch(() => false);
if (!hasManifest) {
return;
}
const manifest: FunctionsConfigManifestV1 = await fs.readJSON(
functionConfigManifestPath
);
return manifest.version === 1 ? manifest : undefined;
}
/**
* Attempts to read the middleware manifest from the pre-defined
* location. If the manifest can't be found it will resolve to