diff --git a/src/config.ts b/src/config.ts index 4d46c9c8..da0f11c1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -418,7 +418,7 @@ export class Config implements IConfig { } catch {} return 0 } - protected async loadPlugins(root: string, type: string, plugins: (string | {root?: string, name?: string, tag?: string})[]) { + protected async loadPlugins(root: string, type: string, plugins: (string | {root?: string, name?: string, tag?: string})[], parent?: Plugin.Plugin) { if (!plugins || !plugins.length) return debug('loading plugins', plugins) await Promise.all((plugins || []).map(async plugin => { @@ -435,7 +435,11 @@ export class Config implements IConfig { await instance.load() if (this.plugins.find(p => p.name === instance.name)) return this.plugins.push(instance) - await this.loadPlugins(instance.root, type, instance.pjson.oclif.plugins || []) + if (parent) { + instance.parent = parent + parent.children.push(instance) + } + await this.loadPlugins(instance.root, type, instance.pjson.oclif.plugins || [], instance) } catch (err) { this.warn(err, 'loadPlugins') } diff --git a/src/plugin.ts b/src/plugin.ts index 30c3f949..492a9a41 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -18,6 +18,8 @@ export interface Options { tag?: string ignoreManifest?: boolean, errorOnManifestCreate?: boolean + parent?: Plugin + children?: Plugin[] } export interface IPlugin { @@ -86,6 +88,8 @@ export class Plugin implements IPlugin { hooks!: {[k: string]: string[]} valid = false alreadyLoaded = false + parent: Plugin | undefined + children: Plugin[] = [] protected _debug = Debug() protected warned = false