1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.buildDepGraphYarnLockV1Simple = 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 | const buildDepGraphYarnLockV1Simple = async (extractedYarnLockV1Pkgs, pkgJson, options) => {
|
8 | const { includeDevDeps, includeOptionalDeps, includePeerDeps, strictOutOfSync, pruneWithinTopLevelDeps, } = options;
|
9 | const depGraphBuilder = new dep_graph_1.DepGraphBuilder({ name: 'yarn' }, { name: pkgJson.name, version: pkgJson.version });
|
10 | const topLevelDeps = (0, util_1.getTopLevelDeps)(pkgJson, {
|
11 | includeDevDeps,
|
12 | includePeerDeps,
|
13 | includeOptionalDeps,
|
14 | });
|
15 | const rootNode = {
|
16 | id: 'root-node',
|
17 | name: pkgJson.name,
|
18 | version: pkgJson.version,
|
19 | dependencies: topLevelDeps,
|
20 | isDev: false,
|
21 | };
|
22 | await dfsVisit(depGraphBuilder, rootNode, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps, pruneWithinTopLevelDeps);
|
23 | return depGraphBuilder.build();
|
24 | };
|
25 | exports.buildDepGraphYarnLockV1Simple = buildDepGraphYarnLockV1Simple;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | const dfsVisit = async (depGraphBuilder, node, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps, pruneWithinTopLevel, visited) => {
|
33 | for (const [name, depInfo] of Object.entries(node.dependencies || {})) {
|
34 | if (event_loop_spinner_1.eventLoopSpinner.isStarving()) {
|
35 | await event_loop_spinner_1.eventLoopSpinner.spin();
|
36 | }
|
37 | const localVisited = visited || new Set();
|
38 | const childNode = (0, util_1.getChildNode)(name, depInfo, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps);
|
39 | if (localVisited.has(childNode.id)) {
|
40 | if (pruneWithinTopLevel) {
|
41 | const prunedId = `${childNode.id}:pruned`;
|
42 | depGraphBuilder.addPkgNode({ name: childNode.name, version: childNode.version }, prunedId, {
|
43 | labels: Object.assign({ scope: node.isDev ? 'dev' : 'prod', pruned: 'true' }, (node.missingLockFileEntry && {
|
44 | missingLockFileEntry: 'true',
|
45 | })),
|
46 | });
|
47 | depGraphBuilder.connectDep(node.id, prunedId);
|
48 | }
|
49 | else {
|
50 | depGraphBuilder.connectDep(node.id, childNode.id);
|
51 | }
|
52 | continue;
|
53 | }
|
54 | depGraphBuilder.addPkgNode({ name: childNode.name, version: childNode.version }, childNode.id, {
|
55 | labels: Object.assign({ scope: node.isDev ? 'dev' : 'prod' }, (node.missingLockFileEntry && {
|
56 | missingLockFileEntry: 'true',
|
57 | })),
|
58 | });
|
59 | depGraphBuilder.connectDep(node.id, childNode.id);
|
60 | localVisited.add(childNode.id);
|
61 | await dfsVisit(depGraphBuilder, childNode, extractedYarnLockV1Pkgs, strictOutOfSync, includeOptionalDeps, pruneWithinTopLevel, localVisited);
|
62 | }
|
63 | };
|
64 |
|
\ | No newline at end of file |