add() — astro Function Reference
Architecture documentation for the add() function in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD e251add5_ea46_2280_c246_1b5a023acc3b["add()"] 9151bb3d_ee1e_da42_752a_45a9db1dd918["index.ts"] e251add5_ea46_2280_c246_1b5a023acc3b -->|defined in| 9151bb3d_ee1e_da42_752a_45a9db1dd918 ffb00280_f878_7381_fa3f_c64fddb70bbc["validateIntegrations()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| ffb00280_f878_7381_fa3f_c64fddb70bbc d8c50440_84a7_3639_a0ff_bb413e95ec8d["tryToInstallIntegrations()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| d8c50440_84a7_3639_a0ff_bb413e95ec8d 2ee262d1_8614_9c2d_75fd_5bb9c01ac63c["askToContinue()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| 2ee262d1_8614_9c2d_75fd_5bb9c01ac63c f3e6969a_3f04_43b5_609b_fdfd7fa60748["updatePackageJsonScripts()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| f3e6969a_3f04_43b5_609b_fdfd7fa60748 bd16dbfd_3c3b_e117_15e8_b4bea7275e1e["setupIntegrationConfig()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| bd16dbfd_3c3b_e117_15e8_b4bea7275e1e 78992d43_7604_45bb_6f89_af949ca96aac["createPrettyError()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| 78992d43_7604_45bb_6f89_af949ca96aac 1b80a1c6_91ad_094f_2427_a33bbc0e05f9["isAdapter()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| 1b80a1c6_91ad_094f_2427_a33bbc0e05f9 baa08624_1acd_75f1_ecfc_8d7091335a43["setAdapter()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| baa08624_1acd_75f1_ecfc_8d7091335a43 ad3d573d_7d5f_ba89_5752_05ae2a8219e1["addVitePlugin()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| ad3d573d_7d5f_ba89_5752_05ae2a8219e1 07b08a43_b086_cd40_27c8_a3517efced2a["addIntegration()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| 07b08a43_b086_cd40_27c8_a3517efced2a b580bf78_66fd_0e74_f9b4_b1847fcf475e["updateAstroConfig()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| b580bf78_66fd_0e74_f9b4_b1847fcf475e 6bba8e7c_bf8b_374e_8b24_b01c2bdb5bd4["getDiffContent()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| 6bba8e7c_bf8b_374e_8b24_b01c2bdb5bd4 31c483d1_c4ed_7d00_d4c0_9cbf5313e1d8["updateTSConfig()"] e251add5_ea46_2280_c246_1b5a023acc3b -->|calls| 31c483d1_c4ed_7d00_d4c0_9cbf5313e1d8 style e251add5_ea46_2280_c246_1b5a023acc3b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/cli/add/index.ts lines 109–527
export async function add(names: string[], { flags }: AddOptions) {
ensureProcessNodeEnv('production');
const inlineConfig = flagsToAstroInlineConfig(flags);
const { userConfig } = await resolveConfig(inlineConfig, 'add');
telemetry.record(eventCliSession('add', userConfig));
if (flags.help || names.length === 0) {
printHelp({
commandName: 'astro add',
usage: '[...integrations] [...adapters]',
tables: {
Flags: [
['--yes', 'Accept all prompts.'],
['--help', 'Show this help message.'],
],
'UI Frameworks': [
['react', 'astro add react'],
['preact', 'astro add preact'],
['vue', 'astro add vue'],
['svelte', 'astro add svelte'],
['solid-js', 'astro add solid-js'],
['lit', 'astro add lit'],
['alpinejs', 'astro add alpinejs'],
],
'Documentation Frameworks': [['starlight', 'astro add starlight']],
'SSR Adapters': [
['netlify', 'astro add netlify'],
['vercel', 'astro add vercel'],
['deno', 'astro add deno'],
['cloudflare', 'astro add cloudflare'],
['node', 'astro add node'],
],
Others: [
['db', 'astro add db'],
['tailwind', 'astro add tailwind'],
['mdx', 'astro add mdx'],
['markdoc', 'astro add markdoc'],
['partytown', 'astro add partytown'],
['sitemap', 'astro add sitemap'],
],
},
description: `For more integrations, check out: ${cyan('https://astro.build/integrations')}`,
});
return;
}
// Some packages might have a common alias! We normalize those here.
const cwd = inlineConfig.root;
const logger = createLoggerFromFlags(flags);
const integrationNames = names.map((name) => (ALIASES.has(name) ? ALIASES.get(name)! : name));
const integrations = await validateIntegrations(integrationNames, flags, logger);
const hasCloudflareIntegration = integrations.some(
(integration) => integration.id === 'cloudflare',
);
let installResult = await tryToInstallIntegrations({ integrations, cwd, flags, logger });
const rootPath = resolveRoot(cwd);
const root = pathToFileURL(rootPath);
// Append forward slash to compute relative paths
root.href = appendForwardSlash(root.href);
const rawConfigPath = await resolveConfigPath({
root: rootPath,
configFile: inlineConfig.configFile,
fs: fsMod,
});
let configURL = rawConfigPath ? pathToFileURL(rawConfigPath) : undefined;
if (configURL) {
logger.debug('add', `Found config at ${configURL}`);
} else {
logger.info('add', `Unable to locate a config file, generating one for you.`);
configURL = new URL('./astro.config.mjs', root);
await fs.writeFile(fileURLToPath(configURL), STUBS.ASTRO_CONFIG, { encoding: 'utf-8' });
}
let packageJson:
| { type: 'exists'; data: { name: string; dependencies?: any; devDependencies?: any } }
| { type: 'unknown' }
| { type: 'does-not-exist' } = { type: 'unknown' };
async function getPackageJson() {
if (packageJson.type === 'exists') {
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does add() do?
add() is a function in the astro codebase, defined in packages/astro/src/cli/add/index.ts.
Where is add() defined?
add() is defined in packages/astro/src/cli/add/index.ts at line 109.
What does add() call?
add() calls 13 function(s): addIntegration, addVitePlugin, askToContinue, createPrettyError, getDiffContent, isAdapter, setAdapter, setupIntegrationConfig, and 5 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free