lockvet 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,211 @@
1
+ import { escapeMarkdown, sanitizeString } from './sanitize.js';
2
+
3
+ /**
4
+ * Format report as JSON string.
5
+ *
6
+ * @param {object} report
7
+ * @returns {string}
8
+ */
9
+ export function formatJson(report) {
10
+ const output = {
11
+ schemaVersion: 1,
12
+ meta: report.meta,
13
+ summary: report.summary,
14
+ findings: report.findings,
15
+ ignoredFindings: report.ignoredFindings || []
16
+ };
17
+ return JSON.stringify(output, null, 2);
18
+ }
19
+
20
+ /**
21
+ * Format report as GitHub-flavored Markdown.
22
+ *
23
+ * @param {object} report
24
+ * @returns {string}
25
+ */
26
+ export function formatMarkdown(report) {
27
+ const lines = [];
28
+ const meta = report.meta || {};
29
+ const summary = report.summary || {};
30
+ const findings = report.findings || [];
31
+
32
+ lines.push('# đŸ›Ąī¸ lockvet Report');
33
+ lines.push('');
34
+ lines.push(
35
+ `**Project:** \`${escapeMarkdown(meta.projectName || 'root')}\` | **Lockfile Version:** ${meta.lockfileVersion || 'unknown'} | **Packages:** ${meta.packageCount || 0}`
36
+ );
37
+ lines.push('');
38
+ lines.push('### Overview');
39
+ lines.push('');
40
+ lines.push('| Metric | Count |');
41
+ lines.push('| :--- | :--- |');
42
+ lines.push(`| 🔴 Errors | ${summary.errors || 0} |`);
43
+ lines.push(`| 🟡 Warnings | ${summary.warnings || 0} |`);
44
+ lines.push(`| â„šī¸ Info | ${summary.info || 0} |`);
45
+ lines.push(`| đŸ“Ļ Total Findings | ${summary.totalFindings || 0} |`);
46
+ lines.push('');
47
+
48
+ if (findings.length === 0) {
49
+ lines.push('🎉 **No findings detected. Lockfile is clean!**');
50
+ lines.push('');
51
+ } else {
52
+ lines.push('### Findings');
53
+ lines.push('');
54
+ lines.push('| Severity | Rule | Package | Version | Scope | Details |');
55
+ lines.push('| :--- | :--- | :--- | :--- | :--- | :--- |');
56
+
57
+ for (const f of findings) {
58
+ const sevIcon =
59
+ f.severity === 'error' ? '🔴 Error' : f.severity === 'warning' ? '🟡 Warning' : 'â„šī¸ Info';
60
+ const pkgName = escapeMarkdown(f.name);
61
+ const version = escapeMarkdown(f.version);
62
+ const scope = escapeMarkdown(f.scope || 'prod');
63
+ const details = escapeMarkdown(f.details);
64
+ lines.push(
65
+ `| ${sevIcon} | \`${escapeMarkdown(f.rule)}\` | \`${pkgName}\` | \`${version}\` | ${scope} | ${details} |`
66
+ );
67
+ }
68
+ lines.push('');
69
+
70
+ // Paths details
71
+ const findingsWithPaths = findings.filter((f) => f.paths && f.paths.length > 0);
72
+ if (findingsWithPaths.length > 0) {
73
+ lines.push('### Dependency Paths & Fix Targets');
74
+ lines.push('');
75
+ for (const f of findingsWithPaths) {
76
+ lines.push(`<details>`);
77
+ lines.push(
78
+ `<summary><strong>${escapeMarkdown(f.name)}@${escapeMarkdown(f.version)}</strong> (${escapeMarkdown(f.rule)})</summary>`
79
+ );
80
+ lines.push('');
81
+ if (f.fixTargets && f.fixTargets.length > 0) {
82
+ lines.push(
83
+ `**Fix targets (direct dependencies):** ${f.fixTargets.map((ft) => `\`${escapeMarkdown(ft)}\``).join(', ')}`
84
+ );
85
+ lines.push('');
86
+ }
87
+ lines.push('Chains:');
88
+ for (const p of f.paths) {
89
+ lines.push(`- \`${p.map(escapeMarkdown).join(' > ')}\``);
90
+ }
91
+ lines.push('');
92
+ lines.push('</details>');
93
+ lines.push('');
94
+ }
95
+ }
96
+ }
97
+
98
+ // Licenses summary
99
+ if (summary.licenses && Object.keys(summary.licenses).length > 0) {
100
+ lines.push('### License Distribution');
101
+ lines.push('');
102
+ lines.push('| SPDX Identifier | Count |');
103
+ lines.push('| :--- | :--- |');
104
+ const sortedLicenses = Object.entries(summary.licenses).sort((a, b) => b[1] - a[1]);
105
+ for (const [lic, count] of sortedLicenses) {
106
+ lines.push(`| \`${escapeMarkdown(lic)}\` | ${count} |`);
107
+ }
108
+ lines.push('');
109
+ }
110
+
111
+ return lines.join('\n');
112
+ }
113
+
114
+ /**
115
+ * Format report as human-readable plain or ANSI-colored terminal text.
116
+ *
117
+ * @param {object} report
118
+ * @param {object} [options]
119
+ * @param {boolean} [options.color=false]
120
+ * @returns {string}
121
+ */
122
+ export function formatText(report, options = {}) {
123
+ const useColor = options.color ?? false;
124
+
125
+ const red = (s) => (useColor ? `\x1b[31m${s}\x1b[0m` : s);
126
+ const yellow = (s) => (useColor ? `\x1b[33m${s}\x1b[0m` : s);
127
+ const cyan = (s) => (useColor ? `\x1b[36m${s}\x1b[0m` : s);
128
+ const bold = (s) => (useColor ? `\x1b[1m${s}\x1b[0m` : s);
129
+ const dim = (s) => (useColor ? `\x1b[2m${s}\x1b[0m` : s);
130
+
131
+ const lines = [];
132
+ const meta = report.meta || {};
133
+ const summary = report.summary || {};
134
+ const findings = report.findings || [];
135
+
136
+ lines.push(bold(`lockvet — npm lockfile triage`));
137
+ lines.push(
138
+ dim(
139
+ `Project: ${meta.projectName || 'root'} | Lockfile v${meta.lockfileVersion || '?'} | ${meta.packageCount || 0} packages`
140
+ )
141
+ );
142
+ lines.push('');
143
+
144
+ if (findings.length === 0) {
145
+ lines.push('✔ No findings. Lockfile is clean.');
146
+ } else {
147
+ for (const f of findings) {
148
+ let badge;
149
+ if (f.severity === 'error') {
150
+ badge = red('[ERROR]');
151
+ } else if (f.severity === 'warning') {
152
+ badge = yellow('[WARN] ');
153
+ } else {
154
+ badge = cyan('[INFO] ');
155
+ }
156
+
157
+ const scopeTag = dim(`(${f.scope || 'prod'})`);
158
+ lines.push(`${badge} ${bold(f.name + '@' + f.version)} ${scopeTag} [${f.rule}]`);
159
+ lines.push(` ${sanitizeString(f.details)}`);
160
+
161
+ if (f.fixTargets && f.fixTargets.length > 0) {
162
+ lines.push(dim(` Fix target: ${f.fixTargets.join(', ')}`));
163
+ }
164
+
165
+ if (f.paths && f.paths.length > 0) {
166
+ for (const p of f.paths) {
167
+ lines.push(dim(` Chain: ${p.join(' -> ')}`));
168
+ }
169
+ }
170
+ lines.push('');
171
+ }
172
+ }
173
+
174
+ // Summary
175
+ lines.push(bold('Summary:'));
176
+ lines.push(` Errors: ${summary.errors || 0}`);
177
+ lines.push(` Warnings: ${summary.warnings || 0}`);
178
+ lines.push(` Info: ${summary.info || 0}`);
179
+ lines.push(` Total: ${summary.totalFindings || 0}`);
180
+
181
+ if (summary.licenses && Object.keys(summary.licenses).length > 0) {
182
+ lines.push('');
183
+ lines.push(bold('Licenses:'));
184
+ const sortedLicenses = Object.entries(summary.licenses).sort((a, b) => b[1] - a[1]);
185
+ for (const [lic, count] of sortedLicenses) {
186
+ lines.push(` ${lic.padEnd(20)} ${count}`);
187
+ }
188
+ }
189
+
190
+ return lines.join('\n');
191
+ }
192
+
193
+ /**
194
+ * Format report based on selected format.
195
+ *
196
+ * @param {object} report
197
+ * @param {object} [options]
198
+ * @param {'text' | 'json' | 'markdown'} [options.format='text']
199
+ * @param {boolean} [options.color]
200
+ * @returns {string}
201
+ */
202
+ export function formatReport(report, options = {}) {
203
+ const fmt = options.format || 'text';
204
+ if (fmt === 'json') {
205
+ return formatJson(report);
206
+ }
207
+ if (fmt === 'markdown') {
208
+ return formatMarkdown(report);
209
+ }
210
+ return formatText(report, options);
211
+ }
package/src/graph.js ADDED
@@ -0,0 +1,376 @@
1
+ import { sanitizeString } from './sanitize.js';
2
+
3
+ /**
4
+ * Extract the package name from an npm lockfile install path.
5
+ * e.g. "node_modules/foo" -> "foo"
6
+ * "node_modules/@scope/bar" -> "@scope/bar"
7
+ * "node_modules/a/node_modules/@scope/b" -> "@scope/b"
8
+ * "" -> root project name
9
+ *
10
+ * @param {string} installPath
11
+ * @param {object} [entry]
12
+ * @returns {string}
13
+ */
14
+ export function derivePackageName(installPath, entry = null, fallbackName = 'root') {
15
+ if (installPath === '') {
16
+ return entry && typeof entry.name === 'string' && entry.name
17
+ ? entry.name
18
+ : fallbackName || 'root';
19
+ }
20
+ const nmIndex = installPath.lastIndexOf('node_modules/');
21
+ if (nmIndex !== -1) {
22
+ return installPath.slice(nmIndex + 'node_modules/'.length);
23
+ }
24
+ if (entry && typeof entry.name === 'string' && entry.name) {
25
+ return entry.name;
26
+ }
27
+ // Fallback for custom workspace paths like "packages/my-pkg"
28
+ const segments = installPath.split('/');
29
+ return segments[segments.length - 1] || installPath;
30
+ }
31
+
32
+ /**
33
+ * Resolve a dependency's install path using Node's hierarchical resolution.
34
+ *
35
+ * @param {Map<string, object>} packagesMap
36
+ * @param {string} fromPath
37
+ * @param {string} depName
38
+ * @returns {string | null} Resolved install path in packagesMap or null
39
+ */
40
+ export function resolveDependencyPath(packagesMap, fromPath, depName) {
41
+ let current = fromPath;
42
+
43
+ while (current !== null) {
44
+ const candidate =
45
+ current === '' ? `node_modules/${depName}` : `${current}/node_modules/${depName}`;
46
+ if (packagesMap.has(candidate)) {
47
+ const target = packagesMap.get(candidate);
48
+ if (target && target.link === true && typeof target.resolved === 'string') {
49
+ const resolvedKey = target.resolved.startsWith('./')
50
+ ? target.resolved.slice(2)
51
+ : target.resolved;
52
+ if (packagesMap.has(resolvedKey)) {
53
+ return resolvedKey;
54
+ }
55
+ }
56
+ return candidate;
57
+ }
58
+
59
+ if (current === '') {
60
+ current = null;
61
+ } else {
62
+ const lastNmIdx = current.lastIndexOf('/node_modules/');
63
+ if (lastNmIdx !== -1) {
64
+ current = current.slice(0, lastNmIdx);
65
+ } else if (current.startsWith('node_modules/')) {
66
+ current = '';
67
+ } else {
68
+ const lastSlash = current.lastIndexOf('/');
69
+ current = lastSlash !== -1 ? current.slice(0, lastSlash) : '';
70
+ }
71
+ }
72
+ }
73
+
74
+ return null;
75
+ }
76
+
77
+ /**
78
+ * Build a dependency graph from the parsed lockfile packages map.
79
+ *
80
+ * @param {object} lockfile Parsed lockfile
81
+ * @returns {object} Graph structure with nodes, root, and warnings
82
+ */
83
+ export function buildGraph(lockfile) {
84
+ const rawPackages = lockfile.packages || {};
85
+ const packagesMap = new Map();
86
+
87
+ for (const [key, val] of Object.entries(rawPackages)) {
88
+ if (val && typeof val === 'object') {
89
+ packagesMap.set(key, val);
90
+ }
91
+ }
92
+
93
+ const nodes = new Map();
94
+ const missingDependencyWarnings = [];
95
+
96
+ // Create node entries
97
+ for (const [installPath, entry] of packagesMap.entries()) {
98
+ const rawName = derivePackageName(installPath, entry, lockfile.name);
99
+ const name = sanitizeString(rawName);
100
+ const version = sanitizeString(
101
+ typeof entry.version === 'string'
102
+ ? entry.version
103
+ : installPath === '' && lockfile.version
104
+ ? lockfile.version
105
+ : '0.0.0'
106
+ );
107
+ const isRoot = installPath === '';
108
+ const isLink = entry.link === true;
109
+
110
+ nodes.set(installPath, {
111
+ installPath,
112
+ name,
113
+ version,
114
+ id: `${name}@${version}`,
115
+ entry,
116
+ dependencies: new Set(),
117
+ scope: 'prod', // Will be refined
118
+ isRoot,
119
+ isLink
120
+ });
121
+ }
122
+
123
+ // Ensure root node exists even if "" wasn't in packages
124
+ if (!nodes.has('')) {
125
+ nodes.set('', {
126
+ installPath: '',
127
+ name: sanitizeString(lockfile.name || 'root'),
128
+ version: sanitizeString(lockfile.version || '0.0.0'),
129
+ id: `${sanitizeString(lockfile.name || 'root')}@${sanitizeString(lockfile.version || '0.0.0')}`,
130
+ entry: {},
131
+ dependencies: new Set(),
132
+ scope: 'prod',
133
+ isRoot: true,
134
+ isLink: false
135
+ });
136
+ }
137
+
138
+ // Wire dependency edges
139
+ for (const [installPath, node] of nodes.entries()) {
140
+ const entry = node.entry;
141
+ if (!entry) continue;
142
+
143
+ // Follow link targets for dependencies
144
+ let depSource = entry;
145
+ if (entry.link === true && entry.resolved) {
146
+ const resolvedTarget = entry.resolved.startsWith('./')
147
+ ? entry.resolved.slice(2)
148
+ : entry.resolved;
149
+ if (packagesMap.has(resolvedTarget)) {
150
+ depSource = packagesMap.get(resolvedTarget);
151
+ }
152
+ }
153
+
154
+ const regularDeps =
155
+ depSource.dependencies && typeof depSource.dependencies === 'object'
156
+ ? Object.keys(depSource.dependencies)
157
+ : [];
158
+ const devDeps =
159
+ node.isRoot && depSource.devDependencies && typeof depSource.devDependencies === 'object'
160
+ ? Object.keys(depSource.devDependencies)
161
+ : [];
162
+ const optionalDeps =
163
+ depSource.optionalDependencies && typeof depSource.optionalDependencies === 'object'
164
+ ? Object.keys(depSource.optionalDependencies)
165
+ : [];
166
+ const peerDeps =
167
+ depSource.peerDependencies && typeof depSource.peerDependencies === 'object'
168
+ ? Object.keys(depSource.peerDependencies)
169
+ : [];
170
+
171
+ const allDepNames = new Set([...regularDeps, ...devDeps, ...optionalDeps, ...peerDeps]);
172
+
173
+ for (const depName of allDepNames) {
174
+ const isOptionalOrPeer = optionalDeps.includes(depName) || peerDeps.includes(depName);
175
+ const isDev = devDeps.includes(depName);
176
+ const resolvedPath = resolveDependencyPath(packagesMap, installPath, depName);
177
+
178
+ if (resolvedPath && nodes.has(resolvedPath)) {
179
+ node.dependencies.add(resolvedPath);
180
+ } else if (!isOptionalOrPeer && !isDev) {
181
+ missingDependencyWarnings.push({
182
+ type: 'missing-dependency',
183
+ from: installPath || '(root)',
184
+ dependency: depName,
185
+ message: `Missing required dependency "${depName}" required by "${installPath || '(root)'}"`
186
+ });
187
+ }
188
+ }
189
+ }
190
+
191
+ // Determine scopes (prod, dev, optional) via BFS from root
192
+ const rootNode = nodes.get('');
193
+ const visitedProd = new Set();
194
+ const visitedDev = new Set();
195
+ const visitedOptional = new Set();
196
+
197
+ // 1. Prod traversal
198
+ const rootEntry = rootNode.entry || {};
199
+ const rootProdNames = new Set([
200
+ ...Object.keys(rootEntry.dependencies || {}),
201
+ ...Object.keys(rootEntry.peerDependencies || {})
202
+ ]);
203
+ const rootDevNames = new Set(Object.keys(rootEntry.devDependencies || {}));
204
+ const rootOptNames = new Set(Object.keys(rootEntry.optionalDependencies || {}));
205
+
206
+ // Resolve root direct deps
207
+ const prodQueue = [];
208
+ for (const depName of rootProdNames) {
209
+ const resolved = resolveDependencyPath(packagesMap, '', depName);
210
+ if (resolved && nodes.has(resolved)) {
211
+ prodQueue.push(resolved);
212
+ visitedProd.add(resolved);
213
+ }
214
+ }
215
+ while (prodQueue.length > 0) {
216
+ const currentPath = prodQueue.shift();
217
+ const curr = nodes.get(currentPath);
218
+ if (!curr) continue;
219
+ for (const childPath of curr.dependencies) {
220
+ if (!visitedProd.has(childPath)) {
221
+ visitedProd.add(childPath);
222
+ prodQueue.push(childPath);
223
+ }
224
+ }
225
+ }
226
+
227
+ // 2. Dev traversal
228
+ const devQueue = [];
229
+ for (const depName of rootDevNames) {
230
+ const resolved = resolveDependencyPath(packagesMap, '', depName);
231
+ if (resolved && nodes.has(resolved)) {
232
+ devQueue.push(resolved);
233
+ visitedDev.add(resolved);
234
+ }
235
+ }
236
+ while (devQueue.length > 0) {
237
+ const currentPath = devQueue.shift();
238
+ const curr = nodes.get(currentPath);
239
+ if (!curr) continue;
240
+ for (const childPath of curr.dependencies) {
241
+ if (!visitedDev.has(childPath)) {
242
+ visitedDev.add(childPath);
243
+ devQueue.push(childPath);
244
+ }
245
+ }
246
+ }
247
+
248
+ // 3. Optional traversal
249
+ const optQueue = [];
250
+ for (const depName of rootOptNames) {
251
+ const resolved = resolveDependencyPath(packagesMap, '', depName);
252
+ if (resolved && nodes.has(resolved)) {
253
+ optQueue.push(resolved);
254
+ visitedOptional.add(resolved);
255
+ }
256
+ }
257
+ while (optQueue.length > 0) {
258
+ const currentPath = optQueue.shift();
259
+ const curr = nodes.get(currentPath);
260
+ if (!curr) continue;
261
+ for (const childPath of curr.dependencies) {
262
+ if (!visitedOptional.has(childPath)) {
263
+ visitedOptional.add(childPath);
264
+ optQueue.push(childPath);
265
+ }
266
+ }
267
+ }
268
+
269
+ // Assign scope
270
+ for (const [installPath, node] of nodes.entries()) {
271
+ if (node.isRoot) {
272
+ node.scope = 'prod';
273
+ continue;
274
+ }
275
+ if (visitedProd.has(installPath)) {
276
+ node.scope = 'prod';
277
+ } else if (
278
+ node.entry.dev === true ||
279
+ (visitedDev.has(installPath) && !visitedProd.has(installPath))
280
+ ) {
281
+ node.scope = 'dev';
282
+ } else if (node.entry.optional === true || visitedOptional.has(installPath)) {
283
+ node.scope = 'optional';
284
+ } else {
285
+ node.scope = 'prod';
286
+ }
287
+ }
288
+
289
+ return {
290
+ nodes,
291
+ root: rootNode,
292
+ warnings: missingDependencyWarnings
293
+ };
294
+ }
295
+
296
+ /**
297
+ * BFS from root to compute up to N shortest dependency chains to target.
298
+ * Chains are returned as arrays of "name@version".
299
+ *
300
+ * @param {object} graph
301
+ * @param {string} target Identifier (package name, installPath, or name@version)
302
+ * @param {object} [options]
303
+ * @param {number} [options.max=3] Maximum number of shortest paths to return
304
+ * @param {string} [options.version] Optional specific version filter
305
+ * @returns {Array<string[]>} Array of chains
306
+ */
307
+ export function findPaths(graph, target, options = {}) {
308
+ const maxPaths = options.max ?? 3;
309
+ if (maxPaths <= 0) return [];
310
+
311
+ const rootNode = graph.root;
312
+ if (!rootNode) return [];
313
+
314
+ // Match target against node
315
+ const matchesTarget = (node) => {
316
+ if (node.isRoot) return false;
317
+ if (options.version && node.version !== options.version) {
318
+ return false;
319
+ }
320
+ if (node.installPath === target) return true;
321
+ if (node.name === target) return true;
322
+ if (node.id === target) return true;
323
+ return false;
324
+ };
325
+
326
+ const results = [];
327
+ // Queue entries: { path: [installPath...], chain: [name@version...], visited: Set<installPath> }
328
+ const queue = [
329
+ {
330
+ path: [''],
331
+ chain: [rootNode.id],
332
+ visited: new Set([''])
333
+ }
334
+ ];
335
+
336
+ const MAX_EXPANSIONS = 25000;
337
+ let expansions = 0;
338
+
339
+ while (queue.length > 0 && results.length < maxPaths) {
340
+ if (++expansions > MAX_EXPANSIONS) {
341
+ break; // Safeguard against massive graphs
342
+ }
343
+
344
+ const { path, chain, visited } = queue.shift();
345
+ const currentPath = path[path.length - 1];
346
+ const currentNode = graph.nodes.get(currentPath);
347
+ if (!currentNode) continue;
348
+
349
+ for (const childPath of currentNode.dependencies) {
350
+ if (visited.has(childPath)) {
351
+ continue; // Prevent circular cycles (A -> B -> A)
352
+ }
353
+
354
+ const childNode = graph.nodes.get(childPath);
355
+ if (!childNode) continue;
356
+
357
+ const nextChain = [...chain, childNode.id];
358
+ if (matchesTarget(childNode)) {
359
+ results.push(nextChain);
360
+ if (results.length >= maxPaths) {
361
+ return results;
362
+ }
363
+ }
364
+
365
+ const nextVisited = new Set(visited);
366
+ nextVisited.add(childPath);
367
+ queue.push({
368
+ path: [...path, childPath],
369
+ chain: nextChain,
370
+ visited: nextVisited
371
+ });
372
+ }
373
+ }
374
+
375
+ return results;
376
+ }
package/src/index.js ADDED
@@ -0,0 +1,69 @@
1
+ import { parseLockfile } from './parse.js';
2
+ import { buildGraph, findPaths } from './graph.js';
3
+ import { evaluateRules } from './rules.js';
4
+ import { formatReport } from './formatters.js';
5
+ import { LockvetError } from './errors.js';
6
+
7
+ /**
8
+ * Analyze an npm lockfile and generate a comprehensive triage report.
9
+ *
10
+ * @param {string | object} lockfileInput Raw JSON string or parsed object
11
+ * @param {object} [options]
12
+ * @param {number} [options.maxPaths=3]
13
+ * @param {boolean} [options.prodOnly=false]
14
+ * @param {string[]} [options.denyLicenses=[]]
15
+ * @param {string[]} [options.allowLicenses=[]]
16
+ * @param {Array<string | { package: string }>} [options.ignore=[]]
17
+ * @param {number} [options.maxSizeBytes]
18
+ * @returns {object} Report object with meta, findings, ignoredFindings, and summary
19
+ */
20
+ export function analyze(lockfileInput, options = {}) {
21
+ const parsed = parseLockfile(lockfileInput, options);
22
+ const graph = buildGraph(parsed);
23
+ const { findings, ignoredFindings, licenseSummary } = evaluateRules(graph, options);
24
+
25
+ const errorsCount = findings.filter((f) => f.severity === 'error').length;
26
+ const warningsCount = findings.filter((f) => f.severity === 'warning').length;
27
+ const infoCount = findings.filter((f) => f.severity === 'info').length;
28
+
29
+ const byRule = Object.create(null);
30
+ for (const f of findings) {
31
+ byRule[f.rule] = (byRule[f.rule] || 0) + 1;
32
+ }
33
+
34
+ // Count packages in packages map excluding root
35
+ let packageCount = 0;
36
+ if (parsed.packages && typeof parsed.packages === 'object') {
37
+ for (const key of Object.keys(parsed.packages)) {
38
+ if (key !== '') {
39
+ packageCount++;
40
+ }
41
+ }
42
+ }
43
+
44
+ const meta = {
45
+ lockfileVersion: parsed.lockfileVersion,
46
+ packageCount,
47
+ projectName: graph.root.name,
48
+ projectVersion: graph.root.version,
49
+ warnings: graph.warnings
50
+ };
51
+
52
+ const summary = {
53
+ totalFindings: findings.length,
54
+ errors: errorsCount,
55
+ warnings: warningsCount,
56
+ info: infoCount,
57
+ byRule,
58
+ licenses: licenseSummary
59
+ };
60
+
61
+ return {
62
+ meta,
63
+ findings,
64
+ ignoredFindings,
65
+ summary
66
+ };
67
+ }
68
+
69
+ export { parseLockfile, buildGraph, findPaths, formatReport, LockvetError };