* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 82 | * @returns {void} |
| 83 | */ |
| 84 | apply(compiler) { |
| 85 | const { _backCompat: backCompat } = compiler; |
| 86 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 87 | if (compilation.moduleMemCaches) { |
| 88 | throw new Error( |
| 89 | class="st">"optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect" |
| 90 | ); |
| 91 | } |
| 92 | const moduleGraph = compilation.moduleGraph; |
| 93 | /** @type {Map<Module, string | ((requestShortener: RequestShortener) => string)>} */ |
| 94 | const bailoutReasonMap = new Map(); |
| 95 | |
| 96 | /** |
| 97 | * Sets bailout reason. |
| 98 | * @param {Module} module the module |
| 99 | * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason |
| 100 | */ |
| 101 | const setBailoutReason = (module, reason) => { |
| 102 | setInnerBailoutReason(module, reason); |
| 103 | moduleGraph |
| 104 | .getOptimizationBailout(module) |
| 105 | .push( |
| 106 | typeof reason === class="st">"function" |
| 107 | ? (rs) => formatBailoutReason(reason(rs)) |
| 108 | : formatBailoutReason(reason) |
| 109 | ); |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * Sets inner bailout reason. |
| 114 | * @param {Module} module the module |
| 115 | * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason |
| 116 | */ |
| 117 | const setInnerBailoutReason = (module, reason) => { |
| 118 | bailoutReasonMap.set(module, reason); |
| 119 | }; |
| 120 | |
| 121 | /** |
| 122 | * Gets inner bailout reason. |
| 123 | * @param {Module} module the module |
| 124 | * @param {RequestShortener} requestShortener the request shortener |
| 125 | * @returns {string | ((requestShortener: RequestShortener) => string) | undefined} the reason |
| 126 | */ |
| 127 | const getInnerBailoutReason = (module, requestShortener) => { |
| 128 | const reason = bailoutReasonMap.get(module); |
| 129 | if (typeof reason === class="st">"function") return reason(requestShortener); |
| 130 | return reason; |
| 131 | }; |
| 132 | |
| 133 | /** |
| 134 | * Format bailout warning. |
| 135 | * @param {Module} module the module |
| 136 | * @param {Problem} problem the problem |
| 137 | * @returns {(requestShortener: RequestShortener) => string} the reason |
| 138 | */ |
| 139 | const formatBailoutWarning = (module, problem) => (requestShortener) => { |
| 140 | if (typeof problem === class="st">"function") { |
| 141 | return formatBailoutReason( |
nothing calls this directly
no test coverage detected