style(installer): replace lazy singletons with normal requires

Use top-level require and constructor instantiation for
ExternalModuleManager instead of module-scoped lazy singletons.
This commit is contained in:
Alex Verkhovsky 2026-03-21 04:15:51 -06:00
parent ad2833caf6
commit 2a9df6377e
2 changed files with 9 additions and 37 deletions

View File

@ -15,18 +15,11 @@ const { CustomHandler } = require('../custom-handler');
const prompts = require('../../../lib/prompts'); const prompts = require('../../../lib/prompts');
const { BMAD_FOLDER_NAME } = require('../ide/shared/path-utils'); const { BMAD_FOLDER_NAME } = require('../ide/shared/path-utils');
const { InstallPaths } = require('./install-paths'); const { InstallPaths } = require('./install-paths');
let _externalManager;
function getExternalManager() {
if (!_externalManager) {
const { ExternalModuleManager } = require('../modules/external-manager'); const { ExternalModuleManager } = require('../modules/external-manager');
_externalManager = new ExternalModuleManager();
}
return _externalManager;
}
class Installer { class Installer {
constructor() { constructor() {
this.externalModuleManager = new ExternalModuleManager();
this.detector = new Detector(); this.detector = new Detector();
this.manifest = new Manifest(); this.manifest = new Manifest();
this.moduleManager = new ModuleManager(); this.moduleManager = new ModuleManager();
@ -213,7 +206,7 @@ class Installer {
} }
// Check if this is an external official module - skip cache for those // Check if this is an external official module - skip cache for those
const isExternal = await getExternalManager().hasModule(moduleId); const isExternal = await this.externalModuleManager.hasModule(moduleId);
if (isExternal) { if (isExternal) {
// External modules are handled via cloneExternalModule, not from cache // External modules are handled via cloneExternalModule, not from cache
continue; continue;
@ -297,7 +290,7 @@ class Installer {
} }
// Check if this is an external official module - skip cache for those // Check if this is an external official module - skip cache for those
const isExternal = await getExternalManager().hasModule(moduleId); const isExternal = await this.externalModuleManager.hasModule(moduleId);
if (isExternal) { if (isExternal) {
// External modules are handled via cloneExternalModule, not from cache // External modules are handled via cloneExternalModule, not from cache
continue; continue;
@ -1843,7 +1836,7 @@ class Installer {
} }
// Check if this is an external official module - skip cache for those // Check if this is an external official module - skip cache for those
const isExternal = await getExternalManager().hasModule(moduleId); const isExternal = await this.externalModuleManager.hasModule(moduleId);
if (isExternal) { if (isExternal) {
// External modules are handled via cloneExternalModule, not from cache // External modules are handled via cloneExternalModule, not from cache
continue; continue;
@ -2069,7 +2062,7 @@ class Installer {
} }
// Check if this is an external official module - skip cache for those // Check if this is an external official module - skip cache for those
const isExternal = await getExternalManager().hasModule(moduleId); const isExternal = await this.externalModuleManager.hasModule(moduleId);
if (isExternal) { if (isExternal) {
// External modules are handled via cloneExternalModule, not from cache // External modules are handled via cloneExternalModule, not from cache
continue; continue;

View File

@ -3,32 +3,11 @@ const fs = require('fs-extra');
const yaml = require('yaml'); const yaml = require('yaml');
const prompts = require('../../../lib/prompts'); const prompts = require('../../../lib/prompts');
const { getProjectRoot, getSourcePath, getModulePath } = require('../../../lib/project-root'); const { getProjectRoot, getSourcePath, getModulePath } = require('../../../lib/project-root');
let _externalManager;
function getExternalManager() {
if (!_externalManager) {
const { ExternalModuleManager } = require('./external-manager'); const { ExternalModuleManager } = require('./external-manager');
_externalManager = new ExternalModuleManager();
}
return _externalManager;
}
/**
* Manages the installation, updating, and removal of BMAD modules.
* Handles module discovery, dependency resolution, and configuration processing.
*
* @class ModuleManager
* @requires fs-extra
* @requires yaml
* @requires prompts
*
* @example
* const manager = new ModuleManager();
* const modules = await manager.listAvailable();
* await manager.install('core-module', '/path/to/bmad');
*/
class ModuleManager { class ModuleManager {
constructor(options = {}) { constructor(options = {}) {
this.externalModuleManager = new ExternalModuleManager();
this.customModulePaths = new Map(); this.customModulePaths = new Map();
} }
@ -178,7 +157,7 @@ class ModuleManager {
} }
// Check external official modules // Check external official modules
const externalSource = await getExternalManager().findExternalModuleSource(moduleCode, options); const externalSource = await this.externalModuleManager.findExternalModuleSource(moduleCode, options);
if (externalSource) { if (externalSource) {
return externalSource; return externalSource;
} }