Skip to content

Commit

Permalink
fix(cli): fix unintended reload of plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 10, 2021
1 parent 1e23160 commit 32e9f2d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class Context {

with<D extends readonly (keyof Plugin.Packages)[]>(deps: D, callback: Plugin.Teleporter<D>) {
const modules = deps.map(safeRequire)
if (!modules.every(val => val)) return
if (!modules.every(val => val)) return this
this.teleport(modules, callback)
this.on('plugin-added', (added) => {
const modules = deps.map(safeRequire)
Expand Down
10 changes: 7 additions & 3 deletions packages/koishi/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function createWatcher() {
ignored: ['**/node_modules/**', '**/.git/**', ...ignored],
})

const logger = new Logger('app:watcher')
const logger = new Logger('watcher')

watcher.on('change', async (path) => {
if (!require.cache[path] || externals.has(path)) return
Expand All @@ -213,7 +213,7 @@ function createWatcher() {
/** files that should be reloaded */
const accepted = new Set<string>()
/** files that should not be reloaded */
const declined = new Set([...externals, loadDependencies(path, externals)])
const declined = new Set([...externals, ...loadDependencies(path, externals)])
declined.delete(path)

const plugins: string[] = []
Expand All @@ -237,7 +237,11 @@ function createWatcher() {

await Promise.all(tasks)

accepted.forEach(dep => delete require.cache[dep])
accepted.forEach((path) => {
logger.debug('cache deleted:', path)
delete require.cache[path]
})

for (const filename of plugins) {
const plugin = require(filename)
const [name, options] = pluginMap.get(filename)
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-webui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const builtinWhitelist = [
'http://c2cpicdw.qpic.cn',
]

export const name = 'status'
export const name = 'webui'

export function apply(ctx: Context, config: Config = {}) {
config = Object.assign(defaultConfig, config)
Expand Down

0 comments on commit 32e9f2d

Please sign in to comment.