Home / File/ redirects.ts — astro Source File

redirects.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 4 imports 7 functions

Entity Profile

Dependency Diagram

graph LR
  2eae0c6b_820a_2609_b99a_dfcd5eb248a7["redirects.ts"]
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  2eae0c6b_820a_2609_b99a_dfcd5eb248a7 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  e4df8f29_fb2f_3d70_a962_fdf6a3670b22["path"]
  2eae0c6b_820a_2609_b99a_dfcd5eb248a7 --> e4df8f29_fb2f_3d70_a962_fdf6a3670b22
  50ce0ace_0bbf_f84c_68dd_331280396924["routing-utils"]
  2eae0c6b_820a_2609_b99a_dfcd5eb248a7 --> 50ce0ace_0bbf_f84c_68dd_331280396924
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  2eae0c6b_820a_2609_b99a_dfcd5eb248a7 --> f16d8c76_2866_6150_bd14_0347b59abfe9
  style 2eae0c6b_820a_2609_b99a_dfcd5eb248a7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import nodePath from 'node:path';
import { isRemotePath, removeLeadingForwardSlash } from '@astrojs/internal-helpers/path';
import type { Redirect } from '@vercel/routing-utils';
import type { AstroConfig, IntegrationResolvedRoute, RoutePart } from 'astro';

const pathJoin = nodePath.posix.join;

// Copied from astro/packages/astro/src/core/routing/manifest/create.ts
// Disable eslint as we're not sure how to improve this regex yet
// eslint-disable-next-line regexp/no-super-linear-backtracking
const ROUTE_DYNAMIC_SPLIT = /\[(.+?\(.+?\)|.+?)\]/;
const ROUTE_SPREAD = /^\.{3}.+$/;
function getParts(part: string, file: string) {
	const result: RoutePart[] = [];
	part.split(ROUTE_DYNAMIC_SPLIT).map((str, i) => {
		if (!str) return;
		const dynamic = i % 2 === 1;

		const [, content] = dynamic ? /([^(]+)$/.exec(str) || [null, null] : [null, str];

		if (!content || (dynamic && !/^(?:\.\.\.)?[\w$]+$/.test(content))) {
			throw new Error(`Invalid route ${file} — parameter name must match /^[a-zA-Z0-9_$]+$/`);
		}

		result.push({
			content,
			dynamic,
			spread: dynamic && ROUTE_SPREAD.test(content),
		});
	});

	return result;
}
/**
 * Convert Astro routes into Vercel path-to-regexp syntax, which are the input for getTransformedRoutes
 */
function getMatchPattern(segments: RoutePart[][]) {
	return segments
		.map((segment) => {
			return segment
				.map((part) => {
					if (part.spread) {
						// Extract parameter name from spread syntax (e.g., "...slug" -> "slug")
						const paramName = part.content.startsWith('...') ? part.content.slice(3) : part.content;
						return `:${paramName}*`;
					}
					if (part.dynamic) {
						return `:${part.content}`;
					}
					return part.content;
				})
				.join('');
		})
		.join('/');
}

// Copied from /home/juanm04/dev/misc/astro/packages/astro/src/core/routing/manifest/create.ts
// 2022-04-26
function getMatchRegex(segments: RoutePart[][]) {
	return segments
// ... (75 more lines)

Domain

Subdomains

Dependencies

  • astro
  • node:path
  • path
  • routing-utils

Frequently Asked Questions

What does redirects.ts do?
redirects.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in redirects.ts?
redirects.ts defines 7 function(s): escapeRegex, getMatchPattern, getMatchRegex, getParts, getRedirectLocation, getRedirectStatus, getRedirects.
What does redirects.ts depend on?
redirects.ts imports 4 module(s): astro, node:path, path, routing-utils.
Where is redirects.ts in the architecture?
redirects.ts is located at packages/integrations/vercel/src/lib/redirects.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/vercel/src/lib).

Analyze Your Own Codebase

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

Try Supermodel Free