Merge pull request #7574 from byzyk/types/ignore-plugin

chore(types): IgnorePlugin
This commit is contained in:
Tobias Koppers 2018-06-26 16:20:07 +02:00 committed by GitHub
commit aab3554cad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 9 deletions

View File

@ -4,16 +4,26 @@
*/
"use strict";
/** @typedef {import("./Compiler.js")} Compiler */
class IgnorePlugin {
/**
* @param {RegExp} resourceRegExp A RegExp to test the request against
* @param {RegExp=} contextRegExp A RegExp to test the context (directory) against
*/
constructor(resourceRegExp, contextRegExp) {
/** @private @type {RegExp} */
this.resourceRegExp = resourceRegExp;
/** @private @type {RegExp} */
this.contextRegExp = contextRegExp;
/** @private @type {Function} */
this.checkIgnore = this.checkIgnore.bind(this);
}
/*
* Only returns true if a "resourceRegExp" exists
/**
* @param {string} resource resource
* @returns {boolean} returns true if a "resourceRegExp" exists
* and the resource given matches the regexp.
*/
checkResource(resource) {
@ -23,8 +33,9 @@ class IgnorePlugin {
return this.resourceRegExp.test(resource);
}
/*
* Returns true if contextRegExp does not exist
/**
* @param {string} context context
* @returns {boolean} returns true if "contextRegExp" does not exist
* or if context matches the given regexp.
*/
checkContext(context) {
@ -34,12 +45,12 @@ class IgnorePlugin {
return this.contextRegExp.test(context);
}
/*
* Returns true if result should be ignored.
* false if it shouldn't.
*
* Not that if "contextRegExp" is given, both the "resourceRegExp"
/**
* Note that if "contextRegExp" is given, both the "resourceRegExp"
* and "contextRegExp" have to match.
*
* @param {TODO} result result
* @returns {boolean} returns true if result should be ignored
*/
checkResult(result) {
if (!result) {
@ -50,6 +61,10 @@ class IgnorePlugin {
);
}
/**
* @param {TODO} result result
* @returns {TODO|null} returns result or null if result should be ignored
*/
checkIgnore(result) {
// check if result is ignored
if (this.checkResult(result)) {
@ -58,6 +73,10 @@ class IgnorePlugin {
return result;
}
/**
* @param {Compiler} compiler Webpack Compiler
* @returns {void}
*/
apply(compiler) {
compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => {
nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);