Home / Function/ build_route_tree() — svelte Function Reference

build_route_tree() — svelte Function Reference

Architecture documentation for the build_route_tree() function in download.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  169d027f_570a_0058_99af_8bec7c7047b4["build_route_tree()"]
  65d20932_41e6_eeee_7338_5dd0682e5e42["download.js"]
  169d027f_570a_0058_99af_8bec7c7047b4 -->|defined in| 65d20932_41e6_eeee_7338_5dd0682e5e42
  04de3495_cffc_dc6d_e930_d1c6d03a3a34["convert_sveltekit_project()"]
  04de3495_cffc_dc6d_e930_d1c6d03a3a34 -->|calls| 169d027f_570a_0058_99af_8bec7c7047b4
  style 169d027f_570a_0058_99af_8bec7c7047b4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

playgrounds/sandbox/scripts/download.js lines 299–323

function build_route_tree(files, routes_prefix) {
	/** @type {Map<string, {layout?: {path: string, contents: string}, page?: {path: string, contents: string}}>} */
	const routes = new Map();

	for (const file of files) {
		if (!file.path.startsWith(routes_prefix)) continue;

		const relative_to_routes = file.path.slice(routes_prefix.length + 1); // +1 for the slash
		const dir = path.dirname(relative_to_routes);
		const route_key = dir === '.' ? '' : dir;

		if (!routes.has(route_key)) {
			routes.set(route_key, {});
		}

		const route = routes.get(route_key);
		if (file.name === '+layout.svelte') {
			route.layout = { path: file.path, contents: file.contents };
		} else if (file.name === '+page.svelte') {
			route.page = { path: file.path, contents: file.contents };
		}
	}

	return routes;
}

Domain

Subdomains

Frequently Asked Questions

What does build_route_tree() do?
build_route_tree() is a function in the svelte codebase, defined in playgrounds/sandbox/scripts/download.js.
Where is build_route_tree() defined?
build_route_tree() is defined in playgrounds/sandbox/scripts/download.js at line 299.
What calls build_route_tree()?
build_route_tree() is called by 1 function(s): convert_sveltekit_project.

Analyze Your Own Codebase

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

Try Supermodel Free