improve typings for loggingDebug and other filtering configuration options

This commit is contained in:
Tobias Koppers 2021-02-22 13:18:27 +01:00
parent 9b448c14d9
commit 0b4506b206
5 changed files with 279 additions and 28 deletions

View File

@ -623,6 +623,51 @@ export type StatsValue =
) )
| boolean | boolean
| StatsOptions; | StatsOptions;
/**
* Filtering modules.
*/
export type ModuleFilterTypes = ModuleFilterItemTypes[] | ModuleFilterItemTypes;
/**
* Filtering value, regexp or function.
*/
export type ModuleFilterItemTypes =
| RegExp
| string
| ((
name: string,
module: import("../lib/stats/DefaultStatsFactoryPlugin").StatsModule,
type: "module" | "chunk" | "root-of-chunk" | "nested"
) => boolean);
/**
* Filtering modules.
*/
export type AssetFilterTypes = AssetFilterItemTypes[] | AssetFilterItemTypes;
/**
* Filtering value, regexp or function.
*/
export type AssetFilterItemTypes =
| RegExp
| string
| ((
name: string,
asset: import("../lib/stats/DefaultStatsFactoryPlugin").StatsAsset
) => boolean);
/**
* Filtering warnings.
*/
export type WarningFilterTypes =
| WarningFilterItemTypes[]
| WarningFilterItemTypes;
/**
* Filtering value, regexp or function.
*/
export type WarningFilterItemTypes =
| RegExp
| string
| ((
warning: import("../lib/stats/DefaultStatsFactoryPlugin").StatsError,
value: string
) => boolean);
/** /**
* Environment to build for. An array of environments to build for all of them when possible. * Environment to build for. An array of environments to build for all of them when possible.
*/ */
@ -2292,15 +2337,15 @@ export interface StatsOptions {
/** /**
* Please use excludeModules instead. * Please use excludeModules instead.
*/ */
exclude?: boolean | FilterTypes; exclude?: boolean | ModuleFilterTypes;
/** /**
* Suppress assets that match the specified filters. Filters can be Strings, RegExps or Functions. * Suppress assets that match the specified filters. Filters can be Strings, RegExps or Functions.
*/ */
excludeAssets?: FilterTypes; excludeAssets?: AssetFilterTypes;
/** /**
* Suppress modules that match the specified filters. Filters can be Strings, RegExps, Booleans or Functions. * Suppress modules that match the specified filters. Filters can be Strings, RegExps, Booleans or Functions.
*/ */
excludeModules?: boolean | FilterTypes; excludeModules?: boolean | ModuleFilterTypes;
/** /**
* Group assets by how their are related to chunks. * Group assets by how their are related to chunks.
*/ */
@ -2460,7 +2505,7 @@ export interface StatsOptions {
/** /**
* Suppress listing warnings that match the specified filters (they will still be counted). Filters can be Strings, RegExps or Functions. * Suppress listing warnings that match the specified filters (they will still be counted). Filters can be Strings, RegExps or Functions.
*/ */
warningsFilter?: FilterTypes; warningsFilter?: WarningFilterTypes;
} }
/** /**
* Options for the watcher. * Options for the watcher.

View File

@ -99,6 +99,9 @@ const { isSourceEqual } = require("./util/source");
/** @typedef {import("./RuntimeModule")} RuntimeModule */ /** @typedef {import("./RuntimeModule")} RuntimeModule */
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */ /** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
/** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions */ /** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions */
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsError} StatsError */
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
/** @typedef {import("./util/Hash")} Hash */ /** @typedef {import("./util/Hash")} Hash */
/** @template T @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T> */ /** @template T @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T> */
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
@ -235,9 +238,9 @@ const { isSourceEqual } = require("./util/source");
* @property {boolean} groupAssetsByPath * @property {boolean} groupAssetsByPath
* @property {boolean} groupAssetsByExtension * @property {boolean} groupAssetsByExtension
* @property {number} assetsSpace * @property {number} assetsSpace
* @property {Function[]} excludeAssets * @property {((value: string, asset: StatsAsset) => boolean)[]} excludeAssets
* @property {Function[]} excludeModules * @property {((name: string, module: StatsModule, type: "module" | "chunk" | "root-of-chunk" | "nested") => boolean)[]} excludeModules
* @property {Function[]} warningsFilter * @property {((warning: StatsError, textValue: string) => boolean)[]} warningsFilter
* @property {boolean} cachedModules * @property {boolean} cachedModules
* @property {boolean} orphanModules * @property {boolean} orphanModules
* @property {boolean} dependentModules * @property {boolean} dependentModules
@ -257,7 +260,7 @@ const { isSourceEqual } = require("./util/source");
* @property {number} chunkModulesSpace * @property {number} chunkModulesSpace
* @property {number} nestedModulesSpace * @property {number} nestedModulesSpace
* @property {false|"none"|"error"|"warn"|"info"|"log"|"verbose"} logging * @property {false|"none"|"error"|"warn"|"info"|"log"|"verbose"} logging
* @property {Function[]} loggingDebug * @property {((value: string) => boolean)[]} loggingDebug
* @property {boolean} loggingTrace * @property {boolean} loggingTrace
* @property {any} _env * @property {any} _env
*/ */

View File

@ -1904,7 +1904,7 @@ const ASSETS_GROUPERS = {
} }
}; };
/** @type {function(string): Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */ /** @type {function("module" | "chunk" | "root-of-chunk" | "nested"): Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
const MODULES_GROUPERS = type => ({ const MODULES_GROUPERS = type => ({
_: (groupConfigs, context, options) => { _: (groupConfigs, context, options) => {
const groupByFlag = (name, type, exclude) => { const groupByFlag = (name, type, exclude) => {

View File

@ -13,6 +13,51 @@
} }
] ]
}, },
"AssetFilterItemTypes": {
"description": "Filtering value, regexp or function.",
"cli": {
"helper": true
},
"anyOf": [
{
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string",
"absolutePath": false
},
{
"instanceof": "Function",
"tsType": "((name: string, asset: import('../lib/stats/DefaultStatsFactoryPlugin').StatsAsset) => boolean)"
}
]
},
"AssetFilterTypes": {
"description": "Filtering modules.",
"cli": {
"helper": true
},
"anyOf": [
{
"type": "array",
"items": {
"description": "Rule to filter.",
"cli": {
"helper": true
},
"oneOf": [
{
"$ref": "#/definitions/AssetFilterItemTypes"
}
]
}
},
{
"$ref": "#/definitions/AssetFilterItemTypes"
}
]
},
"AssetGeneratorDataUrl": { "AssetGeneratorDataUrl": {
"description": "The options for data url generator.", "description": "The options for data url generator.",
"anyOf": [ "anyOf": [
@ -1498,6 +1543,51 @@
"description": "Enable production optimizations or development hints.", "description": "Enable production optimizations or development hints.",
"enum": ["development", "production", "none"] "enum": ["development", "production", "none"]
}, },
"ModuleFilterItemTypes": {
"description": "Filtering value, regexp or function.",
"cli": {
"helper": true
},
"anyOf": [
{
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string",
"absolutePath": false
},
{
"instanceof": "Function",
"tsType": "((name: string, module: import('../lib/stats/DefaultStatsFactoryPlugin').StatsModule, type: 'module' | 'chunk' | 'root-of-chunk' | 'nested') => boolean)"
}
]
},
"ModuleFilterTypes": {
"description": "Filtering modules.",
"cli": {
"helper": true
},
"anyOf": [
{
"type": "array",
"items": {
"description": "Rule to filter.",
"cli": {
"helper": true
},
"oneOf": [
{
"$ref": "#/definitions/ModuleFilterItemTypes"
}
]
}
},
{
"$ref": "#/definitions/ModuleFilterItemTypes"
}
]
},
"ModuleOptions": { "ModuleOptions": {
"description": "Options affecting the normal modules (`NormalModuleFactory`).", "description": "Options affecting the normal modules (`NormalModuleFactory`).",
"type": "object", "type": "object",
@ -3920,7 +4010,7 @@
"type": "boolean" "type": "boolean"
}, },
{ {
"$ref": "#/definitions/FilterTypes" "$ref": "#/definitions/ModuleFilterTypes"
} }
] ]
}, },
@ -3928,7 +4018,7 @@
"description": "Suppress assets that match the specified filters. Filters can be Strings, RegExps or Functions.", "description": "Suppress assets that match the specified filters. Filters can be Strings, RegExps or Functions.",
"oneOf": [ "oneOf": [
{ {
"$ref": "#/definitions/FilterTypes" "$ref": "#/definitions/AssetFilterTypes"
} }
] ]
}, },
@ -3939,7 +4029,7 @@
"type": "boolean" "type": "boolean"
}, },
{ {
"$ref": "#/definitions/FilterTypes" "$ref": "#/definitions/ModuleFilterTypes"
} }
] ]
}, },
@ -4127,7 +4217,7 @@
"description": "Suppress listing warnings that match the specified filters (they will still be counted). Filters can be Strings, RegExps or Functions.", "description": "Suppress listing warnings that match the specified filters (they will still be counted). Filters can be Strings, RegExps or Functions.",
"oneOf": [ "oneOf": [
{ {
"$ref": "#/definitions/FilterTypes" "$ref": "#/definitions/WarningFilterTypes"
} }
] ]
} }
@ -4190,6 +4280,51 @@
"type": "string", "type": "string",
"minLength": 1 "minLength": 1
}, },
"WarningFilterItemTypes": {
"description": "Filtering value, regexp or function.",
"cli": {
"helper": true
},
"anyOf": [
{
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string",
"absolutePath": false
},
{
"instanceof": "Function",
"tsType": "((warning: import('../lib/stats/DefaultStatsFactoryPlugin').StatsError, value: string) => boolean)"
}
]
},
"WarningFilterTypes": {
"description": "Filtering warnings.",
"cli": {
"helper": true
},
"anyOf": [
{
"type": "array",
"items": {
"description": "Rule to filter.",
"cli": {
"helper": true
},
"oneOf": [
{
"$ref": "#/definitions/WarningFilterItemTypes"
}
]
}
},
{
"$ref": "#/definitions/WarningFilterItemTypes"
}
]
},
"WasmLoading": { "WasmLoading": {
"description": "The method of loading WebAssembly Modules (methods included by default are 'fetch' (web/WebWorker), 'async-node' (node.js), but others might be added by plugins).", "description": "The method of loading WebAssembly Modules (methods included by default are 'fetch' (web/WebWorker), 'async-node' (node.js), but others might be added by plugins).",
"anyOf": [ "anyOf": [

98
types.d.ts vendored
View File

@ -232,6 +232,10 @@ declare interface AssetEmittedInfo {
outputPath: string; outputPath: string;
targetPath: string; targetPath: string;
} }
type AssetFilterItemTypes =
| string
| RegExp
| ((name: string, asset: StatsAsset) => boolean);
/** /**
* Options object for data url generation. * Options object for data url generation.
@ -5051,9 +5055,13 @@ declare interface KnownNormalizedStatsOptions {
groupAssetsByPath: boolean; groupAssetsByPath: boolean;
groupAssetsByExtension: boolean; groupAssetsByExtension: boolean;
assetsSpace: number; assetsSpace: number;
excludeAssets: Function[]; excludeAssets: ((value: string, asset: StatsAsset) => boolean)[];
excludeModules: Function[]; excludeModules: ((
warningsFilter: Function[]; name: string,
module: StatsModule,
type: "module" | "chunk" | "root-of-chunk" | "nested"
) => boolean)[];
warningsFilter: ((warning: StatsError, textValue: string) => boolean)[];
cachedModules: boolean; cachedModules: boolean;
orphanModules: boolean; orphanModules: boolean;
dependentModules: boolean; dependentModules: boolean;
@ -5073,7 +5081,7 @@ declare interface KnownNormalizedStatsOptions {
chunkModulesSpace: number; chunkModulesSpace: number;
nestedModulesSpace: number; nestedModulesSpace: number;
logging: false | "none" | "verbose" | "error" | "warn" | "info" | "log"; logging: false | "none" | "verbose" | "error" | "warn" | "info" | "log";
loggingDebug: Function[]; loggingDebug: ((value: string) => boolean)[];
loggingTrace: boolean; loggingTrace: boolean;
} }
declare interface KnownStatsAsset { declare interface KnownStatsAsset {
@ -5910,6 +5918,14 @@ declare interface ModuleFederationPluginOptions {
*/ */
shared?: (string | SharedObject)[] | SharedObject; shared?: (string | SharedObject)[] | SharedObject;
} }
type ModuleFilterItemTypes =
| string
| RegExp
| ((
name: string,
module: StatsModule,
type: "module" | "chunk" | "root-of-chunk" | "nested"
) => boolean);
declare class ModuleGraph { declare class ModuleGraph {
constructor(); constructor();
setParents( setParents(
@ -6636,7 +6652,47 @@ declare class NormalModuleReplacementPlugin {
apply(compiler: Compiler): void; apply(compiler: Compiler): void;
} }
type NormalizedStatsOptions = KnownNormalizedStatsOptions & type NormalizedStatsOptions = KnownNormalizedStatsOptions &
StatsOptions & Omit<
StatsOptions,
| "context"
| "requestShortener"
| "chunkGroups"
| "chunksSort"
| "modulesSort"
| "chunkModulesSort"
| "nestedModulesSort"
| "assetsSort"
| "ids"
| "cachedAssets"
| "groupAssetsByEmitStatus"
| "groupAssetsByPath"
| "groupAssetsByExtension"
| "assetsSpace"
| "excludeAssets"
| "excludeModules"
| "warningsFilter"
| "cachedModules"
| "orphanModules"
| "dependentModules"
| "runtimeModules"
| "groupModulesByCacheStatus"
| "groupModulesByLayer"
| "groupModulesByAttributes"
| "groupModulesByPath"
| "groupModulesByExtension"
| "groupModulesByType"
| "entrypoints"
| "chunkGroupAuxiliary"
| "chunkGroupChildren"
| "chunkGroupMaxAssets"
| "modulesSpace"
| "chunkModulesSpace"
| "nestedModulesSpace"
| "logging"
| "loggingDebug"
| "loggingTrace"
| "_env"
> &
Record<string, any>; Record<string, any>;
declare interface ObjectDeserializerContext { declare interface ObjectDeserializerContext {
read: () => any; read: () => any;
@ -6830,7 +6886,7 @@ declare interface OptimizationSplitChunksCacheGroup {
/** /**
* Select chunks for determining cache group content (defaults to "initial", "initial" and "all" requires adding these chunks to the HTML). * Select chunks for determining cache group content (defaults to "initial", "initial" and "all" requires adding these chunks to the HTML).
*/ */
chunks?: "initial" | "async" | "all" | ((chunk: Chunk) => boolean); chunks?: "all" | "initial" | "async" | ((chunk: Chunk) => boolean);
/** /**
* Ignore minimum size, minimum chunks and maximum requests and always create chunks for this cache group. * Ignore minimum size, minimum chunks and maximum requests and always create chunks for this cache group.
@ -6952,7 +7008,7 @@ declare interface OptimizationSplitChunksOptions {
/** /**
* Select chunks for determining shared modules (defaults to "async", "initial" and "all" requires adding these chunks to the HTML). * Select chunks for determining shared modules (defaults to "async", "initial" and "all" requires adding these chunks to the HTML).
*/ */
chunks?: "initial" | "async" | "all" | ((chunk: Chunk) => boolean); chunks?: "all" | "initial" | "async" | ((chunk: Chunk) => boolean);
/** /**
* Sets the size types which are used when a number is used for sizes. * Sets the size types which are used when a number is used for sizes.
@ -10155,8 +10211,12 @@ declare interface StatsOptions {
| string | string
| boolean | boolean
| RegExp | RegExp
| FilterItemTypes[] | ModuleFilterItemTypes[]
| ((value: string) => boolean); | ((
name: string,
module: StatsModule,
type: "module" | "chunk" | "root-of-chunk" | "nested"
) => boolean);
/** /**
* Suppress assets that match the specified filters. Filters can be Strings, RegExps or Functions. * Suppress assets that match the specified filters. Filters can be Strings, RegExps or Functions.
@ -10164,8 +10224,8 @@ declare interface StatsOptions {
excludeAssets?: excludeAssets?:
| string | string
| RegExp | RegExp
| FilterItemTypes[] | AssetFilterItemTypes[]
| ((value: string) => boolean); | ((name: string, asset: StatsAsset) => boolean);
/** /**
* Suppress modules that match the specified filters. Filters can be Strings, RegExps, Booleans or Functions. * Suppress modules that match the specified filters. Filters can be Strings, RegExps, Booleans or Functions.
@ -10174,8 +10234,12 @@ declare interface StatsOptions {
| string | string
| boolean | boolean
| RegExp | RegExp
| FilterItemTypes[] | ModuleFilterItemTypes[]
| ((value: string) => boolean); | ((
name: string,
module: StatsModule,
type: "module" | "chunk" | "root-of-chunk" | "nested"
) => boolean);
/** /**
* Group assets by how their are related to chunks. * Group assets by how their are related to chunks.
@ -10383,8 +10447,8 @@ declare interface StatsOptions {
warningsFilter?: warningsFilter?:
| string | string
| RegExp | RegExp
| FilterItemTypes[] | WarningFilterItemTypes[]
| ((value: string) => boolean); | ((warning: StatsError, value: string) => boolean);
} }
declare abstract class StatsPrinter { declare abstract class StatsPrinter {
hooks: Readonly<{ hooks: Readonly<{
@ -10627,6 +10691,10 @@ declare interface VariableInfoInterface {
freeName: string | true; freeName: string | true;
tagInfo?: TagInfo; tagInfo?: TagInfo;
} }
type WarningFilterItemTypes =
| string
| RegExp
| ((warning: StatsError, value: string) => boolean);
declare interface WatchFileSystem { declare interface WatchFileSystem {
watch: ( watch: (
files: Iterable<string>, files: Iterable<string>,