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