diff options
Diffstat (limited to 'src/plugins/index.ts')
-rw-r--r-- | src/plugins/index.ts | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/plugins/index.ts b/src/plugins/index.ts index d3842aa..268e200 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -30,11 +30,36 @@ export const PMLogger = logger; export const plugins = Plugins; export const patches = [] as Patch[]; +const settings = Settings.plugins; + export function isPluginEnabled(p: string) { - return (Settings.plugins[p]?.enabled || Plugins[p]?.required) ?? false; + return ( + Plugins[p]?.required || + Plugins[p]?.isDependency || + settings[p]?.enabled + ) ?? false; +} + +const pluginsValues = Object.values(Plugins); + +// First roundtrip to mark and force enable dependencies +for (const p of pluginsValues) { + p.dependencies?.forEach(d => { + const dep = Plugins[d]; + if (dep) { + settings[d].enabled = true; + dep.isDependency = true; + } + else { + const error = new Error(`Plugin ${p.name} has unresolved dependency ${d}`); + if (IS_DEV) + throw error; + logger.warn(error); + } + }); } -for (const p of Object.values(Plugins)) +for (const p of pluginsValues) if (p.patches && isPluginEnabled(p.name)) { for (const patch of p.patches) { patch.plugin = p.name; |