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 1 functions

Entity Profile

Dependency Diagram

graph LR
  99f1c803_6a67_9071_3256_0a49371b7fad["index.ts"]
  e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"]
  99f1c803_6a67_9071_3256_0a49371b7fad --> e9b74c5a_8d34_34a7_e196_5e41b87214aa
  263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"]
  99f1c803_6a67_9071_3256_0a49371b7fad --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7
  5d6d1861_a18d_b246_cd94_08889ab7e74c["promises"]
  99f1c803_6a67_9071_3256_0a49371b7fad --> 5d6d1861_a18d_b246_cd94_08889ab7e74c
  e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"]
  99f1c803_6a67_9071_3256_0a49371b7fad --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  99f1c803_6a67_9071_3256_0a49371b7fad --> d9a92db9_c95e_9165_13ac_24b3d859d946
  style 99f1c803_6a67_9071_3256_0a49371b7fad fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Plugin } from 'vite';
import type { AstroSettings } from '../types/astro.js';
import { mkdir, writeFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { readFile } from 'node:fs/promises';

interface Payload {
	settings: AstroSettings;
}

export function vitePluginChromedevtools({ settings }: Payload): Plugin {
	return {
		name: 'astro:chromedevtools',
		configureServer(viteServer) {
			// Chrome DevTools workspace handler
			// See https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md
			viteServer.middlewares.use(async function chromeDevToolsHandler(request, response, next) {
				if (request.url !== '/.well-known/appspecific/com.chrome.devtools.json') {
					return next();
				}
				if (!settings.config.experimental.chromeDevtoolsWorkspace) {
					// Return early to stop console spam
					response.writeHead(404);
					response.end();
					return;
				}

				const pluginVersion = '1.1';
				const cacheDir = settings.config.cacheDir;
				const configPath = new URL('./chrome-workspace.json', cacheDir);

				if (!existsSync(cacheDir)) {
					await mkdir(cacheDir, { recursive: true });
				}

				let config;
				try {
					config = JSON.parse(await readFile(configPath, 'utf-8'));
					// If the cached workspace config was created with a previous version of this plugin,
					// we throw an error so it gets recreated in the `catch` block below.
					if (config.version !== pluginVersion) throw new Error('Cached config is outdated.');
				} catch {
					config = {
						workspace: {
							version: pluginVersion,
							uuid: crypto.randomUUID(),
							root: fileURLToPath(settings.config.root),
						},
					};
					await writeFile(configPath, JSON.stringify(config));
				}

				response.setHeader('Content-Type', 'application/json');
				response.end(JSON.stringify(config));
				return;
			});
		},
	};
}

Domain

Subdomains

Types

Dependencies

  • ../types/astro.js
  • node:fs
  • node:url
  • promises
  • vite

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 1 function(s): vitePluginChromedevtools.
What does index.ts depend on?
index.ts imports 5 module(s): ../types/astro.js, node:fs, node:url, promises, vite.
Where is index.ts in the architecture?
index.ts is located at packages/astro/src/vite-plugin-chromedevtools/index.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-chromedevtools).

Analyze Your Own Codebase

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

Try Supermodel Free