Home / Class/ YarnPackageManager Class — astro Architecture

YarnPackageManager Class — astro Architecture

Architecture documentation for the YarnPackageManager class in yarn-package-manager.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  bba1aa6e_8d9a_2505_0e7e_07f43b0ed013["YarnPackageManager"]
  b242c522_469d_5b64_237c_649b5a5a6ea0["yarn-package-manager.ts"]
  bba1aa6e_8d9a_2505_0e7e_07f43b0ed013 -->|defined in| b242c522_469d_5b64_237c_649b5a5a6ea0
  3c3d1824_079f_882c_e0dd_7c025a34ff48["constructor()"]
  bba1aa6e_8d9a_2505_0e7e_07f43b0ed013 -->|method| 3c3d1824_079f_882c_e0dd_7c025a34ff48
  69420a5b_fb71_a6c8_f500_8c63c716bb8e["getPackageVersion()"]
  bba1aa6e_8d9a_2505_0e7e_07f43b0ed013 -->|method| 69420a5b_fb71_a6c8_f500_8c63c716bb8e

Relationship Graph

Source Code

packages/astro/src/cli/info/infra/yarn-package-manager.ts lines 18–62

export class YarnPackageManager implements PackageManager {
	readonly name: string = 'yarn';
	readonly #commandExecutor: CommandExecutor;

	constructor({ commandExecutor }: { commandExecutor: CommandExecutor }) {
		this.#commandExecutor = commandExecutor;
	}

	async getPackageVersion(name: string): Promise<string | undefined> {
		try {
			// https://yarnpkg.com/cli/why
			const { stdout } = await this.#commandExecutor.execute('yarn', ['why', name, '--json'], {
				shell: true,
			});

			const hasUserDefinition = stdout.includes('workspace:.');

			/* output is NDJSON: one line contains a json object. For example:
				
				{"type":"step","data":{"message":"Why do we have the module \"hookable\"?","current":1,"total":4}}
				{"type":"step","data":{"message":"Initialising dependency graph","current":2,"total":4}}
				{"type":"activityStart","data":{"id":0}}
				{"type":"activityTick","data":{"id":0,"name":"hookable@^5.5.3"}}
				{"type":"activityEnd","data":{"id":0}}
				{"type":"step","data":{"message":"Finding dependency","current":3,"total":4}}
				{"type":"step","data":{"message":"Calculating file sizes","current":4,"total":4}}
				{"type":"info","data":"\r=> Found \"hookable@5.5.3\""}
				{"type":"info","data":"Has been hoisted to \"hookable\""}
				{"type":"info","data":"This module exists because it's specified in \"dependencies\"."}
				{"type":"info","data":"Disk size without dependencies: \"52KB\""}
				{"type":"info","data":"Disk size with unique dependencies: \"52KB\""}
				{"type":"info","data":"Disk size with transitive dependencies: \"52KB\""}
				{"type":"info","data":"Number of shared dependencies: 0"}
				 */
			for (const line of stdout.split('\n')) {
				if (hasUserDefinition && line.includes('workspace:.'))
					return getYarnOutputDepVersion(name, line);
				if (!hasUserDefinition && line.includes('astro@'))
					return getYarnOutputDepVersion(name, line);
			}
		} catch {
			return undefined;
		}
	}
}

Domain

Frequently Asked Questions

What is the YarnPackageManager class?
YarnPackageManager is a class in the astro codebase, defined in packages/astro/src/cli/info/infra/yarn-package-manager.ts.
Where is YarnPackageManager defined?
YarnPackageManager is defined in packages/astro/src/cli/info/infra/yarn-package-manager.ts at line 18.

Analyze Your Own Codebase

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

Try Supermodel Free