1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.buildDepGraphYarnLockV1SimpleCyclesPruned = void 0;
|
4 | const dep_graph_1 = require("@snyk/dep-graph");
|
5 | const util_1 = require("../util");
|
6 | const event_loop_spinner_1 = require("event-loop-spinner");
|
7 | var Color;
|
8 | (function (Color) {
|
9 | Color[Color["GRAY"] = 0] = "GRAY";
|
10 | Color[Color["BLACK"] = 1] = "BLACK";
|
11 | })(Color || (Color = {}));
|
12 | const buildDepGraphYarnLockV1SimpleCyclesPruned = async (extractedYarnLockV1Pkgs, pkgJson, options) => {
|
13 | const { includeDevDeps, strictOutOfSync, includeOptionalDeps } = options;
|
14 | const depGraphBuilder = new dep_graph_1.DepGraphBuilder({ name: 'yarn' }, { name: pkgJson.name, version: pkgJson.version });
|
15 | const colorMap = {};
|
16 | const topLevelDeps = (0, util_1.getTopLevelDeps)(pkgJson, { includeDevDeps });
|
17 | const rootNode = {
|
18 | id: 'root-node',
|
19 | name: pkgJson.name,
|
20 | version: pkgJson.version,
|
21 | dependencies: topLevelDeps,
|
22 | isDev: false,
|
23 | };
|
24 | await dfsVisit(depGraphBuilder, rootNode, colorMap, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps);
|
25 | return depGraphBuilder.build();
|
26 | };
|
27 | exports.buildDepGraphYarnLockV1SimpleCyclesPruned = buildDepGraphYarnLockV1SimpleCyclesPruned;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | const dfsVisit = async (depGraphBuilder, node, colorMap, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps) => {
|
38 | colorMap[node.id] = Color.GRAY;
|
39 | for (const [name, depInfo] of Object.entries(node.dependencies || {})) {
|
40 | if (event_loop_spinner_1.eventLoopSpinner.isStarving()) {
|
41 | await event_loop_spinner_1.eventLoopSpinner.spin();
|
42 | }
|
43 | const childNode = (0, util_1.getChildNode)(name, depInfo, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps);
|
44 | if (!colorMap.hasOwnProperty(childNode.id)) {
|
45 | (0, util_1.addPkgNodeToGraph)(depGraphBuilder, childNode, {});
|
46 | await dfsVisit(depGraphBuilder, childNode, colorMap, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps);
|
47 | }
|
48 | else if (colorMap[childNode.id] === Color.GRAY) {
|
49 |
|
50 | childNode.id = `${childNode.id}:pruned`;
|
51 | (0, util_1.addPkgNodeToGraph)(depGraphBuilder, childNode, { isCyclic: true });
|
52 | }
|
53 | depGraphBuilder.connectDep(node.id, childNode.id);
|
54 | }
|
55 | colorMap[node.id] = Color.BLACK;
|
56 | };
|
57 |
|
\ | No newline at end of file |