Home / Function/ setPreference() — astro Function Reference

setPreference() — astro Function Reference

Architecture documentation for the setPreference() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  899839a7_6c03_6f51_9c02_7077e2a5b9b0["setPreference()"]
  f7d3fd10_bcd7_7c85_17b8_a4feb9026da8["index.ts"]
  899839a7_6c03_6f51_9c02_7077e2a5b9b0 -->|defined in| f7d3fd10_bcd7_7c85_17b8_a4feb9026da8
  4ec23106_e310_07dc_a9e9_e382aeb6a997["preferences()"]
  4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| 899839a7_6c03_6f51_9c02_7077e2a5b9b0
  style 899839a7_6c03_6f51_9c02_7077e2a5b9b0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/cli/preferences/index.ts lines 154–176

async function setPreference(
	settings: AstroSettings,
	key: PreferenceKey,
	value: unknown,
	{ location }: SubcommandOptions,
) {
	try {
		const defaultType = typeof dlv(DEFAULT_PREFERENCES, key);
		if (typeof coerce(key, value) !== defaultType) {
			throw new Error(`${key} expects a "${defaultType}" value!`);
		}

		await settings.preferences.set(key, coerce(key, value), { location });
		console.log(msg.preferenceSet(key, value));
		return 0;
	} catch (e) {
		if (e instanceof Error) {
			console.error(msg.formatErrorMessage(collectErrorMetadata(e), true));
			return 1;
		}
		throw e;
	}
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does setPreference() do?
setPreference() is a function in the astro codebase, defined in packages/astro/src/cli/preferences/index.ts.
Where is setPreference() defined?
setPreference() is defined in packages/astro/src/cli/preferences/index.ts at line 154.
What calls setPreference()?
setPreference() is called by 1 function(s): preferences.

Analyze Your Own Codebase

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

Try Supermodel Free