Add types to various plugins
This commit is contained in:
parent
c828bfa5c7
commit
d881bb4c8f
|
@ -10,9 +10,10 @@ const {
|
|||
toConstantDependencyWithWebpackRequire,
|
||||
evaluateToString
|
||||
} = require("./JavascriptParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
const NullFactory = require("./NullFactory");
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
const REPLACEMENTS = {
|
||||
|
@ -37,6 +38,11 @@ const REPLACEMENT_TYPES = {
|
|||
/* eslint-enable camelcase */
|
||||
|
||||
class APIPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"APIPlugin",
|
||||
|
|
|
@ -14,7 +14,7 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
|||
class AutomaticPrefetchPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
|
|
|
@ -14,7 +14,7 @@ const NullFactory = require("./NullFactory");
|
|||
class CompatibilityPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
|
|
|
@ -17,7 +17,7 @@ class ContextExclusionPlugin {
|
|||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
|
|
|
@ -10,11 +10,18 @@ const NullFactory = require("./NullFactory");
|
|||
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class DelegatedPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DelegatedPlugin",
|
||||
|
|
|
@ -24,7 +24,7 @@ class EvalSourceMapDevToolPlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
|
|
|
@ -7,11 +7,18 @@
|
|||
|
||||
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class ExternalsPlugin {
|
||||
constructor(type, externals) {
|
||||
this.type = type;
|
||||
this.externals = externals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compile.tap("ExternalsPlugin", ({ normalModuleFactory }) => {
|
||||
new ExternalModuleFactoryPlugin(this.type, this.externals).apply(
|
||||
|
|
|
@ -7,7 +7,14 @@
|
|||
|
||||
const FunctionModuleTemplatePlugin = require("./FunctionModuleTemplatePlugin");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class FunctionModulePlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("FunctionModulePlugin", compilation => {
|
||||
new FunctionModuleTemplatePlugin({
|
||||
|
|
|
@ -82,7 +82,7 @@ class IgnorePlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
|
|
|
@ -9,7 +9,14 @@ const JavascriptModulesPlugin = require("./JavascriptModulesPlugin");
|
|||
const JsonGenerator = require("./JsonGenerator");
|
||||
const JsonParser = require("./JsonParser");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class JsonModulesPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"JsonModulesPlugin",
|
||||
|
|
|
@ -62,12 +62,16 @@ class ModuleProfile {
|
|||
this.storing = this.storingEndTime - this.storingStartTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge this profile into another one
|
||||
* @param {ModuleProfile} realProfile the profile to merge into
|
||||
* @returns {void}
|
||||
*/
|
||||
mergeInto(realProfile) {
|
||||
if (this.factory > realProfile.additionalFactories)
|
||||
realProfile.additionalFactories = this.factory;
|
||||
if (this.integration > realProfile.additionalIntegration)
|
||||
realProfile.additionalIntegration = this.integration;
|
||||
return realProfile;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class NoEmitOnErrorsPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.shouldEmit.tap("NoEmitOnErrorsPlugin", compilation => {
|
||||
if (compilation.getStats().hasErrors()) return false;
|
||||
|
|
|
@ -18,6 +18,7 @@ const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
|||
const ModuleDecoratorDependency = require("./dependencies/ModuleDecoratorDependency");
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
|
@ -30,6 +31,11 @@ class NodeStuffPlugin {
|
|||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
compiler.hooks.compilation.tap(
|
||||
|
|
|
@ -7,12 +7,25 @@
|
|||
|
||||
const path = require("path");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {function(TODO): void} ModuleReplacer */
|
||||
|
||||
class NormalModuleReplacementPlugin {
|
||||
/**
|
||||
* Create an instance of the plugin
|
||||
* @param {RegExp} resourceRegExp the resource matcher
|
||||
* @param {string|ModuleReplacer} newResource the resource replacement
|
||||
*/
|
||||
constructor(resourceRegExp, newResource) {
|
||||
this.resourceRegExp = resourceRegExp;
|
||||
this.newResource = newResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const resourceRegExp = this.resourceRegExp;
|
||||
const newResource = this.newResource;
|
||||
|
|
|
@ -7,16 +7,24 @@
|
|||
|
||||
const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class PrefetchPlugin {
|
||||
constructor(context, request) {
|
||||
if (!request) {
|
||||
this.request = context;
|
||||
} else {
|
||||
if (request) {
|
||||
this.context = context;
|
||||
this.request = request;
|
||||
} else {
|
||||
this.context = null;
|
||||
this.request = context;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"PrefetchPlugin",
|
||||
|
|
|
@ -12,7 +12,14 @@ const {
|
|||
const NullFactory = require("./NullFactory");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
module.exports = class RequireJsStuffPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"RequireJsStuffPlugin",
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
const Module = require("./Module");
|
||||
|
||||
/** @typedef {import("./Compilation").PathData} PathData */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi,
|
||||
REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi,
|
||||
|
@ -131,6 +132,11 @@ const replacePathVariables = (path, data) => {
|
|||
};
|
||||
|
||||
class TemplatedPathPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("TemplatedPathPlugin", compilation => {
|
||||
const mainTemplate = compilation.mainTemplate;
|
||||
|
|
|
@ -11,7 +11,7 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|||
|
||||
class UseStrictPlugin {
|
||||
/**
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
|
|
|
@ -7,7 +7,14 @@
|
|||
|
||||
const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class WarnCaseSensitiveModulesPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"WarnCaseSensitiveModulesPlugin",
|
||||
|
|
|
@ -7,13 +7,26 @@
|
|||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class WarnDeprecatedOptionPlugin {
|
||||
/**
|
||||
* Create an instance of the plugin
|
||||
* @param {string} option the target option
|
||||
* @param {string | number} value the deprecated option value
|
||||
* @param {string} suggestion the suggestion replacement
|
||||
*/
|
||||
constructor(option, value, suggestion) {
|
||||
this.option = option;
|
||||
this.value = value;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap(
|
||||
"WarnDeprecatedOptionPlugin",
|
||||
|
|
|
@ -7,7 +7,14 @@
|
|||
|
||||
const NoModeWarning = require("./NoModeWarning");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class WarnNoModeSetPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap("WarnNoModeSetPlugin", compilation => {
|
||||
compilation.warnings.push(new NoModeWarning());
|
||||
|
|
Loading…
Reference in New Issue