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

Code before:
				await generatePathWithLogs(path, route, integrationRoute, i, paths, false);
			}
		}
	}
}

function* eachRouteInRouteData(route: RouteData) {
	yield route;
	for (const fallbackRoute of route.fallbackRoutes) {
		yield fallbackRoute;
	}
}

async function getPathsForRoute(
	route: RouteData,
	componentPath: string,
	pageMap: Map<string, () => Promise<SinglePageBuiltModule>>,
	app: BaseApp,
	pipeline: BuildPipeline,
	builtPaths: Set<string>,
): Promise<Array<string>> {
	const { logger, options, manifest } = pipeline;
	const { routeCache } = app.pipeline;
	let paths: Array<string> = [];
	if (route.pathname) {
		paths.push(route.pathname);
		builtPaths.add(removeTrailingForwardSlash(route.pathname));
	} else {
		// Load page module only when we need it for getStaticPaths
		const pageModuleFn = pageMap.get(componentPath);
		if (!pageModuleFn) {
			throw new Error(
				`Unable to find module for ${componentPath}. This is unexpected and likely a bug in Astro, please report.`,
			);
		}
		const pageModule = await pageModuleFn();
		const mod = await pageModule.page();

		const staticPaths = await callGetStaticPaths({
			mod,
			route,
			routeCache,
			ssr: manifest.serverLike,
			base: manifest.base,
			trailingSlash: manifest.trailingSlash,
		}).catch((err) => {
			logger.error('build', `Failed to call getStaticPaths for ${route.component}`);
			throw err;
		});

		const label = staticPaths.length === 1 ? 'page' : 'pages';

Review comment (bug):
This feels wrong, there's something incorrect. We already have the pipeline here, so why are we passing `BaseApp`? Was it a mistake?

I'm not really sure about this direction. Can you please explain what's going on?

Code after:
				await generatePathWithLogs(path, route, integrationRoute, i, paths, false);
			}
		}
	}
}

function* eachRouteInRouteData(route: RouteData) {
	yield route;
	for (const fallbackRoute of route.fallbackRoutes) {
		yield fallbackRoute;
	}
}

async function getPathsForRoute(
	route: RouteData,
	componentPath: string,
	pageMap: Map<string, () => Promise<SinglePageBuiltModule>>,
	app: BaseApp,
	pipeline: BuildPipeline,
	builtPaths: Set<string>,
): Promise<Array<string>> {
	const { logger, options, manifest } = pipeline;
	// TODO: investigate if BuildPipeline can be removed. We already have app.pipeline
	// which contains routeCache and other pipeline data. Eventually all pipeline info
	// should come from app.pipeline and BuildPipeline can be eliminated.
	const { routeCache } = app.pipeline;
	let paths: Array<string> = [];
	if (route.pathname) {
		paths.push(route.pathname);
		builtPaths.add(removeTrailingForwardSlash(route.pathname));
	} else {
		// Load page module only when we need it for getStaticPaths
		const pageModuleFn = pageMap.get(componentPath);
		if (!pageModuleFn) {
			throw new Error(
				`Unable to find module for ${componentPath}. This is unexpected and likely a bug in Astro, please report.`,
			);
		}
		const pageModule = await pageModuleFn();
		const mod = await pageModule.page();

		const staticPaths = await callGetStaticPaths({
			mod,
			route,
			routeCache,
			ssr: manifest.serverLike,
			base: manifest.base,
			trailingSlash: manifest.trailingSlash,
		}).catch((err) => {
			logger.error('build', `Failed to call getStaticPaths for ${route.component}`);
			throw err;