in modularity/module-manager.js [226:274]
loadModuleInfos(modulePaths, componentType) {
/** @type {Object.<string, Donuts.Modularity.ILoadedModuleInfo>} */
const moduleInfos = Object.create(null);
for (const modulePath of modulePaths) {
if (!fs.existsSync(modulePath)) {
throw new Error(`The path points to non-existing location: ${modulePath}`);
}
/** @type {Donuts.Modularity.IModule} */
const loadedModule = require(modulePath);
if (!utils.isFunction(loadedModule.getModuleMetadata)) {
throw new Error(`Invalid module: ${modulePath}`);
}
/** @type {ComponentCollection} */
const componentCollection = new ComponentCollection(componentType);
const moduleInfo = loadedModule.getModuleMetadata(componentCollection);
if (!utils.isObject(moduleInfo)) {
throw new Error(`moduleInfo must be an object: ${modulePath}`);
}
if (!utils.isString(moduleInfo.name)) {
throw new Error(`moduleInfo.name must be a string: ${modulePath}`);
}
if (!utils.isString(moduleInfo.version)) {
throw new Error(`moduleInfo.version must be a string: ${modulePath}`);
}
if (moduleInfo.name in moduleInfos
|| moduleInfo.name in this.loadedModules) {
throw new Error(`module with name "${moduleInfo.name}" is already registered.`);
}
if (utils.object.isEmpty(componentCollection.components)) {
continue;
}
// @ts-ignore
moduleInfos[moduleInfo.name] = moduleInfo;
moduleInfos[moduleInfo.name].module = loadedModule;
moduleInfos[moduleInfo.name].components = Object.values(componentCollection.components);
}
return moduleInfos;
}