Skip to content

Commit 7c6ffbc

Browse files
committed
make custom types for CssModule and CssDependency
1 parent b8d2551 commit 7c6ffbc

File tree

7 files changed

+458
-281
lines changed

7 files changed

+458
-281
lines changed

package-lock.json

+379-263
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
},
4343
"files": [
4444
"dist",
45-
"types"
45+
"types",
46+
"public.d.ts"
4647
],
4748
"peerDependencies": {
4849
"webpack": "^5.0.0"
@@ -53,29 +54,29 @@
5354
"devDependencies": {
5455
"@babel/cli": "^7.16.7",
5556
"@babel/core": "^7.16.7",
56-
"@babel/eslint-parser": "^7.16.0",
57+
"@babel/eslint-parser": "^7.16.5",
5758
"@babel/preset-env": "^7.16.7",
58-
"@commitlint/cli": "^15.0.0",
59-
"@commitlint/config-conventional": "^15.0.0",
59+
"@commitlint/cli": "^16.0.2",
60+
"@commitlint/config-conventional": "^16.0.0",
6061
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
6162
"babel-jest": "^27.0.6",
6263
"bootstrap": "^4.6.0",
6364
"cross-env": "^7.0.3",
6465
"css-loader": "^6.2.0",
6566
"del": "^6.0.0",
6667
"del-cli": "^4.0.0",
67-
"es-check": "^6.0.0",
68-
"eslint": "^8.6.0",
69-
"eslint-config-prettier": "^8.1.0",
68+
"es-check": "^6.1.1",
69+
"eslint": "^8.7.0",
70+
"eslint-config-prettier": "^8.3.0",
7071
"eslint-plugin-import": "^2.25.4",
7172
"file-loader": "^6.2.0",
7273
"husky": "^7.0.0",
7374
"jest": "^27.0.6",
7475
"jsdom": "^19.0.0",
75-
"lint-staged": "^12.1.5",
76+
"lint-staged": "^12.1.7",
7677
"memfs": "^3.4.1",
7778
"npm-run-all": "^4.1.5",
78-
"prettier": "^2.3.2",
79+
"prettier": "^2.5.1",
7980
"sass": "^1.45.2",
8081
"sass-loader": "^12.1.0",
8182
"standard-version": "^9.3.0",

public.d.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
type Module = import("webpack").Module;
2+
type Dependency = import("webpack").Dependency;
3+
type Source = import("webpack").sources.Source;
4+
type AssetInfo = import("webpack").AssetInfo;
5+
6+
export interface CssModule {
7+
new ({
8+
context,
9+
identifier,
10+
identifierIndex,
11+
content,
12+
layer,
13+
supports,
14+
media,
15+
sourceMap,
16+
assets,
17+
assetsInfo,
18+
}: {
19+
context: string;
20+
identifier: string;
21+
identifierIndex: number;
22+
content: Buffer;
23+
layer: string | null;
24+
supports?: string;
25+
media: string;
26+
sourceMap?: Buffer;
27+
assets: { [key: string]: Source };
28+
assetsInfo: Map<string, AssetInfo>;
29+
}): Module;
30+
}
31+
32+
interface CssDependencyPublicOptions {
33+
identifier: string;
34+
content: Buffer;
35+
layer?: string;
36+
supports?: string;
37+
media: string;
38+
sourceMap?: Buffer;
39+
}
40+
41+
export interface CssDependency {
42+
new (
43+
{
44+
identifier,
45+
content,
46+
layer,
47+
supports,
48+
media,
49+
sourceMap,
50+
}: CssDependencyPublicOptions,
51+
context: string | null,
52+
identifierIndex: number
53+
): Dependency & {
54+
assetsInfo?: Map<string, AssetInfo>;
55+
assets?: { [key: string]: Source };
56+
};
57+
}

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class MiniCssExtractPlugin {
8888
/**
8989
* @public
9090
* @param {Compiler["webpack"]} webpack
91-
* @returns {typeof CssModule}
91+
* @returns {import("../public").CssModule}
9292
*/
9393
static getCssModule(webpack) {
9494
/**
@@ -348,7 +348,7 @@ class MiniCssExtractPlugin {
348348
/**
349349
* @public
350350
* @param {Compiler["webpack"]} webpack
351-
* @returns {typeof CssDependency}
351+
* @returns {import("../public").CssDependency}
352352
*/
353353
static getCssDependency(webpack) {
354354
/**

src/loader.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,11 @@ function pitch(request) {
126126
identifierCountMap.get(
127127
/** @type {Dependency} */ (dependency).identifier
128128
) || 0;
129-
// @ts-ignore
129+
130130
const CssDependency = MiniCssExtractPlugin.getCssDependency(webpack);
131131

132132
/** @type {NormalModule} */
133133
(this._module).addDependency(
134-
// @ts-ignore
135134
(lastDep = new CssDependency(
136135
/** @type {Dependency} */
137136
(dependency),

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"resolveJsonModule": true,
1010
"allowSyntheticDefaultImports": true
1111
},
12-
"include": ["./src/**/*"]
12+
"include": ["./src/**/*", "public.d.ts"]
1313
}

types/index.d.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ declare class MiniCssExtractPlugin {
33
/**
44
* @public
55
* @param {Compiler["webpack"]} webpack
6-
* @returns {typeof CssModule}
6+
* @returns {import("../public").CssModule}
77
*/
8-
private static getCssModule;
8+
public static getCssModule(
9+
webpack: Compiler["webpack"]
10+
): import("../public").CssModule;
911
/**
1012
* @public
1113
* @param {Compiler["webpack"]} webpack
12-
* @returns {typeof CssDependency}
14+
* @returns {import("../public").CssDependency}
1315
*/
14-
private static getCssDependency;
16+
public static getCssDependency(
17+
webpack: Compiler["webpack"]
18+
): import("../public").CssDependency;
1519
/**
1620
* @param {PluginOptions} [options]
1721
*/

0 commit comments

Comments
 (0)