Home / File/ node.ts — astro Source File

node.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 11 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  cb45fbc5_a108_7969_b027_ddb8eab65943["node.ts"]
  dd2fe7bd_2244_3ff4_38ec_5e07763d1492["../core/encryption.js"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> dd2fe7bd_2244_3ff4_38ec_5e07763d1492
  7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> 7e4494c0_5563_4329_1bff_a84be66e1bc2
  df93c329_2f79_6708_fa84_5c5c757a6c19["../runtime/server/shorthash.js"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> df93c329_2f79_6708_fa84_5c5c757a6c19
  416eda3d_47e6_c298_102b_b7a37d86a44e["../../assets/types.js"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> 416eda3d_47e6_c298_102b_b7a37d86a44e
  885fe8eb_6b3c_f392_ce65_d81fa1101fb3["./imageKind.js"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> 885fe8eb_6b3c_f392_ce65_d81fa1101fb3
  d6a65eab_8a39_9f47_f7ff_a21a736505c6["./metadata.js"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> d6a65eab_8a39_9f47_f7ff_a21a736505c6
  5d6d1861_a18d_b246_cd94_08889ab7e74c["promises"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> 5d6d1861_a18d_b246_cd94_08889ab7e74c
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> d9a92db9_c95e_9165_13ac_24b3d859d946
  e43d916e_7da9_56ba_f995_57e51f0013d5["deterministic-object-hash"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> e43d916e_7da9_56ba_f995_57e51f0013d5
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  cb45fbc5_a108_7969_b027_ddb8eab65943 --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  style cb45fbc5_a108_7969_b027_ddb8eab65943 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs/promises';
import path, { basename, dirname, extname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { deterministicString } from 'deterministic-object-hash';
import type * as vite from 'vite';
import { generateContentHash } from '../../core/encryption.js';
import { prependForwardSlash, removeQueryString, slash } from '../../core/path.js';
import { shorthash } from '../../runtime/server/shorthash.js';
import type { ImageMetadata, ImageTransform } from '../types.js';
import { isESMImportedImage } from './imageKind.js';
import { imageMetadata } from './metadata.js';

type FileEmitter = vite.Rollup.EmitFile;
type ImageMetadataWithContents = ImageMetadata & { contents?: Buffer };

type SvgCacheKey = { hash: string };

// Global cache for SVG content deduplication
const svgContentCache = new WeakMap<SvgCacheKey, { handle: string; filename: string }>();

const keyRegistry = new Map<string, SvgCacheKey>();

function keyFor(hash: string): SvgCacheKey {
	let key = keyRegistry.get(hash);
	if (!key) {
		key = { hash };
		keyRegistry.set(hash, key);
	}
	return key;
}

/**
 * Handles SVG deduplication by checking if the content already exists in cache.
 */
async function handleSvgDeduplication(
	fileData: Buffer,
	filename: string,
	fileEmitter: FileEmitter,
): Promise<string> {
	const contentHash = await generateContentHash(fileData.buffer as ArrayBuffer);
	const key = keyFor(contentHash);
	const existing = svgContentCache.get(key);

	if (existing) {
		// Emit file again with the same filename to get a new handle
		// This ensures Rollup knows about this handle while maintaining deduplication on disk
		const handle = fileEmitter({
			name: existing.filename,
			source: fileData,
			type: 'asset',
		});
		return handle;
	} else {
		// First time seeing this SVG content - emit it
		const handle = fileEmitter({
			name: filename,
			source: fileData,
			type: 'asset',
		});
		svgContentCache.set(key, { handle, filename });
// ... (152 more lines)

Domain

Subdomains

Dependencies

  • ../../assets/types.js
  • ../core/encryption.js
  • ../core/path.js
  • ../runtime/server/shorthash.js
  • ./imageKind.js
  • ./metadata.js
  • deterministic-object-hash
  • node:path
  • node:url
  • promises
  • vite

Frequently Asked Questions

What does node.ts do?
node.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 node.ts?
node.ts defines 6 function(s): emitImageMetadata, fileURLToNormalizedPath, handleSvgDeduplication, hashTransform, keyFor, propsToFilename.
What does node.ts depend on?
node.ts imports 11 module(s): ../../assets/types.js, ../core/encryption.js, ../core/path.js, ../runtime/server/shorthash.js, ./imageKind.js, ./metadata.js, deterministic-object-hash, node:path, and 3 more.
Where is node.ts in the architecture?
node.ts is located at packages/astro/src/assets/utils/node.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