Skip to content

Commit 0952f55

Browse files
committed
feat: add rsdoctor native plugin
1 parent 8454d2a commit 0952f55

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { BuiltinPluginName, JsRsdoctorAsset, JsRsdoctorChunkGraph, JsRsdoctorModuleGraph, JsRsdoctorModuleSource, RawRsdoctorPluginOptions } from "@rspack/binding";
2+
import { z } from "zod";
3+
import { create } from "./base";
4+
import { validate } from "../util/validate";
5+
import { Compiler } from "../Compiler";
6+
import * as liteTapable from "@rspack/lite-tapable";
7+
import { Compilation } from "../Compilation";
8+
9+
export type RsdoctorRspackPluginOptions = {};
10+
const rsdoctorPluginSchema = z.strictObject({}) satisfies z.ZodType<RsdoctorRspackPluginOptions>;
11+
12+
const RsdoctorRspackPluginImpl = create(
13+
BuiltinPluginName.HtmlRspackPlugin,
14+
function (
15+
this: Compiler,
16+
c: RsdoctorRspackPluginOptions = {}
17+
): RawRsdoctorPluginOptions {
18+
validate(c, rsdoctorPluginSchema);
19+
return {};
20+
}
21+
);
22+
23+
export type RsdoctorRspackPluginHooks = {
24+
moduleGraph: liteTapable.AsyncSeriesBailHook<
25+
[JsRsdoctorModuleGraph], false | void
26+
>;
27+
chunkGraph: liteTapable.AsyncSeriesBailHook<
28+
[JsRsdoctorChunkGraph], false | void
29+
>;
30+
moduleSources: liteTapable.AsyncSeriesBailHook<
31+
[JsRsdoctorModuleSource[]], false | void
32+
>;
33+
assets: liteTapable.AsyncSeriesBailHook<
34+
[JsRsdoctorAsset[]], false | void
35+
>;
36+
};
37+
38+
const compilationHooksMap: WeakMap<Compilation, RsdoctorRspackPluginHooks> =
39+
new WeakMap();
40+
41+
const RsdoctorRspackPlugin = RsdoctorRspackPluginImpl as typeof RsdoctorRspackPluginImpl & {
42+
/**
43+
* @deprecated Use `getCompilationHooks` instead.
44+
*/
45+
getHooks: (compilation: Compilation) => RsdoctorRspackPluginHooks;
46+
getCompilationHooks: (compilation: Compilation) => RsdoctorRspackPluginHooks;
47+
};
48+
49+
RsdoctorRspackPlugin.getHooks = RsdoctorRspackPlugin.getCompilationHooks = (
50+
compilation: Compilation
51+
) => {
52+
if (!(compilation instanceof Compilation)) {
53+
throw new TypeError(
54+
"The 'compilation' argument must be an instance of Compilation"
55+
);
56+
}
57+
let hooks = compilationHooksMap.get(compilation);
58+
if (hooks === undefined) {
59+
hooks = {
60+
moduleGraph: new liteTapable.AsyncSeriesBailHook<[JsRsdoctorModuleGraph], false | void>(["moduleGraph"]),
61+
chunkGraph: new liteTapable.AsyncSeriesBailHook<[JsRsdoctorChunkGraph], false | void>(["chunkGraph"]),
62+
moduleSources: new liteTapable.AsyncSeriesBailHook<[JsRsdoctorModuleSource[]], false | void>(["moduleSources"]),
63+
assets: new liteTapable.AsyncSeriesBailHook<[JsRsdoctorAsset[]], false | void>(["assets"]),
64+
};
65+
compilationHooksMap.set(compilation, hooks);
66+
}
67+
return hooks;
68+
};
69+
70+
export { RsdoctorRspackPlugin };

packages/rspack/src/builtin-plugin/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ export * from "./ContextReplacementPlugin";
7171
export * from "./LibManifestPlugin";
7272
export * from "./DllEntryPlugin";
7373
export * from "./DllReferenceAgencyPlugin";
74+
export * from "./RsdoctorPlugin";

0 commit comments

Comments
 (0)