Home / File/ index.ts — astro Source File

index.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 5 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  298bcb8b_76f4_5bc3_f13f_87978f5034c8["index.ts"]
  7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"]
  298bcb8b_76f4_5bc3_f13f_87978f5034c8 --> 7e4494c0_5563_4329_1bff_a84be66e1bc2
  f68003f1_292f_ca44_03ce_21af87a33c7b["../core/util.js"]
  298bcb8b_76f4_5bc3_f13f_87978f5034c8 --> f68003f1_292f_ca44_03ce_21af87a33c7b
  c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"]
  298bcb8b_76f4_5bc3_f13f_87978f5034c8 --> c32d12e2_d85e_28c0_eea7_9b29629857e0
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  298bcb8b_76f4_5bc3_f13f_87978f5034c8 --> d9a92db9_c95e_9165_13ac_24b3d859d946
  d8ba5c67_9b8c_c68f_fa54_0075fd772841["common-ancestor-path"]
  298bcb8b_76f4_5bc3_f13f_87978f5034c8 --> d8ba5c67_9b8c_c68f_fa54_0075fd772841
  style 298bcb8b_76f4_5bc3_f13f_87978f5034c8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { fileURLToPath } from 'node:url';
import { commonAncestorPath } from 'common-ancestor-path';
import {
	appendExtension,
	appendForwardSlash,
	removeLeadingForwardSlashWindows,
} from '../core/path.js';
import { viteID } from '../core/util.js';
import type { AstroConfig } from '../types/public/config.js';

export function getFileInfo(id: string, config: AstroConfig) {
	const sitePathname = appendForwardSlash(
		config.site ? new URL(config.base, config.site).pathname : config.base,
	);

	const fileId = id.split('?')[0];
	let fileUrl = fileId.includes('/pages/')
		? fileId
				.replace(/^.*?\/pages\//, sitePathname)
				.replace(/(?:\/index)?\.(?:md|markdown|mdown|mkdn|mkd|mdwn|astro)$/, '')
		: undefined;
	if (fileUrl && config.trailingSlash === 'always') {
		fileUrl = appendForwardSlash(fileUrl);
	}
	if (fileUrl && config.build.format === 'file') {
		fileUrl = appendExtension(fileUrl, 'html');
	}
	return { fileId, fileUrl };
}

/**
 * Normalizes different file names like:
 *
 * - /@fs/home/user/project/src/pages/index.astro
 * - /src/pages/index.astro
 *
 * as absolute file paths with forward slashes.
 */
export function normalizeFilename(filename: string, root: URL) {
	if (filename.startsWith('/@fs')) {
		filename = filename.slice('/@fs'.length);
	} else if (filename.startsWith('/') && !commonAncestorPath(filename, fileURLToPath(root))) {
		const url = new URL('.' + filename, root);
		filename = viteID(url);
	}
	return removeLeadingForwardSlashWindows(filename);
}

const postfixRE = /[?#].*$/s;
export function cleanUrl(url: string): string {
	return url.replace(postfixRE, '');
}

export const specialQueriesRE = /(?:\?|&)(?:url|raw|direct)(?:&|$)/;
/**
 * Detect `?url`, `?raw`, and `?direct`, in which case we usually want to skip
 * transforming any code with this queries as Vite will handle it directly.
 */
export function hasSpecialQueries(id: string): boolean {
	return specialQueriesRE.test(id);
}

Domain

Subdomains

Dependencies

  • ../core/path.js
  • ../core/util.js
  • ../types/public/config.js
  • common-ancestor-path
  • node:url

Frequently Asked Questions

What does index.ts do?
index.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 index.ts?
index.ts defines 4 function(s): cleanUrl, getFileInfo, hasSpecialQueries, normalizeFilename.
What does index.ts depend on?
index.ts imports 5 module(s): ../core/path.js, ../core/util.js, ../types/public/config.js, common-ancestor-path, node:url.
Where is index.ts in the architecture?
index.ts is located at packages/astro/src/vite-plugin-utils/index.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-utils).

Analyze Your Own Codebase

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

Try Supermodel Free