UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

19 lines (18 loc) • 1 kB
import { fileExtension } from "@astrojs/internal-helpers/path"; import { VIRTUAL_PAGE_MODULE_ID } from "./const.js"; // This is an arbitrary string that we use to replace the dot of the extension. const ASTRO_PAGE_EXTENSION_POST_PATTERN = "@_@"; /** * Prevents Rolldown from triggering other plugins in the process by masking the extension (hence the virtual file). * Inverse function of getComponentFromVirtualModulePageName() below. * @param virtualModulePrefix The prefix used to create the virtual module * @param path Page component path */ export function getVirtualModulePageName(virtualModulePrefix, path) { const extension = fileExtension(path); return virtualModulePrefix + (extension.startsWith(".") ? path.slice(0, -extension.length) + extension.replace(".", ASTRO_PAGE_EXTENSION_POST_PATTERN) : path); } export function getVirtualModulePageNameForComponent(component) { const virtualModuleName = getVirtualModulePageName(VIRTUAL_PAGE_MODULE_ID, component); return virtualModuleName; }