@rsdoctor/graph 0.0.0-next-20240620044732

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/dist/cjs/graph/chunk-graph/asset.js +44 -0
  4. package/dist/cjs/graph/chunk-graph/chunk.js +105 -0
  5. package/dist/cjs/graph/chunk-graph/entrypoint.js +52 -0
  6. package/dist/cjs/graph/chunk-graph/graph.js +88 -0
  7. package/dist/cjs/graph/chunk-graph/index.js +28 -0
  8. package/dist/cjs/graph/index.js +26 -0
  9. package/dist/cjs/graph/module-graph/dependency.js +91 -0
  10. package/dist/cjs/graph/module-graph/graph.js +354 -0
  11. package/dist/cjs/graph/module-graph/index.js +32 -0
  12. package/dist/cjs/graph/module-graph/module.js +290 -0
  13. package/dist/cjs/graph/module-graph/statement.js +82 -0
  14. package/dist/cjs/graph/module-graph/tree-shaking/export.js +107 -0
  15. package/dist/cjs/graph/module-graph/tree-shaking/index.js +30 -0
  16. package/dist/cjs/graph/module-graph/tree-shaking/module.js +98 -0
  17. package/dist/cjs/graph/module-graph/tree-shaking/sideEffect.js +94 -0
  18. package/dist/cjs/graph/module-graph/tree-shaking/types.js +16 -0
  19. package/dist/cjs/graph/module-graph/tree-shaking/variable.js +63 -0
  20. package/dist/cjs/graph/module-graph/types.js +16 -0
  21. package/dist/cjs/graph/module-graph/utils.js +65 -0
  22. package/dist/cjs/graph/package-graph/dependency.js +56 -0
  23. package/dist/cjs/graph/package-graph/graph.js +175 -0
  24. package/dist/cjs/graph/package-graph/index.js +28 -0
  25. package/dist/cjs/graph/package-graph/package.js +121 -0
  26. package/dist/cjs/graph/package-graph/types.js +16 -0
  27. package/dist/cjs/graph/package-graph/utils.js +30 -0
  28. package/dist/cjs/index.js +22 -0
  29. package/dist/esm/graph/chunk-graph/asset.js +20 -0
  30. package/dist/esm/graph/chunk-graph/chunk.js +81 -0
  31. package/dist/esm/graph/chunk-graph/entrypoint.js +28 -0
  32. package/dist/esm/graph/chunk-graph/graph.js +64 -0
  33. package/dist/esm/graph/chunk-graph/index.js +4 -0
  34. package/dist/esm/graph/index.js +3 -0
  35. package/dist/esm/graph/module-graph/dependency.js +67 -0
  36. package/dist/esm/graph/module-graph/graph.js +335 -0
  37. package/dist/esm/graph/module-graph/index.js +6 -0
  38. package/dist/esm/graph/module-graph/module.js +256 -0
  39. package/dist/esm/graph/module-graph/statement.js +58 -0
  40. package/dist/esm/graph/module-graph/tree-shaking/export.js +83 -0
  41. package/dist/esm/graph/module-graph/tree-shaking/index.js +5 -0
  42. package/dist/esm/graph/module-graph/tree-shaking/module.js +74 -0
  43. package/dist/esm/graph/module-graph/tree-shaking/sideEffect.js +70 -0
  44. package/dist/esm/graph/module-graph/tree-shaking/types.js +0 -0
  45. package/dist/esm/graph/module-graph/tree-shaking/variable.js +39 -0
  46. package/dist/esm/graph/module-graph/types.js +0 -0
  47. package/dist/esm/graph/module-graph/utils.js +39 -0
  48. package/dist/esm/graph/package-graph/dependency.js +32 -0
  49. package/dist/esm/graph/package-graph/graph.js +151 -0
  50. package/dist/esm/graph/package-graph/index.js +4 -0
  51. package/dist/esm/graph/package-graph/package.js +97 -0
  52. package/dist/esm/graph/package-graph/types.js +0 -0
  53. package/dist/esm/graph/package-graph/utils.js +6 -0
  54. package/dist/esm/index.js +1 -0
  55. package/dist/type/graph/chunk-graph/asset.d.ts +11 -0
  56. package/dist/type/graph/chunk-graph/asset.d.ts.map +1 -0
  57. package/dist/type/graph/chunk-graph/chunk.d.ts +31 -0
  58. package/dist/type/graph/chunk-graph/chunk.d.ts.map +1 -0
  59. package/dist/type/graph/chunk-graph/entrypoint.d.ts +13 -0
  60. package/dist/type/graph/chunk-graph/entrypoint.d.ts.map +1 -0
  61. package/dist/type/graph/chunk-graph/graph.d.ts +23 -0
  62. package/dist/type/graph/chunk-graph/graph.d.ts.map +1 -0
  63. package/dist/type/graph/chunk-graph/index.d.ts +5 -0
  64. package/dist/type/graph/chunk-graph/index.d.ts.map +1 -0
  65. package/dist/type/graph/index.d.ts +4 -0
  66. package/dist/type/graph/index.d.ts.map +1 -0
  67. package/dist/type/graph/module-graph/dependency.d.ts +26 -0
  68. package/dist/type/graph/module-graph/dependency.d.ts.map +1 -0
  69. package/dist/type/graph/module-graph/graph.d.ts +39 -0
  70. package/dist/type/graph/module-graph/graph.d.ts.map +1 -0
  71. package/dist/type/graph/module-graph/index.d.ts +7 -0
  72. package/dist/type/graph/module-graph/index.d.ts.map +1 -0
  73. package/dist/type/graph/module-graph/module.d.ts +65 -0
  74. package/dist/type/graph/module-graph/module.d.ts.map +1 -0
  75. package/dist/type/graph/module-graph/statement.d.ts +13 -0
  76. package/dist/type/graph/module-graph/statement.d.ts.map +1 -0
  77. package/dist/type/graph/module-graph/tree-shaking/export.d.ts +23 -0
  78. package/dist/type/graph/module-graph/tree-shaking/export.d.ts.map +1 -0
  79. package/dist/type/graph/module-graph/tree-shaking/index.d.ts +6 -0
  80. package/dist/type/graph/module-graph/tree-shaking/index.d.ts.map +1 -0
  81. package/dist/type/graph/module-graph/tree-shaking/module.d.ts +29 -0
  82. package/dist/type/graph/module-graph/tree-shaking/module.d.ts.map +1 -0
  83. package/dist/type/graph/module-graph/tree-shaking/sideEffect.d.ts +28 -0
  84. package/dist/type/graph/module-graph/tree-shaking/sideEffect.d.ts.map +1 -0
  85. package/dist/type/graph/module-graph/tree-shaking/types.d.ts +6 -0
  86. package/dist/type/graph/module-graph/tree-shaking/types.d.ts.map +1 -0
  87. package/dist/type/graph/module-graph/tree-shaking/variable.d.ts +19 -0
  88. package/dist/type/graph/module-graph/tree-shaking/variable.d.ts.map +1 -0
  89. package/dist/type/graph/module-graph/types.d.ts +13 -0
  90. package/dist/type/graph/module-graph/types.d.ts.map +1 -0
  91. package/dist/type/graph/module-graph/utils.d.ts +5 -0
  92. package/dist/type/graph/module-graph/utils.d.ts.map +1 -0
  93. package/dist/type/graph/package-graph/dependency.d.ts +16 -0
  94. package/dist/type/graph/package-graph/dependency.d.ts.map +1 -0
  95. package/dist/type/graph/package-graph/graph.d.ts +26 -0
  96. package/dist/type/graph/package-graph/graph.d.ts.map +1 -0
  97. package/dist/type/graph/package-graph/index.d.ts +5 -0
  98. package/dist/type/graph/package-graph/index.d.ts.map +1 -0
  99. package/dist/type/graph/package-graph/package.d.ts +26 -0
  100. package/dist/type/graph/package-graph/package.d.ts.map +1 -0
  101. package/dist/type/graph/package-graph/types.d.ts +7 -0
  102. package/dist/type/graph/package-graph/types.d.ts.map +1 -0
  103. package/dist/type/graph/package-graph/utils.d.ts +2 -0
  104. package/dist/type/graph/package-graph/utils.d.ts.map +1 -0
  105. package/dist/type/index.d.ts +2 -0
  106. package/dist/type/index.d.ts.map +1 -0
  107. package/package.json +42 -0
@@ -0,0 +1,175 @@
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
+ PackageGraph: () => PackageGraph
22
+ });
23
+ module.exports = __toCommonJS(graph_exports);
24
+ var import_lodash = require("lodash");
25
+ var import_path = require("path");
26
+ var import_types = require("@rsdoctor/types");
27
+ var import_common = require("@rsdoctor/utils/common");
28
+ var import_package = require("./package");
29
+ var import_dependency = require("./dependency");
30
+ class PackageGraph {
31
+ constructor(root) {
32
+ this._dependencies = [];
33
+ this._packages = [];
34
+ this._pkgNameMap = /* @__PURE__ */ new Map();
35
+ this._pkgFileMap = /* @__PURE__ */ new Map();
36
+ this._root = root;
37
+ }
38
+ static fromModuleGraph(graph, root, getPackageFile) {
39
+ const pkgGraph = new PackageGraph(root);
40
+ const modules = graph.getModules().filter((item) => item.kind === import_types.SDK.ModuleKind.Normal);
41
+ for (const item of modules) {
42
+ const pkg = pkgGraph.getPackageByModule(item, getPackageFile);
43
+ if (pkg) {
44
+ pkgGraph.addPackage(pkg);
45
+ pkg.addModule(item);
46
+ }
47
+ }
48
+ for (const dep of graph.getDependencies()) {
49
+ const modulePkg = pkgGraph.getPackageByFile(dep.module.path);
50
+ const dependencyPkg = pkgGraph.getPackageByFile(dep.dependency.path);
51
+ if (modulePkg && dependencyPkg && !modulePkg.isSame(dependencyPkg)) {
52
+ const pkgDep = new import_dependency.PackageDependency(modulePkg, dependencyPkg, dep);
53
+ pkgGraph.addDependency(pkgDep);
54
+ modulePkg.addDependency(pkgDep);
55
+ }
56
+ }
57
+ return pkgGraph;
58
+ }
59
+ getPackages() {
60
+ return this._packages.slice();
61
+ }
62
+ getPackageByModule(module2, readFile) {
63
+ const { path: file, meta } = module2;
64
+ const { _pkgFileMap: pkgsMap } = this;
65
+ const getPackageByData = (data2) => {
66
+ return this.getPackageByData(data2) ?? new import_package.Package(data2.name, data2.root, data2.version);
67
+ };
68
+ if (pkgsMap.has(file)) {
69
+ return pkgsMap.get(file);
70
+ }
71
+ if (meta.packageData) {
72
+ const pkg2 = getPackageByData(meta.packageData);
73
+ pkgsMap.set(file, pkg2);
74
+ return pkg2;
75
+ }
76
+ const readPackageJson = (file2, readFile2) => {
77
+ let result;
78
+ let current = file2;
79
+ while (current !== "/" && !result) {
80
+ if ((0, import_path.dirname)(current) === current) {
81
+ break;
82
+ }
83
+ current = (0, import_path.dirname)(current);
84
+ if (readFile2) {
85
+ result = readFile2((0, import_path.join)(current, "package.json"));
86
+ }
87
+ if (!readFile2) {
88
+ result = import_common.Package.getPackageMetaFromModulePath(file2);
89
+ } else if (!result?.name) {
90
+ result = void 0;
91
+ }
92
+ }
93
+ if (!result) {
94
+ return;
95
+ }
96
+ if (readFile2 && (!result.name || !result.version)) {
97
+ return readPackageJson((0, import_path.dirname)(current), readFile2);
98
+ }
99
+ return {
100
+ ...result,
101
+ root: current
102
+ };
103
+ };
104
+ const cache = this.getPackageContainFile(file);
105
+ if (cache) {
106
+ pkgsMap.set(file, cache);
107
+ return cache;
108
+ }
109
+ const data = readPackageJson(file, readFile);
110
+ if (!data) {
111
+ return;
112
+ }
113
+ if (data.root.startsWith(".")) {
114
+ data.root = (0, import_path.resolve)(this._root, data.root);
115
+ }
116
+ const pkg = getPackageByData(data);
117
+ this.addPackage(pkg);
118
+ pkgsMap.set(file, pkg);
119
+ return pkg;
120
+ }
121
+ getPackageByFile(file) {
122
+ return this._pkgFileMap.get(file);
123
+ }
124
+ getPackageContainFile(file) {
125
+ return this._packages.find((pkg) => pkg.contain(file));
126
+ }
127
+ getPackagesByName(name) {
128
+ return this._pkgNameMap.get(name) ?? [];
129
+ }
130
+ getPackageByData(data) {
131
+ return this._pkgNameMap.get(data.name)?.find(
132
+ (item) => item.version === data.version && item.root === data.root
133
+ );
134
+ }
135
+ addPackage(pkg) {
136
+ if (this._packages.every((item) => !item.isSame(pkg))) {
137
+ this._packages.push(pkg);
138
+ const { _pkgNameMap: map } = this;
139
+ const arr = map.get(pkg.name) ?? [];
140
+ if (arr.every((item) => !item.isSame(pkg))) {
141
+ arr.push(pkg);
142
+ map.set(pkg.name, arr);
143
+ }
144
+ }
145
+ }
146
+ getDependenciesFromPackage(pkg) {
147
+ return this._dependencies.filter((dep) => dep.dependency === pkg);
148
+ }
149
+ addDependency(dep) {
150
+ if (this._dependencies.every((item) => !item.isSame(dep))) {
151
+ this._dependencies.push(dep);
152
+ }
153
+ }
154
+ getDependenciesFromOrigin() {
155
+ return this._dependencies.filter((item) => !item.package);
156
+ }
157
+ getDuplicatePackages() {
158
+ return (0, import_lodash.unionBy)(
159
+ Array.from(this._pkgNameMap.values()).map((pkgs) => {
160
+ return (0, import_lodash.unionBy)(pkgs, "version");
161
+ }).filter((pkgs) => pkgs.length > 1),
162
+ (pkgs) => pkgs[0].name
163
+ );
164
+ }
165
+ toData() {
166
+ return {
167
+ packages: this._packages.map((e) => e.toData()),
168
+ dependencies: this._dependencies.map((d) => d.toData())
169
+ };
170
+ }
171
+ }
172
+ // Annotate the CommonJS export names for ESM import in node:
173
+ 0 && (module.exports = {
174
+ PackageGraph
175
+ });
@@ -0,0 +1,28 @@
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 package_graph_exports = {};
17
+ module.exports = __toCommonJS(package_graph_exports);
18
+ __reExport(package_graph_exports, require("./dependency"), module.exports);
19
+ __reExport(package_graph_exports, require("./graph"), module.exports);
20
+ __reExport(package_graph_exports, require("./package"), module.exports);
21
+ __reExport(package_graph_exports, require("./types"), module.exports);
22
+ // Annotate the CommonJS export names for ESM import in node:
23
+ 0 && (module.exports = {
24
+ ...require("./dependency"),
25
+ ...require("./graph"),
26
+ ...require("./package"),
27
+ ...require("./types")
28
+ });
@@ -0,0 +1,121 @@
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 package_exports = {};
20
+ __export(package_exports, {
21
+ Package: () => Package
22
+ });
23
+ module.exports = __toCommonJS(package_exports);
24
+ var import_path = require("path");
25
+ var import_utils = require("./utils");
26
+ let id = 1;
27
+ class Package {
28
+ constructor(name, root, version) {
29
+ this.id = id++;
30
+ this._modules = [];
31
+ this._dependencies = [];
32
+ this._imported = [];
33
+ this.name = name;
34
+ this.root = root;
35
+ this.version = version;
36
+ }
37
+ getModules() {
38
+ return this._modules.slice();
39
+ }
40
+ getDependencies() {
41
+ return this._dependencies.slice();
42
+ }
43
+ getImported() {
44
+ return this._imported.slice();
45
+ }
46
+ addModule(module2) {
47
+ if (!this._modules.includes(module2)) {
48
+ this._modules.push(module2);
49
+ }
50
+ }
51
+ addDependency(dep) {
52
+ if (this._dependencies.every((item) => !item.isSame(dep))) {
53
+ this._dependencies.push(dep);
54
+ dep.dependency.addImported(this);
55
+ }
56
+ }
57
+ getDependenciesChain(graph) {
58
+ function getImported(pkg, ans) {
59
+ const dependencies = graph.getDependenciesFromPackage(pkg);
60
+ for (const dep of dependencies) {
61
+ if (!dep.refDependency) {
62
+ continue;
63
+ }
64
+ if (ans.some((dep2) => dep2.dependency === pkg)) {
65
+ continue;
66
+ }
67
+ if (!dep.package) {
68
+ return ans.concat(dep);
69
+ }
70
+ return getImported(dep.package, ans.concat(dep));
71
+ }
72
+ return ans;
73
+ }
74
+ return getImported(this, []);
75
+ }
76
+ addImported(pkg) {
77
+ if (!this._imported.includes(pkg)) {
78
+ this._imported.push(pkg);
79
+ }
80
+ }
81
+ contain(file) {
82
+ const subPath = (0, import_path.relative)(this.root, file);
83
+ if (subPath.startsWith("..")) {
84
+ return false;
85
+ }
86
+ return !(0, import_utils.isPackagePath)(subPath);
87
+ }
88
+ isSame(pkg) {
89
+ return this.root === pkg.root && this.version === pkg.version && this.name === pkg.name;
90
+ }
91
+ getSize() {
92
+ return this._modules.reduce(
93
+ (ans, item) => {
94
+ const size = item.getSize();
95
+ ans.sourceSize += size.sourceSize;
96
+ ans.transformedSize += size.transformedSize;
97
+ ans.parsedSize += size.parsedSize;
98
+ return ans;
99
+ },
100
+ {
101
+ sourceSize: 0,
102
+ transformedSize: 0,
103
+ parsedSize: 0
104
+ }
105
+ );
106
+ }
107
+ toData() {
108
+ return {
109
+ id: this.id,
110
+ name: this.name,
111
+ root: this.root,
112
+ version: this.version,
113
+ modules: this.getModules().map((e) => e.id),
114
+ size: this.getSize()
115
+ };
116
+ }
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ Package
121
+ });
@@ -0,0 +1,16 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,30 @@
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 utils_exports = {};
20
+ __export(utils_exports, {
21
+ isPackagePath: () => isPackagePath
22
+ });
23
+ module.exports = __toCommonJS(utils_exports);
24
+ function isPackagePath(path) {
25
+ return /(^|[/\\])node_modules[/\\]/.test(path);
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ isPackagePath
30
+ });
@@ -0,0 +1,22 @@
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 src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./graph"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./graph")
22
+ });
@@ -0,0 +1,20 @@
1
+ import { SDK } from "@rsdoctor/types";
2
+ class Asset {
3
+ constructor(path, size, chunks, content) {
4
+ this.path = path;
5
+ this.size = size;
6
+ this.chunks = chunks;
7
+ this.content = content;
8
+ }
9
+ toData(types) {
10
+ return {
11
+ path: this.path,
12
+ size: this.size,
13
+ chunks: this.chunks?.map((ck) => ck.id),
14
+ content: types === SDK.ToDataType.LiteAndNoAsset ? "" : this.content
15
+ };
16
+ }
17
+ }
18
+ export {
19
+ Asset
20
+ };
@@ -0,0 +1,81 @@
1
+ class Chunk {
2
+ constructor(id, name, size, initial, entry) {
3
+ this._assets = [];
4
+ this._modules = [];
5
+ this._dependencies = [];
6
+ this._imported = [];
7
+ this.id = id;
8
+ this.name = name;
9
+ this.size = size;
10
+ this.initial = initial;
11
+ this.entry = entry;
12
+ }
13
+ isEntry() {
14
+ return this.entry;
15
+ }
16
+ isChunkEntryModule(module) {
17
+ return module.isEntry || module.getImported().every((item) => !this.hasModule(item));
18
+ }
19
+ hasModule(module) {
20
+ return this._modules.includes(module);
21
+ }
22
+ addModule(module) {
23
+ if (!this.hasModule(module)) {
24
+ this._modules.push(module);
25
+ module.addChunk(this);
26
+ }
27
+ }
28
+ addAsset(asset) {
29
+ this._assets.push(asset);
30
+ }
31
+ addModules(modules) {
32
+ modules.forEach((module) => {
33
+ if (!this.hasModule(module)) {
34
+ this._modules.push(module);
35
+ module.addChunk(this);
36
+ }
37
+ });
38
+ }
39
+ addDependency(dep) {
40
+ if (!this._dependencies.includes(dep)) {
41
+ this._dependencies.push(dep);
42
+ }
43
+ }
44
+ addImported(imported) {
45
+ if (!this._imported.includes(imported)) {
46
+ this._imported.push(imported);
47
+ }
48
+ }
49
+ getAssets() {
50
+ return this._assets.slice();
51
+ }
52
+ getModules() {
53
+ return this._modules.slice();
54
+ }
55
+ getDependencies() {
56
+ return this._dependencies.slice();
57
+ }
58
+ getImported() {
59
+ return this._imported.slice();
60
+ }
61
+ setParsedSize(parsedSize) {
62
+ this._parsedSize = parsedSize;
63
+ }
64
+ toData() {
65
+ return {
66
+ id: this.id,
67
+ name: this.name,
68
+ initial: this.initial,
69
+ size: this.size,
70
+ parsedSize: this._parsedSize || 0,
71
+ entry: this.isEntry(),
72
+ assets: this._assets.map(({ path }) => path),
73
+ modules: this._modules.map(({ id }) => id),
74
+ dependencies: this._dependencies.map(({ id }) => id),
75
+ imported: this._imported.map(({ id }) => id)
76
+ };
77
+ }
78
+ }
79
+ export {
80
+ Chunk
81
+ };
@@ -0,0 +1,28 @@
1
+ class EntryPoint {
2
+ constructor(name) {
3
+ this.name = name;
4
+ this._chunks = [];
5
+ this._assets = [];
6
+ }
7
+ addChunk(chunk) {
8
+ if (this._chunks.includes(chunk))
9
+ return;
10
+ this._chunks.push(chunk);
11
+ }
12
+ addAsset(asset) {
13
+ if (this._assets.includes(asset))
14
+ return;
15
+ this._assets.push(asset);
16
+ }
17
+ toData() {
18
+ return {
19
+ name: this.name,
20
+ chunks: this._chunks.map((e) => e.id),
21
+ assets: this._assets.map((e) => e.path),
22
+ size: this._assets.length ? this._assets.reduce((t, e) => t + e.size, 0) : 0
23
+ };
24
+ }
25
+ }
26
+ export {
27
+ EntryPoint
28
+ };
@@ -0,0 +1,64 @@
1
+ class ChunkGraph {
2
+ constructor() {
3
+ this._assets = [];
4
+ this._chunks = [];
5
+ this._entrypoints = [];
6
+ }
7
+ getAssets() {
8
+ return this._assets.slice();
9
+ }
10
+ getChunks() {
11
+ return this._chunks.slice();
12
+ }
13
+ addAsset(...assets) {
14
+ assets.forEach((asset) => {
15
+ if (!this._assets.includes(asset)) {
16
+ this._assets.push(asset);
17
+ }
18
+ });
19
+ }
20
+ addChunk(...chunks) {
21
+ chunks.forEach((chunk) => {
22
+ if (!this._chunks.includes(chunk)) {
23
+ this._chunks.push(chunk);
24
+ }
25
+ });
26
+ }
27
+ getChunkById(id) {
28
+ return this._chunks.find((item) => item.id === id);
29
+ }
30
+ getChunkByModule(module) {
31
+ return this._chunks.find((item) => item.hasModule(module));
32
+ }
33
+ getAssetByPath(path) {
34
+ return this._assets.find((item) => item.path === path);
35
+ }
36
+ getAssetsByChunk(chunk) {
37
+ return this._assets.filter((item) => {
38
+ const _chunk = item.chunks.find((ck) => ck.id === chunk.id);
39
+ if (_chunk)
40
+ return true;
41
+ });
42
+ }
43
+ getEntryPoints() {
44
+ return this._entrypoints.slice();
45
+ }
46
+ addEntryPoint(...entrypoints) {
47
+ entrypoints.forEach((entrypoint) => {
48
+ if (!this._entrypoints.includes(entrypoint)) {
49
+ this._entrypoints.push(entrypoint);
50
+ }
51
+ });
52
+ }
53
+ /** output the chunk graph data */
54
+ toData(type) {
55
+ return {
56
+ assets: this._assets.map((item) => item.toData(type)),
57
+ chunks: this._chunks.map((item) => item.toData()),
58
+ entrypoints: this._entrypoints.map((item) => item.toData())
59
+ };
60
+ }
61
+ }
62
+ export {
63
+ ChunkGraph
64
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./chunk";
2
+ export * from "./graph";
3
+ export * from "./asset";
4
+ export * from "./entrypoint";
@@ -0,0 +1,3 @@
1
+ export * from "./chunk-graph";
2
+ export * from "./module-graph";
3
+ export * from "./package-graph";
@@ -0,0 +1,67 @@
1
+ import { SDK } from "@rsdoctor/types";
2
+ let id = 1;
3
+ class Dependency {
4
+ constructor(request, module, dependency, kind, statements) {
5
+ this.statements = [];
6
+ this.meta = {
7
+ exportsType: "default-with-named"
8
+ };
9
+ this.id = id++;
10
+ this.request = request;
11
+ this.module = module;
12
+ this._originDependency = dependency;
13
+ this.kind = kind;
14
+ this.statements = statements ?? [];
15
+ }
16
+ static init() {
17
+ id = 1;
18
+ }
19
+ get resolvedRequest() {
20
+ return this.dependency.path;
21
+ }
22
+ get dependency() {
23
+ return this.originDependency.rootModule ?? this.originDependency;
24
+ }
25
+ get originDependency() {
26
+ return this._originDependency;
27
+ }
28
+ get kindString() {
29
+ return SDK.DependencyKind[this.kind];
30
+ }
31
+ get resolveConcatenationModule() {
32
+ return this.dependency.kind === SDK.ModuleKind.Concatenation;
33
+ }
34
+ isSameWithoutStatements(dep) {
35
+ return this.request === dep.request && this.kind === dep.kind && this.module.id === dep.module.id && this.dependency.id === dep.dependency.id;
36
+ }
37
+ addStatement(statement) {
38
+ if (!this.hasStatement(statement)) {
39
+ this.statements.push(statement);
40
+ }
41
+ }
42
+ hasStatement(statement) {
43
+ return this.statements.some((item) => item.isSame(statement));
44
+ }
45
+ setBuildMeta(data) {
46
+ this.meta = {
47
+ ...this.meta,
48
+ ...data
49
+ };
50
+ }
51
+ toData() {
52
+ return {
53
+ id: this.id,
54
+ request: this.request,
55
+ resolvedRequest: this.resolvedRequest,
56
+ kind: this.kind,
57
+ module: this.module.id,
58
+ dependency: this.dependency.id,
59
+ originDependency: this.originDependency.id,
60
+ statements: this.statements.map((item) => item.toData())
61
+ };
62
+ }
63
+ }
64
+ Dependency.kind = SDK.DependencyKind;
65
+ export {
66
+ Dependency
67
+ };