* Load plugin settings from settings.json file or manifest.settings. * settings.json takes priority over manifest.settings when both exist. * Only allowlisted keys are included in the result.
( pluginPath: string, manifest: PluginManifest, )
| 1806 | * Only allowlisted keys are included in the result. |
| 1807 | */ |
| 1808 | async function loadPluginSettings( |
| 1809 | pluginPath: string, |
| 1810 | manifest: PluginManifest, |
| 1811 | ): Promise<Record<string, unknown> | undefined> { |
| 1812 | // Try loading settings.json from the plugin directory |
| 1813 | const settingsJsonPath = join(pluginPath, 'settings.json') |
| 1814 | try { |
| 1815 | const content = await readFile(settingsJsonPath, { encoding: 'utf-8' }) |
| 1816 | const parsed = jsonParse(content) |
| 1817 | if (isRecord(parsed)) { |
| 1818 | const filtered = parsePluginSettings(parsed) |
| 1819 | if (filtered) { |
| 1820 | logForDebugging( |
| 1821 | `Loaded settings from settings.json for plugin ${manifest.name}`, |
| 1822 | ) |
| 1823 | return filtered |
| 1824 | } |
| 1825 | } |
| 1826 | } catch (e: unknown) { |
| 1827 | // Missing/inaccessible is expected - settings.json is optional |
| 1828 | if (!isFsInaccessible(e)) { |
| 1829 | logForDebugging( |
| 1830 | `Failed to parse settings.json for plugin ${manifest.name}: ${e}`, |
| 1831 | { level: 'warn' }, |
| 1832 | ) |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | // Fall back to manifest.settings |
| 1837 | if (manifest.settings) { |
| 1838 | const filtered = parsePluginSettings( |
| 1839 | manifest.settings as Record<string, unknown>, |
| 1840 | ) |
| 1841 | if (filtered) { |
| 1842 | logForDebugging( |
| 1843 | `Loaded settings from manifest for plugin ${manifest.name}`, |
| 1844 | ) |
| 1845 | return filtered |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | return undefined |
| 1850 | } |
| 1851 | |
| 1852 | /** |
| 1853 | * Merge two HooksSettings objects |
no test coverage detected