Skip to content

Commit 3446b2b

Browse files
committed
chore: fix plugin
1 parent dc82423 commit 3446b2b

File tree

4 files changed

+144
-229
lines changed

4 files changed

+144
-229
lines changed

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ class MiniCssExtractPlugin {
279279
assetsInfo: this.assetsInfo,
280280
cacheable: true,
281281
hash: this._computeHash(
282-
/** @type {string} */ (compilation.outputOptions.hashFunction)
282+
/** @type {string} */ (
283+
compilation.outputOptions.hashFunction
284+
).toString()
283285
),
284286
};
285287
this.buildMeta = {};
@@ -317,7 +319,8 @@ class MiniCssExtractPlugin {
317319
super.updateHash(hash, context);
318320

319321
hash.update(
320-
/** @type {NonNullable<Module["buildInfo"]>} */ (this.buildInfo).hash
322+
/** @type {NonNullable<Module["buildInfo"]>} */ (this.buildInfo)
323+
.hash || ""
321324
);
322325
}
323326

types/index.d.ts

Lines changed: 121 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,95 @@
11
export = MiniCssExtractPlugin;
22
declare class MiniCssExtractPlugin {
3-
/**
4-
* @param {Compiler["webpack"]} webpack
5-
* @returns {CssModuleConstructor}
6-
*/
7-
static getCssModule(webpack: Compiler["webpack"]): CssModuleConstructor;
8-
/**
9-
* @param {Compiler["webpack"]} webpack
10-
* @returns {CssDependencyConstructor}
11-
*/
12-
static getCssDependency(
13-
webpack: Compiler["webpack"]
14-
): CssDependencyConstructor;
15-
/**
16-
* Returns all hooks for the given compilation
17-
* @param {Compilation} compilation the compilation
18-
* @returns {MiniCssExtractPluginCompilationHooks} hooks
19-
*/
20-
static getCompilationHooks(
21-
compilation: Compilation
22-
): MiniCssExtractPluginCompilationHooks;
23-
/**
24-
* @param {PluginOptions} [options]
25-
*/
26-
constructor(options?: PluginOptions | undefined);
27-
/**
28-
* @private
29-
* @type {WeakMap<Chunk, Set<CssModule>>}
30-
* @private
31-
*/
32-
private _sortedModulesCache;
33-
/**
34-
* @private
35-
* @type {NormalizedPluginOptions}
36-
*/
37-
private options;
38-
/**
39-
* @private
40-
* @type {RuntimeOptions}
41-
*/
42-
private runtimeOptions;
43-
/**
44-
* @param {Compiler} compiler
45-
*/
46-
apply(compiler: Compiler): void;
47-
/**
48-
* @private
49-
* @param {Chunk} chunk
50-
* @param {ChunkGraph} chunkGraph
51-
* @returns {Iterable<Module>}
52-
*/
53-
private getChunkModules;
54-
/**
55-
* @private
56-
* @param {Compilation} compilation
57-
* @param {Chunk} chunk
58-
* @param {CssModule[]} modules
59-
* @param {Compilation["requestShortener"]} requestShortener
60-
* @returns {Set<CssModule>}
61-
*/
62-
private sortModules;
63-
/**
64-
* @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}
73-
*/
74-
private renderContentAsset;
3+
/**
4+
* @param {Compiler["webpack"]} webpack
5+
* @returns {CssModuleConstructor}
6+
*/
7+
static getCssModule(webpack: Compiler["webpack"]): CssModuleConstructor;
8+
/**
9+
* @param {Compiler["webpack"]} webpack
10+
* @returns {CssDependencyConstructor}
11+
*/
12+
static getCssDependency(webpack: Compiler["webpack"]): CssDependencyConstructor;
13+
/**
14+
* Returns all hooks for the given compilation
15+
* @param {Compilation} compilation the compilation
16+
* @returns {MiniCssExtractPluginCompilationHooks} hooks
17+
*/
18+
static getCompilationHooks(compilation: Compilation): MiniCssExtractPluginCompilationHooks;
19+
/**
20+
* @param {PluginOptions} [options]
21+
*/
22+
constructor(options?: PluginOptions | undefined);
23+
/**
24+
* @private
25+
* @type {WeakMap<Chunk, Set<CssModule>>}
26+
* @private
27+
*/
28+
private _sortedModulesCache;
29+
/**
30+
* @private
31+
* @type {NormalizedPluginOptions}
32+
*/
33+
private options;
34+
/**
35+
* @private
36+
* @type {RuntimeOptions}
37+
*/
38+
private runtimeOptions;
39+
/**
40+
* @param {Compiler} compiler
41+
*/
42+
apply(compiler: Compiler): void;
43+
/**
44+
* @private
45+
* @param {Chunk} chunk
46+
* @param {ChunkGraph} chunkGraph
47+
* @returns {Iterable<Module>}
48+
*/
49+
private getChunkModules;
50+
/**
51+
* @private
52+
* @param {Compilation} compilation
53+
* @param {Chunk} chunk
54+
* @param {CssModule[]} modules
55+
* @param {Compilation["requestShortener"]} requestShortener
56+
* @returns {Set<CssModule>}
57+
*/
58+
private sortModules;
59+
/**
60+
* @private
61+
* @param {Compiler} compiler
62+
* @param {Compilation} compilation
63+
* @param {Chunk} chunk
64+
* @param {CssModule[]} modules
65+
* @param {Compiler["requestShortener"]} requestShortener
66+
* @param {string} filenameTemplate
67+
* @param {Parameters<Exclude<Required<Configuration>['output']['filename'], string | undefined>>[0]} pathData
68+
* @returns {Source}
69+
*/
70+
private renderContentAsset;
7571
}
7672
declare namespace MiniCssExtractPlugin {
77-
export {
78-
pluginName,
79-
pluginSymbol,
80-
loader,
81-
Schema,
82-
Compiler,
83-
Compilation,
84-
ChunkGraph,
85-
Chunk,
86-
ChunkGroup,
87-
Module,
88-
Dependency,
89-
Source,
90-
Configuration,
91-
WebpackError,
92-
AssetInfo,
93-
LoaderDependency,
94-
LoaderOptions,
95-
PluginOptions,
96-
NormalizedPluginOptions,
97-
RuntimeOptions,
98-
TODO,
99-
CssModule,
100-
CssModuleDependency,
101-
CssModuleConstructor,
102-
CssDependency,
103-
CssDependencyOptions,
104-
CssDependencyConstructor,
105-
VarNames,
106-
MiniCssExtractPluginCompilationHooks,
107-
};
73+
export { pluginName, pluginSymbol, loader, Schema, Compiler, Compilation, ChunkGraph, Chunk, ChunkGroup, Module, Dependency, Source, Configuration, WebpackError, AssetInfo, LoaderDependency, LoaderOptions, PluginOptions, NormalizedPluginOptions, RuntimeOptions, TODO, CssModule, CssModuleDependency, CssModuleConstructor, CssDependency, CssDependencyOptions, CssDependencyConstructor, VarNames, MiniCssExtractPluginCompilationHooks };
10874
}
10975
type Compiler = import("webpack").Compiler;
11076
type CssModuleConstructor = new (dependency: CssModuleDependency) => CssModule;
111-
type CssDependencyConstructor = new (
112-
loaderDependency: CssDependencyOptions,
113-
context: string | null,
114-
identifierIndex: number
115-
) => CssDependency;
77+
type CssDependencyConstructor = new (loaderDependency: CssDependencyOptions, context: string | null, identifierIndex: number) => CssDependency;
11678
type Compilation = import("webpack").Compilation;
11779
type MiniCssExtractPluginCompilationHooks = {
118-
beforeTagInsert: import("tapable").SyncWaterfallHook<
119-
[string, VarNames],
120-
string
121-
>;
122-
linkPreload: SyncWaterfallHook<[string, Chunk]>;
123-
linkPrefetch: SyncWaterfallHook<[string, Chunk]>;
80+
beforeTagInsert: import("tapable").SyncWaterfallHook<[string, VarNames], string>;
81+
linkPreload: SyncWaterfallHook<[string, Chunk]>;
82+
linkPrefetch: SyncWaterfallHook<[string, Chunk]>;
12483
};
12584
type PluginOptions = {
126-
filename?: Required<Configuration>["output"]["filename"];
127-
chunkFilename?: Required<Configuration>["output"]["chunkFilename"];
128-
ignoreOrder?: boolean | undefined;
129-
insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined;
130-
attributes?: Record<string, string> | undefined;
131-
linkType?: string | false | undefined;
132-
runtime?: boolean | undefined;
133-
experimentalUseImportModule?: boolean | undefined;
85+
filename?: Required<Configuration>['output']['filename'];
86+
chunkFilename?: Required<Configuration>['output']['chunkFilename'];
87+
ignoreOrder?: boolean | undefined;
88+
insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined;
89+
attributes?: Record<string, string> | undefined;
90+
linkType?: string | false | undefined;
91+
runtime?: boolean | undefined;
92+
experimentalUseImportModule?: boolean | undefined;
13493
};
13594
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
13695
/** @typedef {import("webpack").Compiler} Compiler */
@@ -197,67 +156,60 @@ type WebpackError = import("webpack").WebpackError;
197156
type AssetInfo = import("webpack").AssetInfo;
198157
type LoaderDependency = import("./loader.js").Dependency;
199158
type LoaderOptions = {
200-
publicPath?:
201-
| string
202-
| ((resourcePath: string, rootContext: string) => string)
203-
| undefined;
204-
emit?: boolean | undefined;
205-
esModule?: boolean | undefined;
206-
layer?: string | undefined;
207-
defaultExport?: boolean | undefined;
159+
publicPath?: string | ((resourcePath: string, rootContext: string) => string) | undefined;
160+
emit?: boolean | undefined;
161+
esModule?: boolean | undefined;
162+
layer?: string | undefined;
163+
defaultExport?: boolean | undefined;
208164
};
209165
type NormalizedPluginOptions = {
210-
filename: Required<Configuration>["output"]["filename"];
211-
chunkFilename?: Required<Configuration>["output"]["chunkFilename"];
212-
ignoreOrder: boolean;
213-
insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined;
214-
attributes?: Record<string, string> | undefined;
215-
linkType?: string | false | undefined;
216-
runtime: boolean;
217-
experimentalUseImportModule?: boolean | undefined;
166+
filename: Required<Configuration>['output']['filename'];
167+
chunkFilename?: Required<Configuration>['output']['chunkFilename'];
168+
ignoreOrder: boolean;
169+
insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined;
170+
attributes?: Record<string, string> | undefined;
171+
linkType?: string | false | undefined;
172+
runtime: boolean;
173+
experimentalUseImportModule?: boolean | undefined;
218174
};
219175
type RuntimeOptions = {
220-
insert: string | ((linkTag: HTMLLinkElement) => void) | undefined;
221-
linkType: string | false | "text/css";
222-
attributes: Record<string, string> | undefined;
176+
insert: string | ((linkTag: HTMLLinkElement) => void) | undefined;
177+
linkType: string | false | 'text/css';
178+
attributes: Record<string, string> | undefined;
223179
};
224180
type TODO = any;
225181
type CssModule = import("webpack").Module & {
226-
content: Buffer;
227-
media?: string | undefined;
228-
sourceMap?: Buffer | undefined;
229-
supports?: string | undefined;
230-
layer?: string | undefined;
231-
assets?:
232-
| {
182+
content: Buffer;
183+
media?: string | undefined;
184+
sourceMap?: Buffer | undefined;
185+
supports?: string | undefined;
186+
layer?: string | undefined;
187+
assets?: {
233188
[key: string]: any;
234-
}
235-
| undefined;
236-
assetsInfo?: Map<string, import("webpack").AssetInfo> | undefined;
189+
} | undefined;
190+
assetsInfo?: Map<string, import("webpack").AssetInfo> | undefined;
237191
};
238192
type CssModuleDependency = {
239-
context: string | null;
240-
identifier: string;
241-
identifierIndex: number;
242-
content: Buffer;
243-
sourceMap?: Buffer | undefined;
244-
media?: string | undefined;
245-
supports?: string | undefined;
246-
layer?: TODO;
247-
assetsInfo?: Map<string, import("webpack").AssetInfo> | undefined;
248-
assets?:
249-
| {
193+
context: string | null;
194+
identifier: string;
195+
identifierIndex: number;
196+
content: Buffer;
197+
sourceMap?: Buffer | undefined;
198+
media?: string | undefined;
199+
supports?: string | undefined;
200+
layer?: TODO;
201+
assetsInfo?: Map<string, import("webpack").AssetInfo> | undefined;
202+
assets?: {
250203
[key: string]: any;
251-
}
252-
| undefined;
204+
} | undefined;
253205
};
254206
type CssDependency = Dependency & CssModuleDependency;
255207
type CssDependencyOptions = Omit<LoaderDependency, "context">;
256208
type VarNames = {
257-
tag: string;
258-
chunkId: string;
259-
href: string;
260-
resolve: string;
261-
reject: string;
209+
tag: string;
210+
chunkId: string;
211+
href: string;
212+
resolve: string;
213+
reject: string;
262214
};
263215
import { SyncWaterfallHook } from "tapable";

0 commit comments

Comments
 (0)