Home / File/ context.ts — astro Source File

context.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 4 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  4b7851d8_a04b_b68f_e63e_37c4acd250af["context.ts"]
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  4b7851d8_a04b_b68f_e63e_37c4acd250af --> d9a92db9_c95e_9165_13ac_24b3d859d946
  44da03af_fba3_824c_9c9c_2685d1d33d31["cli-kit"]
  4b7851d8_a04b_b68f_e63e_37c4acd250af --> 44da03af_fba3_824c_9c9c_2685d1d33d31
  1ebc273e_6893_8f45_2d8f_9ad5840c6521["arg"]
  4b7851d8_a04b_b68f_e63e_37c4acd250af --> 1ebc273e_6893_8f45_2d8f_9ad5840c6521
  61b635e2_549a_1d06_be03_2c8dced634c4["package-manager-detector"]
  4b7851d8_a04b_b68f_e63e_37c4acd250af --> 61b635e2_549a_1d06_be03_2c8dced634c4
  style 4b7851d8_a04b_b68f_e63e_37c4acd250af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { pathToFileURL } from 'node:url';
import { prompt } from '@astrojs/cli-kit';
import arg from 'arg';
import { type DetectResult, detect } from 'package-manager-detector';

export interface Context {
	help: boolean;
	prompt: typeof prompt;
	version: string;
	dryRun?: boolean;
	cwd: URL;
	stdin?: typeof process.stdin;
	stdout?: typeof process.stdout;
	packageManager: DetectResult;
	packages: PackageInfo[];
	exit(code: number): never;
}

export interface PackageInfo {
	name: string;
	currentVersion: string;
	targetVersion: string;
	tag?: string;
	isDevDependency?: boolean;
	isMajor?: boolean;
	changelogURL?: string;
	changelogTitle?: string;
}

export async function getContext(argv: string[]): Promise<Context> {
	const flags = arg(
		{
			'--dry-run': Boolean,
			'--help': Boolean,

			'-h': '--help',
		},
		{ argv, permissive: true },
	);

	const packageManager = (await detect({
		// Include the `install-metadata` strategy to have the package manager that's
		// used for installation take precedence
		strategies: ['install-metadata', 'lockfile', 'packageManager-field'],
	})) ?? { agent: 'npm', name: 'npm' };
	const { _: [version = 'latest'] = [], '--help': help = false, '--dry-run': dryRun } = flags;

	return {
		help,
		prompt,
		packageManager,
		packages: [],
		cwd: new URL(pathToFileURL(process.cwd()) + '/'),
		dryRun,
		version,
		exit(code) {
			process.exit(code);
		},
	} satisfies Context;
}

Domain

Subdomains

Functions

Dependencies

  • arg
  • cli-kit
  • node:url
  • package-manager-detector

Frequently Asked Questions

What does context.ts do?
context.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 context.ts?
context.ts defines 1 function(s): getContext.
What does context.ts depend on?
context.ts imports 4 module(s): arg, cli-kit, node:url, package-manager-detector.
Where is context.ts in the architecture?
context.ts is located at packages/upgrade/src/actions/context.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/upgrade/src/actions).

Analyze Your Own Codebase

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

Try Supermodel Free