@rsdoctor/docs 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,5 +9,6 @@
9
9
  "plugins-analysis",
10
10
  "bundle-size",
11
11
  "module-analysis",
12
- "resolver"
12
+ "resolver",
13
+ "rule-config"
13
14
  ]
@@ -0,0 +1,85 @@
1
+ # Compilation Diagnostic Rules
2
+
3
+ Building diagnostic rules is similar to lint tools like `ESLint`, but with a difference. `ESLint` performs static code scanning and is independent of the build process. On the other hand, the code diagnostics here are closely related to the build process of `Rspack` or `Webpack`. It incorporates various internal parameters generated during the build process to assist in the analysis, such as ModuleGraph, internal markers for each module by Webpack, and runtime added after code transformation, and so on...
4
+
5
+ If any issues are detected during the build process, they will be displayed in the CLI and the diagnostic summary webpage, as shown in the following image:
6
+
7
+ <img
8
+ width="700"
9
+ style={{ margin: '10px auto' }}
10
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/rule-config-cli.png"
11
+ />
12
+
13
+ <img
14
+ width="700"
15
+ style={{ margin: '10px auto' }}
16
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/rule-config-1.png"
17
+ />
18
+
19
+ ## How to Use
20
+
21
+ Using diagnostic rules is simple. They are configured under the `linter` option of the entire plugin, as shown in the following example:
22
+
23
+ ```ts
24
+ import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
25
+
26
+ export default {
27
+ plugin: [
28
+ new RsdoctorWebpackPlugin({
29
+ linter: {
30
+ level: 'Error',
31
+ extends: [],
32
+ rules: {
33
+ 'default-import-check': 'off',
34
+ 'duplicate-package': [
35
+ 'Error',
36
+ {
37
+ checkVersion: 'minor',
38
+ ignore: ['chalk', '@bable/runtime'],
39
+ },
40
+ ],
41
+ },
42
+ },
43
+ }),
44
+ ],
45
+ };
46
+ ```
47
+
48
+ The type of `linter`:
49
+
50
+ ```ts
51
+ interface Options {
52
+ rules?: RulesMap;
53
+ level?: SeverityString;
54
+ extends?: ExtendRuleData[];
55
+ }
56
+
57
+ /**
58
+ * Validation Level
59
+ * - When set to `'Warn'`, only rules with the category `'Warn'` will be executed
60
+ * - When set to `'Error'`, all rules will be executed
61
+ */
62
+ type SeverityString = 'Warn' | 'Error';
63
+
64
+ /** Rule Level */
65
+ type SeverityInput = SeverityString | 'off' | 'on';
66
+
67
+ /** Rule Configuration */
68
+ type RulesMap = Record<string, RuleConfigItem>;
69
+
70
+ /** Individual Rule Configuration */
71
+ type RuleConfigItem =
72
+ // Only severity level, which takes precedence over the rule's own configuration
73
+ | SeverityInput
74
+ // In the case of an array, the first item is the severity level, and the second item is the rule configuration
75
+ | [SeverityInput, unknown];
76
+ ```
77
+
78
+ ## Existing Internal Rules
79
+
80
+ There are already three rules included in the existing diagnostic tool, which are:
81
+
82
+ 1. [[E1001] Duplicate Packages](./bundle-alerts#%E9%87%8D%E5%A4%8D%E7%AC%AC%E4%B8%89%E6%96%B9%E5%8C%85)
83
+ 2. [[E1002] Default Import Check](../more/rules)
84
+ 3. [[E1003] Loader Performance Optimization](../more/rules)
85
+ 4. [[E1004] ECMA Version Check](../more/rules)
@@ -9,5 +9,6 @@
9
9
  "plugins-analysis",
10
10
  "bundle-size",
11
11
  "module-analysis",
12
- "resolver"
12
+ "resolver",
13
+ "rule-config"
13
14
  ]
@@ -0,0 +1,86 @@
1
+ # 编译诊断规则
2
+
3
+ 构建诊断规则是类似于 `ESLint` 的 lint 工具,但是与其不同之处在于,`ESLint` 是在静态情况下进行代码扫描和构建流程无关。而这里的代码诊断是和 `Rspack 或 Webpack` 的构建流程紧密相关的,其中会加入许许多多构建中产生的内部参数用于辅助判断,比如 ModuleGraph,比如 Webpack 对每个模块的内部标记,比如代码经过转换之后加入的 runtime 等等……
4
+
5
+ 在构建过程中发现了问题,会在 CLI 和最后弹出的诊断汇总网页中看到,如下图:
6
+
7
+ <img
8
+ width="700"
9
+ style={{ margin: '10px auto' }}
10
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/rule-config-cli.png"
11
+ />
12
+
13
+ <img
14
+ width="700"
15
+ style={{ margin: '10px auto' }}
16
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/rule-config-1.png"
17
+ />
18
+
19
+ ## 如何使用
20
+
21
+ 诊断规则的使用很简单,它配置在整个插件的`linter`选项下,如下用例:
22
+
23
+ ```ts
24
+ import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
25
+
26
+ export default {
27
+ plugin: [
28
+ new RsdoctorWebpackPlugin({
29
+ linter: {
30
+ level: 'Error',
31
+ extends: [],
32
+ rules: {
33
+ 'default-import-check': 'off',
34
+ 'duplicate-package': [
35
+ 'Error',
36
+ {
37
+ checkVersion: 'minor',
38
+ ignore: ['chalk', '@bable/runtime'],
39
+ },
40
+ ],
41
+ },
42
+ },
43
+ }),
44
+ ],
45
+ };
46
+ ```
47
+
48
+ `linter`字段的类型为:
49
+
50
+ ```ts
51
+ /** 校验器选项 */
52
+ interface Options {
53
+ rules?: RulesMap;
54
+ level?: SeverityString;
55
+ extends?: ExtendRuleData[];
56
+ }
57
+
58
+ /**
59
+ * 校验等级
60
+ * - `'Warn'`时只运行类别为`'Warn'`的规则
61
+ * - `'Error'`时运行全部规则
62
+ */
63
+ type SeverityString = 'Warn' | 'Error';
64
+
65
+ /** 规则等级 */
66
+ type SeverityInput = SeverityString | 'off' | 'on';
67
+
68
+ /** 规则配置 */
69
+ type RulesMap = Record<string, RuleConfigItem>;
70
+
71
+ /** 单规则配置 */
72
+ type RuleConfigItem =
73
+ // 仅有报错等级,此等级优先级高于规则自身配置
74
+ | SeverityInput
75
+ // 数组情况下,第一项为报错等级,后一项是规则配置
76
+ | [SeverityInput, unknown];
77
+ ```
78
+
79
+ ## 内部已有规则
80
+
81
+ 在现有的诊断器中已经包含了三个规则,它们分别是:
82
+
83
+ 1. [[E1001] Duplicate Packages](./bundle-alerts#%E9%87%8D%E5%A4%8D%E7%AC%AC%E4%B8%89%E6%96%B9%E5%8C%85)
84
+ 2. [[E1002] Default Import Check](../more/rules)
85
+ 3. [[E1003] Loader Performance Optimization](../more/rules)
86
+ 4. [[E1004] ECMA Version Check](../more/rules)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/docs",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -28,7 +28,7 @@
28
28
  "rsbuild-plugin-open-graph": "1.0.0",
29
29
  "rspress-plugin-font-open-sans": "^1.0.0",
30
30
  "typescript": "^5.2.2",
31
- "@rsdoctor/types": "0.2.2"
31
+ "@rsdoctor/types": "0.2.3"
32
32
  },
33
33
  "dependencies": {
34
34
  "framer-motion": "^10.17.6",