Home / File/ virtual-module.ts — astro Source File

virtual-module.ts — astro Source File

Architecture documentation for virtual-module.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 4 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  85e53bb9_8e7d_d72e_753a_aada8d95b40a["virtual-module.ts"]
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  85e53bb9_8e7d_d72e_753a_aada8d95b40a --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  31036a74_f7c5_ea7e_9a2b_48816d66a722["../manifest/serialized.js"]
  85e53bb9_8e7d_d72e_753a_aada8d95b40a --> 31036a74_f7c5_ea7e_9a2b_48816d66a722
  7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"]
  85e53bb9_8e7d_d72e_753a_aada8d95b40a --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  85e53bb9_8e7d_d72e_753a_aada8d95b40a --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  style 85e53bb9_8e7d_d72e_753a_aada8d95b40a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Plugin } from 'vite';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { SERIALIZED_MANIFEST_ID } from './serialized.js';
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../core/constants.js';

const VIRTUAL_SERVER_ID = 'astro:config/server';
const RESOLVED_VIRTUAL_SERVER_ID = '\0' + VIRTUAL_SERVER_ID;
const VIRTUAL_CLIENT_ID = 'astro:config/client';
const RESOLVED_VIRTUAL_CLIENT_ID = '\0' + VIRTUAL_CLIENT_ID;

export default function virtualModulePlugin(): Plugin {
	return {
		name: 'astro-manifest-plugin',
		resolveId: {
			filter: {
				id: new RegExp(`^(${VIRTUAL_SERVER_ID}|${VIRTUAL_CLIENT_ID})$`),
			},
			handler(id) {
				if (id === VIRTUAL_SERVER_ID) {
					return RESOLVED_VIRTUAL_SERVER_ID;
				}
				if (id === VIRTUAL_CLIENT_ID) {
					return RESOLVED_VIRTUAL_CLIENT_ID;
				}
			},
		},
		load: {
			filter: {
				id: new RegExp(`^(${RESOLVED_VIRTUAL_SERVER_ID}|${RESOLVED_VIRTUAL_CLIENT_ID})$`),
			},
			handler(id) {
				if (id === RESOLVED_VIRTUAL_CLIENT_ID) {
					// There's nothing wrong about using `/client` on the server
					const code = `
import { manifest } from '${SERIALIZED_MANIFEST_ID}'
import { fromRoutingStrategy } from 'astro/app';

let i18n = undefined;
if (manifest.i18n) {
i18n = {
  defaultLocale: manifest.i18n.defaultLocale,
  locales: manifest.i18n.locales,
  routing: fromRoutingStrategy(manifest.i18n.strategy, manifest.i18n.fallbackType),
  fallback: manifest.i18n.fallback
  };
}

const base = manifest.base;
const trailingSlash = manifest.trailingSlash;
const site = manifest.site;
const compressHTML = manifest.compressHTML;
const build = {
  format: manifest.buildFormat,
};

export { base, i18n, trailingSlash, site, compressHTML, build };
				`;
					return { code };
				}
				if (id == RESOLVED_VIRTUAL_SERVER_ID) {
					if (this.environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.client) {
						throw new AstroError({
							...AstroErrorData.ServerOnlyModule,
							message: AstroErrorData.ServerOnlyModule.message(VIRTUAL_SERVER_ID),
						});
					}
					const code = `
import { manifest } from '${SERIALIZED_MANIFEST_ID}'
import { fromRoutingStrategy } from "astro/app";

let i18n = undefined;
if (manifest.i18n) {
 i18n = {
   defaultLocale: manifest.i18n.defaultLocale,
   locales: manifest.i18n.locales,
   routing: fromRoutingStrategy(manifest.i18n.strategy, manifest.i18n.fallbackType),
   fallback: manifest.i18n.fallback,
   domains: manifest.i18n.domains,
 };
}

const base = manifest.base;
const build = {
  server: new URL(manifest.buildServerDir),
  client: new URL(manifest.buildClientDir),
  format: manifest.buildFormat,
};

const cacheDir = new URL(manifest.cacheDir);
const outDir = new URL(manifest.outDir);
const publicDir = new URL(manifest.publicDir);
const srcDir = new URL(manifest.srcDir);
const root = new URL(manifest.rootDir);
const trailingSlash = manifest.trailingSlash;
const site = manifest.site;
const compressHTML = manifest.compressHTML;

export {
 base,
 build,
 cacheDir,
 outDir,
 publicDir,
 srcDir,
 root,
 trailingSlash,
 site,
 compressHTML,
 i18n,
}; 

				`;
					return { code };
				}
			},
		},
	};
}

Domain

Subdomains

Dependencies

  • ../core/constants.js
  • ../core/errors/index.js
  • ../manifest/serialized.js
  • vite

Frequently Asked Questions

What does virtual-module.ts do?
virtual-module.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 virtual-module.ts?
virtual-module.ts defines 1 function(s): virtualModulePlugin.
What does virtual-module.ts depend on?
virtual-module.ts imports 4 module(s): ../core/constants.js, ../core/errors/index.js, ../manifest/serialized.js, vite.
Where is virtual-module.ts in the architecture?
virtual-module.ts is located at packages/astro/src/manifest/virtual-module.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/manifest).

Analyze Your Own Codebase

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

Try Supermodel Free