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

Method apply

lib/CleanPlugin.js:352–484  ·  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

350 * @returns {void}
351 */
352 apply(compiler) {
353 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
354 compiler.validate(
355 () => {
356 const { definitions } = require("../schemas/WebpackOptions.json");
357
358 return {
359 definitions,
360 oneOf: [{ $ref: "#/definitions/CleanOptions" }]
361 };
362 },
363 this.options,
364 {
365 name: "Clean Plugin",
366 baseDataPath: "options"
367 }
368 );
369 });
370
371 const { keep } = this.options;
372
373 /** @type {boolean} */
374 const dry = this.options.dry || false;
375 /** @type {KeepFn} */
376 const keepFn =
377 typeof keep === "function"
378 ? keep
379 : typeof keep === "string"
380 ? (path) => path.startsWith(keep)
381 : typeof keep === "object" && keep.test
382 ? (path) => keep.test(path)
383 : () => false;
384
385 // We assume that no external modification happens while the compiler is active
386 // So we can store the old assets and only diff to them to avoid fs access on
387 // incremental builds
388 /** @type {undefined | Assets} */
389 let oldAssets;
390
391 compiler.hooks.emit.tapAsync(
392 {
393 name: PLUGIN_NAME,
394 stage: 100
395 },
396 (compilation, callback) => {
397 const hooks = CleanPlugin.getCompilationHooks(compilation);
398 const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
399 const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem);
400
401 if (!fs.readdir) {
402 return callback(
403 new Error(
404 `${PLUGIN_NAME}: Output filesystem doesn't support listing directories (readdir)`
405 )
406 );
407 }
408
409 /** @type {Assets} */

Callers

nothing calls this directly

Calls 14

getDiffToOldAssetsFunction · 0.85
getDiffToFsFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
getPathMethod · 0.80
getLoggerMethod · 0.65
keysMethod · 0.65
requireFunction · 0.50
callbackFunction · 0.50
testMethod · 0.45
getCompilationHooksMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected