@rsdoctor/core 2.0.0-alpha.1 → 2.0.0-beta.0

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.
Files changed (177) hide show
  1. package/dist/26.js +26174 -0
  2. package/dist/630.js +1280 -0
  3. package/dist/630.js.LICENSE.txt +7 -0
  4. package/dist/build-utils/build/chunks/assetsModules.d.ts +7 -1
  5. package/dist/build-utils/build/loader/probeLoader.d.ts +7 -2
  6. package/dist/build-utils/build/server.d.ts +1 -2
  7. package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
  8. package/dist/index.d.ts +5 -5
  9. package/dist/index.js +1908 -7
  10. package/dist/inner-plugins/constants.d.ts +1 -1
  11. package/dist/inner-plugins/plugins/base.d.ts +2 -2
  12. package/dist/inner-plugins/plugins/errors.d.ts +1 -0
  13. package/dist/inner-plugins/plugins/plugins.d.ts +1 -1
  14. package/dist/inner-plugins/plugins/summary.d.ts +3 -2
  15. package/dist/inner-plugins/utils/sdk.d.ts +2 -1
  16. package/dist/logger.d.ts +2 -2
  17. package/dist/probe-loader.js +2 -0
  18. package/dist/proxy-loader.d.ts +1 -0
  19. package/dist/proxy-loader.js +48 -0
  20. package/dist/rslib-runtime.js +28 -0
  21. package/dist/rspack-plugin/constants.d.ts +1 -1
  22. package/dist/rspack-plugin/multiple.d.ts +5 -3
  23. package/dist/rspack-plugin/plugin.d.ts +43 -17
  24. package/dist/rspack-plugin/session.d.ts +20 -0
  25. package/dist/rules/rules/ecma-version-check/htmlParserStub.d.ts +3 -0
  26. package/dist/rules/rules/ecma-version-check/types.d.ts +13 -2
  27. package/dist/sdk/multiple/controller.d.ts +13 -2
  28. package/dist/sdk/multiple/primary.d.ts +12 -4
  29. package/dist/sdk/server/apis/base.d.ts +1 -1
  30. package/dist/sdk/server/socket/api.d.ts +1 -1
  31. package/dist/sdk/utils/date.d.ts +1 -0
  32. package/dist/types/loader.d.ts +1 -1
  33. package/package.json +23 -117
  34. package/dist/build-utils/build/chunks/assetsModules.js +0 -9
  35. package/dist/build-utils/build/chunks/index.js +0 -3
  36. package/dist/build-utils/build/chunks/rspack/transform.js +0 -44
  37. package/dist/build-utils/build/envinfo.js +0 -60
  38. package/dist/build-utils/build/file/cache.js +0 -24
  39. package/dist/build-utils/build/file/index.js +0 -5
  40. package/dist/build-utils/build/file/sharding.js +0 -38
  41. package/dist/build-utils/build/index.js +0 -12
  42. package/dist/build-utils/build/json.js +0 -67
  43. package/dist/build-utils/build/loader/index.js +0 -3
  44. package/dist/build-utils/build/loader/probeLoader.js +0 -44
  45. package/dist/build-utils/build/loader/probeLoaderPlugin.js +0 -32
  46. package/dist/build-utils/build/module-graph/index.js +0 -2
  47. package/dist/build-utils/build/module-graph/parser.js +0 -13
  48. package/dist/build-utils/build/module-graph/rspack/transform.js +0 -111
  49. package/dist/build-utils/build/module-graph/utils.js +0 -60
  50. package/dist/build-utils/build/process.js +0 -18
  51. package/dist/build-utils/build/server.js +0 -107
  52. package/dist/build-utils/build/utils/index.js +0 -4
  53. package/dist/build-utils/build/utils/loader.js +0 -267
  54. package/dist/build-utils/build/utils/parseBundle.js +0 -238
  55. package/dist/build-utils/build/utils/plugin.js +0 -21
  56. package/dist/build-utils/index.js +0 -13
  57. package/dist/collection.d.ts +0 -1
  58. package/dist/collection.js +0 -2
  59. package/dist/common/file.js +0 -8
  60. package/dist/common/global-config.js +0 -33
  61. package/dist/common/index.d.ts +0 -4
  62. package/dist/common/index.js +0 -6
  63. package/dist/common-browser.d.ts +0 -1
  64. package/dist/common-browser.js +0 -2
  65. package/dist/error/error.js +0 -143
  66. package/dist/error/index.js +0 -3
  67. package/dist/error/transform.js +0 -138
  68. package/dist/error/utils.js +0 -23
  69. package/dist/graph/index.d.ts +0 -1
  70. package/dist/graph/index.js +0 -2
  71. package/dist/inner-plugins/constants.js +0 -19
  72. package/dist/inner-plugins/index.js +0 -3
  73. package/dist/inner-plugins/loaders/proxy.js +0 -65
  74. package/dist/inner-plugins/plugins/base.js +0 -20
  75. package/dist/inner-plugins/plugins/bundle.js +0 -63
  76. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +0 -74
  77. package/dist/inner-plugins/plugins/errors.js +0 -65
  78. package/dist/inner-plugins/plugins/index.js +0 -11
  79. package/dist/inner-plugins/plugins/loader.js +0 -108
  80. package/dist/inner-plugins/plugins/plugins.js +0 -40
  81. package/dist/inner-plugins/plugins/progress.js +0 -35
  82. package/dist/inner-plugins/plugins/resolver.js +0 -57
  83. package/dist/inner-plugins/plugins/rspack.js +0 -99
  84. package/dist/inner-plugins/plugins/rules.js +0 -64
  85. package/dist/inner-plugins/plugins/sourcemapTool.js +0 -230
  86. package/dist/inner-plugins/plugins/summary.js +0 -92
  87. package/dist/inner-plugins/utils/circleDetect.js +0 -16
  88. package/dist/inner-plugins/utils/config.js +0 -141
  89. package/dist/inner-plugins/utils/index.js +0 -8
  90. package/dist/inner-plugins/utils/loader.js +0 -134
  91. package/dist/inner-plugins/utils/normalize-config.js +0 -77
  92. package/dist/inner-plugins/utils/openBrowser.js +0 -55
  93. package/dist/inner-plugins/utils/plugin-common.js +0 -94
  94. package/dist/inner-plugins/utils/plugin.js +0 -70
  95. package/dist/inner-plugins/utils/sdk.js +0 -19
  96. package/dist/logger.js +0 -51
  97. package/dist/rspack-plugin/constants.js +0 -23
  98. package/dist/rspack-plugin/index.js +0 -3
  99. package/dist/rspack-plugin/multiple.js +0 -39
  100. package/dist/rspack-plugin/plugin.js +0 -133
  101. package/dist/rule-utils/document/document.js +0 -46
  102. package/dist/rule-utils/document/index.js +0 -4
  103. package/dist/rule-utils/document/server.js +0 -13
  104. package/dist/rule-utils/document/types.js +0 -1
  105. package/dist/rule-utils/index.js +0 -3
  106. package/dist/rule-utils/parser/asserts.js +0 -105
  107. package/dist/rule-utils/parser/index.js +0 -5
  108. package/dist/rule-utils/parser/parser.js +0 -24
  109. package/dist/rule-utils/parser/types.js +0 -8
  110. package/dist/rule-utils/parser/utils.js +0 -106
  111. package/dist/rules/index.js +0 -4
  112. package/dist/rules/linter.js +0 -36
  113. package/dist/rules/rule.js +0 -101
  114. package/dist/rules/rules/cjs-require/index.js +0 -50
  115. package/dist/rules/rules/cjs-require/types.js +0 -1
  116. package/dist/rules/rules/cross-chunks-package/index.js +0 -41
  117. package/dist/rules/rules/cross-chunks-package/types.js +0 -1
  118. package/dist/rules/rules/cross-chunks-package/utils.js +0 -7
  119. package/dist/rules/rules/default-import-check/index.js +0 -83
  120. package/dist/rules/rules/default-import-check/types.js +0 -1
  121. package/dist/rules/rules/default-import-check/utils.js +0 -52
  122. package/dist/rules/rules/duplicate-package/index.js +0 -39
  123. package/dist/rules/rules/duplicate-package/types.js +0 -24
  124. package/dist/rules/rules/duplicate-package/utils.js +0 -38
  125. package/dist/rules/rules/ecma-version-check/index.js +0 -53
  126. package/dist/rules/rules/ecma-version-check/types.js +0 -1
  127. package/dist/rules/rules/ecma-version-check/utils.js +0 -6
  128. package/dist/rules/rules/esm-resolved-to-cjs/index.js +0 -193
  129. package/dist/rules/rules/esm-resolved-to-cjs/types.js +0 -1
  130. package/dist/rules/rules/index.js +0 -22
  131. package/dist/rules/rules/loader-performance-optimization/index.js +0 -86
  132. package/dist/rules/rules/loader-performance-optimization/types.js +0 -1
  133. package/dist/rules/rules/loader-performance-optimization/utils.js +0 -10
  134. package/dist/rules/rules/module-mixed-chunks/index.js +0 -52
  135. package/dist/rules/rules/module-mixed-chunks/types.js +0 -1
  136. package/dist/rules/rules/side-effects-only-imports/index.js +0 -81
  137. package/dist/rules/rules/side-effects-only-imports/types.js +0 -1
  138. package/dist/rules/utils.js +0 -10
  139. package/dist/sdk/index.js +0 -3
  140. package/dist/sdk/multiple/controller.js +0 -42
  141. package/dist/sdk/multiple/index.js +0 -3
  142. package/dist/sdk/multiple/primary.js +0 -64
  143. package/dist/sdk/multiple/server.js +0 -14
  144. package/dist/sdk/sdk/core.js +0 -163
  145. package/dist/sdk/sdk/index.js +0 -435
  146. package/dist/sdk/sdk/types.js +0 -1
  147. package/dist/sdk/server/apis/alerts.js +0 -30
  148. package/dist/sdk/server/apis/base.js +0 -22
  149. package/dist/sdk/server/apis/bundle-diff.js +0 -51
  150. package/dist/sdk/server/apis/data.js +0 -44
  151. package/dist/sdk/server/apis/fs.js +0 -28
  152. package/dist/sdk/server/apis/graph.js +0 -116
  153. package/dist/sdk/server/apis/index.js +0 -11
  154. package/dist/sdk/server/apis/loader.js +0 -120
  155. package/dist/sdk/server/apis/plugin.js +0 -39
  156. package/dist/sdk/server/apis/project.js +0 -59
  157. package/dist/sdk/server/apis/renderer.js +0 -33
  158. package/dist/sdk/server/apis/resolver.js +0 -38
  159. package/dist/sdk/server/client.js +0 -8
  160. package/dist/sdk/server/fakeServer.js +0 -12
  161. package/dist/sdk/server/index.js +0 -292
  162. package/dist/sdk/server/json-body.js +0 -150
  163. package/dist/sdk/server/router.js +0 -83
  164. package/dist/sdk/server/security.js +0 -47
  165. package/dist/sdk/server/socket/api.js +0 -22
  166. package/dist/sdk/server/socket/index.js +0 -166
  167. package/dist/sdk/server/utils.js +0 -19
  168. package/dist/sdk/utils/base.js +0 -22
  169. package/dist/sdk/utils/constant.js +0 -4
  170. package/dist/sdk/utils/index.js +0 -4
  171. package/dist/sdk/utils/openBrowser.js +0 -53
  172. package/dist/sdk/utils/upload.js +0 -6
  173. package/dist/sdk.js +0 -2
  174. package/dist/types/index.js +0 -4
  175. package/dist/types/loader.js +0 -1
  176. package/dist/types/plugin.js +0 -1
  177. package/dist/types/rules.js +0 -1
@@ -1,106 +0,0 @@
1
- import "node:module";
2
- import { parse } from "acorn";
3
- import { ECMAVersion } from "./types.js";
4
- import { asserts } from "./asserts.js";
5
- function isSameSemantics(node1, node2) {
6
- if (node1.type !== node2.type) return false;
7
- switch(node1.type){
8
- case 'CallExpression':
9
- {
10
- const next = node2;
11
- return node1.arguments.length === next.arguments.length && Boolean(node1.optional) === Boolean(next.optional) && isSameSemantics(node1.callee, next.callee) && node1.arguments.every((node, i)=>isSameSemantics(node, next.arguments[i]));
12
- }
13
- case 'MemberExpression':
14
- {
15
- const next = node2;
16
- return node1.computed === next.computed && Boolean(node1.optional) === Boolean(next.optional) && isSameSemantics(node1.object, next.object) && isSameSemantics(node1.property, next.property);
17
- }
18
- case 'Identifier':
19
- return node1.name === node2.name;
20
- case 'Literal':
21
- if (asserts.isSimpleLiteral(node1) && asserts.isSimpleLiteral(node2)) return node1.value === node2.value;
22
- return node1.raw === node2.raw;
23
- case 'ObjectExpression':
24
- {
25
- const next = node2;
26
- return node1.properties.length === next.properties.length && node1.properties.every((prop, i)=>isSameSemantics(prop, next.properties[i]));
27
- }
28
- case 'Property':
29
- {
30
- const next = node2;
31
- return node1.computed === next.computed && node1.kind === next.kind && node1.method === next.method && isSameSemantics(node1.key, next.key) && isSameSemantics(node1.value, next.value);
32
- }
33
- default:
34
- throw new Error(`Unknown node type: ${node1.type}`);
35
- }
36
- }
37
- function getDefaultImports(node) {
38
- return node.body.filter((statement)=>{
39
- if ('ImportDeclaration' !== statement.type) return false;
40
- const specifier = statement?.specifiers?.[0];
41
- if (specifier?.type === 'ImportDefaultSpecifier') return true;
42
- return false;
43
- });
44
- }
45
- function getIdentifierInPattern(name, node) {
46
- if (asserts.isIdentifier(node) && node.name === name) return node;
47
- if (asserts.isObjectPattern(node)) for (const prop of node.properties){
48
- if (asserts.isAssignmentProperty(prop)) return getIdentifierInPattern(name, prop.value);
49
- if (asserts.isRestElement(prop)) return getIdentifierInPattern(name, prop);
50
- }
51
- if (asserts.isArrayPattern(node)) {
52
- for (const el of node.elements)if (el) {
53
- const result = getIdentifierInPattern(name, el);
54
- if (result) return result;
55
- }
56
- }
57
- if (asserts.isRestElement(node)) return getIdentifierInPattern(name, node.argument);
58
- if (asserts.isAssignmentPattern(node)) return getIdentifierInPattern(name, node.left);
59
- }
60
- function getIdentifierInDeclaration(name, node) {
61
- function getId(node) {
62
- return asserts.isIdentifier(node.id) && node.id.name === name ? node.id : void 0;
63
- }
64
- if (asserts.isFunctionDeclaration(node)) return getId(node);
65
- if (asserts.isClassDeclaration(node)) return getId(node);
66
- if (asserts.isVariableDeclaration(node)) return node.declarations.find((item)=>getIdentifierInPattern(name, item.id))?.id;
67
- }
68
- function getIdentifierInImport(name, node) {
69
- if (asserts.isImportDeclaration(node)) {
70
- for (const specifier of node.specifiers ?? [])if (specifier.local.name === name) return specifier.local;
71
- }
72
- }
73
- function getIdentifierInExport(name, node) {
74
- if (asserts.isExportNamedDeclaration(node)) {
75
- if (node.declaration) return getIdentifierInDeclaration(name, node.declaration);
76
- for (const specifier of node.specifiers ?? [])if (specifier.exported.name === name) return specifier.exported;
77
- }
78
- if (asserts.isExportAllDeclaration(node) && node.exported) {
79
- if (node.exported.name === name) return node.exported;
80
- }
81
- }
82
- function canParse(code, ecmaVersion) {
83
- try {
84
- parse(code, {
85
- ecmaVersion,
86
- sourceType: 'number' == typeof ecmaVersion && ecmaVersion <= 5 ? "script" : 'module'
87
- });
88
- return true;
89
- } catch {
90
- return false;
91
- }
92
- }
93
- function isES5(code) {
94
- return canParse(code, 5);
95
- }
96
- function isES6(code) {
97
- return canParse(code, 6);
98
- }
99
- function detectECMAVersion(code) {
100
- if (isES6(code)) {
101
- if (isES5(code)) return ECMAVersion.ES5;
102
- return ECMAVersion.ES6;
103
- }
104
- return ECMAVersion.ES7P;
105
- }
106
- export { canParse, detectECMAVersion, getDefaultImports, getIdentifierInDeclaration, getIdentifierInExport, getIdentifierInImport, getIdentifierInPattern, isES5, isES6, isSameSemantics };
@@ -1,4 +0,0 @@
1
- import "node:module";
2
- export * from "./linter.js";
3
- export * from "./rule.js";
4
- export { rules } from "./rules/index.js";
@@ -1,36 +0,0 @@
1
- import "node:module";
2
- import { Linter } from "@rsdoctor/shared/types";
3
- import { Rule } from "./rule.js";
4
- import { rules as index_js_rules } from "./rules/index.js";
5
- import { toSeverity } from "./utils.js";
6
- class linter_Linter {
7
- getRules(ruleMap, extendRules, filterLevel) {
8
- const outside = extendRules.map((item)=>Rule.from(item));
9
- const rules = index_js_rules.map((item)=>new Rule(item)).concat(outside);
10
- rules.forEach((rule)=>{
11
- const config = ruleMap[rule.title];
12
- if (null != config) rule.setOption(config);
13
- });
14
- return rules.filter((rule)=>rule.match(filterLevel));
15
- }
16
- async validate(context) {
17
- const lintResult = {
18
- errors: [],
19
- replace: []
20
- };
21
- await Promise.all(this.rules.map(async (rule)=>{
22
- const result = await rule.validate(context);
23
- lintResult.errors.push(...result.errors);
24
- lintResult.replace.push(...result.replace);
25
- }));
26
- return lintResult;
27
- }
28
- async afterValidate(context) {
29
- await Promise.all(this.rules.map((rule)=>rule.afterValidate(context)));
30
- }
31
- constructor({ rules, extends: extendRules, level } = {}){
32
- this.rules = [];
33
- this.rules = this.getRules(rules ?? {}, extendRules ?? [], toSeverity(level ?? 'Error', Linter.Severity.Error));
34
- }
35
- }
36
- export { Linter as LinterType, linter_Linter as Linter };
@@ -1,101 +0,0 @@
1
- import "node:module";
2
- import { Linter, Rule } from "@rsdoctor/shared/types";
3
- import { Lodash } from "../common/index.js";
4
- import { noop, toSeverity } from "./utils.js";
5
- class rule_Rule {
6
- static from(data) {
7
- return new rule_Rule({
8
- check: data.check,
9
- onCheckEnd: data.onCheckEnd,
10
- meta: {
11
- ...data.meta,
12
- code: Rule.RuleMessageCodeEnumerated.Extend,
13
- severity: toSeverity(data.meta.severity, Linter.Severity.Warn)
14
- }
15
- });
16
- }
17
- get code() {
18
- return this.meta.code;
19
- }
20
- get title() {
21
- return this.meta.title;
22
- }
23
- get severity() {
24
- return this._severity;
25
- }
26
- get config() {
27
- return this._config;
28
- }
29
- get category() {
30
- return this.meta.category;
31
- }
32
- setOption(opt) {
33
- let severity;
34
- let config;
35
- if (Array.isArray(opt)) {
36
- severity = toSeverity(opt[0], this.meta.severity);
37
- config = opt[1];
38
- } else {
39
- severity = toSeverity(opt, this.meta.severity);
40
- config = void 0;
41
- }
42
- this._severity = severity;
43
- this._config = Lodash.isPlainObject(config) ? {
44
- ...this.meta.defaultConfig,
45
- ...config
46
- } : config || this.meta.defaultConfig;
47
- }
48
- match(level) {
49
- if (level === Linter.Severity.Ignore || this.severity === Linter.Severity.Ignore) return false;
50
- if (level === Linter.Severity.Error) return this.severity === Linter.Severity.Error || this.severity === Linter.Severity.Warn;
51
- if (level === Linter.Severity.Warn) return this.severity === Linter.Severity.Warn;
52
- return false;
53
- }
54
- async validate(context) {
55
- const errors = [];
56
- const replace = [];
57
- const report = (data, remove)=>{
58
- if (remove) replace.push(remove);
59
- const severity = data.severity ? toSeverity(data.severity, this.severity) : this.severity;
60
- const error = {
61
- ...data,
62
- code: this.code,
63
- severity,
64
- category: this.category,
65
- title: this.title.toUpperCase()
66
- };
67
- if (severity !== Linter.Severity.Ignore) errors.push(error);
68
- };
69
- await this.check({
70
- ...context,
71
- ruleConfig: this.config,
72
- report
73
- });
74
- return {
75
- errors,
76
- replace
77
- };
78
- }
79
- async afterValidate({ hooks, validateResult, data }) {
80
- if (this.onCheckEnd === noop) return;
81
- await this.onCheckEnd({
82
- data: {
83
- ...data,
84
- ruleConfig: this.config
85
- },
86
- hooks,
87
- validateResult
88
- });
89
- }
90
- constructor(data){
91
- this.check = data.check;
92
- this.meta = data.meta;
93
- this.onCheckEnd = 'function' == typeof data.onCheckEnd ? data.onCheckEnd : noop;
94
- this._severity = this.meta.severity;
95
- this._config = this.meta.defaultConfig;
96
- }
97
- }
98
- function defineRule(ruleCreator) {
99
- return ruleCreator();
100
- }
101
- export { defineRule, rule_Rule as Rule };
@@ -1,50 +0,0 @@
1
- import "node:module";
2
- import { Linter } from "@rsdoctor/shared/types";
3
- import { defineRule } from "../../rule.js";
4
- const title = 'cjs-require';
5
- const CJS_REQUIRE_TYPE = 'cjs require';
6
- const NODE_MODULES_PATH_REGEXP = /[/\\]node_modules[/\\]/;
7
- function isNodeModulesPath(modulePath) {
8
- return NODE_MODULES_PATH_REGEXP.test(modulePath);
9
- }
10
- const rule = defineRule(()=>({
11
- meta: {
12
- code: 'E1008',
13
- title: title,
14
- category: 'bundle',
15
- severity: Linter.Severity.Warn,
16
- defaultConfig: {
17
- ignore: []
18
- }
19
- },
20
- check ({ moduleGraph, report, ruleConfig }) {
21
- const dependencies = moduleGraph.getDependencies();
22
- for (const dep of dependencies){
23
- if (dep.typeString !== CJS_REQUIRE_TYPE) continue;
24
- const issuerPath = dep.module.path;
25
- if (isNodeModulesPath(issuerPath)) continue;
26
- const requiredModule = dep.dependency;
27
- if (ruleConfig.ignore.some((pattern)=>issuerPath.includes(pattern) || requiredModule.path.includes(pattern))) continue;
28
- const detail = {
29
- type: title,
30
- issuerModule: {
31
- id: dep.module.id,
32
- path: dep.module.path,
33
- identifier: dep.module.identifier
34
- },
35
- requiredModule: {
36
- id: requiredModule.id,
37
- path: requiredModule.path,
38
- identifier: requiredModule.identifier
39
- },
40
- request: dep.request
41
- };
42
- const message = `"${issuerPath}" uses \`require('${dep.request}')\` (CJS require) which prevents tree-shaking of the entire module "${requiredModule.path}". Consider using \`require('${dep.request}').property\` or ESM \`import\` instead.`;
43
- report({
44
- message,
45
- detail
46
- });
47
- }
48
- }
49
- }));
50
- export { rule };
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,41 +0,0 @@
1
- import "node:module";
2
- import { Linter } from "@rsdoctor/shared/types";
3
- import { defineRule } from "../../rule.js";
4
- import { getErrorMsgForDupPckChunks } from "./utils.js";
5
- import { uniq } from "../../../collection.js";
6
- const title = 'cross-chunks-package';
7
- const rule = defineRule(()=>({
8
- meta: {
9
- code: 'E1002',
10
- title: title,
11
- category: 'bundle',
12
- severity: Linter.Severity.Warn,
13
- defaultConfig: {
14
- ignore: []
15
- }
16
- },
17
- check ({ packageGraph, report }) {
18
- const packages = packageGraph.getPackages().filter((pkg)=>(pkg.duplicates?.length ?? 0) > 0);
19
- for (const pkg of packages){
20
- const duplicates = pkg.duplicates;
21
- const detail = {
22
- type: title,
23
- chunks: duplicates,
24
- package: {
25
- name: pkg.name,
26
- id: pkg.id,
27
- size: pkg.getSize(),
28
- version: pkg.version
29
- }
30
- };
31
- const chunks = [];
32
- duplicates.forEach((dup)=>chunks.push(...dup.chunks.map((ck)=>ck.name)));
33
- const message = getErrorMsgForDupPckChunks(uniq(chunks), pkg.name);
34
- report({
35
- message,
36
- detail
37
- });
38
- }
39
- }
40
- }));
41
- export { rule };
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,7 +0,0 @@
1
- import "node:module";
2
- function getErrorMsgForDupPckChunks(chunks, pkgName) {
3
- let message = `The same package ${pkgName} was bundled into different chunks:\n`;
4
- for (const chunkName of chunks)message += ` ${chunkName}\n`;
5
- return message.slice(0, -1);
6
- }
7
- export { getErrorMsgForDupPckChunks };
@@ -1,83 +0,0 @@
1
- import "node:module";
2
- import { builtinModules } from "module";
3
- import { Linter } from "@rsdoctor/shared/types";
4
- import { getDocument, parser } from "../../../rule-utils/index.js";
5
- import { getDefaultImportByRequest, getFixData, getSourceRangeFromTransformedOffset, hasSameLeftInAssignStatement } from "./utils.js";
6
- import { defineRule } from "../../rule.js";
7
- const title = 'default-import-check';
8
- const rule = defineRule(()=>{
9
- const parserOpt = {
10
- ecmaVersion: 6
11
- };
12
- const exportsDefault = parser.internal.parseExpressionAt('exports.default', 0, parserOpt);
13
- const moduleExportsDefault = parser.internal.parseExpressionAt('module.exports.default', 0, parserOpt);
14
- return {
15
- meta: {
16
- code: 'E1005',
17
- title: title,
18
- category: 'compile',
19
- severity: Linter.Severity.Warn,
20
- defaultConfig: {
21
- ignore: []
22
- }
23
- },
24
- check ({ moduleGraph, report, ruleConfig }) {
25
- const dependencyWithNode = moduleGraph.getDependencies().filter((dep)=>'dynamic' === dep.meta.exportsType).filter((dep)=>!dep.module.path.includes('node_modules')).filter((dep)=>!ruleConfig.ignore.includes(dep.request) && !builtinModules.includes(dep.request)).filter((dep)=>dep.dependency.meta.hasSetEsModuleStatement).filter((dep)=>dep.dependency.getProgram()).filter((dep)=>!hasSameLeftInAssignStatement(dep.dependency.getProgram(), [
26
- exportsDefault,
27
- moduleExportsDefault
28
- ])).map((dependency)=>{
29
- const { module, request } = dependency;
30
- const node = module.getProgram() && getDefaultImportByRequest(module.getProgram(), request);
31
- return node ? {
32
- dependency,
33
- node
34
- } : {};
35
- }).filter((dep)=>dep?.dependency);
36
- for (const { dependency, node } of dependencyWithNode){
37
- if (!dependency) continue;
38
- const document = getSourceRangeFromTransformedOffset(dependency.module, node);
39
- if (!document) continue;
40
- const message = 'Do not to use the default import when you import a cjs module.';
41
- const canFix = !document.isTransformed && !document.path.includes('node_modules');
42
- if (canFix) {
43
- const fixData = getFixData(dependency.module, node, document.range);
44
- const detail = {
45
- type: 'code-change',
46
- file: {
47
- path: document.path,
48
- actual: document.content,
49
- line: document.range.start.line,
50
- expected: getDocument(document.content).edit(fixData)
51
- }
52
- };
53
- report({
54
- message,
55
- document,
56
- detail,
57
- suggestions: {
58
- description: 'Use namespace import instead.',
59
- fixData
60
- }
61
- });
62
- } else {
63
- const detail = {
64
- type: 'code-view',
65
- file: {
66
- path: document.path,
67
- content: document.content,
68
- ranges: [
69
- node.loc
70
- ]
71
- }
72
- };
73
- report({
74
- message,
75
- document,
76
- detail
77
- });
78
- }
79
- }
80
- }
81
- };
82
- });
83
- export { rule };
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,52 +0,0 @@
1
- import "node:module";
2
- import { getDocument, parser } from "../../../rule-utils/index.js";
3
- import { Lodash } from "../../../common/index.js";
4
- function getDefaultImportByRequest(node, request) {
5
- return parser.utils.getDefaultImports(node).find((decl)=>decl.source.value === request);
6
- }
7
- function hasSameLeftInAssignStatement(node, compare) {
8
- return node.body.filter(parser.asserts.isExpressionStatement).map((node)=>node.expression).filter(parser.asserts.isAssignmentExpression).map((node)=>node.left).find((node)=>compare.some((item)=>parser.utils.isSameSemantics(node, item)));
9
- }
10
- function importDeclarationToString(node) {
11
- const defaultSpecifier = node.specifiers[0];
12
- const rawRequest = (node.source.raw ?? '').trim();
13
- return `import * as ${defaultSpecifier.local.name} from ${rawRequest}`;
14
- }
15
- function getFixData(module, node, originalRange) {
16
- const { source, transformed } = module.getSource();
17
- const document = getDocument(source);
18
- const newImportText = importDeclarationToString(node);
19
- const oldText = transformed.substring(node.start, node.end);
20
- const hasLastSemi = ';' === oldText[oldText.length - 1];
21
- return {
22
- start: document.offsetAt(originalRange.start),
23
- end: document.offsetAt(originalRange.end),
24
- newText: hasLastSemi ? `${newImportText};` : newImportText
25
- };
26
- }
27
- function getSourceRangeFromTransformedOffset(module, node) {
28
- const source = module.getSource();
29
- const sourceMap = module.getSourceMap();
30
- const transformedStart = node.loc.start;
31
- const transformedEnd = node.loc.end;
32
- if (!transformedStart || !transformedEnd) return;
33
- const transformedReport = {
34
- path: module.path,
35
- content: source.transformed,
36
- isTransformed: true,
37
- range: {
38
- start: transformedStart,
39
- end: transformedEnd
40
- }
41
- };
42
- if (!sourceMap) return transformedReport;
43
- const sourceRange = module.getSourceRange(node.loc);
44
- if (Lodash.isUndefined(sourceRange?.start.line) || Lodash.isUndefined(sourceRange?.start.column) || Lodash.isUndefined(sourceRange?.end?.line) || Lodash.isUndefined(sourceRange?.end?.column)) return transformedReport;
45
- return {
46
- path: module.path,
47
- isTransformed: false,
48
- content: source.source,
49
- range: sourceRange
50
- };
51
- }
52
- export { getDefaultImportByRequest, getFixData, getSourceRangeFromTransformedOffset, hasSameLeftInAssignStatement, importDeclarationToString };
@@ -1,39 +0,0 @@
1
- import "node:module";
2
- import { Linter } from "@rsdoctor/shared/types";
3
- import { diff, gt } from "semver";
4
- import { getErrorDetail, getErrorMsg } from "./utils.js";
5
- import { defineRule } from "../../rule.js";
6
- import * as __rspack_external__types_js_b06c0ce5 from "./types.js";
7
- const title = 'duplicate-package';
8
- const { CheckVersionMap: CheckVersionMap } = __rspack_external__types_js_b06c0ce5;
9
- const rule = defineRule(()=>({
10
- meta: {
11
- code: 'E1001',
12
- title: title,
13
- category: 'bundle',
14
- severity: Linter.Severity.Warn,
15
- defaultConfig: {
16
- checkVersion: 'major',
17
- ignore: []
18
- }
19
- },
20
- check ({ packageGraph, report, root, ruleConfig }) {
21
- const checkVersion = CheckVersionMap[ruleConfig.checkVersion];
22
- const packages = packageGraph.getDuplicatePackages().filter((pkg)=>!ruleConfig.ignore.includes(pkg[0].name)).map((pkgs)=>pkgs.filter((current)=>{
23
- const check = pkgs.reduce((ans, pkg)=>ans | CheckVersionMap[diff(current.version, pkg.version) ?? 'null'], 0);
24
- return check <= checkVersion;
25
- }).sort((_packA, _packB)=>gt(_packA.version, _packB.version) ? 1 : -1)).filter((pkgs)=>pkgs.length > 1 && pkgs.filter((pkg)=>pkg.getSize().parsedSize > 0).length > 1);
26
- for (const pkg of packages){
27
- const message = getErrorMsg(pkg, root);
28
- const detail = {
29
- type: 'package-relation',
30
- packages: pkg.map((item)=>getErrorDetail(item, packageGraph))
31
- };
32
- report({
33
- message,
34
- detail
35
- });
36
- }
37
- }
38
- }));
39
- export { rule };
@@ -1,24 +0,0 @@
1
- import "node:module";
2
- var types_CheckVersion = /*#__PURE__*/ function(CheckVersion) {
3
- CheckVersion[CheckVersion["null"] = 0] = "null";
4
- CheckVersion[CheckVersion["prerelease"] = 1] = "prerelease";
5
- CheckVersion[CheckVersion["prepatch"] = 16] = "prepatch";
6
- CheckVersion[CheckVersion["patch"] = 256] = "patch";
7
- CheckVersion[CheckVersion["preminor"] = 4096] = "preminor";
8
- CheckVersion[CheckVersion["minor"] = 65536] = "minor";
9
- CheckVersion[CheckVersion["premajor"] = 1048576] = "premajor";
10
- CheckVersion[CheckVersion["major"] = 16777216] = "major";
11
- return CheckVersion;
12
- }({});
13
- var types_CheckVersionMap = /*#__PURE__*/ function(CheckVersionMap) {
14
- CheckVersionMap[CheckVersionMap["null"] = 0] = "null";
15
- CheckVersionMap[CheckVersionMap["prerelease"] = 1] = "prerelease";
16
- CheckVersionMap[CheckVersionMap["prepatch"] = 17] = "prepatch";
17
- CheckVersionMap[CheckVersionMap["patch"] = 273] = "patch";
18
- CheckVersionMap[CheckVersionMap["preminor"] = 4369] = "preminor";
19
- CheckVersionMap[CheckVersionMap["minor"] = 69905] = "minor";
20
- CheckVersionMap[CheckVersionMap["premajor"] = 1118481] = "premajor";
21
- CheckVersionMap[CheckVersionMap["major"] = 17895697] = "major";
22
- return CheckVersionMap;
23
- }({});
24
- export { types_CheckVersion as CheckVersion, types_CheckVersionMap as CheckVersionMap };
@@ -1,38 +0,0 @@
1
- import "node:module";
2
- import path from "path";
3
- import { filesize } from "filesize";
4
- function getErrorMsg(packages, root) {
5
- const pkgName = packages[0].name;
6
- let message = `Multiple packages of ${pkgName} found:\n`;
7
- for (const pkg of packages)message += ` ${pkg.version} ${filesize(pkg.getSize().parsedSize)} ${path.relative(root, pkg.root)}\n`;
8
- return message.slice(0, -1);
9
- }
10
- function getErrorDetail(pkg, pkgGraph) {
11
- function getImported(pkg, ans) {
12
- const dependencies = pkgGraph.getDependenciesFromPackage(pkg);
13
- for (const dep of dependencies)if (dep.refDependency) {
14
- if (!ans.some((dep)=>dep.dependency === pkg)) {
15
- if (!dep.package) return ans.concat(dep);
16
- return getImported(dep.package, ans.concat(dep));
17
- }
18
- }
19
- return ans;
20
- }
21
- const packageImportLinks = getImported(pkg, []);
22
- return {
23
- target: {
24
- name: pkg.name,
25
- version: pkg.version,
26
- root: pkg.root
27
- },
28
- targetSize: {
29
- sourceSize: pkg.getSize().sourceSize,
30
- parsedSize: pkg.getSize().parsedSize
31
- },
32
- dependencies: packageImportLinks.map((item)=>({
33
- dependencyId: item.refDependency.id,
34
- group: item.package ? `${item.package.name}@${item.package.version}` : void 0
35
- }))
36
- };
37
- }
38
- export { getErrorDetail, getErrorMsg };
@@ -1,53 +0,0 @@
1
- import "node:module";
2
- import path from "path";
3
- import { CheckSyntax } from "@rsbuild/plugin-check-syntax";
4
- import { loadConfig } from "browserslist-load-config";
5
- import { defineRule } from "../../rule.js";
6
- import { Linter } from "@rsdoctor/shared/types";
7
- const title = 'ecma-version-check';
8
- const rule = defineRule(()=>({
9
- meta: {
10
- code: 'E1004',
11
- title: title,
12
- category: 'bundle',
13
- severity: Linter.Severity.Warn,
14
- defaultConfig: {
15
- ecmaVersion: void 0,
16
- targets: []
17
- }
18
- },
19
- async check ({ chunkGraph, report, ruleConfig, root, configs }) {
20
- for (const asset of chunkGraph.getAssets()){
21
- if ('.js' !== path.extname(asset.path) && '.bundle' !== path.extname(asset.path)) continue;
22
- const browserslistConfig = loadConfig({
23
- path: root,
24
- env: 'production'
25
- });
26
- const { exclude, excludeOutput, targets, ecmaVersion } = ruleConfig;
27
- const finalTargets = targets || browserslistConfig || [];
28
- if (!finalTargets.length && !ecmaVersion) return;
29
- const buildConfig = configs[0]?.config;
30
- const context = buildConfig?.context || root;
31
- const checkSyntax = new CheckSyntax({
32
- exclude,
33
- excludeOutput,
34
- ecmaVersion,
35
- rootPath: context,
36
- targets: finalTargets
37
- });
38
- const outputDir = buildConfig?.output?.path || path.resolve(root, 'dist');
39
- const assetPath = path.resolve(outputDir, asset.path);
40
- await checkSyntax.check(assetPath, asset.content);
41
- checkSyntax.errors.forEach((err)=>{
42
- report({
43
- message: `Found syntax that does not match "ecmaVersion <= ${checkSyntax.ecmaVersion}"`,
44
- detail: {
45
- error: err,
46
- type: 'link'
47
- }
48
- });
49
- });
50
- }
51
- }
52
- }));
53
- export { rule };
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,6 +0,0 @@
1
- import "node:module";
2
- function getVersionNumber(ECMAString) {
3
- const version = ECMAString.match(/\d/);
4
- return version?.length ? Number(version[0]) : void 0;
5
- }
6
- export { getVersionNumber };