@rsdoctor/graph 1.2.3 → 1.2.4-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/{type/graph → graph}/chunk-graph/asset.d.ts +0 -1
  2. package/dist/{type/graph → graph}/chunk-graph/chunk.d.ts +0 -1
  3. package/dist/{type/graph → graph}/chunk-graph/entrypoint.d.ts +0 -1
  4. package/dist/{type/graph → graph}/chunk-graph/graph.d.ts +0 -1
  5. package/dist/{type/graph → graph}/chunk-graph/index.d.ts +0 -1
  6. package/dist/{type/graph → graph}/index.d.ts +0 -1
  7. package/dist/{type/graph → graph}/module-graph/dependency.d.ts +0 -1
  8. package/dist/{type/graph → graph}/module-graph/graph.d.ts +0 -1
  9. package/dist/{type/graph → graph}/module-graph/index.d.ts +0 -1
  10. package/dist/{type/graph → graph}/module-graph/module.d.ts +1 -2
  11. package/dist/{type/graph → graph}/module-graph/statement.d.ts +0 -1
  12. package/dist/{type/graph → graph}/module-graph/tree-shaking/export.d.ts +0 -1
  13. package/dist/{type/graph → graph}/module-graph/tree-shaking/index.d.ts +0 -1
  14. package/dist/{type/graph → graph}/module-graph/tree-shaking/module.d.ts +0 -1
  15. package/dist/{type/graph → graph}/module-graph/tree-shaking/sideEffect.d.ts +0 -1
  16. package/dist/{type/graph → graph}/module-graph/tree-shaking/types.d.ts +0 -1
  17. package/dist/{type/graph → graph}/module-graph/tree-shaking/variable.d.ts +0 -1
  18. package/dist/{type/graph → graph}/module-graph/types.d.ts +0 -1
  19. package/dist/{type/graph → graph}/module-graph/utils.d.ts +0 -1
  20. package/dist/{type/graph → graph}/package-graph/dependency.d.ts +0 -1
  21. package/dist/{type/graph → graph}/package-graph/graph.d.ts +0 -1
  22. package/dist/{type/graph → graph}/package-graph/index.d.ts +0 -1
  23. package/dist/{type/graph → graph}/package-graph/package.d.ts +0 -1
  24. package/dist/{type/graph → graph}/package-graph/types.d.ts +0 -1
  25. package/dist/{type/graph → graph}/package-graph/utils.d.ts +0 -1
  26. package/dist/index.cjs +1541 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.js +1452 -0
  29. package/dist/transform/chunks/assetsContent.d.ts +4 -0
  30. package/dist/transform/chunks/assetsModules.d.ts +22 -0
  31. package/dist/transform/chunks/chunkTransform.d.ts +5 -0
  32. package/dist/transform/chunks/index.d.ts +3 -0
  33. package/dist/transform/index.d.ts +4 -0
  34. package/dist/transform/module-graph/compatible.d.ts +8 -0
  35. package/dist/transform/module-graph/index.d.ts +3 -0
  36. package/dist/transform/module-graph/transform.d.ts +7 -0
  37. package/dist/transform/module-graph/utils.d.ts +13 -0
  38. package/dist/transform/trans-utils/index.d.ts +1 -0
  39. package/dist/transform/trans-utils/transStats.d.ts +10 -0
  40. package/dist/transform/webpack/compatible.d.ts +16 -0
  41. package/dist/types/index.d.ts +1 -0
  42. package/dist/types/transform.d.ts +6 -0
  43. package/package.json +18 -8
  44. package/dist/cjs/graph/chunk-graph/asset.js +0 -72
  45. package/dist/cjs/graph/chunk-graph/chunk.js +0 -121
  46. package/dist/cjs/graph/chunk-graph/entrypoint.js +0 -73
  47. package/dist/cjs/graph/chunk-graph/graph.js +0 -109
  48. package/dist/cjs/graph/chunk-graph/index.js +0 -87
  49. package/dist/cjs/graph/index.js +0 -78
  50. package/dist/cjs/graph/module-graph/dependency.js +0 -100
  51. package/dist/cjs/graph/module-graph/graph.js +0 -319
  52. package/dist/cjs/graph/module-graph/index.js +0 -105
  53. package/dist/cjs/graph/module-graph/module.js +0 -328
  54. package/dist/cjs/graph/module-graph/statement.js +0 -92
  55. package/dist/cjs/graph/module-graph/tree-shaking/export.js +0 -102
  56. package/dist/cjs/graph/module-graph/tree-shaking/index.js +0 -96
  57. package/dist/cjs/graph/module-graph/tree-shaking/module.js +0 -100
  58. package/dist/cjs/graph/module-graph/tree-shaking/sideEffect.js +0 -89
  59. package/dist/cjs/graph/module-graph/tree-shaking/types.js +0 -18
  60. package/dist/cjs/graph/module-graph/tree-shaking/variable.js +0 -69
  61. package/dist/cjs/graph/module-graph/types.js +0 -18
  62. package/dist/cjs/graph/module-graph/utils.js +0 -63
  63. package/dist/cjs/graph/package-graph/dependency.js +0 -64
  64. package/dist/cjs/graph/package-graph/graph.js +0 -170
  65. package/dist/cjs/graph/package-graph/index.js +0 -87
  66. package/dist/cjs/graph/package-graph/package.js +0 -125
  67. package/dist/cjs/graph/package-graph/types.js +0 -18
  68. package/dist/cjs/graph/package-graph/utils.js +0 -61
  69. package/dist/cjs/index.js +0 -60
  70. package/dist/esm/graph/chunk-graph/asset.mjs +0 -38
  71. package/dist/esm/graph/chunk-graph/chunk.mjs +0 -87
  72. package/dist/esm/graph/chunk-graph/entrypoint.mjs +0 -39
  73. package/dist/esm/graph/chunk-graph/graph.mjs +0 -75
  74. package/dist/esm/graph/chunk-graph/index.mjs +0 -4
  75. package/dist/esm/graph/index.mjs +0 -3
  76. package/dist/esm/graph/module-graph/dependency.mjs +0 -66
  77. package/dist/esm/graph/module-graph/graph.mjs +0 -285
  78. package/dist/esm/graph/module-graph/index.mjs +0 -6
  79. package/dist/esm/graph/module-graph/module.mjs +0 -284
  80. package/dist/esm/graph/module-graph/statement.mjs +0 -58
  81. package/dist/esm/graph/module-graph/tree-shaking/export.mjs +0 -68
  82. package/dist/esm/graph/module-graph/tree-shaking/index.mjs +0 -5
  83. package/dist/esm/graph/module-graph/tree-shaking/module.mjs +0 -66
  84. package/dist/esm/graph/module-graph/tree-shaking/sideEffect.mjs +0 -55
  85. package/dist/esm/graph/module-graph/tree-shaking/types.mjs +0 -0
  86. package/dist/esm/graph/module-graph/tree-shaking/variable.mjs +0 -35
  87. package/dist/esm/graph/module-graph/types.mjs +0 -0
  88. package/dist/esm/graph/module-graph/utils.mjs +0 -23
  89. package/dist/esm/graph/package-graph/dependency.mjs +0 -30
  90. package/dist/esm/graph/package-graph/graph.mjs +0 -123
  91. package/dist/esm/graph/package-graph/index.mjs +0 -4
  92. package/dist/esm/graph/package-graph/package.mjs +0 -91
  93. package/dist/esm/graph/package-graph/types.mjs +0 -0
  94. package/dist/esm/graph/package-graph/utils.mjs +0 -24
  95. package/dist/esm/index.mjs +0 -1
  96. package/dist/type/graph/chunk-graph/asset.d.ts.map +0 -1
  97. package/dist/type/graph/chunk-graph/chunk.d.ts.map +0 -1
  98. package/dist/type/graph/chunk-graph/entrypoint.d.ts.map +0 -1
  99. package/dist/type/graph/chunk-graph/graph.d.ts.map +0 -1
  100. package/dist/type/graph/chunk-graph/index.d.ts.map +0 -1
  101. package/dist/type/graph/index.d.ts.map +0 -1
  102. package/dist/type/graph/module-graph/dependency.d.ts.map +0 -1
  103. package/dist/type/graph/module-graph/graph.d.ts.map +0 -1
  104. package/dist/type/graph/module-graph/index.d.ts.map +0 -1
  105. package/dist/type/graph/module-graph/module.d.ts.map +0 -1
  106. package/dist/type/graph/module-graph/statement.d.ts.map +0 -1
  107. package/dist/type/graph/module-graph/tree-shaking/export.d.ts.map +0 -1
  108. package/dist/type/graph/module-graph/tree-shaking/index.d.ts.map +0 -1
  109. package/dist/type/graph/module-graph/tree-shaking/module.d.ts.map +0 -1
  110. package/dist/type/graph/module-graph/tree-shaking/sideEffect.d.ts.map +0 -1
  111. package/dist/type/graph/module-graph/tree-shaking/types.d.ts.map +0 -1
  112. package/dist/type/graph/module-graph/tree-shaking/variable.d.ts.map +0 -1
  113. package/dist/type/graph/module-graph/types.d.ts.map +0 -1
  114. package/dist/type/graph/module-graph/utils.d.ts.map +0 -1
  115. package/dist/type/graph/package-graph/dependency.d.ts.map +0 -1
  116. package/dist/type/graph/package-graph/graph.d.ts.map +0 -1
  117. package/dist/type/graph/package-graph/index.d.ts.map +0 -1
  118. package/dist/type/graph/package-graph/package.d.ts.map +0 -1
  119. package/dist/type/graph/package-graph/types.d.ts.map +0 -1
  120. package/dist/type/graph/package-graph/utils.d.ts.map +0 -1
  121. package/dist/type/index.d.ts +0 -2
  122. package/dist/type/index.d.ts.map +0 -1
@@ -1,285 +0,0 @@
1
- import { SDK } from "@rsdoctor/types";
2
- import { Dependency } from "./dependency.mjs";
3
- import { Module } from "./module.mjs";
4
- import { Statement } from "./statement.mjs";
5
- import { ExportInfo, ModuleGraphModule, SideEffect, Variable } from "./tree-shaking/index.mjs";
6
- class ModuleGraph {
7
- static init() {
8
- Module.init();
9
- Dependency.init();
10
- ModuleGraphModule.init();
11
- }
12
- static fromData(data) {
13
- const moduleGraph = new ModuleGraph();
14
- const getStatement = (data)=>new Statement(moduleGraph.getModuleById(data.module), data.position);
15
- for (const item of data.modules ?? []){
16
- var _item_meta, _item_meta1;
17
- const module = new Module(String(item.id), item.path, item.isEntry, item.kind, item.renderId, item.layer);
18
- module.id = item.id;
19
- module.setSize(item.size);
20
- module.meta = {
21
- strictHarmonyModule: (null == (_item_meta = item.meta) ? void 0 : _item_meta.strictHarmonyModule) ?? false,
22
- hasSetEsModuleStatement: (null == (_item_meta1 = item.meta) ? void 0 : _item_meta1.hasSetEsModuleStatement) ?? false
23
- };
24
- module._isPreferSource = item.isPreferSource;
25
- module.chunks = item.chunks;
26
- moduleGraph.addModule(module);
27
- }
28
- for (const moduleData of data.modules ?? []){
29
- const module = moduleGraph.getModuleById(moduleData.id);
30
- for (const depId of moduleData.dependencies){
31
- const depData = (data.dependencies ?? []).find((item)=>item.id === depId);
32
- const depModule = depData && moduleGraph.getModuleById(depData.originDependency);
33
- if (!depData || !depModule) {
34
- console.warn(`The connection data ID is empty: ${depId}`);
35
- continue;
36
- }
37
- const dep = module.addDependency(depData.request, depModule, depData.kind, depData.statements.map(getStatement));
38
- if (dep) {
39
- dep.id = depData.id;
40
- moduleGraph.addDependency(dep);
41
- }
42
- }
43
- for (const normalModuleId of moduleData.modules ?? []){
44
- const normalModule = moduleGraph.getModuleById(normalModuleId);
45
- if (!normalModule) {
46
- console.warn(`Add the ordinary module ID as empty: ${normalModuleId}`);
47
- continue;
48
- }
49
- module.addNormalModule(normalModule);
50
- }
51
- for (const concatenationModuleId of moduleData.concatenationModules ?? []){
52
- const concatenationModule = moduleGraph.getModuleById(concatenationModuleId);
53
- if (!concatenationModule) {
54
- console.warn(`The aggregation module ID is empty: ${concatenationModule}`);
55
- continue;
56
- }
57
- module.addConcatenationModule(concatenationModule);
58
- }
59
- }
60
- for (const exportData of data.exports ?? []){
61
- const info = new ExportInfo(exportData.name, exportData.identifier ? getStatement(exportData.identifier) : void 0);
62
- info.id = exportData.id;
63
- moduleGraph.addExportInfo(info);
64
- }
65
- for (const exportData of data.exports ?? [])if (exportData.from) {
66
- const current = moduleGraph._exportIdMap.get(exportData.id);
67
- const from = moduleGraph._exportIdMap.get(exportData.from);
68
- if (current && from) current.setFromExport(from);
69
- }
70
- for (const varData of data.variables ?? []){
71
- const module = moduleGraph.getModuleById(varData.module);
72
- if (!module) {
73
- console.warn(`The module ID in the variable is empty\u{FF1A}${varData.module}`);
74
- continue;
75
- }
76
- const info = new Variable(varData.name, module, varData.usedInfo, getStatement(varData.identifier));
77
- const exportInfo = moduleGraph._exportIdMap.get(varData.exported ?? -1);
78
- if (exportInfo) info.setExportInfo(exportInfo);
79
- info.id = varData.id;
80
- moduleGraph.addVariable(info);
81
- }
82
- for (const sideData of data.sideEffects ?? []){
83
- const module = moduleGraph.getModuleById(sideData.module);
84
- if (!module) {
85
- console.warn(`The module ID in the side effects is empty\u{FF1A}${sideData.module}`);
86
- continue;
87
- }
88
- const info = new SideEffect(sideData.name, module, getStatement(sideData.identifier), sideData.originName);
89
- info.isNameSpace = sideData.isNameSpace;
90
- info.id = sideData.id;
91
- for (const exportId of sideData.exports ?? []){
92
- const exportInfo = moduleGraph._exportIdMap.get(exportId);
93
- if (exportInfo) exportInfo.addSideEffect(info);
94
- }
95
- if (sideData.variable) {
96
- const varInfo = moduleGraph._varIdMap.get(sideData.variable);
97
- if (varInfo) info._variable = varInfo;
98
- }
99
- moduleGraph.addSideEffect(info);
100
- }
101
- for (const mgmData of data.moduleGraphModules ?? []){
102
- const module = moduleGraph.getModuleById(mgmData.module);
103
- if (!module) {
104
- console.warn(`The module ID in ModuleGraphModule is empty: ${mgmData.module}`);
105
- continue;
106
- }
107
- const mgm = new ModuleGraphModule(module, moduleGraph, mgmData.dynamic);
108
- moduleGraph.addModuleGraphModule(mgm);
109
- mgmData.exports.forEach((id)=>{
110
- const info = moduleGraph._exportIdMap.get(id);
111
- if (info) mgm.addExportInfo(info);
112
- });
113
- mgmData.sideEffects.forEach((id)=>{
114
- const info = moduleGraph._sideEffectIdMap.get(id);
115
- if (info) mgm.addSideEffect(info);
116
- });
117
- mgmData.variables.forEach((id)=>{
118
- const info = moduleGraph._varIdMap.get(id);
119
- if (info) mgm.addVariable(info);
120
- });
121
- }
122
- ModuleGraph.init();
123
- return moduleGraph;
124
- }
125
- clear() {
126
- this._dependenciesIdMap = new Map();
127
- this._moduleWebpackIdMap = new Map();
128
- this._moduleIdMap = new Map();
129
- this._moduleGraphModules = new Map();
130
- this._exportIdMap = new Map();
131
- this._sideEffectIdMap = new Map();
132
- this._varIdMap = new Map();
133
- this._layers = new Map();
134
- }
135
- size() {
136
- return this._moduleIdMap.size;
137
- }
138
- fromInstance(data) {
139
- this._dependenciesIdMap = new Map(data._dependenciesIdMap);
140
- this._moduleWebpackIdMap = new Map(data._moduleWebpackIdMap);
141
- this._moduleIdMap = new Map(data._moduleIdMap);
142
- this._moduleGraphModules = new Map(data._moduleGraphModules);
143
- this._exportIdMap = new Map(data._exportIdMap);
144
- this._sideEffectIdMap = new Map(data._sideEffectIdMap);
145
- this._varIdMap = new Map(data._varIdMap);
146
- this._layers = new Map(data._layers);
147
- }
148
- getSubGraphByModule(module) {
149
- const map = new Set();
150
- const result = [
151
- module
152
- ];
153
- map.add(module);
154
- for(let i = 0; i < result.length; i++){
155
- const current = result[i];
156
- for (const { dependency: depModule } of current.getDependencies())if (!map.has(depModule)) {
157
- map.add(depModule);
158
- result.push(depModule);
159
- }
160
- }
161
- return result;
162
- }
163
- getModules() {
164
- return Array.from(this._moduleWebpackIdMap.values());
165
- }
166
- getDependencies() {
167
- return Array.from(this._dependenciesIdMap.values());
168
- }
169
- getEntryModules() {
170
- return this.getModules().filter((item)=>item.isEntry && item.kind !== SDK.ModuleKind.Concatenation);
171
- }
172
- getModuleById(id) {
173
- return this._moduleIdMap.get(id);
174
- }
175
- getDependencyById(id) {
176
- return this._dependenciesIdMap.get(id);
177
- }
178
- getModuleByWebpackId(id) {
179
- return this._moduleWebpackIdMap.get(id);
180
- }
181
- getModuleByFile(file) {
182
- return this.getModules().find((item)=>item.path === file);
183
- }
184
- addModule(...modules) {
185
- for (const module of modules)if (!this._moduleIdMap.has(module.id)) {
186
- this._moduleWebpackIdMap.set(module.webpackId, module);
187
- this._moduleIdMap.set(module.id, module);
188
- module.layer && this.addLayer(module.layer);
189
- }
190
- }
191
- addDependency(...deps) {
192
- for (const dep of deps)if (!this._dependenciesIdMap.has(dep.id)) {
193
- this._dependenciesIdMap.set(dep.id, dep);
194
- this.addModule(dep.module);
195
- this.addModule(dep.dependency);
196
- }
197
- }
198
- removeModule(module) {
199
- this._moduleIdMap.delete(module.id);
200
- this._moduleWebpackIdMap.delete(module.webpackId);
201
- for (const dep of module.getDependencies()){
202
- this.removeDependency(dep);
203
- this._dependenciesIdMap.delete(dep.id);
204
- }
205
- for (const imported of module.getImported())imported.removeDependencyByModule(imported);
206
- }
207
- removeDependency(dep) {
208
- dep.module.removeDependency(dep);
209
- dep.dependency.removeImported(dep.module);
210
- this._dependenciesIdMap.delete(dep.id);
211
- }
212
- addModuleGraphModule(mgm) {
213
- if (!this._moduleGraphModules.has(mgm.module)) this._moduleGraphModules.set(mgm.module, mgm);
214
- }
215
- getModuleGraphModule(module) {
216
- return this._moduleGraphModules.get(module);
217
- }
218
- getModuleGraphModules() {
219
- return Array.from(this._moduleGraphModules.values());
220
- }
221
- addExportInfo(data) {
222
- this._exportIdMap.set(data.id, data);
223
- }
224
- addSideEffect(data) {
225
- this._sideEffectIdMap.set(data.id, data);
226
- }
227
- addVariable(data) {
228
- this._varIdMap.set(data.id, data);
229
- }
230
- addLayer(layer) {
231
- if (!this._layers.get(layer)) this._layers.set(layer, 1);
232
- }
233
- getLayers() {
234
- return this._layers;
235
- }
236
- toData(configs) {
237
- return {
238
- dependencies: this.getDependencies().map((item)=>item.toData()),
239
- modules: this.getModules().map((item)=>item.toData(null == configs ? void 0 : configs.contextPath)),
240
- moduleGraphModules: Array.from(this._moduleGraphModules.values()).map((item)=>item.toData()),
241
- exports: Array.from(this._exportIdMap.values()).map((item)=>item.toData()),
242
- sideEffects: Array.from(this._sideEffectIdMap.values()).map((item)=>item.toData()),
243
- variables: Array.from(this._varIdMap.values()).map((item)=>item.toData()),
244
- layers: Array.from(this._layers.keys())
245
- };
246
- }
247
- toCodeData(type = SDK.ToDataType.Normal) {
248
- const codeMap = {};
249
- this.getModules().forEach((item)=>{
250
- codeMap[item.id] = item.getSource(type);
251
- });
252
- return codeMap;
253
- }
254
- setModules(modules) {
255
- this._moduleIdMap = new Map(modules.map((m)=>[
256
- m.id,
257
- m
258
- ]));
259
- this._moduleWebpackIdMap = new Map(modules.map((m)=>[
260
- m.webpackId,
261
- m
262
- ]));
263
- this._layers = new Map(modules.filter((m)=>m.layer).map((m)=>[
264
- m.layer,
265
- 1
266
- ]));
267
- }
268
- setDependencies(dependencies) {
269
- this._dependenciesIdMap = new Map(dependencies.map((d)=>[
270
- d.id,
271
- d
272
- ]));
273
- }
274
- constructor(){
275
- this._dependenciesIdMap = new Map();
276
- this._moduleWebpackIdMap = new Map();
277
- this._moduleIdMap = new Map();
278
- this._moduleGraphModules = new Map();
279
- this._exportIdMap = new Map();
280
- this._sideEffectIdMap = new Map();
281
- this._varIdMap = new Map();
282
- this._layers = new Map();
283
- }
284
- }
285
- export { ModuleGraph };
@@ -1,6 +0,0 @@
1
- export * from "./dependency.mjs";
2
- export * from "./module.mjs";
3
- export * from "./graph.mjs";
4
- export * from "./statement.mjs";
5
- export * from "./tree-shaking/index.mjs";
6
- export * from "./types.mjs";
@@ -1,284 +0,0 @@
1
- import { SDK } from "@rsdoctor/types";
2
- import path_0 from "path";
3
- import { Lodash } from "@rsdoctor/utils/common";
4
- import { Dependency } from "./dependency.mjs";
5
- import { Statement } from "./statement.mjs";
6
- import { getModuleName } from "./utils.mjs";
7
- import { gzipSync } from "node:zlib";
8
- let module_id = 1;
9
- class Module {
10
- static init() {
11
- module_id = 1;
12
- }
13
- get rootModule() {
14
- return this.modules.find((item)=>item.path === this.path);
15
- }
16
- get isPreferSource() {
17
- if ('boolean' == typeof this._isPreferSource) return this._isPreferSource;
18
- const result = this.source.source.length > 0 && 'test code' !== this.source.source && Boolean(this.sourceMap);
19
- this._isPreferSource = result;
20
- return result;
21
- }
22
- addBailoutReason(reason) {
23
- this.bailoutReason.push(reason);
24
- }
25
- getBailoutReason() {
26
- return this.bailoutReason;
27
- }
28
- getChunks() {
29
- return this.chunks.slice();
30
- }
31
- addChunk(chunk) {
32
- if (!this.chunks.includes(chunk)) {
33
- this.chunks.push(chunk);
34
- chunk.addModule(this);
35
- }
36
- }
37
- removeChunk(chunk) {
38
- this.chunks = this.chunks.filter((item)=>item !== chunk);
39
- }
40
- getDependencies() {
41
- return this.dependencies.slice();
42
- }
43
- getDependencyByRequest(request) {
44
- return this.dependencies.find((item)=>item.request === request);
45
- }
46
- getDependencyByModule(module) {
47
- return this.dependencies.find((item)=>item.originDependency === module || item.dependency === module);
48
- }
49
- addDependency(request, module, kind, statements) {
50
- const dep = new Dependency(request, this, module, kind, statements);
51
- if (this.dependencies.every((item)=>!item.isSameWithoutStatements(dep))) {
52
- this.dependencies.push(dep);
53
- module.addImported(this);
54
- if (module.rootModule) module.rootModule.addImported(this);
55
- return dep;
56
- }
57
- }
58
- removeDependency(dep) {
59
- this.dependencies = this.dependencies.filter((item)=>item === dep);
60
- }
61
- removeDependencyByModule(module) {
62
- const dep = this.getDependencyByModule(module);
63
- if (dep) this.removeDependency(dep);
64
- }
65
- getImported() {
66
- return this.imported.slice();
67
- }
68
- addImported(module) {
69
- if (!this.imported.includes(module)) this.imported.push(module);
70
- }
71
- removeImported(module) {
72
- this.imported = this.imported.filter((item)=>item === module);
73
- }
74
- setProgram(program) {
75
- this.program = program;
76
- }
77
- getProgram() {
78
- return this.program;
79
- }
80
- setSource(input) {
81
- const { source } = this;
82
- source.source = input.source ?? source.source;
83
- source.transformed = input.transformed ?? source.transformed;
84
- source.parsedSource = input.parsedSource ?? source.parsedSource;
85
- }
86
- getSource(type = SDK.ToDataType.Normal) {
87
- if (type === SDK.ToDataType.NoCode) return {
88
- source: '',
89
- transformed: '',
90
- parsedSource: ''
91
- };
92
- if (type === SDK.ToDataType.NoSourceAndAssets || type === SDK.ToDataType.NoSource) return {
93
- source: '',
94
- transformed: '',
95
- parsedSource: this.isPreferSource ? '' : this.source.parsedSource
96
- };
97
- if (type === SDK.ToDataType.All) return {
98
- source: this.source.source,
99
- transformed: this.source.transformed,
100
- parsedSource: this.isPreferSource ? '' : this.source.parsedSource
101
- };
102
- return {
103
- source: this.source.source,
104
- transformed: '',
105
- parsedSource: this.isPreferSource ? '' : this.source.parsedSource
106
- };
107
- }
108
- setSourceMap(sourceMap) {
109
- this.sourceMap = sourceMap;
110
- }
111
- getSourceMap() {
112
- return this.sourceMap;
113
- }
114
- setSize(input) {
115
- const { size } = this;
116
- size.sourceSize = input.sourceSize ?? size.sourceSize;
117
- size.transformedSize = input.transformedSize ?? size.transformedSize;
118
- size.parsedSize = input.parsedSize ?? size.parsedSize;
119
- if ('number' == typeof input.gzipSize) size.gzipSize = input.gzipSize;
120
- else {
121
- const code = this.source.parsedSource || this.source.source;
122
- if (code && 'string' == typeof code && code.length > 0) try {
123
- size.gzipSize = gzipSync(code, {
124
- level: 9
125
- }).length;
126
- } catch (e) {
127
- size.gzipSize = 0;
128
- }
129
- }
130
- }
131
- getSize() {
132
- return {
133
- ...this.size
134
- };
135
- }
136
- getStatement(transformed) {
137
- return new Statement(this, {
138
- source: this.getSourceRange(transformed),
139
- transformed: {
140
- start: {
141
- ...transformed.start
142
- },
143
- end: transformed.end ? {
144
- ...transformed.end
145
- } : void 0
146
- }
147
- });
148
- }
149
- getSourceRange(transformed) {
150
- const { sourceMap } = this;
151
- if (!sourceMap) return;
152
- const source = {
153
- start: {}
154
- };
155
- const startInSource = sourceMap.originalPositionFor({
156
- line: transformed.start.line ?? 0,
157
- column: transformed.start.column ?? 0,
158
- bias: 1
159
- });
160
- if (Lodash.isNumber(startInSource.line)) source.start = {
161
- line: startInSource.line,
162
- column: startInSource.column ?? void 0
163
- };
164
- if (transformed.end) {
165
- const endInSource = sourceMap.originalPositionFor({
166
- line: transformed.end.line ?? 0,
167
- column: transformed.end.column ?? 0
168
- });
169
- if (Lodash.isNumber(endInSource.line)) source.end = {
170
- line: endInSource.line,
171
- column: endInSource.column ?? void 0
172
- };
173
- }
174
- return source;
175
- }
176
- addNormalModule(module) {
177
- if (!this.modules.includes(module)) {
178
- this.modules.push(module);
179
- module.addConcatenationModule(this);
180
- }
181
- }
182
- getNormalModules() {
183
- return this.modules.slice();
184
- }
185
- addConcatenationModule(module) {
186
- if (!this.concatenationModules.includes(module)) this.concatenationModules.push(module);
187
- }
188
- addIssuerPath(issuerPath) {
189
- var _this_issuerPath;
190
- if (!(null == (_this_issuerPath = this.issuerPath) ? void 0 : _this_issuerPath.length)) this.issuerPath = issuerPath;
191
- }
192
- getIssuerPath() {
193
- return this.issuerPath;
194
- }
195
- getConcatenationModules() {
196
- return this.concatenationModules.slice();
197
- }
198
- toData(contextPath) {
199
- var _this_issuerPath;
200
- const { isPreferSource } = this;
201
- const moduleName = getModuleName(this.webpackId);
202
- const data = {
203
- id: this.id,
204
- renderId: this.renderId,
205
- webpackId: contextPath && moduleName.indexOf('.') > 0 ? path_0.relative(contextPath, moduleName) : this.webpackId,
206
- path: this.path,
207
- isPreferSource,
208
- dependencies: this.dependencies.map((item)=>item.id),
209
- imported: this.imported.map((item)=>item.id),
210
- chunks: this.chunks.map((item)=>item.id),
211
- size: this.getSize(),
212
- kind: this.kind,
213
- ...this.layer ? {
214
- layer: this.layer
215
- } : {},
216
- issuerPath: (null == (_this_issuerPath = this.issuerPath) ? void 0 : _this_issuerPath.filter((issuer)=>issuer.moduleId).map((issuer)=>issuer.moduleId)) || [],
217
- bailoutReason: this.bailoutReason
218
- };
219
- if (this.meta.hasSetEsModuleStatement || this.meta.strictHarmonyModule) {
220
- data.meta = {};
221
- if (this.meta.hasSetEsModuleStatement) data.meta.hasSetEsModuleStatement = true;
222
- if (this.meta.strictHarmonyModule) data.meta.strictHarmonyModule = true;
223
- }
224
- if (this.isEntry) data.isEntry = this.isEntry;
225
- if (this.modules.length > 0) data.modules = this.modules.map((item)=>item.id);
226
- if (this.rootModule) data.rootModule = this.rootModule.id;
227
- if (this.concatenationModules.length > 0) data.concatenationModules = this.concatenationModules.map((data)=>data.id);
228
- return data;
229
- }
230
- setId(id) {
231
- this.id = id;
232
- }
233
- setRenderId(renderId) {
234
- this.renderId = renderId;
235
- }
236
- setChunks(chunks) {
237
- this.chunks = chunks;
238
- }
239
- setDependencies(dependencies) {
240
- this.dependencies = dependencies;
241
- }
242
- setImported(imported) {
243
- this.imported = imported;
244
- }
245
- setModules(modules) {
246
- this.modules = modules;
247
- }
248
- setConcatenationModules(modules) {
249
- this.concatenationModules = modules;
250
- }
251
- constructor(webpackId, path, isEntry = false, kind = SDK.ModuleKind.Normal, renderId, layer = ''){
252
- this.issuerPath = [];
253
- this.bailoutReason = [];
254
- this.source = {
255
- source: '',
256
- transformed: '',
257
- parsedSource: ''
258
- };
259
- this.size = {
260
- sourceSize: 0,
261
- transformedSize: 0,
262
- parsedSize: 0,
263
- gzipSize: 0
264
- };
265
- this.chunks = [];
266
- this.dependencies = [];
267
- this.imported = [];
268
- this.modules = [];
269
- this.concatenationModules = [];
270
- this.meta = {
271
- hasSetEsModuleStatement: false,
272
- strictHarmonyModule: false
273
- };
274
- this.id = module_id++;
275
- this.webpackId = webpackId;
276
- this.path = path;
277
- this.isEntry = isEntry;
278
- this.kind = kind;
279
- this.renderId = renderId;
280
- this.layer = layer;
281
- }
282
- }
283
- Module.kind = SDK.ModuleKind;
284
- export { Module };
@@ -1,58 +0,0 @@
1
- import { isSameRange } from "./utils.mjs";
2
- class Statement {
3
- static getDefaultStatement(module) {
4
- const defaultPosition = {
5
- line: 1,
6
- column: 0
7
- };
8
- const defaultRange = {
9
- start: {
10
- ...defaultPosition
11
- },
12
- end: {
13
- ...defaultPosition
14
- }
15
- };
16
- return new Statement(module, {
17
- source: {
18
- ...defaultRange
19
- },
20
- transformed: {
21
- ...defaultRange
22
- }
23
- });
24
- }
25
- isSame(statement) {
26
- return this.module.id === statement.module.id && isSameRange(this.position.transformed, statement.position.transformed);
27
- }
28
- getSourcePosition() {
29
- const { module, position } = this;
30
- if (position.source) return position.source;
31
- if (module.getSourceMap()) {
32
- position.source = module.getSourceRange(position.transformed);
33
- return position.source;
34
- }
35
- }
36
- getLineCode() {
37
- const useSource = this.module.isPreferSource && this.position.source;
38
- const sourceCode = this.module.getSource();
39
- const source = useSource ? sourceCode.source : sourceCode.transformed;
40
- const line = useSource ? this.position.source.start.line : this.position.transformed.start.line;
41
- if ('number' == typeof line) return source.split('\n')[line - 1];
42
- }
43
- toData() {
44
- const position = {
45
- transformed: this.position.transformed
46
- };
47
- if (this.position.source) position.source = this.position.source;
48
- return {
49
- position,
50
- module: this.module.id
51
- };
52
- }
53
- constructor(module, position){
54
- this.module = module;
55
- this.position = position;
56
- }
57
- }
58
- export { Statement };
@@ -1,68 +0,0 @@
1
- let id = 1;
2
- class ExportInfo {
3
- static init() {
4
- id = 1;
5
- }
6
- get isReExport() {
7
- return Boolean(this.from);
8
- }
9
- set variable(data) {
10
- this._variable = data;
11
- }
12
- get variable() {
13
- var _this_getRecursiveExport;
14
- if (this._variable) return this._variable;
15
- if (!this.from || false === this._variable) {
16
- this._variable = false;
17
- return;
18
- }
19
- const result = null == (_this_getRecursiveExport = this.getRecursiveExport()) ? void 0 : _this_getRecursiveExport.variable;
20
- if (!result) this._variable = false;
21
- return result;
22
- }
23
- addSideEffect(info) {
24
- if (this._sideEffects.every((item)=>item.id !== info.id)) {
25
- this._sideEffects.push(info);
26
- if (this.from) this.from.addSideEffect(info);
27
- }
28
- }
29
- getSideEffects() {
30
- return this._sideEffects.slice();
31
- }
32
- setFromExport(from) {
33
- this.from = from;
34
- }
35
- getRecursiveExport(depth = 1 / 0) {
36
- if (0 === depth) throw new Error('`getRecursiveExport` method parameter depth must be greater than 1.');
37
- if (!this.from) return this;
38
- let currentDepth = 0;
39
- let current = this;
40
- while(current.from && currentDepth < depth){
41
- currentDepth++;
42
- current = current.from;
43
- }
44
- return current;
45
- }
46
- toData() {
47
- const data = {
48
- id: this.id,
49
- name: this.name,
50
- isReExport: this.isReExport,
51
- used: this._sideEffects.map((item)=>item.id)
52
- };
53
- if (this.from) {
54
- data.from = this.from.id;
55
- data.root = this.getRecursiveExport().id;
56
- }
57
- if (this.variable) data.variable = this.variable.id;
58
- return data;
59
- }
60
- constructor(name, identifier, variable){
61
- this.id = id++;
62
- this._sideEffects = [];
63
- this.name = name;
64
- this.identifier = identifier;
65
- this._variable = variable;
66
- }
67
- }
68
- export { ExportInfo };