UNPKG

webpack-dev-middleware

Version:
325 lines (298 loc) • 11.5 kB
// Generated by scripts/build-client-logger.mjs from webpack/lib/logging/Logger.js — do not edit. /* MIT License https://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _toConsumableArray(a) { return _arrayWithoutHoles(a) || _iterableToArray(a) || _unsupportedIterableToArray(a) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(t, e) { if (t) { if ("string" == typeof t) return _arrayLikeToArray(t, e); var o = {}.toString.call(t).slice(8, -1); return "Object" === o && t.constructor && (o = t.constructor.name), "Map" === o || "Set" === o ? Array.from(t) : "Arguments" === o || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o) ? _arrayLikeToArray(t, e) : void 0; } } function _iterableToArray(r) { var e = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (Array.isArray(r) && (null == e || e === ("undefined" != typeof Symbol && [][Symbol.iterator]) || e === []["@@iterator"])) return r; if (null != e) { for (var t, o = [], a = e.call(r); !(t = a.next()).done;) o.push(t.value); return o; } } function _arrayWithoutHoles(a) { if (Array.isArray(a)) return _arrayLikeToArray(a); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(r, t) { for (var o = 0; o < t.length; o++) { var i = t[o]; i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(r, _toPropertyKey(i.key), i); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(r) { var o = _toPrimitive(r, "string"); return "symbol" == _typeof(o) ? o : o + ""; } function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); } var LogType = Object.freeze({ error: (/** @type {"error"} */"error"), // message, c style arguments warn: (/** @type {"warn"} */"warn"), // message, c style arguments info: (/** @type {"info"} */"info"), // message, c style arguments log: (/** @type {"log"} */"log"), // message, c style arguments debug: (/** @type {"debug"} */"debug"), // message, c style arguments trace: (/** @type {"trace"} */"trace"), // no arguments group: (/** @type {"group"} */"group"), // [label] groupCollapsed: (/** @type {"groupCollapsed"} */"groupCollapsed"), // [label] groupEnd: (/** @type {"groupEnd"} */"groupEnd"), // [label] profile: (/** @type {"profile"} */"profile"), // [profileName] profileEnd: (/** @type {"profileEnd"} */"profileEnd"), // [profileName] time: (/** @type {"time"} */"time"), // name, time as [seconds, nanoseconds] clear: (/** @type {"clear"} */"clear"), // no arguments status: (/** @type {"status"} */"status") // message, arguments }); module.exports.LogType = LogType; /** @typedef {typeof LogType[keyof typeof LogType]} LogTypeEnum */ /** @typedef {Map<string | undefined, [number, number]>} TimersMap */ var LOG_SYMBOL = Symbol("webpack logger raw log method"); var TIMERS_SYMBOL = Symbol("webpack logger times"); var TIMERS_AGGREGATES_SYMBOL = Symbol("webpack logger aggregated times"); /** @typedef {EXPECTED_ANY[]} Args */ /** @typedef {(type: LogTypeEnum, args?: Args) => void} LogFn */ /** @typedef {(name: string | (() => string)) => Logger} GetChildLogger */ var Logger = /*#__PURE__*/function () { /** * Creates an instance of Logger. * @param {LogFn} log log function * @param {GetChildLogger} getChildLogger function to create child logger */ function Logger(log, getChildLogger) { _classCallCheck(this, Logger); /** @type {LogFn} */ this[LOG_SYMBOL] = log; /** @type {GetChildLogger} */ this.getChildLogger = getChildLogger; } /** * Processes the provided arg. * @param {Args} args args */ return _createClass(Logger, [{ key: "error", value: function error() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } this[LOG_SYMBOL](LogType.error, args); } /** * Processes the provided arg. * @param {Args} args args */ }, { key: "warn", value: function warn() { for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } this[LOG_SYMBOL](LogType.warn, args); } /** * Processes the provided arg. * @param {Args} args args */ }, { key: "info", value: function info() { for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { args[_key3] = arguments[_key3]; } this[LOG_SYMBOL](LogType.info, args); } /** * Processes the provided arg. * @param {Args} args args */ }, { key: "log", value: function log() { for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { args[_key4] = arguments[_key4]; } this[LOG_SYMBOL](LogType.log, args); } /** * Processes the provided arg. * @param {Args} args args */ }, { key: "debug", value: function debug() { for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { args[_key5] = arguments[_key5]; } this[LOG_SYMBOL](LogType.debug, args); } /** * Processes the provided condition. * @param {boolean=} condition condition * @param {Args} args args */ }, { key: "assert", value: function assert(condition) { if (!condition) { for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { args[_key6 - 1] = arguments[_key6]; } this[LOG_SYMBOL](LogType.error, args); } } }, { key: "trace", value: function trace() { this[LOG_SYMBOL](LogType.trace, ["Trace"]); } }, { key: "clear", value: function clear() { this[LOG_SYMBOL](LogType.clear); } /** * Processes the provided arg. * @param {Args} args args */ }, { key: "status", value: function status() { for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { args[_key7] = arguments[_key7]; } this[LOG_SYMBOL](LogType.status, args); } /** * Processes the provided arg. * @param {Args} args args */ }, { key: "group", value: function group() { for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) { args[_key8] = arguments[_key8]; } this[LOG_SYMBOL](LogType.group, args); } /** * Processes the provided arg. * @param {Args} args args */ }, { key: "groupCollapsed", value: function groupCollapsed() { for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) { args[_key9] = arguments[_key9]; } this[LOG_SYMBOL](LogType.groupCollapsed, args); } }, { key: "groupEnd", value: function groupEnd() { this[LOG_SYMBOL](LogType.groupEnd); } /** * Processes the provided label. * @param {string=} label label */ }, { key: "profile", value: function profile(label) { this[LOG_SYMBOL](LogType.profile, [label]); } /** * Processes the provided label. * @param {string=} label label */ }, { key: "profileEnd", value: function profileEnd(label) { this[LOG_SYMBOL](LogType.profileEnd, [label]); } /** * Processes the provided label. * @param {string} label label */ }, { key: "time", value: function time(label) { /** @type {TimersMap} */ this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map(); this[TIMERS_SYMBOL].set(label, process.hrtime()); } /** * Processes the provided label. * @param {string=} label label */ }, { key: "timeLog", value: function timeLog(label) { var prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label); if (!prev) { throw new Error("No such label '".concat(label, "' for Logger.timeLog()")); } var time = process.hrtime(prev); this[LOG_SYMBOL](LogType.time, [label].concat(_toConsumableArray(time))); } /** * Processes the provided label. * @param {string=} label label */ }, { key: "timeEnd", value: function timeEnd(label) { var prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label); if (!prev) { throw new Error("No such label '".concat(label, "' for Logger.timeEnd()")); } var time = process.hrtime(prev); /** @type {TimersMap} */ this[TIMERS_SYMBOL].delete(label); this[LOG_SYMBOL](LogType.time, [label].concat(_toConsumableArray(time))); } /** * Processes the provided label. * @param {string=} label label */ }, { key: "timeAggregate", value: function timeAggregate(label) { var prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label); if (!prev) { throw new Error("No such label '".concat(label, "' for Logger.timeAggregate()")); } var time = process.hrtime(prev); /** @type {TimersMap} */ this[TIMERS_SYMBOL].delete(label); /** @type {TimersMap} */ this[TIMERS_AGGREGATES_SYMBOL] = this[TIMERS_AGGREGATES_SYMBOL] || new Map(); var current = this[TIMERS_AGGREGATES_SYMBOL].get(label); if (current !== undefined) { if (time[1] + current[1] > 1e9) { time[0] += current[0] + 1; time[1] = time[1] - 1e9 + current[1]; } else { time[0] += current[0]; time[1] += current[1]; } } this[TIMERS_AGGREGATES_SYMBOL].set(label, time); } /** * Time aggregate end. * @param {string=} label label */ }, { key: "timeAggregateEnd", value: function timeAggregateEnd(label) { if (this[TIMERS_AGGREGATES_SYMBOL] === undefined) return; var time = this[TIMERS_AGGREGATES_SYMBOL].get(label); if (time === undefined) return; this[TIMERS_AGGREGATES_SYMBOL].delete(label); this[LOG_SYMBOL](LogType.time, [label].concat(_toConsumableArray(time))); } }]); }(); module.exports.Logger = Logger;