@rsdoctor/core 1.5.8 → 1.5.9
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/module-graph/webpack/transform.cjs +1 -1
- package/dist/build-utils/build/module-graph/webpack/transform.js +1 -1
- package/dist/build-utils/build/utils/loader.cjs +2 -3
- package/dist/build-utils/build/utils/loader.js +2 -3
- package/dist/inner-plugins/loaders/proxy.cjs +10 -4
- package/dist/inner-plugins/loaders/proxy.js +10 -4
- package/dist/inner-plugins/plugins/bundleTagPlugin.cjs +3 -3
- package/dist/inner-plugins/plugins/bundleTagPlugin.js +3 -3
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.cjs +1 -1
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +1 -1
- package/dist/inner-plugins/plugins/sourcemapTool.cjs +2 -2
- package/dist/inner-plugins/plugins/sourcemapTool.js +2 -2
- package/dist/inner-plugins/utils/plugin.cjs +7 -7
- package/dist/inner-plugins/utils/plugin.js +7 -7
- package/dist/rules/rule.cjs +1 -1
- package/dist/rules/rule.js +1 -1
- package/dist/rules/rules/esm-resolved-to-cjs/index.cjs +30 -2
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +30 -2
- package/package.json +5 -5
|
@@ -155,7 +155,7 @@ async function appendModuleGraphByCompilation(compilation, graph, features, cont
|
|
|
155
155
|
await Promise.all(allModules.map((module)=>appendModuleData(module, webpackGraph, graph, fileSystemInfo, features, context)));
|
|
156
156
|
graph_namespaceObject.ModuleGraphTrans.removeNoImportStyle(graph);
|
|
157
157
|
return graph;
|
|
158
|
-
} catch
|
|
158
|
+
} catch {
|
|
159
159
|
return graph;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -117,7 +117,7 @@ async function appendModuleGraphByCompilation(compilation, graph, features, cont
|
|
|
117
117
|
await Promise.all(allModules.map((module)=>appendModuleData(module, webpackGraph, graph, fileSystemInfo, features, context)));
|
|
118
118
|
ModuleGraphTrans.removeNoImportStyle(graph);
|
|
119
119
|
return graph;
|
|
120
|
-
} catch
|
|
120
|
+
} catch {
|
|
121
121
|
return graph;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -168,7 +168,7 @@ var __webpack_exports__ = {};
|
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
function isESMLoader(r) {
|
|
171
|
-
|
|
171
|
+
const _loaderName = 'object' == typeof r && 'string' == typeof r?.loader ? r.loader : 'string' == typeof r ? r : '';
|
|
172
172
|
if (!_loaderName) return false;
|
|
173
173
|
const isPath = external_node_path_default().isAbsolute(_loaderName) || _loaderName.startsWith('./') || _loaderName.startsWith('../');
|
|
174
174
|
if (isPath) {
|
|
@@ -302,8 +302,7 @@ var __webpack_exports__ = {};
|
|
|
302
302
|
common_namespaceObject.Loader.LoaderInternalPropertyName
|
|
303
303
|
]) : Reflect.get(target, key, receiver);
|
|
304
304
|
default:
|
|
305
|
-
|
|
306
|
-
return _target[key];
|
|
305
|
+
return target[key];
|
|
307
306
|
}
|
|
308
307
|
},
|
|
309
308
|
set (target, key, value, receiver) {
|
|
@@ -113,7 +113,7 @@ function mapEachRules(rules, callback) {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
function isESMLoader(r) {
|
|
116
|
-
|
|
116
|
+
const _loaderName = 'object' == typeof r && 'string' == typeof r?.loader ? r.loader : 'string' == typeof r ? r : '';
|
|
117
117
|
if (!_loaderName) return false;
|
|
118
118
|
const isPath = node_path.isAbsolute(_loaderName) || _loaderName.startsWith('./') || _loaderName.startsWith('../');
|
|
119
119
|
if (isPath) {
|
|
@@ -247,8 +247,7 @@ function createLoaderContextTrap(final) {
|
|
|
247
247
|
Loader.LoaderInternalPropertyName
|
|
248
248
|
]) : Reflect.get(target, key, receiver);
|
|
249
249
|
default:
|
|
250
|
-
|
|
251
|
-
return _target[key];
|
|
250
|
+
return target[key];
|
|
252
251
|
}
|
|
253
252
|
},
|
|
254
253
|
set (target, key, value, receiver) {
|
|
@@ -36,8 +36,11 @@ const loaderModule = function(...args) {
|
|
|
36
36
|
const mod = (0, external_utils_index_cjs_namespaceObject.getOriginLoaderModule)(this);
|
|
37
37
|
if (mod.default) {
|
|
38
38
|
if (false === mod.raw && Buffer.isBuffer(args[0])) args[0] = args[0].toString();
|
|
39
|
-
let start;
|
|
40
|
-
let startHRTime
|
|
39
|
+
let start = 0;
|
|
40
|
+
let startHRTime = [
|
|
41
|
+
0,
|
|
42
|
+
0
|
|
43
|
+
];
|
|
41
44
|
const trap = index_cjs_namespaceObject.Utils.createLoaderContextTrap.call(this, (err, res, sourceMap)=>{
|
|
42
45
|
(0, external_utils_index_cjs_namespaceObject.reportLoader)(this, start, startHRTime, false, false, args[0].toString(), err, res, sourceMap);
|
|
43
46
|
});
|
|
@@ -61,8 +64,11 @@ const pitch = function() {
|
|
|
61
64
|
this.cacheable(false);
|
|
62
65
|
const mod = (0, external_utils_index_cjs_namespaceObject.getOriginLoaderModule)(this);
|
|
63
66
|
if (mod.pitch && 'function' == typeof mod.pitch) {
|
|
64
|
-
let start;
|
|
65
|
-
let startHRTime
|
|
67
|
+
let start = 0;
|
|
68
|
+
let startHRTime = [
|
|
69
|
+
0,
|
|
70
|
+
0
|
|
71
|
+
];
|
|
66
72
|
const trap = index_cjs_namespaceObject.Utils.createLoaderContextTrap.call(this, (err, res)=>{
|
|
67
73
|
(0, external_utils_index_cjs_namespaceObject.reportLoader)(this, start, startHRTime, true, false, err ? 'Loader Pitch Async Error' : '', err, res);
|
|
68
74
|
});
|
|
@@ -7,8 +7,11 @@ const loaderModule = function(...args) {
|
|
|
7
7
|
const mod = getOriginLoaderModule(this);
|
|
8
8
|
if (mod.default) {
|
|
9
9
|
if (false === mod.raw && Buffer.isBuffer(args[0])) args[0] = args[0].toString();
|
|
10
|
-
let start;
|
|
11
|
-
let startHRTime
|
|
10
|
+
let start = 0;
|
|
11
|
+
let startHRTime = [
|
|
12
|
+
0,
|
|
13
|
+
0
|
|
14
|
+
];
|
|
12
15
|
const trap = Utils.createLoaderContextTrap.call(this, (err, res, sourceMap)=>{
|
|
13
16
|
reportLoader(this, start, startHRTime, false, false, args[0].toString(), err, res, sourceMap);
|
|
14
17
|
});
|
|
@@ -32,8 +35,11 @@ const pitch = function() {
|
|
|
32
35
|
this.cacheable(false);
|
|
33
36
|
const mod = getOriginLoaderModule(this);
|
|
34
37
|
if (mod.pitch && 'function' == typeof mod.pitch) {
|
|
35
|
-
let start;
|
|
36
|
-
let startHRTime
|
|
38
|
+
let start = 0;
|
|
39
|
+
let startHRTime = [
|
|
40
|
+
0,
|
|
41
|
+
0
|
|
42
|
+
];
|
|
37
43
|
const trap = Utils.createLoaderContextTrap.call(this, (err, res)=>{
|
|
38
44
|
reportLoader(this, start, startHRTime, true, false, err ? 'Loader Pitch Async Error' : '', err, res);
|
|
39
45
|
});
|
|
@@ -52,13 +52,13 @@ class InternalBundleTagPlugin extends external_base_cjs_namespaceObject.Internal
|
|
|
52
52
|
if (true === terserDropConsole || true === swcDropConsole) logger_namespaceObject.logger.warn(logger_namespaceObject.chalk.yellow('Warning: BannerPlugin detected in project. Please disable drop_console option in TerserPlugin or SwcJsMinimizerRspackPlugin to enable Rsdoctor analysis for BannerPlugin.'));
|
|
53
53
|
}
|
|
54
54
|
const chunks = compilation.chunks;
|
|
55
|
-
for (
|
|
55
|
+
for (const chunk of chunks)for (const file of chunk.files){
|
|
56
56
|
if (!file || '.js' !== (0, external_path_namespaceObject.extname)(file)) continue;
|
|
57
57
|
const { ConcatSource } = compiler.webpack.sources;
|
|
58
58
|
compilation.updateAsset(file, (old)=>{
|
|
59
59
|
const concatSource = new ConcatSource();
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const header = "\n console.log('RSDOCTOR_START::');\n";
|
|
61
|
+
const footer = "\n console.log('RSDOCTOR_END::');\n";
|
|
62
62
|
concatSource.add(header);
|
|
63
63
|
concatSource.add(old);
|
|
64
64
|
concatSource.add(footer);
|
|
@@ -25,13 +25,13 @@ class InternalBundleTagPlugin extends InternalBasePlugin {
|
|
|
25
25
|
if (true === terserDropConsole || true === swcDropConsole) logger.warn(chalk.yellow('Warning: BannerPlugin detected in project. Please disable drop_console option in TerserPlugin or SwcJsMinimizerRspackPlugin to enable Rsdoctor analysis for BannerPlugin.'));
|
|
26
26
|
}
|
|
27
27
|
const chunks = compilation.chunks;
|
|
28
|
-
for (
|
|
28
|
+
for (const chunk of chunks)for (const file of chunk.files){
|
|
29
29
|
if (!file || '.js' !== extname(file)) continue;
|
|
30
30
|
const { ConcatSource } = compiler.webpack.sources;
|
|
31
31
|
compilation.updateAsset(file, (old)=>{
|
|
32
32
|
const concatSource = new ConcatSource();
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const header = "\n console.log('RSDOCTOR_START::');\n";
|
|
34
|
+
const footer = "\n console.log('RSDOCTOR_END::');\n";
|
|
35
35
|
concatSource.add(header);
|
|
36
36
|
concatSource.add(old);
|
|
37
37
|
concatSource.add(footer);
|
|
@@ -138,7 +138,7 @@ async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, s
|
|
|
138
138
|
if (!moduleGraph) return;
|
|
139
139
|
try {
|
|
140
140
|
await index_cjs_namespaceObject.Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle, assetsWithoutSourceMap);
|
|
141
|
-
} catch
|
|
141
|
+
} catch {}
|
|
142
142
|
}
|
|
143
143
|
function escapeRegExp(str) {
|
|
144
144
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -109,7 +109,7 @@ async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, s
|
|
|
109
109
|
if (!moduleGraph) return;
|
|
110
110
|
try {
|
|
111
111
|
await Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle, assetsWithoutSourceMap);
|
|
112
|
-
} catch
|
|
112
|
+
} catch {}
|
|
113
113
|
}
|
|
114
114
|
function escapeRegExp(str) {
|
|
115
115
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -137,8 +137,8 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex,
|
|
|
137
137
|
sourceMapPath = (0, external_path_namespaceObject.resolve)(outputPath, mapFileName);
|
|
138
138
|
}
|
|
139
139
|
} else {
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
const sourceMapFile = asset.info.related?.sourceMap;
|
|
141
|
+
const sourceMapFileAssetName = sourceMapFile?.replace(/(\.[^.]+)(\.[^.]+)?$/, '$1');
|
|
142
142
|
if (sourceMapFile) {
|
|
143
143
|
let sourceMapAsset = assets.find((asset)=>asset.name === sourceMapFile);
|
|
144
144
|
if (!sourceMapAsset && sourceMapFileAssetName) {
|
|
@@ -106,8 +106,8 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex,
|
|
|
106
106
|
sourceMapPath = resolve(outputPath, mapFileName);
|
|
107
107
|
}
|
|
108
108
|
} else {
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
const sourceMapFile = asset.info.related?.sourceMap;
|
|
110
|
+
const sourceMapFileAssetName = sourceMapFile?.replace(/(\.[^.]+)(\.[^.]+)?$/, '$1');
|
|
111
111
|
if (sourceMapFile) {
|
|
112
112
|
let sourceMapAsset = assets.find((asset)=>asset.name === sourceMapFile);
|
|
113
113
|
if (!sourceMapAsset && sourceMapFileAssetName) {
|
|
@@ -57,10 +57,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
57
57
|
hook.intercept({
|
|
58
58
|
register (tap) {
|
|
59
59
|
const o = tap.fn;
|
|
60
|
-
if ('sync' === tap.type) tap.fn = function() {
|
|
60
|
+
if ('sync' === tap.type) tap.fn = function(...args) {
|
|
61
61
|
const start = Date.now();
|
|
62
62
|
try {
|
|
63
|
-
const res = o.apply(this,
|
|
63
|
+
const res = o.apply(this, args);
|
|
64
64
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
65
65
|
return res;
|
|
66
66
|
} catch (error) {
|
|
@@ -68,10 +68,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
68
68
|
throw error;
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
-
else if ('async' === tap.type) tap.fn = async function() {
|
|
71
|
+
else if ('async' === tap.type) tap.fn = async function(...args) {
|
|
72
72
|
const start = Date.now();
|
|
73
73
|
try {
|
|
74
|
-
const res = await o.apply(this,
|
|
74
|
+
const res = await o.apply(this, args);
|
|
75
75
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
76
76
|
return res;
|
|
77
77
|
} catch (error) {
|
|
@@ -79,10 +79,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
else if ('promise' === tap.type) tap.fn = function() {
|
|
82
|
+
else if ('promise' === tap.type) tap.fn = function(...args) {
|
|
83
83
|
const start = Date.now();
|
|
84
|
-
const isChild =
|
|
85
|
-
return o.apply(this,
|
|
84
|
+
const isChild = args?.[0]?.compiler?.isChild();
|
|
85
|
+
return o.apply(this, args).then((res)=>{
|
|
86
86
|
if (isChild) return res;
|
|
87
87
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
88
88
|
return res;
|
|
@@ -29,10 +29,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
29
29
|
hook.intercept({
|
|
30
30
|
register (tap) {
|
|
31
31
|
const o = tap.fn;
|
|
32
|
-
if ('sync' === tap.type) tap.fn = function() {
|
|
32
|
+
if ('sync' === tap.type) tap.fn = function(...args) {
|
|
33
33
|
const start = Date.now();
|
|
34
34
|
try {
|
|
35
|
-
const res = o.apply(this,
|
|
35
|
+
const res = o.apply(this, args);
|
|
36
36
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
37
37
|
return res;
|
|
38
38
|
} catch (error) {
|
|
@@ -40,10 +40,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
40
40
|
throw error;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
else if ('async' === tap.type) tap.fn = async function() {
|
|
43
|
+
else if ('async' === tap.type) tap.fn = async function(...args) {
|
|
44
44
|
const start = Date.now();
|
|
45
45
|
try {
|
|
46
|
-
const res = await o.apply(this,
|
|
46
|
+
const res = await o.apply(this, args);
|
|
47
47
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
48
48
|
return res;
|
|
49
49
|
} catch (error) {
|
|
@@ -51,10 +51,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
51
51
|
throw error;
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
else if ('promise' === tap.type) tap.fn = function() {
|
|
54
|
+
else if ('promise' === tap.type) tap.fn = function(...args) {
|
|
55
55
|
const start = Date.now();
|
|
56
|
-
const isChild =
|
|
57
|
-
return o.apply(this,
|
|
56
|
+
const isChild = args?.[0]?.compiler?.isChild();
|
|
57
|
+
return o.apply(this, args).then((res)=>{
|
|
58
58
|
if (isChild) return res;
|
|
59
59
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
60
60
|
return res;
|
package/dist/rules/rule.cjs
CHANGED
|
@@ -84,7 +84,7 @@ class Rule {
|
|
|
84
84
|
const replace = [];
|
|
85
85
|
const report = (data, remove)=>{
|
|
86
86
|
if (remove) replace.push(remove);
|
|
87
|
-
|
|
87
|
+
const severity = data.severity ? (0, external_utils_cjs_namespaceObject.toSeverity)(data.severity, this.severity) : this.severity;
|
|
88
88
|
const error = {
|
|
89
89
|
...data,
|
|
90
90
|
code: this.code,
|
package/dist/rules/rule.js
CHANGED
|
@@ -56,7 +56,7 @@ class rule_Rule {
|
|
|
56
56
|
const replace = [];
|
|
57
57
|
const report = (data, remove)=>{
|
|
58
58
|
if (remove) replace.push(remove);
|
|
59
|
-
|
|
59
|
+
const severity = data.severity ? toSeverity(data.severity, this.severity) : this.severity;
|
|
60
60
|
const error = {
|
|
61
61
|
...data,
|
|
62
62
|
code: this.code,
|
|
@@ -42,6 +42,16 @@ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_na
|
|
|
42
42
|
const types_namespaceObject = require("@rsdoctor/types");
|
|
43
43
|
const external_rule_cjs_namespaceObject = require("../../rule.cjs");
|
|
44
44
|
const title = 'esm-resolved-to-cjs';
|
|
45
|
+
function normalizePathForCompare(filePath) {
|
|
46
|
+
const queryIndex = filePath.indexOf('?');
|
|
47
|
+
const hashIndex = filePath.indexOf('#');
|
|
48
|
+
const splitIndex = [
|
|
49
|
+
queryIndex,
|
|
50
|
+
hashIndex
|
|
51
|
+
].filter((index)=>index >= 0).reduce((min, index)=>Math.min(min, index), 1 / 0);
|
|
52
|
+
const cleanPath = splitIndex === 1 / 0 ? filePath : filePath.slice(0, splitIndex);
|
|
53
|
+
return external_path_default().normalize(cleanPath);
|
|
54
|
+
}
|
|
45
55
|
function extractEsmEntry(pkgJson, pkgRoot) {
|
|
46
56
|
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
47
57
|
if (null !== exportsField && 'object' == typeof exportsField) {
|
|
@@ -78,6 +88,7 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
78
88
|
},
|
|
79
89
|
check ({ moduleGraph, packageGraph, report, ruleConfig }) {
|
|
80
90
|
const pkgJsonCache = new Map();
|
|
91
|
+
const realPathCache = new Map();
|
|
81
92
|
const readPkgJson = (pkgRoot)=>{
|
|
82
93
|
if (pkgJsonCache.has(pkgRoot)) return pkgJsonCache.get(pkgRoot);
|
|
83
94
|
try {
|
|
@@ -90,14 +101,31 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
90
101
|
return null;
|
|
91
102
|
}
|
|
92
103
|
};
|
|
104
|
+
const toRealPath = (filePath)=>{
|
|
105
|
+
const normalized = normalizePathForCompare(filePath);
|
|
106
|
+
if (realPathCache.has(normalized)) return realPathCache.get(normalized);
|
|
107
|
+
try {
|
|
108
|
+
const realPath = 'function' == typeof external_fs_default().realpathSync.native ? external_fs_default().realpathSync.native(normalized) : external_fs_default().realpathSync(normalized);
|
|
109
|
+
const normalizedRealPath = external_path_default().normalize(realPath);
|
|
110
|
+
realPathCache.set(normalized, normalizedRealPath);
|
|
111
|
+
return normalizedRealPath;
|
|
112
|
+
} catch {
|
|
113
|
+
realPathCache.set(normalized, normalized);
|
|
114
|
+
return normalized;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
93
117
|
const groups = new Map();
|
|
94
118
|
const inNodeModules = /[/\\]node_modules[/\\]/;
|
|
95
119
|
for (const dep of moduleGraph.getDependencies()){
|
|
96
120
|
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
121
|
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
98
|
-
|
|
122
|
+
if (!pkg?.root) continue;
|
|
123
|
+
const pkgJson = readPkgJson(pkg.root);
|
|
124
|
+
const esmEntry = !ruleConfig.ignore.some((p)=>pkg.name.includes(p)) && pkgJson && extractEsmEntry(pkgJson, pkg.root);
|
|
99
125
|
if (!esmEntry) continue;
|
|
100
|
-
const
|
|
126
|
+
const resolvedModuleRealPath = toRealPath(dep.dependency.path);
|
|
127
|
+
if (resolvedModuleRealPath === toRealPath(esmEntry)) continue;
|
|
128
|
+
const groupKey = `${pkg.name}::${resolvedModuleRealPath}`;
|
|
101
129
|
const issuer = {
|
|
102
130
|
id: dep.module.id,
|
|
103
131
|
path: dep.module.path,
|
|
@@ -4,6 +4,16 @@ import path from "path";
|
|
|
4
4
|
import { Linter, SDK } from "@rsdoctor/types";
|
|
5
5
|
import { defineRule } from "../../rule.js";
|
|
6
6
|
const title = 'esm-resolved-to-cjs';
|
|
7
|
+
function normalizePathForCompare(filePath) {
|
|
8
|
+
const queryIndex = filePath.indexOf('?');
|
|
9
|
+
const hashIndex = filePath.indexOf('#');
|
|
10
|
+
const splitIndex = [
|
|
11
|
+
queryIndex,
|
|
12
|
+
hashIndex
|
|
13
|
+
].filter((index)=>index >= 0).reduce((min, index)=>Math.min(min, index), 1 / 0);
|
|
14
|
+
const cleanPath = splitIndex === 1 / 0 ? filePath : filePath.slice(0, splitIndex);
|
|
15
|
+
return path.normalize(cleanPath);
|
|
16
|
+
}
|
|
7
17
|
function extractEsmEntry(pkgJson, pkgRoot) {
|
|
8
18
|
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
9
19
|
if (null !== exportsField && 'object' == typeof exportsField) {
|
|
@@ -40,6 +50,7 @@ const rule = defineRule(()=>({
|
|
|
40
50
|
},
|
|
41
51
|
check ({ moduleGraph, packageGraph, report, ruleConfig }) {
|
|
42
52
|
const pkgJsonCache = new Map();
|
|
53
|
+
const realPathCache = new Map();
|
|
43
54
|
const readPkgJson = (pkgRoot)=>{
|
|
44
55
|
if (pkgJsonCache.has(pkgRoot)) return pkgJsonCache.get(pkgRoot);
|
|
45
56
|
try {
|
|
@@ -52,14 +63,31 @@ const rule = defineRule(()=>({
|
|
|
52
63
|
return null;
|
|
53
64
|
}
|
|
54
65
|
};
|
|
66
|
+
const toRealPath = (filePath)=>{
|
|
67
|
+
const normalized = normalizePathForCompare(filePath);
|
|
68
|
+
if (realPathCache.has(normalized)) return realPathCache.get(normalized);
|
|
69
|
+
try {
|
|
70
|
+
const realPath = 'function' == typeof fs.realpathSync.native ? fs.realpathSync.native(normalized) : fs.realpathSync(normalized);
|
|
71
|
+
const normalizedRealPath = path.normalize(realPath);
|
|
72
|
+
realPathCache.set(normalized, normalizedRealPath);
|
|
73
|
+
return normalizedRealPath;
|
|
74
|
+
} catch {
|
|
75
|
+
realPathCache.set(normalized, normalized);
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
55
79
|
const groups = new Map();
|
|
56
80
|
const inNodeModules = /[/\\]node_modules[/\\]/;
|
|
57
81
|
for (const dep of moduleGraph.getDependencies()){
|
|
58
82
|
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
83
|
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
60
|
-
|
|
84
|
+
if (!pkg?.root) continue;
|
|
85
|
+
const pkgJson = readPkgJson(pkg.root);
|
|
86
|
+
const esmEntry = !ruleConfig.ignore.some((p)=>pkg.name.includes(p)) && pkgJson && extractEsmEntry(pkgJson, pkg.root);
|
|
61
87
|
if (!esmEntry) continue;
|
|
62
|
-
const
|
|
88
|
+
const resolvedModuleRealPath = toRealPath(dep.dependency.path);
|
|
89
|
+
if (resolvedModuleRealPath === toRealPath(esmEntry)) continue;
|
|
90
|
+
const groupKey = `${pkg.name}::${resolvedModuleRealPath}`;
|
|
63
91
|
const issuer = {
|
|
64
92
|
id: dep.module.id,
|
|
65
93
|
path: dep.module.path,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -69,10 +69,10 @@
|
|
|
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/sdk": "1.5.
|
|
74
|
-
"@rsdoctor/
|
|
75
|
-
"@rsdoctor/
|
|
72
|
+
"@rsdoctor/graph": "1.5.9",
|
|
73
|
+
"@rsdoctor/sdk": "1.5.9",
|
|
74
|
+
"@rsdoctor/types": "1.5.9",
|
|
75
|
+
"@rsdoctor/utils": "1.5.9"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@rspack/core": "2.0.0-rc.1",
|