* Loads and validates plugin hooks configuration from a JSON file. * IMPORTANT: Only call this when the hooks file is expected to exist. * * @param hooksConfigPath - Full path to the hooks.json file * @param pluginName - Plugin name for error messages * @returns Validated HooksSettings * @thro
( hooksConfigPath: string, pluginName: string, )
| 1222 | * @throws Error if file doesn't exist or is invalid |
| 1223 | */ |
| 1224 | async function loadPluginHooks( |
| 1225 | hooksConfigPath: string, |
| 1226 | pluginName: string, |
| 1227 | ): Promise<HooksSettings> { |
| 1228 | if (!(await pathExists(hooksConfigPath))) { |
| 1229 | throw new Error( |
| 1230 | `Hooks file not found at ${hooksConfigPath} for plugin ${pluginName}. If the manifest declares hooks, the file must exist.`, |
| 1231 | ) |
| 1232 | } |
| 1233 | |
| 1234 | const content = await readFile(hooksConfigPath, { encoding: 'utf-8' }) |
| 1235 | const rawHooksConfig = jsonParse(content) |
| 1236 | |
| 1237 | // The hooks.json file has a wrapper structure with description and hooks |
| 1238 | // Use PluginHooksSchema to validate and extract the hooks property |
| 1239 | const validatedPluginHooks = PluginHooksSchema().parse(rawHooksConfig) |
| 1240 | |
| 1241 | return validatedPluginHooks.hooks as HooksSettings |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Validate a list of plugin component relative paths by checking existence in parallel. |
no test coverage detected