Home / File/ scripts.ts — astro Source File

scripts.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 4 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  7d939579_ff24_6e88_6d95_2d48a8dbe011["scripts.ts"]
  10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"]
  7d939579_ff24_6e88_6d95_2d48a8dbe011 --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05
  7d87d570_df6b_670e_7e71_a3b1206e5c9d["./astro-island.prebuilt.js"]
  7d939579_ff24_6e88_6d95_2d48a8dbe011 --> 7d87d570_df6b_670e_7e71_a3b1206e5c9d
  bbab4d82_07cf_6d5a_a7eb_99aaba8abe36["./astro-island.prebuilt-dev.js"]
  7d939579_ff24_6e88_6d95_2d48a8dbe011 --> bbab4d82_07cf_6d5a_a7eb_99aaba8abe36
  93d5356a_fdbc_31d6_20b6_5e34a5326784["./astro-island-styles.js"]
  7d939579_ff24_6e88_6d95_2d48a8dbe011 --> 93d5356a_fdbc_31d6_20b6_5e34a5326784
  style 7d939579_ff24_6e88_6d95_2d48a8dbe011 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { SSRResult } from '../../types/public/internal.js';
import islandScript from './astro-island.prebuilt.js';
import islandScriptDev from './astro-island.prebuilt-dev.js';
import { ISLAND_STYLES } from './astro-island-styles.js';

export function determineIfNeedsHydrationScript(result: SSRResult): boolean {
	if (result._metadata.hasHydrationScript) {
		return false;
	}
	return (result._metadata.hasHydrationScript = true);
}

export function determinesIfNeedsDirectiveScript(result: SSRResult, directive: string): boolean {
	if (result._metadata.hasDirectives.has(directive)) {
		return false;
	}
	result._metadata.hasDirectives.add(directive);
	return true;
}

export type PrescriptType = 'both' | 'directive';

function getDirectiveScriptText(result: SSRResult, directive: string): string {
	const clientDirectives = result.clientDirectives;
	const clientDirective = clientDirectives.get(directive);
	if (!clientDirective) {
		throw new Error(`Unknown directive: ${directive}`);
	}
	return clientDirective;
}

export function getPrescripts(result: SSRResult, type: PrescriptType, directive: string): string {
	// Note that this is a classic script, not a module script.
	// This is so that it executes immediately, and when the browser encounters
	// an astro-island element, the callbacks will fire immediately, causing the JS
	// deps to be loaded immediately.
	switch (type) {
		case 'both':
			return `<style>${ISLAND_STYLES}</style><script>${getDirectiveScriptText(result, directive)}</script><script>${
				process.env.NODE_ENV === 'development' ? islandScriptDev : islandScript
			}</script>`;
		case 'directive':
			return `<script>${getDirectiveScriptText(result, directive)}</script>`;
	}
}

Domain

Subdomains

Dependencies

  • ../types/public/internal.js
  • ./astro-island-styles.js
  • ./astro-island.prebuilt-dev.js
  • ./astro-island.prebuilt.js

Frequently Asked Questions

What does scripts.ts do?
scripts.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 scripts.ts?
scripts.ts defines 4 function(s): determineIfNeedsHydrationScript, determinesIfNeedsDirectiveScript, getDirectiveScriptText, getPrescripts.
What does scripts.ts depend on?
scripts.ts imports 4 module(s): ../types/public/internal.js, ./astro-island-styles.js, ./astro-island.prebuilt-dev.js, ./astro-island.prebuilt.js.
Where is scripts.ts in the architecture?
scripts.ts is located at packages/astro/src/runtime/server/scripts.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/runtime/server).

Analyze Your Own Codebase

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

Try Supermodel Free