diff --git a/lib/Compilation.js b/lib/Compilation.js index 7df0b86f9..02afdac30 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -807,7 +807,7 @@ class Compilation { dependentModule.profile = currentProfile; } - dependentModule.issuer = module; + dependentModule.setIssuer(this.moduleGraph, module); } else { if (this.profile) { if (module.profile) { diff --git a/lib/Module.js b/lib/Module.js index 8a5f713a6..e63db4db7 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -45,6 +45,7 @@ const SortableSet = require("./util/SortableSet"); const EMPTY_RESOLVE_OPTIONS = {}; const optimizationBailoutSymbol = Symbol("optimization bailout"); const usedExportsSymbol = Symbol("used exports"); +const issuerSymbol = Symbol("issuer"); let debugId = 1000; @@ -120,8 +121,6 @@ class Module extends DependenciesBlock { this.index2 = null; /** @type {number} */ this.depth = null; - /** @type {Module} */ - this.issuer = null; /** @type {undefined | object} */ this.profile = undefined; /** @type {boolean} */ @@ -149,6 +148,25 @@ class Module extends DependenciesBlock { return (this.buildInfo && this.buildInfo.moduleArgument) || "module"; } + /** + * @param {ModuleGraph} moduleGraph the module graph + * @returns {Module | null} the issuer module + */ + getIssuer(moduleGraph) { + const meta = moduleGraph.getMeta(this); + return meta[issuerSymbol]; + } + + /** + * @param {ModuleGraph} moduleGraph the module graph + * @param {Module | null} issuer the issuer module + * @returns {void} + */ + setIssuer(moduleGraph, issuer) { + const meta = moduleGraph.getMeta(this); + meta[issuerSymbol] = issuer; + } + /** * @param {ModuleGraph} moduleGraph the module graph * @returns {(string | OptimizationBailoutFunction)[]} optimization bailouts @@ -199,7 +217,6 @@ class Module extends DependenciesBlock { this.index = null; this.index2 = null; this.depth = null; - this.issuer = null; this.profile = undefined; this.prefetched = false; this.built = false; diff --git a/lib/ModuleDependencyError.js b/lib/ModuleDependencyError.js index 9f028aeb2..b3c8e1114 100644 --- a/lib/ModuleDependencyError.js +++ b/lib/ModuleDependencyError.js @@ -27,7 +27,6 @@ class ModuleDependencyError extends WebpackError { this.module = module; this.loc = loc; this.error = err; - this.origin = module.issuer; Error.captureStackTrace(this, this.constructor); } diff --git a/lib/ModuleDependencyWarning.js b/lib/ModuleDependencyWarning.js index 6a45b6e10..17c4c9d36 100644 --- a/lib/ModuleDependencyWarning.js +++ b/lib/ModuleDependencyWarning.js @@ -19,7 +19,6 @@ module.exports = class ModuleDependencyWarning extends WebpackError { this.module = module; this.loc = loc; this.error = err; - this.origin = module.issuer; Error.captureStackTrace(this, this.constructor); } diff --git a/lib/Stats.js b/lib/Stats.js index 343f6ac86..0638eca62 100644 --- a/lib/Stats.js +++ b/lib/Stats.js @@ -317,9 +317,10 @@ class Stats { if (showErrorDetails && e.missing) { text += e.missing.map(item => `\n[${item}]`).join(""); } - if (showModuleTrace && e.origin) { + const origin = e.origin || (e.module && e.module.getIssuer(moduleGraph)); + if (showModuleTrace && origin) { text += `\n @ ${this.formatFilePath( - e.origin.readableIdentifier(requestShortener) + origin.readableIdentifier(requestShortener) )}`; if (typeof e.originLoc === "object") { const locInfo = formatLocation(e.originLoc); @@ -334,10 +335,10 @@ class Stats { text += ` ${locInfo}`; } } - let current = e.origin; - while (current.issuer) { - current = current.issuer; + let current = origin.getIssuer(moduleGraph); + while (current) { text += `\n @ ${current.readableIdentifier(requestShortener)}`; + current = current.getIssuer(moduleGraph); } } return text; @@ -493,9 +494,11 @@ class Stats { const fnModule = module => { const path = []; - let current = module; - while (current.issuer) { - path.push((current = current.issuer)); + const issuer = module.getIssuer(moduleGraph); + let current = issuer; + while (current) { + path.push(current); + current = current.getIssuer(moduleGraph); } path.reverse(); const obj = { @@ -510,12 +513,11 @@ class Stats { optional: module.isOptional(moduleGraph), prefetched: module.prefetched, chunks: Array.from(module.chunksIterable, chunk => chunk.id), - issuer: module.issuer && module.issuer.identifier(), - issuerId: module.issuer && module.issuer.id, - issuerName: - module.issuer && module.issuer.readableIdentifier(requestShortener), + issuer: issuer && issuer.identifier(), + issuerId: issuer && issuer.id, + issuerName: issuer && issuer.readableIdentifier(requestShortener), issuerPath: - module.issuer && + issuer && path.map(module => ({ id: module.id, identifier: module.identifier(),