@rsdoctor/graph 0.0.2-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.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/cjs/graph/chunk-graph/asset.js +44 -0
- package/dist/cjs/graph/chunk-graph/chunk.js +105 -0
- package/dist/cjs/graph/chunk-graph/entrypoint.js +52 -0
- package/dist/cjs/graph/chunk-graph/graph.js +88 -0
- package/dist/cjs/graph/chunk-graph/index.js +28 -0
- package/dist/cjs/graph/index.js +26 -0
- package/dist/cjs/graph/module-graph/dependency.js +91 -0
- package/dist/cjs/graph/module-graph/graph.js +354 -0
- package/dist/cjs/graph/module-graph/index.js +32 -0
- package/dist/cjs/graph/module-graph/module.js +284 -0
- package/dist/cjs/graph/module-graph/statement.js +82 -0
- package/dist/cjs/graph/module-graph/tree-shaking/export.js +107 -0
- package/dist/cjs/graph/module-graph/tree-shaking/index.js +30 -0
- package/dist/cjs/graph/module-graph/tree-shaking/module.js +98 -0
- package/dist/cjs/graph/module-graph/tree-shaking/sideEffect.js +94 -0
- package/dist/cjs/graph/module-graph/tree-shaking/types.js +16 -0
- package/dist/cjs/graph/module-graph/tree-shaking/variable.js +63 -0
- package/dist/cjs/graph/module-graph/types.js +16 -0
- package/dist/cjs/graph/module-graph/utils.js +65 -0
- package/dist/cjs/graph/package-graph/dependency.js +56 -0
- package/dist/cjs/graph/package-graph/graph.js +173 -0
- package/dist/cjs/graph/package-graph/index.js +28 -0
- package/dist/cjs/graph/package-graph/package.js +121 -0
- package/dist/cjs/graph/package-graph/types.js +16 -0
- package/dist/cjs/graph/package-graph/utils.js +30 -0
- package/dist/cjs/index.js +22 -0
- package/dist/esm/graph/chunk-graph/asset.js +20 -0
- package/dist/esm/graph/chunk-graph/chunk.js +81 -0
- package/dist/esm/graph/chunk-graph/entrypoint.js +28 -0
- package/dist/esm/graph/chunk-graph/graph.js +64 -0
- package/dist/esm/graph/chunk-graph/index.js +4 -0
- package/dist/esm/graph/index.js +3 -0
- package/dist/esm/graph/module-graph/dependency.js +67 -0
- package/dist/esm/graph/module-graph/graph.js +335 -0
- package/dist/esm/graph/module-graph/index.js +6 -0
- package/dist/esm/graph/module-graph/module.js +250 -0
- package/dist/esm/graph/module-graph/statement.js +58 -0
- package/dist/esm/graph/module-graph/tree-shaking/export.js +83 -0
- package/dist/esm/graph/module-graph/tree-shaking/index.js +5 -0
- package/dist/esm/graph/module-graph/tree-shaking/module.js +74 -0
- package/dist/esm/graph/module-graph/tree-shaking/sideEffect.js +70 -0
- package/dist/esm/graph/module-graph/tree-shaking/types.js +0 -0
- package/dist/esm/graph/module-graph/tree-shaking/variable.js +39 -0
- package/dist/esm/graph/module-graph/types.js +0 -0
- package/dist/esm/graph/module-graph/utils.js +39 -0
- package/dist/esm/graph/package-graph/dependency.js +32 -0
- package/dist/esm/graph/package-graph/graph.js +149 -0
- package/dist/esm/graph/package-graph/index.js +4 -0
- package/dist/esm/graph/package-graph/package.js +97 -0
- package/dist/esm/graph/package-graph/types.js +0 -0
- package/dist/esm/graph/package-graph/utils.js +6 -0
- package/dist/esm/index.js +1 -0
- package/dist/type/graph/chunk-graph/asset.d.ts +10 -0
- package/dist/type/graph/chunk-graph/chunk.d.ts +30 -0
- package/dist/type/graph/chunk-graph/entrypoint.d.ts +12 -0
- package/dist/type/graph/chunk-graph/graph.d.ts +22 -0
- package/dist/type/graph/chunk-graph/index.d.ts +4 -0
- package/dist/type/graph/index.d.ts +3 -0
- package/dist/type/graph/module-graph/dependency.d.ts +25 -0
- package/dist/type/graph/module-graph/graph.d.ts +38 -0
- package/dist/type/graph/module-graph/index.d.ts +6 -0
- package/dist/type/graph/module-graph/module.d.ts +64 -0
- package/dist/type/graph/module-graph/statement.d.ts +12 -0
- package/dist/type/graph/module-graph/tree-shaking/export.d.ts +22 -0
- package/dist/type/graph/module-graph/tree-shaking/index.d.ts +5 -0
- package/dist/type/graph/module-graph/tree-shaking/module.d.ts +28 -0
- package/dist/type/graph/module-graph/tree-shaking/sideEffect.d.ts +27 -0
- package/dist/type/graph/module-graph/tree-shaking/types.d.ts +5 -0
- package/dist/type/graph/module-graph/tree-shaking/variable.d.ts +18 -0
- package/dist/type/graph/module-graph/types.d.ts +12 -0
- package/dist/type/graph/module-graph/utils.d.ts +4 -0
- package/dist/type/graph/package-graph/dependency.d.ts +15 -0
- package/dist/type/graph/package-graph/graph.d.ts +25 -0
- package/dist/type/graph/package-graph/index.d.ts +4 -0
- package/dist/type/graph/package-graph/package.d.ts +25 -0
- package/dist/type/graph/package-graph/types.d.ts +6 -0
- package/dist/type/graph/package-graph/utils.d.ts +1 -0
- package/dist/type/index.d.ts +1 -0
- package/package.json +42 -0
@@ -0,0 +1,354 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var graph_exports = {};
|
20
|
+
__export(graph_exports, {
|
21
|
+
ModuleGraph: () => ModuleGraph
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(graph_exports);
|
24
|
+
var import_types = require("@rsdoctor/types");
|
25
|
+
var import_dependency = require("./dependency");
|
26
|
+
var import_module = require("./module");
|
27
|
+
var import_statement = require("./statement");
|
28
|
+
var import_tree_shaking = require("./tree-shaking");
|
29
|
+
class ModuleGraph {
|
30
|
+
constructor() {
|
31
|
+
this._dependenciesIdMap = /* @__PURE__ */ new Map();
|
32
|
+
this._moduleWebpackIdMap = /* @__PURE__ */ new Map();
|
33
|
+
this._moduleIdMap = /* @__PURE__ */ new Map();
|
34
|
+
this._moduleGraphModules = /* @__PURE__ */ new Map();
|
35
|
+
this._exportIdMap = /* @__PURE__ */ new Map();
|
36
|
+
this._sideEffectIdMap = /* @__PURE__ */ new Map();
|
37
|
+
this._varIdMap = /* @__PURE__ */ new Map();
|
38
|
+
}
|
39
|
+
static init() {
|
40
|
+
import_module.Module.init();
|
41
|
+
import_dependency.Dependency.init();
|
42
|
+
import_tree_shaking.ModuleGraphModule.init();
|
43
|
+
}
|
44
|
+
static fromData(data) {
|
45
|
+
const moduleGraph = new ModuleGraph();
|
46
|
+
const getStatement = (data2) => new import_statement.Statement(moduleGraph.getModuleById(data2.module), data2.position);
|
47
|
+
for (const item of data.modules ?? []) {
|
48
|
+
const module2 = new import_module.Module(
|
49
|
+
String(item.id),
|
50
|
+
item.path,
|
51
|
+
item.isEntry,
|
52
|
+
item.kind
|
53
|
+
);
|
54
|
+
module2.id = item.id;
|
55
|
+
module2.setSize(item.size);
|
56
|
+
module2.meta = {
|
57
|
+
strictHarmonyModule: item.meta?.strictHarmonyModule ?? false,
|
58
|
+
hasSetEsModuleStatement: item.meta?.hasSetEsModuleStatement ?? false
|
59
|
+
};
|
60
|
+
module2._isPreferSource = item.isPreferSource;
|
61
|
+
module2.chunks = item.chunks;
|
62
|
+
moduleGraph.addModule(module2);
|
63
|
+
}
|
64
|
+
for (const moduleData of data.modules ?? []) {
|
65
|
+
const module2 = moduleGraph.getModuleById(moduleData.id);
|
66
|
+
for (const depId of moduleData.dependencies) {
|
67
|
+
const depData = (data.dependencies ?? []).find(
|
68
|
+
(item) => item.id === depId
|
69
|
+
);
|
70
|
+
const depModule = depData && moduleGraph.getModuleById(depData.originDependency);
|
71
|
+
if (!depData || !depModule) {
|
72
|
+
console.warn(`The connection data ID is empty: ${depId}`);
|
73
|
+
continue;
|
74
|
+
}
|
75
|
+
const dep = module2.addDependency(
|
76
|
+
depData.request,
|
77
|
+
depModule,
|
78
|
+
depData.kind,
|
79
|
+
depData.statements.map(getStatement)
|
80
|
+
);
|
81
|
+
if (!dep) {
|
82
|
+
continue;
|
83
|
+
}
|
84
|
+
dep.id = depData.id;
|
85
|
+
moduleGraph.addDependency(dep);
|
86
|
+
}
|
87
|
+
for (const normalModuleId of moduleData.modules ?? []) {
|
88
|
+
const normalModule = moduleGraph.getModuleById(normalModuleId);
|
89
|
+
if (!normalModule) {
|
90
|
+
console.warn(
|
91
|
+
`Add the ordinary module ID as empty: ${normalModuleId}`
|
92
|
+
);
|
93
|
+
continue;
|
94
|
+
}
|
95
|
+
module2.addNormalModule(normalModule);
|
96
|
+
}
|
97
|
+
for (const concatenationModuleId of moduleData.concatenationModules ?? []) {
|
98
|
+
const concatenationModule = moduleGraph.getModuleById(
|
99
|
+
concatenationModuleId
|
100
|
+
);
|
101
|
+
if (!concatenationModule) {
|
102
|
+
console.warn(
|
103
|
+
`The aggregation module ID is empty: ${concatenationModule}`
|
104
|
+
);
|
105
|
+
continue;
|
106
|
+
}
|
107
|
+
module2.addConcatenationModule(concatenationModule);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
for (const exportData of data.exports ?? []) {
|
111
|
+
const info = new import_tree_shaking.ExportInfo(
|
112
|
+
exportData.name,
|
113
|
+
exportData.identifier ? getStatement(exportData.identifier) : void 0
|
114
|
+
);
|
115
|
+
info.id = exportData.id;
|
116
|
+
moduleGraph.addExportInfo(info);
|
117
|
+
}
|
118
|
+
for (const exportData of data.exports ?? []) {
|
119
|
+
if (exportData.from) {
|
120
|
+
const current = moduleGraph._exportIdMap.get(exportData.id);
|
121
|
+
const from = moduleGraph._exportIdMap.get(exportData.from);
|
122
|
+
if (current && from) {
|
123
|
+
current.setFromExport(from);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
for (const varData of data.variables ?? []) {
|
128
|
+
const module2 = moduleGraph.getModuleById(varData.module);
|
129
|
+
if (!module2) {
|
130
|
+
console.warn(
|
131
|
+
`The module ID in the variable is empty:${varData.module}`
|
132
|
+
);
|
133
|
+
continue;
|
134
|
+
}
|
135
|
+
const info = new import_tree_shaking.Variable(
|
136
|
+
varData.name,
|
137
|
+
module2,
|
138
|
+
varData.usedInfo,
|
139
|
+
getStatement(varData.identifier)
|
140
|
+
);
|
141
|
+
const exportInfo = moduleGraph._exportIdMap.get(varData.exported ?? -1);
|
142
|
+
if (exportInfo) {
|
143
|
+
info.setExportInfo(exportInfo);
|
144
|
+
}
|
145
|
+
info.id = varData.id;
|
146
|
+
moduleGraph.addVariable(info);
|
147
|
+
}
|
148
|
+
for (const sideData of data.sideEffects ?? []) {
|
149
|
+
const module2 = moduleGraph.getModuleById(sideData.module);
|
150
|
+
if (!module2) {
|
151
|
+
console.warn(
|
152
|
+
`The module ID in the side effects is empty:${sideData.module}`
|
153
|
+
);
|
154
|
+
continue;
|
155
|
+
}
|
156
|
+
const info = new import_tree_shaking.SideEffect(
|
157
|
+
sideData.name,
|
158
|
+
module2,
|
159
|
+
getStatement(sideData.identifier),
|
160
|
+
sideData.originName
|
161
|
+
);
|
162
|
+
info.isNameSpace = sideData.isNameSpace;
|
163
|
+
info.id = sideData.id;
|
164
|
+
for (const exportId of sideData.exports ?? []) {
|
165
|
+
const exportInfo = moduleGraph._exportIdMap.get(exportId);
|
166
|
+
if (exportInfo) {
|
167
|
+
exportInfo.addSideEffect(info);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
if (sideData.variable) {
|
171
|
+
const varInfo = moduleGraph._varIdMap.get(sideData.variable);
|
172
|
+
if (varInfo) {
|
173
|
+
info._variable = varInfo;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
moduleGraph.addSideEffect(info);
|
177
|
+
}
|
178
|
+
for (const mgmData of data.moduleGraphModules ?? []) {
|
179
|
+
const module2 = moduleGraph.getModuleById(mgmData.module);
|
180
|
+
if (!module2) {
|
181
|
+
console.warn(
|
182
|
+
`The module ID in ModuleGraphModule is empty: ${mgmData.module}`
|
183
|
+
);
|
184
|
+
continue;
|
185
|
+
}
|
186
|
+
const mgm = new import_tree_shaking.ModuleGraphModule(module2, moduleGraph, mgmData.dynamic);
|
187
|
+
moduleGraph.addModuleGraphModule(mgm);
|
188
|
+
mgmData.exports.forEach((id) => {
|
189
|
+
const info = moduleGraph._exportIdMap.get(id);
|
190
|
+
if (info) {
|
191
|
+
mgm.addExportInfo(info);
|
192
|
+
}
|
193
|
+
});
|
194
|
+
mgmData.sideEffects.forEach((id) => {
|
195
|
+
const info = moduleGraph._sideEffectIdMap.get(id);
|
196
|
+
if (info) {
|
197
|
+
mgm.addSideEffect(info);
|
198
|
+
}
|
199
|
+
});
|
200
|
+
mgmData.variables.forEach((id) => {
|
201
|
+
const info = moduleGraph._varIdMap.get(id);
|
202
|
+
if (info) {
|
203
|
+
mgm.addVariable(info);
|
204
|
+
}
|
205
|
+
});
|
206
|
+
}
|
207
|
+
ModuleGraph.init();
|
208
|
+
return moduleGraph;
|
209
|
+
}
|
210
|
+
clear() {
|
211
|
+
this._dependenciesIdMap = /* @__PURE__ */ new Map();
|
212
|
+
this._moduleWebpackIdMap = /* @__PURE__ */ new Map();
|
213
|
+
this._moduleIdMap = /* @__PURE__ */ new Map();
|
214
|
+
this._moduleGraphModules = /* @__PURE__ */ new Map();
|
215
|
+
this._exportIdMap = /* @__PURE__ */ new Map();
|
216
|
+
this._sideEffectIdMap = /* @__PURE__ */ new Map();
|
217
|
+
this._varIdMap = /* @__PURE__ */ new Map();
|
218
|
+
}
|
219
|
+
size() {
|
220
|
+
return this._moduleIdMap.size;
|
221
|
+
}
|
222
|
+
fromInstance(data) {
|
223
|
+
this._dependenciesIdMap = new Map(data._dependenciesIdMap);
|
224
|
+
this._moduleWebpackIdMap = new Map(data._moduleWebpackIdMap);
|
225
|
+
this._moduleIdMap = new Map(data._moduleIdMap);
|
226
|
+
this._moduleGraphModules = new Map(data._moduleGraphModules);
|
227
|
+
this._exportIdMap = new Map(data._exportIdMap);
|
228
|
+
this._sideEffectIdMap = new Map(data._sideEffectIdMap);
|
229
|
+
this._varIdMap = new Map(data._varIdMap);
|
230
|
+
}
|
231
|
+
getSubGraphByModule(module2) {
|
232
|
+
const map = /* @__PURE__ */ new Set();
|
233
|
+
const result = [module2];
|
234
|
+
map.add(module2);
|
235
|
+
for (let i = 0; i < result.length; i++) {
|
236
|
+
const current = result[i];
|
237
|
+
for (const { dependency: depModule } of current.getDependencies()) {
|
238
|
+
if (map.has(depModule)) {
|
239
|
+
continue;
|
240
|
+
}
|
241
|
+
map.add(depModule);
|
242
|
+
result.push(depModule);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
return result;
|
246
|
+
}
|
247
|
+
getModules() {
|
248
|
+
return Array.from(this._moduleWebpackIdMap.values());
|
249
|
+
}
|
250
|
+
getDependencies() {
|
251
|
+
return Array.from(this._dependenciesIdMap.values());
|
252
|
+
}
|
253
|
+
getEntryModules() {
|
254
|
+
return this.getModules().filter(
|
255
|
+
(item) => item.isEntry && item.kind !== import_types.SDK.ModuleKind.Concatenation
|
256
|
+
);
|
257
|
+
}
|
258
|
+
getModuleById(id) {
|
259
|
+
return this._moduleIdMap.get(id);
|
260
|
+
}
|
261
|
+
getDependencyById(id) {
|
262
|
+
return this._dependenciesIdMap.get(id);
|
263
|
+
}
|
264
|
+
getModuleByWebpackId(id) {
|
265
|
+
return this._moduleWebpackIdMap.get(id);
|
266
|
+
}
|
267
|
+
getModuleByFile(file) {
|
268
|
+
return this.getModules().find((item) => item.path === file);
|
269
|
+
}
|
270
|
+
addModule(...modules) {
|
271
|
+
for (const module2 of modules) {
|
272
|
+
if (!this._moduleIdMap.has(module2.id)) {
|
273
|
+
this._moduleWebpackIdMap.set(module2.webpackId, module2);
|
274
|
+
this._moduleIdMap.set(module2.id, module2);
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
addDependency(...deps) {
|
279
|
+
for (const dep of deps) {
|
280
|
+
if (!this._dependenciesIdMap.has(dep.id)) {
|
281
|
+
this._dependenciesIdMap.set(dep.id, dep);
|
282
|
+
this.addModule(dep.module);
|
283
|
+
this.addModule(dep.dependency);
|
284
|
+
}
|
285
|
+
}
|
286
|
+
}
|
287
|
+
removeModule(module2) {
|
288
|
+
this._moduleIdMap.delete(module2.id);
|
289
|
+
this._moduleWebpackIdMap.delete(module2.webpackId);
|
290
|
+
for (const dep of module2.getDependencies()) {
|
291
|
+
this.removeDependency(dep);
|
292
|
+
this._dependenciesIdMap.delete(dep.id);
|
293
|
+
}
|
294
|
+
for (const imported of module2.getImported()) {
|
295
|
+
imported.removeDependencyByModule(imported);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
removeDependency(dep) {
|
299
|
+
dep.module.removeDependency(dep);
|
300
|
+
dep.dependency.removeImported(dep.module);
|
301
|
+
this._dependenciesIdMap.delete(dep.id);
|
302
|
+
}
|
303
|
+
addModuleGraphModule(mgm) {
|
304
|
+
if (!this._moduleGraphModules.has(mgm.module)) {
|
305
|
+
this._moduleGraphModules.set(mgm.module, mgm);
|
306
|
+
}
|
307
|
+
}
|
308
|
+
getModuleGraphModule(module2) {
|
309
|
+
return this._moduleGraphModules.get(module2);
|
310
|
+
}
|
311
|
+
getModuleGraphModules() {
|
312
|
+
return Array.from(this._moduleGraphModules.values());
|
313
|
+
}
|
314
|
+
addExportInfo(data) {
|
315
|
+
this._exportIdMap.set(data.id, data);
|
316
|
+
}
|
317
|
+
addSideEffect(data) {
|
318
|
+
this._sideEffectIdMap.set(data.id, data);
|
319
|
+
}
|
320
|
+
addVariable(data) {
|
321
|
+
this._varIdMap.set(data.id, data);
|
322
|
+
}
|
323
|
+
toData(configs) {
|
324
|
+
return {
|
325
|
+
dependencies: this.getDependencies().map((item) => item.toData()),
|
326
|
+
modules: this.getModules().map(
|
327
|
+
(item) => item.toData(configs?.contextPath)
|
328
|
+
),
|
329
|
+
moduleGraphModules: Array.from(this._moduleGraphModules.values()).map(
|
330
|
+
(item) => item.toData()
|
331
|
+
),
|
332
|
+
exports: Array.from(this._exportIdMap.values()).map(
|
333
|
+
(item) => item.toData()
|
334
|
+
),
|
335
|
+
sideEffects: Array.from(this._sideEffectIdMap.values()).map(
|
336
|
+
(item) => item.toData()
|
337
|
+
),
|
338
|
+
variables: Array.from(this._varIdMap.values()).map(
|
339
|
+
(item) => item.toData()
|
340
|
+
)
|
341
|
+
};
|
342
|
+
}
|
343
|
+
toCodeData(type = import_types.SDK.ToDataType.Normal) {
|
344
|
+
const codeMap = {};
|
345
|
+
this.getModules().forEach((item) => {
|
346
|
+
codeMap[item.id] = item.getSource(type);
|
347
|
+
});
|
348
|
+
return codeMap;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
// Annotate the CommonJS export names for ESM import in node:
|
352
|
+
0 && (module.exports = {
|
353
|
+
ModuleGraph
|
354
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
for (let key of __getOwnPropNames(from))
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
11
|
+
}
|
12
|
+
return to;
|
13
|
+
};
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
16
|
+
var module_graph_exports = {};
|
17
|
+
module.exports = __toCommonJS(module_graph_exports);
|
18
|
+
__reExport(module_graph_exports, require("./dependency"), module.exports);
|
19
|
+
__reExport(module_graph_exports, require("./module"), module.exports);
|
20
|
+
__reExport(module_graph_exports, require("./graph"), module.exports);
|
21
|
+
__reExport(module_graph_exports, require("./statement"), module.exports);
|
22
|
+
__reExport(module_graph_exports, require("./tree-shaking"), module.exports);
|
23
|
+
__reExport(module_graph_exports, require("./types"), module.exports);
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
25
|
+
0 && (module.exports = {
|
26
|
+
...require("./dependency"),
|
27
|
+
...require("./module"),
|
28
|
+
...require("./graph"),
|
29
|
+
...require("./statement"),
|
30
|
+
...require("./tree-shaking"),
|
31
|
+
...require("./types")
|
32
|
+
});
|
@@ -0,0 +1,284 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var module_exports = {};
|
30
|
+
__export(module_exports, {
|
31
|
+
Module: () => Module
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(module_exports);
|
34
|
+
var import_types = require("@rsdoctor/types");
|
35
|
+
var import_path = __toESM(require("path"));
|
36
|
+
var import_lodash = require("lodash");
|
37
|
+
var import_dependency = require("./dependency");
|
38
|
+
var import_statement = require("./statement");
|
39
|
+
var import_utils = require("./utils");
|
40
|
+
let id = 1;
|
41
|
+
class Module {
|
42
|
+
constructor(webpackId, path2, isEntry = false, kind = import_types.SDK.ModuleKind.Normal) {
|
43
|
+
this.source = {
|
44
|
+
source: "",
|
45
|
+
transformed: "",
|
46
|
+
parsedSource: ""
|
47
|
+
};
|
48
|
+
this.size = {
|
49
|
+
sourceSize: 0,
|
50
|
+
transformedSize: 0,
|
51
|
+
parsedSize: 0
|
52
|
+
};
|
53
|
+
this.chunks = [];
|
54
|
+
this.dependencies = [];
|
55
|
+
this.imported = [];
|
56
|
+
this.modules = [];
|
57
|
+
this.concatenationModules = [];
|
58
|
+
this.meta = {
|
59
|
+
hasSetEsModuleStatement: false,
|
60
|
+
strictHarmonyModule: false
|
61
|
+
};
|
62
|
+
this.id = id++;
|
63
|
+
this.webpackId = webpackId;
|
64
|
+
this.path = path2;
|
65
|
+
this.isEntry = isEntry;
|
66
|
+
this.kind = kind;
|
67
|
+
}
|
68
|
+
static init() {
|
69
|
+
id = 1;
|
70
|
+
}
|
71
|
+
get rootModule() {
|
72
|
+
return this.modules.find((item) => item.path === this.path);
|
73
|
+
}
|
74
|
+
get isPreferSource() {
|
75
|
+
if (typeof this._isPreferSource === "boolean") {
|
76
|
+
return this._isPreferSource;
|
77
|
+
}
|
78
|
+
const result = this.source.source.length > 0 && this.source.source !== "test code" && Boolean(this.sourceMap);
|
79
|
+
this._isPreferSource = result;
|
80
|
+
return result;
|
81
|
+
}
|
82
|
+
getChunks() {
|
83
|
+
return this.chunks.slice();
|
84
|
+
}
|
85
|
+
addChunk(chunk) {
|
86
|
+
if (!this.chunks.includes(chunk)) {
|
87
|
+
this.chunks.push(chunk);
|
88
|
+
chunk.addModule(this);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
removeChunk(chunk) {
|
92
|
+
this.chunks = this.chunks.filter((item) => item !== chunk);
|
93
|
+
}
|
94
|
+
getDependencies() {
|
95
|
+
return this.dependencies.slice();
|
96
|
+
}
|
97
|
+
getDependencyByRequest(request) {
|
98
|
+
return this.dependencies.find((item) => item.request === request);
|
99
|
+
}
|
100
|
+
getDependencyByModule(module2) {
|
101
|
+
return this.dependencies.find(
|
102
|
+
(item) => item.originDependency === module2 || item.dependency === module2
|
103
|
+
);
|
104
|
+
}
|
105
|
+
addDependency(request, module2, kind, statements) {
|
106
|
+
const dep = new import_dependency.Dependency(request, this, module2, kind, statements);
|
107
|
+
if (this.dependencies.every((item) => !item.isSameWithoutStatements(dep))) {
|
108
|
+
this.dependencies.push(dep);
|
109
|
+
module2.addImported(this);
|
110
|
+
if (module2.rootModule) {
|
111
|
+
module2.rootModule.addImported(this);
|
112
|
+
}
|
113
|
+
return dep;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
removeDependency(dep) {
|
117
|
+
this.dependencies = this.dependencies.filter((item) => item === dep);
|
118
|
+
}
|
119
|
+
removeDependencyByModule(module2) {
|
120
|
+
const dep = this.getDependencyByModule(module2);
|
121
|
+
if (dep) {
|
122
|
+
this.removeDependency(dep);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
getImported() {
|
126
|
+
return this.imported.slice();
|
127
|
+
}
|
128
|
+
addImported(module2) {
|
129
|
+
if (!this.imported.includes(module2)) {
|
130
|
+
this.imported.push(module2);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
removeImported(module2) {
|
134
|
+
this.imported = this.imported.filter((item) => item === module2);
|
135
|
+
}
|
136
|
+
setProgram(program) {
|
137
|
+
this.program = program;
|
138
|
+
}
|
139
|
+
getProgram() {
|
140
|
+
return this.program;
|
141
|
+
}
|
142
|
+
setSource(input) {
|
143
|
+
const { source } = this;
|
144
|
+
source.source = input.source ?? source.source;
|
145
|
+
source.transformed = input.transformed ?? source.transformed;
|
146
|
+
source.parsedSource = input.parsedSource ?? source.parsedSource;
|
147
|
+
}
|
148
|
+
getSource(type = import_types.SDK.ToDataType.Normal) {
|
149
|
+
return type === import_types.SDK.ToDataType.Lite ? {
|
150
|
+
source: "",
|
151
|
+
transformed: "",
|
152
|
+
parsedSource: this.source.parsedSource
|
153
|
+
} : this.isPreferSource ? {
|
154
|
+
source: this.source.source,
|
155
|
+
transformed: "",
|
156
|
+
parsedSource: ""
|
157
|
+
} : {
|
158
|
+
source: this.source.source,
|
159
|
+
transformed: this.source.transformed,
|
160
|
+
parsedSource: this.source.parsedSource
|
161
|
+
};
|
162
|
+
}
|
163
|
+
setSourceMap(sourceMap) {
|
164
|
+
this.sourceMap = sourceMap;
|
165
|
+
}
|
166
|
+
getSourceMap() {
|
167
|
+
return this.sourceMap;
|
168
|
+
}
|
169
|
+
setSize(input) {
|
170
|
+
const { size } = this;
|
171
|
+
size.sourceSize = input.sourceSize ?? size.sourceSize;
|
172
|
+
size.transformedSize = input.transformedSize ?? size.transformedSize;
|
173
|
+
size.parsedSize = input.parsedSize ?? size.parsedSize;
|
174
|
+
}
|
175
|
+
getSize() {
|
176
|
+
return { ...this.size };
|
177
|
+
}
|
178
|
+
getStatement(transformed) {
|
179
|
+
return new import_statement.Statement(this, {
|
180
|
+
source: this.getSourceRange(transformed),
|
181
|
+
transformed: {
|
182
|
+
start: { ...transformed.start },
|
183
|
+
end: transformed.end ? { ...transformed.end } : void 0
|
184
|
+
}
|
185
|
+
});
|
186
|
+
}
|
187
|
+
getSourceRange(transformed) {
|
188
|
+
const { sourceMap } = this;
|
189
|
+
if (!sourceMap) {
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
const source = {
|
193
|
+
start: {}
|
194
|
+
};
|
195
|
+
const startInSource = sourceMap.originalPositionFor({
|
196
|
+
line: transformed.start.line ?? 0,
|
197
|
+
column: transformed.start.column ?? 0,
|
198
|
+
// The largest lower bound.
|
199
|
+
bias: 1
|
200
|
+
});
|
201
|
+
if ((0, import_lodash.isNumber)(startInSource.line)) {
|
202
|
+
source.start = {
|
203
|
+
line: startInSource.line,
|
204
|
+
column: startInSource.column ?? void 0
|
205
|
+
};
|
206
|
+
}
|
207
|
+
if (transformed.end) {
|
208
|
+
const endInSource = sourceMap.originalPositionFor({
|
209
|
+
line: transformed.end.line ?? 0,
|
210
|
+
column: transformed.end.column ?? 0
|
211
|
+
// The smallest lower bound
|
212
|
+
// bias: 2,
|
213
|
+
});
|
214
|
+
if ((0, import_lodash.isNumber)(endInSource.line)) {
|
215
|
+
source.end = {
|
216
|
+
line: endInSource.line,
|
217
|
+
column: endInSource.column ?? void 0
|
218
|
+
};
|
219
|
+
}
|
220
|
+
}
|
221
|
+
return source;
|
222
|
+
}
|
223
|
+
addNormalModule(module2) {
|
224
|
+
if (!this.modules.includes(module2)) {
|
225
|
+
this.modules.push(module2);
|
226
|
+
module2.addConcatenationModule(this);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
getNormalModules() {
|
230
|
+
return this.modules.slice();
|
231
|
+
}
|
232
|
+
addConcatenationModule(module2) {
|
233
|
+
if (!this.concatenationModules.includes(module2)) {
|
234
|
+
this.concatenationModules.push(module2);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
getConcatenationModules() {
|
238
|
+
return this.concatenationModules.slice();
|
239
|
+
}
|
240
|
+
toData(contextPath) {
|
241
|
+
const { isPreferSource } = this;
|
242
|
+
const moduleName = (0, import_utils.getModuleName)(this.webpackId);
|
243
|
+
const data = {
|
244
|
+
id: this.id,
|
245
|
+
webpackId: contextPath && moduleName.indexOf(".") > 0 ? import_path.default.relative(contextPath, moduleName) : this.webpackId,
|
246
|
+
path: this.path,
|
247
|
+
isPreferSource,
|
248
|
+
dependencies: this.dependencies.map((item) => item.id),
|
249
|
+
imported: this.imported.map((item) => item.id),
|
250
|
+
chunks: this.chunks.map((item) => item.id),
|
251
|
+
size: this.getSize(),
|
252
|
+
kind: this.kind
|
253
|
+
};
|
254
|
+
if (this.meta.hasSetEsModuleStatement || this.meta.strictHarmonyModule) {
|
255
|
+
data.meta = {};
|
256
|
+
if (this.meta.hasSetEsModuleStatement) {
|
257
|
+
data.meta.hasSetEsModuleStatement = true;
|
258
|
+
}
|
259
|
+
if (this.meta.strictHarmonyModule) {
|
260
|
+
data.meta.strictHarmonyModule = true;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
if (this.isEntry) {
|
264
|
+
data.isEntry = this.isEntry;
|
265
|
+
}
|
266
|
+
if (this.modules.length > 0) {
|
267
|
+
data.modules = this.modules.map((item) => item.id);
|
268
|
+
}
|
269
|
+
if (this.rootModule) {
|
270
|
+
data.rootModule = this.rootModule.id;
|
271
|
+
}
|
272
|
+
if (this.concatenationModules.length > 0) {
|
273
|
+
data.concatenationModules = this.concatenationModules.map(
|
274
|
+
(data2) => data2.id
|
275
|
+
);
|
276
|
+
}
|
277
|
+
return data;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
Module.kind = import_types.SDK.ModuleKind;
|
281
|
+
// Annotate the CommonJS export names for ESM import in node:
|
282
|
+
0 && (module.exports = {
|
283
|
+
Module
|
284
|
+
});
|