feat: 优化插件加载逻辑
This commit is contained in:
@@ -13,15 +13,21 @@ export class JSFileScanner implements plugin.PluginScanner {
|
||||
}
|
||||
|
||||
read(file: any): plugin.PluginLoadMetadata {
|
||||
return { file, type: this.type, scanner: this, loaded: false }
|
||||
return {
|
||||
file,
|
||||
path: file.canonicalPath || file.toString(),
|
||||
type: this.type,
|
||||
scanner: this,
|
||||
loaded: false
|
||||
}
|
||||
}
|
||||
|
||||
load(metadata: plugin.PluginLoadMetadata): plugin.PluginLoadMetadata {
|
||||
if (metadata.type !== this.type) { return }
|
||||
this.updatePlugin(metadata.file)
|
||||
//@ts-ignore load plugin not use cache
|
||||
metadata.instance = require(metadata.file.toString(), { cache: false })
|
||||
return metadata
|
||||
load(loadMetadata: plugin.PluginLoadMetadata): plugin.PluginLoadMetadata {
|
||||
if (loadMetadata.type !== this.type) { return }
|
||||
this.updatePlugin(loadMetadata.file)
|
||||
delete require.cache[loadMetadata.path]
|
||||
loadMetadata.instance = require(loadMetadata.path)
|
||||
return loadMetadata
|
||||
}
|
||||
|
||||
private scanFolder(folder: any): string[] {
|
||||
@@ -45,7 +51,7 @@ export class JSFileScanner implements plugin.PluginScanner {
|
||||
}
|
||||
|
||||
private updatePlugin(file: any) {
|
||||
var update = fs.file(fs.file(fs.file(file).parentFile, 'update'), file.name)
|
||||
var update = fs.file(fs.concat(file.parentFile, 'update', file.name))
|
||||
if (update.exists()) {
|
||||
console.i18n("ms.plugin.manager.build.update", { name: file.name })
|
||||
fs.move(update, file, true)
|
||||
|
||||
Reference in New Issue
Block a user