index.ts — astro Source File
Architecture documentation for index.ts, a typescript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c["index.ts"] e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"] 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c --> e9b74c5a_8d34_34a7_e196_5e41b87214aa e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 41525615_7e06_b0e8_f601_674c57b118ee["typescript"] 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c --> 41525615_7e06_b0e8_f601_674c57b118ee 263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"] 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7 style 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
import path from 'node:path';
import type { CompilerOptions } from 'typescript';
import { normalizePath, type Plugin as VitePlugin } from 'vite';
import type { AstroSettings } from '../types/astro.js';
type Alias = {
find: RegExp;
replacement: string;
};
/** Returns a list of compiled aliases. */
const getConfigAlias = (settings: AstroSettings): Alias[] | null => {
const { tsConfig, tsConfigPath } = settings;
if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions) return null;
const { baseUrl, paths } = tsConfig.compilerOptions as CompilerOptions;
// If paths exist but baseUrl doesn't, default to "." (tsconfig directory)
const effectiveBaseUrl = baseUrl ?? (paths ? '.' : undefined);
if (!effectiveBaseUrl) return null;
// resolve the base url from the configuration file directory
const resolvedBaseUrl = path.resolve(path.dirname(tsConfigPath), effectiveBaseUrl);
const aliases: Alias[] = [];
// compile any alias expressions and push them to the list
if (paths) {
for (const [alias, values] of Object.entries(paths)) {
/** Regular Expression used to match a given path. */
const find = new RegExp(
`^${[...alias]
.map((segment) =>
segment === '*' ? '(.+)' : segment.replace(/[\\^$*+?.()|[\]{}]/, '\\$&'),
)
.join('')}$`,
);
for (const value of values) {
/** Internal index used to calculate the matching id in a replacement. */
let matchId = 0;
/** String used to replace a matched path. */
const replacement = [...normalizePath(path.resolve(resolvedBaseUrl, value))]
.map((segment) => (segment === '*' ? `$${++matchId}` : segment === '$' ? '$$' : segment))
.join('');
aliases.push({ find, replacement });
}
}
}
// compile the baseUrl expression and push it to the list
// - `baseUrl` changes the way non-relative specifiers are resolved
// - if `baseUrl` exists then all non-relative specifiers are resolved relative to it
// - only add this if an explicit baseUrl was provided (not the default)
if (baseUrl) {
aliases.push({
find: /^(?!\.*\/|\.*$|\w:)(.+)$/,
// ... (111 more lines)
Domain
Subdomains
Types
Dependencies
- ../types/astro.js
- node:fs
- node:path
- typescript
- vite
Source
Frequently Asked Questions
What does index.ts do?
index.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 index.ts?
index.ts defines 3 function(s): configAliasVitePlugin, getConfigAlias, getViteResolveAlias.
What does index.ts depend on?
index.ts imports 5 module(s): ../types/astro.js, node:fs, node:path, typescript, vite.
Where is index.ts in the architecture?
index.ts is located at packages/astro/src/vite-plugin-config-alias/index.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-config-alias).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free