MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/debug/ProfilingPlugin.js:266–395  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

264 * @returns {void}
265 */
266 apply(compiler) {
267 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
268 compiler.validate(
269 () => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
270 this.options,
271 {
272 name: "Profiling Plugin",
273 baseDataPath: "options"
274 },
275 (options) =>
276 require("../../schemas/plugins/debug/ProfilingPlugin.check")(options)
277 );
278 });
279
280 const tracer = createTrace(
281 /** @type {IntermediateFileSystem} */
282 (compiler.intermediateFileSystem),
283 this.options.outputPath || "events.json"
284 );
285 tracer.profiler.startProfiling();
286
287 // Compiler Hooks
288 for (const hookName of Object.keys(compiler.hooks)) {
289 const hook =
290 compiler.hooks[/** @type {keyof Compiler["hooks"]} */ (hookName)];
291 if (hook) {
292 hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName));
293 }
294 }
295
296 for (const hookName of Object.keys(compiler.resolverFactory.hooks)) {
297 const hook =
298 compiler.resolverFactory.hooks[
299 /** @type {keyof ResolverFactory["hooks"]} */
300 (hookName)
301 ];
302 if (hook) {
303 hook.intercept(
304 /** @type {EXPECTED_ANY} */
305 (makeInterceptorFor("Resolver", tracer)(hookName))
306 );
307 }
308 }
309
310 compiler.hooks.compilation.tap(
311 PLUGIN_NAME,
312 (compilation, { normalModuleFactory, contextModuleFactory }) => {
313 interceptAllHooksFor(compilation, tracer, "Compilation");
314 interceptAllHooksFor(
315 normalModuleFactory,
316 tracer,
317 "Normal Module Factory"
318 );
319 interceptAllHooksFor(
320 contextModuleFactory,
321 tracer,
322 "Context Module Factory"
323 );

Callers

nothing calls this directly

Calls 15

createTraceFunction · 0.85
makeInterceptorForFunction · 0.85
interceptAllHooksForFunction · 0.85
interceptAllParserHooksFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
startProfilingMethod · 0.80
interceptMethod · 0.80
stopProfilingMethod · 0.80

Tested by

no test coverage detected