Home / File/ common.ts — astro Source File

common.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 10 imports 10 functions

Entity Profile

Dependency Diagram

graph LR
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23["common.ts"]
  7d87d570_df6b_670e_7e71_a3b1206e5c9d["./astro-island.prebuilt.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> 7d87d570_df6b_670e_7e71_a3b1206e5c9d
  bbab4d82_07cf_6d5a_a7eb_99aaba8abe36["./astro-island.prebuilt-dev.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> bbab4d82_07cf_6d5a_a7eb_99aaba8abe36
  93d5356a_fdbc_31d6_20b6_5e34a5326784["./astro-island-styles.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> 93d5356a_fdbc_31d6_20b6_5e34a5326784
  e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> e9b74c5a_8d34_34a7_e196_5e41b87214aa
  baa53824_73a3_1e03_2043_4d0c058ecca5["../types/public/index.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> baa53824_73a3_1e03_2043_4d0c058ecca5
  1ddffc51_ee9d_5b0c_968e_331983e95ff4["../core/build/internal.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> 1ddffc51_ee9d_5b0c_968e_331983e95ff4
  dd2fe7bd_2244_3ff4_38ec_5e07763d1492["../core/encryption.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> dd2fe7bd_2244_3ff4_38ec_5e07763d1492
  d34ed003_355b_637d_1578_cba29babbd4c["../../core/csp/config.js"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> d34ed003_355b_637d_1578_cba29babbd4c
  e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23 --> d9a92db9_c95e_9165_13ac_24b3d859d946
  style 0f62fcfb_9504_86a2_16bb_d8a9742e1f23 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import astroIslandPrebuilt from '../../runtime/server/astro-island.prebuilt.js';
import astroIslandPrebuiltDev from '../../runtime/server/astro-island.prebuilt-dev.js';
import { ISLAND_STYLES } from '../../runtime/server/astro-island-styles.js';
import type { AstroSettings } from '../../types/astro.js';
import type { AstroConfig, CspAlgorithm } from '../../types/public/index.js';
import type { BuildInternals } from '../build/internal.js';
import { generateCspDigest } from '../encryption.js';
import type { CspDirective } from './config.js';

type EnabledCsp = Exclude<AstroConfig['security']['csp'], false>;

export function shouldTrackCspHashes(csp: any): csp is EnabledCsp {
	return csp === true || typeof csp === 'object';
}

export function getAlgorithm(csp: EnabledCsp): CspAlgorithm {
	if (csp === true) {
		return 'SHA-256';
	}
	return csp.algorithm;
}

export function getScriptHashes(csp: EnabledCsp): string[] {
	if (csp === true) {
		return [];
	} else {
		return csp.scriptDirective?.hashes ?? [];
	}
}

export function getScriptResources(csp: EnabledCsp): string[] {
	if (csp === true) {
		return [];
	}
	return csp.scriptDirective?.resources ?? [];
}

export function getStyleHashes(csp: EnabledCsp): string[] {
	if (csp === true) {
		return [];
	}
	return csp.styleDirective?.hashes ?? [];
}

export function getStyleResources(csp: EnabledCsp): string[] {
	if (csp === true) {
		return [];
	}
	return csp.styleDirective?.resources ?? [];
}

// Unlike other helpers like getStyleResources, getDirectives has more logic
// because it has to collect and deduplicate font resources from both the user
// config and the vite plugin for fonts
export function getDirectives(settings: AstroSettings): CspDirective[] {
	const { csp } = settings.config.security;
	if (!shouldTrackCspHashes(csp)) {
		return [];
// ... (106 more lines)

Domain

Subdomains

Types

Dependencies

  • ../../core/csp/config.js
  • ../core/build/internal.js
  • ../core/encryption.js
  • ../types/astro.js
  • ../types/public/index.js
  • ./astro-island-styles.js
  • ./astro-island.prebuilt-dev.js
  • ./astro-island.prebuilt.js
  • node:fs
  • node:url

Frequently Asked Questions

What does common.ts do?
common.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 common.ts?
common.ts defines 10 function(s): getAlgorithm, getDirectives, getScriptHashes, getScriptResources, getStrictDynamic, getStyleHashes, getStyleResources, shouldTrackCspHashes, trackScriptHashes, trackStyleHashes.
What does common.ts depend on?
common.ts imports 10 module(s): ../../core/csp/config.js, ../core/build/internal.js, ../core/encryption.js, ../types/astro.js, ../types/public/index.js, ./astro-island-styles.js, ./astro-island.prebuilt-dev.js, ./astro-island.prebuilt.js, and 2 more.
Where is common.ts in the architecture?
common.ts is located at packages/astro/src/core/csp/common.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/csp).

Analyze Your Own Codebase

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

Try Supermodel Free