(key: string, configScope: string)
| 114 | } |
| 115 | |
| 116 | async reloadPlugin(key: string, configScope: string) { |
| 117 | const plugin = this.resolvePlugin(key); |
| 118 | if (!plugin) return; |
| 119 | // currently cordis validates config and converts proxy to plain object |
| 120 | // must do a full reload once config changed |
| 121 | const config = await this.resolveConfig(plugin, configScope, false); |
| 122 | let fork = this.state[key]; |
| 123 | const displayPath = key.includes('node_modules') |
| 124 | ? key.split('node_modules').pop() |
| 125 | : path.relative(process.cwd(), key); |
| 126 | logger.info( |
| 127 | `%s plugin %c${configScope ? ' with scope %c' : ''}`, |
| 128 | fork ? 'update' : 'apply', displayPath, configScope, |
| 129 | ); |
| 130 | if (fork) { |
| 131 | fork.update(config, true); |
| 132 | } else { |
| 133 | fork = this.ctx.plugin(plugin, config); |
| 134 | if (!fork) return; |
| 135 | const inner = Object.getPrototypeOf(fork) !== Fiber.prototype |
| 136 | ? Object.getPrototypeOf(fork) : fork; |
| 137 | this.state[key] = inner; |
| 138 | } |
| 139 | if (!Object.isFrozen(config)) { |
| 140 | fork.ctx.on('system/setting', async () => { |
| 141 | if (!fork.uid || !this.state[key]) return; |
| 142 | const resolved = await this.resolveConfig(plugin, configScope, false); |
| 143 | if (isEqual(this.state[key].config, resolved)) return; |
| 144 | this.reloadPlugin(key, configScope); |
| 145 | }); |
| 146 | } |
| 147 | return fork; |
| 148 | } |
| 149 | |
| 150 | resolvePlugin(name: string) { |
| 151 | try { |
no test coverage detected