Home / File/ assets.ts — astro Source File

assets.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 1 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  c4d8aadb_8112_3532_7394_a147bf9a438f["assets.ts"]
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  c4d8aadb_8112_3532_7394_a147bf9a438f --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  style c4d8aadb_8112_3532_7394_a147bf9a438f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Environment, Rollup } from 'vite';

type PluginContext = Rollup.PluginContext;
type EmitFileOptions = Parameters<Rollup.PluginContext['emitFile']>[0];

// WeakMap keyed by Environment objects to track emitted asset handles
// Using WeakMap ensures automatic cleanup when environments are garbage collected
const assetHandlesByEnvironment = new WeakMap<Environment, Set<string>>();

/**
 * Gets or creates the handle set for an environment
 */
export function getHandles(env: Environment): Set<string> {
	let handles = assetHandlesByEnvironment.get(env);
	if (!handles) {
		handles = new Set();
		assetHandlesByEnvironment.set(env, handles);
	}
	return handles;
}

/**
 * Resets the handle tracking for an environment.
 * Called at the start of each build.
 */
export function resetHandles(env: Environment): void {
	assetHandlesByEnvironment.set(env, new Set());
}

/**
 * Emit a client asset and track it for later movement to the client directory.
 * Use this instead of pluginContext.emitFile for assets that should
 * be moved from the server/prerender directory to the client directory.
 *
 * Note: The pluginContext is typed as Rollup.PluginContext for compatibility
 * with content entry types, but in practice it will always have the `environment`
 * property when running in Vite.
 */
export function emitClientAsset(pluginContext: PluginContext, options: EmitFileOptions): string {
	const env = (pluginContext as PluginContext & { environment: Environment }).environment;
	const handle = pluginContext.emitFile(options);

	const handles = getHandles(env);
	handles.add(handle);

	return handle;
}

Domain

Subdomains

Dependencies

  • vite

Frequently Asked Questions

What does assets.ts do?
assets.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 assets.ts?
assets.ts defines 3 function(s): emitClientAsset, getHandles, resetHandles.
What does assets.ts depend on?
assets.ts imports 1 module(s): vite.
Where is assets.ts in the architecture?
assets.ts is located at packages/astro/src/assets/utils/assets.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets/utils).

Analyze Your Own Codebase

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

Try Supermodel Free