1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createChangedPackagesGraph = void 0;
|
4 | const dep_graph_1 = require("./dep-graph");
|
5 | const builder_1 = require("./builder");
|
6 | const event_loop_spinner_1 = require("event-loop-spinner");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | async function createChangedPackagesGraph(graphA, graphB) {
|
15 | const depGraph = graphB;
|
16 | const graphAPackageIds = new Set(graphA.getDepPkgs().map(dep_graph_1.DepGraphImpl.getPkgId));
|
17 | const addedOrUpdatedPackages = depGraph
|
18 | .getDepPkgs()
|
19 | .filter((pkg) => !graphAPackageIds.has(dep_graph_1.DepGraphImpl.getPkgId(pkg)));
|
20 | const depGraphBuilder = new builder_1.DepGraphBuilder(depGraph.pkgManager, depGraph.rootPkg);
|
21 | const parentQueue = [];
|
22 | for (const changedPackage of addedOrUpdatedPackages) {
|
23 | for (const changedNodeId of depGraph.getPkgNodeIds(changedPackage)) {
|
24 |
|
25 |
|
26 | depGraphBuilder.addPkgNode(depGraph.getNodePkg(changedNodeId), changedNodeId, getNodeInfo(depGraph, changedNodeId));
|
27 |
|
28 | for (const parentId of depGraph.getNodeParentsNodeIds(changedNodeId)) {
|
29 | parentQueue.push([parentId, changedNodeId]);
|
30 | if (event_loop_spinner_1.eventLoopSpinner.isStarving()) {
|
31 | await event_loop_spinner_1.eventLoopSpinner.spin();
|
32 | }
|
33 | }
|
34 | }
|
35 | }
|
36 |
|
37 | const visited = new Set([depGraph.rootNodeId]);
|
38 | while (parentQueue.length > 0) {
|
39 | const [nodeId, dependencyNodeId] = parentQueue.pop();
|
40 | if (visited.has(nodeId)) {
|
41 |
|
42 | depGraphBuilder.connectDep(nodeId, dependencyNodeId);
|
43 | continue;
|
44 | }
|
45 | visited.add(nodeId);
|
46 | depGraphBuilder.addPkgNode(depGraph.getNodePkg(nodeId), nodeId, getNodeInfo(depGraph, nodeId));
|
47 | depGraphBuilder.connectDep(nodeId, dependencyNodeId);
|
48 | for (const parentId of depGraph.getNodeParentsNodeIds(nodeId)) {
|
49 | parentQueue.push([parentId, nodeId]);
|
50 | if (event_loop_spinner_1.eventLoopSpinner.isStarving()) {
|
51 | await event_loop_spinner_1.eventLoopSpinner.spin();
|
52 | }
|
53 | }
|
54 | }
|
55 | return depGraphBuilder.build();
|
56 | }
|
57 | exports.createChangedPackagesGraph = createChangedPackagesGraph;
|
58 | function getNodeInfo(depGraph, nodeId) {
|
59 | const nodeInfo = depGraph.getNode(nodeId);
|
60 | if (!nodeInfo || Object.keys(nodeInfo).length === 0) {
|
61 | return undefined;
|
62 | }
|
63 | return nodeInfo;
|
64 | }
|
65 |
|
\ | No newline at end of file |