Repository: withastro/astro
File: packages/astro/src/core/build/generate.ts (TypeScript)

Code before:
import { type BuildInternals, hasPrerenderedPages } from './internal.js';
import type { StaticBuildOptions } from './types.js';
import { getTimeStat, shouldAppendForwardSlash } from './util.js';

export async function generatePages(
	options: StaticBuildOptions,
	internals: BuildInternals,
	prerenderOutputDir: URL,
) {
	const generatePagesTimer = performance.now();
	const ssr = options.settings.buildOutput === 'server';
	// Import from the single prerender entrypoint
	const prerenderEntryFileName = internals.prerenderEntryFileName;
	if (!prerenderEntryFileName) {
		throw new Error(
			`Prerender entry filename not found in build internals. This is likely a bug in Astro.`,
		);
	}
	const prerenderEntryUrl = new URL(prerenderEntryFileName, prerenderOutputDir);
	const prerenderEntry = await import(prerenderEntryUrl.toString());

	// Grab the manifest and create the pipeline
	const app = prerenderEntry.app as BuildApp;
	app.setInternals(internals);
	app.setOptions(options);
	app.setLogger(options.logger);

	const logger = app.logger;

	// HACK! `astro:assets` relies on a global to know if its running in dev, prod, ssr, ssg, full moon
	// If we don't delete it here, it's technically not impossible (albeit improbable) for it to leak
	if (ssr && !hasPrerenderedPages(internals)) {
		delete globalThis?.astroAsset?.addStaticImage;
	}

	const verb = ssr ? 'prerendering' : 'generating';
	logger.info('SKIP_FORMAT', `\n${colors.bgGreen(colors.black(` ${verb} static routes `))}`);
	const builtPaths = new Set<string>();
	const pagesToGenerate = app.pipeline.retrieveRoutesToGenerate();
	const routeToHeaders: RouteToHeaders = new Map();

	if (ssr) {
		for (const routeData of pagesToGenerate) {
			if (routeData.prerender) {
				// i18n domains won't work with pre rendered routes at the moment, so we need to throw an error
				if (app.manifest.i18n?.domains && Object.keys(app.manifest.i18n.domains).length > 0) {
					throw new AstroError({
						...NoPrerenderedRoutesWithDomains,
						message: NoPrerenderedRoutesWithDomains.message(routeData.component),
					});
				}

Review comment (suggestion):
`setLogger` is redundant. At line 59, we already use `setOptions` and we pass `options`. Update the `setOptions` function to set the logger. 

Code after:
import { type BuildInternals, hasPrerenderedPages } from './internal.js';
import type { StaticBuildOptions } from './types.js';
import { getTimeStat, shouldAppendForwardSlash } from './util.js';

export async function generatePages(
	options: StaticBuildOptions,
	internals: BuildInternals,
	prerenderOutputDir: URL,
) {
	const generatePagesTimer = performance.now();
	const ssr = options.settings.buildOutput === 'server';
	// Import from the single prerender entrypoint
	const prerenderEntryFileName = internals.prerenderEntryFileName;
	if (!prerenderEntryFileName) {
		throw new Error(
			`Prerender entry filename not found in build internals. This is likely a bug in Astro.`,
		);
	}
	const prerenderEntryUrl = new URL(prerenderEntryFileName, prerenderOutputDir);
	const prerenderEntry = await import(prerenderEntryUrl.toString());

	// Grab the manifest and create the pipeline
	const app = prerenderEntry.app as BuildApp;
	app.setInternals(internals);
	app.setOptions(options);

	const logger = app.logger;

	// HACK! `astro:assets` relies on a global to know if its running in dev, prod, ssr, ssg, full moon
	// If we don't delete it here, it's technically not impossible (albeit improbable) for it to leak
	if (ssr && !hasPrerenderedPages(internals)) {
		delete globalThis?.astroAsset?.addStaticImage;
	}

	const verb = ssr ? 'prerendering' : 'generating';
	logger.info('SKIP_FORMAT', `\n${colors.bgGreen(colors.black(` ${verb} static routes `))}`);
	const builtPaths = new Set<string>();
	const pagesToGenerate = app.pipeline.retrieveRoutesToGenerate();
	const routeToHeaders: RouteToHeaders = new Map();

	if (ssr) {
		for (const routeData of pagesToGenerate) {
			if (routeData.prerender) {
				// i18n domains won't work with pre rendered routes at the moment, so we need to throw an error
				if (app.manifest.i18n?.domains && Object.keys(app.manifest.i18n.domains).length > 0) {
					throw new AstroError({
						...NoPrerenderedRoutesWithDomains,
						message: NoPrerenderedRoutesWithDomains.message(routeData.component),
					});
				}