/// import { Socket } from 'node:net'; import { RouterState } from 'react-router'; import { Alias, ModuleNode, RenderBuiltAssetUrl } from 'vite'; import { IRequestContext } from "../node/render.js"; import { TRoutesTree } from "./parse-routes.js"; import PathNormalize from "./path-normalize.js"; import ServerConfig from "./server-config.js"; interface ISsrManifestParams { buildDir?: string; viteAliases?: Alias[]; basename?: string; renderBuiltUrl?: RenderBuiltAssetUrl; } interface IManifest { [path: string]: { assets: string[]; css: string[]; file: string; isEntry?: boolean; imports: string[]; }; } declare enum AssetType { style = "style", script = "script", image = "image", font = "font" } interface IAsset { type: AssetType; url: string; weight: number; isNested: boolean; isPreload: boolean; content?: string; } type TAssets = { [id: string]: IAsset; }; /** * Working with SSR Manifest file */ declare class SsrManifest { /** * Singleton */ protected static instance: SsrManifest | null; /** * Server config */ protected readonly config: ServerConfig; /** * Path normalize service */ protected readonly pathNormalize: PathNormalize; /** * Project root path */ protected readonly root: string; /** * Build dir */ protected readonly buildDir?: string; /** * Client manifest file name */ protected readonly manifestName = "manifest.json"; /** * Assets manifest file name */ protected readonly assetsManifest = "assets-manifest.json"; /** * Vite resolve aliases */ protected readonly viteAliases?: Alias[]; /** * Vite base */ protected readonly basename?: string; /** * Vite renderBuiltUrl config func */ protected readonly renderBuiltUrl?: RenderBuiltAssetUrl; /** * Loaded assets manifest file */ protected routesAssets: Record | null; /** * @constructor */ /** * @constructor */ protected constructor(config: ServerConfig, { buildDir, viteAliases, basename, renderBuiltUrl }?: ISsrManifestParams); /** * Get singleton instance */ /** * Get singleton instance */ static get(config: ServerConfig, params?: ISsrManifestParams): SsrManifest; /** * Get output dir */ /** * Get output dir */ protected getOutDir(): string; /** * Get assets manifest file name */ /** * Get assets manifest file name */ protected getAssetsManifestFile(): string; /** * Load client ssr manifest */ /** * Load client ssr manifest */ protected loadClientManifest(): IManifest; /** * Load assets manifest */ /** * Load assets manifest */ protected loadAssetsManifest(): Record; /** * Same as 'getAsyncRoutesIds' but for routes tree from 'ParseRoutes' */ /** * Same as 'getAsyncRoutesIds' but for routes tree from 'ParseRoutes' */ protected getRoutesTreeIds(routes: TRoutesTree[], index?: string): Record; /** * Sort assets */ /** * Sort assets */ protected sortAssets(assets: IAsset[]): IAsset[]; /** * Get recursive module assets */ /** * Get recursive module assets */ protected getRouteAssets(manifest: IManifest, module: IManifest[string], isNested?: boolean): Record; /** * Build routes manifest file */ /** * Build routes manifest file */ buildRoutesManifest(): void; /** * Get route assets */ /** * Get route assets */ protected getAssets(routes?: RouterState['matches']): IAsset[]; /** * Get development route assets */ /** * Get development route assets */ protected getAssetsDev(routes?: RouterState['matches']): IAsset[]; /** * Get module assets */ /** * Get module assets */ protected getModuleAssets(module?: ModuleNode, skipModules?: Set): TAssets; /** * Get asset weight */ /** * Get asset weight */ protected getAssetWeight(asset: string): number; /** * Get asset type */ /** * Get asset type */ protected getAssetType(asset: string): AssetType | null; /** * Write 103 Early Hits header */ /** * Write 103 Early Hits header */ writeEarlyHits(assets: IAsset[], socket: Socket): void; /** * Inject route assets to head html */ /** * Inject route assets to head html */ injectAssets({ routerContext, html, res, hasEarlyHints }: IRequestContext): void; } export { SsrManifest as default };