preferences() — astro Function Reference
Architecture documentation for the preferences() function in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 4ec23106_e310_07dc_a9e9_e382aeb6a997["preferences()"] f7d3fd10_bcd7_7c85_17b8_a4feb9026da8["index.ts"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|defined in| f7d3fd10_bcd7_7c85_17b8_a4feb9026da8 b27aef3e_dc25_7ebb_6720_cb782a29f4f8["isValidSubcommand()"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| b27aef3e_dc25_7ebb_6720_cb782a29f4f8 f72816d7_841e_fbeb_de77_6ad73e837140["listPreferences()"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| f72816d7_841e_fbeb_de77_6ad73e837140 dbd24844_d9f2_0606_a8f9_7b3c7cdd9389["getPreference()"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| dbd24844_d9f2_0606_a8f9_7b3c7cdd9389 899839a7_6c03_6f51_9c02_7077e2a5b9b0["setPreference()"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| 899839a7_6c03_6f51_9c02_7077e2a5b9b0 443dfc64_c40a_725d_ee3b_fc5593232b27["resetPreference()"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| 443dfc64_c40a_725d_ee3b_fc5593232b27 87981f14_0f96_683b_056a_ee60abb74e6d["enablePreference()"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| 87981f14_0f96_683b_056a_ee60abb74e6d 1c0e6fc6_e0cd_fa8d_95a1_e4aa6f08e356["disablePreference()"] 4ec23106_e310_07dc_a9e9_e382aeb6a997 -->|calls| 1c0e6fc6_e0cd_fa8d_95a1_e4aa6f08e356 style 4ec23106_e310_07dc_a9e9_e382aeb6a997 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/cli/preferences/index.ts lines 39–120
export async function preferences(
subcommand: string,
key: string,
value: string | undefined,
{ flags }: PreferencesOptions,
): Promise<number> {
if (!isValidSubcommand(subcommand) || flags?.help || flags?.h) {
msg.printHelp({
commandName: 'astro preferences',
usage: '[command]',
tables: {
Commands: [
['list', 'Pretty print all current preferences'],
['list --json', 'Log all current preferences as a JSON object'],
['get [key]', 'Log current preference value'],
['set [key] [value]', 'Update preference value'],
['reset [key]', 'Reset preference value to default'],
['enable [key]', 'Set a boolean preference to true'],
['disable [key]', 'Set a boolean preference to false'],
],
Flags: [
[
'--global',
'Scope command to global preferences (all Astro projects) rather than the current project',
],
],
},
});
return 0;
}
const inlineConfig = flagsToAstroInlineConfig(flags);
const logger = createLoggerFromFlags(flags);
const { astroConfig } = await resolveConfig(inlineConfig ?? {}, 'dev');
const settings = await createSettings(
astroConfig,
inlineConfig.logLevel,
fileURLToPath(astroConfig.root),
);
const opts: SubcommandOptions = {
location: flags.global ? 'global' : undefined,
json: !!flags.json,
};
if (subcommand === 'list') {
return listPreferences(settings, opts);
}
if (subcommand === 'enable' || subcommand === 'disable') {
key = `${key}.enabled` as PreferenceKey;
}
if (!isValidKey(key)) {
logger.error('preferences', `Unknown preference "${key}"\n`);
return 1;
}
if (subcommand === 'set' && value === undefined) {
const type = typeof dlv(DEFAULT_PREFERENCES, key);
console.error(
msg.formatErrorMessage(
collectErrorMetadata(new Error(`Please provide a ${type} value for "${key}"`)),
true,
),
);
return 1;
}
switch (subcommand) {
case 'get':
return getPreference(settings, key, opts);
case 'set':
return setPreference(settings, key, value, opts);
case 'reset':
case 'delete':
return resetPreference(settings, key, opts);
case 'enable':
return enablePreference(settings, key, opts);
case 'disable':
return disablePreference(settings, key, opts);
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does preferences() do?
preferences() is a function in the astro codebase, defined in packages/astro/src/cli/preferences/index.ts.
Where is preferences() defined?
preferences() is defined in packages/astro/src/cli/preferences/index.ts at line 39.
What does preferences() call?
preferences() calls 7 function(s): disablePreference, enablePreference, getPreference, isValidSubcommand, listPreferences, resetPreference, setPreference.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free