@rsdoctor/core 1.5.3 → 1.5.5
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 +11 -1
- package/dist/build-utils/build/module-graph/rspack/transform.js +12 -3
- 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 +40 -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.cjs +3 -2
- package/dist/rules/rules/duplicate-package/index.d.ts +2 -2
- package/dist/rules/rules/duplicate-package/index.js +11 -5
- 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/esm-resolved-to-cjs/index.cjs +144 -0
- package/dist/rules/rules/esm-resolved-to-cjs/index.d.ts +4 -0
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +100 -0
- package/dist/rules/rules/esm-resolved-to-cjs/types.cjs +18 -0
- package/dist/rules/rules/esm-resolved-to-cjs/types.d.ts +8 -0
- package/dist/rules/rules/esm-resolved-to-cjs/types.js +1 -0
- package/dist/rules/rules/index.cjs +7 -1
- package/dist/rules/rules/index.d.ts +1 -1
- package/dist/rules/rules/index.js +8 -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,82 @@
|
|
|
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 = 'cjs-require';
|
|
32
|
+
const CJS_REQUIRE_TYPE = 'cjs require';
|
|
33
|
+
function isNodeModulesPath(modulePath) {
|
|
34
|
+
return modulePath.includes('/node_modules/');
|
|
35
|
+
}
|
|
36
|
+
const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
37
|
+
meta: {
|
|
38
|
+
code: 'E1008',
|
|
39
|
+
title,
|
|
40
|
+
category: 'bundle',
|
|
41
|
+
severity: types_namespaceObject.Linter.Severity.Warn,
|
|
42
|
+
defaultConfig: {
|
|
43
|
+
ignore: []
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
check ({ moduleGraph, report, ruleConfig }) {
|
|
47
|
+
const dependencies = moduleGraph.getDependencies();
|
|
48
|
+
for (const dep of dependencies){
|
|
49
|
+
if (dep.typeString !== CJS_REQUIRE_TYPE) continue;
|
|
50
|
+
const issuerPath = dep.module.path;
|
|
51
|
+
if (isNodeModulesPath(issuerPath)) continue;
|
|
52
|
+
const requiredModule = dep.dependency;
|
|
53
|
+
if (ruleConfig.ignore.some((pattern)=>issuerPath.includes(pattern) || requiredModule.path.includes(pattern))) continue;
|
|
54
|
+
const detail = {
|
|
55
|
+
type: title,
|
|
56
|
+
issuerModule: {
|
|
57
|
+
id: dep.module.id,
|
|
58
|
+
path: dep.module.path,
|
|
59
|
+
webpackId: dep.module.webpackId
|
|
60
|
+
},
|
|
61
|
+
requiredModule: {
|
|
62
|
+
id: requiredModule.id,
|
|
63
|
+
path: requiredModule.path,
|
|
64
|
+
webpackId: requiredModule.webpackId
|
|
65
|
+
},
|
|
66
|
+
request: dep.request
|
|
67
|
+
};
|
|
68
|
+
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.`;
|
|
69
|
+
report({
|
|
70
|
+
message,
|
|
71
|
+
detail
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
exports.rule = __webpack_exports__.rule;
|
|
77
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
78
|
+
"rule"
|
|
79
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
80
|
+
Object.defineProperty(exports, '__esModule', {
|
|
81
|
+
value: true
|
|
82
|
+
});
|
|
@@ -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";
|
|
@@ -32,6 +32,7 @@ const external_types_cjs_namespaceObject = require("./types.cjs");
|
|
|
32
32
|
const external_utils_cjs_namespaceObject = require("./utils.cjs");
|
|
33
33
|
const external_rule_cjs_namespaceObject = require("../../rule.cjs");
|
|
34
34
|
const title = 'duplicate-package';
|
|
35
|
+
const { CheckVersionMap } = external_types_cjs_namespaceObject;
|
|
35
36
|
const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
36
37
|
meta: {
|
|
37
38
|
code: 'E1001',
|
|
@@ -44,9 +45,9 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
44
45
|
}
|
|
45
46
|
},
|
|
46
47
|
check ({ packageGraph, report, root, ruleConfig }) {
|
|
47
|
-
const checkVersion =
|
|
48
|
+
const checkVersion = CheckVersionMap[ruleConfig.checkVersion];
|
|
48
49
|
const packages = packageGraph.getDuplicatePackages().filter((pkg)=>!ruleConfig.ignore.includes(pkg[0].name)).map((pkgs)=>pkgs.filter((current)=>{
|
|
49
|
-
const check = pkgs.reduce((ans, pkg)=>ans |
|
|
50
|
+
const check = pkgs.reduce((ans, pkg)=>ans | CheckVersionMap[(0, external_semver_namespaceObject.diff)(current.version, pkg.version) ?? 'null'], 0);
|
|
50
51
|
return check <= checkVersion;
|
|
51
52
|
}).sort((_packA, _packB)=>(0, external_semver_namespaceObject.gt)(_packA.version, _packB.version) ? 1 : -1)).filter((pkgs)=>pkgs.length > 1 && pkgs.filter((pkg)=>pkg.getSize().parsedSize > 0).length > 1);
|
|
52
53
|
for (const pkg of packages){
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Linter } from '@rsdoctor/types';
|
|
2
|
-
import
|
|
2
|
+
import * as duplicatePackageTypes from './types.js';
|
|
3
3
|
export type { Config, CheckVersion } from './types.js';
|
|
4
|
-
export declare const rule: Linter.RuleData<Config, "duplicate-package">;
|
|
4
|
+
export declare const rule: Linter.RuleData<duplicatePackageTypes.Config, "duplicate-package">;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { __webpack_require__ } from "../../../rslib-runtime.js";
|
|
3
3
|
import { Linter } from "@rsdoctor/types";
|
|
4
4
|
import { diff, gt } from "semver";
|
|
5
5
|
import { CheckVersionMap } from "./types.js";
|
|
6
6
|
import { getErrorDetail, getErrorMsg } from "./utils.js";
|
|
7
7
|
import { defineRule } from "../../rule.js";
|
|
8
|
+
var external_types_js_namespaceObject = {};
|
|
9
|
+
__webpack_require__.r(external_types_js_namespaceObject);
|
|
10
|
+
__webpack_require__.d(external_types_js_namespaceObject, {
|
|
11
|
+
CheckVersionMap: ()=>CheckVersionMap
|
|
12
|
+
});
|
|
8
13
|
const title = 'duplicate-package';
|
|
14
|
+
const { CheckVersionMap: duplicate_package_CheckVersionMap } = external_types_js_namespaceObject;
|
|
9
15
|
const rule = defineRule(()=>({
|
|
10
16
|
meta: {
|
|
11
17
|
code: 'E1001',
|
|
12
|
-
title,
|
|
18
|
+
title: title,
|
|
13
19
|
category: 'bundle',
|
|
14
20
|
severity: Linter.Severity.Warn,
|
|
15
21
|
defaultConfig: {
|
|
@@ -18,9 +24,9 @@ const rule = defineRule(()=>({
|
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
check ({ packageGraph, report, root, ruleConfig }) {
|
|
21
|
-
const checkVersion =
|
|
27
|
+
const checkVersion = duplicate_package_CheckVersionMap[ruleConfig.checkVersion];
|
|
22
28
|
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 |
|
|
29
|
+
const check = pkgs.reduce((ans, pkg)=>ans | duplicate_package_CheckVersionMap[diff(current.version, pkg.version) ?? 'null'], 0);
|
|
24
30
|
return check <= checkVersion;
|
|
25
31
|
}).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
32
|
for (const pkg of packages){
|
|
@@ -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";
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
rule: ()=>rule
|
|
37
|
+
});
|
|
38
|
+
const external_fs_namespaceObject = require("fs");
|
|
39
|
+
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
|
|
40
|
+
const external_path_namespaceObject = require("path");
|
|
41
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
42
|
+
const types_namespaceObject = require("@rsdoctor/types");
|
|
43
|
+
const external_rule_cjs_namespaceObject = require("../../rule.cjs");
|
|
44
|
+
const title = 'esm-resolved-to-cjs';
|
|
45
|
+
function extractEsmEntry(pkgJson, pkgRoot) {
|
|
46
|
+
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
47
|
+
if (null !== exportsField && 'object' == typeof exportsField) {
|
|
48
|
+
const exports1 = exportsField;
|
|
49
|
+
const dotEntry = exports1['.'];
|
|
50
|
+
if (null !== dotEntry && 'object' == typeof dotEntry) {
|
|
51
|
+
const dot = dotEntry;
|
|
52
|
+
const importEntry = dot['import'];
|
|
53
|
+
if ('string' == typeof importEntry) return external_path_default().resolve(pkgRoot, importEntry);
|
|
54
|
+
if (null !== importEntry && 'object' == typeof importEntry) {
|
|
55
|
+
const nested = importEntry['default'];
|
|
56
|
+
if ('string' == typeof nested) return external_path_default().resolve(pkgRoot, nested);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const topImport = exports1['import'];
|
|
60
|
+
if ('string' == typeof topImport) return external_path_default().resolve(pkgRoot, topImport);
|
|
61
|
+
if (null !== topImport && 'object' == typeof topImport) {
|
|
62
|
+
const nested = topImport['default'];
|
|
63
|
+
if ('string' == typeof nested) return external_path_default().resolve(pkgRoot, nested);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if ('string' == typeof moduleField) return external_path_default().resolve(pkgRoot, moduleField);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
70
|
+
meta: {
|
|
71
|
+
code: 'E1009',
|
|
72
|
+
title,
|
|
73
|
+
category: 'bundle',
|
|
74
|
+
severity: types_namespaceObject.Linter.Severity.Warn,
|
|
75
|
+
defaultConfig: {
|
|
76
|
+
ignore: []
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
check ({ moduleGraph, packageGraph, report, ruleConfig }) {
|
|
80
|
+
const pkgJsonCache = new Map();
|
|
81
|
+
const readPkgJson = (pkgRoot)=>{
|
|
82
|
+
if (pkgJsonCache.has(pkgRoot)) return pkgJsonCache.get(pkgRoot);
|
|
83
|
+
try {
|
|
84
|
+
const raw = external_fs_default().readFileSync(external_path_default().join(pkgRoot, 'package.json'), 'utf-8');
|
|
85
|
+
const parsed = JSON.parse(raw);
|
|
86
|
+
pkgJsonCache.set(pkgRoot, parsed);
|
|
87
|
+
return parsed;
|
|
88
|
+
} catch {
|
|
89
|
+
pkgJsonCache.set(pkgRoot, null);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const groups = new Map();
|
|
94
|
+
const inNodeModules = /[/\\]node_modules[/\\]/;
|
|
95
|
+
for (const dep of moduleGraph.getDependencies()){
|
|
96
|
+
if (dep.kind !== types_namespaceObject.SDK.DependencyKind.ImportStatement || inNodeModules.test(dep.module.path) || !inNodeModules.test(dep.dependency.path) || dep.dependency.meta.strictHarmonyModule || ruleConfig.ignore.some((p)=>dep.request.includes(p))) continue;
|
|
97
|
+
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
98
|
+
const esmEntry = pkg?.root && !ruleConfig.ignore.some((p)=>pkg.name.includes(p)) && readPkgJson(pkg.root) && extractEsmEntry(readPkgJson(pkg.root), pkg.root);
|
|
99
|
+
if (!esmEntry) continue;
|
|
100
|
+
const groupKey = `${pkg.name}::${dep.dependency.path}`;
|
|
101
|
+
const issuer = {
|
|
102
|
+
id: dep.module.id,
|
|
103
|
+
path: dep.module.path,
|
|
104
|
+
request: dep.request
|
|
105
|
+
};
|
|
106
|
+
if (groups.has(groupKey)) groups.get(groupKey).issuers.push(issuer);
|
|
107
|
+
else groups.set(groupKey, {
|
|
108
|
+
packageName: pkg.name,
|
|
109
|
+
packageVersion: pkg.version,
|
|
110
|
+
esmEntry,
|
|
111
|
+
resolvedModule: {
|
|
112
|
+
id: dep.dependency.id,
|
|
113
|
+
path: dep.dependency.path,
|
|
114
|
+
webpackId: dep.dependency.webpackId
|
|
115
|
+
},
|
|
116
|
+
issuers: [
|
|
117
|
+
issuer
|
|
118
|
+
]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
for (const group of groups.values()){
|
|
122
|
+
const detail = {
|
|
123
|
+
type: title,
|
|
124
|
+
packageName: group.packageName,
|
|
125
|
+
packageVersion: group.packageVersion,
|
|
126
|
+
esmEntry: group.esmEntry,
|
|
127
|
+
resolvedModule: group.resolvedModule,
|
|
128
|
+
issuers: group.issuers
|
|
129
|
+
};
|
|
130
|
+
const message = `"${group.packageName}" declares an ESM entry ("${group.esmEntry}") but was resolved to CJS by ${group.issuers.length} ESM import(s). Check your bundler's \`resolve.mainFields\` or \`resolve.conditionNames\` config.`;
|
|
131
|
+
report({
|
|
132
|
+
message,
|
|
133
|
+
detail
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
exports.rule = __webpack_exports__.rule;
|
|
139
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
140
|
+
"rule"
|
|
141
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
142
|
+
Object.defineProperty(exports, '__esModule', {
|
|
143
|
+
value: true
|
|
144
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { Linter, SDK } from "@rsdoctor/types";
|
|
5
|
+
import { defineRule } from "../../rule.js";
|
|
6
|
+
const title = 'esm-resolved-to-cjs';
|
|
7
|
+
function extractEsmEntry(pkgJson, pkgRoot) {
|
|
8
|
+
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
9
|
+
if (null !== exportsField && 'object' == typeof exportsField) {
|
|
10
|
+
const exports = exportsField;
|
|
11
|
+
const dotEntry = exports['.'];
|
|
12
|
+
if (null !== dotEntry && 'object' == typeof dotEntry) {
|
|
13
|
+
const dot = dotEntry;
|
|
14
|
+
const importEntry = dot['import'];
|
|
15
|
+
if ('string' == typeof importEntry) return path.resolve(pkgRoot, importEntry);
|
|
16
|
+
if (null !== importEntry && 'object' == typeof importEntry) {
|
|
17
|
+
const nested = importEntry['default'];
|
|
18
|
+
if ('string' == typeof nested) return path.resolve(pkgRoot, nested);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const topImport = exports['import'];
|
|
22
|
+
if ('string' == typeof topImport) return path.resolve(pkgRoot, topImport);
|
|
23
|
+
if (null !== topImport && 'object' == typeof topImport) {
|
|
24
|
+
const nested = topImport['default'];
|
|
25
|
+
if ('string' == typeof nested) return path.resolve(pkgRoot, nested);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if ('string' == typeof moduleField) return path.resolve(pkgRoot, moduleField);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const rule = defineRule(()=>({
|
|
32
|
+
meta: {
|
|
33
|
+
code: 'E1009',
|
|
34
|
+
title: title,
|
|
35
|
+
category: 'bundle',
|
|
36
|
+
severity: Linter.Severity.Warn,
|
|
37
|
+
defaultConfig: {
|
|
38
|
+
ignore: []
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
check ({ moduleGraph, packageGraph, report, ruleConfig }) {
|
|
42
|
+
const pkgJsonCache = new Map();
|
|
43
|
+
const readPkgJson = (pkgRoot)=>{
|
|
44
|
+
if (pkgJsonCache.has(pkgRoot)) return pkgJsonCache.get(pkgRoot);
|
|
45
|
+
try {
|
|
46
|
+
const raw = fs.readFileSync(path.join(pkgRoot, 'package.json'), 'utf-8');
|
|
47
|
+
const parsed = JSON.parse(raw);
|
|
48
|
+
pkgJsonCache.set(pkgRoot, parsed);
|
|
49
|
+
return parsed;
|
|
50
|
+
} catch {
|
|
51
|
+
pkgJsonCache.set(pkgRoot, null);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const groups = new Map();
|
|
56
|
+
const inNodeModules = /[/\\]node_modules[/\\]/;
|
|
57
|
+
for (const dep of moduleGraph.getDependencies()){
|
|
58
|
+
if (dep.kind !== SDK.DependencyKind.ImportStatement || inNodeModules.test(dep.module.path) || !inNodeModules.test(dep.dependency.path) || dep.dependency.meta.strictHarmonyModule || ruleConfig.ignore.some((p)=>dep.request.includes(p))) continue;
|
|
59
|
+
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
60
|
+
const esmEntry = pkg?.root && !ruleConfig.ignore.some((p)=>pkg.name.includes(p)) && readPkgJson(pkg.root) && extractEsmEntry(readPkgJson(pkg.root), pkg.root);
|
|
61
|
+
if (!esmEntry) continue;
|
|
62
|
+
const groupKey = `${pkg.name}::${dep.dependency.path}`;
|
|
63
|
+
const issuer = {
|
|
64
|
+
id: dep.module.id,
|
|
65
|
+
path: dep.module.path,
|
|
66
|
+
request: dep.request
|
|
67
|
+
};
|
|
68
|
+
if (groups.has(groupKey)) groups.get(groupKey).issuers.push(issuer);
|
|
69
|
+
else groups.set(groupKey, {
|
|
70
|
+
packageName: pkg.name,
|
|
71
|
+
packageVersion: pkg.version,
|
|
72
|
+
esmEntry,
|
|
73
|
+
resolvedModule: {
|
|
74
|
+
id: dep.dependency.id,
|
|
75
|
+
path: dep.dependency.path,
|
|
76
|
+
webpackId: dep.dependency.webpackId
|
|
77
|
+
},
|
|
78
|
+
issuers: [
|
|
79
|
+
issuer
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
for (const group of groups.values()){
|
|
84
|
+
const detail = {
|
|
85
|
+
type: title,
|
|
86
|
+
packageName: group.packageName,
|
|
87
|
+
packageVersion: group.packageVersion,
|
|
88
|
+
esmEntry: group.esmEntry,
|
|
89
|
+
resolvedModule: group.resolvedModule,
|
|
90
|
+
issuers: group.issuers
|
|
91
|
+
};
|
|
92
|
+
const message = `"${group.packageName}" declares an ESM entry ("${group.esmEntry}") but was resolved to CJS by ${group.issuers.length} ESM import(s). Check your bundler's \`resolve.mainFields\` or \`resolve.conditionNames\` config.`;
|
|
93
|
+
report({
|
|
94
|
+
message,
|
|
95
|
+
detail
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
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";
|
|
@@ -32,13 +32,19 @@ 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");
|
|
37
|
+
const external_esm_resolved_to_cjs_index_cjs_namespaceObject = require("./esm-resolved-to-cjs/index.cjs");
|
|
35
38
|
const rules = [
|
|
36
39
|
index_cjs_namespaceObject.rule,
|
|
37
40
|
external_default_import_check_index_cjs_namespaceObject.rule,
|
|
38
41
|
external_loader_performance_optimization_index_cjs_namespaceObject.rule,
|
|
39
42
|
external_ecma_version_check_index_cjs_namespaceObject.rule,
|
|
40
43
|
external_cross_chunks_package_index_cjs_namespaceObject.rule,
|
|
41
|
-
external_module_mixed_chunks_index_cjs_namespaceObject.rule
|
|
44
|
+
external_module_mixed_chunks_index_cjs_namespaceObject.rule,
|
|
45
|
+
external_side_effects_only_imports_index_cjs_namespaceObject.rule,
|
|
46
|
+
external_cjs_require_index_cjs_namespaceObject.rule,
|
|
47
|
+
external_esm_resolved_to_cjs_index_cjs_namespaceObject.rule
|
|
42
48
|
];
|
|
43
49
|
exports.rules = __webpack_exports__.rules;
|
|
44
50
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|