|
1 | 1 | /* eslint-disable max-classes-per-file */ |
2 | | - |
3 | | -import { ReplaceSource } from "webpack-sources"; |
4 | | - |
5 | | -// eslint-disable-next-line |
6 | | -// @ts-ignore: What's the right way to refer to this one? |
7 | | -import Hash from "webpack/lib/util/Hash.js"; |
| 2 | +import * as webpack from "webpack"; |
8 | 3 |
|
9 | 4 | // eslint-disable-next-line |
10 | 5 | // @ts-ignore: What's the right way to refer to this one? |
11 | 6 | import makeSerializable from "webpack/lib/util/makeSerializable.js"; |
12 | 7 |
|
13 | | -// eslint-disable-next-line |
14 | | -// @ts-ignore TODO: Figure out where to find a typed version |
15 | | -import NullDependency from "webpack/lib/dependencies/NullDependency.js"; |
| 8 | +class DocGenDependency extends webpack.dependencies.NullDependency { |
| 9 | + public codeBlock: string; |
16 | 10 |
|
17 | | -class DocGenDependency extends NullDependency { |
18 | | - public static Template: NullDependency.Template; |
19 | | - private codeBlock: string; |
20 | | - |
21 | | - constructor(request: string, codeBlock: string) { |
22 | | - super(request); |
| 11 | + constructor(codeBlock: string) { |
| 12 | + super(); |
23 | 13 |
|
24 | 14 | this.codeBlock = codeBlock; |
25 | 15 | } |
26 | 16 |
|
27 | | - updateHash(hash: Hash): void { |
| 17 | + updateHash: webpack.dependencies.NullDependency["updateHash"] = (hash) => { |
28 | 18 | hash.update(this.codeBlock); |
29 | | - } |
| 19 | + }; |
30 | 20 | } |
31 | 21 |
|
32 | 22 | makeSerializable( |
33 | 23 | DocGenDependency, |
34 | 24 | "react-docgen-typescript-plugin/dist/dependency" |
35 | 25 | ); |
36 | | -class DocGenTemplate extends NullDependency.Template { |
37 | | - apply(dependency: NullDependency, source: ReplaceSource): void { |
| 26 | + |
| 27 | +type NullDependencyTemplateType = InstanceType< |
| 28 | + typeof webpack.dependencies.NullDependency.Template |
| 29 | +>; |
| 30 | +class DocGenTemplate extends webpack.dependencies.NullDependency.Template |
| 31 | + implements NullDependencyTemplateType { |
| 32 | + apply: NullDependencyTemplateType["apply"] = ( |
| 33 | + dependency: DocGenDependency, |
| 34 | + source |
| 35 | + ) => { |
38 | 36 | if (dependency.codeBlock) { |
39 | 37 | // Insert to the end |
40 | 38 | source.insert(Infinity, dependency.codeBlock); |
41 | 39 | } |
42 | | - } |
| 40 | + }; |
43 | 41 | } |
44 | 42 |
|
45 | 43 | DocGenDependency.Template = DocGenTemplate; |
|
0 commit comments