Home / File/ importPackage.ts — astro Source File

importPackage.ts — astro Source File

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

File typescript CoreAstro CoreMiddleware 4 imports 1 dependents 9 functions

Entity Profile

Dependency Diagram

graph LR
  e0c225c9_e989_934d_19e8_8e80b7a6857f["importPackage.ts"]
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  e0c225c9_e989_934d_19e8_8e80b7a6857f --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  1f840c01_eaf1_989b_5dd4_bfb73a87271a["editor.cjs"]
  e0c225c9_e989_934d_19e8_8e80b7a6857f --> 1f840c01_eaf1_989b_5dd4_bfb73a87271a
  c4248635_3e94_5021_2940_72536fcb50c2["editor.cjs"]
  e0c225c9_e989_934d_19e8_8e80b7a6857f --> c4248635_3e94_5021_2940_72536fcb50c2
  7b9a50bd_51a2_9134_7c44_86e832798cbb["prettier"]
  e0c225c9_e989_934d_19e8_8e80b7a6857f --> 7b9a50bd_51a2_9134_7c44_86e832798cbb
  6db4d7db_edbb_c18d_7ff5_decb13f1c284["utils.ts"]
  6db4d7db_edbb_c18d_7ff5_decb13f1c284 --> e0c225c9_e989_934d_19e8_8e80b7a6857f
  style e0c225c9_e989_934d_19e8_8e80b7a6857f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { dirname, resolve } from 'node:path';

// Those three imports needs to always be `type` imports, as we always want to import them dynamically

// TODO: Consider maybe somehow moving those integrations to a separate package to avoid circular dependencies?
// @ts-ignore - Due to a circular dependency, we can't have those as dependencies
import type * as svelte from '@astrojs/svelte/dist/editor.cjs';
// @ts-ignore - Due to a circular dependency, we can't have those as dependencies
import type * as vue from '@astrojs/vue/dist/editor.cjs';

import type * as prettier from 'prettier';

type PackageVersion = {
	full: string;
	major: number;
	minor: number;
	patch: number;
};

let isTrusted = true;

export function setIsTrusted(_isTrusted: boolean) {
	isTrusted = _isTrusted;
}

export type PackageInfo = {
	entrypoint: string;
	directory: string;
	version: PackageVersion;
};

/**
 * Get the path of a package's directory from the paths in `fromPath`, if `root` is set to false, it will return the path of the package's entry point
 */
export function getPackageInfo(packageName: string, fromPath: string[]): PackageInfo | undefined {
	const paths = [];
	if (isTrusted) {
		paths.unshift(...fromPath);
	}

	try {
		const packageJSON = require.resolve(packageName + '/package.json', { paths });
		return {
			directory: dirname(packageJSON),
			entrypoint: require.resolve(packageName, { paths }),
			version: parsePackageVersion(require(packageJSON).version),
		};
	} catch {
		return undefined;
	}
}

function importEditorIntegration<T>(packageName: string, fromPath: string): T | undefined {
	const pkgPath = getPackageInfo(packageName, [fromPath])?.directory;

	if (pkgPath) {
		try {
			const main = resolve(pkgPath, 'dist', 'editor.cjs');

			return require(main) as T;
// ... (84 more lines)

Domain

Subdomains

Dependencies

  • editor.cjs
  • editor.cjs
  • node:path
  • prettier

Frequently Asked Questions

What does importPackage.ts do?
importPackage.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in importPackage.ts?
importPackage.ts defines 9 function(s): getPackageInfo, getPrettierPluginPath, getWorkspacePnpPath, importEditorIntegration, importPrettier, importSvelteIntegration, importVueIntegration, parsePackageVersion, setIsTrusted.
What does importPackage.ts depend on?
importPackage.ts imports 4 module(s): editor.cjs, editor.cjs, node:path, prettier.
What files import importPackage.ts?
importPackage.ts is imported by 1 file(s): utils.ts.
Where is importPackage.ts in the architecture?
importPackage.ts is located at packages/language-tools/language-server/src/importPackage.ts (domain: CoreAstro, subdomain: CoreMiddleware, 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