You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

warn-mixin.js 725B

123456789101112131415161718192021222324
  1. 'use strict'
  2. module.exports = Base => class extends Base {
  3. warn (code, message, data = {}) {
  4. if (this.file) {
  5. data.file = this.file
  6. }
  7. if (this.cwd) {
  8. data.cwd = this.cwd
  9. }
  10. data.code = message instanceof Error && message.code || code
  11. data.tarCode = code
  12. if (!this.strict && data.recoverable !== false) {
  13. if (message instanceof Error) {
  14. data = Object.assign(message, data)
  15. message = message.message
  16. }
  17. this.emit('warn', data.tarCode, message, data)
  18. } else if (message instanceof Error) {
  19. this.emit('error', Object.assign(message, data))
  20. } else {
  21. this.emit('error', Object.assign(new Error(`${code}: ${message}`), data))
  22. }
  23. }
  24. }