From 677ccd90ea5d343a5c415894317a2b2efefc843b Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 23 Jul 2019 09:28:06 +0200 Subject: [PATCH] small fixes --- lib/Compilation.js | 7 +++++-- lib/Compiler.js | 4 ++-- lib/NormalModule.js | 2 +- lib/Stats.js | 21 ++++++++++++++----- lib/logging/createConsoleLogger.js | 2 +- .../__snapshots__/StatsTestCases.test.js.snap | 2 +- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/Compilation.js b/lib/Compilation.js index 60242bac20f..9a77119b253 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -101,6 +101,7 @@ const ErrorHelpers = require("./ErrorHelpers"); * @typedef {Object} LogEntry * @property {string} type * @property {any[]} args + * @property {number} time * @property {string[]=} trace */ @@ -521,6 +522,7 @@ class Compilation extends Tapable { if (!name) { throw new TypeError("Compilation.getLogger(name) called without a name"); } + /** @type {LogEntry[] | undefined} */ let logEntries; return new Logger((type, args) => { if (typeof name === "function") { @@ -541,6 +543,7 @@ class Compilation extends Tapable { .slice(3); break; } + /** @type {LogEntry} */ const logEntry = { time: Date.now(), type, @@ -552,7 +555,7 @@ class Compilation extends Tapable { // eslint-disable-next-line node/no-unsupported-features/node-builtins if (typeof console.profileEnd === "function") { // eslint-disable-next-line node/no-unsupported-features/node-builtins - console.profileEnd(`[${logEntry.name}] ${logEntry.args[0]}`); + console.profileEnd(`[${name}] ${logEntry.args[0]}`); } } if (logEntries === undefined) { @@ -567,7 +570,7 @@ class Compilation extends Tapable { // eslint-disable-next-line node/no-unsupported-features/node-builtins if (typeof console.profile === "function") { // eslint-disable-next-line node/no-unsupported-features/node-builtins - console.profile(`[${logEntry.name}] ${logEntry.args[0]}`); + console.profile(`[${name}] ${logEntry.args[0]}`); } } } diff --git a/lib/Compiler.js b/lib/Compiler.js index b22a4033de2..97ae85c3437 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -86,7 +86,7 @@ class Compiler extends Tapable { watchClose: new SyncHook([]), /** @type {SyncBailHook} */ - log: new SyncBailHook(["origin", "type", "args"]), + infrastructurelog: new SyncBailHook(["origin", "type", "args"]), // TODO the following hooks are weirdly located here // TODO move them for webpack 5 @@ -221,7 +221,7 @@ class Compiler extends Tapable { ); } } - if (this.hooks.log.call(name, type, args) === undefined) { + if (this.hooks.infrastructurelog.call(name, type, args) === undefined) { if (this.infrastructureLogger !== undefined) { this.infrastructureLogger(name, type, args); } diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 84c1211b6e4..a6d9915378d 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -179,7 +179,7 @@ class NormalModule extends Module { return compilation.getLogger(() => [currentLoader && currentLoader.loader, name, this.identifier()] .filter(Boolean) - .join(" ") + .join("|") ); }, // TODO remove in webpack 5 diff --git a/lib/Stats.js b/lib/Stats.js index 2c6378b2235..7a586cb4da7 100644 --- a/lib/Stats.js +++ b/lib/Stats.js @@ -776,8 +776,11 @@ class Stats { if (collapseCounter > 0) collapseCounter++; return collapseCounter === 0; case LogType.groupEnd: - collapseCounter--; - return collapseCounter === 0; + if (collapseCounter > 0) { + collapseCounter--; + return false; + } + return true; default: return collapseCounter === 0; } @@ -803,9 +806,17 @@ class Stats { trace: showLoggingTrace && entry.trace ? entry.trace : undefined }; }); - obj.logging[ - identifierUtils.makePathsRelative(context, origin, compilation.cache) - ] = { + let name = identifierUtils + .makePathsRelative(context, origin, compilation.cache) + .replace(/\|/g, " "); + if (name in obj.logging) { + let i = 1; + while (`${name}#${i}` in obj.logging) { + i++; + } + name = `${name}#${i}`; + } + obj.logging[name] = { entries: processedLogEntries, filteredEntries: logEntries.length - processedLogEntries.length, debug: debugMode diff --git a/lib/logging/createConsoleLogger.js b/lib/logging/createConsoleLogger.js index b6459663491..b6b49660d19 100644 --- a/lib/logging/createConsoleLogger.js +++ b/lib/logging/createConsoleLogger.js @@ -15,7 +15,7 @@ const { LogType } = require("./Logger"); /** * @typedef {Object} LoggerOptions - * @property {false|true|"error"|"warn"|"info"|"log"|"verbose"} options.level loglevel + * @property {false|true|"none"|"error"|"warn"|"info"|"log"|"verbose"} options.level loglevel * @property {FilterTypes|boolean} options.debug filter for debug logging */ diff --git a/test/__snapshots__/StatsTestCases.test.js.snap b/test/__snapshots__/StatsTestCases.test.js.snap index 34724bc4cc5..41bf722fdf9 100644 --- a/test/__snapshots__/StatsTestCases.test.js.snap +++ b/test/__snapshots__/StatsTestCases.test.js.snap @@ -1247,7 +1247,7 @@ Entrypoint main = main.js LOG from MyPlugin Plugin is now active <+> Nested -+ 2 hidden lines ++ 3 hidden lines DEBUG LOG from node_modules/custom-loader/index.js node_modules/custom-loader/index.js!index.js An error