verimu 0.0.2 → 0.0.3
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/README.md +30 -10
- package/dist/index.cjs +675 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +340 -2
- package/dist/index.d.ts +340 -2
- package/dist/index.mjs +667 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -75,7 +75,8 @@ var PURL_TYPE_MAP = {
|
|
|
75
75
|
cargo: "cargo",
|
|
76
76
|
maven: "maven",
|
|
77
77
|
pip: "pypi",
|
|
78
|
-
go: "golang"
|
|
78
|
+
go: "golang",
|
|
79
|
+
ruby: "gem"
|
|
79
80
|
};
|
|
80
81
|
function buildPurl(name, version, ecosystem) {
|
|
81
82
|
const type = PURL_TYPE_MAP[ecosystem] || ecosystem;
|
|
@@ -110,7 +111,7 @@ var VerimuError = class extends Error {
|
|
|
110
111
|
var NoLockfileError = class extends VerimuError {
|
|
111
112
|
constructor(projectPath) {
|
|
112
113
|
super(
|
|
113
|
-
`No supported lockfile found in ${projectPath}. Supported: package-lock.json (npm), packages.lock.json (NuGet), Cargo.lock (Rust)`,
|
|
114
|
+
`No supported lockfile found in ${projectPath}. Supported: package-lock.json (npm), packages.lock.json (NuGet), Cargo.lock (Rust), requirements.txt / Pipfile.lock (Python), pom.xml (Maven), go.sum (Go), Gemfile.lock (Ruby)`,
|
|
114
115
|
"NO_LOCKFILE"
|
|
115
116
|
);
|
|
116
117
|
this.name = "NoLockfileError";
|
|
@@ -246,26 +247,670 @@ var NpmScanner = class {
|
|
|
246
247
|
};
|
|
247
248
|
|
|
248
249
|
// src/scanners/nuget/nuget-scanner.ts
|
|
250
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
251
|
+
import { existsSync as existsSync2 } from "fs";
|
|
252
|
+
import path2 from "path";
|
|
249
253
|
var NugetScanner = class {
|
|
250
254
|
ecosystem = "nuget";
|
|
251
255
|
lockfileNames = ["packages.lock.json"];
|
|
252
|
-
async detect(
|
|
253
|
-
|
|
256
|
+
async detect(projectPath) {
|
|
257
|
+
const lockfilePath = path2.join(projectPath, "packages.lock.json");
|
|
258
|
+
return existsSync2(lockfilePath) ? lockfilePath : null;
|
|
259
|
+
}
|
|
260
|
+
async scan(projectPath, lockfilePath) {
|
|
261
|
+
const lockfileRaw = await readFile2(lockfilePath, "utf-8");
|
|
262
|
+
let lockfile;
|
|
263
|
+
try {
|
|
264
|
+
lockfile = JSON.parse(lockfileRaw);
|
|
265
|
+
} catch {
|
|
266
|
+
throw new LockfileParseError(lockfilePath, "Invalid JSON");
|
|
267
|
+
}
|
|
268
|
+
if (!lockfile.dependencies) {
|
|
269
|
+
throw new LockfileParseError(lockfilePath, 'Missing "dependencies" field');
|
|
270
|
+
}
|
|
271
|
+
const dependencies = this.parseLockfile(lockfile);
|
|
272
|
+
return {
|
|
273
|
+
projectPath,
|
|
274
|
+
ecosystem: "nuget",
|
|
275
|
+
dependencies,
|
|
276
|
+
lockfilePath,
|
|
277
|
+
scannedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Parses packages.lock.json and extracts dependencies across all
|
|
282
|
+
* target frameworks. Deduplicates by package name (keeps highest version
|
|
283
|
+
* if the same package appears under multiple frameworks).
|
|
284
|
+
*/
|
|
285
|
+
parseLockfile(lockfile) {
|
|
286
|
+
const depMap = /* @__PURE__ */ new Map();
|
|
287
|
+
for (const [_framework, packages] of Object.entries(lockfile.dependencies)) {
|
|
288
|
+
for (const [name, info] of Object.entries(packages)) {
|
|
289
|
+
if (!info.resolved) continue;
|
|
290
|
+
const isDirect = info.type === "Direct";
|
|
291
|
+
const existing = depMap.get(name);
|
|
292
|
+
if (!existing) {
|
|
293
|
+
depMap.set(name, {
|
|
294
|
+
name,
|
|
295
|
+
version: info.resolved,
|
|
296
|
+
direct: isDirect,
|
|
297
|
+
ecosystem: "nuget",
|
|
298
|
+
purl: this.buildPurl(name, info.resolved)
|
|
299
|
+
});
|
|
300
|
+
} else if (isDirect && !existing.direct) {
|
|
301
|
+
existing.direct = true;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return Array.from(depMap.values());
|
|
254
306
|
}
|
|
255
|
-
|
|
256
|
-
|
|
307
|
+
/**
|
|
308
|
+
* Builds a purl for a NuGet package.
|
|
309
|
+
* NuGet purls are straightforward: pkg:nuget/Name@Version
|
|
310
|
+
*/
|
|
311
|
+
buildPurl(name, version) {
|
|
312
|
+
return `pkg:nuget/${name}@${version}`;
|
|
257
313
|
}
|
|
258
314
|
};
|
|
259
315
|
|
|
260
316
|
// src/scanners/cargo/cargo-scanner.ts
|
|
317
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
318
|
+
import { existsSync as existsSync3 } from "fs";
|
|
319
|
+
import path3 from "path";
|
|
261
320
|
var CargoScanner = class {
|
|
262
321
|
ecosystem = "cargo";
|
|
263
322
|
lockfileNames = ["Cargo.lock"];
|
|
264
|
-
async detect(
|
|
323
|
+
async detect(projectPath) {
|
|
324
|
+
const lockfilePath = path3.join(projectPath, "Cargo.lock");
|
|
325
|
+
return existsSync3(lockfilePath) ? lockfilePath : null;
|
|
326
|
+
}
|
|
327
|
+
async scan(projectPath, lockfilePath) {
|
|
328
|
+
const [lockfileRaw, cargoTomlRaw] = await Promise.all([
|
|
329
|
+
readFile3(lockfilePath, "utf-8"),
|
|
330
|
+
readFile3(path3.join(projectPath, "Cargo.toml"), "utf-8").catch(() => null)
|
|
331
|
+
]);
|
|
332
|
+
const packages = this.parseLockfile(lockfileRaw, lockfilePath);
|
|
333
|
+
const directNames = cargoTomlRaw ? this.parseCargoToml(cargoTomlRaw) : /* @__PURE__ */ new Set();
|
|
334
|
+
const rootName = packages.length > 0 ? packages[0].name : null;
|
|
335
|
+
const dependencies = [];
|
|
336
|
+
for (const pkg of packages) {
|
|
337
|
+
if (pkg.name === rootName && pkg.source === void 0) continue;
|
|
338
|
+
dependencies.push({
|
|
339
|
+
name: pkg.name,
|
|
340
|
+
version: pkg.version,
|
|
341
|
+
direct: directNames.has(pkg.name),
|
|
342
|
+
ecosystem: "cargo",
|
|
343
|
+
purl: this.buildPurl(pkg.name, pkg.version)
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
projectPath,
|
|
348
|
+
ecosystem: "cargo",
|
|
349
|
+
dependencies,
|
|
350
|
+
lockfilePath,
|
|
351
|
+
scannedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Parses Cargo.lock by splitting on [[package]] blocks.
|
|
356
|
+
* This is a lightweight parser that handles the regular structure
|
|
357
|
+
* of Cargo.lock without needing a full TOML parser.
|
|
358
|
+
*/
|
|
359
|
+
parseLockfile(content, lockfilePath) {
|
|
360
|
+
const packages = [];
|
|
361
|
+
const blocks = content.split(/^\[\[package\]\]$/m);
|
|
362
|
+
for (const block of blocks) {
|
|
363
|
+
if (!block.trim()) continue;
|
|
364
|
+
const name = this.extractField(block, "name");
|
|
365
|
+
const version = this.extractField(block, "version");
|
|
366
|
+
const source = this.extractField(block, "source");
|
|
367
|
+
if (name && version) {
|
|
368
|
+
packages.push({ name, version, source: source || void 0 });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (packages.length === 0 && content.includes("[[package]]")) {
|
|
372
|
+
throw new LockfileParseError(lockfilePath, "Failed to parse any packages from Cargo.lock");
|
|
373
|
+
}
|
|
374
|
+
return packages;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Extracts a string field value from a TOML block.
|
|
378
|
+
* Handles: `name = "value"` format.
|
|
379
|
+
*/
|
|
380
|
+
extractField(block, fieldName) {
|
|
381
|
+
const regex = new RegExp(`^${fieldName}\\s*=\\s*"([^"]*)"`, "m");
|
|
382
|
+
const match = block.match(regex);
|
|
383
|
+
return match ? match[1] : null;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Parses Cargo.toml to extract direct dependency names.
|
|
387
|
+
* Looks for [dependencies] and [dev-dependencies] sections.
|
|
388
|
+
*/
|
|
389
|
+
parseCargoToml(content) {
|
|
390
|
+
const directNames = /* @__PURE__ */ new Set();
|
|
391
|
+
let inDepsSection = false;
|
|
392
|
+
for (const rawLine of content.split("\n")) {
|
|
393
|
+
const line = rawLine.trim();
|
|
394
|
+
if (line.startsWith("[")) {
|
|
395
|
+
inDepsSection = line === "[dependencies]" || line === "[dev-dependencies]" || line === "[build-dependencies]";
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (inDepsSection && line && !line.startsWith("#")) {
|
|
399
|
+
const match = line.match(/^([a-zA-Z0-9_-]+)\s*=/);
|
|
400
|
+
if (match) {
|
|
401
|
+
directNames.add(match[1]);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return directNames;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Builds a purl for a Cargo (crates.io) package.
|
|
409
|
+
*/
|
|
410
|
+
buildPurl(name, version) {
|
|
411
|
+
return `pkg:cargo/${name}@${version}`;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// src/scanners/pip/pip-scanner.ts
|
|
416
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
417
|
+
import { existsSync as existsSync4 } from "fs";
|
|
418
|
+
import path4 from "path";
|
|
419
|
+
var PipScanner = class {
|
|
420
|
+
ecosystem = "pip";
|
|
421
|
+
lockfileNames = ["requirements.txt", "Pipfile.lock"];
|
|
422
|
+
async detect(projectPath) {
|
|
423
|
+
for (const lockfile of this.lockfileNames) {
|
|
424
|
+
const fullPath = path4.join(projectPath, lockfile);
|
|
425
|
+
if (existsSync4(fullPath)) return fullPath;
|
|
426
|
+
}
|
|
265
427
|
return null;
|
|
266
428
|
}
|
|
267
|
-
async scan(
|
|
268
|
-
|
|
429
|
+
async scan(projectPath, lockfilePath) {
|
|
430
|
+
const raw = await readFile4(lockfilePath, "utf-8");
|
|
431
|
+
const filename = path4.basename(lockfilePath);
|
|
432
|
+
let dependencies;
|
|
433
|
+
if (filename === "Pipfile.lock") {
|
|
434
|
+
dependencies = this.parsePipfileLock(raw, lockfilePath);
|
|
435
|
+
} else {
|
|
436
|
+
dependencies = this.parseRequirementsTxt(raw, lockfilePath);
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
projectPath,
|
|
440
|
+
ecosystem: "pip",
|
|
441
|
+
dependencies,
|
|
442
|
+
lockfilePath,
|
|
443
|
+
scannedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Parses `requirements.txt` format.
|
|
448
|
+
*
|
|
449
|
+
* Supports:
|
|
450
|
+
* - `package==1.2.3` (pinned)
|
|
451
|
+
* - `package>=1.2.0` (minimum — uses the specified version)
|
|
452
|
+
* - `package~=1.2.0` (compatible release)
|
|
453
|
+
* - Comments (`#`) and blank lines are skipped
|
|
454
|
+
* - `-r other-file.txt` (include directive) — skipped for now
|
|
455
|
+
* - `--index-url` and other pip flags — skipped
|
|
456
|
+
*/
|
|
457
|
+
parseRequirementsTxt(content, lockfilePath) {
|
|
458
|
+
const deps = [];
|
|
459
|
+
for (const rawLine of content.split("\n")) {
|
|
460
|
+
const line = rawLine.trim();
|
|
461
|
+
if (!line || line.startsWith("#") || line.startsWith("-") || line.startsWith("--")) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const match = line.match(/^([a-zA-Z0-9_][a-zA-Z0-9._-]*)\s*(?:[~=!<>]=?)\s*(.+)$/);
|
|
465
|
+
if (match) {
|
|
466
|
+
const [, name, versionSpec] = match;
|
|
467
|
+
const version = this.extractVersion(versionSpec);
|
|
468
|
+
if (name && version) {
|
|
469
|
+
deps.push({
|
|
470
|
+
name: this.normalizePipName(name),
|
|
471
|
+
version,
|
|
472
|
+
direct: true,
|
|
473
|
+
// requirements.txt doesn't distinguish
|
|
474
|
+
ecosystem: "pip",
|
|
475
|
+
purl: this.buildPurl(name, version)
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return deps;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Parses `Pipfile.lock` (JSON format from Pipenv).
|
|
484
|
+
*
|
|
485
|
+
* Structure:
|
|
486
|
+
* ```json
|
|
487
|
+
* {
|
|
488
|
+
* "_meta": { ... },
|
|
489
|
+
* "default": {
|
|
490
|
+
* "requests": { "version": "==2.31.0", ... }
|
|
491
|
+
* },
|
|
492
|
+
* "develop": {
|
|
493
|
+
* "pytest": { "version": "==7.4.0", ... }
|
|
494
|
+
* }
|
|
495
|
+
* }
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
parsePipfileLock(content, lockfilePath) {
|
|
499
|
+
let lockfile;
|
|
500
|
+
try {
|
|
501
|
+
lockfile = JSON.parse(content);
|
|
502
|
+
} catch {
|
|
503
|
+
throw new LockfileParseError(lockfilePath, "Invalid JSON in Pipfile.lock");
|
|
504
|
+
}
|
|
505
|
+
const deps = [];
|
|
506
|
+
if (lockfile.default) {
|
|
507
|
+
for (const [name, info] of Object.entries(lockfile.default)) {
|
|
508
|
+
const version = info.version?.replace(/^==/, "") ?? "";
|
|
509
|
+
if (version) {
|
|
510
|
+
deps.push({
|
|
511
|
+
name: this.normalizePipName(name),
|
|
512
|
+
version,
|
|
513
|
+
direct: true,
|
|
514
|
+
ecosystem: "pip",
|
|
515
|
+
purl: this.buildPurl(name, version)
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (lockfile.develop) {
|
|
521
|
+
for (const [name, info] of Object.entries(lockfile.develop)) {
|
|
522
|
+
const version = info.version?.replace(/^==/, "") ?? "";
|
|
523
|
+
if (version) {
|
|
524
|
+
deps.push({
|
|
525
|
+
name: this.normalizePipName(name),
|
|
526
|
+
version,
|
|
527
|
+
direct: true,
|
|
528
|
+
ecosystem: "pip",
|
|
529
|
+
purl: this.buildPurl(name, version)
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return deps;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Extracts the version number from a pip version specifier.
|
|
538
|
+
* "1.2.3" → "1.2.3"
|
|
539
|
+
* "1.2.3,<2.0" → "1.2.3"
|
|
540
|
+
*/
|
|
541
|
+
extractVersion(spec) {
|
|
542
|
+
const cleaned = spec.split(",")[0].trim();
|
|
543
|
+
return cleaned;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Normalizes a pip package name per PEP 503.
|
|
547
|
+
* Converts to lowercase and replaces any run of [-_.] with a single hyphen.
|
|
548
|
+
*/
|
|
549
|
+
normalizePipName(name) {
|
|
550
|
+
return name.toLowerCase().replace(/[-_.]+/g, "-");
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Builds a purl for a PyPI package.
|
|
554
|
+
* Per purl spec, the type is "pypi" (not "pip").
|
|
555
|
+
*/
|
|
556
|
+
buildPurl(name, version) {
|
|
557
|
+
return `pkg:pypi/${this.normalizePipName(name)}@${version}`;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
// src/scanners/maven/maven-scanner.ts
|
|
562
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
563
|
+
import { existsSync as existsSync5 } from "fs";
|
|
564
|
+
import { execSync } from "child_process";
|
|
565
|
+
import path5 from "path";
|
|
566
|
+
var MavenScanner = class {
|
|
567
|
+
ecosystem = "maven";
|
|
568
|
+
lockfileNames = ["pom.xml"];
|
|
569
|
+
/** Allow injection for testing */
|
|
570
|
+
execSyncFn;
|
|
571
|
+
constructor(execSyncImpl) {
|
|
572
|
+
this.execSyncFn = execSyncImpl ?? execSync;
|
|
573
|
+
}
|
|
574
|
+
async detect(projectPath) {
|
|
575
|
+
const pomPath = path5.join(projectPath, "pom.xml");
|
|
576
|
+
return existsSync5(pomPath) ? pomPath : null;
|
|
577
|
+
}
|
|
578
|
+
async scan(projectPath, _lockfilePath) {
|
|
579
|
+
const depTreePath = path5.join(projectPath, "dependency-tree.txt");
|
|
580
|
+
if (existsSync5(depTreePath)) {
|
|
581
|
+
const content = await readFile5(depTreePath, "utf-8");
|
|
582
|
+
const dependencies = this.parseDependencyList(content, depTreePath);
|
|
583
|
+
return this.buildResult(projectPath, depTreePath, dependencies);
|
|
584
|
+
}
|
|
585
|
+
if (this.isMavenAvailable()) {
|
|
586
|
+
const output = this.runMavenDependencyList(projectPath);
|
|
587
|
+
const dependencies = this.parseDependencyList(output, "mvn dependency:list");
|
|
588
|
+
return this.buildResult(projectPath, path5.join(projectPath, "pom.xml"), dependencies);
|
|
589
|
+
}
|
|
590
|
+
throw new LockfileParseError(
|
|
591
|
+
path5.join(projectPath, "pom.xml"),
|
|
592
|
+
"Maven project detected (pom.xml found) but could not resolve dependencies. Either install Maven (`mvn` must be on $PATH) or pre-generate a dependency list:\n mvn dependency:list -DoutputFile=dependency-tree.txt -DappendOutput=true"
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Parses Maven `dependency:list` output.
|
|
597
|
+
*
|
|
598
|
+
* Each dependency line has the format:
|
|
599
|
+
* groupId:artifactId:type:version:scope
|
|
600
|
+
* groupId:artifactId:type:classifier:version:scope
|
|
601
|
+
*
|
|
602
|
+
* Lines are typically indented with leading whitespace.
|
|
603
|
+
*/
|
|
604
|
+
parseDependencyList(content, source) {
|
|
605
|
+
const deps = [];
|
|
606
|
+
const depPattern = /^\s*([a-zA-Z0-9._-]+):([a-zA-Z0-9._-]+):([a-z]+):(?:([a-zA-Z0-9._-]+):)?([a-zA-Z0-9._-]+):([a-z]+)/;
|
|
607
|
+
for (const rawLine of content.split("\n")) {
|
|
608
|
+
const line = rawLine.trim();
|
|
609
|
+
if (!line) continue;
|
|
610
|
+
const match = line.match(depPattern);
|
|
611
|
+
if (match) {
|
|
612
|
+
const groupId = match[1];
|
|
613
|
+
const artifactId = match[2];
|
|
614
|
+
const version = match[4] && match[5] ? match[5] : match[4] ?? match[5];
|
|
615
|
+
const scope = match[4] && match[5] ? match[6] : match[5] && match[6] ? match[6] : match[5];
|
|
616
|
+
const parts = line.split(":");
|
|
617
|
+
if (parts.length >= 5) {
|
|
618
|
+
const gId = parts[0].trim();
|
|
619
|
+
const aId = parts[1];
|
|
620
|
+
const ver = parts.length === 6 ? parts[4] : parts[3];
|
|
621
|
+
const scp = parts.length === 6 ? parts[5] : parts[4];
|
|
622
|
+
if (gId && aId && ver) {
|
|
623
|
+
const name = `${gId}:${aId}`;
|
|
624
|
+
deps.push({
|
|
625
|
+
name,
|
|
626
|
+
version: ver,
|
|
627
|
+
direct: scp === "compile" || scp === "runtime" || scp === "provided",
|
|
628
|
+
ecosystem: "maven",
|
|
629
|
+
purl: this.buildPurl(gId, aId, ver)
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return deps;
|
|
636
|
+
}
|
|
637
|
+
/** Checks if `mvn` is available on PATH */
|
|
638
|
+
isMavenAvailable() {
|
|
639
|
+
try {
|
|
640
|
+
this.execSyncFn("mvn --version", { stdio: "pipe", timeout: 1e4 });
|
|
641
|
+
return true;
|
|
642
|
+
} catch {
|
|
643
|
+
return false;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Runs `mvn dependency:list` and returns the output.
|
|
648
|
+
*/
|
|
649
|
+
runMavenDependencyList(projectPath) {
|
|
650
|
+
try {
|
|
651
|
+
const output = this.execSyncFn(
|
|
652
|
+
"mvn dependency:list -DoutputType=text -DincludeScope=compile",
|
|
653
|
+
{
|
|
654
|
+
cwd: projectPath,
|
|
655
|
+
stdio: "pipe",
|
|
656
|
+
timeout: 12e4,
|
|
657
|
+
// 2 minute timeout
|
|
658
|
+
encoding: "utf-8"
|
|
659
|
+
}
|
|
660
|
+
);
|
|
661
|
+
return output.toString();
|
|
662
|
+
} catch (err) {
|
|
663
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
664
|
+
throw new LockfileParseError(
|
|
665
|
+
path5.join(projectPath, "pom.xml"),
|
|
666
|
+
`Failed to run 'mvn dependency:list': ${message}`
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Builds a purl for a Maven package.
|
|
672
|
+
* Format: pkg:maven/groupId/artifactId@version
|
|
673
|
+
*/
|
|
674
|
+
buildPurl(groupId, artifactId, version) {
|
|
675
|
+
return `pkg:maven/${groupId}/${artifactId}@${version}`;
|
|
676
|
+
}
|
|
677
|
+
buildResult(projectPath, lockfilePath, dependencies) {
|
|
678
|
+
return {
|
|
679
|
+
projectPath,
|
|
680
|
+
ecosystem: "maven",
|
|
681
|
+
dependencies,
|
|
682
|
+
lockfilePath,
|
|
683
|
+
scannedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
// src/scanners/go/go-scanner.ts
|
|
689
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
690
|
+
import { existsSync as existsSync6 } from "fs";
|
|
691
|
+
import path6 from "path";
|
|
692
|
+
var GoScanner = class {
|
|
693
|
+
ecosystem = "go";
|
|
694
|
+
lockfileNames = ["go.sum"];
|
|
695
|
+
async detect(projectPath) {
|
|
696
|
+
const goSumPath = path6.join(projectPath, "go.sum");
|
|
697
|
+
return existsSync6(goSumPath) ? goSumPath : null;
|
|
698
|
+
}
|
|
699
|
+
async scan(projectPath, lockfilePath) {
|
|
700
|
+
const [goSumRaw, goModRaw] = await Promise.all([
|
|
701
|
+
readFile6(lockfilePath, "utf-8"),
|
|
702
|
+
readFile6(path6.join(projectPath, "go.mod"), "utf-8").catch(() => null)
|
|
703
|
+
]);
|
|
704
|
+
const { directNames, indirectNames } = goModRaw ? this.parseGoMod(goModRaw) : { directNames: /* @__PURE__ */ new Set(), indirectNames: /* @__PURE__ */ new Set() };
|
|
705
|
+
const dependencies = this.parseGoSum(goSumRaw, lockfilePath, directNames, indirectNames);
|
|
706
|
+
return {
|
|
707
|
+
projectPath,
|
|
708
|
+
ecosystem: "go",
|
|
709
|
+
dependencies,
|
|
710
|
+
lockfilePath,
|
|
711
|
+
scannedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Parses go.sum and extracts unique module dependencies.
|
|
716
|
+
*
|
|
717
|
+
* Each module may appear twice in go.sum (once for the source archive,
|
|
718
|
+
* once for go.mod). We deduplicate by module path + version, keeping
|
|
719
|
+
* only the `h1:` entry (not the `/go.mod` entry).
|
|
720
|
+
*/
|
|
721
|
+
parseGoSum(content, lockfilePath, directNames, indirectNames) {
|
|
722
|
+
const depMap = /* @__PURE__ */ new Map();
|
|
723
|
+
for (const rawLine of content.split("\n")) {
|
|
724
|
+
const line = rawLine.trim();
|
|
725
|
+
if (!line) continue;
|
|
726
|
+
const parts = line.split(/\s+/);
|
|
727
|
+
if (parts.length < 3) continue;
|
|
728
|
+
const modulePath = parts[0];
|
|
729
|
+
let version = parts[1];
|
|
730
|
+
if (version.endsWith("/go.mod")) continue;
|
|
731
|
+
version = version.replace(/\+incompatible$/, "");
|
|
732
|
+
const key = `${modulePath}@${version}`;
|
|
733
|
+
if (depMap.has(key)) continue;
|
|
734
|
+
const isDirect = directNames.size > 0 || indirectNames.size > 0 ? directNames.has(modulePath) || (!indirectNames.has(modulePath) && !directNames.has(modulePath) ? false : directNames.has(modulePath)) : true;
|
|
735
|
+
depMap.set(key, {
|
|
736
|
+
name: modulePath,
|
|
737
|
+
version,
|
|
738
|
+
direct: isDirect,
|
|
739
|
+
ecosystem: "go",
|
|
740
|
+
purl: this.buildPurl(modulePath, version)
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
return Array.from(depMap.values());
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Parses go.mod to extract direct and indirect dependency names.
|
|
747
|
+
*
|
|
748
|
+
* Handles both single-line and block `require` directives:
|
|
749
|
+
* ```
|
|
750
|
+
* require github.com/pkg/errors v0.9.1
|
|
751
|
+
*
|
|
752
|
+
* require (
|
|
753
|
+
* github.com/gin-gonic/gin v1.9.1
|
|
754
|
+
* golang.org/x/text v0.14.0 // indirect
|
|
755
|
+
* )
|
|
756
|
+
* ```
|
|
757
|
+
*/
|
|
758
|
+
parseGoMod(content) {
|
|
759
|
+
const directNames = /* @__PURE__ */ new Set();
|
|
760
|
+
const indirectNames = /* @__PURE__ */ new Set();
|
|
761
|
+
let inRequireBlock = false;
|
|
762
|
+
for (const rawLine of content.split("\n")) {
|
|
763
|
+
const line = rawLine.trim();
|
|
764
|
+
if (line.startsWith("require ") && !line.includes("(")) {
|
|
765
|
+
const match = line.match(/^require\s+(\S+)\s+\S+(.*)$/);
|
|
766
|
+
if (match) {
|
|
767
|
+
const modulePath = match[1];
|
|
768
|
+
const rest = match[2];
|
|
769
|
+
if (rest.includes("// indirect")) {
|
|
770
|
+
indirectNames.add(modulePath);
|
|
771
|
+
} else {
|
|
772
|
+
directNames.add(modulePath);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
if (line === "require (" || line.startsWith("require (")) {
|
|
778
|
+
inRequireBlock = true;
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
if (inRequireBlock && line === ")") {
|
|
782
|
+
inRequireBlock = false;
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
if (inRequireBlock && line && !line.startsWith("//")) {
|
|
786
|
+
const match = line.match(/^(\S+)\s+\S+(.*)$/);
|
|
787
|
+
if (match) {
|
|
788
|
+
const modulePath = match[1];
|
|
789
|
+
const rest = match[2];
|
|
790
|
+
if (rest.includes("// indirect")) {
|
|
791
|
+
indirectNames.add(modulePath);
|
|
792
|
+
} else {
|
|
793
|
+
directNames.add(modulePath);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
return { directNames, indirectNames };
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Builds a purl for a Go module.
|
|
802
|
+
*
|
|
803
|
+
* Per purl spec, the type is "golang" and the module path
|
|
804
|
+
* uses `/` separators (no encoding needed for path segments).
|
|
805
|
+
*
|
|
806
|
+
* Example: `pkg:golang/github.com/gin-gonic/gin@v1.9.1`
|
|
807
|
+
*/
|
|
808
|
+
buildPurl(modulePath, version) {
|
|
809
|
+
return `pkg:golang/${modulePath}@${version}`;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
// src/scanners/ruby/ruby-scanner.ts
|
|
814
|
+
import { readFile as readFile7 } from "fs/promises";
|
|
815
|
+
import { existsSync as existsSync7 } from "fs";
|
|
816
|
+
import path7 from "path";
|
|
817
|
+
var RubyScanner = class {
|
|
818
|
+
ecosystem = "ruby";
|
|
819
|
+
lockfileNames = ["Gemfile.lock"];
|
|
820
|
+
async detect(projectPath) {
|
|
821
|
+
const lockfilePath = path7.join(projectPath, "Gemfile.lock");
|
|
822
|
+
return existsSync7(lockfilePath) ? lockfilePath : null;
|
|
823
|
+
}
|
|
824
|
+
async scan(projectPath, lockfilePath) {
|
|
825
|
+
const content = await readFile7(lockfilePath, "utf-8");
|
|
826
|
+
const specs = this.parseSpecs(content, lockfilePath);
|
|
827
|
+
const directNames = this.parseDependencies(content);
|
|
828
|
+
const dependencies = specs.map(({ name, version }) => ({
|
|
829
|
+
name,
|
|
830
|
+
version,
|
|
831
|
+
direct: directNames.has(name),
|
|
832
|
+
ecosystem: "ruby",
|
|
833
|
+
purl: `pkg:gem/${name}@${version}`
|
|
834
|
+
}));
|
|
835
|
+
return {
|
|
836
|
+
projectPath,
|
|
837
|
+
ecosystem: "ruby",
|
|
838
|
+
dependencies,
|
|
839
|
+
lockfilePath,
|
|
840
|
+
scannedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Parses the GEM > specs section to extract all resolved gems.
|
|
845
|
+
*
|
|
846
|
+
* Gems at the top level of the specs section (indented 4 spaces) are
|
|
847
|
+
* resolved packages. Their sub-dependencies (indented 6+ spaces) are
|
|
848
|
+
* constraints, not separate entries — those sub-deps appear as their
|
|
849
|
+
* own top-level spec entries elsewhere.
|
|
850
|
+
*
|
|
851
|
+
* Format: ` gem-name (1.2.3)`
|
|
852
|
+
*/
|
|
853
|
+
parseSpecs(content, lockfilePath) {
|
|
854
|
+
const gems = [];
|
|
855
|
+
let inGemSection = false;
|
|
856
|
+
let inSpecs = false;
|
|
857
|
+
for (const rawLine of content.split("\n")) {
|
|
858
|
+
const line = rawLine;
|
|
859
|
+
if (line.length > 0 && line[0] !== " ") {
|
|
860
|
+
if (line.startsWith("GEM")) {
|
|
861
|
+
inGemSection = true;
|
|
862
|
+
inSpecs = false;
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
inGemSection = false;
|
|
866
|
+
inSpecs = false;
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
if (inGemSection && line.trimStart().startsWith("specs:")) {
|
|
870
|
+
inSpecs = true;
|
|
871
|
+
continue;
|
|
872
|
+
}
|
|
873
|
+
if (!inSpecs) continue;
|
|
874
|
+
const match = line.match(/^ {4}(\S+)\s+\(([^)]+)\)$/);
|
|
875
|
+
if (match) {
|
|
876
|
+
const [, name, version] = match;
|
|
877
|
+
gems.push({ name, version });
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (gems.length === 0) {
|
|
881
|
+
throw new LockfileParseError(
|
|
882
|
+
lockfilePath,
|
|
883
|
+
"No gems found in GEM specs section"
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
return gems;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Parses the DEPENDENCIES section to get direct dependency names.
|
|
890
|
+
*
|
|
891
|
+
* Format: ` gem-name (>= 1.0)` or ` gem-name`
|
|
892
|
+
* The version constraint is optional and we only need the name.
|
|
893
|
+
*/
|
|
894
|
+
parseDependencies(content) {
|
|
895
|
+
const directNames = /* @__PURE__ */ new Set();
|
|
896
|
+
let inDependencies = false;
|
|
897
|
+
for (const rawLine of content.split("\n")) {
|
|
898
|
+
const line = rawLine;
|
|
899
|
+
if (line.length > 0 && line[0] !== " ") {
|
|
900
|
+
if (line.startsWith("DEPENDENCIES")) {
|
|
901
|
+
inDependencies = true;
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (inDependencies) break;
|
|
905
|
+
continue;
|
|
906
|
+
}
|
|
907
|
+
if (!inDependencies) continue;
|
|
908
|
+
const match = line.match(/^ {2}(\S+?)!?\s*(?:\(|$)/);
|
|
909
|
+
if (match) {
|
|
910
|
+
directNames.add(match[1]);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
return directNames;
|
|
269
914
|
}
|
|
270
915
|
};
|
|
271
916
|
|
|
@@ -276,8 +921,11 @@ var ScannerRegistry = class {
|
|
|
276
921
|
this.scanners = [
|
|
277
922
|
new NpmScanner(),
|
|
278
923
|
new NugetScanner(),
|
|
279
|
-
new CargoScanner()
|
|
280
|
-
|
|
924
|
+
new CargoScanner(),
|
|
925
|
+
new PipScanner(),
|
|
926
|
+
new MavenScanner(),
|
|
927
|
+
new GoScanner(),
|
|
928
|
+
new RubyScanner()
|
|
281
929
|
];
|
|
282
930
|
}
|
|
283
931
|
/**
|
|
@@ -572,7 +1220,8 @@ var OsvSource = class {
|
|
|
572
1220
|
cargo: "crates.io",
|
|
573
1221
|
maven: "Maven",
|
|
574
1222
|
pip: "PyPI",
|
|
575
|
-
go: "Go"
|
|
1223
|
+
go: "Go",
|
|
1224
|
+
ruby: "RubyGems"
|
|
576
1225
|
};
|
|
577
1226
|
return map[ecosystem] ?? ecosystem;
|
|
578
1227
|
}
|
|
@@ -802,14 +1451,20 @@ function printReport(report) {
|
|
|
802
1451
|
}
|
|
803
1452
|
export {
|
|
804
1453
|
ApiKeyRequiredError,
|
|
1454
|
+
CargoScanner,
|
|
805
1455
|
ConsoleReporter,
|
|
806
1456
|
CveAggregator,
|
|
807
1457
|
CveSourceError,
|
|
808
1458
|
CycloneDxGenerator,
|
|
1459
|
+
GoScanner,
|
|
809
1460
|
LockfileParseError,
|
|
1461
|
+
MavenScanner,
|
|
810
1462
|
NoLockfileError,
|
|
811
1463
|
NpmScanner,
|
|
1464
|
+
NugetScanner,
|
|
812
1465
|
OsvSource,
|
|
1466
|
+
PipScanner,
|
|
1467
|
+
RubyScanner,
|
|
813
1468
|
ScannerRegistry,
|
|
814
1469
|
VerimuError,
|
|
815
1470
|
generateSbom,
|