Home / File/ vite-plugin-mdx-postprocess.ts — astro Source File

vite-plugin-mdx-postprocess.ts — astro Source File

Architecture documentation for vite-plugin-mdx-postprocess.ts, a typescript file in the astro codebase. 5 imports, 0 dependents.

File typescript CoreAstro RoutingSystem 5 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  1d16286a_a608_ecf0_1939_33200eaee4a0["vite-plugin-mdx-postprocess.ts"]
  0f250b55_e4b6_9260_5a32_5ff9fb454b7e["./rehype-images-to-component.js"]
  1d16286a_a608_ecf0_1939_33200eaee4a0 --> 0f250b55_e4b6_9260_5a32_5ff9fb454b7e
  ab5f9b39_abc6_0697_d4ba_c51748add5b2["./utils.js"]
  1d16286a_a608_ecf0_1939_33200eaee4a0 --> ab5f9b39_abc6_0697_d4ba_c51748add5b2
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  1d16286a_a608_ecf0_1939_33200eaee4a0 --> f16d8c76_2866_6150_bd14_0347b59abfe9
  58b96617_ab14_83d2_3aac_1c7f1ca9b66c["es-module-lexer"]
  1d16286a_a608_ecf0_1939_33200eaee4a0 --> 58b96617_ab14_83d2_3aac_1c7f1ca9b66c
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  1d16286a_a608_ecf0_1939_33200eaee4a0 --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  style 1d16286a_a608_ecf0_1939_33200eaee4a0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { AstroConfig } from 'astro';
import { type ExportSpecifier, type ImportSpecifier, parse } from 'es-module-lexer';
import type { Plugin } from 'vite';
import {
	ASTRO_IMAGE_ELEMENT,
	ASTRO_IMAGE_IMPORT,
	USES_ASTRO_IMAGE_FLAG,
} from './rehype-images-to-component.js';
import { type FileInfo, getFileInfo } from './utils.js';

const underscoreFragmentImportRegex = /[\s,{]_Fragment[\s,}]/;
const astroTagComponentImportRegex = /[\s,{]__astro_tag_component__[\s,}]/;

// These transforms must happen *after* JSX runtime transformations
export function vitePluginMdxPostprocess(astroConfig: AstroConfig): Plugin {
	return {
		name: '@astrojs/mdx-postprocess',
		transform: {
			filter: {
				id: /\.mdx$/,
			},
			handler(code, id) {
				const fileInfo = getFileInfo(id, astroConfig);
				const [imports, exports] = parse(code);

				// Call a series of functions that transform the code
				code = injectUnderscoreFragmentImport(code, imports);
				code = injectMetadataExports(code, exports, fileInfo);
				code = transformContentExport(code, exports);
				code = annotateContentExport(
					code,
					id,
					this.environment.name === 'ssr' || this.environment.name === 'prerender',
					imports,
				);

				// The code transformations above are append-only, so the line/column mappings are the same
				// and we can omit the sourcemap for performance.
				return { code, map: null };
			},
		},
	};
}

/**
 * Inject `Fragment` identifier import if not already present.
 */
function injectUnderscoreFragmentImport(code: string, imports: readonly ImportSpecifier[]) {
	if (!isSpecifierImported(code, imports, underscoreFragmentImportRegex, 'astro/jsx-runtime')) {
		code += `\nimport { Fragment as _Fragment } from 'astro/jsx-runtime';`;
	}
	return code;
}

/**
 * Inject MDX metadata as exports of the module.
 */
function injectMetadataExports(
	code: string,
	exports: readonly ExportSpecifier[],
// ... (97 more lines)

Domain

Subdomains

Dependencies

  • ./rehype-images-to-component.js
  • ./utils.js
  • astro
  • es-module-lexer
  • vite

Frequently Asked Questions

What does vite-plugin-mdx-postprocess.ts do?
vite-plugin-mdx-postprocess.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in vite-plugin-mdx-postprocess.ts?
vite-plugin-mdx-postprocess.ts defines 6 function(s): annotateContentExport, injectMetadataExports, injectUnderscoreFragmentImport, isSpecifierImported, transformContentExport, vitePluginMdxPostprocess.
What does vite-plugin-mdx-postprocess.ts depend on?
vite-plugin-mdx-postprocess.ts imports 5 module(s): ./rehype-images-to-component.js, ./utils.js, astro, es-module-lexer, vite.
Where is vite-plugin-mdx-postprocess.ts in the architecture?
vite-plugin-mdx-postprocess.ts is located at packages/integrations/mdx/src/vite-plugin-mdx-postprocess.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/mdx/src).

Analyze Your Own Codebase

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

Try Supermodel Free