@rsdoctor/core 1.5.3 → 1.5.4
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.
- package/dist/build-utils/build/chunks/assetsModules.js +1 -2
- package/dist/build-utils/build/chunks/chunkTransform.js +1 -2
- package/dist/build-utils/build/chunks/index.js +1 -2
- package/dist/build-utils/build/chunks/rspack/transform.js +1 -2
- package/dist/build-utils/build/index.js +1 -2
- package/dist/build-utils/build/loader/index.js +1 -2
- package/dist/build-utils/build/loader/probeLoader.js +3 -3
- package/dist/build-utils/build/loader/probeLoaderPlugin.js +1 -2
- package/dist/build-utils/build/module-graph/index.js +1 -2
- package/dist/build-utils/build/module-graph/parser.js +1 -2
- package/dist/build-utils/build/module-graph/rspack/transform.cjs +10 -0
- package/dist/build-utils/build/module-graph/rspack/transform.js +11 -2
- package/dist/build-utils/build/module-graph/transform.js +1 -2
- package/dist/build-utils/build/module-graph/treeShaking.js +1 -2
- package/dist/build-utils/build/module-graph/utils.js +1 -2
- package/dist/build-utils/build/module-graph/webpack/transform.js +1 -2
- package/dist/build-utils/build/utils/index.js +1 -2
- package/dist/build-utils/build/utils/loader.js +7 -16
- package/dist/build-utils/build/utils/parseBundle.js +1 -2
- package/dist/build-utils/build/utils/plugin.js +1 -2
- package/dist/build-utils/index.js +1 -2
- package/dist/index.js +1 -2
- package/dist/inner-plugins/constants.js +1 -2
- package/dist/inner-plugins/index.js +1 -2
- package/dist/inner-plugins/loaders/proxy.js +3 -3
- package/dist/inner-plugins/plugins/base.js +1 -2
- package/dist/inner-plugins/plugins/bundle.js +1 -2
- package/dist/inner-plugins/plugins/bundleTagPlugin.js +1 -2
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +1 -2
- package/dist/inner-plugins/plugins/errors.js +1 -2
- package/dist/inner-plugins/plugins/index.js +1 -2
- package/dist/inner-plugins/plugins/loader.js +2 -2
- package/dist/inner-plugins/plugins/plugins.js +1 -2
- package/dist/inner-plugins/plugins/progress.js +1 -2
- package/dist/inner-plugins/plugins/resolver.js +1 -2
- package/dist/inner-plugins/plugins/rspack.js +1 -2
- package/dist/inner-plugins/plugins/rules.js +1 -2
- package/dist/inner-plugins/plugins/sourcemapTool.js +1 -2
- package/dist/inner-plugins/plugins/summary.js +1 -2
- package/dist/inner-plugins/utils/circleDetect.js +1 -2
- package/dist/inner-plugins/utils/config.js +1 -2
- package/dist/inner-plugins/utils/index.js +1 -2
- package/dist/inner-plugins/utils/loader.js +1 -2
- package/dist/inner-plugins/utils/normalize-config.js +1 -2
- package/dist/inner-plugins/utils/plugin-common.js +1 -2
- package/dist/inner-plugins/utils/plugin.js +1 -2
- package/dist/inner-plugins/utils/sdk.js +1 -2
- package/dist/rslib-runtime.js +19 -0
- package/dist/rules/index.js +2 -4
- package/dist/rules/linter.js +2 -3
- package/dist/rules/rule.js +2 -3
- package/dist/rules/rules/cjs-require/index.cjs +82 -0
- package/dist/rules/rules/cjs-require/index.d.ts +4 -0
- package/dist/rules/rules/cjs-require/index.js +49 -0
- package/dist/rules/rules/cjs-require/types.cjs +18 -0
- package/dist/rules/rules/cjs-require/types.d.ts +4 -0
- package/dist/rules/rules/cjs-require/types.js +1 -0
- package/dist/rules/rules/cross-chunks-package/index.js +2 -3
- package/dist/rules/rules/cross-chunks-package/types.js +1 -2
- package/dist/rules/rules/cross-chunks-package/utils.js +1 -2
- package/dist/rules/rules/default-import-check/index.js +2 -3
- package/dist/rules/rules/default-import-check/types.js +1 -2
- package/dist/rules/rules/default-import-check/utils.js +1 -2
- package/dist/rules/rules/duplicate-package/index.js +2 -3
- package/dist/rules/rules/duplicate-package/types.js +1 -2
- package/dist/rules/rules/duplicate-package/utils.js +1 -2
- package/dist/rules/rules/ecma-version-check/index.js +2 -3
- package/dist/rules/rules/ecma-version-check/types.js +1 -2
- package/dist/rules/rules/ecma-version-check/utils.js +1 -2
- package/dist/rules/rules/index.cjs +5 -1
- package/dist/rules/rules/index.d.ts +1 -1
- package/dist/rules/rules/index.js +6 -3
- package/dist/rules/rules/loader-performance-optimization/index.js +2 -3
- package/dist/rules/rules/loader-performance-optimization/types.js +1 -2
- package/dist/rules/rules/loader-performance-optimization/utils.js +1 -2
- package/dist/rules/rules/module-mixed-chunks/index.js +2 -3
- package/dist/rules/rules/module-mixed-chunks/types.js +1 -2
- package/dist/rules/rules/side-effects-only-imports/index.cjs +114 -0
- package/dist/rules/rules/side-effects-only-imports/index.d.ts +4 -0
- package/dist/rules/rules/side-effects-only-imports/index.js +81 -0
- package/dist/rules/rules/side-effects-only-imports/types.cjs +18 -0
- package/dist/rules/rules/side-effects-only-imports/types.d.ts +9 -0
- package/dist/rules/rules/side-effects-only-imports/types.js +1 -0
- package/dist/rules/utils.js +1 -2
- package/dist/types/chunks.js +1 -2
- package/dist/types/index.js +1 -2
- package/dist/types/loader.js +1 -2
- package/dist/types/plugin.js +1 -2
- package/dist/types/rules.js +1 -2
- package/package.json +12 -12
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { Linter } from "@rsdoctor/types";
|
|
3
|
+
import { defineRule } from "../../rule.js";
|
|
4
|
+
const title = 'cjs-require';
|
|
5
|
+
const CJS_REQUIRE_TYPE = 'cjs require';
|
|
6
|
+
function isNodeModulesPath(modulePath) {
|
|
7
|
+
return modulePath.includes('/node_modules/');
|
|
8
|
+
}
|
|
9
|
+
const rule = defineRule(()=>({
|
|
10
|
+
meta: {
|
|
11
|
+
code: 'E1008',
|
|
12
|
+
title: title,
|
|
13
|
+
category: 'bundle',
|
|
14
|
+
severity: Linter.Severity.Warn,
|
|
15
|
+
defaultConfig: {
|
|
16
|
+
ignore: []
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
check ({ moduleGraph, report, ruleConfig }) {
|
|
20
|
+
const dependencies = moduleGraph.getDependencies();
|
|
21
|
+
for (const dep of dependencies){
|
|
22
|
+
if (dep.typeString !== CJS_REQUIRE_TYPE) continue;
|
|
23
|
+
const issuerPath = dep.module.path;
|
|
24
|
+
if (isNodeModulesPath(issuerPath)) continue;
|
|
25
|
+
const requiredModule = dep.dependency;
|
|
26
|
+
if (ruleConfig.ignore.some((pattern)=>issuerPath.includes(pattern) || requiredModule.path.includes(pattern))) continue;
|
|
27
|
+
const detail = {
|
|
28
|
+
type: title,
|
|
29
|
+
issuerModule: {
|
|
30
|
+
id: dep.module.id,
|
|
31
|
+
path: dep.module.path,
|
|
32
|
+
webpackId: dep.module.webpackId
|
|
33
|
+
},
|
|
34
|
+
requiredModule: {
|
|
35
|
+
id: requiredModule.id,
|
|
36
|
+
path: requiredModule.path,
|
|
37
|
+
webpackId: requiredModule.webpackId
|
|
38
|
+
},
|
|
39
|
+
request: dep.request
|
|
40
|
+
};
|
|
41
|
+
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.`;
|
|
42
|
+
report({
|
|
43
|
+
message,
|
|
44
|
+
detail
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
export { rule };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
import { Linter } from "@rsdoctor/types";
|
|
4
3
|
import { defineRule } from "../../rule.js";
|
|
5
4
|
import { getErrorMsgForDupPckChunks } from "./utils.js";
|
|
@@ -8,7 +7,7 @@ const title = 'cross-chunks-package';
|
|
|
8
7
|
const rule = defineRule(()=>({
|
|
9
8
|
meta: {
|
|
10
9
|
code: 'E1002',
|
|
11
|
-
title,
|
|
10
|
+
title: title,
|
|
12
11
|
category: 'bundle',
|
|
13
12
|
severity: Linter.Severity.Warn,
|
|
14
13
|
defaultConfig: {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
function getErrorMsgForDupPckChunks(chunks, pkgName) {
|
|
4
3
|
let message = `The same package ${pkgName} was bundled into different chunks:\n`;
|
|
5
4
|
for (const chunkName of chunks)message += ` ${chunkName}\n`;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
import { builtinModules } from "module";
|
|
4
3
|
import { Linter } from "@rsdoctor/types";
|
|
5
4
|
import { getDocument, parser } from "@rsdoctor/utils/ruleUtils";
|
|
@@ -15,7 +14,7 @@ const rule = defineRule(()=>{
|
|
|
15
14
|
return {
|
|
16
15
|
meta: {
|
|
17
16
|
code: 'E1005',
|
|
18
|
-
title,
|
|
17
|
+
title: title,
|
|
19
18
|
category: 'compile',
|
|
20
19
|
severity: Linter.Severity.Warn,
|
|
21
20
|
defaultConfig: {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
import { Linter } from "@rsdoctor/types";
|
|
4
3
|
import { diff, gt } from "semver";
|
|
5
4
|
import { CheckVersionMap } from "./types.js";
|
|
@@ -9,7 +8,7 @@ const title = 'duplicate-package';
|
|
|
9
8
|
const rule = defineRule(()=>({
|
|
10
9
|
meta: {
|
|
11
10
|
code: 'E1001',
|
|
12
|
-
title,
|
|
11
|
+
title: title,
|
|
13
12
|
category: 'bundle',
|
|
14
13
|
severity: Linter.Severity.Warn,
|
|
15
14
|
defaultConfig: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import { CheckSyntax } from "@rsbuild/plugin-check-syntax";
|
|
5
4
|
import { loadConfig } from "browserslist-load-config";
|
|
@@ -9,7 +8,7 @@ const title = 'ecma-version-check';
|
|
|
9
8
|
const rule = defineRule(()=>({
|
|
10
9
|
meta: {
|
|
11
10
|
code: 'E1004',
|
|
12
|
-
title,
|
|
11
|
+
title: title,
|
|
13
12
|
category: 'bundle',
|
|
14
13
|
severity: Linter.Severity.Warn,
|
|
15
14
|
defaultConfig: {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
@@ -32,13 +32,17 @@ const external_loader_performance_optimization_index_cjs_namespaceObject = requi
|
|
|
32
32
|
const external_ecma_version_check_index_cjs_namespaceObject = require("./ecma-version-check/index.cjs");
|
|
33
33
|
const external_cross_chunks_package_index_cjs_namespaceObject = require("./cross-chunks-package/index.cjs");
|
|
34
34
|
const external_module_mixed_chunks_index_cjs_namespaceObject = require("./module-mixed-chunks/index.cjs");
|
|
35
|
+
const external_side_effects_only_imports_index_cjs_namespaceObject = require("./side-effects-only-imports/index.cjs");
|
|
36
|
+
const external_cjs_require_index_cjs_namespaceObject = require("./cjs-require/index.cjs");
|
|
35
37
|
const rules = [
|
|
36
38
|
index_cjs_namespaceObject.rule,
|
|
37
39
|
external_default_import_check_index_cjs_namespaceObject.rule,
|
|
38
40
|
external_loader_performance_optimization_index_cjs_namespaceObject.rule,
|
|
39
41
|
external_ecma_version_check_index_cjs_namespaceObject.rule,
|
|
40
42
|
external_cross_chunks_package_index_cjs_namespaceObject.rule,
|
|
41
|
-
external_module_mixed_chunks_index_cjs_namespaceObject.rule
|
|
43
|
+
external_module_mixed_chunks_index_cjs_namespaceObject.rule,
|
|
44
|
+
external_side_effects_only_imports_index_cjs_namespaceObject.rule,
|
|
45
|
+
external_cjs_require_index_cjs_namespaceObject.rule
|
|
42
46
|
];
|
|
43
47
|
exports.rules = __webpack_exports__.rules;
|
|
44
48
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const rules: (import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./duplicate-package/index.js").Config, "duplicate-package"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./default-import-check/index.js").Config, "default-import-check"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./loader-performance-optimization/index.js").Config, "loader-performance-optimization"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./ecma-version-check/index.js").Config, "ecma-version-check"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./cross-chunks-package/index.js").Config, "cross-chunks-package"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./module-mixed-chunks/index.js").Config, "module-mixed-chunks">)[];
|
|
1
|
+
export declare const rules: (import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./duplicate-package/index.js").Config, "duplicate-package"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./default-import-check/index.js").Config, "default-import-check"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./loader-performance-optimization/index.js").Config, "loader-performance-optimization"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./ecma-version-check/index.js").Config, "ecma-version-check"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./cross-chunks-package/index.js").Config, "cross-chunks-package"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./module-mixed-chunks/index.js").Config, "module-mixed-chunks"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./side-effects-only-imports/index.js").Config, "tree-shaking-side-effects-only"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./cjs-require/index.js").Config, "cjs-require">)[];
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
import { rule } from "./duplicate-package/index.js";
|
|
4
3
|
import { rule as index_js_rule } from "./default-import-check/index.js";
|
|
5
4
|
import { rule as external_loader_performance_optimization_index_js_rule } from "./loader-performance-optimization/index.js";
|
|
6
5
|
import { rule as external_ecma_version_check_index_js_rule } from "./ecma-version-check/index.js";
|
|
7
6
|
import { rule as external_cross_chunks_package_index_js_rule } from "./cross-chunks-package/index.js";
|
|
8
7
|
import { rule as external_module_mixed_chunks_index_js_rule } from "./module-mixed-chunks/index.js";
|
|
8
|
+
import { rule as external_side_effects_only_imports_index_js_rule } from "./side-effects-only-imports/index.js";
|
|
9
|
+
import { rule as external_cjs_require_index_js_rule } from "./cjs-require/index.js";
|
|
9
10
|
const rules = [
|
|
10
11
|
rule,
|
|
11
12
|
index_js_rule,
|
|
12
13
|
external_loader_performance_optimization_index_js_rule,
|
|
13
14
|
external_ecma_version_check_index_js_rule,
|
|
14
15
|
external_cross_chunks_package_index_js_rule,
|
|
15
|
-
external_module_mixed_chunks_index_js_rule
|
|
16
|
+
external_module_mixed_chunks_index_js_rule,
|
|
17
|
+
external_side_effects_only_imports_index_js_rule,
|
|
18
|
+
external_cjs_require_index_js_rule
|
|
16
19
|
];
|
|
17
20
|
export { rules };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
import { Linter } from "@rsdoctor/types";
|
|
4
3
|
import { Loader, Time } from "@rsdoctor/utils/common";
|
|
5
4
|
import { defineRule } from "../../rule.js";
|
|
@@ -8,7 +7,7 @@ const title = 'loader-performance-optimization';
|
|
|
8
7
|
const rule = defineRule(()=>({
|
|
9
8
|
meta: {
|
|
10
9
|
code: 'E1003',
|
|
11
|
-
title,
|
|
10
|
+
title: title,
|
|
12
11
|
category: 'compile',
|
|
13
12
|
severity: Linter.Severity.Warn,
|
|
14
13
|
defaultConfig: {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
3
2
|
import { Linter } from "@rsdoctor/types";
|
|
4
3
|
import { defineRule } from "../../rule.js";
|
|
5
4
|
const title = 'module-mixed-chunks';
|
|
6
5
|
const rule = defineRule(()=>({
|
|
7
6
|
meta: {
|
|
8
7
|
code: 'E1006',
|
|
9
|
-
title,
|
|
8
|
+
title: title,
|
|
10
9
|
category: 'bundle',
|
|
11
10
|
severity: Linter.Severity.Warn,
|
|
12
11
|
defaultConfig: {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
rule: ()=>rule
|
|
28
|
+
});
|
|
29
|
+
const types_namespaceObject = require("@rsdoctor/types");
|
|
30
|
+
const external_rule_cjs_namespaceObject = require("../../rule.cjs");
|
|
31
|
+
const title = 'tree-shaking-side-effects-only';
|
|
32
|
+
function isSideEffectDependencyType(dependencyType) {
|
|
33
|
+
return 'esm import' === dependencyType.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
function isImportSpecifierDependencyType(dependencyType) {
|
|
36
|
+
return 'esm import specifier' === dependencyType.toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
function isStyleFile(modulePath) {
|
|
39
|
+
const normalizedPath = modulePath.split('?')[0].split('#')[0].toLowerCase();
|
|
40
|
+
return /\.(css|less|sass|scss|styl|stylus|pcss|postcss)$/.test(normalizedPath);
|
|
41
|
+
}
|
|
42
|
+
function shouldCheckModule(modulePath, include) {
|
|
43
|
+
const isNodeModulesModule = modulePath.includes('/node_modules/');
|
|
44
|
+
if (!isNodeModulesModule) return true;
|
|
45
|
+
return include.some((pattern)=>modulePath.includes(pattern));
|
|
46
|
+
}
|
|
47
|
+
function getSideEffectsImportConnections(connections, fallbackOriginModule) {
|
|
48
|
+
const byOrigin = new Map();
|
|
49
|
+
for (const connection of connections){
|
|
50
|
+
const originModule = connection.originModule ?? fallbackOriginModule;
|
|
51
|
+
const existing = byOrigin.get(originModule);
|
|
52
|
+
if (existing) existing.push(connection);
|
|
53
|
+
else byOrigin.set(originModule, [
|
|
54
|
+
connection
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
const result = [];
|
|
58
|
+
for (const group of byOrigin.values()){
|
|
59
|
+
const hasEsmImport = group.some((connection)=>isSideEffectDependencyType(connection.dependencyType));
|
|
60
|
+
const hasEsmImportSpecifier = group.some((connection)=>isImportSpecifierDependencyType(connection.dependencyType));
|
|
61
|
+
if (hasEsmImport && !hasEsmImportSpecifier) result.push(...group.filter((connection)=>isSideEffectDependencyType(connection.dependencyType)));
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
66
|
+
meta: {
|
|
67
|
+
code: 'E1007',
|
|
68
|
+
title,
|
|
69
|
+
category: 'bundle',
|
|
70
|
+
severity: types_namespaceObject.Linter.Severity.Warn,
|
|
71
|
+
defaultConfig: {
|
|
72
|
+
ignore: [],
|
|
73
|
+
include: []
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
check ({ moduleGraph, report, ruleConfig }) {
|
|
77
|
+
const precomputed = moduleGraph.getConnectionsOnlyImports();
|
|
78
|
+
for (const item of precomputed){
|
|
79
|
+
if (isStyleFile(item.modulePath)) continue;
|
|
80
|
+
if (ruleConfig.ignore.some((pattern)=>item.modulePath.includes(pattern))) continue;
|
|
81
|
+
if (!shouldCheckModule(item.modulePath, ruleConfig.include)) continue;
|
|
82
|
+
const module = moduleGraph.getModuleById(item.moduleUkey);
|
|
83
|
+
if (!module) continue;
|
|
84
|
+
const sideEffectConnections = getSideEffectsImportConnections(item.connections, item.moduleUkey);
|
|
85
|
+
if (!sideEffectConnections.length) continue;
|
|
86
|
+
const detail = {
|
|
87
|
+
type: title,
|
|
88
|
+
module: {
|
|
89
|
+
id: module.id,
|
|
90
|
+
path: module.path,
|
|
91
|
+
webpackId: module.webpackId
|
|
92
|
+
},
|
|
93
|
+
connections: sideEffectConnections.map((c)=>({
|
|
94
|
+
originModule: c.originModule ?? module.id,
|
|
95
|
+
dependencyType: c.dependencyType,
|
|
96
|
+
userRequest: c.userRequest
|
|
97
|
+
}))
|
|
98
|
+
};
|
|
99
|
+
const importerCount = new Set(sideEffectConnections.map((c)=>c.originModule ?? module.id)).size;
|
|
100
|
+
const message = `Module "${item.modulePath}" is only imported for its side effects by ${importerCount} importer(s). This may indicate an unintended tree-shaking failure causing redundant bundle output.`;
|
|
101
|
+
report({
|
|
102
|
+
message,
|
|
103
|
+
detail
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}));
|
|
108
|
+
exports.rule = __webpack_exports__.rule;
|
|
109
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
110
|
+
"rule"
|
|
111
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
112
|
+
Object.defineProperty(exports, '__esModule', {
|
|
113
|
+
value: true
|
|
114
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { Linter } from "@rsdoctor/types";
|
|
3
|
+
import { defineRule } from "../../rule.js";
|
|
4
|
+
const title = 'tree-shaking-side-effects-only';
|
|
5
|
+
function isSideEffectDependencyType(dependencyType) {
|
|
6
|
+
return 'esm import' === dependencyType.toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
function isImportSpecifierDependencyType(dependencyType) {
|
|
9
|
+
return 'esm import specifier' === dependencyType.toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
function isStyleFile(modulePath) {
|
|
12
|
+
const normalizedPath = modulePath.split('?')[0].split('#')[0].toLowerCase();
|
|
13
|
+
return /\.(css|less|sass|scss|styl|stylus|pcss|postcss)$/.test(normalizedPath);
|
|
14
|
+
}
|
|
15
|
+
function shouldCheckModule(modulePath, include) {
|
|
16
|
+
const isNodeModulesModule = modulePath.includes('/node_modules/');
|
|
17
|
+
if (!isNodeModulesModule) return true;
|
|
18
|
+
return include.some((pattern)=>modulePath.includes(pattern));
|
|
19
|
+
}
|
|
20
|
+
function getSideEffectsImportConnections(connections, fallbackOriginModule) {
|
|
21
|
+
const byOrigin = new Map();
|
|
22
|
+
for (const connection of connections){
|
|
23
|
+
const originModule = connection.originModule ?? fallbackOriginModule;
|
|
24
|
+
const existing = byOrigin.get(originModule);
|
|
25
|
+
if (existing) existing.push(connection);
|
|
26
|
+
else byOrigin.set(originModule, [
|
|
27
|
+
connection
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
const result = [];
|
|
31
|
+
for (const group of byOrigin.values()){
|
|
32
|
+
const hasEsmImport = group.some((connection)=>isSideEffectDependencyType(connection.dependencyType));
|
|
33
|
+
const hasEsmImportSpecifier = group.some((connection)=>isImportSpecifierDependencyType(connection.dependencyType));
|
|
34
|
+
if (hasEsmImport && !hasEsmImportSpecifier) result.push(...group.filter((connection)=>isSideEffectDependencyType(connection.dependencyType)));
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
const rule = defineRule(()=>({
|
|
39
|
+
meta: {
|
|
40
|
+
code: 'E1007',
|
|
41
|
+
title: title,
|
|
42
|
+
category: 'bundle',
|
|
43
|
+
severity: Linter.Severity.Warn,
|
|
44
|
+
defaultConfig: {
|
|
45
|
+
ignore: [],
|
|
46
|
+
include: []
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
check ({ moduleGraph, report, ruleConfig }) {
|
|
50
|
+
const precomputed = moduleGraph.getConnectionsOnlyImports();
|
|
51
|
+
for (const item of precomputed){
|
|
52
|
+
if (isStyleFile(item.modulePath)) continue;
|
|
53
|
+
if (ruleConfig.ignore.some((pattern)=>item.modulePath.includes(pattern))) continue;
|
|
54
|
+
if (!shouldCheckModule(item.modulePath, ruleConfig.include)) continue;
|
|
55
|
+
const module = moduleGraph.getModuleById(item.moduleUkey);
|
|
56
|
+
if (!module) continue;
|
|
57
|
+
const sideEffectConnections = getSideEffectsImportConnections(item.connections, item.moduleUkey);
|
|
58
|
+
if (!sideEffectConnections.length) continue;
|
|
59
|
+
const detail = {
|
|
60
|
+
type: title,
|
|
61
|
+
module: {
|
|
62
|
+
id: module.id,
|
|
63
|
+
path: module.path,
|
|
64
|
+
webpackId: module.webpackId
|
|
65
|
+
},
|
|
66
|
+
connections: sideEffectConnections.map((c)=>({
|
|
67
|
+
originModule: c.originModule ?? module.id,
|
|
68
|
+
dependencyType: c.dependencyType,
|
|
69
|
+
userRequest: c.userRequest
|
|
70
|
+
}))
|
|
71
|
+
};
|
|
72
|
+
const importerCount = new Set(sideEffectConnections.map((c)=>c.originModule ?? module.id)).size;
|
|
73
|
+
const message = `Module "${item.modulePath}" is only imported for its side effects by ${importerCount} importer(s). This may indicate an unintended tree-shaking failure causing redundant bundle output.`;
|
|
74
|
+
report({
|
|
75
|
+
message,
|
|
76
|
+
detail
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
export { rule };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
package/dist/rules/utils.js
CHANGED
package/dist/types/chunks.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
package/dist/types/index.js
CHANGED
package/dist/types/loader.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
package/dist/types/plugin.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
package/dist/types/rules.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
1
|
+
import "node:module";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -63,32 +63,32 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"browserslist-load-config": "^1.0.1",
|
|
65
65
|
"@rsbuild/plugin-check-syntax": "1.6.1",
|
|
66
|
-
"@rspack/resolver": "0.2.
|
|
67
|
-
"es-toolkit": "^1.
|
|
66
|
+
"@rspack/resolver": "0.2.8",
|
|
67
|
+
"es-toolkit": "^1.45.1",
|
|
68
68
|
"filesize": "^10.1.6",
|
|
69
69
|
"fs-extra": "^11.1.1",
|
|
70
70
|
"semver": "^7.7.4",
|
|
71
71
|
"source-map": "^0.7.6",
|
|
72
|
-
"@rsdoctor/graph": "1.5.
|
|
73
|
-
"@rsdoctor/
|
|
74
|
-
"@rsdoctor/utils": "1.5.
|
|
75
|
-
"@rsdoctor/
|
|
72
|
+
"@rsdoctor/graph": "1.5.4",
|
|
73
|
+
"@rsdoctor/sdk": "1.5.4",
|
|
74
|
+
"@rsdoctor/utils": "1.5.4",
|
|
75
|
+
"@rsdoctor/types": "1.5.4"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"axios": "^1.13.6",
|
|
79
|
-
"@rspack/core": "2.0.0-
|
|
79
|
+
"@rspack/core": "2.0.0-canary-20260116",
|
|
80
80
|
"@types/fs-extra": "^11.0.4",
|
|
81
81
|
"@types/node": "^22.8.1",
|
|
82
82
|
"@types/node-fetch": "^2.6.13",
|
|
83
83
|
"@types/semver": "^7.7.1",
|
|
84
|
-
"@types/tapable": "2.
|
|
85
|
-
"babel-loader": "10.
|
|
86
|
-
"prebundle": "1.6.
|
|
84
|
+
"@types/tapable": "2.3.0",
|
|
85
|
+
"babel-loader": "10.1.1",
|
|
86
|
+
"prebundle": "1.6.4",
|
|
87
87
|
"string-loader": "0.0.1",
|
|
88
88
|
"ts-loader": "^9.5.4",
|
|
89
89
|
"tslib": "2.8.1",
|
|
90
90
|
"typescript": "^5.9.2",
|
|
91
|
-
"webpack": "^5.105.
|
|
91
|
+
"webpack": "^5.105.4",
|
|
92
92
|
"@scripts/test-helper": "0.1.1"
|
|
93
93
|
},
|
|
94
94
|
"publishConfig": {
|