[plugins] Fix bug where not all plugins are loaded
This commit is contained in:
parent
fca79c36ef
commit
3e091fd02b
|
@ -86,7 +86,7 @@ module.exports = configure(function (/* ctx */) {
|
||||||
const custom_plgns = require('./plugin.config.js')
|
const custom_plgns = require('./plugin.config.js')
|
||||||
const required_plgns = require('./src/vendor-plugin.config.js')
|
const required_plgns = require('./src/vendor-plugin.config.js')
|
||||||
return src.replace(/\/\* *INSERT_PLUGIN_LIST *\*\//,
|
return src.replace(/\/\* *INSERT_PLUGIN_LIST *\*\//,
|
||||||
[...custom_plgns, ...required_plgns].map(v => `import("${v}").then(v => success(v)).catch(() => failure("${v}"))`)
|
[...custom_plgns, ...required_plgns].map(v => `import("${v}").catch(() => "${v}")`)
|
||||||
.join(','))
|
.join(','))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,26 +21,10 @@ function validatePlugin(plugin: FG_Plugin.Plugin) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable */
|
|
||||||
// This functions are used by webpack magic
|
|
||||||
// Called when import promise resolved
|
|
||||||
function success(value: ImportPlgn, path: string) {
|
|
||||||
if (validatePlugin(value.default)) PLUGINS.plugins.set(value.default.id, value.default);
|
|
||||||
else failure(path);
|
|
||||||
}
|
|
||||||
// Called when import promise rejected
|
|
||||||
function failure(path = 'unknown') {
|
|
||||||
console.error(`Plugin ${path} could not be found and not imported`);
|
|
||||||
}
|
|
||||||
/* eslint-enable */
|
|
||||||
|
|
||||||
// Here does some magic happens, WebPack will automatically replace the following comment with the import statements
|
// Here does some magic happens, WebPack will automatically replace the following comment with the import statements
|
||||||
const PLUGINS = {
|
const PLUGINS = <Array<Promise<ImportPlgn>>>[
|
||||||
context: <Array<() => Promise<ImportPlgn>>>[
|
|
||||||
/*INSERT_PLUGIN_LIST*/
|
/*INSERT_PLUGIN_LIST*/
|
||||||
],
|
];
|
||||||
plugins: new Map<string, FG_Plugin.Plugin>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
interface BackendPlugin {
|
interface BackendPlugin {
|
||||||
permissions: string[];
|
permissions: string[];
|
||||||
|
@ -314,10 +298,26 @@ export default boot(async ({ router, app }) => {
|
||||||
widgets: [],
|
widgets: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const BreakError = {};
|
|
||||||
try {
|
try {
|
||||||
PLUGINS.plugins.forEach((plugin, id) => {
|
// Wait for all plugins to be loaded
|
||||||
if (!loadPlugin(loadedPlugins, plugin, backend)) {
|
const results = await Promise.allSettled(PLUGINS);
|
||||||
|
|
||||||
|
// Check if loaded successfully
|
||||||
|
results.forEach((result) => {
|
||||||
|
if (result.status === 'rejected') {
|
||||||
|
throw <string>result.reason;
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
!(
|
||||||
|
validatePlugin(result.value.default) &&
|
||||||
|
loadPlugin(loadedPlugins, result.value.default, backend)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
throw result.value.default.id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (reason) {
|
||||||
|
const id = <string>reason;
|
||||||
void router.push({ name: 'error' });
|
void router.push({ name: 'error' });
|
||||||
|
|
||||||
Notify.create({
|
Notify.create({
|
||||||
|
@ -326,11 +326,6 @@ export default boot(async ({ router, app }) => {
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
progress: true,
|
progress: true,
|
||||||
});
|
});
|
||||||
throw BreakError;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
if (e !== BreakError) throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort widgets by priority
|
// Sort widgets by priority
|
||||||
|
|
Loading…
Reference in New Issue