npm-audit-report-cli 1.0.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/README.md +180 -0
- package/action.yml +38 -0
- package/dist/chunk-L2D2NQGH.js +574 -0
- package/dist/cli.cjs +760 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +197 -0
- package/dist/index.cjs +613 -0
- package/dist/index.d.cts +54 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +23 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# audit-report
|
|
2
|
+
|
|
3
|
+
> Convert `npm audit --json` output to Markdown, HTML, SARIF, or GitHub Actions annotations. Zero runtime dependencies.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Project-local
|
|
9
|
+
npm install -D audit-report
|
|
10
|
+
|
|
11
|
+
# Or run directly
|
|
12
|
+
npx audit-report --help
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
### Markdown report
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm audit --json | npx audit-report --format markdown > audit.md
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### SARIF (for GitHub code scanning)
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm audit --json | npx audit-report --format sarif > audit.sarif
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### GitHub Actions annotations
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm audit --json | npx audit-report --format annotations
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## CLI flags
|
|
36
|
+
|
|
37
|
+
| Flag | Alias | Default | Description |
|
|
38
|
+
|---|---|---|---|
|
|
39
|
+
| `--format <fmt>` | `-f` | `markdown` | Output format: `markdown`, `html`, `sarif`, `annotations` |
|
|
40
|
+
| `--output <path>` | `-o` | stdout | Write output to a file instead of stdout |
|
|
41
|
+
| `--severity <sev>` | `-s` | `low` | Minimum severity to include |
|
|
42
|
+
| `--fail-on <sev>` | | `high` | Exit code 1 when findings meet or exceed this severity. Use `none` to never fail |
|
|
43
|
+
| `--file <path>` | | stdin | Read audit JSON from a file instead of stdin |
|
|
44
|
+
| `--title <text>` | | `npm audit report` | Title for the generated report |
|
|
45
|
+
| `--template <path>` | | | Reserved for future use |
|
|
46
|
+
| `--no-color` | | | Reserved (no-op) |
|
|
47
|
+
| `--quiet` | `-q` | | Suppress non-essential stderr output |
|
|
48
|
+
| `--version` | `-v` | | Print version and exit |
|
|
49
|
+
| `--help` | `-h` | | Print usage and exit |
|
|
50
|
+
|
|
51
|
+
### Exit codes
|
|
52
|
+
|
|
53
|
+
- `0` — no findings at/above `--fail-on` threshold
|
|
54
|
+
- `1` — findings at/above `--fail-on` threshold
|
|
55
|
+
- `2` — invalid input (bad JSON or unrecognized npm audit schema)
|
|
56
|
+
- `3` — `--file` path does not exist
|
|
57
|
+
|
|
58
|
+
## GitHub Actions
|
|
59
|
+
|
|
60
|
+
Use the bundled composite action:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
name: Audit
|
|
64
|
+
on: [push, pull_request]
|
|
65
|
+
|
|
66
|
+
jobs:
|
|
67
|
+
audit:
|
|
68
|
+
runs-on: ubuntu-latest
|
|
69
|
+
steps:
|
|
70
|
+
- uses: actions/checkout@v4
|
|
71
|
+
- uses: actions/setup-node@v4
|
|
72
|
+
with: { node-version: 20 }
|
|
73
|
+
- run: npm ci
|
|
74
|
+
- uses: dimasdarfi/audit-report@v1
|
|
75
|
+
with:
|
|
76
|
+
format: sarif
|
|
77
|
+
severity: low
|
|
78
|
+
fail-on: high
|
|
79
|
+
output-file: audit.sarif
|
|
80
|
+
- uses: github/codeql-action/upload-sarif@v3
|
|
81
|
+
if: always()
|
|
82
|
+
with:
|
|
83
|
+
sarif_file: audit.sarif
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Or call the CLI directly:
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
- run: npm audit --json | npx audit-report -f annotations
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Node.js library
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { parse, format, report } from 'audit-report';
|
|
96
|
+
|
|
97
|
+
// One-shot
|
|
98
|
+
const md = report(jsonString, { format: 'markdown' });
|
|
99
|
+
|
|
100
|
+
// Two-step
|
|
101
|
+
const r = parse(jsonString);
|
|
102
|
+
const html = format(r, { format: 'html', title: 'Weekly audit' });
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Types
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import type { AuditReport, Vulnerability, Severity, Format, FormatOptions } from 'audit-report';
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Output preview — Markdown
|
|
112
|
+
|
|
113
|
+
```markdown
|
|
114
|
+
## npm audit report
|
|
115
|
+
|
|
116
|
+
> 3 vulnerabilities found · audited 2026-06-09 · 342 dependencies
|
|
117
|
+
|
|
118
|
+
| Severity | Count | Fixable |
|
|
119
|
+
|----------|-------|---------|
|
|
120
|
+
| 🔴 Critical | 1 | 1 |
|
|
121
|
+
| 🟠 High | 1 | 1 |
|
|
122
|
+
| 🟡 Moderate | 1 | 0 |
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary>🔴 Critical (1)</summary>
|
|
126
|
+
|
|
127
|
+
### lodash
|
|
128
|
+
- **ID:** GHSA-1065
|
|
129
|
+
- **Title:** Prototype Pollution
|
|
130
|
+
- **Range:** `<4.17.21`
|
|
131
|
+
- **Fix:** `npm install lodash@4.17.21`
|
|
132
|
+
- **Advisory:** https://npmjs.com/advisories/1065
|
|
133
|
+
- **Paths:** `node_modules/lodash`
|
|
134
|
+
|
|
135
|
+
</details>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Output preview — SARIF
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
|
|
143
|
+
"version": "2.1.0",
|
|
144
|
+
"runs": [
|
|
145
|
+
{
|
|
146
|
+
"tool": { "driver": { "name": "npm-audit", "rules": [...] } },
|
|
147
|
+
"results": [
|
|
148
|
+
{
|
|
149
|
+
"ruleId": "GHSA-1065",
|
|
150
|
+
"level": "error",
|
|
151
|
+
"message": { "text": "Prototype Pollution. Affected range: <4.17.21. Fix: npm install lodash@4.17.21" },
|
|
152
|
+
"locations": [{ "physicalLocation": { "artifactLocation": { "uri": "package.json" } } }]
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Output preview — GitHub annotations
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
::error file=package.json,title=GHSA-1065::lodash — Prototype Pollution, affected: <4.17.21 (fix: npm install lodash@4.17.21)
|
|
164
|
+
::warning file=package.json,title=GHSA-1779::minimatch — Inefficient Regular Expression Complexity in minimatch, affected: <3.0.5 (no fix)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Contributing
|
|
168
|
+
|
|
169
|
+
PRs welcome. Run locally:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
npm install
|
|
173
|
+
npm run lint
|
|
174
|
+
npm test
|
|
175
|
+
npm run build
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT
|
package/action.yml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: 'audit-report'
|
|
2
|
+
description: 'Convert npm audit JSON to Markdown, HTML, SARIF, or GitHub annotations'
|
|
3
|
+
author: 'Dimas Darfi Angga'
|
|
4
|
+
|
|
5
|
+
inputs:
|
|
6
|
+
format:
|
|
7
|
+
description: 'Output format: markdown|html|sarif|annotations'
|
|
8
|
+
default: 'markdown'
|
|
9
|
+
severity:
|
|
10
|
+
description: 'Minimum severity to include: critical|high|moderate|low|info'
|
|
11
|
+
default: 'low'
|
|
12
|
+
fail-on:
|
|
13
|
+
description: 'Exit 1 if findings at or above this severity: critical|high|moderate|low|info|none'
|
|
14
|
+
default: 'high'
|
|
15
|
+
output-file:
|
|
16
|
+
description: 'Output filename'
|
|
17
|
+
default: 'audit-report.md'
|
|
18
|
+
upload-artifact:
|
|
19
|
+
description: 'Upload output as GitHub Actions artifact'
|
|
20
|
+
default: 'true'
|
|
21
|
+
|
|
22
|
+
runs:
|
|
23
|
+
using: 'composite'
|
|
24
|
+
steps:
|
|
25
|
+
- name: Run audit and report
|
|
26
|
+
shell: bash
|
|
27
|
+
run: |
|
|
28
|
+
npm audit --json | npx audit-report \
|
|
29
|
+
--format ${{ inputs.format }} \
|
|
30
|
+
--severity ${{ inputs.severity }} \
|
|
31
|
+
--fail-on ${{ inputs.fail-on }} \
|
|
32
|
+
--output ${{ inputs.output-file }}
|
|
33
|
+
- name: Upload artifact
|
|
34
|
+
if: ${{ inputs.upload-artifact == 'true' }}
|
|
35
|
+
uses: actions/upload-artifact@v4
|
|
36
|
+
with:
|
|
37
|
+
name: audit-report
|
|
38
|
+
path: ${{ inputs.output-file }}
|