@@ -27,6 +27,16 @@ export const getSettingsPath = (): string => {
2727 return path . join ( getConfigDir ( ) , 'settings.json' )
2828}
2929
30+ /**
31+ * Ensure the config directory exists, creating it if necessary
32+ */
33+ const ensureConfigDirExists = ( ) : void => {
34+ const configDir = getConfigDir ( )
35+ if ( ! fs . existsSync ( configDir ) ) {
36+ fs . mkdirSync ( configDir , { recursive : true } )
37+ }
38+ }
39+
3040/**
3141 * Load all settings from file system
3242 * @returns The saved settings object, with defaults for missing values
@@ -35,6 +45,7 @@ export const loadSettings = (): Settings => {
3545 const settingsPath = getSettingsPath ( )
3646
3747 if ( ! fs . existsSync ( settingsPath ) ) {
48+ ensureConfigDirExists ( )
3849 // Create default settings file
3950 fs . writeFileSync ( settingsPath , JSON . stringify ( DEFAULT_SETTINGS , null , 2 ) )
4051 return DEFAULT_SETTINGS
@@ -86,13 +97,10 @@ const validateSettings = (parsed: unknown): Settings => {
8697 * Save settings to file system (merges with existing settings)
8798 */
8899export const saveSettings = ( newSettings : Partial < Settings > ) : void => {
89- const configDir = getConfigDir ( )
90100 const settingsPath = getSettingsPath ( )
91101
92102 try {
93- if ( ! fs . existsSync ( configDir ) ) {
94- fs . mkdirSync ( configDir , { recursive : true } )
95- }
103+ ensureConfigDirExists ( )
96104
97105 // Load existing settings and merge
98106 const existingSettings = loadSettings ( )
0 commit comments