Skip to content

Commit 987f30e

Browse files
refactor: update types
1 parent 2fdca19 commit 987f30e

File tree

4 files changed

+257
-138
lines changed

4 files changed

+257
-138
lines changed

types/hmr/hotModuleReplacement.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare namespace _exports {
22
export { TODO };
33
}
4-
declare function _exports(moduleId: TODO, options: TODO): TODO;
4+
declare function _exports(moduleId: number | string, options: TODO): TODO;
55
export = _exports;
66
type TODO = any;

types/index.d.ts

Lines changed: 161 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export = MiniCssExtractPlugin;
22
declare class MiniCssExtractPlugin {
33
/**
4-
* @param {Compiler["webpack"]} webpack
5-
* @returns {CssModuleConstructor}
4+
* @param {Compiler["webpack"]} webpack webpack
5+
* @returns {CssModuleConstructor} CSS module constructor
66
*/
77
static getCssModule(webpack: Compiler["webpack"]): CssModuleConstructor;
88
/**
9-
* @param {Compiler["webpack"]} webpack
10-
* @returns {CssDependencyConstructor}
9+
* @param {Compiler["webpack"]} webpack webpack
10+
* @returns {CssDependencyConstructor} CSS dependency constructor
1111
*/
1212
static getCssDependency(
1313
webpack: Compiler["webpack"],
@@ -21,13 +21,12 @@ declare class MiniCssExtractPlugin {
2121
compilation: Compilation,
2222
): MiniCssExtractPluginCompilationHooks;
2323
/**
24-
* @param {PluginOptions} [options]
24+
* @param {PluginOptions=} options options
2525
*/
26-
constructor(options?: PluginOptions);
26+
constructor(options?: PluginOptions | undefined);
2727
/**
2828
* @private
2929
* @type {WeakMap<Chunk, Set<CssModule>>}
30-
* @private
3130
*/
3231
private _sortedModulesCache;
3332
/**
@@ -41,35 +40,35 @@ declare class MiniCssExtractPlugin {
4140
*/
4241
private runtimeOptions;
4342
/**
44-
* @param {Compiler} compiler
43+
* @param {Compiler} compiler compiler
4544
*/
4645
apply(compiler: Compiler): void;
4746
/**
4847
* @private
49-
* @param {Chunk} chunk
50-
* @param {ChunkGraph} chunkGraph
51-
* @returns {Iterable<Module>}
48+
* @param {Chunk} chunk chunk
49+
* @param {ChunkGraph} chunkGraph chunk graph
50+
* @returns {Iterable<Module>} modules
5251
*/
5352
private getChunkModules;
5453
/**
5554
* @private
56-
* @param {Compilation} compilation
57-
* @param {Chunk} chunk
58-
* @param {CssModule[]} modules
59-
* @param {Compilation["requestShortener"]} requestShortener
60-
* @returns {Set<CssModule>}
55+
* @param {Compilation} compilation compilation
56+
* @param {Chunk} chunk chunk
57+
* @param {CssModule[]} modules modules
58+
* @param {Compilation["requestShortener"]} requestShortener request shortener
59+
* @returns {Set<CssModule>} css modules
6160
*/
6261
private sortModules;
6362
/**
6463
* @private
65-
* @param {Compiler} compiler
66-
* @param {Compilation} compilation
67-
* @param {Chunk} chunk
68-
* @param {CssModule[]} modules
69-
* @param {Compiler["requestShortener"]} requestShortener
70-
* @param {string} filenameTemplate
71-
* @param {Parameters<Exclude<Required<Configuration>['output']['filename'], string | undefined>>[0]} pathData
72-
* @returns {Source}
64+
* @param {Compiler} compiler compiler
65+
* @param {Compilation} compilation compilation
66+
* @param {Chunk} chunk chunk
67+
* @param {CssModule[]} modules modules
68+
* @param {Compiler["requestShortener"]} requestShortener request shortener
69+
* @param {string} filenameTemplate filename template
70+
* @param {Parameters<Exclude<Required<Configuration>['output']['filename'], string | undefined>>[0]} pathData path data
71+
* @returns {Source} source
7372
*/
7473
private renderContentAsset;
7574
}
@@ -120,40 +119,40 @@ declare namespace MiniCssExtractPlugin {
120119
/** @typedef {import("webpack").AssetInfo} AssetInfo */
121120
/** @typedef {import("./loader.js").Dependency} LoaderDependency */
122121
/**
123-
* @typedef {Object} LoaderOptions
124-
* @property {string | ((resourcePath: string, rootContext: string) => string)} [publicPath]
125-
* @property {boolean} [emit]
126-
* @property {boolean} [esModule]
127-
* @property {string} [layer]
128-
* @property {boolean} [defaultExport]
122+
* @typedef {object} LoaderOptions
123+
* @property {string | ((resourcePath: string, rootContext: string) => string)=} publicPath public path
124+
* @property {boolean=} emit true when need to emit, otherwise false
125+
* @property {boolean=} esModule need to generate ES module syntax
126+
* @property {string=} layer a layer
127+
* @property {boolean=} defaultExport true when need to use default export, otherwise false
129128
*/
130129
/**
131-
* @typedef {Object} PluginOptions
132-
* @property {Required<Configuration>['output']['filename']} [filename]
133-
* @property {Required<Configuration>['output']['chunkFilename']} [chunkFilename]
134-
* @property {boolean} [ignoreOrder]
135-
* @property {string | ((linkTag: HTMLLinkElement) => void)} [insert]
136-
* @property {Record<string, string>} [attributes]
137-
* @property {string | false | 'text/css'} [linkType]
138-
* @property {boolean} [runtime]
139-
* @property {boolean} [experimentalUseImportModule]
130+
* @typedef {object} PluginOptions
131+
* @property {Required<Configuration>['output']['filename']=} filename filename
132+
* @property {Required<Configuration>['output']['chunkFilename']=} chunkFilename chunk filename
133+
* @property {boolean=} ignoreOrder true when need to ignore order, otherwise false
134+
* @property {string | ((linkTag: HTMLLinkElement) => void)=} insert link insert place or a custom insert function
135+
* @property {Record<string, string>=} attributes link attributes
136+
* @property {string | false | 'text/css'=} linkType value of a link type attribute
137+
* @property {boolean=} runtime true when need to generate runtime code, otherwise false
138+
* @property {boolean=} experimentalUseImportModule true when need to use `experimentalUseImportModule` API, otherwise false
140139
*/
141140
/**
142-
* @typedef {Object} NormalizedPluginOptions
143-
* @property {Required<Configuration>['output']['filename']} filename
144-
* @property {Required<Configuration>['output']['chunkFilename']} [chunkFilename]
145-
* @property {boolean} ignoreOrder
146-
* @property {string | ((linkTag: HTMLLinkElement) => void)} [insert]
147-
* @property {Record<string, string>} [attributes]
148-
* @property {string | false | 'text/css'} [linkType]
149-
* @property {boolean} runtime
150-
* @property {boolean} [experimentalUseImportModule]
141+
* @typedef {object} NormalizedPluginOptions
142+
* @property {Required<Configuration>['output']['filename']} filename filename
143+
* @property {Required<Configuration>['output']['chunkFilename']=} chunkFilename chunk filename
144+
* @property {boolean} ignoreOrder true when need to ignore order, otherwise false
145+
* @property {string | ((linkTag: HTMLLinkElement) => void)=} insert a link insert place or a custom insert function
146+
* @property {Record<string, string>=} attributes link attributes
147+
* @property {string | false | 'text/css'=} linkType value of a link type attribute
148+
* @property {boolean} runtime true when need to generate runtime code, otherwise false
149+
* @property {boolean=} experimentalUseImportModule true when need to use `experimentalUseImportModule` API, otherwise false
151150
*/
152151
/**
153-
* @typedef {Object} RuntimeOptions
154-
* @property {string | ((linkTag: HTMLLinkElement) => void) | undefined} insert
155-
* @property {string | false | 'text/css'} linkType
156-
* @property {Record<string, string> | undefined} attributes
152+
* @typedef {object} RuntimeOptions
153+
* @property {string | ((linkTag: HTMLLinkElement) => void)=} insert a link insert place or a custom insert function
154+
* @property {string | false | 'text/css'} linkType value of a link type attribute
155+
* @property {Record<string, string>=} attributes link attributes
157156
*/
158157
/** @typedef {any} TODO */
159158
declare const pluginName: "mini-css-extract-plugin";
@@ -173,39 +172,114 @@ type WebpackError = import("webpack").WebpackError;
173172
type AssetInfo = import("webpack").AssetInfo;
174173
type LoaderDependency = import("./loader.js").Dependency;
175174
type LoaderOptions = {
175+
/**
176+
* public path
177+
*/
176178
publicPath?:
177-
| string
178-
| ((resourcePath: string, rootContext: string) => string)
179+
| (string | ((resourcePath: string, rootContext: string) => string))
179180
| undefined;
181+
/**
182+
* true when need to emit, otherwise false
183+
*/
180184
emit?: boolean | undefined;
185+
/**
186+
* need to generate ES module syntax
187+
*/
181188
esModule?: boolean | undefined;
189+
/**
190+
* a layer
191+
*/
182192
layer?: string | undefined;
193+
/**
194+
* true when need to use default export, otherwise false
195+
*/
183196
defaultExport?: boolean | undefined;
184197
};
185198
type PluginOptions = {
186-
filename?: Required<Configuration>["output"]["filename"];
187-
chunkFilename?: Required<Configuration>["output"]["chunkFilename"];
199+
/**
200+
* filename
201+
*/
202+
filename?: Required<Configuration>["output"]["filename"] | undefined;
203+
/**
204+
* chunk filename
205+
*/
206+
chunkFilename?:
207+
| Required<Configuration>["output"]["chunkFilename"]
208+
| undefined;
209+
/**
210+
* true when need to ignore order, otherwise false
211+
*/
188212
ignoreOrder?: boolean | undefined;
189-
insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined;
213+
/**
214+
* link insert place or a custom insert function
215+
*/
216+
insert?: (string | ((linkTag: HTMLLinkElement) => void)) | undefined;
217+
/**
218+
* link attributes
219+
*/
190220
attributes?: Record<string, string> | undefined;
191-
linkType?: string | false | undefined;
221+
/**
222+
* value of a link type attribute
223+
*/
224+
linkType?: (string | false | "text/css") | undefined;
225+
/**
226+
* true when need to generate runtime code, otherwise false
227+
*/
192228
runtime?: boolean | undefined;
229+
/**
230+
* true when need to use `experimentalUseImportModule` API, otherwise false
231+
*/
193232
experimentalUseImportModule?: boolean | undefined;
194233
};
195234
type NormalizedPluginOptions = {
235+
/**
236+
* filename
237+
*/
196238
filename: Required<Configuration>["output"]["filename"];
197-
chunkFilename?: Required<Configuration>["output"]["chunkFilename"];
239+
/**
240+
* chunk filename
241+
*/
242+
chunkFilename?:
243+
| Required<Configuration>["output"]["chunkFilename"]
244+
| undefined;
245+
/**
246+
* true when need to ignore order, otherwise false
247+
*/
198248
ignoreOrder: boolean;
199-
insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined;
249+
/**
250+
* a link insert place or a custom insert function
251+
*/
252+
insert?: (string | ((linkTag: HTMLLinkElement) => void)) | undefined;
253+
/**
254+
* link attributes
255+
*/
200256
attributes?: Record<string, string> | undefined;
201-
linkType?: string | false | undefined;
257+
/**
258+
* value of a link type attribute
259+
*/
260+
linkType?: (string | false | "text/css") | undefined;
261+
/**
262+
* true when need to generate runtime code, otherwise false
263+
*/
202264
runtime: boolean;
265+
/**
266+
* true when need to use `experimentalUseImportModule` API, otherwise false
267+
*/
203268
experimentalUseImportModule?: boolean | undefined;
204269
};
205270
type RuntimeOptions = {
206-
insert: string | ((linkTag: HTMLLinkElement) => void) | undefined;
271+
/**
272+
* a link insert place or a custom insert function
273+
*/
274+
insert?: (string | ((linkTag: HTMLLinkElement) => void)) | undefined;
275+
/**
276+
* value of a link type attribute
277+
*/
207278
linkType: string | false | "text/css";
208-
attributes: Record<string, string> | undefined;
279+
/**
280+
* link attributes
281+
*/
282+
attributes?: Record<string, string> | undefined;
209283
};
210284
type TODO = any;
211285
type CssModule = Module & {
@@ -246,18 +320,42 @@ type CssDependencyConstructor = {
246320
): CssDependency;
247321
};
248322
type VarNames = {
323+
/**
324+
* tag
325+
*/
249326
tag: string;
327+
/**
328+
* chunk id
329+
*/
250330
chunkId: string;
331+
/**
332+
* href
333+
*/
251334
href: string;
335+
/**
336+
* resolve
337+
*/
252338
resolve: string;
339+
/**
340+
* reject
341+
*/
253342
reject: string;
254343
};
255344
type MiniCssExtractPluginCompilationHooks = {
345+
/**
346+
* before tag insert hook
347+
*/
256348
beforeTagInsert: import("tapable").SyncWaterfallHook<
257349
[string, VarNames],
258350
string
259351
>;
352+
/**
353+
* link preload hook
354+
*/
260355
linkPreload: SyncWaterfallHook<[string, Chunk]>;
356+
/**
357+
* link prefetch hook
358+
*/
261359
linkPrefetch: SyncWaterfallHook<[string, Chunk]>;
262360
};
263361
import { SyncWaterfallHook } from "tapable";

0 commit comments

Comments
 (0)