cve-lite-cli 1.24.0 → 1.25.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.
Files changed (55) hide show
  1. package/README.md +56 -0
  2. package/dist/audit-log/events.js +3 -0
  3. package/dist/audit-log/handle.js +20 -0
  4. package/dist/audit-log/index.js +16 -0
  5. package/dist/audit-log/ndjson-writer.js +28 -0
  6. package/dist/cli/args.js +71 -0
  7. package/dist/cli/fix-overrides-hook.js +64 -0
  8. package/dist/cli/help.js +22 -0
  9. package/dist/cli/overrides.js +67 -0
  10. package/dist/index.js +270 -12
  11. package/dist/osv/cache.js +23 -3
  12. package/dist/output/formatters.js +23 -4
  13. package/dist/output/html-reporter.js +34 -4
  14. package/dist/output/override-findings-html.js +57 -0
  15. package/dist/output/override-findings-json.js +3 -0
  16. package/dist/output/override-findings-sarif.js +52 -0
  17. package/dist/output/override-findings-terminal.js +37 -0
  18. package/dist/output/printers.js +25 -8
  19. package/dist/output/sarif.js +77 -8
  20. package/dist/output/write-outputs.js +7 -3
  21. package/dist/overrides/api.js +79 -0
  22. package/dist/overrides/composite.js +23 -0
  23. package/dist/overrides/context-builder.js +150 -0
  24. package/dist/overrides/context.js +3 -0
  25. package/dist/overrides/detectors/index.js +23 -0
  26. package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
  27. package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
  28. package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
  29. package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
  30. package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
  31. package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
  32. package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
  33. package/dist/overrides/detectors/oa008-materialized.js +75 -0
  34. package/dist/overrides/detectors/platform-binary.js +37 -0
  35. package/dist/overrides/fixer.js +199 -0
  36. package/dist/overrides/index.js +5 -0
  37. package/dist/overrides/parsing/installed-tree.js +164 -0
  38. package/dist/overrides/parsing/json-pointer.js +8 -0
  39. package/dist/overrides/parsing/node-modules.js +19 -0
  40. package/dist/overrides/parsing/package-json.js +139 -0
  41. package/dist/overrides/parsing/registry.js +66 -0
  42. package/dist/overrides/types.js +2 -0
  43. package/dist/parsers/yarn-lock.js +2 -2
  44. package/dist/remediation/fix-commands.js +59 -5
  45. package/dist/remediation/npm-registry.js +30 -0
  46. package/dist/remediation/npm-transitive-resolution.js +2 -2
  47. package/dist/remediation/transitive-chain-resolver.js +100 -0
  48. package/dist/scan/multi-folder-scan.js +26 -0
  49. package/dist/scanner.js +61 -5
  50. package/dist/types.js +13 -1
  51. package/dist/utils/baseline.js +16 -0
  52. package/dist/utils/create-pr.js +19 -4
  53. package/dist/utils/string.js +34 -0
  54. package/dist/utils/version.js +115 -0
  55. package/package.json +3 -1
@@ -1,3 +1,37 @@
1
1
  export function pluralize(count, singular, plural = `${singular}s`) {
2
2
  return count === 1 ? singular : plural;
3
3
  }
4
+ /** Known top-level cve-lite commands, for typo suggestions on a mistyped first argument. */
5
+ const KNOWN_COMMANDS = ["advisories", "install-skill", "config", "overrides"];
6
+ /**
7
+ * Suggest the nearest known command for a mistyped first argument. Returns
8
+ * undefined when nothing is within edit distance 2 (e.g. a real typo'd path
9
+ * rather than a typo'd command).
10
+ */
11
+ export function nearestCommand(arg) {
12
+ let best;
13
+ let bestDist = 3;
14
+ for (const c of KNOWN_COMMANDS) {
15
+ const d = levenshtein(arg.toLowerCase(), c);
16
+ if (d < bestDist) {
17
+ bestDist = d;
18
+ best = c;
19
+ }
20
+ }
21
+ return best;
22
+ }
23
+ export function levenshtein(a, b) {
24
+ const m = a.length;
25
+ const n = b.length;
26
+ const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
27
+ for (let i = 0; i <= m; i++)
28
+ dp[i][0] = i;
29
+ for (let j = 0; j <= n; j++)
30
+ dp[0][j] = j;
31
+ for (let i = 1; i <= m; i++) {
32
+ for (let j = 1; j <= n; j++) {
33
+ dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
34
+ }
35
+ }
36
+ return dp[m][n];
37
+ }
@@ -45,3 +45,118 @@ export function normalizeRawVersion(value) {
45
45
  return cleaned;
46
46
  return null;
47
47
  }
48
+ /**
49
+ * Extract the leading integer (major) from a version string. Returns null
50
+ * if the string does not start with a digit-only run.
51
+ */
52
+ export function majorVersion(value) {
53
+ if (!value)
54
+ return null;
55
+ const m = value.match(/^(\d+)/);
56
+ if (!m)
57
+ return null;
58
+ return Number(m[1]);
59
+ }
60
+ /**
61
+ * Coerce a partial or range-prefixed version into a concrete X.Y.Z form.
62
+ * Strips leading range operators (`^`, `~`, `>=`, `<=`, `>`, `<`, `=`), pads
63
+ * missing minor/patch with zeros. Returns null if the input cannot be
64
+ * interpreted as a version.
65
+ *
66
+ * Examples:
67
+ * "1" -> "1.0.0"
68
+ * "1.2" -> "1.2.0"
69
+ * "^1.2.3" -> "1.2.3"
70
+ * ">=2.0" -> "2.0.0"
71
+ * "latest" -> null
72
+ */
73
+ export function coerceVersion(input) {
74
+ if (!input)
75
+ return null;
76
+ const stripped = input.trim().replace(/^[\^~]|^[<>]=?|^=/, "").trim();
77
+ const m = stripped.match(/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+][^\s]+)?/);
78
+ if (!m)
79
+ return null;
80
+ const [, major, minor = "0", patch = "0"] = m;
81
+ return `${major}.${minor}.${patch}`;
82
+ }
83
+ /**
84
+ * Does the string parse as a version range cve-lite recognises?
85
+ * Supports plain versions and the operators `^`, `~`, `>=`, `<=`, `>`, `<`, `=`.
86
+ * Does not support OR (`||`) or hyphen ranges (`1.0.0 - 2.0.0`) - if those
87
+ * surface in real projects, extend later.
88
+ */
89
+ export function isValidRange(input) {
90
+ if (!input)
91
+ return false;
92
+ const trimmed = input.trim();
93
+ if (!/^(?:\^|~|>=|<=|>|<|=)?\s*\d+(?:\.\d+)?(?:\.\d+)?(?:[-+][^\s]+)?$/.test(trimmed)) {
94
+ return false;
95
+ }
96
+ return coerceVersion(trimmed) !== null;
97
+ }
98
+ /**
99
+ * Does `version` satisfy `range`? Minimal subset of semver semantics covering
100
+ * what the OA detectors need: exact, `^`, `~`, `>=`, `<=`, `>`, `<`, `=`.
101
+ *
102
+ * Pre-releases follow semver convention: a pre-release version (e.g.
103
+ * "1.2.3-beta") satisfies a range only if the range explicitly mentions a
104
+ * pre-release component at the same major.minor.patch boundary.
105
+ */
106
+ export function satisfiesRange(version, range) {
107
+ const v = coerceVersion(version);
108
+ if (!v)
109
+ return false;
110
+ const trimmedRange = range.trim();
111
+ // Exact match (no operator)
112
+ if (/^\d/.test(trimmedRange)) {
113
+ return compareVersions(v, coerceVersion(trimmedRange) ?? "") === 0;
114
+ }
115
+ // `=` operator
116
+ if (trimmedRange.startsWith("=")) {
117
+ const target = coerceVersion(trimmedRange.slice(1));
118
+ return target !== null && compareVersions(v, target) === 0;
119
+ }
120
+ // `^` caret: same major, >= specified, < next major
121
+ if (trimmedRange.startsWith("^")) {
122
+ const target = coerceVersion(trimmedRange.slice(1));
123
+ if (!target)
124
+ return false;
125
+ if (compareVersions(v, target) < 0)
126
+ return false;
127
+ const tMajor = majorVersion(target);
128
+ const vMajor = majorVersion(v);
129
+ if (tMajor === null || vMajor === null)
130
+ return false;
131
+ return vMajor === tMajor;
132
+ }
133
+ // `~` tilde: same major.minor, >= specified
134
+ if (trimmedRange.startsWith("~")) {
135
+ const target = coerceVersion(trimmedRange.slice(1));
136
+ if (!target)
137
+ return false;
138
+ if (compareVersions(v, target) < 0)
139
+ return false;
140
+ const [vMaj, vMin] = v.split(".").map(Number);
141
+ const [tMaj, tMin] = target.split(".").map(Number);
142
+ return vMaj === tMaj && vMin === tMin;
143
+ }
144
+ // Comparators
145
+ for (const op of [">=", "<=", ">", "<"]) {
146
+ if (trimmedRange.startsWith(op)) {
147
+ const target = coerceVersion(trimmedRange.slice(op.length));
148
+ if (!target)
149
+ return false;
150
+ const cmp = compareVersions(v, target);
151
+ if (op === ">=")
152
+ return cmp >= 0;
153
+ if (op === "<=")
154
+ return cmp <= 0;
155
+ if (op === ">")
156
+ return cmp > 0;
157
+ if (op === "<")
158
+ return cmp < 0;
159
+ }
160
+ }
161
+ return false;
162
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.24.0",
3
+ "version": "1.25.0",
4
4
  "description": "Developer-friendly CLI for scanning JS/TS projects for dependency vulnerabilities using local lockfiles and OSV",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,6 +10,8 @@
10
10
  "build": "tsc -p tsconfig.json",
11
11
  "dev": "tsx src/index.ts .",
12
12
  "start": "node dist/index.js .",
13
+ "lint:tests": "node scripts/check-test-hygiene.mjs",
14
+ "pretest": "node scripts/check-test-hygiene.mjs",
13
15
  "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --passWithNoTests",
14
16
  "test:watch": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch --passWithNoTests"
15
17
  },