@codacy/tools-trivy-0 0.4.0 → 0.5.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.
package/dist/index.js CHANGED
@@ -92,19 +92,33 @@ var patterns_default = [
92
92
  }
93
93
  ];
94
94
 
95
+ // src/metadata.ts
96
+ var descriptor = {
97
+ id: "Trivy",
98
+ displayName: "Trivy",
99
+ preferredVersion: "0.69.3",
100
+ languages: [
101
+ "Python",
102
+ "JavaScript",
103
+ "TypeScript",
104
+ "Go",
105
+ "Java",
106
+ "Ruby",
107
+ "Rust",
108
+ "PHP",
109
+ "C#",
110
+ "Dart",
111
+ "Elixir",
112
+ "Swift"
113
+ ],
114
+ filePatterns: ["*"],
115
+ supportedOS: ["linux", "darwin"],
116
+ supportedArch: ["x64", "arm64"],
117
+ supportedRunners: ["local", "container"]
118
+ };
119
+
95
120
  // src/adapter.ts
96
121
  var TOOL_ID = "Trivy";
97
- function getLineContent(lines, lineNumber) {
98
- return lines[lineNumber - 1] ?? "";
99
- }
100
- async function readFileLines(filePath) {
101
- try {
102
- const content = await import_promises.default.readFile(filePath, "utf-8");
103
- return content.split("\n");
104
- } catch {
105
- return [];
106
- }
107
- }
108
122
  var PATTERN_META = new Map(
109
123
  patterns_default.map((p) => [
110
124
  p.id,
@@ -197,26 +211,6 @@ async function resolveBinaryPath(ctx) {
197
211
  if (version) return codacyBin;
198
212
  return BINARY;
199
213
  }
200
- function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
201
- const durationMs = completedAt.getTime() - startedAt.getTime();
202
- return {
203
- metadata: {
204
- startedAt: startedAt.toISOString(),
205
- completedAt: completedAt.toISOString(),
206
- durationMs
207
- },
208
- issues,
209
- errors,
210
- summary: {
211
- toolId: TOOL_ID,
212
- status: errors.some((e) => e.level === "error") ? "partial" : "success",
213
- issueCount: issues.length,
214
- errorCount: errors.length,
215
- durationMs,
216
- filesAnalyzed
217
- }
218
- };
219
- }
220
214
  async function ensureCacheDir(globalDir) {
221
215
  const cacheDir = import_path.default.join(globalDir, "cache", "trivy");
222
216
  await import_promises.default.mkdir(cacheDir, { recursive: true });
@@ -277,7 +271,7 @@ async function parseVulnerabilities(output, enabledPatterns, targetFilesSet, rep
277
271
  const relPath = result.Target;
278
272
  if (targetFilesSet.size > 0 && !targetFilesSet.has(relPath)) continue;
279
273
  if (!linesCache.has(relPath)) {
280
- linesCache.set(relPath, await readFileLines(import_path.default.join(repositoryRoot, relPath)));
274
+ linesCache.set(relPath, await (0, import_tooling.readFileLines)(import_path.default.join(repositoryRoot, relPath)));
281
275
  }
282
276
  const lines = linesCache.get(relPath);
283
277
  const pkgLineByID = /* @__PURE__ */ new Map();
@@ -306,7 +300,7 @@ async function parseVulnerabilities(output, enabledPatterns, targetFilesSet, rep
306
300
  line,
307
301
  column: 1,
308
302
  message: `Insecure dependency ${vuln.PkgName}@${vuln.InstalledVersion} (${vuln.VulnerabilityID}${title}). ${fix}`,
309
- lineContent: getLineContent(lines, line),
303
+ lineContent: (0, import_tooling.getLineContent)(lines, line),
310
304
  category: meta.category,
311
305
  severity: meta.severity
312
306
  });
@@ -329,7 +323,7 @@ async function parseSecrets(output, enabledPatterns, targetFilesSet, repositoryR
329
323
  const relPath = result.Target;
330
324
  if (targetFilesSet.size > 0 && !targetFilesSet.has(relPath)) continue;
331
325
  if (!linesCache.has(relPath)) {
332
- linesCache.set(relPath, await readFileLines(import_path.default.join(repositoryRoot, relPath)));
326
+ linesCache.set(relPath, await (0, import_tooling.readFileLines)(import_path.default.join(repositoryRoot, relPath)));
333
327
  }
334
328
  const lines = linesCache.get(relPath);
335
329
  for (const secret of result.Secrets) {
@@ -341,7 +335,7 @@ async function parseSecrets(output, enabledPatterns, targetFilesSet, repositoryR
341
335
  column: 1,
342
336
  endLine: secret.EndLine,
343
337
  message: `Possible hardcoded secret: ${secret.Title} (${secret.Category})`,
344
- lineContent: getLineContent(lines, secret.StartLine),
338
+ lineContent: (0, import_tooling.getLineContent)(lines, secret.StartLine),
345
339
  multilineContent: (0, import_tooling.getMultilineContent)(lines, secret.StartLine, secret.EndLine),
346
340
  category: meta.category,
347
341
  severity: meta.severity
@@ -426,7 +420,7 @@ async function parseMaliciousPackages(output, enabledPatterns, targetFilesSet, r
426
420
  const malVulns = maliciousByPkg.get(queryKey);
427
421
  if (!malVulns) continue;
428
422
  if (!linesCache.has(pkg.filePath)) {
429
- linesCache.set(pkg.filePath, await readFileLines(import_path.default.join(repositoryRoot, pkg.filePath)));
423
+ linesCache.set(pkg.filePath, await (0, import_tooling.readFileLines)(import_path.default.join(repositoryRoot, pkg.filePath)));
430
424
  }
431
425
  const lines = linesCache.get(pkg.filePath);
432
426
  for (const vuln of malVulns) {
@@ -438,7 +432,7 @@ async function parseMaliciousPackages(output, enabledPatterns, targetFilesSet, r
438
432
  line: pkg.line,
439
433
  column: 1,
440
434
  message: `Malicious package detected: ${pkg.name}@${pkg.version} (${vuln.id}).${summary}`,
441
- lineContent: getLineContent(lines, pkg.line),
435
+ lineContent: (0, import_tooling.getLineContent)(lines, pkg.line),
442
436
  category: meta.category,
443
437
  severity: meta.severity
444
438
  });
@@ -448,29 +442,9 @@ async function parseMaliciousPackages(output, enabledPatterns, targetFilesSet, r
448
442
  return { issues, errors };
449
443
  }
450
444
  var adapter = {
451
- id: TOOL_ID,
452
- displayName: "Trivy",
453
- preferredVersion: "0.69.3",
445
+ ...descriptor,
454
446
  compatibleVersions: ">=0.50.0",
455
447
  website: "https://trivy.dev/",
456
- languages: [
457
- "Python",
458
- "JavaScript",
459
- "TypeScript",
460
- "Go",
461
- "Java",
462
- "Ruby",
463
- "Rust",
464
- "PHP",
465
- "C#",
466
- "Dart",
467
- "Elixir",
468
- "Swift"
469
- ],
470
- filePatterns: ["*"],
471
- supportedOS: ["linux", "darwin"],
472
- supportedArch: ["x64", "arm64"],
473
- supportedRunners: ["local", "container"],
474
448
  prerequisites: [],
475
449
  /**
476
450
  * Checks whether the `trivy` binary is present and runnable.
@@ -607,13 +581,7 @@ var adapter = {
607
581
  const issues = [];
608
582
  const errors = [];
609
583
  if (ctx.targetFiles.length === 0) {
610
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
611
- }
612
- if (!(codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile) && codacyConfig.patterns.length === 0) {
613
- ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
614
- toolId: TOOL_ID
615
- });
616
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
584
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
617
585
  }
618
586
  const binary = await resolveBinaryPath(ctx);
619
587
  let cacheDir;
@@ -627,7 +595,7 @@ var adapter = {
627
595
  message: `Failed to create cache directory: ${err instanceof Error ? err.message : String(err)}`,
628
596
  level: "error"
629
597
  });
630
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
598
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
631
599
  }
632
600
  const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
633
601
  const targetFilesSet = new Set(ctx.targetFiles);
@@ -727,7 +695,14 @@ var adapter = {
727
695
  level: "error"
728
696
  });
729
697
  }
730
- const result = buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
698
+ const result = (0, import_tooling.buildResult)(
699
+ TOOL_ID,
700
+ startedAt,
701
+ /* @__PURE__ */ new Date(),
702
+ issues,
703
+ errors,
704
+ ctx.targetFiles.length
705
+ );
731
706
  ctx.logger.info("Analysis complete", {
732
707
  toolId: TOOL_ID,
733
708
  issueCount: result.summary.issueCount,
@@ -0,0 +1,13 @@
1
+ import { AdapterDescriptor } from '@codacy/tooling';
2
+
3
+ /**
4
+ * Lightweight adapter descriptor for lazy loading.
5
+ *
6
+ * This module contains only plain-data metadata fields and has zero heavy
7
+ * imports (no patterns.json, no runtime utilities). The CLI imports this
8
+ * at startup for adapter registration without loading the full adapter module.
9
+ */
10
+
11
+ declare const descriptor: AdapterDescriptor;
12
+
13
+ export { descriptor };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/metadata.ts
21
+ var metadata_exports = {};
22
+ __export(metadata_exports, {
23
+ descriptor: () => descriptor
24
+ });
25
+ module.exports = __toCommonJS(metadata_exports);
26
+ var descriptor = {
27
+ id: "Trivy",
28
+ displayName: "Trivy",
29
+ preferredVersion: "0.69.3",
30
+ languages: [
31
+ "Python",
32
+ "JavaScript",
33
+ "TypeScript",
34
+ "Go",
35
+ "Java",
36
+ "Ruby",
37
+ "Rust",
38
+ "PHP",
39
+ "C#",
40
+ "Dart",
41
+ "Elixir",
42
+ "Swift"
43
+ ],
44
+ filePatterns: ["*"],
45
+ supportedOS: ["linux", "darwin"],
46
+ supportedArch: ["x64", "arm64"],
47
+ supportedRunners: ["local", "container"]
48
+ };
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ descriptor
52
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/tools-trivy-0",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Trivy adapter — CLI-mode security scanner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
- "@codacy/tooling": "0.4.0"
11
+ "@codacy/tooling": "0.5.0"
12
12
  },
13
13
  "license": "MIT",
14
14
  "author": "Codacy <support@codacy.com> (https://www.codacy.com)",
@@ -21,8 +21,18 @@
21
21
  "engines": {
22
22
  "node": ">=20.0.0"
23
23
  },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./metadata": {
30
+ "types": "./dist/metadata.d.ts",
31
+ "default": "./dist/metadata.js"
32
+ }
33
+ },
24
34
  "scripts": {
25
- "build": "tsup src/index.ts --format cjs --dts --clean",
35
+ "build": "tsup src/index.ts src/metadata.ts --format cjs --dts --clean",
26
36
  "test": "vitest run",
27
37
  "lint": "eslint src/",
28
38
  "clean": "rm -rf dist",