@codacy/tools-trivy-0 0.4.0 → 0.6.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
@@ -48,6 +48,28 @@ var patterns_default = [
48
48
  severityLevel: "Error",
49
49
  title: "Detect Malicious Packages",
50
50
  enabled: true,
51
+ languages: [
52
+ "Dart",
53
+ "XML",
54
+ "TypeScript",
55
+ "Python",
56
+ "Javascript",
57
+ "Elixir",
58
+ "PHP",
59
+ "C",
60
+ "CSharp",
61
+ "Swift",
62
+ "CPP",
63
+ "Scala",
64
+ "JSON",
65
+ "Rust",
66
+ "Ruby",
67
+ "Terraform",
68
+ "Go",
69
+ "Java",
70
+ "Dockerfile",
71
+ "YAML"
72
+ ],
51
73
  parameters: []
52
74
  },
53
75
  {
@@ -56,6 +78,28 @@ var patterns_default = [
56
78
  severityLevel: "Error",
57
79
  title: "Detect Secret Exposure",
58
80
  enabled: true,
81
+ languages: [
82
+ "Dart",
83
+ "XML",
84
+ "TypeScript",
85
+ "Python",
86
+ "Javascript",
87
+ "Elixir",
88
+ "PHP",
89
+ "C",
90
+ "CSharp",
91
+ "Swift",
92
+ "CPP",
93
+ "Scala",
94
+ "JSON",
95
+ "Rust",
96
+ "Ruby",
97
+ "Terraform",
98
+ "Go",
99
+ "Java",
100
+ "Dockerfile",
101
+ "YAML"
102
+ ],
59
103
  parameters: []
60
104
  },
61
105
  {
@@ -64,6 +108,28 @@ var patterns_default = [
64
108
  severityLevel: "Error",
65
109
  title: "Detect Insecure Dependencies (Critical Severity)",
66
110
  enabled: true,
111
+ languages: [
112
+ "Dart",
113
+ "XML",
114
+ "TypeScript",
115
+ "Python",
116
+ "Javascript",
117
+ "Elixir",
118
+ "PHP",
119
+ "C",
120
+ "CSharp",
121
+ "Swift",
122
+ "CPP",
123
+ "Scala",
124
+ "JSON",
125
+ "Rust",
126
+ "Ruby",
127
+ "Terraform",
128
+ "Go",
129
+ "Java",
130
+ "Dockerfile",
131
+ "YAML"
132
+ ],
67
133
  parameters: []
68
134
  },
69
135
  {
@@ -72,6 +138,28 @@ var patterns_default = [
72
138
  severityLevel: "High",
73
139
  title: "Detect Insecure Dependencies (High Severity)",
74
140
  enabled: true,
141
+ languages: [
142
+ "Dart",
143
+ "XML",
144
+ "TypeScript",
145
+ "Python",
146
+ "Javascript",
147
+ "Elixir",
148
+ "PHP",
149
+ "C",
150
+ "CSharp",
151
+ "Swift",
152
+ "CPP",
153
+ "Scala",
154
+ "JSON",
155
+ "Rust",
156
+ "Ruby",
157
+ "Terraform",
158
+ "Go",
159
+ "Java",
160
+ "Dockerfile",
161
+ "YAML"
162
+ ],
75
163
  parameters: []
76
164
  },
77
165
  {
@@ -80,6 +168,28 @@ var patterns_default = [
80
168
  severityLevel: "Warning",
81
169
  title: "Detect Insecure Dependencies (Medium Severity)",
82
170
  enabled: true,
171
+ languages: [
172
+ "Dart",
173
+ "XML",
174
+ "TypeScript",
175
+ "Python",
176
+ "Javascript",
177
+ "Elixir",
178
+ "PHP",
179
+ "C",
180
+ "CSharp",
181
+ "Swift",
182
+ "CPP",
183
+ "Scala",
184
+ "JSON",
185
+ "Rust",
186
+ "Ruby",
187
+ "Terraform",
188
+ "Go",
189
+ "Java",
190
+ "Dockerfile",
191
+ "YAML"
192
+ ],
83
193
  parameters: []
84
194
  },
85
195
  {
@@ -88,23 +198,59 @@ var patterns_default = [
88
198
  severityLevel: "Info",
89
199
  title: "Detect Insecure Dependencies (Minor Severity)",
90
200
  enabled: true,
201
+ languages: [
202
+ "Dart",
203
+ "XML",
204
+ "TypeScript",
205
+ "Python",
206
+ "Javascript",
207
+ "Elixir",
208
+ "PHP",
209
+ "C",
210
+ "CSharp",
211
+ "Swift",
212
+ "CPP",
213
+ "Scala",
214
+ "JSON",
215
+ "Rust",
216
+ "Ruby",
217
+ "Terraform",
218
+ "Go",
219
+ "Java",
220
+ "Dockerfile",
221
+ "YAML"
222
+ ],
91
223
  parameters: []
92
224
  }
93
225
  ];
94
226
 
227
+ // src/metadata.ts
228
+ var descriptor = {
229
+ id: "Trivy",
230
+ displayName: "Trivy",
231
+ preferredVersion: "0.69.3",
232
+ languages: [
233
+ "Python",
234
+ "JavaScript",
235
+ "TypeScript",
236
+ "Go",
237
+ "Java",
238
+ "Ruby",
239
+ "Rust",
240
+ "PHP",
241
+ "C#",
242
+ "Dart",
243
+ "Elixir",
244
+ "Swift"
245
+ ],
246
+ filePatterns: ["*"],
247
+ supportedOS: ["linux", "darwin"],
248
+ supportedArch: ["x64", "arm64"],
249
+ supportedRunners: ["local", "container"]
250
+ };
251
+
95
252
  // src/adapter.ts
96
253
  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
254
  var PATTERN_META = new Map(
109
255
  patterns_default.map((p) => [
110
256
  p.id,
@@ -197,26 +343,6 @@ async function resolveBinaryPath(ctx) {
197
343
  if (version) return codacyBin;
198
344
  return BINARY;
199
345
  }
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
346
  async function ensureCacheDir(globalDir) {
221
347
  const cacheDir = import_path.default.join(globalDir, "cache", "trivy");
222
348
  await import_promises.default.mkdir(cacheDir, { recursive: true });
@@ -277,7 +403,7 @@ async function parseVulnerabilities(output, enabledPatterns, targetFilesSet, rep
277
403
  const relPath = result.Target;
278
404
  if (targetFilesSet.size > 0 && !targetFilesSet.has(relPath)) continue;
279
405
  if (!linesCache.has(relPath)) {
280
- linesCache.set(relPath, await readFileLines(import_path.default.join(repositoryRoot, relPath)));
406
+ linesCache.set(relPath, await (0, import_tooling.readFileLines)(import_path.default.join(repositoryRoot, relPath)));
281
407
  }
282
408
  const lines = linesCache.get(relPath);
283
409
  const pkgLineByID = /* @__PURE__ */ new Map();
@@ -306,7 +432,7 @@ async function parseVulnerabilities(output, enabledPatterns, targetFilesSet, rep
306
432
  line,
307
433
  column: 1,
308
434
  message: `Insecure dependency ${vuln.PkgName}@${vuln.InstalledVersion} (${vuln.VulnerabilityID}${title}). ${fix}`,
309
- lineContent: getLineContent(lines, line),
435
+ lineContent: (0, import_tooling.getLineContent)(lines, line),
310
436
  category: meta.category,
311
437
  severity: meta.severity
312
438
  });
@@ -329,7 +455,7 @@ async function parseSecrets(output, enabledPatterns, targetFilesSet, repositoryR
329
455
  const relPath = result.Target;
330
456
  if (targetFilesSet.size > 0 && !targetFilesSet.has(relPath)) continue;
331
457
  if (!linesCache.has(relPath)) {
332
- linesCache.set(relPath, await readFileLines(import_path.default.join(repositoryRoot, relPath)));
458
+ linesCache.set(relPath, await (0, import_tooling.readFileLines)(import_path.default.join(repositoryRoot, relPath)));
333
459
  }
334
460
  const lines = linesCache.get(relPath);
335
461
  for (const secret of result.Secrets) {
@@ -341,7 +467,7 @@ async function parseSecrets(output, enabledPatterns, targetFilesSet, repositoryR
341
467
  column: 1,
342
468
  endLine: secret.EndLine,
343
469
  message: `Possible hardcoded secret: ${secret.Title} (${secret.Category})`,
344
- lineContent: getLineContent(lines, secret.StartLine),
470
+ lineContent: (0, import_tooling.getLineContent)(lines, secret.StartLine),
345
471
  multilineContent: (0, import_tooling.getMultilineContent)(lines, secret.StartLine, secret.EndLine),
346
472
  category: meta.category,
347
473
  severity: meta.severity
@@ -426,7 +552,7 @@ async function parseMaliciousPackages(output, enabledPatterns, targetFilesSet, r
426
552
  const malVulns = maliciousByPkg.get(queryKey);
427
553
  if (!malVulns) continue;
428
554
  if (!linesCache.has(pkg.filePath)) {
429
- linesCache.set(pkg.filePath, await readFileLines(import_path.default.join(repositoryRoot, pkg.filePath)));
555
+ linesCache.set(pkg.filePath, await (0, import_tooling.readFileLines)(import_path.default.join(repositoryRoot, pkg.filePath)));
430
556
  }
431
557
  const lines = linesCache.get(pkg.filePath);
432
558
  for (const vuln of malVulns) {
@@ -438,7 +564,7 @@ async function parseMaliciousPackages(output, enabledPatterns, targetFilesSet, r
438
564
  line: pkg.line,
439
565
  column: 1,
440
566
  message: `Malicious package detected: ${pkg.name}@${pkg.version} (${vuln.id}).${summary}`,
441
- lineContent: getLineContent(lines, pkg.line),
567
+ lineContent: (0, import_tooling.getLineContent)(lines, pkg.line),
442
568
  category: meta.category,
443
569
  severity: meta.severity
444
570
  });
@@ -448,29 +574,9 @@ async function parseMaliciousPackages(output, enabledPatterns, targetFilesSet, r
448
574
  return { issues, errors };
449
575
  }
450
576
  var adapter = {
451
- id: TOOL_ID,
452
- displayName: "Trivy",
453
- preferredVersion: "0.69.3",
577
+ ...descriptor,
454
578
  compatibleVersions: ">=0.50.0",
455
579
  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
580
  prerequisites: [],
475
581
  /**
476
582
  * Checks whether the `trivy` binary is present and runnable.
@@ -607,13 +713,7 @@ var adapter = {
607
713
  const issues = [];
608
714
  const errors = [];
609
715
  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);
716
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
617
717
  }
618
718
  const binary = await resolveBinaryPath(ctx);
619
719
  let cacheDir;
@@ -627,7 +727,7 @@ var adapter = {
627
727
  message: `Failed to create cache directory: ${err instanceof Error ? err.message : String(err)}`,
628
728
  level: "error"
629
729
  });
630
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
730
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
631
731
  }
632
732
  const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
633
733
  const targetFilesSet = new Set(ctx.targetFiles);
@@ -727,7 +827,14 @@ var adapter = {
727
827
  level: "error"
728
828
  });
729
829
  }
730
- const result = buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
830
+ const result = (0, import_tooling.buildResult)(
831
+ TOOL_ID,
832
+ startedAt,
833
+ /* @__PURE__ */ new Date(),
834
+ issues,
835
+ errors,
836
+ ctx.targetFiles.length
837
+ );
731
838
  ctx.logger.info("Analysis complete", {
732
839
  toolId: TOOL_ID,
733
840
  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.6.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.6.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",