Skip to content

docs: fix broken programmatic usage example in README#11

Open
dmchaledev wants to merge 1 commit into
mainfrom
claude/magical-ptolemy-2nu415
Open

docs: fix broken programmatic usage example in README#11
dmchaledev wants to merge 1 commit into
mainfrom
claude/magical-ptolemy-2nu415

Conversation

@dmchaledev

Copy link
Copy Markdown
Contributor

Problem

The Programmatic usage example in the README documents an API that does not exist and will not run if copy-pasted. As the primary programmatic example on a published npm package, this is a high-friction first impression for adopters.

The current example:

import { diff } from '@hailbytes/sbom-diff';

const report = await diff('old.cdx.json', 'new.cdx.json');
// ...
console.log(report.upgraded); // { from: Component, to: Component }[]

Three things are wrong:

  1. diff does not take file paths. The real signature is diff(a: SBOM, b: SBOM): ChangeReport — it takes two parsed SBOM objects. Passing path strings makes TypeScript error and crashes at runtime (it tries to read .components off a string).
  2. diff is not async. await diff(...) is misleading — it returns a ChangeReport synchronously.
  3. report.upgraded is mis-typed in the comment. It is VersionChange[] ({ component, from, to, isMajorBump }), where from/to are version strings, not Components.

Fix

Rewrite the example to use the real exported API — parse + diff + renderReport — mirroring the JSDoc example already in src/index.ts. Also document the actual report fields, including fixedCVEs, and show rendering output.

import { readFile } from 'node:fs/promises';
import { parse, diff, renderReport } from '@hailbytes/sbom-diff';

const oldSBOM = parse(await readFile('old.cdx.json', 'utf-8'));
const newSBOM = parse(await readFile('new.cdx.json', 'utf-8'));

const report = diff(oldSBOM, newSBOM);
console.log(renderReport(report, 'markdown'));

Docs-only change — no source or test changes. Tests (20) and build remain green.

https://claude.ai/code/session_019aMbKwZ3ZJMRJPgTfVFUNi


Generated by Claude Code

The Programmatic section documented an API that does not exist:
- diff() was shown taking file paths and being awaited, but the real
  diff(a: SBOM, b: SBOM) is synchronous and takes two parsed SBOMs.
- report.upgraded was described as { from: Component, to: Component }[],
  but it is VersionChange[] with from/to as version strings.

Rewrite the example to use the real exported API (parse + diff +
renderReport), matching the JSDoc example in src/index.ts, and document
the actual report fields including fixedCVEs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants