Home / Class/ ContainerPipeline Class — astro Architecture

ContainerPipeline Class — astro Architecture

Architecture documentation for the ContainerPipeline class in pipeline.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3["ContainerPipeline"]
  34831467_a238_d0f7_b82f_574e9e416484["pipeline.ts"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|defined in| 34831467_a238_d0f7_b82f_574e9e416484
  1ce449a4_d85a_dfd0_7ecd_e12ca58c8813["getName()"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|method| 1ce449a4_d85a_dfd0_7ecd_e12ca58c8813
  78019260_92f4_ec7e_da48_6aade289282f["create()"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|method| 78019260_92f4_ec7e_da48_6aade289282f
  d34ebbd9_3ab6_c9da_0b5b_472b38de9246["componentMetadata()"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|method| d34ebbd9_3ab6_c9da_0b5b_472b38de9246
  b6e71592_ae2d_e816_9222_62e56a8e10bb["headElements()"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|method| b6e71592_ae2d_e816_9222_62e56a8e10bb
  735ba179_276d_3c4c_7c5b_ae306468a54e["tryRewrite()"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|method| 735ba179_276d_3c4c_7c5b_ae306468a54e
  5c4d758d_9f6f_ac01_cdc5_283eed352176["insertRoute()"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|method| 5c4d758d_9f6f_ac01_cdc5_283eed352176
  2aa59556_8548_b5bf_a6a6_c3b895612816["getComponentByRoute()"]
  7feea19b_1eb1_3680_d050_0ea7bb95b6d3 -->|method| 2aa59556_8548_b5bf_a6a6_c3b895612816

Relationship Graph

Source Code

packages/astro/src/container/pipeline.ts lines 12–91

export class ContainerPipeline extends Pipeline {
	/**
	 * Internal cache to store components instances by `RouteData`.
	 * @private
	 */
	#componentsInterner: WeakMap<RouteData, SinglePageBuiltModule> = new WeakMap<
		RouteData,
		SinglePageBuiltModule
	>();

	getName(): string {
		return 'ContainerPipeline';
	}

	static create({
		logger,
		manifest,
		renderers,
		resolve,
		streaming,
	}: Pick<ContainerPipeline, 'logger' | 'manifest' | 'renderers' | 'resolve' | 'streaming'>) {
		return new ContainerPipeline(logger, manifest, 'development', renderers, resolve, streaming);
	}

	componentMetadata(_routeData: RouteData): Promise<SSRResult['componentMetadata']> | void {}

	headElements(routeData: RouteData): Promise<HeadElements> | HeadElements {
		const routeInfo = this.manifest.routes.find((route) => route.routeData === routeData);
		const links = new Set<never>();
		const scripts = new Set<SSRElement>();
		const styles = createStylesheetElementSet(routeInfo?.styles ?? []);

		for (const script of routeInfo?.scripts ?? []) {
			if ('stage' in script) {
				if (script.stage === 'head-inline') {
					scripts.add({
						props: {},
						children: script.children,
					});
				}
			} else {
				scripts.add(createModuleScriptElement(script));
			}
		}
		return { links, styles, scripts };
	}

	async tryRewrite(payload: RewritePayload, request: Request): Promise<TryRewriteResult> {
		const { newUrl, pathname, routeData } = findRouteToRewrite({
			payload,
			request,
			routes: this.manifest?.routes.map((r) => r.routeData),
			trailingSlash: this.manifest.trailingSlash,
			buildFormat: this.manifest.buildFormat,
			base: this.manifest.base,
			outDir: this.manifest.outDir,
		});

		const componentInstance = await this.getComponentByRoute(routeData);
		return { componentInstance, routeData, newUrl, pathname };
	}

	insertRoute(route: RouteData, componentInstance: ComponentInstance): void {
		this.#componentsInterner.set(route, {
			page() {
				return Promise.resolve(componentInstance);
			},
			onRequest: this.resolvedMiddleware,
		});
	}

	// At the moment it's not used by the container via any public API
	async getComponentByRoute(routeData: RouteData): Promise<ComponentInstance> {
		const page = this.#componentsInterner.get(routeData);
		if (page) {
			return page.page();
		}
		throw new Error("Couldn't find component for route " + routeData.pathname);
	}
}

Domain

Frequently Asked Questions

What is the ContainerPipeline class?
ContainerPipeline is a class in the astro codebase, defined in packages/astro/src/container/pipeline.ts.
Where is ContainerPipeline defined?
ContainerPipeline is defined in packages/astro/src/container/pipeline.ts at line 12.

Analyze Your Own Codebase

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

Try Supermodel Free