output-error.js 788 B

123456789101112131415161718192021222324252627282930
  1. const { log, output } = require('proc-log')
  2. const outputError = ({ standard = [], verbose = [], error = [], summary = [], detail = [] }) => {
  3. for (const line of standard) {
  4. // Each output line is just a single string
  5. output.standard(line)
  6. }
  7. for (const line of verbose) {
  8. log.verbose(...line)
  9. }
  10. for (const line of [...error, ...summary, ...detail]) {
  11. log.error(...line)
  12. }
  13. }
  14. const jsonError = (error, npm) => {
  15. if (error && npm?.loaded && npm?.config.get('json')) {
  16. return {
  17. code: error.code,
  18. summary: (error.summary || []).map(l => l.slice(1).join(' ')).join('\n').trim(),
  19. detail: (error.detail || []).map(l => l.slice(1).join(' ')).join('\n').trim(),
  20. ...error.json,
  21. }
  22. }
  23. }
  24. module.exports = {
  25. outputError,
  26. jsonError,
  27. }