VercelBuilder Class — astro Architecture
Architecture documentation for the VercelBuilder class in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD b9cdb338_a865_cfb5_1987_5fa8663f4726["VercelBuilder"] 9b72c5c7_3349_4acd_8ca1_afe541842abe["index.ts"] b9cdb338_a865_cfb5_1987_5fa8663f4726 -->|defined in| 9b72c5c7_3349_4acd_8ca1_afe541842abe a67662ae_0ef1_3f96_3043_23c8c4f1cd11["constructor()"] b9cdb338_a865_cfb5_1987_5fa8663f4726 -->|method| a67662ae_0ef1_3f96_3043_23c8c4f1cd11 b08d0cb6_4d5e_9fe0_317b_85cd9ce4765d["buildServerlessFolder()"] b9cdb338_a865_cfb5_1987_5fa8663f4726 -->|method| b08d0cb6_4d5e_9fe0_317b_85cd9ce4765d 8053f98f_c4a0_24d5_fb52_9329536f5a87["buildISRFolder()"] b9cdb338_a865_cfb5_1987_5fa8663f4726 -->|method| 8053f98f_c4a0_24d5_fb52_9329536f5a87 e0424635_5fcc_b507_73d9_0057236d2bb6["buildMiddlewareFolder()"] b9cdb338_a865_cfb5_1987_5fa8663f4726 -->|method| e0424635_5fcc_b507_73d9_0057236d2bb6
Relationship Graph
Source Code
packages/integrations/vercel/src/index.ts lines 645–727
class VercelBuilder {
readonly NTF_CACHE = {};
constructor(
readonly config: AstroConfig,
readonly excludeFiles: URL[],
readonly includeFiles: URL[],
readonly logger: AstroIntegrationLogger,
readonly outDir: URL,
readonly maxDuration?: number,
readonly runtime = getRuntime(process, logger),
) {}
async buildServerlessFolder(entry: URL, functionName: string, root: URL) {
const { includeFiles, excludeFiles, logger, NTF_CACHE, runtime, maxDuration } = this;
// .vercel/output/functions/<name>.func/
const functionFolder = new URL(`./functions/${functionName}.func/`, this.outDir);
const packageJson = new URL(`./functions/${functionName}.func/package.json`, this.outDir);
const vcConfig = new URL(`./functions/${functionName}.func/.vc-config.json`, this.outDir);
// Copy necessary files (e.g. node_modules/)
const { handler } = await copyDependenciesToFunction(
{
entry,
outDir: functionFolder,
includeFiles,
excludeFiles,
logger,
root,
},
NTF_CACHE,
);
// Enable ESM
// https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/
await writeJson(packageJson, {
type: 'module',
});
// Serverless function config
// https://vercel.com/docs/build-output-api/v3#vercel-primitives/serverless-functions/configuration
await writeJson(vcConfig, {
runtime,
handler: handler.replaceAll('\\', '/'),
launcherType: 'Nodejs',
maxDuration,
supportsResponseStreaming: true,
});
}
async buildISRFolder(entry: URL, functionName: string, isr: VercelISRConfig, root: URL) {
await this.buildServerlessFolder(entry, functionName, root);
const prerenderConfig = new URL(
`./functions/${functionName}.prerender-config.json`,
this.outDir,
);
// https://vercel.com/docs/build-output-api/v3/primitives#prerender-configuration-file
await writeJson(prerenderConfig, {
expiration: isr.expiration ?? false,
bypassToken: isr.bypassToken,
allowQuery: [ASTRO_PATH_PARAM],
passQuery: true,
});
}
async buildMiddlewareFolder(entry: URL, functionName: string, middlewareSecret: string) {
const functionFolder = new URL(`./functions/${functionName}.func/`, this.outDir);
await generateEdgeMiddleware(
entry,
this.config.root,
new URL(VERCEL_EDGE_MIDDLEWARE_FILE, this.config.srcDir),
new URL('./middleware.mjs', functionFolder),
middlewareSecret,
this.logger,
);
await writeJson(new URL(`./.vc-config.json`, functionFolder), {
runtime: 'edge',
entrypoint: 'middleware.mjs',
});
Domain
Defined In
Source
Frequently Asked Questions
What is the VercelBuilder class?
VercelBuilder is a class in the astro codebase, defined in packages/integrations/vercel/src/index.ts.
Where is VercelBuilder defined?
VercelBuilder is defined in packages/integrations/vercel/src/index.ts at line 645.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free