Home / File/ page.ts — astro Source File

page.ts — astro Source File

Architecture documentation for page.ts, a typescript file in the astro codebase. 7 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 7 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e["page.ts"]
  7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"]
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e --> 7e4494c0_5563_4329_1bff_a84be66e1bc2
  313916b3_64e3_9a00_0504_f5123ae24ad8["../core/routing/default.js"]
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e --> 313916b3_64e3_9a00_0504_f5123ae24ad8
  c923dac6_4ccb_a783_dee2_4bc95f0ebcf1["../core/routing/index.js"]
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e --> c923dac6_4ccb_a783_dee2_4bc95f0ebcf1
  e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"]
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e --> e9b74c5a_8d34_34a7_e196_5e41b87214aa
  c0c8a87f_ca88_4ea8_585b_2040cded1231["./const.js"]
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e --> c0c8a87f_ca88_4ea8_585b_2040cded1231
  7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"]
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  0ca4b994_0ce6_e5b5_9813_c64eb15ad76e --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  style 0ca4b994_0ce6_e5b5_9813_c64eb15ad76e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Plugin as VitePlugin } from 'vite';
import { prependForwardSlash } from '../core/path.js';
import { DEFAULT_COMPONENTS } from '../core/routing/default.js';
import { routeIsRedirect } from '../core/routing/index.js';
import type { RoutesList } from '../types/astro.js';
import { VIRTUAL_PAGE_MODULE_ID, VIRTUAL_PAGE_RESOLVED_MODULE_ID } from './const.js';
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../core/constants.js';

interface PagePluginOptions {
	routesList: RoutesList;
}

export function pluginPage({ routesList }: PagePluginOptions): VitePlugin {
	return {
		name: '@astro/plugin-page',
		applyToEnvironment(environment) {
			return (
				environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr ||
				environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender
			);
		},
		resolveId: {
			filter: {
				id: new RegExp(`^${VIRTUAL_PAGE_MODULE_ID}`),
			},
			handler(id) {
				return VIRTUAL_PAGE_RESOLVED_MODULE_ID + id.slice(VIRTUAL_PAGE_MODULE_ID.length);
			},
		},
		load: {
			filter: {
				id: new RegExp(`^${VIRTUAL_PAGE_RESOLVED_MODULE_ID}`),
			},
			handler(id) {
				const componentPath = getComponentFromVirtualModulePageName(
					VIRTUAL_PAGE_RESOLVED_MODULE_ID,
					id,
				);

				// Skip default components (404, server islands, etc.)
				if (DEFAULT_COMPONENTS.some((component) => componentPath === component)) {
					return { code: '' };
				}

				// Find the route(s) that use this component
				const routes = routesList.routes.filter((route) => route.component === componentPath);

				for (const route of routes) {
					if (routeIsRedirect(route)) {
						continue;
					}

					const astroModuleId = prependForwardSlash(componentPath);
					const imports: string[] = [];
					const exports: string[] = [];

					imports.push(`import * as _page from ${JSON.stringify(astroModuleId)};`);
					exports.push(`export const page = () => _page`);

					return { code: `${imports.join('\n')}\n${exports.join('\n')}` };
				}
			},
		},
	};
}

/**
 * From the VirtualModulePageName, get the component path.
 * Remember that the component can be use by multiple routes.
 */
function getComponentFromVirtualModulePageName(virtualModulePrefix: string, id: string): string {
	return id.slice(virtualModulePrefix.length).replace(/@_@/g, '.');
}

Domain

Subdomains

Dependencies

  • ../core/constants.js
  • ../core/path.js
  • ../core/routing/default.js
  • ../core/routing/index.js
  • ../types/astro.js
  • ./const.js
  • vite

Frequently Asked Questions

What does page.ts do?
page.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in page.ts?
page.ts defines 2 function(s): getComponentFromVirtualModulePageName, pluginPage.
What does page.ts depend on?
page.ts imports 7 module(s): ../core/constants.js, ../core/path.js, ../core/routing/default.js, ../core/routing/index.js, ../types/astro.js, ./const.js, vite.
Where is page.ts in the architecture?
page.ts is located at packages/astro/src/vite-plugin-pages/page.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-pages).

Analyze Your Own Codebase

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

Try Supermodel Free