fix(installer): harden readMarketplaceJsonFromDisk and hoist require

- Add try/catch to readMarketplaceJsonFromDisk so malformed JSON returns
  null instead of throwing an unhandled parse error
- Hoist CustomModuleManager require outside the per-module loop in
  _installOfficialModules
This commit is contained in:
Brian Madison 2026-04-09 17:53:54 -05:00
parent eec011ae9a
commit ed51e6c538
2 changed files with 6 additions and 2 deletions

View File

@ -569,6 +569,7 @@ class Installer {
*/
async _installOfficialModules(config, paths, officialModuleIds, addResult, isQuickUpdate, officialModules, ctx) {
const { message, installedModuleNames } = ctx;
const { CustomModuleManager } = require('../modules/custom-module-manager');
for (const moduleName of officialModuleIds) {
if (installedModuleNames.has(moduleName)) continue;
@ -598,7 +599,6 @@ class Installer {
// Prefer version from resolution cache (accurate for custom/local modules),
// fall back to marketplace.json walk-up for official modules
const { CustomModuleManager } = require('../modules/custom-module-manager');
const cachedResolution = CustomModuleManager._resolutionCache.get(moduleName);
const version = cachedResolution?.version || (sourcePath ? await this._getMarketplaceVersion(sourcePath) : '');
addResult(displayName, 'ok', '', { moduleCode: moduleName, newVersion: version });

View File

@ -148,7 +148,11 @@ class CustomModuleManager {
async readMarketplaceJsonFromDisk(dirPath) {
const marketplacePath = path.join(dirPath, '.claude-plugin', 'marketplace.json');
if (!(await fs.pathExists(marketplacePath))) return null;
try {
return JSON.parse(await fs.readFile(marketplacePath, 'utf8'));
} catch {
return null;
}
}
// ─── Discovery ────────────────────────────────────────────────────────────