| | |
| | | /*! |
| | | * depd |
| | | * Copyright(c) 2014-2017 Douglas Christopher Wilson |
| | | * Copyright(c) 2014-2018 Douglas Christopher Wilson |
| | | * MIT Licensed |
| | | */ |
| | | |
| | |
| | | * Module dependencies. |
| | | */ |
| | | |
| | | var callSiteToString = require('./lib/compat').callSiteToString |
| | | var eventListenerCount = require('./lib/compat').eventListenerCount |
| | | var relative = require('path').relative |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | for (var i = 0; i < stack.length; i++) { |
| | | str += '\n at ' + callSiteToString(stack[i]) |
| | | str += '\n at ' + stack[i].toString() |
| | | } |
| | | |
| | | return str |
| | |
| | | } |
| | | |
| | | /** |
| | | * Determine if event emitter has listeners of a given type. |
| | | * |
| | | * The way to do this check is done three different ways in Node.js >= 0.8 |
| | | * so this consolidates them into a minimal set using instance methods. |
| | | * |
| | | * @param {EventEmitter} emitter |
| | | * @param {string} type |
| | | * @returns {boolean} |
| | | * @private |
| | | */ |
| | | |
| | | function eehaslisteners (emitter, type) { |
| | | var count = typeof emitter.listenerCount !== 'function' |
| | | ? emitter.listeners(type).length |
| | | : emitter.listenerCount(type) |
| | | |
| | | return count > 0 |
| | | } |
| | | |
| | | /** |
| | | * Determine if namespace is ignored. |
| | | */ |
| | | |
| | | function isignored (namespace) { |
| | | /* istanbul ignore next: tested in a child processs */ |
| | | if (process.noDeprecation) { |
| | | // --no-deprecation support |
| | | return true |
| | |
| | | */ |
| | | |
| | | function istraced (namespace) { |
| | | /* istanbul ignore next: tested in a child processs */ |
| | | if (process.traceDeprecation) { |
| | | // --trace-deprecation support |
| | | return true |
| | |
| | | */ |
| | | |
| | | function log (message, site) { |
| | | var haslisteners = eventListenerCount(process, 'deprecation') !== 0 |
| | | var haslisteners = eehaslisteners(process, 'deprecation') |
| | | |
| | | // abort early if no destination |
| | | if (!haslisteners && this._ignored) { |
| | |
| | | // add stack trace |
| | | if (this._traced) { |
| | | for (var i = 0; i < stack.length; i++) { |
| | | formatted += '\n at ' + callSiteToString(stack[i]) |
| | | formatted += '\n at ' + stack[i].toString() |
| | | } |
| | | |
| | | return formatted |
| | |
| | | // add stack trace |
| | | if (this._traced) { |
| | | for (var i = 0; i < stack.length; i++) { |
| | | formatted += '\n \x1b[36mat ' + callSiteToString(stack[i]) + '\x1b[39m' // cyan |
| | | formatted += '\n \x1b[36mat ' + stack[i].toString() + '\x1b[39m' // cyan |
| | | } |
| | | |
| | | return formatted |
| | |
| | | } |
| | | |
| | | var args = createArgumentsString(fn.length) |
| | | var deprecate = this // eslint-disable-line no-unused-vars |
| | | var stack = getStack() |
| | | var site = callSiteLocation(stack[1]) |
| | | |
| | | site.name = fn.name |
| | | |
| | | // eslint-disable-next-line no-eval |
| | | var deprecatedfn = eval('(function (' + args + ') {\n' + |
| | | // eslint-disable-next-line no-new-func |
| | | var deprecatedfn = new Function('fn', 'log', 'deprecate', 'message', 'site', |
| | | '"use strict"\n' + |
| | | 'return function (' + args + ') {' + |
| | | 'log.call(deprecate, message, site)\n' + |
| | | 'return fn.apply(this, arguments)\n' + |
| | | '})') |
| | | '}')(fn, log, this, message, site) |
| | | |
| | | return deprecatedfn |
| | | } |