refactor(installer): remove customModulePaths local variable

install() no longer stores the return value of discoverPaths —
this.customModules.paths is accessed directly throughout.
Remove customModulePaths parameter from _installCustomModules.
This commit is contained in:
Alex Verkhovsky 2026-03-21 04:53:29 -06:00
parent 4a76289b35
commit aa406419e7
1 changed files with 20 additions and 30 deletions

View File

@ -58,7 +58,7 @@ class Installer {
// Collect configurations for official modules // Collect configurations for official modules
const moduleConfigs = await this._collectConfigs(config, paths); const moduleConfigs = await this._collectConfigs(config, paths);
const customModulePaths = await this.customModules.discoverPaths(config, paths); await this.customModules.discoverPaths(config, paths);
this.ideManager.setBmadFolderName(BMAD_FOLDER_NAME); this.ideManager.setBmadFolderName(BMAD_FOLDER_NAME);
// Tool selection will be collected after we determine if it's a reinstall/update/new install // Tool selection will be collected after we determine if it's a reinstall/update/new install
@ -199,7 +199,7 @@ class Installer {
} }
// Skip if we already have this module from manifest // Skip if we already have this module from manifest
if (customModulePaths.has(moduleId)) { if (this.customModules.paths.has(moduleId)) {
continue; continue;
} }
@ -213,11 +213,11 @@ class Installer {
// Check if this is actually a custom module (has module.yaml) // Check if this is actually a custom module (has module.yaml)
const moduleYamlPath = path.join(cachedPath, 'module.yaml'); const moduleYamlPath = path.join(cachedPath, 'module.yaml');
if (await fs.pathExists(moduleYamlPath)) { if (await fs.pathExists(moduleYamlPath)) {
customModulePaths.set(moduleId, cachedPath); this.customModules.paths.set(moduleId, cachedPath);
} }
} }
// customModulePaths is this.customModules.paths — .set() above updates it in place // .set() above updates this.customModules.paths in place
} }
// If there are custom files, back them up temporarily // If there are custom files, back them up temporarily
@ -282,7 +282,7 @@ class Installer {
} }
// Skip if we already have this module from manifest // Skip if we already have this module from manifest
if (customModulePaths.has(moduleId)) { if (this.customModules.paths.has(moduleId)) {
continue; continue;
} }
@ -296,7 +296,7 @@ class Installer {
// Check if this is actually a custom module (has module.yaml) // Check if this is actually a custom module (has module.yaml)
const moduleYamlPath = path.join(cachedPath, 'module.yaml'); const moduleYamlPath = path.join(cachedPath, 'module.yaml');
if (await fs.pathExists(moduleYamlPath)) { if (await fs.pathExists(moduleYamlPath)) {
customModulePaths.set(moduleId, cachedPath); this.customModules.paths.set(moduleId, cachedPath);
} }
} }
} }
@ -473,18 +473,18 @@ class Installer {
} }
// Cache custom modules if any // Cache custom modules if any
if (customModulePaths && customModulePaths.size > 0) { if (this.customModules.paths && this.customModules.paths.size > 0) {
spinner.message('Caching custom modules...'); spinner.message('Caching custom modules...');
const { CustomModuleCache } = require('./custom-module-cache'); const { CustomModuleCache } = require('./custom-module-cache');
const customCache = new CustomModuleCache(paths.bmadDir); const customCache = new CustomModuleCache(paths.bmadDir);
for (const [moduleId, sourcePath] of customModulePaths) { for (const [moduleId, sourcePath] of this.customModules.paths) {
const cachedInfo = await customCache.cacheModule(moduleId, sourcePath, { const cachedInfo = await customCache.cacheModule(moduleId, sourcePath, {
sourcePath: sourcePath, // Store original path for updates sourcePath: sourcePath, // Store original path for updates
}); });
// Update the customModulePaths to use the cached location // Update cached path to use the local cache location
customModulePaths.set(moduleId, cachedInfo.cachePath); this.customModules.paths.set(moduleId, cachedInfo.cachePath);
} }
addResult('Custom modules cached', 'ok'); addResult('Custom modules cached', 'ok');
@ -495,7 +495,7 @@ class Installer {
// Build custom module ID set first (needed to filter official list) // Build custom module ID set first (needed to filter official list)
const customModuleIds = new Set(); const customModuleIds = new Set();
for (const id of customModulePaths.keys()) { for (const id of this.customModules.paths.keys()) {
customModuleIds.add(id); customModuleIds.add(id);
} }
if (config._customModuleSources) { if (config._customModuleSources) {
@ -569,19 +569,10 @@ class Installer {
installedModuleNames, installedModuleNames,
}); });
await this._installCustomModules( await this._installCustomModules(config, paths, moduleConfigs, finalCustomContent, addResult, isQuickUpdate, {
config, message,
paths, installedModuleNames,
moduleConfigs, });
customModulePaths,
finalCustomContent,
addResult,
isQuickUpdate,
{
message,
installedModuleNames,
},
);
return `${allModules.length} module(s) ${isQuickUpdate ? 'updated' : 'installed'}`; return `${allModules.length} module(s) ${isQuickUpdate ? 'updated' : 'installed'}`;
}, },
@ -961,13 +952,12 @@ class Installer {
* @param {Object} config - Installation configuration * @param {Object} config - Installation configuration
* @param {Object} paths - InstallPaths instance * @param {Object} paths - InstallPaths instance
* @param {Object} moduleConfigs - Collected module configurations * @param {Object} moduleConfigs - Collected module configurations
* @param {Map} customModulePaths - Map of custom module ID to source path
* @param {Object|undefined} finalCustomContent - Custom content from config * @param {Object|undefined} finalCustomContent - Custom content from config
* @param {Function} addResult - Callback to record installation results * @param {Function} addResult - Callback to record installation results
* @param {boolean} isQuickUpdate - Whether this is a quick update * @param {boolean} isQuickUpdate - Whether this is a quick update
* @param {Object} ctx - Shared context: { message, installedModuleNames } * @param {Object} ctx - Shared context: { message, installedModuleNames }
*/ */
async _installCustomModules(config, paths, moduleConfigs, customModulePaths, finalCustomContent, addResult, isQuickUpdate, ctx) { async _installCustomModules(config, paths, moduleConfigs, finalCustomContent, addResult, isQuickUpdate, ctx) {
const { message, installedModuleNames } = ctx; const { message, installedModuleNames } = ctx;
// Collect all custom module IDs with their info from all sources // Collect all custom module IDs with their info from all sources
@ -1006,8 +996,8 @@ class Installer {
} }
} }
// Fourth: any remaining custom modules from customModulePaths not yet covered // Fourth: any remaining custom modules not yet covered
for (const [moduleId, modulePath] of customModulePaths) { for (const [moduleId, modulePath] of this.customModules.paths) {
if (!customModules.has(moduleId)) { if (!customModules.has(moduleId)) {
customModules.set(moduleId, { id: moduleId, path: modulePath, config: {} }); customModules.set(moduleId, { id: moduleId, path: modulePath, config: {} });
} }
@ -1019,8 +1009,8 @@ class Installer {
message(`${isQuickUpdate ? 'Updating' : 'Installing'} ${moduleName}...`); message(`${isQuickUpdate ? 'Updating' : 'Installing'} ${moduleName}...`);
if (!customModulePaths.has(moduleName) && customInfo.path) { if (!this.customModules.paths.has(moduleName) && customInfo.path) {
customModulePaths.set(moduleName, customInfo.path); this.customModules.paths.set(moduleName, customInfo.path);
} }
const collectedModuleConfig = moduleConfigs[moduleName] || {}; const collectedModuleConfig = moduleConfigs[moduleName] || {};