import { Construct } from "constructs"; import { NextjsType } from "../constants"; import { NextjsBaseProps } from "../root-constructs/nextjs-base-construct"; export interface NextjsBuildProps { /** * @see {@link NextjsBaseProps["buildCommand"]} */ readonly buildCommand: NextjsBaseProps["buildCommand"]; /** * Directory where the Next.js application is located for local builds. * This should contain the package.json and Next.js application files. */ readonly buildDirectory: string; readonly nextjsType: NextjsType; /** * @see {@link NextjsBaseProps.skipBuild} */ readonly skipBuild?: boolean; } export interface PublicDirEntry { readonly name: string; readonly isDirectory: boolean; } /** * Builds Next.js assets. * @link https://nextjs.org/docs/pages/api-reference/next-config-js/output */ export declare class NextjsBuild extends Construct { /** * Unique id for Next.js build. Used to partition cache storage and as * metadata for static assets in S3 bucket. */ buildId: string; /** * Absolute path to the init cache directory * @example "/Users/john/myapp/.next/cdk-nextjs-init-cache" */ initCacheDir: string; /** * Absolute path to public. Use by CloudFront/ALB to create behaviors/rules * @example "/Users/john/myapp/public" */ publicDirEntries: PublicDirEntry[]; /** * The entrypoint JavaScript file used as an argument for Node.js to run the * Next.js standalone server relative to the standalone directory. * @example "./server.js" * @example "./packages/ui/server.js" (monorepo) */ relativePathToEntrypoint: string; /** * Relative path from the standalone directory to the package containing the Next.js app. * This is automatically detected from the standalone build output. * @example "." for non-monorepo apps * @example "./apps/web" for monorepo apps */ relativePathToPackage: string; /** * Absolute path to the .next directory containing Next.js build artifacts */ dotNextPath: string; private props; private buildCommand; constructor(scope: Construct, id: string, props: NextjsBuildProps); /** * Execute local build command in the specified directory */ private runNextBuild; /** * Validate Next.js build output * All builds must be standalone - no fallback to regular builds */ private validateNextBuildOutput; /** * Find entrypoint client side js files to patch `fetch` only for NextjsGlobalFunctions */ private patchFetchInClientJs; /** * Automatically finds the relative path from standalone directory to the * package containing server.js by searching for server.js with a .next sibling. * @returns "." for non-monorepo apps, or relative path like "app-playground" for monorepo apps */ private findRelativePathToServerJs; /** * Get build ID from .next directory */ private getBuildId; /** * Get public directory entries from local filesystem */ private getLocalPublicDirEntries; /** * Recursively find and remove existing Sharp platform binaries */ private removeExistingSharpBinaries; /** * Download and install correct Sharp binaries for Linux MUSL */ private downloadAndInstallSharpBinaries; }