Home / File/ compile.ts — astro Source File

compile.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 9 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6["compile.ts"]
  c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> c32d12e2_d85e_28c0_eea7_9b29629857e0
  dd6187d6_53c4_ce90_a1d1_3a0b5e7e7d3f["../../core/errors/errors.js"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> dd6187d6_53c4_ce90_a1d1_3a0b5e7e7d3f
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  a370a45c_02f1_30de_445d_47ee08d095a2["../core/viteUtils.js"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> a370a45c_02f1_30de_445d_47ee08d095a2
  b0b304aa_5509_322d_a328_64496e15ed18["./style.js"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> b0b304aa_5509_322d_a328_64496e15ed18
  dec1e816_8ffc_7c1a_0ff1_5897dbd3dc9b["../core/compile/types.js"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> dec1e816_8ffc_7c1a_0ff1_5897dbd3dc9b
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> d9a92db9_c95e_9165_13ac_24b3d859d946
  40286c5f_532d_1bd5_70e5_3dbec8398413["compiler"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> 40286c5f_532d_1bd5_70e5_3dbec8398413
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  style d1d31d2a_5ee0_0540_2ca3_25d0e761efc6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { fileURLToPath } from 'node:url';
import type { TransformResult } from '@astrojs/compiler';
import { transform } from '@astrojs/compiler';
import type { ResolvedConfig } from 'vite';
import type { AstroConfig } from '../../types/public/config.js';
import type { AstroError } from '../errors/errors.js';
import { AggregateError, CompilerError } from '../errors/errors.js';
import { AstroErrorData } from '../errors/index.js';
import { normalizePath, resolvePath } from '../viteUtils.js';
import { createStylePreprocessor, type PartialCompileCssResult } from './style.js';
import type { CompileCssResult } from './types.js';

export interface CompileProps {
	astroConfig: AstroConfig;
	viteConfig: ResolvedConfig;
	toolbarEnabled: boolean;
	filename: string;
	source: string;
}

export interface CompileResult extends Omit<TransformResult, 'css'> {
	css: CompileCssResult[];
}

export async function compile({
	astroConfig,
	viteConfig,
	toolbarEnabled,
	filename,
	source,
}: CompileProps): Promise<CompileResult> {
	// Because `@astrojs/compiler` can't return the dependencies for each style transformed,
	// we need to use an external array to track the dependencies whenever preprocessing is called,
	// and we'll rebuild the final `css` result after transformation.
	const cssPartialCompileResults: PartialCompileCssResult[] = [];
	const cssTransformErrors: AstroError[] = [];
	let transformResult: TransformResult;

	try {
		// Transform from `.astro` to valid `.ts`
		// use `sourcemap: "both"` so that sourcemap is included in the code
		// result passed to esbuild, but also available in the catch handler.
		transformResult = await transform(source, {
			compact: astroConfig.compressHTML,
			filename,
			normalizedFilename: normalizeFilename(filename, astroConfig.root),
			sourcemap: 'both',
			internalURL: 'astro/compiler-runtime',
			// TODO: remove in Astro v7
			astroGlobalArgs: JSON.stringify(astroConfig.site),
			scopedStyleStrategy: astroConfig.scopedStyleStrategy,
			resultScopedSlot: true,
			transitionsAnimationURL: 'astro/components/viewtransitions.css',
			annotateSourceFile:
				viteConfig.command === 'serve' &&
				astroConfig.devToolbar &&
				astroConfig.devToolbar.enabled &&
				toolbarEnabled,
			preprocessStyle: createStylePreprocessor({
				filename,
// ... (76 more lines)

Domain

Subdomains

Dependencies

  • ../../core/errors/errors.js
  • ../core/compile/types.js
  • ../core/errors/index.js
  • ../core/viteUtils.js
  • ../types/public/config.js
  • ./style.js
  • compiler
  • node:url
  • vite

Frequently Asked Questions

What does compile.ts do?
compile.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 compile.ts?
compile.ts defines 3 function(s): compile, handleCompileResultErrors, normalizeFilename.
What does compile.ts depend on?
compile.ts imports 9 module(s): ../../core/errors/errors.js, ../core/compile/types.js, ../core/errors/index.js, ../core/viteUtils.js, ../types/public/config.js, ./style.js, compiler, node:url, and 1 more.
Where is compile.ts in the architecture?
compile.ts is located at packages/astro/src/core/compile/compile.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/compile).

Analyze Your Own Codebase

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

Try Supermodel Free