addDirPluginSettings.ts
utils/plugins/addDirPluginSettings.ts
No strong subsystem tag
72
Lines
2320
Bytes
2
Exports
5
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 72 lines, 5 detected imports, and 2 detected exports.
Important relationships
Detected exports
getAddDirEnabledPluginsgetAddDirExtraMarketplaces
Keywords
settingsenabledpluginslocalresultjsonextraknownmarketplacesdirectoriesrecordfileadd-dir
Detected imports
pathzod/v4../../bootstrap/state.js../settings/settings.js../settings/types.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* Reads plugin-related settings (enabledPlugins, extraKnownMarketplaces)
* from --add-dir directories.
*
* These have the LOWEST priority — callers must spread standard settings
* on top so that user/project/local/flag/policy sources all override.
*/
import { join } from 'path'
import type { z } from 'zod/v4'
import { getAdditionalDirectoriesForClaudeMd } from '../../bootstrap/state.js'
import { parseSettingsFile } from '../settings/settings.js'
import type {
ExtraKnownMarketplaceSchema,
SettingsJson,
} from '../settings/types.js'
type ExtraKnownMarketplace = z.infer<
ReturnType<typeof ExtraKnownMarketplaceSchema>
>
const SETTINGS_FILES = ['settings.json', 'settings.local.json'] as const
/**
* Returns a merged record of enabledPlugins from all --add-dir directories.
*
* Within each directory, settings.local.json is processed after settings.json
* (local wins within that dir). Across directories, later CLI-order wins on
* conflict.
*
* This has the lowest priority — callers must spread their standard settings
* on top to let user/project/local/flag/policy override.
*/
export function getAddDirEnabledPlugins(): NonNullable<
SettingsJson['enabledPlugins']
> {
const result: NonNullable<SettingsJson['enabledPlugins']> = {}
for (const dir of getAdditionalDirectoriesForClaudeMd()) {
for (const file of SETTINGS_FILES) {
const { settings } = parseSettingsFile(join(dir, '.claude', file))
if (!settings?.enabledPlugins) {
continue
}
Object.assign(result, settings.enabledPlugins)
}
}
return result
}
/**
* Returns a merged record of extraKnownMarketplaces from all --add-dir directories.
*
* Same priority rules as getAddDirEnabledPlugins: settings.local.json wins
* within each dir, and callers spread standard settings on top.
*/
export function getAddDirExtraMarketplaces(): Record<
string,
ExtraKnownMarketplace
> {
const result: Record<string, ExtraKnownMarketplace> = {}
for (const dir of getAdditionalDirectoriesForClaudeMd()) {
for (const file of SETTINGS_FILES) {
const { settings } = parseSettingsFile(join(dir, '.claude', file))
if (!settings?.extraKnownMarketplaces) {
continue
}
Object.assign(result, settings.extraKnownMarketplaces)
}
}
return result
}