MCPcopy
hub / github.com/claude-code-best/claude-code / loadPluginManifest

Function loadPluginManifest

src/utils/plugins/pluginLoader.ts:1148–1214  ·  view source on GitHub ↗
(
  manifestPath: string,
  pluginName: string,
  source: string,
)

Source from the content-addressed store, hash-verified

1146 * @throws Error if manifest exists but is invalid (corrupt JSON or schema validation failure)
1147 */
1148export async function loadPluginManifest(
1149 manifestPath: string,
1150 pluginName: string,
1151 source: string,
1152): Promise<PluginManifest> {
1153 // Check if manifest file exists
1154 // If not, create a minimal manifest to allow plugin to function
1155 if (!(await pathExists(manifestPath))) {
1156 // Return default manifest with provided name and source
1157 return {
1158 name: pluginName,
1159 description: `Plugin from ${source}`,
1160 }
1161 }
1162
1163 try {
1164 // Read and parse the manifest JSON file
1165 const content = await readFile(manifestPath, { encoding: 'utf-8' })
1166 const parsedJson = jsonParse(content)
1167
1168 // Validate against the PluginManifest schema
1169 const result = PluginManifestSchema().safeParse(parsedJson)
1170
1171 if (result.success) {
1172 // Valid manifest - return the validated data
1173 return result.data
1174 }
1175
1176 // Schema validation failed but JSON was valid
1177 const errors = result.error.issues
1178 .map(err =>
1179 err.path.length > 0
1180 ? `${err.path.join('.')}: ${err.message}`
1181 : err.message,
1182 )
1183 .join(', ')
1184
1185 logForDebugging(
1186 `Plugin ${pluginName} has an invalid manifest file at ${manifestPath}. Validation errors: ${errors}`,
1187 { level: 'error' },
1188 )
1189
1190 throw new Error(
1191 `Plugin ${pluginName} has an invalid manifest file at ${manifestPath}.\n\nValidation errors: ${errors}`,
1192 )
1193 } catch (error) {
1194 // Check if this is the error we just threw (validation error)
1195 if (
1196 error instanceof Error &&
1197 error.message.includes('invalid manifest file')
1198 ) {
1199 throw error
1200 }
1201
1202 // JSON parsing failed or file read error
1203 const errorMsg = errorMessage(error)
1204
1205 logForDebugging(

Callers 3

createPluginFromPathFunction · 0.85
performPluginUpdateFunction · 0.85

Calls 5

pathExistsFunction · 0.85
readFileFunction · 0.85
jsonParseFunction · 0.85
logForDebuggingFunction · 0.50
errorMessageFunction · 0.50

Tested by

no test coverage detected