@rsdoctor/graph 1.2.3 → 1.2.4-beta.1
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/{type/graph → graph}/chunk-graph/asset.d.ts +0 -1
- package/dist/{type/graph → graph}/chunk-graph/chunk.d.ts +0 -1
- package/dist/{type/graph → graph}/chunk-graph/entrypoint.d.ts +0 -1
- package/dist/{type/graph → graph}/chunk-graph/graph.d.ts +0 -1
- package/dist/{type/graph → graph}/chunk-graph/index.d.ts +0 -1
- package/dist/{type/graph → graph}/index.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/dependency.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/graph.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/index.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/module.d.ts +1 -2
- package/dist/{type/graph → graph}/module-graph/statement.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/tree-shaking/export.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/tree-shaking/index.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/tree-shaking/module.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/tree-shaking/sideEffect.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/tree-shaking/types.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/tree-shaking/variable.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/types.d.ts +0 -1
- package/dist/{type/graph → graph}/module-graph/utils.d.ts +0 -1
- package/dist/{type/graph → graph}/package-graph/dependency.d.ts +0 -1
- package/dist/{type/graph → graph}/package-graph/graph.d.ts +0 -1
- package/dist/{type/graph → graph}/package-graph/index.d.ts +0 -1
- package/dist/{type/graph → graph}/package-graph/package.d.ts +0 -1
- package/dist/{type/graph → graph}/package-graph/types.d.ts +0 -1
- package/dist/{type/graph → graph}/package-graph/utils.d.ts +0 -1
- package/dist/index.cjs +1541 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1452 -0
- package/dist/transform/chunks/assetsContent.d.ts +4 -0
- package/dist/transform/chunks/assetsModules.d.ts +22 -0
- package/dist/transform/chunks/chunkTransform.d.ts +5 -0
- package/dist/transform/chunks/index.d.ts +3 -0
- package/dist/transform/index.d.ts +4 -0
- package/dist/transform/module-graph/compatible.d.ts +8 -0
- package/dist/transform/module-graph/index.d.ts +3 -0
- package/dist/transform/module-graph/transform.d.ts +7 -0
- package/dist/transform/module-graph/utils.d.ts +13 -0
- package/dist/transform/trans-utils/index.d.ts +1 -0
- package/dist/transform/trans-utils/transStats.d.ts +10 -0
- package/dist/transform/webpack/compatible.d.ts +16 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/transform.d.ts +6 -0
- package/package.json +19 -9
- package/dist/cjs/graph/chunk-graph/asset.js +0 -72
- package/dist/cjs/graph/chunk-graph/chunk.js +0 -121
- package/dist/cjs/graph/chunk-graph/entrypoint.js +0 -73
- package/dist/cjs/graph/chunk-graph/graph.js +0 -109
- package/dist/cjs/graph/chunk-graph/index.js +0 -87
- package/dist/cjs/graph/index.js +0 -78
- package/dist/cjs/graph/module-graph/dependency.js +0 -100
- package/dist/cjs/graph/module-graph/graph.js +0 -319
- package/dist/cjs/graph/module-graph/index.js +0 -105
- package/dist/cjs/graph/module-graph/module.js +0 -328
- package/dist/cjs/graph/module-graph/statement.js +0 -92
- package/dist/cjs/graph/module-graph/tree-shaking/export.js +0 -102
- package/dist/cjs/graph/module-graph/tree-shaking/index.js +0 -96
- package/dist/cjs/graph/module-graph/tree-shaking/module.js +0 -100
- package/dist/cjs/graph/module-graph/tree-shaking/sideEffect.js +0 -89
- package/dist/cjs/graph/module-graph/tree-shaking/types.js +0 -18
- package/dist/cjs/graph/module-graph/tree-shaking/variable.js +0 -69
- package/dist/cjs/graph/module-graph/types.js +0 -18
- package/dist/cjs/graph/module-graph/utils.js +0 -63
- package/dist/cjs/graph/package-graph/dependency.js +0 -64
- package/dist/cjs/graph/package-graph/graph.js +0 -170
- package/dist/cjs/graph/package-graph/index.js +0 -87
- package/dist/cjs/graph/package-graph/package.js +0 -125
- package/dist/cjs/graph/package-graph/types.js +0 -18
- package/dist/cjs/graph/package-graph/utils.js +0 -61
- package/dist/cjs/index.js +0 -60
- package/dist/esm/graph/chunk-graph/asset.mjs +0 -38
- package/dist/esm/graph/chunk-graph/chunk.mjs +0 -87
- package/dist/esm/graph/chunk-graph/entrypoint.mjs +0 -39
- package/dist/esm/graph/chunk-graph/graph.mjs +0 -75
- package/dist/esm/graph/chunk-graph/index.mjs +0 -4
- package/dist/esm/graph/index.mjs +0 -3
- package/dist/esm/graph/module-graph/dependency.mjs +0 -66
- package/dist/esm/graph/module-graph/graph.mjs +0 -285
- package/dist/esm/graph/module-graph/index.mjs +0 -6
- package/dist/esm/graph/module-graph/module.mjs +0 -284
- package/dist/esm/graph/module-graph/statement.mjs +0 -58
- package/dist/esm/graph/module-graph/tree-shaking/export.mjs +0 -68
- package/dist/esm/graph/module-graph/tree-shaking/index.mjs +0 -5
- package/dist/esm/graph/module-graph/tree-shaking/module.mjs +0 -66
- package/dist/esm/graph/module-graph/tree-shaking/sideEffect.mjs +0 -55
- package/dist/esm/graph/module-graph/tree-shaking/types.mjs +0 -0
- package/dist/esm/graph/module-graph/tree-shaking/variable.mjs +0 -35
- package/dist/esm/graph/module-graph/types.mjs +0 -0
- package/dist/esm/graph/module-graph/utils.mjs +0 -23
- package/dist/esm/graph/package-graph/dependency.mjs +0 -30
- package/dist/esm/graph/package-graph/graph.mjs +0 -123
- package/dist/esm/graph/package-graph/index.mjs +0 -4
- package/dist/esm/graph/package-graph/package.mjs +0 -91
- package/dist/esm/graph/package-graph/types.mjs +0 -0
- package/dist/esm/graph/package-graph/utils.mjs +0 -24
- package/dist/esm/index.mjs +0 -1
- package/dist/type/graph/chunk-graph/asset.d.ts.map +0 -1
- package/dist/type/graph/chunk-graph/chunk.d.ts.map +0 -1
- package/dist/type/graph/chunk-graph/entrypoint.d.ts.map +0 -1
- package/dist/type/graph/chunk-graph/graph.d.ts.map +0 -1
- package/dist/type/graph/chunk-graph/index.d.ts.map +0 -1
- package/dist/type/graph/index.d.ts.map +0 -1
- package/dist/type/graph/module-graph/dependency.d.ts.map +0 -1
- package/dist/type/graph/module-graph/graph.d.ts.map +0 -1
- package/dist/type/graph/module-graph/index.d.ts.map +0 -1
- package/dist/type/graph/module-graph/module.d.ts.map +0 -1
- package/dist/type/graph/module-graph/statement.d.ts.map +0 -1
- package/dist/type/graph/module-graph/tree-shaking/export.d.ts.map +0 -1
- package/dist/type/graph/module-graph/tree-shaking/index.d.ts.map +0 -1
- package/dist/type/graph/module-graph/tree-shaking/module.d.ts.map +0 -1
- package/dist/type/graph/module-graph/tree-shaking/sideEffect.d.ts.map +0 -1
- package/dist/type/graph/module-graph/tree-shaking/types.d.ts.map +0 -1
- package/dist/type/graph/module-graph/tree-shaking/variable.d.ts.map +0 -1
- package/dist/type/graph/module-graph/types.d.ts.map +0 -1
- package/dist/type/graph/module-graph/utils.d.ts.map +0 -1
- package/dist/type/graph/package-graph/dependency.d.ts.map +0 -1
- package/dist/type/graph/package-graph/graph.d.ts.map +0 -1
- package/dist/type/graph/package-graph/index.d.ts.map +0 -1
- package/dist/type/graph/package-graph/package.d.ts.map +0 -1
- package/dist/type/graph/package-graph/types.d.ts.map +0 -1
- package/dist/type/graph/package-graph/utils.d.ts.map +0 -1
- package/dist/type/index.d.ts +0 -2
- package/dist/type/index.d.ts.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1541 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
let __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
|
+
var __webpack_modules__ = {
|
|
4
|
+
"node:zlib": function(module) {
|
|
5
|
+
module.exports = require("node:zlib");
|
|
6
|
+
}
|
|
7
|
+
}, __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
15
|
+
}
|
|
16
|
+
__webpack_require__.n = (module)=>{
|
|
17
|
+
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
18
|
+
return __webpack_require__.d(getter, {
|
|
19
|
+
a: getter
|
|
20
|
+
}), getter;
|
|
21
|
+
}, (()=>{
|
|
22
|
+
var leafPrototypes, getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__;
|
|
23
|
+
__webpack_require__.t = function(value, mode) {
|
|
24
|
+
if (1 & mode && (value = this(value)), 8 & mode || 'object' == typeof value && value && (4 & mode && value.__esModule || 16 & mode && 'function' == typeof value.then)) return value;
|
|
25
|
+
var ns = Object.create(null);
|
|
26
|
+
__webpack_require__.r(ns);
|
|
27
|
+
var def = {};
|
|
28
|
+
leafPrototypes = leafPrototypes || [
|
|
29
|
+
null,
|
|
30
|
+
getProto({}),
|
|
31
|
+
getProto([]),
|
|
32
|
+
getProto(getProto)
|
|
33
|
+
];
|
|
34
|
+
for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach((key)=>{
|
|
35
|
+
def[key] = ()=>value[key];
|
|
36
|
+
});
|
|
37
|
+
return def.default = ()=>value, __webpack_require__.d(ns, def), ns;
|
|
38
|
+
};
|
|
39
|
+
})(), __webpack_require__.d = (exports1, definition)=>{
|
|
40
|
+
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
41
|
+
enumerable: !0,
|
|
42
|
+
get: definition[key]
|
|
43
|
+
});
|
|
44
|
+
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
45
|
+
'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
46
|
+
value: 'Module'
|
|
47
|
+
}), Object.defineProperty(exports1, '__esModule', {
|
|
48
|
+
value: !0
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var __webpack_exports__ = {};
|
|
52
|
+
for(var __webpack_i__ in (()=>{
|
|
53
|
+
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
ExportInfo: ()=>ExportInfo,
|
|
55
|
+
PackageDependency: ()=>PackageDependency,
|
|
56
|
+
Asset: ()=>Asset,
|
|
57
|
+
ModuleGraph: ()=>ModuleGraph,
|
|
58
|
+
EntryPoint: ()=>EntryPoint,
|
|
59
|
+
PackageGraph: ()=>PackageGraph,
|
|
60
|
+
Variable: ()=>Variable,
|
|
61
|
+
ModuleGraphTrans: ()=>transform_module_graph_namespaceObject,
|
|
62
|
+
ChunkGraph: ()=>ChunkGraph,
|
|
63
|
+
Dependency: ()=>Dependency,
|
|
64
|
+
TransUtils: ()=>trans_utils_namespaceObject,
|
|
65
|
+
readPackageJson: ()=>readPackageJson,
|
|
66
|
+
Statement: ()=>Statement,
|
|
67
|
+
Webpack: ()=>webpack_compatible_namespaceObject,
|
|
68
|
+
Module: ()=>Module,
|
|
69
|
+
Package: ()=>Package,
|
|
70
|
+
Chunks: ()=>chunks_namespaceObject,
|
|
71
|
+
SideEffect: ()=>SideEffect,
|
|
72
|
+
ModuleGraphModule: ()=>ModuleGraphModule,
|
|
73
|
+
Chunk: ()=>Chunk
|
|
74
|
+
});
|
|
75
|
+
var chunks_namespaceObject = {};
|
|
76
|
+
__webpack_require__.r(chunks_namespaceObject), __webpack_require__.d(chunks_namespaceObject, {
|
|
77
|
+
assetsContents: ()=>assetsContents,
|
|
78
|
+
chunkTransform: ()=>chunkTransform,
|
|
79
|
+
getAssetsModulesData: ()=>getAssetsModulesData,
|
|
80
|
+
transformAssetsModulesData: ()=>transformAssetsModulesData
|
|
81
|
+
});
|
|
82
|
+
var transform_module_graph_namespaceObject = {};
|
|
83
|
+
__webpack_require__.r(transform_module_graph_namespaceObject), __webpack_require__.d(transform_module_graph_namespaceObject, {
|
|
84
|
+
getImportKind: ()=>getImportKind,
|
|
85
|
+
getModuleGraphByStats: ()=>getModuleGraphByStats,
|
|
86
|
+
getModulesFromArray: ()=>getModulesFromArray,
|
|
87
|
+
getPositionByStatsLocation: ()=>getPositionByStatsLocation,
|
|
88
|
+
isImportDependency: ()=>isImportDependency,
|
|
89
|
+
isWebpack5orRspack: ()=>isWebpack5orRspack,
|
|
90
|
+
removeNoImportStyle: ()=>removeNoImportStyle
|
|
91
|
+
});
|
|
92
|
+
var trans_utils_namespaceObject = {};
|
|
93
|
+
__webpack_require__.r(trans_utils_namespaceObject), __webpack_require__.d(trans_utils_namespaceObject, {
|
|
94
|
+
transStats: ()=>transStats
|
|
95
|
+
});
|
|
96
|
+
var webpack_compatible_namespaceObject = {};
|
|
97
|
+
__webpack_require__.r(webpack_compatible_namespaceObject), __webpack_require__.d(webpack_compatible_namespaceObject, {
|
|
98
|
+
getAllModules: ()=>getAllModules,
|
|
99
|
+
getDependencyPosition: ()=>getDependencyPosition,
|
|
100
|
+
getEntryModule: ()=>getEntryModule,
|
|
101
|
+
getExportDependency: ()=>getExportDependency,
|
|
102
|
+
getExportStatement: ()=>getExportStatement,
|
|
103
|
+
getLastExportInfo: ()=>getLastExportInfo,
|
|
104
|
+
getModuleSource: ()=>getModuleSource,
|
|
105
|
+
getResolveRequest: ()=>getResolveRequest,
|
|
106
|
+
getSdkDependencyByWebpackDependency: ()=>getSdkDependencyByWebpackDependency,
|
|
107
|
+
getWebpackDependencyRequest: ()=>getWebpackDependencyRequest,
|
|
108
|
+
getWebpackModuleId: ()=>getWebpackModuleId,
|
|
109
|
+
getWebpackModulePath: ()=>getWebpackModulePath,
|
|
110
|
+
isExternalModule: ()=>isExternalModule,
|
|
111
|
+
isNormalModule: ()=>isNormalModule
|
|
112
|
+
});
|
|
113
|
+
class Chunk {
|
|
114
|
+
constructor(id, name, size, initial, entry){
|
|
115
|
+
this._assets = [], this._modules = [], this._dependencies = [], this._imported = [], this.id = id, this.name = name, this.size = size, this.initial = initial, this.entry = entry;
|
|
116
|
+
}
|
|
117
|
+
isEntry() {
|
|
118
|
+
return this.entry;
|
|
119
|
+
}
|
|
120
|
+
isChunkEntryModule(module) {
|
|
121
|
+
return module.isEntry || module.getImported().every((item)=>!this.hasModule(item));
|
|
122
|
+
}
|
|
123
|
+
hasModule(module) {
|
|
124
|
+
return this._modules.includes(module);
|
|
125
|
+
}
|
|
126
|
+
addModule(module) {
|
|
127
|
+
this.hasModule(module) || (this._modules.push(module), module.addChunk(this));
|
|
128
|
+
}
|
|
129
|
+
addAsset(asset) {
|
|
130
|
+
this._assets.push(asset);
|
|
131
|
+
}
|
|
132
|
+
addModules(modules) {
|
|
133
|
+
modules.forEach((module)=>{
|
|
134
|
+
this.hasModule(module) || (this._modules.push(module), module.addChunk(this));
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
addDependency(dep) {
|
|
138
|
+
this._dependencies.includes(dep) || this._dependencies.push(dep);
|
|
139
|
+
}
|
|
140
|
+
addImported(imported) {
|
|
141
|
+
this._imported.includes(imported) || this._imported.push(imported);
|
|
142
|
+
}
|
|
143
|
+
getAssets() {
|
|
144
|
+
return this._assets.slice();
|
|
145
|
+
}
|
|
146
|
+
getModules() {
|
|
147
|
+
return this._modules.slice();
|
|
148
|
+
}
|
|
149
|
+
getDependencies() {
|
|
150
|
+
return this._dependencies.slice();
|
|
151
|
+
}
|
|
152
|
+
getImported() {
|
|
153
|
+
return this._imported.slice();
|
|
154
|
+
}
|
|
155
|
+
setParsedSize(parsedSize) {
|
|
156
|
+
this._parsedSize = parsedSize;
|
|
157
|
+
}
|
|
158
|
+
toData() {
|
|
159
|
+
return {
|
|
160
|
+
id: this.id,
|
|
161
|
+
name: this.name,
|
|
162
|
+
initial: this.initial,
|
|
163
|
+
size: this.size,
|
|
164
|
+
parsedSize: this._parsedSize || 0,
|
|
165
|
+
entry: this.isEntry(),
|
|
166
|
+
assets: this._assets.map(({ path })=>path),
|
|
167
|
+
modules: this._modules.map(({ id })=>id),
|
|
168
|
+
dependencies: this._dependencies.map(({ id })=>id),
|
|
169
|
+
imported: this._imported.map(({ id })=>id)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
setDependencies(dependencies) {
|
|
173
|
+
this._dependencies = dependencies;
|
|
174
|
+
}
|
|
175
|
+
setImported(imported) {
|
|
176
|
+
this._imported = imported;
|
|
177
|
+
}
|
|
178
|
+
setModules(modules) {
|
|
179
|
+
this._modules = modules;
|
|
180
|
+
}
|
|
181
|
+
setAssets(assets) {
|
|
182
|
+
this._assets = assets;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
class ChunkGraph {
|
|
186
|
+
getAssets() {
|
|
187
|
+
return Array.from(this._assetMap.values());
|
|
188
|
+
}
|
|
189
|
+
getChunks() {
|
|
190
|
+
return Array.from(this._chunkMap.values());
|
|
191
|
+
}
|
|
192
|
+
addAsset(...assets) {
|
|
193
|
+
assets.forEach((asset)=>{
|
|
194
|
+
this._assetMap.set(asset.id, asset), this._assetPathMap.set(asset.path, asset);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
addChunk(...chunks) {
|
|
198
|
+
chunks.forEach((chunk)=>{
|
|
199
|
+
this._chunkMap.set(chunk.id, chunk);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
getChunkById(id) {
|
|
203
|
+
return this._chunkMap.get(id);
|
|
204
|
+
}
|
|
205
|
+
getAssetByPath(path) {
|
|
206
|
+
return this._assetPathMap.get(path);
|
|
207
|
+
}
|
|
208
|
+
getAssetById(id) {
|
|
209
|
+
return this._assetMap.get(id);
|
|
210
|
+
}
|
|
211
|
+
getEntryPoints() {
|
|
212
|
+
return Array.from(this._entrypointMap.values());
|
|
213
|
+
}
|
|
214
|
+
getEntryPointById(id) {
|
|
215
|
+
return this._entrypointMap.get(id);
|
|
216
|
+
}
|
|
217
|
+
addEntryPoint(...entrypoints) {
|
|
218
|
+
entrypoints.forEach((entrypoint)=>{
|
|
219
|
+
this._entrypointMap.set(entrypoint.id, entrypoint);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
toData(type) {
|
|
223
|
+
return {
|
|
224
|
+
assets: Array.from(this._assetMap.values()).map((item)=>item.toData(type)),
|
|
225
|
+
chunks: Array.from(this._chunkMap.values()).map((item)=>item.toData()),
|
|
226
|
+
entrypoints: Array.from(this._entrypointMap.values()).map((item)=>item.toData())
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
setChunks(chunks) {
|
|
230
|
+
this._chunkMap = new Map(chunks.map((item)=>[
|
|
231
|
+
item.id,
|
|
232
|
+
item
|
|
233
|
+
]));
|
|
234
|
+
}
|
|
235
|
+
setEntrypoints(entrypoints) {
|
|
236
|
+
this._entrypointMap = new Map(entrypoints.map((item)=>[
|
|
237
|
+
item.id,
|
|
238
|
+
item
|
|
239
|
+
]));
|
|
240
|
+
}
|
|
241
|
+
setAssets(assets) {
|
|
242
|
+
this._assetMap = new Map(assets.map((item)=>[
|
|
243
|
+
item.id,
|
|
244
|
+
item
|
|
245
|
+
])), this._assetPathMap = new Map(assets.map((item)=>[
|
|
246
|
+
item.path,
|
|
247
|
+
item
|
|
248
|
+
]));
|
|
249
|
+
}
|
|
250
|
+
constructor(){
|
|
251
|
+
this._assetMap = new Map(), this._assetPathMap = new Map(), this._chunkMap = new Map(), this._entrypointMap = new Map();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
let types_namespaceObject = require("@rsdoctor/types");
|
|
255
|
+
var external_node_zlib_ = __webpack_require__("node:zlib");
|
|
256
|
+
let asset_id = 1;
|
|
257
|
+
class Asset {
|
|
258
|
+
static init() {
|
|
259
|
+
asset_id = 1;
|
|
260
|
+
}
|
|
261
|
+
constructor(path, size, chunks, content){
|
|
262
|
+
this.id = asset_id++, this.path = path, this.size = size, this.chunks = chunks, this.content = content;
|
|
263
|
+
}
|
|
264
|
+
toData(types) {
|
|
265
|
+
return {
|
|
266
|
+
id: this.id,
|
|
267
|
+
path: this.path,
|
|
268
|
+
size: this.size,
|
|
269
|
+
gzipSize: this.gzipSize,
|
|
270
|
+
chunks: this.chunks?.map((ck)=>ck.id),
|
|
271
|
+
content: types === types_namespaceObject.SDK.ToDataType.NoSourceAndAssets || types === types_namespaceObject.SDK.ToDataType.NoCode ? '' : this.content
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
setChunks(chunks) {
|
|
275
|
+
this.chunks = chunks;
|
|
276
|
+
}
|
|
277
|
+
setId(id) {
|
|
278
|
+
this.id = id;
|
|
279
|
+
}
|
|
280
|
+
setGzipSize(content) {
|
|
281
|
+
this.gzipSize = (0, external_node_zlib_.gzipSync)(content, {
|
|
282
|
+
level: 9
|
|
283
|
+
}).length;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
let entrypoint_id = 1;
|
|
287
|
+
class EntryPoint {
|
|
288
|
+
static init() {
|
|
289
|
+
entrypoint_id = 1;
|
|
290
|
+
}
|
|
291
|
+
constructor(name){
|
|
292
|
+
this.name = name, this._chunks = [], this._assets = [], this.id = entrypoint_id++;
|
|
293
|
+
}
|
|
294
|
+
addChunk(chunk) {
|
|
295
|
+
this._chunks.includes(chunk) || this._chunks.push(chunk);
|
|
296
|
+
}
|
|
297
|
+
addAsset(asset) {
|
|
298
|
+
this._assets.includes(asset) || this._assets.push(asset);
|
|
299
|
+
}
|
|
300
|
+
toData() {
|
|
301
|
+
return {
|
|
302
|
+
id: this.id,
|
|
303
|
+
name: this.name,
|
|
304
|
+
chunks: this._chunks.map((e)=>e.id),
|
|
305
|
+
assets: this._assets.map((e)=>e.path),
|
|
306
|
+
size: this._assets.length ? this._assets.reduce((t, e)=>t + e.size, 0) : 0
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
setChunks(chunks) {
|
|
310
|
+
this._chunks = chunks;
|
|
311
|
+
}
|
|
312
|
+
setAssets(assets) {
|
|
313
|
+
this._assets = assets;
|
|
314
|
+
}
|
|
315
|
+
setId(id) {
|
|
316
|
+
this.id = id;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
let dependency_id = 1;
|
|
320
|
+
class Dependency {
|
|
321
|
+
static{
|
|
322
|
+
this.kind = types_namespaceObject.SDK.DependencyKind;
|
|
323
|
+
}
|
|
324
|
+
static init() {
|
|
325
|
+
dependency_id = 1;
|
|
326
|
+
}
|
|
327
|
+
constructor(request, module, dependency, kind, statements){
|
|
328
|
+
this.statements = [], this.meta = {
|
|
329
|
+
exportsType: 'default-with-named'
|
|
330
|
+
}, this.id = dependency_id++, this.request = request, this.module = module, this._originDependency = dependency, this.kind = kind, this.statements = statements ?? [];
|
|
331
|
+
}
|
|
332
|
+
get resolvedRequest() {
|
|
333
|
+
return this.dependency.path;
|
|
334
|
+
}
|
|
335
|
+
get dependency() {
|
|
336
|
+
return this.originDependency.rootModule ?? this.originDependency;
|
|
337
|
+
}
|
|
338
|
+
get originDependency() {
|
|
339
|
+
return this._originDependency;
|
|
340
|
+
}
|
|
341
|
+
get kindString() {
|
|
342
|
+
return types_namespaceObject.SDK.DependencyKind[this.kind];
|
|
343
|
+
}
|
|
344
|
+
get resolveConcatenationModule() {
|
|
345
|
+
return this.dependency.kind === types_namespaceObject.SDK.ModuleKind.Concatenation;
|
|
346
|
+
}
|
|
347
|
+
isSameWithoutStatements(dep) {
|
|
348
|
+
return this.request === dep.request && this.kind === dep.kind && this.module.id === dep.module.id && this.dependency.id === dep.dependency.id;
|
|
349
|
+
}
|
|
350
|
+
addStatement(statement) {
|
|
351
|
+
this.hasStatement(statement) || this.statements.push(statement);
|
|
352
|
+
}
|
|
353
|
+
hasStatement(statement) {
|
|
354
|
+
return this.statements.some((item)=>item.isSame(statement));
|
|
355
|
+
}
|
|
356
|
+
setBuildMeta(data) {
|
|
357
|
+
this.meta = {
|
|
358
|
+
...this.meta,
|
|
359
|
+
...data
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
toData() {
|
|
363
|
+
return {
|
|
364
|
+
id: this.id,
|
|
365
|
+
request: this.request,
|
|
366
|
+
resolvedRequest: this.resolvedRequest,
|
|
367
|
+
kind: this.kind,
|
|
368
|
+
module: this.module.id,
|
|
369
|
+
dependency: this.dependency.id,
|
|
370
|
+
originDependency: this.originDependency.id,
|
|
371
|
+
statements: this.statements.map((item)=>item.toData())
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
setId(id) {
|
|
375
|
+
this.id = id;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
let external_path_namespaceObject = require("path");
|
|
379
|
+
var external_path_default = __webpack_require__.n(external_path_namespaceObject);
|
|
380
|
+
let common_namespaceObject = require("@rsdoctor/utils/common");
|
|
381
|
+
function isSamePosition(po1, po2) {
|
|
382
|
+
return po1.line === po2.line && po1.column === po2.column;
|
|
383
|
+
}
|
|
384
|
+
let NAME_WITH_LOADERS = /!/, NAME_WITH_MODULES = /\s\+\s\d*\smodules$/, INVALID_CSS_PREFIX = /^css\s.*node_modules(?!\/)/;
|
|
385
|
+
class Statement {
|
|
386
|
+
static getDefaultStatement(module) {
|
|
387
|
+
let defaultPosition = {
|
|
388
|
+
line: 1,
|
|
389
|
+
column: 0
|
|
390
|
+
}, defaultRange = {
|
|
391
|
+
start: {
|
|
392
|
+
...defaultPosition
|
|
393
|
+
},
|
|
394
|
+
end: {
|
|
395
|
+
...defaultPosition
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
return new Statement(module, {
|
|
399
|
+
source: {
|
|
400
|
+
...defaultRange
|
|
401
|
+
},
|
|
402
|
+
transformed: {
|
|
403
|
+
...defaultRange
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
constructor(module, position){
|
|
408
|
+
this.module = module, this.position = position;
|
|
409
|
+
}
|
|
410
|
+
isSame(statement) {
|
|
411
|
+
var po1, po2;
|
|
412
|
+
return this.module.id === statement.module.id && (po1 = this.position.transformed, po2 = statement.position.transformed, !!isSamePosition(po1.start, po2.start) && (common_namespaceObject.Lodash.isNil(po1.end) || common_namespaceObject.Lodash.isNil(po2.end) ? common_namespaceObject.Lodash.isUndefined(po1.end) && common_namespaceObject.Lodash.isUndefined(po2.end) : isSamePosition(po1.end, po2.end)));
|
|
413
|
+
}
|
|
414
|
+
getSourcePosition() {
|
|
415
|
+
let { module, position } = this;
|
|
416
|
+
return position.source ? position.source : module.getSourceMap() ? (position.source = module.getSourceRange(position.transformed), position.source) : void 0;
|
|
417
|
+
}
|
|
418
|
+
getLineCode() {
|
|
419
|
+
let useSource = this.module.isPreferSource && this.position.source, sourceCode = this.module.getSource(), source = useSource ? sourceCode.source : sourceCode.transformed, line = useSource ? this.position.source.start.line : this.position.transformed.start.line;
|
|
420
|
+
if ('number' == typeof line) return source.split('\n')[line - 1];
|
|
421
|
+
}
|
|
422
|
+
toData() {
|
|
423
|
+
let position = {
|
|
424
|
+
transformed: this.position.transformed
|
|
425
|
+
};
|
|
426
|
+
return this.position.source && (position.source = this.position.source), {
|
|
427
|
+
position,
|
|
428
|
+
module: this.module.id
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
let module_id = 1;
|
|
433
|
+
class Module {
|
|
434
|
+
static{
|
|
435
|
+
this.kind = types_namespaceObject.SDK.ModuleKind;
|
|
436
|
+
}
|
|
437
|
+
static init() {
|
|
438
|
+
module_id = 1;
|
|
439
|
+
}
|
|
440
|
+
constructor(webpackId, path, isEntry = !1, kind = types_namespaceObject.SDK.ModuleKind.Normal, renderId, layer = ''){
|
|
441
|
+
this.issuerPath = [], this.bailoutReason = [], this.source = {
|
|
442
|
+
source: '',
|
|
443
|
+
transformed: '',
|
|
444
|
+
parsedSource: ''
|
|
445
|
+
}, this.size = {
|
|
446
|
+
sourceSize: 0,
|
|
447
|
+
transformedSize: 0,
|
|
448
|
+
parsedSize: 0,
|
|
449
|
+
gzipSize: 0
|
|
450
|
+
}, this.chunks = [], this.dependencies = [], this.imported = [], this.modules = [], this.concatenationModules = [], this.meta = {
|
|
451
|
+
hasSetEsModuleStatement: !1,
|
|
452
|
+
strictHarmonyModule: !1
|
|
453
|
+
}, this.id = module_id++, this.webpackId = webpackId, this.path = path, this.isEntry = isEntry, this.kind = kind, this.renderId = renderId, this.layer = layer;
|
|
454
|
+
}
|
|
455
|
+
get rootModule() {
|
|
456
|
+
return this.modules.find((item)=>item.path === this.path);
|
|
457
|
+
}
|
|
458
|
+
get isPreferSource() {
|
|
459
|
+
if ('boolean' == typeof this._isPreferSource) return this._isPreferSource;
|
|
460
|
+
let result = this.source.source.length > 0 && 'test code' !== this.source.source && !!this.sourceMap;
|
|
461
|
+
return this._isPreferSource = result, result;
|
|
462
|
+
}
|
|
463
|
+
addBailoutReason(reason) {
|
|
464
|
+
this.bailoutReason.push(reason);
|
|
465
|
+
}
|
|
466
|
+
getBailoutReason() {
|
|
467
|
+
return this.bailoutReason;
|
|
468
|
+
}
|
|
469
|
+
getChunks() {
|
|
470
|
+
return this.chunks.slice();
|
|
471
|
+
}
|
|
472
|
+
addChunk(chunk) {
|
|
473
|
+
this.chunks.includes(chunk) || (this.chunks.push(chunk), chunk.addModule(this));
|
|
474
|
+
}
|
|
475
|
+
removeChunk(chunk) {
|
|
476
|
+
this.chunks = this.chunks.filter((item)=>item !== chunk);
|
|
477
|
+
}
|
|
478
|
+
getDependencies() {
|
|
479
|
+
return this.dependencies.slice();
|
|
480
|
+
}
|
|
481
|
+
getDependencyByRequest(request) {
|
|
482
|
+
return this.dependencies.find((item)=>item.request === request);
|
|
483
|
+
}
|
|
484
|
+
getDependencyByModule(module) {
|
|
485
|
+
return this.dependencies.find((item)=>item.originDependency === module || item.dependency === module);
|
|
486
|
+
}
|
|
487
|
+
addDependency(request, module, kind, statements) {
|
|
488
|
+
let dep = new Dependency(request, this, module, kind, statements);
|
|
489
|
+
if (this.dependencies.every((item)=>!item.isSameWithoutStatements(dep))) return this.dependencies.push(dep), module.addImported(this), module.rootModule && module.rootModule.addImported(this), dep;
|
|
490
|
+
}
|
|
491
|
+
removeDependency(dep) {
|
|
492
|
+
this.dependencies = this.dependencies.filter((item)=>item === dep);
|
|
493
|
+
}
|
|
494
|
+
removeDependencyByModule(module) {
|
|
495
|
+
let dep = this.getDependencyByModule(module);
|
|
496
|
+
dep && this.removeDependency(dep);
|
|
497
|
+
}
|
|
498
|
+
getImported() {
|
|
499
|
+
return this.imported.slice();
|
|
500
|
+
}
|
|
501
|
+
addImported(module) {
|
|
502
|
+
this.imported.includes(module) || this.imported.push(module);
|
|
503
|
+
}
|
|
504
|
+
removeImported(module) {
|
|
505
|
+
this.imported = this.imported.filter((item)=>item === module);
|
|
506
|
+
}
|
|
507
|
+
setProgram(program) {
|
|
508
|
+
this.program = program;
|
|
509
|
+
}
|
|
510
|
+
getProgram() {
|
|
511
|
+
return this.program;
|
|
512
|
+
}
|
|
513
|
+
setSource(input) {
|
|
514
|
+
let { source } = this;
|
|
515
|
+
source.source = input.source ?? source.source, source.transformed = input.transformed ?? source.transformed, source.parsedSource = input.parsedSource ?? source.parsedSource;
|
|
516
|
+
}
|
|
517
|
+
getSource(type = types_namespaceObject.SDK.ToDataType.Normal) {
|
|
518
|
+
return type === types_namespaceObject.SDK.ToDataType.NoCode ? {
|
|
519
|
+
source: '',
|
|
520
|
+
transformed: '',
|
|
521
|
+
parsedSource: ''
|
|
522
|
+
} : type === types_namespaceObject.SDK.ToDataType.NoSourceAndAssets || type === types_namespaceObject.SDK.ToDataType.NoSource ? {
|
|
523
|
+
source: '',
|
|
524
|
+
transformed: '',
|
|
525
|
+
parsedSource: this.isPreferSource ? '' : this.source.parsedSource
|
|
526
|
+
} : type === types_namespaceObject.SDK.ToDataType.All ? {
|
|
527
|
+
source: this.source.source,
|
|
528
|
+
transformed: this.source.transformed,
|
|
529
|
+
parsedSource: this.isPreferSource ? '' : this.source.parsedSource
|
|
530
|
+
} : {
|
|
531
|
+
source: this.source.source,
|
|
532
|
+
transformed: '',
|
|
533
|
+
parsedSource: this.isPreferSource ? '' : this.source.parsedSource
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
setSourceMap(sourceMap) {
|
|
537
|
+
this.sourceMap = sourceMap;
|
|
538
|
+
}
|
|
539
|
+
getSourceMap() {
|
|
540
|
+
return this.sourceMap;
|
|
541
|
+
}
|
|
542
|
+
setSize(input) {
|
|
543
|
+
let { size } = this;
|
|
544
|
+
if (size.sourceSize = input.sourceSize ?? size.sourceSize, size.transformedSize = input.transformedSize ?? size.transformedSize, size.parsedSize = input.parsedSize ?? size.parsedSize, 'number' == typeof input.gzipSize) size.gzipSize = input.gzipSize;
|
|
545
|
+
else {
|
|
546
|
+
let code = this.source.parsedSource || this.source.source;
|
|
547
|
+
if (code && 'string' == typeof code && code.length > 0) try {
|
|
548
|
+
size.gzipSize = (0, external_node_zlib_.gzipSync)(code, {
|
|
549
|
+
level: 9
|
|
550
|
+
}).length;
|
|
551
|
+
} catch (e) {
|
|
552
|
+
size.gzipSize = 0;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
getSize() {
|
|
557
|
+
return {
|
|
558
|
+
...this.size
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
getStatement(transformed) {
|
|
562
|
+
return new Statement(this, {
|
|
563
|
+
source: this.getSourceRange(transformed),
|
|
564
|
+
transformed: {
|
|
565
|
+
start: {
|
|
566
|
+
...transformed.start
|
|
567
|
+
},
|
|
568
|
+
end: transformed.end ? {
|
|
569
|
+
...transformed.end
|
|
570
|
+
} : void 0
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
getSourceRange(transformed) {
|
|
575
|
+
let { sourceMap } = this;
|
|
576
|
+
if (!sourceMap) return;
|
|
577
|
+
let source = {
|
|
578
|
+
start: {}
|
|
579
|
+
}, startInSource = sourceMap.originalPositionFor({
|
|
580
|
+
line: transformed.start.line ?? 0,
|
|
581
|
+
column: transformed.start.column ?? 0,
|
|
582
|
+
bias: 1
|
|
583
|
+
});
|
|
584
|
+
if (common_namespaceObject.Lodash.isNumber(startInSource.line) && (source.start = {
|
|
585
|
+
line: startInSource.line,
|
|
586
|
+
column: startInSource.column ?? void 0
|
|
587
|
+
}), transformed.end) {
|
|
588
|
+
let endInSource = sourceMap.originalPositionFor({
|
|
589
|
+
line: transformed.end.line ?? 0,
|
|
590
|
+
column: transformed.end.column ?? 0
|
|
591
|
+
});
|
|
592
|
+
common_namespaceObject.Lodash.isNumber(endInSource.line) && (source.end = {
|
|
593
|
+
line: endInSource.line,
|
|
594
|
+
column: endInSource.column ?? void 0
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
return source;
|
|
598
|
+
}
|
|
599
|
+
addNormalModule(module) {
|
|
600
|
+
this.modules.includes(module) || (this.modules.push(module), module.addConcatenationModule(this));
|
|
601
|
+
}
|
|
602
|
+
getNormalModules() {
|
|
603
|
+
return this.modules.slice();
|
|
604
|
+
}
|
|
605
|
+
addConcatenationModule(module) {
|
|
606
|
+
this.concatenationModules.includes(module) || this.concatenationModules.push(module);
|
|
607
|
+
}
|
|
608
|
+
addIssuerPath(issuerPath) {
|
|
609
|
+
this.issuerPath?.length || (this.issuerPath = issuerPath);
|
|
610
|
+
}
|
|
611
|
+
getIssuerPath() {
|
|
612
|
+
return this.issuerPath;
|
|
613
|
+
}
|
|
614
|
+
getConcatenationModules() {
|
|
615
|
+
return this.concatenationModules.slice();
|
|
616
|
+
}
|
|
617
|
+
toData(contextPath, isBrief) {
|
|
618
|
+
let { isPreferSource } = this, moduleName = function(name) {
|
|
619
|
+
if (!name) return '';
|
|
620
|
+
if (NAME_WITH_LOADERS.test(name)) {
|
|
621
|
+
let normalizedName = common_namespaceObject.Lodash.last(name.split(NAME_WITH_LOADERS));
|
|
622
|
+
if (normalizedName?.trim()) return normalizedName;
|
|
623
|
+
}
|
|
624
|
+
return NAME_WITH_MODULES.test(name) ? name.replace(NAME_WITH_MODULES, '') : INVALID_CSS_PREFIX.test(name) ? name.replace(INVALID_CSS_PREFIX, '') : name;
|
|
625
|
+
}(this.webpackId), data = {
|
|
626
|
+
id: this.id,
|
|
627
|
+
renderId: this.renderId,
|
|
628
|
+
webpackId: contextPath && moduleName.indexOf('.') > 0 ? external_path_default().relative(contextPath, moduleName) : this.webpackId,
|
|
629
|
+
path: this.path,
|
|
630
|
+
isPreferSource,
|
|
631
|
+
dependencies: this.dependencies.map((item)=>item.id),
|
|
632
|
+
imported: this.imported.map((item)=>item.id),
|
|
633
|
+
chunks: this.chunks.map((item)=>item.id),
|
|
634
|
+
size: this.getSize(),
|
|
635
|
+
kind: this.kind,
|
|
636
|
+
...this.layer ? {
|
|
637
|
+
layer: this.layer
|
|
638
|
+
} : {},
|
|
639
|
+
issuerPath: isBrief ? void 0 : this.issuerPath?.filter((issuer)=>issuer.moduleId).map((issuer)=>issuer.moduleId) || [],
|
|
640
|
+
bailoutReason: isBrief ? void 0 : this.bailoutReason
|
|
641
|
+
};
|
|
642
|
+
return (this.meta.hasSetEsModuleStatement || this.meta.strictHarmonyModule) && (data.meta = {}, this.meta.hasSetEsModuleStatement && (data.meta.hasSetEsModuleStatement = !0), this.meta.strictHarmonyModule && (data.meta.strictHarmonyModule = !0)), this.isEntry && (data.isEntry = this.isEntry), this.modules.length > 0 && (data.modules = this.modules.map((item)=>item.id)), this.rootModule && (data.rootModule = this.rootModule.id), this.concatenationModules.length > 0 && (data.concatenationModules = this.concatenationModules.map((data)=>data.id)), data;
|
|
643
|
+
}
|
|
644
|
+
setId(id) {
|
|
645
|
+
this.id = id;
|
|
646
|
+
}
|
|
647
|
+
setRenderId(renderId) {
|
|
648
|
+
this.renderId = renderId;
|
|
649
|
+
}
|
|
650
|
+
setChunks(chunks) {
|
|
651
|
+
this.chunks = chunks;
|
|
652
|
+
}
|
|
653
|
+
setDependencies(dependencies) {
|
|
654
|
+
this.dependencies = dependencies;
|
|
655
|
+
}
|
|
656
|
+
setImported(imported) {
|
|
657
|
+
this.imported = imported;
|
|
658
|
+
}
|
|
659
|
+
setModules(modules) {
|
|
660
|
+
this.modules = modules;
|
|
661
|
+
}
|
|
662
|
+
setConcatenationModules(modules) {
|
|
663
|
+
this.concatenationModules = modules;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
let export_id = 1;
|
|
667
|
+
class ExportInfo {
|
|
668
|
+
static init() {
|
|
669
|
+
export_id = 1;
|
|
670
|
+
}
|
|
671
|
+
constructor(name, identifier, variable){
|
|
672
|
+
this.id = export_id++, this._sideEffects = [], this.name = name, this.identifier = identifier, this._variable = variable;
|
|
673
|
+
}
|
|
674
|
+
get isReExport() {
|
|
675
|
+
return !!this.from;
|
|
676
|
+
}
|
|
677
|
+
set variable(data) {
|
|
678
|
+
this._variable = data;
|
|
679
|
+
}
|
|
680
|
+
get variable() {
|
|
681
|
+
if (this._variable) return this._variable;
|
|
682
|
+
if (!this.from || !1 === this._variable) {
|
|
683
|
+
this._variable = !1;
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
let result = this.getRecursiveExport()?.variable;
|
|
687
|
+
return result || (this._variable = !1), result;
|
|
688
|
+
}
|
|
689
|
+
addSideEffect(info) {
|
|
690
|
+
this._sideEffects.every((item)=>item.id !== info.id) && (this._sideEffects.push(info), this.from && this.from.addSideEffect(info));
|
|
691
|
+
}
|
|
692
|
+
getSideEffects() {
|
|
693
|
+
return this._sideEffects.slice();
|
|
694
|
+
}
|
|
695
|
+
setFromExport(from) {
|
|
696
|
+
this.from = from;
|
|
697
|
+
}
|
|
698
|
+
getRecursiveExport(depth = 1 / 0) {
|
|
699
|
+
if (0 === depth) throw Error('`getRecursiveExport` method parameter depth must be greater than 1.');
|
|
700
|
+
if (!this.from) return this;
|
|
701
|
+
let currentDepth = 0, current = this;
|
|
702
|
+
for(; current.from && currentDepth < depth;)currentDepth++, current = current.from;
|
|
703
|
+
return current;
|
|
704
|
+
}
|
|
705
|
+
toData() {
|
|
706
|
+
let data = {
|
|
707
|
+
id: this.id,
|
|
708
|
+
name: this.name,
|
|
709
|
+
isReExport: this.isReExport,
|
|
710
|
+
used: this._sideEffects.map((item)=>item.id)
|
|
711
|
+
};
|
|
712
|
+
return this.from && (data.from = this.from.id, data.root = this.getRecursiveExport().id), this.variable && (data.variable = this.variable.id), data;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
let sideEffect_id = 1;
|
|
716
|
+
class SideEffect {
|
|
717
|
+
static init() {
|
|
718
|
+
sideEffect_id = 1;
|
|
719
|
+
}
|
|
720
|
+
static{
|
|
721
|
+
this.NamespaceSymbol = Symbol('namespace');
|
|
722
|
+
}
|
|
723
|
+
constructor(name, module, identifier, fromRequest, originName){
|
|
724
|
+
this.id = sideEffect_id++, this._exports = [], this.name = name, this.module = module, this.identifier = identifier, fromRequest && (this.fromDependency = this.module.getDependencyByRequest(fromRequest)), originName === SideEffect.NamespaceSymbol ? this.isNameSpace = !0 : (this.isNameSpace = !1, this.originName = originName);
|
|
725
|
+
}
|
|
726
|
+
get variable() {
|
|
727
|
+
if (void 0 !== this._variable) return this._variable ? this._variable : void 0;
|
|
728
|
+
let result = this.exports[0]?.getRecursiveExport()?.variable;
|
|
729
|
+
return this._variable = result ?? !1, result;
|
|
730
|
+
}
|
|
731
|
+
get exports() {
|
|
732
|
+
return this._exports?.slice() ?? [];
|
|
733
|
+
}
|
|
734
|
+
setModuleExport(mgm) {
|
|
735
|
+
mgm.getExports().forEach((info)=>this.setExportInfo(info));
|
|
736
|
+
}
|
|
737
|
+
setExportInfo(info) {
|
|
738
|
+
this._exports.push(info), info.addSideEffect(this);
|
|
739
|
+
}
|
|
740
|
+
toData() {
|
|
741
|
+
let data = {
|
|
742
|
+
id: this.id,
|
|
743
|
+
name: this.name,
|
|
744
|
+
identifier: this.identifier.toData(),
|
|
745
|
+
module: this.module.id
|
|
746
|
+
};
|
|
747
|
+
return this.fromDependency && (data.fromDependency = this.fromDependency.id), this.isNameSpace && (data.isNameSpace = this.isNameSpace), this.exports.length > 0 && (data.exports = this.exports.map((item)=>item.id)), this.variable && (data.variable = this.variable.id), data;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
let variable_id = 1;
|
|
751
|
+
class Variable {
|
|
752
|
+
static init() {
|
|
753
|
+
variable_id = 1;
|
|
754
|
+
}
|
|
755
|
+
constructor(name, module, usedInfo, identifier){
|
|
756
|
+
this.id = variable_id++, this.name = name, this.module = module, this.usedInfo = usedInfo, this.identifier = identifier;
|
|
757
|
+
}
|
|
758
|
+
get isUsed() {
|
|
759
|
+
return !!this._exported && this._exported.getSideEffects().length > 0;
|
|
760
|
+
}
|
|
761
|
+
setExportInfo(info) {
|
|
762
|
+
this._exported = info, info.variable = this;
|
|
763
|
+
}
|
|
764
|
+
getExportInfo() {
|
|
765
|
+
return this._exported;
|
|
766
|
+
}
|
|
767
|
+
toData() {
|
|
768
|
+
let data = {
|
|
769
|
+
id: this.id,
|
|
770
|
+
name: this.name,
|
|
771
|
+
module: this.module.id,
|
|
772
|
+
identifier: this.identifier.toData(),
|
|
773
|
+
usedInfo: this.usedInfo
|
|
774
|
+
};
|
|
775
|
+
return this._exported && (data.exported = this._exported.id), data;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
class ModuleGraphModule {
|
|
779
|
+
static init() {
|
|
780
|
+
ExportInfo.init(), SideEffect.init(), Variable.init();
|
|
781
|
+
}
|
|
782
|
+
constructor(module, graph, dynamic){
|
|
783
|
+
this.exports = [], this.sideEffects = [], this.variables = [], this.module = module, this._graph = graph, 'boolean' == typeof this._dynamic && (this._dynamic = dynamic);
|
|
784
|
+
}
|
|
785
|
+
get dynamic() {
|
|
786
|
+
return 'boolean' == typeof this._dynamic ? this._dynamic : this.module.getImported().map((item)=>item.getDependencyByModule(this.module)).some((item)=>item && 'dynamic' === item.meta.exportsType);
|
|
787
|
+
}
|
|
788
|
+
addExportInfo(data) {
|
|
789
|
+
this.exports.push(data), this._graph.addExportInfo(data);
|
|
790
|
+
}
|
|
791
|
+
addSideEffect(data) {
|
|
792
|
+
this.sideEffects.push(data), this._graph.addSideEffect(data);
|
|
793
|
+
}
|
|
794
|
+
addVariable(data) {
|
|
795
|
+
this.variables.push(data), this._graph.addVariable(data);
|
|
796
|
+
}
|
|
797
|
+
getExports() {
|
|
798
|
+
return this.exports.slice();
|
|
799
|
+
}
|
|
800
|
+
getSideEffects(name) {
|
|
801
|
+
return name ? this.sideEffects.filter((item)=>item.name === name) : this.sideEffects.slice();
|
|
802
|
+
}
|
|
803
|
+
getOwnExports() {
|
|
804
|
+
return this.exports.filter((item)=>!item.isReExport);
|
|
805
|
+
}
|
|
806
|
+
getExport(name) {
|
|
807
|
+
return this.exports.find((item)=>item.name === name);
|
|
808
|
+
}
|
|
809
|
+
getReExports() {
|
|
810
|
+
return this.exports.filter((item)=>item.isReExport);
|
|
811
|
+
}
|
|
812
|
+
getOwnExport(name) {
|
|
813
|
+
return this.getOwnExports().find((item)=>item.name === name);
|
|
814
|
+
}
|
|
815
|
+
getReExport(name) {
|
|
816
|
+
return this.getReExports().find((item)=>item.name === name);
|
|
817
|
+
}
|
|
818
|
+
toData() {
|
|
819
|
+
return {
|
|
820
|
+
module: this.module.id,
|
|
821
|
+
dynamic: this.dynamic,
|
|
822
|
+
exports: this.exports.map((item)=>item.id),
|
|
823
|
+
sideEffects: this.sideEffects.map((item)=>item.id),
|
|
824
|
+
variables: this.variables.map((item)=>item.id)
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
class ModuleGraph {
|
|
829
|
+
static init() {
|
|
830
|
+
Module.init(), Dependency.init(), ModuleGraphModule.init();
|
|
831
|
+
}
|
|
832
|
+
static fromData(data) {
|
|
833
|
+
let moduleGraph = new ModuleGraph(), getStatement = (data)=>new Statement(moduleGraph.getModuleById(data.module), data.position);
|
|
834
|
+
for (let item of data.modules ?? []){
|
|
835
|
+
let module = new Module(String(item.id), item.path, item.isEntry, item.kind, item.renderId, item.layer);
|
|
836
|
+
module.id = item.id, module.setSize(item.size), module.meta = {
|
|
837
|
+
strictHarmonyModule: item.meta?.strictHarmonyModule ?? !1,
|
|
838
|
+
hasSetEsModuleStatement: item.meta?.hasSetEsModuleStatement ?? !1
|
|
839
|
+
}, module._isPreferSource = item.isPreferSource, module.chunks = item.chunks, moduleGraph.addModule(module);
|
|
840
|
+
}
|
|
841
|
+
for (let moduleData of data.modules ?? []){
|
|
842
|
+
let module = moduleGraph.getModuleById(moduleData.id);
|
|
843
|
+
for (let depId of moduleData.dependencies){
|
|
844
|
+
let depData = (data.dependencies ?? []).find((item)=>item.id === depId), depModule = depData && moduleGraph.getModuleById(depData.originDependency);
|
|
845
|
+
if (!depData || !depModule) {
|
|
846
|
+
console.warn(`The connection data ID is empty: ${depId}`);
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
let dep = module.addDependency(depData.request, depModule, depData.kind, depData.statements.map(getStatement));
|
|
850
|
+
dep && (dep.id = depData.id, moduleGraph.addDependency(dep));
|
|
851
|
+
}
|
|
852
|
+
for (let normalModuleId of moduleData.modules ?? []){
|
|
853
|
+
let normalModule = moduleGraph.getModuleById(normalModuleId);
|
|
854
|
+
if (!normalModule) {
|
|
855
|
+
console.warn(`Add the ordinary module ID as empty: ${normalModuleId}`);
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
module.addNormalModule(normalModule);
|
|
859
|
+
}
|
|
860
|
+
for (let concatenationModuleId of moduleData.concatenationModules ?? []){
|
|
861
|
+
let concatenationModule = moduleGraph.getModuleById(concatenationModuleId);
|
|
862
|
+
if (!concatenationModule) {
|
|
863
|
+
console.warn(`The aggregation module ID is empty: ${concatenationModule}`);
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
module.addConcatenationModule(concatenationModule);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
for (let exportData of data.exports ?? []){
|
|
870
|
+
let info = new ExportInfo(exportData.name, exportData.identifier ? getStatement(exportData.identifier) : void 0);
|
|
871
|
+
info.id = exportData.id, moduleGraph.addExportInfo(info);
|
|
872
|
+
}
|
|
873
|
+
for (let exportData of data.exports ?? [])if (exportData.from) {
|
|
874
|
+
let current = moduleGraph._exportIdMap.get(exportData.id), from = moduleGraph._exportIdMap.get(exportData.from);
|
|
875
|
+
current && from && current.setFromExport(from);
|
|
876
|
+
}
|
|
877
|
+
for (let varData of data.variables ?? []){
|
|
878
|
+
let module = moduleGraph.getModuleById(varData.module);
|
|
879
|
+
if (!module) {
|
|
880
|
+
console.warn(`The module ID in the variable is empty\u{FF1A}${varData.module}`);
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
let info = new Variable(varData.name, module, varData.usedInfo, getStatement(varData.identifier)), exportInfo = moduleGraph._exportIdMap.get(varData.exported ?? -1);
|
|
884
|
+
exportInfo && info.setExportInfo(exportInfo), info.id = varData.id, moduleGraph.addVariable(info);
|
|
885
|
+
}
|
|
886
|
+
for (let sideData of data.sideEffects ?? []){
|
|
887
|
+
let module = moduleGraph.getModuleById(sideData.module);
|
|
888
|
+
if (!module) {
|
|
889
|
+
console.warn(`The module ID in the side effects is empty\u{FF1A}${sideData.module}`);
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
let info = new SideEffect(sideData.name, module, getStatement(sideData.identifier), sideData.originName);
|
|
893
|
+
for (let exportId of (info.isNameSpace = sideData.isNameSpace, info.id = sideData.id, sideData.exports ?? [])){
|
|
894
|
+
let exportInfo = moduleGraph._exportIdMap.get(exportId);
|
|
895
|
+
exportInfo && exportInfo.addSideEffect(info);
|
|
896
|
+
}
|
|
897
|
+
if (sideData.variable) {
|
|
898
|
+
let varInfo = moduleGraph._varIdMap.get(sideData.variable);
|
|
899
|
+
varInfo && (info._variable = varInfo);
|
|
900
|
+
}
|
|
901
|
+
moduleGraph.addSideEffect(info);
|
|
902
|
+
}
|
|
903
|
+
for (let mgmData of data.moduleGraphModules ?? []){
|
|
904
|
+
let module = moduleGraph.getModuleById(mgmData.module);
|
|
905
|
+
if (!module) {
|
|
906
|
+
console.warn(`The module ID in ModuleGraphModule is empty: ${mgmData.module}`);
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
let mgm = new ModuleGraphModule(module, moduleGraph, mgmData.dynamic);
|
|
910
|
+
moduleGraph.addModuleGraphModule(mgm), mgmData.exports.forEach((id)=>{
|
|
911
|
+
let info = moduleGraph._exportIdMap.get(id);
|
|
912
|
+
info && mgm.addExportInfo(info);
|
|
913
|
+
}), mgmData.sideEffects.forEach((id)=>{
|
|
914
|
+
let info = moduleGraph._sideEffectIdMap.get(id);
|
|
915
|
+
info && mgm.addSideEffect(info);
|
|
916
|
+
}), mgmData.variables.forEach((id)=>{
|
|
917
|
+
let info = moduleGraph._varIdMap.get(id);
|
|
918
|
+
info && mgm.addVariable(info);
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
return ModuleGraph.init(), moduleGraph;
|
|
922
|
+
}
|
|
923
|
+
clear() {
|
|
924
|
+
this._dependenciesIdMap = new Map(), this._moduleWebpackIdMap = new Map(), this._moduleIdMap = new Map(), this._moduleGraphModules = new Map(), this._exportIdMap = new Map(), this._sideEffectIdMap = new Map(), this._varIdMap = new Map(), this._layers = new Map();
|
|
925
|
+
}
|
|
926
|
+
size() {
|
|
927
|
+
return this._moduleIdMap.size;
|
|
928
|
+
}
|
|
929
|
+
fromInstance(data) {
|
|
930
|
+
this._dependenciesIdMap = new Map(data._dependenciesIdMap), this._moduleWebpackIdMap = new Map(data._moduleWebpackIdMap), this._moduleIdMap = new Map(data._moduleIdMap), this._moduleGraphModules = new Map(data._moduleGraphModules), this._exportIdMap = new Map(data._exportIdMap), this._sideEffectIdMap = new Map(data._sideEffectIdMap), this._varIdMap = new Map(data._varIdMap), this._layers = new Map(data._layers);
|
|
931
|
+
}
|
|
932
|
+
getSubGraphByModule(module) {
|
|
933
|
+
let map = new Set(), result = [
|
|
934
|
+
module
|
|
935
|
+
];
|
|
936
|
+
map.add(module);
|
|
937
|
+
for(let i = 0; i < result.length; i++)for (let { dependency: depModule } of result[i].getDependencies())map.has(depModule) || (map.add(depModule), result.push(depModule));
|
|
938
|
+
return result;
|
|
939
|
+
}
|
|
940
|
+
getModules() {
|
|
941
|
+
return Array.from(this._moduleWebpackIdMap.values());
|
|
942
|
+
}
|
|
943
|
+
getDependencies() {
|
|
944
|
+
return Array.from(this._dependenciesIdMap.values());
|
|
945
|
+
}
|
|
946
|
+
getEntryModules() {
|
|
947
|
+
return this.getModules().filter((item)=>item.isEntry && item.kind !== types_namespaceObject.SDK.ModuleKind.Concatenation);
|
|
948
|
+
}
|
|
949
|
+
getModuleById(id) {
|
|
950
|
+
return this._moduleIdMap.get(id);
|
|
951
|
+
}
|
|
952
|
+
getDependencyById(id) {
|
|
953
|
+
return this._dependenciesIdMap.get(id);
|
|
954
|
+
}
|
|
955
|
+
getModuleByWebpackId(id) {
|
|
956
|
+
return this._moduleWebpackIdMap.get(id);
|
|
957
|
+
}
|
|
958
|
+
getModuleByFile(file) {
|
|
959
|
+
return this.getModules().find((item)=>item.path === file);
|
|
960
|
+
}
|
|
961
|
+
addModule(...modules) {
|
|
962
|
+
for (let module of modules)!this._moduleIdMap.has(module.id) && (this._moduleWebpackIdMap.set(module.webpackId, module), this._moduleIdMap.set(module.id, module), module.layer && this.addLayer(module.layer));
|
|
963
|
+
}
|
|
964
|
+
addDependency(...deps) {
|
|
965
|
+
for (let dep of deps)this._dependenciesIdMap.has(dep.id) || (this._dependenciesIdMap.set(dep.id, dep), this.addModule(dep.module), this.addModule(dep.dependency));
|
|
966
|
+
}
|
|
967
|
+
removeModule(module) {
|
|
968
|
+
for (let dep of (this._moduleIdMap.delete(module.id), this._moduleWebpackIdMap.delete(module.webpackId), module.getDependencies()))this.removeDependency(dep), this._dependenciesIdMap.delete(dep.id);
|
|
969
|
+
for (let imported of module.getImported())imported.removeDependencyByModule(imported);
|
|
970
|
+
}
|
|
971
|
+
removeDependency(dep) {
|
|
972
|
+
dep.module.removeDependency(dep), dep.dependency.removeImported(dep.module), this._dependenciesIdMap.delete(dep.id);
|
|
973
|
+
}
|
|
974
|
+
addModuleGraphModule(mgm) {
|
|
975
|
+
this._moduleGraphModules.has(mgm.module) || this._moduleGraphModules.set(mgm.module, mgm);
|
|
976
|
+
}
|
|
977
|
+
getModuleGraphModule(module) {
|
|
978
|
+
return this._moduleGraphModules.get(module);
|
|
979
|
+
}
|
|
980
|
+
getModuleGraphModules() {
|
|
981
|
+
return Array.from(this._moduleGraphModules.values());
|
|
982
|
+
}
|
|
983
|
+
addExportInfo(data) {
|
|
984
|
+
this._exportIdMap.set(data.id, data);
|
|
985
|
+
}
|
|
986
|
+
addSideEffect(data) {
|
|
987
|
+
this._sideEffectIdMap.set(data.id, data);
|
|
988
|
+
}
|
|
989
|
+
addVariable(data) {
|
|
990
|
+
this._varIdMap.set(data.id, data);
|
|
991
|
+
}
|
|
992
|
+
addLayer(layer) {
|
|
993
|
+
this._layers.get(layer) || this._layers.set(layer, 1);
|
|
994
|
+
}
|
|
995
|
+
getLayers() {
|
|
996
|
+
return this._layers;
|
|
997
|
+
}
|
|
998
|
+
toData(configs) {
|
|
999
|
+
let isBrief = !!(configs?.briefOptions?.type && configs.briefOptions.type.length);
|
|
1000
|
+
return {
|
|
1001
|
+
dependencies: this.getDependencies().map((item)=>item.toData()),
|
|
1002
|
+
modules: this.getModules().map((item)=>item.toData(configs?.contextPath, isBrief)),
|
|
1003
|
+
moduleGraphModules: isBrief ? [] : Array.from(this._moduleGraphModules.values()).map((item)=>item.toData()),
|
|
1004
|
+
exports: isBrief ? [] : Array.from(this._exportIdMap.values()).map((item)=>item.toData()),
|
|
1005
|
+
sideEffects: isBrief ? [] : Array.from(this._sideEffectIdMap.values()).map((item)=>item.toData()),
|
|
1006
|
+
variables: isBrief ? [] : Array.from(this._varIdMap.values()).map((item)=>item.toData()),
|
|
1007
|
+
layers: Array.from(this._layers.keys())
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
toCodeData(type = types_namespaceObject.SDK.ToDataType.Normal) {
|
|
1011
|
+
let codeMap = {};
|
|
1012
|
+
return this.getModules().forEach((item)=>{
|
|
1013
|
+
codeMap[item.id] = item.getSource(type);
|
|
1014
|
+
}), codeMap;
|
|
1015
|
+
}
|
|
1016
|
+
setModules(modules) {
|
|
1017
|
+
this._moduleIdMap = new Map(modules.map((m)=>[
|
|
1018
|
+
m.id,
|
|
1019
|
+
m
|
|
1020
|
+
])), this._moduleWebpackIdMap = new Map(modules.map((m)=>[
|
|
1021
|
+
m.webpackId,
|
|
1022
|
+
m
|
|
1023
|
+
])), this._layers = new Map(modules.filter((m)=>m.layer).map((m)=>[
|
|
1024
|
+
m.layer,
|
|
1025
|
+
1
|
|
1026
|
+
]));
|
|
1027
|
+
}
|
|
1028
|
+
setDependencies(dependencies) {
|
|
1029
|
+
this._dependenciesIdMap = new Map(dependencies.map((d)=>[
|
|
1030
|
+
d.id,
|
|
1031
|
+
d
|
|
1032
|
+
]));
|
|
1033
|
+
}
|
|
1034
|
+
constructor(){
|
|
1035
|
+
this._dependenciesIdMap = new Map(), this._moduleWebpackIdMap = new Map(), this._moduleIdMap = new Map(), this._moduleGraphModules = new Map(), this._exportIdMap = new Map(), this._sideEffectIdMap = new Map(), this._varIdMap = new Map(), this._layers = new Map();
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
let package_graph_dependency_id = 1;
|
|
1039
|
+
class PackageDependency {
|
|
1040
|
+
constructor(pack, dep, refDependency){
|
|
1041
|
+
this.id = package_graph_dependency_id++, this.package = pack, this.dependency = dep, this.refDependency = refDependency;
|
|
1042
|
+
}
|
|
1043
|
+
get name() {
|
|
1044
|
+
return this.dependency.name;
|
|
1045
|
+
}
|
|
1046
|
+
get version() {
|
|
1047
|
+
return this.dependency.version;
|
|
1048
|
+
}
|
|
1049
|
+
get root() {
|
|
1050
|
+
return this.dependency.root;
|
|
1051
|
+
}
|
|
1052
|
+
isSame(dep) {
|
|
1053
|
+
return this.refDependency === dep.refDependency && this.dependency.isSame(dep.dependency);
|
|
1054
|
+
}
|
|
1055
|
+
toData() {
|
|
1056
|
+
return {
|
|
1057
|
+
id: this.id,
|
|
1058
|
+
dependency: this.dependency.id,
|
|
1059
|
+
package: this.package.id,
|
|
1060
|
+
refDependency: this.refDependency.id
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
let external_lodash_unionby_namespaceObject = require("lodash.unionby");
|
|
1065
|
+
var external_lodash_unionby_default = __webpack_require__.n(external_lodash_unionby_namespaceObject);
|
|
1066
|
+
let readPackageJson = (file, readFile)=>{
|
|
1067
|
+
let result, current = file;
|
|
1068
|
+
for(; '/' !== current && !result && (0, external_path_namespaceObject.dirname)(current) !== current;)current = (0, external_path_namespaceObject.dirname)(current), readFile && (result = readFile((0, external_path_namespaceObject.join)(current, 'package.json'))), readFile ? result?.name || (result = void 0) : result = common_namespaceObject.Package.getPackageMetaFromModulePath(file);
|
|
1069
|
+
if (result) return !readFile || result.name && result.version ? {
|
|
1070
|
+
...result,
|
|
1071
|
+
root: current
|
|
1072
|
+
} : readPackageJson((0, external_path_namespaceObject.dirname)(current), readFile);
|
|
1073
|
+
}, package_id = 1;
|
|
1074
|
+
class Package {
|
|
1075
|
+
constructor(name, root, version){
|
|
1076
|
+
this.id = package_id++, this._modules = [], this._dependencies = [], this._imported = [], this.name = name, this.root = root, this.version = version, this.duplicates = [];
|
|
1077
|
+
}
|
|
1078
|
+
setDuplicates(data) {
|
|
1079
|
+
this.duplicates.push({
|
|
1080
|
+
module: data.module,
|
|
1081
|
+
chunks: data.chunks
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
getModules() {
|
|
1085
|
+
return this._modules.slice();
|
|
1086
|
+
}
|
|
1087
|
+
getDependencies() {
|
|
1088
|
+
return this._dependencies.slice();
|
|
1089
|
+
}
|
|
1090
|
+
getImported() {
|
|
1091
|
+
return this._imported.slice();
|
|
1092
|
+
}
|
|
1093
|
+
addModule(module) {
|
|
1094
|
+
this._modules.includes(module) || this._modules.push(module);
|
|
1095
|
+
}
|
|
1096
|
+
addDependency(dep) {
|
|
1097
|
+
this._dependencies.every((item)=>!item.isSame(dep)) && (this._dependencies.push(dep), dep.dependency.addImported(this));
|
|
1098
|
+
}
|
|
1099
|
+
getDependenciesChain(graph) {
|
|
1100
|
+
return function getImported(pkg, ans) {
|
|
1101
|
+
for (let dep of graph.getDependenciesFromPackage(pkg))if (dep.refDependency && !ans.some((dep)=>dep.dependency === pkg)) {
|
|
1102
|
+
if (!dep.package) return ans.concat(dep);
|
|
1103
|
+
return getImported(dep.package, ans.concat(dep));
|
|
1104
|
+
}
|
|
1105
|
+
return ans;
|
|
1106
|
+
}(this, []);
|
|
1107
|
+
}
|
|
1108
|
+
addImported(pkg) {
|
|
1109
|
+
this._imported.includes(pkg) || this._imported.push(pkg);
|
|
1110
|
+
}
|
|
1111
|
+
contain(file) {
|
|
1112
|
+
var path;
|
|
1113
|
+
return !!file.includes(this.root) && (path = (0, external_path_namespaceObject.relative)(this.root, file), !/(^|[/\\])node_modules[/\\]/.test(path));
|
|
1114
|
+
}
|
|
1115
|
+
isSame(pkg) {
|
|
1116
|
+
return this.root === pkg.root && this.version === pkg.version && this.name === pkg.name;
|
|
1117
|
+
}
|
|
1118
|
+
getSize() {
|
|
1119
|
+
return this._modules.reduce((ans, item)=>{
|
|
1120
|
+
let size = item.getSize();
|
|
1121
|
+
return ans.sourceSize += size.sourceSize, ans.transformedSize += size.transformedSize, ans.parsedSize += size.parsedSize, ans.gzipSize += size.gzipSize, ans;
|
|
1122
|
+
}, {
|
|
1123
|
+
sourceSize: 0,
|
|
1124
|
+
transformedSize: 0,
|
|
1125
|
+
parsedSize: 0,
|
|
1126
|
+
gzipSize: 0
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
toData() {
|
|
1130
|
+
return {
|
|
1131
|
+
id: this.id,
|
|
1132
|
+
name: this.name,
|
|
1133
|
+
root: this.root,
|
|
1134
|
+
version: this.version,
|
|
1135
|
+
modules: this.getModules().map((e)=>e.id),
|
|
1136
|
+
size: this.getSize(),
|
|
1137
|
+
duplicates: this.duplicates
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
class PackageGraph {
|
|
1142
|
+
static fromModuleGraph(graph, root, getPackageFile) {
|
|
1143
|
+
let pkgGraph = new PackageGraph(root);
|
|
1144
|
+
for (let item of graph.getModules().filter((item)=>item.kind === types_namespaceObject.SDK.ModuleKind.Normal)){
|
|
1145
|
+
if (!item.getChunks()) continue;
|
|
1146
|
+
let pkg = pkgGraph.getPackageByModule(item, getPackageFile);
|
|
1147
|
+
pkg && (pkgGraph.addPackage(pkg), pkg.addModule(item));
|
|
1148
|
+
}
|
|
1149
|
+
for (let dep of graph.getDependencies()){
|
|
1150
|
+
let modulePkg = pkgGraph.getPackageByFile(dep.module.path), dependencyPkg = pkgGraph.getPackageByFile(dep.dependency.path);
|
|
1151
|
+
if (modulePkg && dependencyPkg && !modulePkg.isSame(dependencyPkg)) {
|
|
1152
|
+
let pkgDep = new PackageDependency(modulePkg, dependencyPkg, dep);
|
|
1153
|
+
pkgGraph.addDependency(pkgDep), modulePkg.addDependency(pkgDep);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return pkgGraph;
|
|
1157
|
+
}
|
|
1158
|
+
constructor(root){
|
|
1159
|
+
this._dependencies = [], this._packages = [], this._pkgNameMap = new Map(), this._pkgFileMap = new Map(), this._root = root;
|
|
1160
|
+
}
|
|
1161
|
+
getPackages() {
|
|
1162
|
+
return this._packages.slice();
|
|
1163
|
+
}
|
|
1164
|
+
getPackageByModule(module, readFile) {
|
|
1165
|
+
let { path: file, meta } = module, { _pkgFileMap: pkgsMap } = this, getPackageByData = (data)=>this.getPackageByData(data) ?? new Package(data.name, data.root, data.version);
|
|
1166
|
+
if (pkgsMap.has(file)) return pkgsMap.get(file);
|
|
1167
|
+
if (meta.packageData) {
|
|
1168
|
+
let pkg = getPackageByData(meta.packageData);
|
|
1169
|
+
return this.setDuplicates(module, pkg), pkgsMap.set(file, pkg), pkg;
|
|
1170
|
+
}
|
|
1171
|
+
let cache = this.getPackageContainFile(file);
|
|
1172
|
+
if (cache) return pkgsMap.set(file, cache), cache;
|
|
1173
|
+
let data = readPackageJson(file, readFile);
|
|
1174
|
+
if (!data) return;
|
|
1175
|
+
data.root.startsWith('.') && (data.root = (0, external_path_namespaceObject.resolve)(this._root, data.root));
|
|
1176
|
+
let pkg = getPackageByData(data);
|
|
1177
|
+
return this.setDuplicates(module, pkg), this.addPackage(pkg), pkgsMap.set(file, pkg), pkg;
|
|
1178
|
+
}
|
|
1179
|
+
getPackageByFile(file) {
|
|
1180
|
+
return this._pkgFileMap.get(file);
|
|
1181
|
+
}
|
|
1182
|
+
getPackageContainFile(file) {
|
|
1183
|
+
return this._packages.find((pkg)=>pkg.contain(file));
|
|
1184
|
+
}
|
|
1185
|
+
getPackagesByName(name) {
|
|
1186
|
+
return this._pkgNameMap.get(name) ?? [];
|
|
1187
|
+
}
|
|
1188
|
+
getPackageByData(data) {
|
|
1189
|
+
return this._pkgNameMap.get(data.name)?.find((item)=>item.version === data.version && item.root === data.root);
|
|
1190
|
+
}
|
|
1191
|
+
addPackage(pkg) {
|
|
1192
|
+
if (this._packages.every((item)=>!item.isSame(pkg))) {
|
|
1193
|
+
this._packages.push(pkg);
|
|
1194
|
+
let { _pkgNameMap: map } = this, arr = map.get(pkg.name) ?? [];
|
|
1195
|
+
arr.every((item)=>!item.isSame(pkg)) && (arr.push(pkg), map.set(pkg.name, arr));
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
setDuplicates(module, pkg) {
|
|
1199
|
+
let assetsList = [], chunksList = module.getChunks();
|
|
1200
|
+
chunksList.forEach((chunk)=>assetsList.push(...chunk.getAssets().filter((asset)=>asset.path.endsWith('.js')))), chunksList.length > 1 && pkg.setDuplicates({
|
|
1201
|
+
module: {
|
|
1202
|
+
id: module.id,
|
|
1203
|
+
path: module.path
|
|
1204
|
+
},
|
|
1205
|
+
chunks: assetsList.map((asset)=>({
|
|
1206
|
+
name: asset.path
|
|
1207
|
+
}))
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
getDependenciesFromPackage(pkg) {
|
|
1211
|
+
return this._dependencies.filter((dep)=>dep.dependency === pkg);
|
|
1212
|
+
}
|
|
1213
|
+
addDependency(dep) {
|
|
1214
|
+
this._dependencies.every((item)=>!item.isSame(dep)) && this._dependencies.push(dep);
|
|
1215
|
+
}
|
|
1216
|
+
getDependenciesFromOrigin() {
|
|
1217
|
+
return this._dependencies.filter((item)=>!item.package);
|
|
1218
|
+
}
|
|
1219
|
+
getDuplicatePackages() {
|
|
1220
|
+
return external_lodash_unionby_default()(Array.from(this._pkgNameMap.values()).map((pkgs)=>external_lodash_unionby_default()(pkgs, 'version')).filter((pkgs)=>pkgs.length > 1), (pkgs)=>pkgs[0].name);
|
|
1221
|
+
}
|
|
1222
|
+
toData() {
|
|
1223
|
+
return {
|
|
1224
|
+
packages: this._packages.map((e)=>e.toData()),
|
|
1225
|
+
dependencies: this._dependencies.map((d)=>d.toData())
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
let logger_namespaceObject = require("@rsdoctor/utils/logger");
|
|
1230
|
+
async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, opts, sourceMapSets = new Map()) {
|
|
1231
|
+
if (opts.parseBundle && sourceMapSets.size < 1) {
|
|
1232
|
+
(0, logger_namespaceObject.time)("Start Parse bundle by AST.");
|
|
1233
|
+
let { parseBundle = ()=>({}) } = opts || {}, assets = chunkGraph.getAssets(), modules = moduleGraph.getModules(), bundlesSources = null, parsedModules = null;
|
|
1234
|
+
if (bundleDir && assets.length) {
|
|
1235
|
+
for (let asset of (bundlesSources = {}, parsedModules = {}, assets)){
|
|
1236
|
+
let bundleInfo, assetFile = external_path_default().join(bundleDir, asset.path);
|
|
1237
|
+
try {
|
|
1238
|
+
bundleInfo = parseBundle(assetFile, modules);
|
|
1239
|
+
} catch (err) {
|
|
1240
|
+
let { code = '', message } = err, msg = 'ENOENT' === code ? 'no such file' : message;
|
|
1241
|
+
'1' === process.env.DEVTOOLS_NODE_DEV && logger_namespaceObject.logger.warn(`Error parsing bundle asset "${assetFile}": ${msg}`);
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
bundlesSources[asset.path] = common_namespaceObject.Lodash.pick(bundleInfo, [
|
|
1245
|
+
'src',
|
|
1246
|
+
'runtimeSrc'
|
|
1247
|
+
]), Object.assign(parsedModules, bundleInfo?.modules || {});
|
|
1248
|
+
}
|
|
1249
|
+
common_namespaceObject.Lodash.isEmpty(bundlesSources) && (bundlesSources = null, parsedModules = null, process.env.DEVTOOLS_DEV && logger_namespaceObject.logger.warn('\nNo bundles were parsed. Analyzer will show only original module sizes from stats file.\n')), parsedModules && transformAssetsModulesData(parsedModules, moduleGraph);
|
|
1250
|
+
}
|
|
1251
|
+
(0, logger_namespaceObject.timeEnd)("Start Parse bundle by AST.");
|
|
1252
|
+
} else {
|
|
1253
|
+
for (let [modulePath, codes] of ((0, logger_namespaceObject.time)("Start Parse bundle by sourcemap."), sourceMapSets.entries())){
|
|
1254
|
+
let gzipSize, module = moduleGraph.getModuleByFile(modulePath);
|
|
1255
|
+
if (module) {
|
|
1256
|
+
try {
|
|
1257
|
+
if (codes && 'string' == typeof codes && codes.length > 0) {
|
|
1258
|
+
let { gzipSync } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "node:zlib", 23));
|
|
1259
|
+
gzipSize = gzipSync(codes, {
|
|
1260
|
+
level: 9
|
|
1261
|
+
}).length;
|
|
1262
|
+
}
|
|
1263
|
+
} catch {}
|
|
1264
|
+
module?.setSize({
|
|
1265
|
+
parsedSize: codes.length,
|
|
1266
|
+
gzipSize
|
|
1267
|
+
}), module?.setSource({
|
|
1268
|
+
parsedSource: codes
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
(0, logger_namespaceObject.timeEnd)("Start Parse bundle by sourcemap.");
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
function transformAssetsModulesData(parsedModulesData, moduleGraph) {
|
|
1276
|
+
moduleGraph && Object.entries(parsedModulesData).forEach(([moduleId, parsedData])=>{
|
|
1277
|
+
let gzipSize, module = moduleGraph.getModuleByWebpackId(moduleId ?? '');
|
|
1278
|
+
try {
|
|
1279
|
+
parsedData?.content && 'string' == typeof parsedData.content && parsedData.content.length > 0 && (gzipSize = (0, external_node_zlib_.gzipSync)(parsedData.content, {
|
|
1280
|
+
level: 9
|
|
1281
|
+
}).length);
|
|
1282
|
+
} catch {}
|
|
1283
|
+
module?.setSize({
|
|
1284
|
+
parsedSize: parsedData?.size,
|
|
1285
|
+
gzipSize
|
|
1286
|
+
}), module?.setSource({
|
|
1287
|
+
parsedSource: parsedData?.content || ''
|
|
1288
|
+
});
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
function chunkTransform(assetMap, bundleStats) {
|
|
1292
|
+
let chunkGraph = new ChunkGraph();
|
|
1293
|
+
if (bundleStats.chunks?.forEach((_chunk)=>{
|
|
1294
|
+
let chunk = new Chunk(String(_chunk.id), _chunk.names?.join('') || _chunk.files?.join('| ') || '', _chunk.size, _chunk.initial, _chunk.entry);
|
|
1295
|
+
chunk.setParsedSize(0), chunkGraph.addChunk(chunk);
|
|
1296
|
+
}), bundleStats.assets?.forEach((_asset)=>{
|
|
1297
|
+
if ('assets by status' === _asset.type) return;
|
|
1298
|
+
let chunks = _asset.chunks?.map((ck)=>chunkGraph.getChunkById(String(ck))).filter((chunk)=>!!chunk) || [], { content = '' } = assetMap.get(_asset.name) || {}, asset = new Asset(_asset.name, _asset.size, chunks, content);
|
|
1299
|
+
chunks.forEach((chunk)=>chunk?.addAsset(asset)), chunkGraph.addAsset(asset);
|
|
1300
|
+
}), bundleStats.entrypoints) for (let [key, _entrypoint] of Object.entries(bundleStats.entrypoints)){
|
|
1301
|
+
let entrypoint = new EntryPoint(_entrypoint.name || key);
|
|
1302
|
+
_entrypoint.chunks?.forEach((chunkId)=>{
|
|
1303
|
+
let ck = chunkGraph.getChunkById(`${chunkId}`);
|
|
1304
|
+
ck && entrypoint.addChunk(ck);
|
|
1305
|
+
}), _entrypoint.assets?.forEach((_asset)=>{
|
|
1306
|
+
let asset = chunkGraph.getAssetByPath(_asset.name);
|
|
1307
|
+
asset && entrypoint.addAsset(asset);
|
|
1308
|
+
}), chunkGraph.addEntryPoint(entrypoint);
|
|
1309
|
+
}
|
|
1310
|
+
return chunkGraph;
|
|
1311
|
+
}
|
|
1312
|
+
let COMPRESSIBLE_REGEX = /\.(?:js|css|html|json|svg|txt|xml|xhtml|wasm|manifest)$/i;
|
|
1313
|
+
function assetsContents(assetMap, chunkGraph, supports) {
|
|
1314
|
+
chunkGraph.getAssets().forEach((asset)=>{
|
|
1315
|
+
let { content = '' } = assetMap.get(asset.path) || {};
|
|
1316
|
+
asset.content = content, COMPRESSIBLE_REGEX.test(asset.path) && supports?.gzip && asset.setGzipSize(content);
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
let external_path_browserify_namespaceObject = require("path-browserify");
|
|
1320
|
+
var external_path_browserify_default = __webpack_require__.n(external_path_browserify_namespaceObject);
|
|
1321
|
+
function isImportDependency({ type }) {
|
|
1322
|
+
return 'harmony side effect evaluation' === type || 'cjs require' === type || 'cjs full require' === type || 'cjs export require' === type || 'provided' === type || 'esm import' === type;
|
|
1323
|
+
}
|
|
1324
|
+
function getImportKind(dep) {
|
|
1325
|
+
let { type } = dep;
|
|
1326
|
+
return type ? type.includes('harmony') ? types_namespaceObject.SDK.DependencyKind.ImportStatement : type.includes('cjs') ? types_namespaceObject.SDK.DependencyKind.RequireCall : type.includes('import()') ? types_namespaceObject.SDK.DependencyKind.DynamicImport : type.includes('amd') ? types_namespaceObject.SDK.DependencyKind.AMDRequire : types_namespaceObject.SDK.DependencyKind.Unknown : types_namespaceObject.SDK.DependencyKind.Unknown;
|
|
1327
|
+
}
|
|
1328
|
+
function removeNoImportStyle(graph) {
|
|
1329
|
+
graph.getModules().filter((module)=>common_namespaceObject.File.isStyleExt(module.path)).filter((item)=>0 === item.getImported().length).forEach((item)=>graph.removeModule(item));
|
|
1330
|
+
}
|
|
1331
|
+
function getPositionByStatsLocation(loc) {
|
|
1332
|
+
function formatPosition(loc) {
|
|
1333
|
+
let [line, column] = loc.split(':');
|
|
1334
|
+
return {
|
|
1335
|
+
line: Number(line),
|
|
1336
|
+
column: Number(column)
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
if (loc.includes('-')) {
|
|
1340
|
+
let positionString = loc.split('-'), start = formatPosition(positionString[0]), end = formatPosition(positionString[1]);
|
|
1341
|
+
return {
|
|
1342
|
+
start,
|
|
1343
|
+
end: Number.isNaN(end.column) ? {
|
|
1344
|
+
line: start.line,
|
|
1345
|
+
column: end.line
|
|
1346
|
+
} : end
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
return loc.includes(':') ? {
|
|
1350
|
+
start: formatPosition(loc)
|
|
1351
|
+
} : loc.includes('[') ? {
|
|
1352
|
+
start: {
|
|
1353
|
+
index: Number(loc.match(/\[(\d+)\]/)[1])
|
|
1354
|
+
}
|
|
1355
|
+
} : void 0;
|
|
1356
|
+
}
|
|
1357
|
+
function isWebpack5orRspack(compilation) {
|
|
1358
|
+
return 'moduleGraph' in compilation && !!compilation.moduleGraph;
|
|
1359
|
+
}
|
|
1360
|
+
function getCanSkip(data) {
|
|
1361
|
+
if (!data.identifier || !(data?.nameForCondition || data.name) || data.identifier.startsWith('webpack/runtime') || data?.name?.startsWith('(webpack)')) return !0;
|
|
1362
|
+
}
|
|
1363
|
+
function getGetModuleName(root, data) {
|
|
1364
|
+
if (data.nameForCondition) return data.nameForCondition.replace('\x00', '');
|
|
1365
|
+
let name = data.name.replace(/ ?\+ ?\d+ ?modules$/, '');
|
|
1366
|
+
return external_path_browserify_default().isAbsolute(name) ? name : external_path_browserify_default().join(root, name);
|
|
1367
|
+
}
|
|
1368
|
+
function getModulesFromArray(modules, collectedModules) {
|
|
1369
|
+
modules.forEach((module)=>{
|
|
1370
|
+
var module1, collectedModules1;
|
|
1371
|
+
module1 = module, collectedModules1 = collectedModules, 'module' === module1.type || void 0 === module1.type ? collectedModules1.push(module1) : 'children' in module1 && module1.children && getModulesFromArray(module1.children, collectedModules1);
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
function getModuleGraphByStats({ modules, chunks }, root, chunkGraph) {
|
|
1375
|
+
var chunks1, collectedModules;
|
|
1376
|
+
ModuleGraph.init();
|
|
1377
|
+
let moduleGraph = new ModuleGraph(), allModules = [], collectedModules1 = [];
|
|
1378
|
+
for (let data of (getModulesFromArray(modules ?? [], collectedModules1), chunks1 = chunks ?? [], collectedModules = collectedModules1, chunks1?.forEach((chunk)=>{
|
|
1379
|
+
chunk.modules?.length && collectedModules.push(...chunk.modules);
|
|
1380
|
+
}), collectedModules1 ?? [])){
|
|
1381
|
+
if (getCanSkip(data) || moduleGraph.getModuleByWebpackId(data.identifier)) continue;
|
|
1382
|
+
allModules.push(data);
|
|
1383
|
+
let isConcatenated = !!(data.modules && data.modules.length > 0), concatenatedModule = new Module(data.identifier, getGetModuleName(root, data), 0 === data.depth, isConcatenated ? types_namespaceObject.SDK.ModuleKind.Concatenation : types_namespaceObject.SDK.ModuleKind.Normal, data.id ? String(data.id) : void 0, data.layer);
|
|
1384
|
+
for (let normal of (data.optimizationBailout && data.optimizationBailout.forEach((reason)=>concatenatedModule.addBailoutReason(reason)), data.issuerPath && concatenatedModule.addIssuerPath(data.issuerPath), data.chunks?.forEach((_chunkId)=>{
|
|
1385
|
+
let chunk = chunkGraph.getChunkById(String(_chunkId));
|
|
1386
|
+
chunk && concatenatedModule.addChunk(chunk);
|
|
1387
|
+
}), moduleGraph.addModule(concatenatedModule), data.source && concatenatedModule.setSource({
|
|
1388
|
+
transformed: Buffer.isBuffer(data.source) ? data.source.toString() : data.source
|
|
1389
|
+
}), 'number' == typeof data.size && concatenatedModule.setSize({
|
|
1390
|
+
sourceSize: data.size,
|
|
1391
|
+
transformedSize: data.size
|
|
1392
|
+
}), data.modules ?? [])){
|
|
1393
|
+
let normalModule;
|
|
1394
|
+
if (getCanSkip(normal)) continue;
|
|
1395
|
+
allModules.push(normal);
|
|
1396
|
+
let webpackId = normal.identifier, registeredModule = moduleGraph.getModuleByWebpackId(webpackId);
|
|
1397
|
+
normalModule = registeredModule || (moduleGraph.getModuleByWebpackId(webpackId) ?? new Module(webpackId, getGetModuleName(root, normal), 0 === normal.depth, types_namespaceObject.SDK.ModuleKind.Normal, normal.id ? String(normal.id) : void 0, normal.layer)), normal.optimizationBailout && normal.optimizationBailout.forEach((reason)=>normalModule.addBailoutReason(reason)), normal.issuerPath && normalModule.addIssuerPath(normal.issuerPath), normal.chunks?.length ? normal.chunks?.forEach((_chunkId)=>{
|
|
1398
|
+
let chunk = chunkGraph.getChunkById(String(_chunkId));
|
|
1399
|
+
chunk && normalModule.addChunk(chunk);
|
|
1400
|
+
}) : data.chunks?.forEach((_chunkId)=>{
|
|
1401
|
+
let chunk = chunkGraph.getChunkById(String(_chunkId));
|
|
1402
|
+
chunk && normalModule.addChunk(chunk);
|
|
1403
|
+
}), normal.source && normalModule.setSource({
|
|
1404
|
+
transformed: Buffer.isBuffer(normal.source) ? normal.source.toString() : normal.source
|
|
1405
|
+
}), 'number' == typeof normal.size && normalModule.setSize({
|
|
1406
|
+
sourceSize: normal.size,
|
|
1407
|
+
transformedSize: normal.size
|
|
1408
|
+
}), moduleGraph.addModule(normalModule), concatenatedModule.addNormalModule(normalModule);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
for (let module of allModules){
|
|
1412
|
+
let currentModule = moduleGraph.getModuleByWebpackId(module.identifier ?? '');
|
|
1413
|
+
if (!currentModule) continue;
|
|
1414
|
+
let dependencies = (module.reasons ?? []).filter(isImportDependency).filter((item)=>!!(item.moduleIdentifier && item.userRequest));
|
|
1415
|
+
for (let dep of ((module.reasons ?? []).filter((item)=>'from origin' === item.type).forEach((dep)=>dep?.children?.forEach((_d)=>dependencies.push({
|
|
1416
|
+
...dep,
|
|
1417
|
+
..._d,
|
|
1418
|
+
children: void 0
|
|
1419
|
+
}))), dependencies)){
|
|
1420
|
+
let rawRequest = dep.userRequest, requestModule = moduleGraph.getModuleByWebpackId(dep.moduleIdentifier);
|
|
1421
|
+
if (!requestModule) continue;
|
|
1422
|
+
if (!requestModule.getDependencyByRequest(rawRequest)) {
|
|
1423
|
+
let data = requestModule.addDependency(rawRequest, currentModule, getImportKind(dep));
|
|
1424
|
+
data && moduleGraph.addDependency(data);
|
|
1425
|
+
}
|
|
1426
|
+
let dependency = requestModule.getDependencyByRequest(rawRequest);
|
|
1427
|
+
if (dependency && dep?.loc) {
|
|
1428
|
+
let position = getPositionByStatsLocation(dep.loc);
|
|
1429
|
+
position && dependency.addStatement(new Statement(requestModule, {
|
|
1430
|
+
transformed: position
|
|
1431
|
+
}));
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
let moduleCache = new Map();
|
|
1436
|
+
return moduleGraph.getModules().forEach((module)=>{
|
|
1437
|
+
module.issuerPath && module.issuerPath.forEach((issuer)=>{
|
|
1438
|
+
let moduleInstance = moduleCache.get(issuer.identifier);
|
|
1439
|
+
!moduleInstance && (moduleInstance = moduleGraph.getModuleByWebpackId(issuer.identifier)) && moduleCache.set(issuer.identifier, moduleInstance), moduleInstance && (issuer.moduleId = moduleInstance.id);
|
|
1440
|
+
});
|
|
1441
|
+
}), moduleGraph;
|
|
1442
|
+
}
|
|
1443
|
+
async function transStats(json) {
|
|
1444
|
+
let chunkGraph = chunkTransform(new Map(), json), moduleGraph = getModuleGraphByStats(json, '.', chunkGraph);
|
|
1445
|
+
return await getAssetsModulesData(moduleGraph, chunkGraph, json.outputPath || '', {}), {
|
|
1446
|
+
chunkGraph,
|
|
1447
|
+
moduleGraph
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
function isNormalModule(mod) {
|
|
1451
|
+
return 'request' in mod && 'rawRequest' in mod && 'resource' in mod;
|
|
1452
|
+
}
|
|
1453
|
+
function getWebpackModuleId(mod) {
|
|
1454
|
+
return mod.identifier();
|
|
1455
|
+
}
|
|
1456
|
+
function getWebpackModulePath(mod) {
|
|
1457
|
+
return mod.resource ?? mod.nameForCondition?.() ?? getWebpackModuleId(mod);
|
|
1458
|
+
}
|
|
1459
|
+
function getWebpackDependencyRequest(dep, module) {
|
|
1460
|
+
return dep.request ?? dep.userRequest ?? module?.rawRequest;
|
|
1461
|
+
}
|
|
1462
|
+
function getResolveRequest(dep, graph) {
|
|
1463
|
+
return getWebpackModulePath(graph.getResolvedModule(dep));
|
|
1464
|
+
}
|
|
1465
|
+
function isExternalModule(mod) {
|
|
1466
|
+
return !!mod.externalType;
|
|
1467
|
+
}
|
|
1468
|
+
function getModuleSource(mod) {
|
|
1469
|
+
return isExternalModule(mod) ? '' : mod.originalSource?.()?.source().toString() ?? '';
|
|
1470
|
+
}
|
|
1471
|
+
function getEntryModule(entryMap) {
|
|
1472
|
+
return Array.from(entryMap.values()).map((entry)=>entry.getRuntimeChunk()).map((chunk)=>chunk ? chunk.entryModule : null).filter(Boolean).map((mod)=>isNormalModule(mod) ? mod : mod.rootModule);
|
|
1473
|
+
}
|
|
1474
|
+
function getDependencyPosition(dep, module, getSource = !0) {
|
|
1475
|
+
let { loc: depLoc } = dep;
|
|
1476
|
+
if (void 0 === depLoc || !('start' in depLoc)) return;
|
|
1477
|
+
let transformed = {
|
|
1478
|
+
start: {
|
|
1479
|
+
line: depLoc.start.line,
|
|
1480
|
+
column: depLoc.start.column
|
|
1481
|
+
},
|
|
1482
|
+
end: depLoc.end ? {
|
|
1483
|
+
line: depLoc.end.line,
|
|
1484
|
+
column: depLoc.end.column
|
|
1485
|
+
} : void 0
|
|
1486
|
+
};
|
|
1487
|
+
return new Statement(module, {
|
|
1488
|
+
source: getSource ? module.getSourceRange(transformed) : void 0,
|
|
1489
|
+
transformed
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
function getExportDependency(info, module) {
|
|
1493
|
+
let dep = module.dependencies.find((dep)=>dep.name === info.name && ('harmony export imported specifier' === dep.type || 'harmony export specifier' === dep.type));
|
|
1494
|
+
return !dep && info._target && info._target.size > 0 && (dep = info._getMaxTarget().values().next().value.connection.dependency), dep;
|
|
1495
|
+
}
|
|
1496
|
+
function getSdkDependencyByWebpackDependency(dep, module, graph) {
|
|
1497
|
+
let modulePath = getWebpackModulePath(module), request = getWebpackDependencyRequest(dep);
|
|
1498
|
+
return graph.getDependencies().find((item)=>item.module.path === modulePath && item.request === request);
|
|
1499
|
+
}
|
|
1500
|
+
function getExportStatement(info, normalModule, graph) {
|
|
1501
|
+
let webpackDependency = getExportDependency(info, normalModule);
|
|
1502
|
+
if (!webpackDependency) return;
|
|
1503
|
+
let modulePath = getWebpackModulePath(normalModule), request = getWebpackDependencyRequest(webpackDependency), sdkDependency = graph.getDependencies().find((item)=>item.module.path === modulePath && item.request === request);
|
|
1504
|
+
if (sdkDependency && 1 === sdkDependency.statements.length) return sdkDependency.statements[0];
|
|
1505
|
+
let sdkModule = graph.getModuleByWebpackId(getWebpackModuleId(normalModule));
|
|
1506
|
+
if (sdkModule) return getDependencyPosition(webpackDependency, sdkModule);
|
|
1507
|
+
}
|
|
1508
|
+
function getLastExportInfo(info, webpackGraph) {
|
|
1509
|
+
let target = info.findTarget(webpackGraph, ()=>!0);
|
|
1510
|
+
if (target && target.export) return webpackGraph.getExportsInfo(target.module).getExportInfo(target.export[0]);
|
|
1511
|
+
}
|
|
1512
|
+
function getAllModules(compilation) {
|
|
1513
|
+
let modules = [];
|
|
1514
|
+
for (let mod of compilation.modules)modules.push(...mod.modules ?? []), modules.push(mod);
|
|
1515
|
+
return external_lodash_unionby_default()(modules.filter((mod)=>!getWebpackModuleId(mod).startsWith('webpack/runtime')), (mod)=>getWebpackModuleId(mod));
|
|
1516
|
+
}
|
|
1517
|
+
})(), exports.Asset = __webpack_exports__.Asset, exports.Chunk = __webpack_exports__.Chunk, exports.ChunkGraph = __webpack_exports__.ChunkGraph, exports.Chunks = __webpack_exports__.Chunks, exports.Dependency = __webpack_exports__.Dependency, exports.EntryPoint = __webpack_exports__.EntryPoint, exports.ExportInfo = __webpack_exports__.ExportInfo, exports.Module = __webpack_exports__.Module, exports.ModuleGraph = __webpack_exports__.ModuleGraph, exports.ModuleGraphModule = __webpack_exports__.ModuleGraphModule, exports.ModuleGraphTrans = __webpack_exports__.ModuleGraphTrans, exports.Package = __webpack_exports__.Package, exports.PackageDependency = __webpack_exports__.PackageDependency, exports.PackageGraph = __webpack_exports__.PackageGraph, exports.SideEffect = __webpack_exports__.SideEffect, exports.Statement = __webpack_exports__.Statement, exports.TransUtils = __webpack_exports__.TransUtils, exports.Variable = __webpack_exports__.Variable, exports.Webpack = __webpack_exports__.Webpack, exports.readPackageJson = __webpack_exports__.readPackageJson, __webpack_exports__)-1 === [
|
|
1518
|
+
"Asset",
|
|
1519
|
+
"Chunk",
|
|
1520
|
+
"ChunkGraph",
|
|
1521
|
+
"Chunks",
|
|
1522
|
+
"Dependency",
|
|
1523
|
+
"EntryPoint",
|
|
1524
|
+
"ExportInfo",
|
|
1525
|
+
"Module",
|
|
1526
|
+
"ModuleGraph",
|
|
1527
|
+
"ModuleGraphModule",
|
|
1528
|
+
"ModuleGraphTrans",
|
|
1529
|
+
"Package",
|
|
1530
|
+
"PackageDependency",
|
|
1531
|
+
"PackageGraph",
|
|
1532
|
+
"SideEffect",
|
|
1533
|
+
"Statement",
|
|
1534
|
+
"TransUtils",
|
|
1535
|
+
"Variable",
|
|
1536
|
+
"Webpack",
|
|
1537
|
+
"readPackageJson"
|
|
1538
|
+
].indexOf(__webpack_i__) && (exports[__webpack_i__] = __webpack_exports__[__webpack_i__]);
|
|
1539
|
+
Object.defineProperty(exports, '__esModule', {
|
|
1540
|
+
value: !0
|
|
1541
|
+
});
|