@rsdoctor/core 1.5.12 → 2.0.0-alpha.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.
- package/dist/build-utils/build/module-graph/index.cjs +4 -18
- package/dist/build-utils/build/module-graph/index.d.cts +0 -2
- package/dist/build-utils/build/module-graph/index.d.ts +0 -2
- package/dist/build-utils/build/module-graph/index.js +0 -2
- package/dist/build-utils/build/module-graph/rspack/transform.cjs +1 -1
- package/dist/build-utils/build/module-graph/rspack/transform.js +1 -1
- package/dist/build-utils/build/module-graph/transform.cjs +2 -3
- package/dist/build-utils/build/module-graph/transform.d.cts +1 -2
- package/dist/build-utils/build/module-graph/transform.d.ts +1 -2
- package/dist/build-utils/build/module-graph/transform.js +2 -3
- package/dist/build-utils/build/utils/parseBundle.cjs +1 -1
- package/dist/build-utils/build/utils/parseBundle.js +1 -1
- package/dist/build-utils/build/utils/plugin.cjs +1 -2
- package/dist/build-utils/build/utils/plugin.js +1 -2
- package/dist/inner-plugins/constants.cjs +1 -1
- package/dist/inner-plugins/constants.d.cts +1 -1
- package/dist/inner-plugins/constants.d.ts +1 -1
- package/dist/inner-plugins/constants.js +1 -1
- package/dist/inner-plugins/plugins/bundle.cjs +1 -17
- package/dist/inner-plugins/plugins/bundle.js +1 -17
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.cjs +3 -40
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.cts +4 -6
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.ts +4 -6
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +4 -41
- package/dist/inner-plugins/plugins/errors.cjs +3 -3
- package/dist/inner-plugins/plugins/errors.d.cts +1 -1
- package/dist/inner-plugins/plugins/errors.d.ts +1 -1
- package/dist/inner-plugins/plugins/errors.js +3 -3
- package/dist/inner-plugins/plugins/index.cjs +2 -9
- package/dist/inner-plugins/plugins/index.d.cts +0 -1
- package/dist/inner-plugins/plugins/index.d.ts +0 -1
- package/dist/inner-plugins/plugins/index.js +0 -1
- package/dist/inner-plugins/plugins/loader.cjs +1 -1
- package/dist/inner-plugins/plugins/loader.js +1 -1
- package/dist/inner-plugins/plugins/plugins.cjs +1 -1
- package/dist/inner-plugins/plugins/plugins.js +1 -1
- package/dist/inner-plugins/plugins/progress.cjs +14 -16
- package/dist/inner-plugins/plugins/progress.d.cts +1 -1
- package/dist/inner-plugins/plugins/progress.d.ts +1 -1
- package/dist/inner-plugins/plugins/progress.js +14 -16
- package/dist/inner-plugins/plugins/resolver.d.cts +1 -2
- package/dist/inner-plugins/plugins/resolver.d.ts +1 -2
- package/dist/inner-plugins/plugins/rules.cjs +3 -3
- package/dist/inner-plugins/plugins/rules.js +3 -3
- package/dist/inner-plugins/utils/config.cjs +0 -1
- package/dist/inner-plugins/utils/config.d.cts +1 -1
- package/dist/inner-plugins/utils/config.d.ts +1 -1
- package/dist/inner-plugins/utils/config.js +0 -1
- package/dist/inner-plugins/utils/loader.cjs +2 -2
- package/dist/inner-plugins/utils/loader.js +2 -2
- package/dist/inner-plugins/utils/normalize-config.d.cts +3 -6
- package/dist/inner-plugins/utils/normalize-config.d.ts +3 -6
- package/dist/rules/rules/cjs-require/index.cjs +2 -2
- package/dist/rules/rules/cjs-require/index.js +2 -2
- package/dist/rules/rules/esm-resolved-to-cjs/index.cjs +2 -17
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +2 -17
- package/dist/rules/rules/loader-performance-optimization/index.cjs +1 -1
- package/dist/rules/rules/loader-performance-optimization/index.js +1 -1
- package/dist/rules/rules/module-mixed-chunks/index.cjs +1 -1
- package/dist/rules/rules/module-mixed-chunks/index.js +1 -1
- package/dist/rules/rules/side-effects-only-imports/index.cjs +1 -1
- package/dist/rules/rules/side-effects-only-imports/index.js +1 -1
- package/dist/types/plugin.d.cts +2 -2
- package/dist/types/plugin.d.ts +2 -2
- package/dist/types/rules.d.cts +4 -4
- package/dist/types/rules.d.ts +4 -4
- package/package.json +6 -7
- package/dist/build-utils/build/module-graph/treeShaking.cjs +0 -106
- package/dist/build-utils/build/module-graph/treeShaking.d.cts +0 -2
- package/dist/build-utils/build/module-graph/treeShaking.d.ts +0 -2
- package/dist/build-utils/build/module-graph/treeShaking.js +0 -73
- package/dist/build-utils/build/module-graph/webpack/transform.cjs +0 -170
- package/dist/build-utils/build/module-graph/webpack/transform.d.cts +0 -16
- package/dist/build-utils/build/module-graph/webpack/transform.d.ts +0 -16
- package/dist/build-utils/build/module-graph/webpack/transform.js +0 -124
- package/dist/inner-plugins/plugins/bundleTagPlugin.cjs +0 -84
- package/dist/inner-plugins/plugins/bundleTagPlugin.d.cts +0 -6
- package/dist/inner-plugins/plugins/bundleTagPlugin.d.ts +0 -6
- package/dist/inner-plugins/plugins/bundleTagPlugin.js +0 -51
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
appendTreeShaking: ()=>appendTreeShaking
|
|
28
|
-
});
|
|
29
|
-
const graph_namespaceObject = require("@rsdoctor/graph");
|
|
30
|
-
const external_utils_cjs_namespaceObject = require("./utils.cjs");
|
|
31
|
-
function transformMgm(origin, webpackGraph, graph, cache) {
|
|
32
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
33
|
-
if (!module) return;
|
|
34
|
-
const mgm = new graph_namespaceObject.ModuleGraphModule(module, graph);
|
|
35
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
36
|
-
graph.addModuleGraphModule(mgm);
|
|
37
|
-
for (const info of originalMgm.exports){
|
|
38
|
-
const { name } = info;
|
|
39
|
-
const exportIdStatement = (0, external_utils_cjs_namespaceObject.getExportIdentifierStatement)(name, module) ?? graph_namespaceObject.Statement.getDefaultStatement(module);
|
|
40
|
-
const declareIdStatement = (0, external_utils_cjs_namespaceObject.getDeclarationIdentifier)(name, module);
|
|
41
|
-
const exportInfo = new graph_namespaceObject.ExportInfo(info.name, exportIdStatement);
|
|
42
|
-
if (declareIdStatement) {
|
|
43
|
-
const variable = new graph_namespaceObject.Variable(name, module, info.getUsedInfo(), declareIdStatement);
|
|
44
|
-
variable.setExportInfo(exportInfo);
|
|
45
|
-
mgm.addVariable(variable);
|
|
46
|
-
}
|
|
47
|
-
cache.set(info, exportInfo);
|
|
48
|
-
mgm.addExportInfo(exportInfo);
|
|
49
|
-
}
|
|
50
|
-
for (const dep of origin.dependencies){
|
|
51
|
-
if ('harmony import specifier' !== dep.type) continue;
|
|
52
|
-
const HISDep = dep;
|
|
53
|
-
const { name, userRequest } = HISDep;
|
|
54
|
-
const originName = HISDep.getIds(webpackGraph)[0] ?? graph_namespaceObject.SideEffect.NamespaceSymbol;
|
|
55
|
-
const importIdStatement = module.getStatement(dep.loc);
|
|
56
|
-
const importInfo = new graph_namespaceObject.SideEffect(name, module, importIdStatement, userRequest, originName);
|
|
57
|
-
mgm.addSideEffect(importInfo);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function appendExportConnection(origin, webpackGraph, graph, cache) {
|
|
61
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
62
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
63
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
64
|
-
if (!mgm || !module) return;
|
|
65
|
-
for (const info of originalMgm.exports){
|
|
66
|
-
if (!info.isReexport()) continue;
|
|
67
|
-
const lastExport = graph_namespaceObject.Webpack.getLastExportInfo(info, webpackGraph);
|
|
68
|
-
const lastSdkExport = cache.get(lastExport);
|
|
69
|
-
const sdkExport = cache.get(info);
|
|
70
|
-
if (!lastSdkExport || !sdkExport) return;
|
|
71
|
-
sdkExport.setFromExport(lastSdkExport);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function appendImportConnection(origin, graph) {
|
|
75
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
76
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
77
|
-
if (!mgm || !module) return;
|
|
78
|
-
for (const info of mgm.getSideEffects()){
|
|
79
|
-
const exportName = info.originName ?? info.name;
|
|
80
|
-
const resolveModule = info.fromDependency?.dependency;
|
|
81
|
-
if (!resolveModule) continue;
|
|
82
|
-
const resolveExport = graph.getModuleGraphModule(resolveModule).getExport(exportName);
|
|
83
|
-
if (resolveExport) info.setExportInfo(resolveExport);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function appendTreeShaking(moduleGraph, compilation) {
|
|
87
|
-
if (!graph_namespaceObject.ModuleGraphTrans.isWebpack5orRspack(compilation)) return moduleGraph;
|
|
88
|
-
if ('moduleGraph' in compilation) {
|
|
89
|
-
const exportData = new Map();
|
|
90
|
-
const webpackCompilation = compilation;
|
|
91
|
-
const { moduleGraph: webpackGraph } = webpackCompilation;
|
|
92
|
-
const allModules = graph_namespaceObject.Webpack.getAllModules(webpackCompilation);
|
|
93
|
-
allModules.forEach((origin)=>transformMgm(origin, webpackGraph, moduleGraph, exportData));
|
|
94
|
-
allModules.forEach((origin)=>appendExportConnection(origin, webpackGraph, moduleGraph, exportData));
|
|
95
|
-
allModules.forEach((origin)=>appendImportConnection(origin, moduleGraph));
|
|
96
|
-
exportData.clear();
|
|
97
|
-
}
|
|
98
|
-
return moduleGraph;
|
|
99
|
-
}
|
|
100
|
-
exports.appendTreeShaking = __webpack_exports__.appendTreeShaking;
|
|
101
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
102
|
-
"appendTreeShaking"
|
|
103
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
104
|
-
Object.defineProperty(exports, '__esModule', {
|
|
105
|
-
value: true
|
|
106
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { ExportInfo, ModuleGraphModule, ModuleGraphTrans, SideEffect, Statement, Variable, Webpack } from "@rsdoctor/graph";
|
|
3
|
-
import { getDeclarationIdentifier, getExportIdentifierStatement } from "./utils.js";
|
|
4
|
-
function transformMgm(origin, webpackGraph, graph, cache) {
|
|
5
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
6
|
-
if (!module) return;
|
|
7
|
-
const mgm = new ModuleGraphModule(module, graph);
|
|
8
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
9
|
-
graph.addModuleGraphModule(mgm);
|
|
10
|
-
for (const info of originalMgm.exports){
|
|
11
|
-
const { name } = info;
|
|
12
|
-
const exportIdStatement = getExportIdentifierStatement(name, module) ?? Statement.getDefaultStatement(module);
|
|
13
|
-
const declareIdStatement = getDeclarationIdentifier(name, module);
|
|
14
|
-
const exportInfo = new ExportInfo(info.name, exportIdStatement);
|
|
15
|
-
if (declareIdStatement) {
|
|
16
|
-
const variable = new Variable(name, module, info.getUsedInfo(), declareIdStatement);
|
|
17
|
-
variable.setExportInfo(exportInfo);
|
|
18
|
-
mgm.addVariable(variable);
|
|
19
|
-
}
|
|
20
|
-
cache.set(info, exportInfo);
|
|
21
|
-
mgm.addExportInfo(exportInfo);
|
|
22
|
-
}
|
|
23
|
-
for (const dep of origin.dependencies){
|
|
24
|
-
if ('harmony import specifier' !== dep.type) continue;
|
|
25
|
-
const HISDep = dep;
|
|
26
|
-
const { name, userRequest } = HISDep;
|
|
27
|
-
const originName = HISDep.getIds(webpackGraph)[0] ?? SideEffect.NamespaceSymbol;
|
|
28
|
-
const importIdStatement = module.getStatement(dep.loc);
|
|
29
|
-
const importInfo = new SideEffect(name, module, importIdStatement, userRequest, originName);
|
|
30
|
-
mgm.addSideEffect(importInfo);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function appendExportConnection(origin, webpackGraph, graph, cache) {
|
|
34
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
35
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
36
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
37
|
-
if (!mgm || !module) return;
|
|
38
|
-
for (const info of originalMgm.exports){
|
|
39
|
-
if (!info.isReexport()) continue;
|
|
40
|
-
const lastExport = Webpack.getLastExportInfo(info, webpackGraph);
|
|
41
|
-
const lastSdkExport = cache.get(lastExport);
|
|
42
|
-
const sdkExport = cache.get(info);
|
|
43
|
-
if (!lastSdkExport || !sdkExport) return;
|
|
44
|
-
sdkExport.setFromExport(lastSdkExport);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function appendImportConnection(origin, graph) {
|
|
48
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
49
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
50
|
-
if (!mgm || !module) return;
|
|
51
|
-
for (const info of mgm.getSideEffects()){
|
|
52
|
-
const exportName = info.originName ?? info.name;
|
|
53
|
-
const resolveModule = info.fromDependency?.dependency;
|
|
54
|
-
if (!resolveModule) continue;
|
|
55
|
-
const resolveExport = graph.getModuleGraphModule(resolveModule).getExport(exportName);
|
|
56
|
-
if (resolveExport) info.setExportInfo(resolveExport);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function appendTreeShaking(moduleGraph, compilation) {
|
|
60
|
-
if (!ModuleGraphTrans.isWebpack5orRspack(compilation)) return moduleGraph;
|
|
61
|
-
if ('moduleGraph' in compilation) {
|
|
62
|
-
const exportData = new Map();
|
|
63
|
-
const webpackCompilation = compilation;
|
|
64
|
-
const { moduleGraph: webpackGraph } = webpackCompilation;
|
|
65
|
-
const allModules = Webpack.getAllModules(webpackCompilation);
|
|
66
|
-
allModules.forEach((origin)=>transformMgm(origin, webpackGraph, moduleGraph, exportData));
|
|
67
|
-
allModules.forEach((origin)=>appendExportConnection(origin, webpackGraph, moduleGraph, exportData));
|
|
68
|
-
allModules.forEach((origin)=>appendImportConnection(origin, moduleGraph));
|
|
69
|
-
exportData.clear();
|
|
70
|
-
}
|
|
71
|
-
return moduleGraph;
|
|
72
|
-
}
|
|
73
|
-
export { appendTreeShaking };
|
|
@@ -1,170 +0,0 @@
|
|
|
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
|
-
appendModuleGraphByCompilation: ()=>appendModuleGraphByCompilation,
|
|
37
|
-
getModuleExportsType: ()=>getModuleExportsType
|
|
38
|
-
});
|
|
39
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
40
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
41
|
-
const graph_namespaceObject = require("@rsdoctor/graph");
|
|
42
|
-
const external_parser_cjs_namespaceObject = require("../parser.cjs");
|
|
43
|
-
const compat_namespaceObject = require("es-toolkit/compat");
|
|
44
|
-
const logger_namespaceObject = require("@rsdoctor/utils/logger");
|
|
45
|
-
async function readFile(target, wbFs) {
|
|
46
|
-
if (wbFs?.fs?.readFile) {
|
|
47
|
-
const result = new Promise((resolve, reject)=>{
|
|
48
|
-
wbFs.fs.readFile(target, (err, content)=>{
|
|
49
|
-
if (err) return void reject(err);
|
|
50
|
-
content ? resolve(Buffer.from(content)) : resolve();
|
|
51
|
-
});
|
|
52
|
-
}).catch(()=>{});
|
|
53
|
-
if (result) return result;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
return await external_node_fs_default().promises.readFile(target);
|
|
57
|
-
} catch {
|
|
58
|
-
logger_namespaceObject.logger.debug(`readFile error: ${target}`);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function getModuleExportsType(module, moduleGraph, strict = false) {
|
|
63
|
-
if (moduleGraph && 'getExportsType' in module) return module.getExportsType(moduleGraph, strict);
|
|
64
|
-
return strict ? 'default-with-named' : 'dynamic';
|
|
65
|
-
}
|
|
66
|
-
function appendDependency(webpackDep, module, webpackGraph, graph) {
|
|
67
|
-
const resolvedWebpackModule = webpackGraph?.getResolvedModule ? webpackGraph.getResolvedModule(webpackDep) : void 0;
|
|
68
|
-
if (!resolvedWebpackModule) return;
|
|
69
|
-
const rawRequest = graph_namespaceObject.Webpack.getWebpackDependencyRequest(webpackDep, resolvedWebpackModule);
|
|
70
|
-
const resolveRequest = graph_namespaceObject.Webpack.getWebpackModulePath(resolvedWebpackModule);
|
|
71
|
-
const request = rawRequest ?? resolveRequest;
|
|
72
|
-
if (!module.getDependencyByRequest(request)) {
|
|
73
|
-
const depLayer = resolvedWebpackModule.layer || void 0;
|
|
74
|
-
const depModule = graph.getModuleByFile(resolveRequest, depLayer)[0];
|
|
75
|
-
if (depModule) {
|
|
76
|
-
const dep = module.addDependency(request, depModule, graph_namespaceObject.ModuleGraphTrans.getImportKind(webpackDep));
|
|
77
|
-
if (dep) graph.addDependency(dep);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const dependency = module.getDependencyByRequest(request);
|
|
81
|
-
if (dependency) {
|
|
82
|
-
dependency.setBuildMeta({
|
|
83
|
-
exportsType: getModuleExportsType(resolvedWebpackModule, webpackGraph, module.meta.strictHarmonyModule)
|
|
84
|
-
});
|
|
85
|
-
const statement = graph_namespaceObject.Webpack.getDependencyPosition(webpackDep, module, false);
|
|
86
|
-
if (statement) dependency.addStatement(statement);
|
|
87
|
-
dependency.statements.forEach((state)=>{
|
|
88
|
-
state.position.source = state.module.getSourceRange(state.position.transformed);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function getModuleSource(modulePath, wbFs, sourceMap) {
|
|
93
|
-
if (sourceMap) try {
|
|
94
|
-
const contentFromSourceMap = sourceMap.sourceContentFor(modulePath);
|
|
95
|
-
if (contentFromSourceMap) return Buffer.from(contentFromSourceMap);
|
|
96
|
-
} catch (e) {
|
|
97
|
-
logger_namespaceObject.logger.debug(`getModuleSource error: ${e}`);
|
|
98
|
-
}
|
|
99
|
-
return readFile(modulePath, wbFs);
|
|
100
|
-
}
|
|
101
|
-
async function appendModuleData(origin, webpackGraph, graph, wbFs, features, context) {
|
|
102
|
-
const module = graph.getModuleByWebpackId(graph_namespaceObject.Webpack.getWebpackModuleId(origin));
|
|
103
|
-
if (!origin || !module) return;
|
|
104
|
-
const { getSourceMap, astCache, packagePathMap } = context ?? {};
|
|
105
|
-
try {
|
|
106
|
-
const sourceMap = await getSourceMap?.(module.path);
|
|
107
|
-
const source = await getModuleSource(module.path, wbFs, sourceMap) ?? Buffer.from('');
|
|
108
|
-
if (sourceMap) module.setSourceMap(sourceMap);
|
|
109
|
-
if (astCache?.has(origin)) {
|
|
110
|
-
const program = astCache.get(origin);
|
|
111
|
-
module.setProgram(program);
|
|
112
|
-
module.meta.hasSetEsModuleStatement = (0, external_parser_cjs_namespaceObject.hasSetEsModuleStatement)(program);
|
|
113
|
-
}
|
|
114
|
-
const transformed = graph_namespaceObject.Webpack.isExternalModule(origin) ? '' : module.getSource().transformed.length > 0 ? module.getSource().transformed : (0, compat_namespaceObject.isFunction)(origin?.originalSource) ? origin.originalSource()?.source()?.toString() ?? '' : '';
|
|
115
|
-
const transformedSize = graph_namespaceObject.Webpack.isExternalModule(origin) ? 0 : module.getSize().transformedSize > 0 ? module.getSize().transformedSize : Buffer.from(transformed).byteLength;
|
|
116
|
-
module.setSource({
|
|
117
|
-
transformed,
|
|
118
|
-
source: source.toString()
|
|
119
|
-
});
|
|
120
|
-
module.setSize({
|
|
121
|
-
transformedSize,
|
|
122
|
-
sourceSize: source.byteLength
|
|
123
|
-
});
|
|
124
|
-
let packageData;
|
|
125
|
-
if (packagePathMap && origin.resourceResolveData) {
|
|
126
|
-
let { descriptionFileRoot: root } = origin.resourceResolveData;
|
|
127
|
-
const { descriptionFileData: data } = origin.resourceResolveData;
|
|
128
|
-
if (root && data && data.name && data.version) {
|
|
129
|
-
if (packagePathMap.has(root)) root = packagePathMap.get(root);
|
|
130
|
-
else {
|
|
131
|
-
const realpath = await external_node_fs_default().promises.realpath(root, {
|
|
132
|
-
encoding: 'utf-8'
|
|
133
|
-
});
|
|
134
|
-
root = realpath;
|
|
135
|
-
packagePathMap.set(root, realpath);
|
|
136
|
-
}
|
|
137
|
-
packageData = {
|
|
138
|
-
...origin.resourceResolveData.descriptionFileData,
|
|
139
|
-
root
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
module.meta.strictHarmonyModule = origin.buildMeta?.strictHarmonyModule ?? false;
|
|
144
|
-
module.meta.packageData = packageData;
|
|
145
|
-
if (!features?.lite && origin?.dependencies) Array.from(origin.dependencies).filter((item)=>graph_namespaceObject.ModuleGraphTrans.isImportDependency(item)).concat(origin.blocks.reduce((ans, item)=>ans.concat(item.dependencies), [])).forEach((dep)=>appendDependency(dep, module, webpackGraph, graph));
|
|
146
|
-
} catch (e) {
|
|
147
|
-
console.error(`module ${module.path} transform has error:`, e);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async function appendModuleGraphByCompilation(compilation, graph, features, context) {
|
|
151
|
-
try {
|
|
152
|
-
const webpackCompilation = compilation;
|
|
153
|
-
const { moduleGraph: webpackGraph, fileSystemInfo } = webpackCompilation;
|
|
154
|
-
const allModules = graph_namespaceObject.Webpack.getAllModules(webpackCompilation);
|
|
155
|
-
await Promise.all(allModules.map((module)=>appendModuleData(module, webpackGraph, graph, fileSystemInfo, features, context)));
|
|
156
|
-
graph_namespaceObject.ModuleGraphTrans.removeNoImportStyle(graph);
|
|
157
|
-
return graph;
|
|
158
|
-
} catch {
|
|
159
|
-
return graph;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.appendModuleGraphByCompilation = __webpack_exports__.appendModuleGraphByCompilation;
|
|
163
|
-
exports.getModuleExportsType = __webpack_exports__.getModuleExportsType;
|
|
164
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
165
|
-
"appendModuleGraphByCompilation",
|
|
166
|
-
"getModuleExportsType"
|
|
167
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
168
|
-
Object.defineProperty(exports, '__esModule', {
|
|
169
|
-
value: true
|
|
170
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { SourceMapConsumer } from 'source-map';
|
|
2
|
-
import * as Webpack from 'webpack';
|
|
3
|
-
import * as Rspack from '@rspack/core';
|
|
4
|
-
import { Node } from '@rsdoctor/utils/ruleUtils';
|
|
5
|
-
import { Plugin, SDK } from '@rsdoctor/types';
|
|
6
|
-
export interface TransformContext {
|
|
7
|
-
astCache?: Map<Webpack.NormalModule, Node.Program>;
|
|
8
|
-
packagePathMap?: Map<string, string>;
|
|
9
|
-
getSourceMap?(module: string): Promise<SourceMapConsumer | undefined>;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Get the type of dependencies between modules.
|
|
13
|
-
* This property can determine what runtime webpack has added to the modules.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getModuleExportsType(module: Webpack.NormalModule | Rspack.NormalModule, moduleGraph?: Webpack.ModuleGraph, strict?: boolean): SDK.DependencyBuildMeta['exportsType'];
|
|
16
|
-
export declare function appendModuleGraphByCompilation(compilation: Plugin.BaseCompilation, graph: SDK.ModuleGraphInstance, features?: Plugin.RsdoctorWebpackPluginFeatures, context?: TransformContext): Promise<SDK.ModuleGraphInstance>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { SourceMapConsumer } from 'source-map';
|
|
2
|
-
import * as Webpack from 'webpack';
|
|
3
|
-
import * as Rspack from '@rspack/core';
|
|
4
|
-
import { Node } from '@rsdoctor/utils/ruleUtils';
|
|
5
|
-
import { Plugin, SDK } from '@rsdoctor/types';
|
|
6
|
-
export interface TransformContext {
|
|
7
|
-
astCache?: Map<Webpack.NormalModule, Node.Program>;
|
|
8
|
-
packagePathMap?: Map<string, string>;
|
|
9
|
-
getSourceMap?(module: string): Promise<SourceMapConsumer | undefined>;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Get the type of dependencies between modules.
|
|
13
|
-
* This property can determine what runtime webpack has added to the modules.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getModuleExportsType(module: Webpack.NormalModule | Rspack.NormalModule, moduleGraph?: Webpack.ModuleGraph, strict?: boolean): SDK.DependencyBuildMeta['exportsType'];
|
|
16
|
-
export declare function appendModuleGraphByCompilation(compilation: Plugin.BaseCompilation, graph: SDK.ModuleGraphInstance, features?: Plugin.RsdoctorWebpackPluginFeatures, context?: TransformContext): Promise<SDK.ModuleGraphInstance>;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import node_fs from "node:fs";
|
|
3
|
-
import { ModuleGraphTrans, Webpack } from "@rsdoctor/graph";
|
|
4
|
-
import { hasSetEsModuleStatement } from "../parser.js";
|
|
5
|
-
import { isFunction } from "es-toolkit/compat";
|
|
6
|
-
import { logger } from "@rsdoctor/utils/logger";
|
|
7
|
-
async function readFile(target, wbFs) {
|
|
8
|
-
if (wbFs?.fs?.readFile) {
|
|
9
|
-
const result = new Promise((resolve, reject)=>{
|
|
10
|
-
wbFs.fs.readFile(target, (err, content)=>{
|
|
11
|
-
if (err) return void reject(err);
|
|
12
|
-
content ? resolve(Buffer.from(content)) : resolve();
|
|
13
|
-
});
|
|
14
|
-
}).catch(()=>{});
|
|
15
|
-
if (result) return result;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
return await node_fs.promises.readFile(target);
|
|
19
|
-
} catch {
|
|
20
|
-
logger.debug(`readFile error: ${target}`);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function getModuleExportsType(module, moduleGraph, strict = false) {
|
|
25
|
-
if (moduleGraph && 'getExportsType' in module) return module.getExportsType(moduleGraph, strict);
|
|
26
|
-
return strict ? 'default-with-named' : 'dynamic';
|
|
27
|
-
}
|
|
28
|
-
function appendDependency(webpackDep, module, webpackGraph, graph) {
|
|
29
|
-
const resolvedWebpackModule = webpackGraph?.getResolvedModule ? webpackGraph.getResolvedModule(webpackDep) : void 0;
|
|
30
|
-
if (!resolvedWebpackModule) return;
|
|
31
|
-
const rawRequest = Webpack.getWebpackDependencyRequest(webpackDep, resolvedWebpackModule);
|
|
32
|
-
const resolveRequest = Webpack.getWebpackModulePath(resolvedWebpackModule);
|
|
33
|
-
const request = rawRequest ?? resolveRequest;
|
|
34
|
-
if (!module.getDependencyByRequest(request)) {
|
|
35
|
-
const depLayer = resolvedWebpackModule.layer || void 0;
|
|
36
|
-
const depModule = graph.getModuleByFile(resolveRequest, depLayer)[0];
|
|
37
|
-
if (depModule) {
|
|
38
|
-
const dep = module.addDependency(request, depModule, ModuleGraphTrans.getImportKind(webpackDep));
|
|
39
|
-
if (dep) graph.addDependency(dep);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const dependency = module.getDependencyByRequest(request);
|
|
43
|
-
if (dependency) {
|
|
44
|
-
dependency.setBuildMeta({
|
|
45
|
-
exportsType: getModuleExportsType(resolvedWebpackModule, webpackGraph, module.meta.strictHarmonyModule)
|
|
46
|
-
});
|
|
47
|
-
const statement = Webpack.getDependencyPosition(webpackDep, module, false);
|
|
48
|
-
if (statement) dependency.addStatement(statement);
|
|
49
|
-
dependency.statements.forEach((state)=>{
|
|
50
|
-
state.position.source = state.module.getSourceRange(state.position.transformed);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function getModuleSource(modulePath, wbFs, sourceMap) {
|
|
55
|
-
if (sourceMap) try {
|
|
56
|
-
const contentFromSourceMap = sourceMap.sourceContentFor(modulePath);
|
|
57
|
-
if (contentFromSourceMap) return Buffer.from(contentFromSourceMap);
|
|
58
|
-
} catch (e) {
|
|
59
|
-
logger.debug(`getModuleSource error: ${e}`);
|
|
60
|
-
}
|
|
61
|
-
return readFile(modulePath, wbFs);
|
|
62
|
-
}
|
|
63
|
-
async function appendModuleData(origin, webpackGraph, graph, wbFs, features, context) {
|
|
64
|
-
const module = graph.getModuleByWebpackId(Webpack.getWebpackModuleId(origin));
|
|
65
|
-
if (!origin || !module) return;
|
|
66
|
-
const { getSourceMap, astCache, packagePathMap } = context ?? {};
|
|
67
|
-
try {
|
|
68
|
-
const sourceMap = await getSourceMap?.(module.path);
|
|
69
|
-
const source = await getModuleSource(module.path, wbFs, sourceMap) ?? Buffer.from('');
|
|
70
|
-
if (sourceMap) module.setSourceMap(sourceMap);
|
|
71
|
-
if (astCache?.has(origin)) {
|
|
72
|
-
const program = astCache.get(origin);
|
|
73
|
-
module.setProgram(program);
|
|
74
|
-
module.meta.hasSetEsModuleStatement = hasSetEsModuleStatement(program);
|
|
75
|
-
}
|
|
76
|
-
const transformed = Webpack.isExternalModule(origin) ? '' : module.getSource().transformed.length > 0 ? module.getSource().transformed : isFunction(origin?.originalSource) ? origin.originalSource()?.source()?.toString() ?? '' : '';
|
|
77
|
-
const transformedSize = Webpack.isExternalModule(origin) ? 0 : module.getSize().transformedSize > 0 ? module.getSize().transformedSize : Buffer.from(transformed).byteLength;
|
|
78
|
-
module.setSource({
|
|
79
|
-
transformed,
|
|
80
|
-
source: source.toString()
|
|
81
|
-
});
|
|
82
|
-
module.setSize({
|
|
83
|
-
transformedSize,
|
|
84
|
-
sourceSize: source.byteLength
|
|
85
|
-
});
|
|
86
|
-
let packageData;
|
|
87
|
-
if (packagePathMap && origin.resourceResolveData) {
|
|
88
|
-
let { descriptionFileRoot: root } = origin.resourceResolveData;
|
|
89
|
-
const { descriptionFileData: data } = origin.resourceResolveData;
|
|
90
|
-
if (root && data && data.name && data.version) {
|
|
91
|
-
if (packagePathMap.has(root)) root = packagePathMap.get(root);
|
|
92
|
-
else {
|
|
93
|
-
const realpath = await node_fs.promises.realpath(root, {
|
|
94
|
-
encoding: 'utf-8'
|
|
95
|
-
});
|
|
96
|
-
root = realpath;
|
|
97
|
-
packagePathMap.set(root, realpath);
|
|
98
|
-
}
|
|
99
|
-
packageData = {
|
|
100
|
-
...origin.resourceResolveData.descriptionFileData,
|
|
101
|
-
root
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
module.meta.strictHarmonyModule = origin.buildMeta?.strictHarmonyModule ?? false;
|
|
106
|
-
module.meta.packageData = packageData;
|
|
107
|
-
if (!features?.lite && origin?.dependencies) Array.from(origin.dependencies).filter((item)=>ModuleGraphTrans.isImportDependency(item)).concat(origin.blocks.reduce((ans, item)=>ans.concat(item.dependencies), [])).forEach((dep)=>appendDependency(dep, module, webpackGraph, graph));
|
|
108
|
-
} catch (e) {
|
|
109
|
-
console.error(`module ${module.path} transform has error:`, e);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async function appendModuleGraphByCompilation(compilation, graph, features, context) {
|
|
113
|
-
try {
|
|
114
|
-
const webpackCompilation = compilation;
|
|
115
|
-
const { moduleGraph: webpackGraph, fileSystemInfo } = webpackCompilation;
|
|
116
|
-
const allModules = Webpack.getAllModules(webpackCompilation);
|
|
117
|
-
await Promise.all(allModules.map((module)=>appendModuleData(module, webpackGraph, graph, fileSystemInfo, features, context)));
|
|
118
|
-
ModuleGraphTrans.removeNoImportStyle(graph);
|
|
119
|
-
return graph;
|
|
120
|
-
} catch {
|
|
121
|
-
return graph;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
export { appendModuleGraphByCompilation, getModuleExportsType };
|
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
InternalBundleTagPlugin: ()=>InternalBundleTagPlugin
|
|
28
|
-
});
|
|
29
|
-
const external_path_namespaceObject = require("path");
|
|
30
|
-
const external_base_cjs_namespaceObject = require("./base.cjs");
|
|
31
|
-
const logger_namespaceObject = require("@rsdoctor/utils/logger");
|
|
32
|
-
class InternalBundleTagPlugin extends external_base_cjs_namespaceObject.InternalBasePlugin {
|
|
33
|
-
apply(compiler) {
|
|
34
|
-
(0, logger_namespaceObject.time)('InternalBundleTagPlugin.apply');
|
|
35
|
-
try {
|
|
36
|
-
const supportBannerPlugin = this.options.supports?.banner;
|
|
37
|
-
compiler.hooks.compilation.tap('RsdoctorTagBannerPlugin', (compilation)=>{
|
|
38
|
-
compilation.hooks.processAssets.tapPromise({
|
|
39
|
-
name: 'RsdoctorTagBannerPlugin',
|
|
40
|
-
stage: -2000
|
|
41
|
-
}, async ()=>{
|
|
42
|
-
if (true !== supportBannerPlugin || 'rspack' in compiler) return;
|
|
43
|
-
logger_namespaceObject.logger.info(logger_namespaceObject.chalk.magenta("Rsdoctor's `supports.banner` option is enabled, this is for debugging only. Do not use it for production."));
|
|
44
|
-
const minimizers = compiler.options.optimization?.minimizer || [];
|
|
45
|
-
const terserPlugin = minimizers.find((plugin)=>plugin?.constructor?.name === 'TerserPlugin');
|
|
46
|
-
const swcPlugin = minimizers.find((plugin)=>plugin?.constructor?.name === 'SwcJsMinimizerRspackPlugin');
|
|
47
|
-
const hasTerserPlugin = !!terserPlugin;
|
|
48
|
-
const hasSwcJsMinimizer = !!swcPlugin;
|
|
49
|
-
if (hasTerserPlugin || hasSwcJsMinimizer) {
|
|
50
|
-
const terserDropConsole = terserPlugin?.options?.minimizer?.options?.compress?.drop_console;
|
|
51
|
-
const swcDropConsole = swcPlugin?._args?.[0]?.minimizerOptions?.compress?.drop_console;
|
|
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
|
-
}
|
|
54
|
-
const chunks = compilation.chunks;
|
|
55
|
-
for (const chunk of chunks)for (const file of chunk.files){
|
|
56
|
-
if (!file || '.js' !== (0, external_path_namespaceObject.extname)(file)) continue;
|
|
57
|
-
const { ConcatSource } = compiler.webpack.sources;
|
|
58
|
-
compilation.updateAsset(file, (old)=>{
|
|
59
|
-
const concatSource = new ConcatSource();
|
|
60
|
-
const header = "\n console.log('RSDOCTOR_START::');\n";
|
|
61
|
-
const footer = "\n console.log('RSDOCTOR_END::');\n";
|
|
62
|
-
concatSource.add(header);
|
|
63
|
-
concatSource.add(old);
|
|
64
|
-
concatSource.add(footer);
|
|
65
|
-
return concatSource;
|
|
66
|
-
}, ()=>{});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
} finally{
|
|
71
|
-
(0, logger_namespaceObject.timeEnd)('InternalBundleTagPlugin.apply');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
constructor(...args){
|
|
75
|
-
super(...args), this.name = 'bundleTag';
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.InternalBundleTagPlugin = __webpack_exports__.InternalBundleTagPlugin;
|
|
79
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
80
|
-
"InternalBundleTagPlugin"
|
|
81
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
82
|
-
Object.defineProperty(exports, '__esModule', {
|
|
83
|
-
value: true
|
|
84
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@rsdoctor/types';
|
|
2
|
-
import { InternalBasePlugin } from './base';
|
|
3
|
-
export declare class InternalBundleTagPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
|
|
4
|
-
readonly name = "bundleTag";
|
|
5
|
-
apply(compiler: Plugin.BaseCompiler): void;
|
|
6
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@rsdoctor/types';
|
|
2
|
-
import { InternalBasePlugin } from './base.js';
|
|
3
|
-
export declare class InternalBundleTagPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
|
|
4
|
-
readonly name = "bundleTag";
|
|
5
|
-
apply(compiler: Plugin.BaseCompiler): void;
|
|
6
|
-
}
|