Home / Function/ trackScriptHashes() — astro Function Reference

trackScriptHashes() — astro Function Reference

Architecture documentation for the trackScriptHashes() function in common.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  d8d2eca4_6df5_3e58_1209_4208967941a2["trackScriptHashes()"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23["common.ts"]
  d8d2eca4_6df5_3e58_1209_4208967941a2 -->|defined in| 0f62fcfb_9504_86a2_16bb_d8a9742e1f23
  style d8d2eca4_6df5_3e58_1209_4208967941a2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/csp/common.ts lines 127–165

export async function trackScriptHashes(
	internals: BuildInternals,
	settings: AstroSettings,
	algorithm: CspAlgorithm,
): Promise<string[]> {
	const clientScriptHashes: string[] = [];

	for (const script of internals.inlinedScripts.values()) {
		clientScriptHashes.push(await generateCspDigest(script, algorithm));
	}

	for (const directiveContent of Array.from(settings.clientDirectives.values())) {
		clientScriptHashes.push(await generateCspDigest(directiveContent, algorithm));
	}

	for (const clientAsset in internals.clientChunksAndAssets) {
		const contents = readFileSync(
			fileURLToPath(new URL(clientAsset, settings.config.build.client)),
			'utf-8',
		);
		if (clientAsset.endsWith('.js') || clientAsset.endsWith('.mjs')) {
			clientScriptHashes.push(await generateCspDigest(contents, algorithm));
		}
	}

	for (const script of settings.scripts) {
		const { content, stage } = script;
		if (stage === 'head-inline' || stage === 'before-hydration') {
			clientScriptHashes.push(await generateCspDigest(content, algorithm));
		}
	}

	if (settings.renderers.length > 0) {
		clientScriptHashes.push(await generateCspDigest(astroIslandPrebuilt, algorithm));
		clientScriptHashes.push(await generateCspDigest(astroIslandPrebuiltDev, algorithm));
	}

	return clientScriptHashes;
}

Domain

Subdomains

Frequently Asked Questions

What does trackScriptHashes() do?
trackScriptHashes() is a function in the astro codebase, defined in packages/astro/src/core/csp/common.ts.
Where is trackScriptHashes() defined?
trackScriptHashes() is defined in packages/astro/src/core/csp/common.ts at line 127.

Analyze Your Own Codebase

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

Try Supermodel Free