vite.ts — astro Source File
Architecture documentation for vite.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 07d85cd0_2c3b_d625_d196_6081b8d3c820["vite.ts"] 7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"] 07d85cd0_2c3b_d625_d196_6081b8d3c820 --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b f68003f1_292f_ca44_03ce_21af87a33c7b["../core/util.js"] 07d85cd0_2c3b_d625_d196_6081b8d3c820 --> f68003f1_292f_ca44_03ce_21af87a33c7b 87530382_6d99_2339_182d_074e3de33bc8["../vite-plugin-utils/index.js"] 07d85cd0_2c3b_d625_d196_6081b8d3c820 --> 87530382_6d99_2339_182d_074e3de33bc8 eb7ca709_080c_a438_b9d7_f1238835779d["../content/consts.js"] 07d85cd0_2c3b_d625_d196_6081b8d3c820 --> eb7ca709_080c_a438_b9d7_f1238835779d c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] 07d85cd0_2c3b_d625_d196_6081b8d3c820 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"] 07d85cd0_2c3b_d625_d196_6081b8d3c820 --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7 style 07d85cd0_2c3b_d625_d196_6081b8d3c820 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import npath from 'node:path';
import { type EnvironmentModuleNode, isCSSRequest, type RunnableDevEnvironment } from 'vite';
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from '../core/constants.js';
import { unwrapId } from '../core/util.js';
import { hasSpecialQueries } from '../vite-plugin-utils/index.js';
import { PROPAGATED_ASSET_QUERY_PARAM } from '../content/consts.js';
/**
* List of file extensions signalling we can (and should) SSR ahead-of-time
* See usage below
*/
const fileExtensionsToSSR = new Set(['.astro', '.mdoc', ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
/** recursively crawl the module graph to get all style files imported by parent id */
export async function* crawlGraph(
environment: RunnableDevEnvironment,
_id: string,
isRootFile: boolean,
scanned = new Set<string>(),
): AsyncGenerator<EnvironmentModuleNode, void, unknown> {
const id = unwrapId(_id);
const importedModules = new Set<EnvironmentModuleNode>();
const moduleEntriesForId = isRootFile
? // "getModulesByFile" pulls from a delayed module cache (fun implementation detail),
// So we can get up-to-date info on initial server load.
// Needed for slower CSS preprocessing like Tailwind
(environment.moduleGraph.getModulesByFile(id) ?? new Set())
: // For non-root files, we're safe to pull from "getModuleById" based on testing.
// TODO: Find better invalidation strategy to use "getModuleById" in all cases!
new Set([environment.moduleGraph.getModuleById(id)]);
// Collect all imported modules for the module(s).
for (const entry of moduleEntriesForId) {
// Handle this in case an module entries weren't found for ID
// This seems possible with some virtual IDs (ex: `astro:markdown/*.md`)
if (!entry) {
continue;
}
if (id === entry.id) {
scanned.add(id);
// NOTE: It may be worth revisiting if we can crawl direct imports of the module since
// `.importedModules` would also include modules that are dynamically watched, not imported.
// That way we no longer need the below `continue` skips.
// CSS requests `importedModules` are usually from `@import`, but we don't really need
// to crawl into those as the `@import` code are already inlined into this `id`.
// If CSS requests `importedModules` contain non-CSS files, e.g. Tailwind might add HMR
// dependencies as `importedModules`, we should also skip them as they aren't really
// imported. Without this, every hoisted script in the project is added to every page!
if (isCSSRequest(id)) {
continue;
}
// Some special Vite queries like `?url` or `?raw` are known to be a simple default export
// and doesn't have any imports to crawl. However, since they would `this.addWatchFile` the
// underlying module, our logic would crawl into them anyways which is incorrect as they
// don't take part in the final rendering, so we skip it here.
// ... (68 more lines)
Domain
Subdomains
Functions
Dependencies
- ../content/consts.js
- ../core/constants.js
- ../core/util.js
- ../vite-plugin-utils/index.js
- node:path
- vite
Source
Frequently Asked Questions
What does vite.ts do?
vite.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 vite.ts?
vite.ts defines 2 function(s): crawlGraph, isImportedBy.
What does vite.ts depend on?
vite.ts imports 6 module(s): ../content/consts.js, ../core/constants.js, ../core/util.js, ../vite-plugin-utils/index.js, node:path, vite.
Where is vite.ts in the architecture?
vite.ts is located at packages/astro/src/vite-plugin-astro-server/vite.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-astro-server).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free