use declarations from schemas in plugins
This commit is contained in:
parent
a91f7366dc
commit
1f6b92de3e
|
@ -12,6 +12,9 @@ const Template = require("./Template");
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/BannerPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
|
||||
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
|
||||
|
||||
const wrapComment = str => {
|
||||
if (!str.includes("\n")) {
|
||||
return Template.toComment(str);
|
||||
|
@ -23,6 +26,9 @@ const wrapComment = str => {
|
|||
};
|
||||
|
||||
class BannerPlugin {
|
||||
/**
|
||||
* @param {BannerPluginArgument} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
if (arguments.length > 1) {
|
||||
throw new Error(
|
||||
|
@ -38,17 +44,19 @@ class BannerPlugin {
|
|||
};
|
||||
}
|
||||
|
||||
this.options = options || {};
|
||||
/** @type {BannerPluginOptions} */
|
||||
this.options = options;
|
||||
|
||||
if (typeof options.banner === "function") {
|
||||
const getBanner = this.options.banner;
|
||||
const bannerOption = options.banner;
|
||||
if (typeof bannerOption === "function") {
|
||||
const getBanner = bannerOption;
|
||||
this.banner = this.options.raw
|
||||
? getBanner
|
||||
: data => wrapComment(getBanner(data));
|
||||
} else {
|
||||
const banner = this.options.raw
|
||||
? this.options.banner
|
||||
: wrapComment(this.options.banner);
|
||||
? bannerOption
|
||||
: wrapComment(bannerOption);
|
||||
this.banner = () => banner;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,12 @@ const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/DllPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
|
||||
|
||||
class DllPlugin {
|
||||
/**
|
||||
* @param {DllPluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options, "Dll Plugin");
|
||||
this.options = options;
|
||||
|
|
|
@ -16,7 +16,12 @@ const WebpackError = require("./WebpackError");
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/DllReferencePlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
||||
|
||||
class DllReferencePlugin {
|
||||
/**
|
||||
* @param {DllReferencePluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options, "Dll Reference Plugin");
|
||||
this.options = options;
|
||||
|
|
|
@ -8,10 +8,18 @@ const createHash = require("./util/createHash");
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/HashedModuleIdsPlugin.json");
|
||||
|
||||
class HashedModuleIdsPlugin {
|
||||
constructor(options) {
|
||||
validateOptions(schema, options || {}, "Hashed Module Ids Plugin");
|
||||
/** @typedef {import("../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
||||
|
||||
class HashedModuleIdsPlugin {
|
||||
/**
|
||||
* @param {HashedModuleIdsPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
if (!options) options = {};
|
||||
|
||||
validateOptions(schema, options, "Hashed Module Ids Plugin");
|
||||
|
||||
/** @type {HashedModuleIdsPluginOptions} */
|
||||
this.options = Object.assign(
|
||||
{
|
||||
context: null,
|
||||
|
|
|
@ -7,15 +7,12 @@
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/IgnorePlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class IgnorePlugin {
|
||||
/**
|
||||
* @param {object} options IgnorePlugin options
|
||||
* @param {RegExp} options.resourceRegExp - A RegExp to test the request against
|
||||
* @param {RegExp} options.contextRegExp - A RegExp to test the context (directory) against
|
||||
* @param {function(string): boolean=} options.checkResource - A filter function for resource
|
||||
* @param {function(string): boolean=} options.checkContext - A filter function for context
|
||||
* @param {IgnorePluginOptions} options IgnorePlugin options
|
||||
*/
|
||||
constructor(options) {
|
||||
// TODO webpack 5 remove this compat-layer
|
||||
|
@ -39,13 +36,13 @@ class IgnorePlugin {
|
|||
* and the resource given matches the regexp.
|
||||
*/
|
||||
checkResource(resource) {
|
||||
if (this.options.checkResource) {
|
||||
if ("checkResource" in this.options && this.options.checkResource) {
|
||||
return this.options.checkResource(resource);
|
||||
}
|
||||
if (!this.options.resourceRegExp) {
|
||||
return false;
|
||||
if ("resourceRegExp" in this.options && this.options.resourceRegExp) {
|
||||
return this.options.resourceRegExp.test(resource);
|
||||
}
|
||||
return this.options.resourceRegExp.test(resource);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,14 +51,13 @@ class IgnorePlugin {
|
|||
* or if context matches the given regexp.
|
||||
*/
|
||||
checkContext(context) {
|
||||
if (this.options.checkContext) {
|
||||
if ("checkContext" in this.options && this.options.checkContext) {
|
||||
return this.options.checkContext(context);
|
||||
}
|
||||
|
||||
if (!this.options.contextRegExp) {
|
||||
return true;
|
||||
if ("contextRegExp" in this.options && this.options.contextRegExp) {
|
||||
return this.options.contextRegExp.test(context);
|
||||
}
|
||||
return this.options.contextRegExp.test(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,12 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/LoaderOptionsPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
|
||||
|
||||
class LoaderOptionsPlugin {
|
||||
/**
|
||||
* @param {LoaderOptionsPluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options || {}, "Loader Options Plugin");
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ const createHash = require("./util/createHash");
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/SourceMapDevToolPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
||||
|
||||
const basename = name => {
|
||||
if (!name.includes("/")) return name;
|
||||
return name.substr(name.lastIndexOf("/") + 1);
|
||||
|
@ -52,6 +54,9 @@ const getTaskForFile = (file, chunk, options, compilation) => {
|
|||
};
|
||||
|
||||
class SourceMapDevToolPlugin {
|
||||
/**
|
||||
* @param {SourceMapDevToolPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
if (arguments.length > 1) {
|
||||
throw new Error(
|
||||
|
@ -59,10 +64,12 @@ class SourceMapDevToolPlugin {
|
|||
);
|
||||
}
|
||||
|
||||
validateOptions(schema, options || {}, "SourceMap DevTool Plugin");
|
||||
|
||||
if (!options) options = {};
|
||||
|
||||
validateOptions(schema, options, "SourceMap DevTool Plugin");
|
||||
|
||||
this.sourceMapFilename = options.filename;
|
||||
/** @type {string | false} */
|
||||
this.sourceMappingURLComment =
|
||||
options.append === false
|
||||
? false
|
||||
|
@ -227,6 +234,7 @@ class SourceMapDevToolPlugin {
|
|||
sourceMap.sourceRoot = options.sourceRoot || "";
|
||||
sourceMap.file = file;
|
||||
assetsCache.set(asset, { file, assets });
|
||||
/** @type {string | false} */
|
||||
let currentSourceMappingURLComment = sourceMappingURLComment;
|
||||
if (
|
||||
currentSourceMappingURLComment !== false &&
|
||||
|
@ -276,6 +284,11 @@ class SourceMapDevToolPlugin {
|
|||
] = new RawSource(sourceMapString);
|
||||
chunk.files.push(sourceMapFile);
|
||||
} else {
|
||||
if (currentSourceMappingURLComment === false) {
|
||||
throw new Error(
|
||||
"SourceMapDevToolPlugin: append can't be false when no filename is provided"
|
||||
);
|
||||
}
|
||||
assets[file] = compilation.assets[file] = new ConcatSource(
|
||||
new RawSource(source),
|
||||
currentSourceMappingURLComment
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/WatchIgnorePlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
|
||||
|
||||
class IgnoringWatchFileSystem {
|
||||
constructor(wfs, paths) {
|
||||
this.wfs = wfs;
|
||||
|
@ -82,6 +84,9 @@ class IgnoringWatchFileSystem {
|
|||
}
|
||||
|
||||
class WatchIgnorePlugin {
|
||||
/**
|
||||
* @param {WatchIgnorePluginOptions} paths list of paths
|
||||
*/
|
||||
constructor(paths) {
|
||||
validateOptions(schema, paths, "Watch Ignore Plugin");
|
||||
this.paths = paths;
|
||||
|
|
|
@ -2,6 +2,9 @@ const fs = require("fs");
|
|||
const { Tracer } = require("chrome-trace-event");
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
|
||||
|
||||
/** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
|
||||
|
||||
let inspector = undefined;
|
||||
|
||||
try {
|
||||
|
@ -145,6 +148,9 @@ const createTrace = outputPath => {
|
|||
const pluginName = "ProfilingPlugin";
|
||||
|
||||
class ProfilingPlugin {
|
||||
/**
|
||||
* @param {ProfilingPluginOptions=} opts options object
|
||||
*/
|
||||
constructor(opts) {
|
||||
validateOptions(schema, opts || {}, "Profiling plugin");
|
||||
opts = opts || {};
|
||||
|
|
|
@ -9,6 +9,8 @@ const { intersect } = require("../util/SetHelpers");
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json");
|
||||
|
||||
/** @typedef {import("../../declarations/plugins/optimize/AggressiveSplittingPlugin").AggressiveSplittingPluginOptions} AggressiveSplittingPluginOptions */
|
||||
|
||||
const moveModuleBetween = (oldChunk, newChunk) => {
|
||||
return module => {
|
||||
oldChunk.moveModule(module, newChunk);
|
||||
|
@ -22,10 +24,15 @@ const isNotAEntryModule = entryModule => {
|
|||
};
|
||||
|
||||
class AggressiveSplittingPlugin {
|
||||
/**
|
||||
* @param {AggressiveSplittingPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options || {}, "Aggressive Splitting Plugin");
|
||||
if (!options) options = {};
|
||||
|
||||
this.options = options || {};
|
||||
validateOptions(schema, options, "Aggressive Splitting Plugin");
|
||||
|
||||
this.options = options;
|
||||
if (typeof this.options.minSize !== "number") {
|
||||
this.options.minSize = 30 * 1024;
|
||||
}
|
||||
|
|
|
@ -7,10 +7,17 @@
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../../schemas/plugins/optimize/LimitChunkCountPlugin.json");
|
||||
|
||||
/** @typedef {import("../../declarations/plugins/optimize/LimitChunkCountPlugin").LimitChunkCountPluginOptions} LimitChunkCountPluginOptions */
|
||||
|
||||
class LimitChunkCountPlugin {
|
||||
/**
|
||||
* @param {LimitChunkCountPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options || {}, "Limit Chunk Count Plugin");
|
||||
this.options = options || {};
|
||||
if (!options) options = {};
|
||||
|
||||
validateOptions(schema, options, "Limit Chunk Count Plugin");
|
||||
this.options = options;
|
||||
}
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
|
|
|
@ -7,7 +7,12 @@
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../../schemas/plugins/optimize/MinChunkSizePlugin.json");
|
||||
|
||||
/** @typedef {import("../../declarations/plugins/optimize/MinChunkSizePlugin").MinChunkSizePluginOptions} MinChunkSizePluginOptions */
|
||||
|
||||
class MinChunkSizePlugin {
|
||||
/**
|
||||
* @param {MinChunkSizePluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options, "Min Chunk Size Plugin");
|
||||
this.options = options;
|
||||
|
|
|
@ -7,7 +7,12 @@
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../../schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json");
|
||||
|
||||
/** @typedef {import("../../declarations/plugins/optimize/OccurrenceOrderChunkIdsPlugin").OccurrenceOrderChunkIdsPluginOptions} OccurrenceOrderChunkIdsPluginOptions */
|
||||
|
||||
class OccurrenceOrderChunkIdsPlugin {
|
||||
/**
|
||||
* @param {OccurrenceOrderChunkIdsPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
validateOptions(schema, options, "Occurrence Order Chunk Ids Plugin");
|
||||
this.options = options;
|
||||
|
|
|
@ -7,7 +7,12 @@
|
|||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../../schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json");
|
||||
|
||||
/** @typedef {import("../../declarations/plugins/optimize/OccurrenceOrderModuleIdsPlugin").OccurrenceOrderModuleIdsPluginOptions} OccurrenceOrderModuleIdsPluginOptions */
|
||||
|
||||
class OccurrenceOrderModuleIdsPlugin {
|
||||
/**
|
||||
* @param {OccurrenceOrderModuleIdsPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
validateOptions(schema, options, "Occurrence Order Module Ids Plugin");
|
||||
this.options = options;
|
||||
|
|
Loading…
Reference in New Issue