Add JSDoc types for ContextExclusionPlugin

This commit is contained in:
Mohsen Azimi 2018-07-05 08:20:24 +03:00
parent bdd4442c44
commit 57f21c0d20
2 changed files with 20 additions and 1 deletions

View File

@ -1,12 +1,25 @@
"use strict";
/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
class ContextExclusionPlugin {
/**
* @param {RegExp} negativeMatcher Matcher regular expression
*/
constructor(negativeMatcher) {
this.negativeMatcher = negativeMatcher;
}
/**
* Apply the plugin
* @param {Compiler} compiler Webpack Compiler
* @returns {void}
*/
apply(compiler) {
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", (
/** @type {ContextModuleFactory} */ cmf
) => {
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
return files.filter(filePath => !this.negativeMatcher.test(filePath));
});

View File

@ -15,15 +15,21 @@ const {
const ContextModule = require("./ContextModule");
const ContextElementDependency = require("./dependencies/ContextElementDependency");
/** @typedef {import("./Module")} Module */
const EMPTY_RESOLVE_OPTIONS = {};
module.exports = class ContextModuleFactory extends Tapable {
constructor(resolverFactory) {
super();
this.hooks = {
/** @type {AsyncSeriesWaterfallHook<TODO>} */
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
/** @type {AsyncSeriesWaterfallHook<TODO>} */
afterResolve: new AsyncSeriesWaterfallHook(["data"]),
/** @type {SyncWaterfallHook<string[]>} */
contextModuleFiles: new SyncWaterfallHook(["files"]),
/** @type {SyncWaterfallHook<TODO[]>} */
alternatives: new AsyncSeriesWaterfallHook(["modules"])
};
this._pluginCompat.tap("ContextModuleFactory", options => {