Home / File/ utils.ts — astro Source File

utils.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 2 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  95a68fc5_3ffe_042b_2c60_3f03f30904cf["utils.ts"]
  8d3d0086_915f_5a8c_ee4d_83532eb23d3f["./importPackage.js"]
  95a68fc5_3ffe_042b_2c60_3f03f30904cf --> 8d3d0086_915f_5a8c_ee4d_83532eb23d3f
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  95a68fc5_3ffe_042b_2c60_3f03f30904cf --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  style 95a68fc5_3ffe_042b_2c60_3f03f30904cf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as path from 'node:path';
import type { PackageInfo } from './importPackage.js';
import { getPackageInfo } from './importPackage.js';

export function getLanguageServerTypesDir(ts: typeof import('typescript')) {
	return ts.sys.resolvePath(path.resolve(__dirname, '../types'));
}

export function getAstroInstall(
	basePaths: string[],
	checkForAstro?: {
		nearestPackageJson: string | undefined;
		readDirectory: typeof import('typescript').sys.readDirectory;
	},
): PackageInfo | 'not-an-astro-project' | 'not-found' {
	if (checkForAstro && checkForAstro.nearestPackageJson) {
		basePaths.push(path.dirname(checkForAstro.nearestPackageJson));

		let deps = new Set<string>();
		try {
			const packageJSON = require(checkForAstro.nearestPackageJson);
			[
				...Object.keys(packageJSON.dependencies ?? {}),
				...Object.keys(packageJSON.devDependencies ?? {}),
				...Object.keys(packageJSON.peerDependencies ?? {}),
			].forEach((dep) => deps.add(dep));
		} catch {}

		if (!deps.has('astro')) {
			const directoryContent = checkForAstro.readDirectory(
				path.dirname(checkForAstro.nearestPackageJson),
				['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'],
				undefined,
				undefined,
				1,
			);

			if (!directoryContent.some((file) => path.basename(file).startsWith('astro.config'))) {
				return 'not-an-astro-project';
			}
		}
	}

	let astroPackage = getPackageInfo('astro', basePaths);

	if (!astroPackage) {
		// If we couldn't find it inside the workspace's node_modules, it might means we're in the Astro development monorepo
		astroPackage = getPackageInfo('./packages/astro', basePaths);

		if (!astroPackage) {
			console.error(
				`${basePaths[0]} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`,
			);

			// If we still couldn't find it, it probably just doesn't exist
			return 'not-found';
		}
	}

	return astroPackage;
}

Domain

Subdomains

Dependencies

  • ./importPackage.js
  • node:path

Frequently Asked Questions

What does utils.ts do?
utils.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 utils.ts?
utils.ts defines 2 function(s): getAstroInstall, getLanguageServerTypesDir.
What does utils.ts depend on?
utils.ts imports 2 module(s): ./importPackage.js, node:path.
Where is utils.ts in the architecture?
utils.ts is located at packages/language-tools/language-server/src/utils.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/language-tools/language-server/src).

Analyze Your Own Codebase

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

Try Supermodel Free