Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

fix: nested plugin types #57

Merged
merged 7 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,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 => {
Expand All @@ -433,7 +433,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')
}
Expand Down
4 changes: 4 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface Options {
tag?: string
ignoreManifest?: boolean,
errorOnManifestCreate?: boolean
parent?: Plugin
children?: Plugin[]
}

export interface IPlugin {
Expand Down Expand Up @@ -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

Expand Down