@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,173 @@
|
|
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")) || import_common.Package.getPackageMetaFromModulePath(file2);
|
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()).filter((pkgs) => pkgs.length > 1),
|
160
|
+
(pkgs) => pkgs[0].name
|
161
|
+
);
|
162
|
+
}
|
163
|
+
toData() {
|
164
|
+
return {
|
165
|
+
packages: this._packages.map((e) => e.toData()),
|
166
|
+
dependencies: this._dependencies.map((d) => d.toData())
|
167
|
+
};
|
168
|
+
}
|
169
|
+
}
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
171
|
+
0 && (module.exports = {
|
172
|
+
PackageGraph
|
173
|
+
});
|
@@ -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,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
|
+
};
|