1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.buildDepGraphYarnLockV1Workspace = 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 | const buildDepGraphYarnLockV1Workspace = async (extractedYarnLockV1Pkgs, pkgJson, workspacePkgNameToVersion, options) => {
|
9 | const { includeDevDeps, strictOutOfSync, includeOptionalDeps } = options;
|
10 | const depGraphBuilder = new dep_graph_1.DepGraphBuilder({ name: 'yarn' }, { name: pkgJson.name, version: pkgJson.version });
|
11 | const visitedMap = new Set();
|
12 | const topLevelDeps = (0, util_1.getTopLevelDeps)(pkgJson, { includeDevDeps });
|
13 | const rootNode = {
|
14 | id: 'root-node',
|
15 | name: pkgJson.name,
|
16 | version: pkgJson.version,
|
17 | dependencies: topLevelDeps,
|
18 | isDev: false,
|
19 | };
|
20 | await dfsVisit(depGraphBuilder, rootNode, visitedMap, extractedYarnLockV1Pkgs, workspacePkgNameToVersion, strictOutOfSync, includeOptionalDeps);
|
21 | return depGraphBuilder.build();
|
22 | };
|
23 | exports.buildDepGraphYarnLockV1Workspace = buildDepGraphYarnLockV1Workspace;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | const dfsVisit = async (depGraphBuilder, node, visitedMap, extractedYarnLockV1Pkgs, workspacePkgNameToVersion, strictOutOfSync, includeOptionalDeps) => {
|
35 | visitedMap.add(node.id);
|
36 | for (const [name, depInfo] of Object.entries(node.dependencies || {})) {
|
37 | if (event_loop_spinner_1.eventLoopSpinner.isStarving()) {
|
38 | await event_loop_spinner_1.eventLoopSpinner.spin();
|
39 | }
|
40 | const isWorkspacePkg = !!workspacePkgNameToVersion[name];
|
41 | const childNode = (0, util_2.getChildNodeYarnLockV1Workspace)(name, depInfo, workspacePkgNameToVersion, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps);
|
42 | if (!visitedMap.has(childNode.id)) {
|
43 | (0, util_1.addPkgNodeToGraph)(depGraphBuilder, childNode, {
|
44 | isCyclic: false,
|
45 | isWorkspacePkg,
|
46 | });
|
47 | if (!isWorkspacePkg) {
|
48 | await dfsVisit(depGraphBuilder, childNode, visitedMap, extractedYarnLockV1Pkgs, workspacePkgNameToVersion, strictOutOfSync, includeOptionalDeps);
|
49 | }
|
50 | }
|
51 | depGraphBuilder.connectDep(node.id, childNode.id);
|
52 | }
|
53 | };
|
54 |
|
\ | No newline at end of file |