Home / Function/ getPackageVersion() — astro Function Reference

getPackageVersion() — astro Function Reference

Architecture documentation for the getPackageVersion() function in yarn-package-manager.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  69420a5b_fb71_a6c8_f500_8c63c716bb8e["getPackageVersion()"]
  bba1aa6e_8d9a_2505_0e7e_07f43b0ed013["YarnPackageManager"]
  69420a5b_fb71_a6c8_f500_8c63c716bb8e -->|defined in| bba1aa6e_8d9a_2505_0e7e_07f43b0ed013
  39fde743_a54e_e62a_2d68_f3f078eb93ae["getYarnOutputDepVersion()"]
  69420a5b_fb71_a6c8_f500_8c63c716bb8e -->|calls| 39fde743_a54e_e62a_2d68_f3f078eb93ae
  style 69420a5b_fb71_a6c8_f500_8c63c716bb8e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/cli/info/infra/yarn-package-manager.ts lines 26–61

	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

Subdomains

Frequently Asked Questions

What does getPackageVersion() do?
getPackageVersion() is a function in the astro codebase, defined in packages/astro/src/cli/info/infra/yarn-package-manager.ts.
Where is getPackageVersion() defined?
getPackageVersion() is defined in packages/astro/src/cli/info/infra/yarn-package-manager.ts at line 26.
What does getPackageVersion() call?
getPackageVersion() calls 1 function(s): getYarnOutputDepVersion.

Analyze Your Own Codebase

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

Try Supermodel Free