Skip to content

Commit bc25829

Browse files
fix: a lot of types (#19486)
1 parent ea3ba3d commit bc25829

File tree

152 files changed

+1703
-520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+1703
-520
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ test/**/*.*
66
!test/*.cjs
77
!test/*.mjs
88
!test/**/webpack.config.js
9+
!test/**/webpack.config.cjs
10+
!test/**/webpack.config.mjs
911
!test/**/test.config.js
1012
!test/**/test.filter.js
1113
!test/**/errors.js
@@ -15,7 +17,6 @@ test/**/*.*
1517
!test/*.md
1618
!test/helpers/*.*
1719
!test/benchmarkCases/**/*.mjs
18-
!test/_helpers/**/*.mjs
1920
test/js/**/*.*
2021

2122
# Ignore some folders

declarations.test.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
declare module "*.json";
22

3+
type Env = Record<string, any>;
4+
type TestOptions = { testPath: string, srcPath: string };
5+
36
declare namespace jest {
47
interface Matchers<R> {
58
toBeTypeOf: (

declarations/LoaderContext.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ type AdditionalData = {
245245
};
246246

247247
type WebpackLoaderContextCallback = (
248-
err: Error | undefined | null,
248+
err: undefined | null | Error,
249249
content?: string | Buffer,
250-
sourceMap?: string | SourceMap,
250+
sourceMap?: null | string | SourceMap,
251251
additionalData?: AdditionalData
252252
) => void;
253253

declarations/WebpackOptions.d.ts

Lines changed: 206 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,26 @@ export type ExternalItem =
187187
| RegExp
188188
| string
189189
| (ExternalItemObjectKnown & ExternalItemObjectUnknown)
190-
| (
191-
| ((
192-
data: ExternalItemFunctionData,
193-
callback: (err?: Error | null, result?: ExternalItemValue) => void
194-
) => void)
195-
| ((data: ExternalItemFunctionData) => Promise<ExternalItemValue>)
196-
);
190+
| ExternalItemFunction;
191+
/**
192+
* The function is called on each dependency.
193+
*/
194+
export type ExternalItemFunction =
195+
| ExternalItemFunctionCallback
196+
| ExternalItemFunctionPromise;
197+
/**
198+
* The function is called on each dependency (`function(context, request, callback(err, result))`).
199+
*/
200+
export type ExternalItemFunctionCallback = (
201+
data: ExternalItemFunctionData,
202+
callback: (err?: Error | null, result?: ExternalItemValue) => void
203+
) => void;
204+
/**
205+
* The function is called on each dependency (`function(context, request)`).
206+
*/
207+
export type ExternalItemFunctionPromise = (
208+
data: ExternalItemFunctionData
209+
) => Promise<ExternalItemValue>;
197210
/**
198211
* Specifies the default type of externals ('amd*', 'umd*', 'system' and 'jsonp' depend on output.libraryTarget set to the same value).
199212
*/
@@ -349,13 +362,7 @@ export type ResolvePluginInstance =
349362
*/
350363
export type RuleSetUse =
351364
| (Falsy | RuleSetUseItem)[]
352-
| ((data: {
353-
resource: string;
354-
realResource: string;
355-
resourceQuery: string;
356-
issuer: string;
357-
compiler: string;
358-
}) => (Falsy | RuleSetUseItem)[])
365+
| RuleSetUseFunction
359366
| RuleSetUseItem;
360367
/**
361368
* A description of an applied loader.
@@ -375,8 +382,14 @@ export type RuleSetUseItem =
375382
*/
376383
options?: RuleSetLoaderOptions;
377384
}
378-
| ((data: object) => RuleSetUseItem | (Falsy | RuleSetUseItem)[])
385+
| RuleSetUseFunction
379386
| RuleSetLoader;
387+
/**
388+
* The function is called on each data and return rule set item.
389+
*/
390+
export type RuleSetUseFunction = (
391+
data: import("../lib/rules/RuleSetCompiler").EffectData
392+
) => RuleSetUseItem | (Falsy | RuleSetUseItem)[];
380393
/**
381394
* A list of rules.
382395
*/
@@ -390,10 +403,10 @@ export type GeneratorOptionsByModuleType = GeneratorOptionsByModuleTypeKnown &
390403
* Don't parse files matching. It's matched against the full resolved request.
391404
*/
392405
export type NoParse =
393-
| (RegExp | string | Function)[]
406+
| (RegExp | string | ((content: string) => boolean))[]
394407
| RegExp
395408
| string
396-
| Function;
409+
| ((content: string) => boolean);
397410
/**
398411
* Specify options for each parser.
399412
*/
@@ -424,8 +437,19 @@ export type OptimizationRuntimeChunk =
424437
/**
425438
* The name or name factory for the runtime chunks.
426439
*/
427-
name?: string | Function;
440+
name?:
441+
| string
442+
| import("../lib/optimize/RuntimeChunkPlugin").RuntimeChunkFunction;
428443
};
444+
/**
445+
* A function returning cache groups.
446+
*/
447+
export type OptimizationSplitChunksGetCacheGroups = (
448+
module: import("../lib/Module")
449+
) =>
450+
| OptimizationSplitChunksCacheGroup
451+
| OptimizationSplitChunksCacheGroup[]
452+
| void;
429453
/**
430454
* Size description for limits.
431455
*/
@@ -794,6 +818,33 @@ export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
794818
*/
795819
export type ExperimentsNormalized = ExperimentsCommon &
796820
ExperimentsNormalizedExtra;
821+
/**
822+
* Get a resolve function with the current resolver options.
823+
*/
824+
export type ExternalItemFunctionDataGetResolve = (
825+
options?: ResolveOptions
826+
) =>
827+
| ExternalItemFunctionDataGetResolveCallbackResult
828+
| ExternalItemFunctionDataGetResolveResult;
829+
/**
830+
* Result of get a resolve function with the current resolver options.
831+
*/
832+
export type ExternalItemFunctionDataGetResolveCallbackResult = (
833+
context: string,
834+
request: string,
835+
callback: (
836+
err?: Error | null,
837+
result?: string | false,
838+
resolveRequest?: import("enhanced-resolve").ResolveRequest
839+
) => void
840+
) => void;
841+
/**
842+
* Callback result of get a resolve function with the current resolver options.
843+
*/
844+
export type ExternalItemFunctionDataGetResolveResult = (
845+
context: string,
846+
request: string
847+
) => Promise<string>;
797848
/**
798849
* The dependency used for the external.
799850
*/
@@ -832,17 +883,8 @@ export type OptimizationRuntimeChunkNormalized =
832883
/**
833884
* The name factory for the runtime chunks.
834885
*/
835-
name?: Function;
886+
name?: import("../lib/optimize/RuntimeChunkPlugin").RuntimeChunkFunction;
836887
};
837-
/**
838-
* A function returning cache groups.
839-
*/
840-
export type OptimizationSplitChunksGetCacheGroups = (
841-
module: import("../lib/Module")
842-
) =>
843-
| OptimizationSplitChunksCacheGroup
844-
| OptimizationSplitChunksCacheGroup[]
845-
| void;
846888

847889
/**
848890
* Options object as provided by the user.
@@ -1368,7 +1410,7 @@ export interface ModuleOptions {
13681410
/**
13691411
* Cache the resolving of module requests.
13701412
*/
1371-
unsafeCache?: boolean | Function;
1413+
unsafeCache?: boolean | ((module: import("../lib/Module")) => boolean);
13721414
/**
13731415
* Enable warnings for partial dynamic dependencies. Deprecated: This option has moved to 'module.parser.javascript.wrappedContextCritical'.
13741416
*/
@@ -1835,7 +1877,7 @@ export interface OptimizationSplitChunksOptions {
18351877
| false
18361878
| RegExp
18371879
| string
1838-
| Function
1880+
| OptimizationSplitChunksGetCacheGroups
18391881
| OptimizationSplitChunksCacheGroup;
18401882
};
18411883
/**
@@ -2387,7 +2429,11 @@ export interface PerformanceOptions {
23872429
/**
23882430
* Filter function to select assets that are checked.
23892431
*/
2390-
assetFilter?: Function;
2432+
assetFilter?: (
2433+
name: import("../lib/Compilation").Asset["name"],
2434+
source: import("../lib/Compilation").Asset["source"],
2435+
assetInfo: import("../lib/Compilation").Asset["info"]
2436+
) => boolean;
23912437
/**
23922438
* Sets the format of the hints: warnings, errors or nothing at all.
23932439
*/
@@ -3178,19 +3224,7 @@ export interface ExternalItemFunctionData {
31783224
/**
31793225
* Get a resolve function with the current resolver options.
31803226
*/
3181-
getResolve?: (
3182-
options?: ResolveOptions
3183-
) =>
3184-
| ((
3185-
context: string,
3186-
request: string,
3187-
callback: (
3188-
err?: Error | null,
3189-
result?: string | false,
3190-
resolveRequest?: import("enhanced-resolve").ResolveRequest
3191-
) => void
3192-
) => void)
3193-
| ((context: string, request: string) => Promise<string>);
3227+
getResolve?: ExternalItemFunctionDataGetResolve;
31943228
/**
31953229
* The request as written by the user in the require/import expression/statement.
31963230
*/
@@ -3392,6 +3426,21 @@ export interface JsonGeneratorOptions {
33923426
*/
33933427
JSONParse?: boolean;
33943428
}
3429+
/**
3430+
* Parser options for JSON modules.
3431+
*/
3432+
export interface JsonParserOptions {
3433+
/**
3434+
* The depth of json dependency flagged as `exportInfo`.
3435+
*/
3436+
exportsDepth?: number;
3437+
/**
3438+
* Function to parser content and return JSON.
3439+
*/
3440+
parse?: (
3441+
input: string
3442+
) => Buffer | import("../lib/json/JsonParser").JsonValue;
3443+
}
33953444
/**
33963445
* Options for the default backend.
33973446
*/
@@ -3482,7 +3531,114 @@ export interface ModuleOptionsNormalized {
34823531
/**
34833532
* Cache the resolving of module requests.
34843533
*/
3485-
unsafeCache?: boolean | Function;
3534+
unsafeCache?: boolean | ((module: import("../lib/Module")) => boolean);
3535+
}
3536+
/**
3537+
* Enables/Disables integrated optimizations.
3538+
*/
3539+
export interface OptimizationNormalized {
3540+
/**
3541+
* Avoid wrapping the entry module in an IIFE.
3542+
*/
3543+
avoidEntryIife?: boolean;
3544+
/**
3545+
* Check for incompatible wasm types when importing/exporting from/to ESM.
3546+
*/
3547+
checkWasmTypes?: boolean;
3548+
/**
3549+
* Define the algorithm to choose chunk ids (named: readable ids for better debugging, deterministic: numeric hash ids for better long term caching, size: numeric ids focused on minimal initial download size, total-size: numeric ids focused on minimal total download size, false: no algorithm used, as custom one can be provided via plugin).
3550+
*/
3551+
chunkIds?:
3552+
| "natural"
3553+
| "named"
3554+
| "deterministic"
3555+
| "size"
3556+
| "total-size"
3557+
| false;
3558+
/**
3559+
* Concatenate modules when possible to generate less modules, more efficient code and enable more optimizations by the minimizer.
3560+
*/
3561+
concatenateModules?: boolean;
3562+
/**
3563+
* Emit assets even when errors occur. Critical errors are emitted into the generated code and will cause errors at runtime.
3564+
*/
3565+
emitOnErrors?: boolean;
3566+
/**
3567+
* Also flag chunks as loaded which contain a subset of the modules.
3568+
*/
3569+
flagIncludedChunks?: boolean;
3570+
/**
3571+
* Creates a module-internal dependency graph for top level symbols, exports and imports, to improve unused exports detection.
3572+
*/
3573+
innerGraph?: boolean;
3574+
/**
3575+
* Rename exports when possible to generate shorter code (depends on optimization.usedExports and optimization.providedExports, true/"deterministic": generate short deterministic names optimized for caching, "size": generate the shortest possible names).
3576+
*/
3577+
mangleExports?: ("size" | "deterministic") | boolean;
3578+
/**
3579+
* Reduce size of WASM by changing imports to shorter strings.
3580+
*/
3581+
mangleWasmImports?: boolean;
3582+
/**
3583+
* Merge chunks which contain the same modules.
3584+
*/
3585+
mergeDuplicateChunks?: boolean;
3586+
/**
3587+
* Enable minimizing the output. Uses optimization.minimizer.
3588+
*/
3589+
minimize?: boolean;
3590+
/**
3591+
* Minimizer(s) to use for minimizing the output.
3592+
*/
3593+
minimizer?: ("..." | Falsy | WebpackPluginInstance | WebpackPluginFunction)[];
3594+
/**
3595+
* Define the algorithm to choose module ids (natural: numeric ids in order of usage, named: readable ids for better debugging, hashed: (deprecated) short hashes as ids for better long term caching, deterministic: numeric hash ids for better long term caching, size: numeric ids focused on minimal initial download size, false: no algorithm used, as custom one can be provided via plugin).
3596+
*/
3597+
moduleIds?: "natural" | "named" | "hashed" | "deterministic" | "size" | false;
3598+
/**
3599+
* Avoid emitting assets when errors occur (deprecated: use 'emitOnErrors' instead).
3600+
*/
3601+
noEmitOnErrors?: boolean;
3602+
/**
3603+
* Set process.env.NODE_ENV to a specific value.
3604+
*/
3605+
nodeEnv?: false | string;
3606+
/**
3607+
* Generate records with relative paths to be able to move the context folder.
3608+
*/
3609+
portableRecords?: boolean;
3610+
/**
3611+
* Figure out which exports are provided by modules to generate more efficient code.
3612+
*/
3613+
providedExports?: boolean;
3614+
/**
3615+
* Use real [contenthash] based on final content of the assets.
3616+
*/
3617+
realContentHash?: boolean;
3618+
/**
3619+
* Removes modules from chunks when these modules are already included in all parents.
3620+
*/
3621+
removeAvailableModules?: boolean;
3622+
/**
3623+
* Remove chunks which are empty.
3624+
*/
3625+
removeEmptyChunks?: boolean;
3626+
/**
3627+
* Create an additional chunk which contains only the webpack runtime and chunk hash maps.
3628+
*/
3629+
runtimeChunk?: OptimizationRuntimeChunkNormalized;
3630+
/**
3631+
* Skip over modules which contain no side effects when exports are not used (false: disabled, 'flag': only use manually placed side effects flag, true: also analyse source code for side effects).
3632+
*/
3633+
sideEffects?: "flag" | boolean;
3634+
/**
3635+
* Optimize duplication and caching by splitting chunks by shared modules and cache group.
3636+
*/
3637+
splitChunks?: false | OptimizationSplitChunksOptions;
3638+
/**
3639+
* Figure out which exports are used by modules to mangle export names, omit unused exports and generate more efficient code (true: analyse used exports for each runtime, "global": analyse exports globally for all runtimes combined).
3640+
*/
3641+
usedExports?: "global" | boolean;
34863642
}
34873643
/**
34883644
* Normalized options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.
@@ -3772,7 +3928,7 @@ export interface WebpackOptionsNormalized {
37723928
/**
37733929
* Enables/Disables integrated optimizations.
37743930
*/
3775-
optimization: Optimization;
3931+
optimization: OptimizationNormalized;
37763932
/**
37773933
* Normalized options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.
37783934
*/
@@ -3999,6 +4155,10 @@ export interface ParserOptionsByModuleTypeKnown {
39994155
* Parser options for javascript modules.
40004156
*/
40014157
"javascript/esm"?: JavascriptParserOptions;
4158+
/**
4159+
* Parser options for JSON modules.
4160+
*/
4161+
json?: JsonParserOptions;
40024162
}
40034163
/**
40044164
* Specify options for each parser.

0 commit comments

Comments
 (0)