Home / Function/ runHookConfigSetup() — astro Function Reference

runHookConfigSetup() — astro Function Reference

Architecture documentation for the runHookConfigSetup() function in hooks.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  be77f595_7989_6e12_ba52_33627e2d9d4d["runHookConfigSetup()"]
  19f4084c_157f_a15d_f001_5d8088b75dee["hooks.ts"]
  be77f595_7989_6e12_ba52_33627e2d9d4d -->|defined in| 19f4084c_157f_a15d_f001_5d8088b75dee
  1e1ca282_3771_2cb3_ede6_ff5ab0d382fa["runHookInternal()"]
  be77f595_7989_6e12_ba52_33627e2d9d4d -->|calls| 1e1ca282_3771_2cb3_ede6_ff5ab0d382fa
  2873f6b6_8222_203b_2706_97a1fe360c5a["normalizeCodegenDir()"]
  be77f595_7989_6e12_ba52_33627e2d9d4d -->|calls| 2873f6b6_8222_203b_2706_97a1fe360c5a
  style be77f595_7989_6e12_ba52_33627e2d9d4d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/integrations/hooks.ts lines 175–360

export async function runHookConfigSetup({
	settings,
	command,
	logger,
	isRestart = false,
	fs = fsMod,
}: RunHookConfigSetup): Promise<AstroSettings> {
	// An adapter is an integration, so if one is provided add it to the list of integrations.
	if (settings.config.adapter) {
		settings.config.integrations.unshift(settings.config.adapter);
	}
	const actionsFilename = await isActionsFilePresent(fs, settings.config.srcDir);
	if (actionsFilename) {
		settings.config.integrations.push(
			astroIntegrationActionsRouteHandler({ settings, filename: actionsFilename }),
		);
	}

	let updatedConfig: AstroConfig = { ...settings.config };
	let updatedSettings: AstroSettings = { ...settings, config: updatedConfig };
	let addedClientDirectives = new Map<string, Promise<string>>();
	let astroJSXRenderer: AstroRenderer | null = null;

	// eslint-disable-next-line @typescript-eslint/prefer-for-of -- We need a for loop to be able to read integrations pushed while the loop is running.
	for (let i = 0; i < updatedConfig.integrations.length; i++) {
		const integration = updatedConfig.integrations[i];

		/**
		 * By making integration hooks optional, Astro can now ignore null or undefined Integrations
		 * instead of giving an internal error most people can't read
		 *
		 * This also enables optional integrations, e.g.
		 * ```ts
		 * integration: [
		 *   // Only run `compress` integration in production environments, etc...
		 *   import.meta.env.production ? compress() : null
		 * ]
		 * ```
		 */

		const { integrationLogger } = await runHookInternal({
			integration,
			hookName: 'astro:config:setup',
			logger,
			params: () => {
				const hooks: Omit<HookParameters<'astro:config:setup'>, 'logger'> = {
					config: updatedConfig,
					command,
					isRestart,
					addRenderer(renderer: AstroRenderer) {
						if (!renderer.name) {
							throw new Error(
								`Integration ${colors.bold(integration.name)} has an unnamed renderer.`,
							);
						}

						if (!renderer.serverEntrypoint) {
							throw new Error(
								`Renderer ${colors.bold(renderer.name)} does not provide a serverEntrypoint.`,
							);
						}

						if (renderer.name === 'astro:jsx') {
							astroJSXRenderer = renderer;
						} else {
							updatedSettings.renderers.push(renderer);
						}
					},
					injectScript: (stage, content) => {
						updatedSettings.scripts.push({ stage, content });
					},
					updateConfig: (newConfig) => {
						updatedConfig = mergeConfig(updatedConfig, newConfig);
						return { ...updatedConfig };
					},
					injectRoute: (injectRoute) => {
						if (injectRoute.entrypoint == null && 'entryPoint' in injectRoute) {
							logger.warn(
								null,
								`The injected route "${injectRoute.pattern}" by ${integration.name} specifies the entry point with the "entryPoint" property. This property is deprecated, please use "entrypoint" instead.`,
							);

Domain

Subdomains

Frequently Asked Questions

What does runHookConfigSetup() do?
runHookConfigSetup() is a function in the astro codebase, defined in packages/astro/src/integrations/hooks.ts.
Where is runHookConfigSetup() defined?
runHookConfigSetup() is defined in packages/astro/src/integrations/hooks.ts at line 175.
What does runHookConfigSetup() call?
runHookConfigSetup() calls 2 function(s): normalizeCodegenDir, runHookInternal.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free