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