(options = {})
| 396 | } |
| 397 | |
| 398 | export function readExternalPlugins(options = {}) { |
| 399 | const filePath = options.filePath ?? EXTERNAL_PLUGINS_FILE; |
| 400 | |
| 401 | if (!fs.existsSync(filePath)) { |
| 402 | return { |
| 403 | plugins: [], |
| 404 | errors: [], |
| 405 | warnings: [], |
| 406 | }; |
| 407 | } |
| 408 | |
| 409 | let plugins; |
| 410 | try { |
| 411 | const content = fs.readFileSync(filePath, "utf8"); |
| 412 | plugins = JSON.parse(content); |
| 413 | } catch (error) { |
| 414 | return { |
| 415 | plugins: [], |
| 416 | errors: [`Error reading ${path.basename(filePath)}: ${error.message}`], |
| 417 | warnings: [], |
| 418 | }; |
| 419 | } |
| 420 | |
| 421 | const { errors, warnings } = validateExternalPlugins(plugins, options); |
| 422 | return { plugins, errors, warnings }; |
| 423 | } |
no test coverage detected