@rsdoctor/graph 1.3.8 → 1.3.10

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