@syntopica/quality-config 0.15.0 → 0.17.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/CHANGELOG.md +519 -0
- package/PUBLIC_API.md +33 -0
- package/README.md +25 -0
- package/bin/auditLevels.mjs +1 -0
- package/bin/baseline-audit.mjs +25 -140
- package/bin/baseline-changes.mjs +49 -0
- package/bin/baseline-deps-graph.mjs +73 -81
- package/bin/baseline-dupes.mjs +3 -3
- package/bin/baseline-type-coverage.mjs +8 -8
- package/bin/classifyAuditAdvisories.mjs +22 -0
- package/bin/compareVersions.mjs +11 -0
- package/bin/cruiseWorkspaceSelection.mjs +5 -0
- package/bin/defaultCruiseSources.mjs +1 -0
- package/bin/findChanges.mjs +23 -0
- package/bin/findCruiseWorkspaces.mjs +18 -0
- package/bin/formatChanges.mjs +25 -0
- package/bin/isReplaceableStamp.mjs +12 -0
- package/bin/localNodeToolCommand.mjs +18 -0
- package/bin/maxCruiseDepth.mjs +1 -0
- package/bin/normalizeVersion.mjs +8 -0
- package/bin/parseAuditArguments.mjs +16 -0
- package/bin/parseChangelog.mjs +21 -0
- package/bin/parseCruiseArguments.mjs +30 -0
- package/bin/presentCruiseSources.mjs +11 -0
- package/bin/readAuditAllowlist.mjs +28 -0
- package/bin/readAuditReport.mjs +18 -0
- package/bin/readCruiseCompilerOptions.mjs +18 -0
- package/bin/readInstalledPackages.mjs +42 -0
- package/bin/readVersionStamp.mjs +11 -0
- package/bin/rebaseCruisePaths.mjs +40 -0
- package/bin/reportAuditOutcome.mjs +28 -0
- package/bin/runPackageAudit.mjs +13 -0
- package/bin/runSynchronousCruise.mjs +11 -0
- package/bin/sectionsBetween.mjs +11 -0
- package/bin/skippedCruiseDirectories.mjs +12 -0
- package/bin/spawnCruise.mjs +8 -0
- package/bin/splitActionRequired.mjs +21 -0
- package/bin/throwCruiseConfigDiagnostic.mjs +5 -0
- package/bin/validateAuditReport.mjs +105 -0
- package/bin/withCruiseTsconfig.d.mts +5 -0
- package/bin/withCruiseTsconfig.mjs +42 -0
- package/bin/writeVersionStamp.mjs +27 -0
- package/jscpd.json +7 -2
- package/package.json +16 -10
- package/src/LefthookOptions.ts +5 -0
- package/src/TADU_BACKLOG_PATHS.ts +7 -0
- package/src/dependency-cruiser.ts +4 -1
- package/src/knip-framework.ts +4 -4
- package/src/knip.ts +11 -2
- package/src/lefthook.ts +55 -31
- package/src/readInstalledDependencyNames.ts +30 -0
package/bin/baseline-audit.mjs
CHANGED
|
@@ -1,147 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// Usage:
|
|
5
|
-
// baseline-audit [--level low|moderate|high|critical] [--file <path>]
|
|
6
|
-
//
|
|
7
|
-
// The problem this replaces: two advisories in this repository sat below the
|
|
8
|
-
// `--audit-level=high` line and were documented as prose in TODO.md. Nothing
|
|
9
|
-
// re-checked them, nothing expired them, and the only way to raise the audit
|
|
10
|
-
// level was to accept the noise of findings that had already been judged.
|
|
11
|
-
//
|
|
12
|
-
// An allowlist entry is a decision with a date on it. `reason` is required and
|
|
13
|
-
// `expires` is required, so a waiver comes back on its own and has to be
|
|
14
|
-
// re-argued rather than inherited. That is what makes it safe to gate at
|
|
15
|
-
// `moderate` instead of `high`: the known exceptions stop being noise.
|
|
16
|
-
//
|
|
17
|
-
// Allowlist file (`.baseline-advisories.json`), keyed by GitHub advisory ID:
|
|
18
|
-
//
|
|
19
|
-
// {
|
|
20
|
-
// "GHSA-w5hq-g745-h8pq": {
|
|
21
|
-
// "reason": "via @lhci/cli > uuid, resolved at 8.3.2; no consumer release past 0.15.1",
|
|
22
|
-
// "expires": "2026-12-31"
|
|
23
|
-
// }
|
|
24
|
-
// }
|
|
25
|
-
import { spawnSync } from 'node:child_process'
|
|
26
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
+
// Run the existing dated advisory policy only after a complete audit response.
|
|
27
3
|
import { resolve } from 'node:path'
|
|
28
4
|
import { argv, cwd, exit } from 'node:process'
|
|
29
|
-
import {
|
|
5
|
+
import { classifyAuditAdvisories } from './classifyAuditAdvisories.mjs'
|
|
6
|
+
import { parseAuditArguments } from './parseAuditArguments.mjs'
|
|
7
|
+
import { readAuditAllowlist } from './readAuditAllowlist.mjs'
|
|
8
|
+
import { reportAuditOutcome } from './reportAuditOutcome.mjs'
|
|
9
|
+
import { runPackageAudit } from './runPackageAudit.mjs'
|
|
30
10
|
|
|
31
|
-
|
|
32
|
-
const DEFAULT_FILE = '.baseline-advisories.json'
|
|
33
|
-
|
|
34
|
-
const flag = (name, fallback) => {
|
|
35
|
-
const index = argv.indexOf(`--${name}`)
|
|
36
|
-
return index === -1 ? fallback : (argv[index + 1] ?? fallback)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const level = flag('level', 'moderate')
|
|
40
|
-
if (!LEVELS.includes(level)) {
|
|
41
|
-
console.error(`baseline-audit: --level must be one of ${LEVELS.join(', ')}.`)
|
|
42
|
-
exit(2)
|
|
43
|
-
}
|
|
44
|
-
const minimum = LEVELS.indexOf(level)
|
|
45
|
-
const today = new Date().toISOString().slice(0, 10)
|
|
46
|
-
const root = cwd()
|
|
47
|
-
|
|
48
|
-
const allowlist = await readAllowlist(resolve(root, flag('file', DEFAULT_FILE)))
|
|
49
|
-
|
|
50
|
-
// `pnpm audit` exits non-zero when it finds anything, which is the whole
|
|
51
|
-
// point, so its status is not an error condition here - the JSON is.
|
|
52
|
-
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
53
|
-
const result = spawnSync(pnpm, [...pnpmArgs, 'audit', '--json'], {
|
|
54
|
-
encoding: 'utf8',
|
|
55
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
56
|
-
})
|
|
57
|
-
if (result.error) {
|
|
58
|
-
console.error(
|
|
59
|
-
`baseline-audit: could not run pnpm audit: ${result.error.message}`,
|
|
60
|
-
)
|
|
61
|
-
exit(2)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let report
|
|
65
|
-
try {
|
|
66
|
-
report = JSON.parse(result.stdout)
|
|
67
|
-
} catch {
|
|
68
|
-
console.error('baseline-audit: pnpm audit did not return JSON.')
|
|
69
|
-
console.error(result.stdout.slice(0, 2000))
|
|
70
|
-
exit(2)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const advisories = Object.values(report.advisories ?? {})
|
|
74
|
-
const failures = []
|
|
75
|
-
const waived = []
|
|
76
|
-
const stale = []
|
|
77
|
-
|
|
78
|
-
for (const advisory of advisories) {
|
|
79
|
-
if (LEVELS.indexOf(advisory.severity) < minimum) continue
|
|
80
|
-
|
|
81
|
-
const entry =
|
|
82
|
-
allowlist[advisory.github_advisory_id] ?? allowlist[String(advisory.id)]
|
|
83
|
-
if (!entry) {
|
|
84
|
-
failures.push(advisory)
|
|
85
|
-
continue
|
|
86
|
-
}
|
|
87
|
-
if (entry.expires < today) {
|
|
88
|
-
stale.push({ advisory, entry })
|
|
89
|
-
continue
|
|
90
|
-
}
|
|
91
|
-
waived.push({ advisory, entry })
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
for (const { advisory, entry } of waived) {
|
|
95
|
-
console.log(
|
|
96
|
-
`waived ${advisory.severity.padEnd(8)} ${advisory.github_advisory_id} ` +
|
|
97
|
-
`${advisory.module_name} (expires ${entry.expires})\n ${entry.reason}`,
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
for (const { advisory, entry } of stale) {
|
|
102
|
-
console.error(
|
|
103
|
-
`EXPIRED ${advisory.severity.padEnd(8)} ${advisory.github_advisory_id} ` +
|
|
104
|
-
`${advisory.module_name} (expired ${entry.expires})\n ${entry.reason}\n` +
|
|
105
|
-
' Re-check it, then renew the entry or remove it.',
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
for (const advisory of failures) {
|
|
110
|
-
console.error(
|
|
111
|
-
`FAIL ${advisory.severity.padEnd(8)} ${advisory.github_advisory_id} ` +
|
|
112
|
-
`${advisory.module_name} ${advisory.vulnerable_versions}\n` +
|
|
113
|
-
` patched in ${advisory.patched_versions} - ${advisory.url}\n` +
|
|
114
|
-
` via ${(advisory.findings?.[0]?.paths ?? []).slice(0, 2).join(', ')}`,
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const failed = failures.length + stale.length
|
|
119
|
-
console.log(
|
|
120
|
-
`\nbaseline-audit: ${advisories.length} advisories, gate at ${level}: ` +
|
|
121
|
-
`${failures.length} unwaived, ${stale.length} expired, ${waived.length} waived.`,
|
|
122
|
-
)
|
|
123
|
-
if (failed) exit(1)
|
|
124
|
-
|
|
125
|
-
async function readAllowlist(path) {
|
|
126
|
-
let raw
|
|
11
|
+
export async function runBaselineAudit() {
|
|
127
12
|
try {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
13
|
+
const { level, file } = parseAuditArguments(argv.slice(2))
|
|
14
|
+
const allowlist = await readAuditAllowlist(resolve(cwd(), file))
|
|
15
|
+
const report = runPackageAudit()
|
|
16
|
+
const advisories = Object.values(report.advisories)
|
|
17
|
+
const outcome = classifyAuditAdvisories(
|
|
18
|
+
advisories,
|
|
19
|
+
allowlist,
|
|
20
|
+
level,
|
|
21
|
+
new Date().toISOString().slice(0, 10),
|
|
22
|
+
)
|
|
23
|
+
return reportAuditOutcome(advisories, outcome, level)
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error(
|
|
26
|
+
`baseline-audit: ${error instanceof Error ? error.message : 'Could not validate audit response.'}`,
|
|
27
|
+
)
|
|
28
|
+
return 2
|
|
132
29
|
}
|
|
133
|
-
|
|
134
|
-
const parsed = JSON.parse(raw)
|
|
135
|
-
for (const [id, entry] of Object.entries(parsed)) {
|
|
136
|
-
// Both fields are required, and the check is here rather than at use: an
|
|
137
|
-
// entry missing one is a waiver nobody can audit, and treating it as
|
|
138
|
-
// absent would hide the mistake behind a passing gate.
|
|
139
|
-
if (!entry?.reason || !entry?.expires) {
|
|
140
|
-
console.error(
|
|
141
|
-
`baseline-audit: allowlist entry ${id} needs both \`reason\` and \`expires\`.`,
|
|
142
|
-
)
|
|
143
|
-
exit(2)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return parsed
|
|
147
30
|
}
|
|
31
|
+
|
|
32
|
+
exit(await runBaselineAudit())
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Prints what changed in the baseline packages since the last time this
|
|
3
|
+
// command ran in the project, and what the person upgrading must do about it.
|
|
4
|
+
//
|
|
5
|
+
// Usage:
|
|
6
|
+
// baseline-changes [dir] [--no-write]
|
|
7
|
+
//
|
|
8
|
+
// Installed copies carry no release notes of their own, and pnpm 10+ does not
|
|
9
|
+
// run dependency lifecycle scripts, so no package can announce its own upgrade.
|
|
10
|
+
// This runs from the project's own gate (`check:ci`) instead. It compares the
|
|
11
|
+
// installed versions with the ones recorded in `.baseline-versions.json`
|
|
12
|
+
// (commit that file), prints the CHANGELOG.md sections in between - every
|
|
13
|
+
// `### Action required` subsection first - then records the installed versions,
|
|
14
|
+
// so the notice appears once, in the run that follows the upgrade.
|
|
15
|
+
//
|
|
16
|
+
// Exit code is always 0: a notice is not a gate. Under `CI` the file is never
|
|
17
|
+
// written, so a pipeline cannot swallow a notice a person has not seen.
|
|
18
|
+
import { join, resolve } from 'node:path'
|
|
19
|
+
import { argv, cwd, env } from 'node:process'
|
|
20
|
+
import { findChanges } from './findChanges.mjs'
|
|
21
|
+
import { formatChanges } from './formatChanges.mjs'
|
|
22
|
+
import { readInstalledPackages } from './readInstalledPackages.mjs'
|
|
23
|
+
import { readVersionStamp } from './readVersionStamp.mjs'
|
|
24
|
+
import { writeVersionStamp } from './writeVersionStamp.mjs'
|
|
25
|
+
|
|
26
|
+
const STAMP_FILE = '.baseline-versions.json'
|
|
27
|
+
const args = argv.slice(2)
|
|
28
|
+
const root = resolve(cwd(), args.find((arg) => !arg.startsWith('--')) ?? '.')
|
|
29
|
+
const mayWrite = !args.includes('--no-write') && !env.CI
|
|
30
|
+
|
|
31
|
+
const installed = await readInstalledPackages(root)
|
|
32
|
+
const stampPath = join(root, STAMP_FILE)
|
|
33
|
+
const stamp = await readVersionStamp(stampPath)
|
|
34
|
+
const changes = stamp ? findChanges(installed, stamp) : []
|
|
35
|
+
|
|
36
|
+
if (changes.length > 0) {
|
|
37
|
+
console.log(
|
|
38
|
+
`baseline-changes: ${changes.length} package(s) upgraded since ${STAMP_FILE} was written.\n`,
|
|
39
|
+
)
|
|
40
|
+
console.log(formatChanges(changes))
|
|
41
|
+
} else if (!stamp) {
|
|
42
|
+
console.log(
|
|
43
|
+
`baseline-changes: no ${STAMP_FILE} yet, recording the installed versions.`,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (mayWrite && installed.length > 0) {
|
|
48
|
+
await writeVersionStamp(stampPath, stamp ?? {}, installed)
|
|
49
|
+
}
|
|
@@ -11,96 +11,88 @@
|
|
|
11
11
|
// baseline-deps-graph # src, app, server, lib
|
|
12
12
|
// baseline-deps-graph src app # only these
|
|
13
13
|
// baseline-deps-graph --config path.cjs src
|
|
14
|
-
import {
|
|
15
|
-
import { existsSync, readdirSync } from 'node:fs'
|
|
14
|
+
import { existsSync } from 'node:fs'
|
|
16
15
|
import { relative, resolve } from 'node:path'
|
|
17
16
|
import { argv, cwd, exit } from 'node:process'
|
|
17
|
+
import { cruiseWorkspaceSelection } from './cruiseWorkspaceSelection.mjs'
|
|
18
|
+
import { DEFAULT_CRUISE_SOURCES } from './defaultCruiseSources.mjs'
|
|
19
|
+
import { findCruiseWorkspaces } from './findCruiseWorkspaces.mjs'
|
|
20
|
+
import { parseCruiseArguments } from './parseCruiseArguments.mjs'
|
|
18
21
|
import { pnpmCommand } from './pnpmCommand.mjs'
|
|
22
|
+
import { presentCruiseSources } from './presentCruiseSources.mjs'
|
|
23
|
+
import { spawnCruise } from './spawnCruise.mjs'
|
|
24
|
+
import { withCruiseTsconfig } from './withCruiseTsconfig.mjs'
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'build',
|
|
25
|
-
'coverage',
|
|
26
|
-
'target',
|
|
27
|
-
'.git',
|
|
28
|
-
'.next',
|
|
29
|
-
'.nuxt',
|
|
30
|
-
'.output',
|
|
31
|
-
'.astro',
|
|
32
|
-
])
|
|
33
|
-
const MAX_DEPTH = 3
|
|
34
|
-
|
|
35
|
-
const args = argv.slice(2)
|
|
36
|
-
const configIndex = args.indexOf('--config')
|
|
37
|
-
const configPath = resolve(
|
|
38
|
-
cwd(),
|
|
39
|
-
configIndex === -1
|
|
40
|
-
? '.dependency-cruiser.cjs'
|
|
41
|
-
: (args[configIndex + 1] ?? ''),
|
|
42
|
-
)
|
|
43
|
-
const sources = (
|
|
44
|
-
configIndex === -1
|
|
45
|
-
? args
|
|
46
|
-
: [...args.slice(0, configIndex), ...args.slice(configIndex + 2)]
|
|
47
|
-
).filter(Boolean)
|
|
48
|
-
const sourceDirectories = sources.length ? sources : DEFAULT_SOURCES
|
|
49
|
-
|
|
50
|
-
// Every path below is derived from the invoking project's own tree, which is
|
|
51
|
-
// the point of this tool - not untrusted input.
|
|
52
|
-
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
53
|
-
if (!existsSync(configPath)) {
|
|
54
|
-
console.error(
|
|
55
|
-
`baseline-deps-graph: no dependency-cruiser config at ${relative(cwd(), configPath)}. ` +
|
|
56
|
-
'Pass one with --config.',
|
|
26
|
+
export function runDependencyGraphs() {
|
|
27
|
+
const { configPath, sources, cwdOnly } = parseCruiseArguments(
|
|
28
|
+
argv.slice(2),
|
|
29
|
+
cwd(),
|
|
57
30
|
)
|
|
58
|
-
|
|
59
|
-
}
|
|
31
|
+
const sourceDirectories = sources.length ? sources : DEFAULT_CRUISE_SOURCES
|
|
60
32
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
33
|
+
// Every path below is derived from the invoking project's own tree, which is
|
|
34
|
+
// the point of this tool - not untrusted input.
|
|
35
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
36
|
+
if (!existsSync(configPath)) {
|
|
37
|
+
console.error(
|
|
38
|
+
`baseline-deps-graph: no dependency-cruiser config at ${relative(cwd(), configPath)}. ` +
|
|
39
|
+
'Pass one with --config.',
|
|
40
|
+
)
|
|
41
|
+
exit(1)
|
|
69
42
|
}
|
|
70
|
-
return found
|
|
71
|
-
}
|
|
72
43
|
|
|
73
|
-
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
44
|
+
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
74
45
|
|
|
75
|
-
const failed = []
|
|
76
|
-
for (const workspace of
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
46
|
+
const failed = []
|
|
47
|
+
for (const workspace of cruiseWorkspaceSelection(
|
|
48
|
+
cwd(),
|
|
49
|
+
cwdOnly,
|
|
50
|
+
findCruiseWorkspaces,
|
|
51
|
+
)) {
|
|
52
|
+
const present = presentCruiseSources(workspace, sourceDirectories)
|
|
53
|
+
if (
|
|
54
|
+
cwdOnly &&
|
|
55
|
+
sources.length > 0 &&
|
|
56
|
+
present.length !== sourceDirectories.length
|
|
57
|
+
) {
|
|
58
|
+
console.error(`deps-graph: missing explicit source in ${workspace}`)
|
|
59
|
+
failed.push(relative(cwd(), workspace) || '.')
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
if (!present.length) continue
|
|
81
63
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
64
|
+
const label = relative(cwd(), workspace) || '.'
|
|
65
|
+
console.log(`deps-graph: cruising ${label} (${present.join(', ')})`)
|
|
66
|
+
try {
|
|
67
|
+
const result = withCruiseTsconfig(
|
|
68
|
+
resolve(workspace, 'tsconfig.json'),
|
|
69
|
+
spawnCruise.bind(
|
|
70
|
+
null,
|
|
71
|
+
pnpm,
|
|
72
|
+
[
|
|
73
|
+
...pnpmArgs,
|
|
74
|
+
'exec',
|
|
75
|
+
'depcruise',
|
|
76
|
+
...present,
|
|
77
|
+
'--config',
|
|
78
|
+
configPath,
|
|
79
|
+
],
|
|
80
|
+
workspace,
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
if (result.status !== 0) failed.push(label)
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(`deps-graph: ${label}: ${String(error)}`)
|
|
86
|
+
failed.push(label)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/* eslint-enable security/detect-non-literal-fs-filename */
|
|
101
90
|
|
|
102
|
-
if (failed.length) {
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
if (failed.length) {
|
|
92
|
+
console.error(`deps-graph: failed for ${failed.join(', ')}`)
|
|
93
|
+
exit(1)
|
|
94
|
+
}
|
|
95
|
+
console.log('deps-graph: no violations found.')
|
|
105
96
|
}
|
|
106
|
-
|
|
97
|
+
|
|
98
|
+
runDependencyGraphs()
|
package/bin/baseline-dupes.mjs
CHANGED
|
@@ -38,7 +38,7 @@ import { tmpdir } from 'node:os'
|
|
|
38
38
|
import { join } from 'node:path'
|
|
39
39
|
import { argv, exit } from 'node:process'
|
|
40
40
|
import { fileURLToPath } from 'node:url'
|
|
41
|
-
import {
|
|
41
|
+
import { localNodeToolCommand } from './localNodeToolCommand.mjs'
|
|
42
42
|
|
|
43
43
|
const PACKAGED_CONFIG = fileURLToPath(new URL('../jscpd.json', import.meta.url))
|
|
44
44
|
|
|
@@ -109,8 +109,8 @@ if (found.value !== -1) args[found.value] = config
|
|
|
109
109
|
else if (found.inline !== -1) args[found.inline] = `--config=${config}`
|
|
110
110
|
else args.push('--config', config)
|
|
111
111
|
|
|
112
|
-
const [
|
|
113
|
-
const result = spawnSync(
|
|
112
|
+
const [node, tool] = localNodeToolCommand('jscpd')
|
|
113
|
+
const result = spawnSync(node, [tool, ...args], {
|
|
114
114
|
stdio: 'inherit',
|
|
115
115
|
})
|
|
116
116
|
|
|
@@ -36,7 +36,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
|
36
36
|
import { dirname, relative, resolve } from 'node:path'
|
|
37
37
|
import { argv, cwd, exit } from 'node:process'
|
|
38
38
|
import { fileURLToPath } from 'node:url'
|
|
39
|
-
import {
|
|
39
|
+
import { localNodeToolCommand } from './localNodeToolCommand.mjs'
|
|
40
40
|
|
|
41
41
|
const IGNORED_FILES = ['.next/**', '.nuxt/**', 'tests/**', '**/*.test.*']
|
|
42
42
|
const SKIPPED_DIRECTORIES = new Set([
|
|
@@ -217,17 +217,17 @@ if (!workspaces.length) {
|
|
|
217
217
|
exit(1)
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
221
|
-
|
|
222
220
|
let failed = false
|
|
223
221
|
for (const workspace of workspaces) {
|
|
224
222
|
const label = relative(cwd(), workspace.project ?? workspace.directory) || '.'
|
|
223
|
+
const [node, tool] = localNodeToolCommand(
|
|
224
|
+
'type-coverage',
|
|
225
|
+
workspace.directory,
|
|
226
|
+
)
|
|
225
227
|
const result = spawnSync(
|
|
226
|
-
|
|
228
|
+
node,
|
|
227
229
|
[
|
|
228
|
-
|
|
229
|
-
'exec',
|
|
230
|
-
'type-coverage',
|
|
230
|
+
tool,
|
|
231
231
|
'--strict',
|
|
232
232
|
'--at-least',
|
|
233
233
|
threshold,
|
|
@@ -257,7 +257,7 @@ if (failed) {
|
|
|
257
257
|
(override === undefined
|
|
258
258
|
? '.\n'
|
|
259
259
|
: ` (this project's own floor; the shared bar is ${declared[1]}%).\n`) +
|
|
260
|
-
'Run
|
|
260
|
+
'Run the installed `type-coverage --strict --detail` in the failing workspace to see where.',
|
|
261
261
|
)
|
|
262
262
|
exit(1)
|
|
263
263
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AUDIT_LEVELS } from './auditLevels.mjs'
|
|
2
|
+
|
|
3
|
+
export function classifyAuditAdvisories(advisories, allowlist, level, today) {
|
|
4
|
+
const minimum = AUDIT_LEVELS.indexOf(level)
|
|
5
|
+
const failures = []
|
|
6
|
+
const waived = []
|
|
7
|
+
const stale = []
|
|
8
|
+
for (const advisory of advisories) {
|
|
9
|
+
if (AUDIT_LEVELS.indexOf(advisory.severity) < minimum) continue
|
|
10
|
+
const githubEntry = Object.hasOwn(allowlist, advisory.github_advisory_id)
|
|
11
|
+
? allowlist[advisory.github_advisory_id]
|
|
12
|
+
: undefined
|
|
13
|
+
const numericEntry = Object.hasOwn(allowlist, String(advisory.id))
|
|
14
|
+
? allowlist[String(advisory.id)]
|
|
15
|
+
: undefined
|
|
16
|
+
const entry = githubEntry ?? numericEntry
|
|
17
|
+
if (!entry) failures.push(advisory)
|
|
18
|
+
else if (entry.expires < today) stale.push({ advisory, entry })
|
|
19
|
+
else waived.push({ advisory, entry })
|
|
20
|
+
}
|
|
21
|
+
return { failures, waived, stale }
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Orders two `major.minor.patch` strings. A pre-release suffix is ignored: the
|
|
2
|
+
// changelogs only record released versions.
|
|
3
|
+
export function compareVersions(a, b) {
|
|
4
|
+
const left = a.split('-')[0].split('.').map(Number)
|
|
5
|
+
const right = b.split('-')[0].split('.').map(Number)
|
|
6
|
+
for (let index = 0; index < 3; index += 1) {
|
|
7
|
+
const difference = (left[index] ?? 0) - (right[index] ?? 0)
|
|
8
|
+
if (difference !== 0) return difference
|
|
9
|
+
}
|
|
10
|
+
return 0
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_CRUISE_SOURCES = ['src', 'app', 'server', 'lib']
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { compareVersions } from './compareVersions.mjs'
|
|
2
|
+
import { normalizeVersion } from './normalizeVersion.mjs'
|
|
3
|
+
import { parseChangelog } from './parseChangelog.mjs'
|
|
4
|
+
import { sectionsBetween } from './sectionsBetween.mjs'
|
|
5
|
+
|
|
6
|
+
const REPOSITORY = 'https://github.com/syntopica/codeality/blob/main'
|
|
7
|
+
|
|
8
|
+
// The installed packages that moved forward since `stamp` was written, each
|
|
9
|
+
// with the changelog sections it passed. A package absent from the stamp is
|
|
10
|
+
// new, not upgraded, and a downgrade has nothing to announce. Versions are
|
|
11
|
+
// normalized so no raw stamp text reaches the terminal.
|
|
12
|
+
export function findChanges(installed, stamp) {
|
|
13
|
+
return installed.flatMap(({ name, version, changelog, directory }) => {
|
|
14
|
+
const from = normalizeVersion(stamp[name])
|
|
15
|
+
const to = normalizeVersion(version)
|
|
16
|
+
if (!from || !to || compareVersions(to, from) <= 0) return []
|
|
17
|
+
const sections = changelog
|
|
18
|
+
? sectionsBetween(parseChangelog(changelog), from, to)
|
|
19
|
+
: []
|
|
20
|
+
const link = `${REPOSITORY}/${directory ?? 'packages'}/CHANGELOG.md`
|
|
21
|
+
return [{ name, from, to, sections, link }]
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { MAX_CRUISE_DEPTH } from './maxCruiseDepth.mjs'
|
|
4
|
+
import { SKIPPED_CRUISE_DIRECTORIES } from './skippedCruiseDirectories.mjs'
|
|
5
|
+
|
|
6
|
+
export function findCruiseWorkspaces(root, depth = 0) {
|
|
7
|
+
const found = []
|
|
8
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- root starts at the invoking project's cwd and recurses through directory entries.
|
|
9
|
+
if (existsSync(resolve(root, 'tsconfig.json'))) found.push(root)
|
|
10
|
+
if (depth >= MAX_CRUISE_DEPTH) return found
|
|
11
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- The selected project is read recursively; isDirectory excludes symlink entries below.
|
|
12
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
13
|
+
if (!entry.isDirectory() || SKIPPED_CRUISE_DIRECTORIES.has(entry.name))
|
|
14
|
+
continue
|
|
15
|
+
found.push(...findCruiseWorkspaces(resolve(root, entry.name), depth + 1))
|
|
16
|
+
}
|
|
17
|
+
return found
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { splitActionRequired } from './splitActionRequired.mjs'
|
|
2
|
+
|
|
3
|
+
// `changes` is [{ name, from, to, sections, link }]. What a person must do
|
|
4
|
+
// comes first and on its own; the other notes follow, newest release first.
|
|
5
|
+
export function formatChanges(changes) {
|
|
6
|
+
const actions = []
|
|
7
|
+
const notes = []
|
|
8
|
+
for (const { name, from, to, sections, link } of changes) {
|
|
9
|
+
notes.push(`${name} ${from} -> ${to}`)
|
|
10
|
+
if (sections.length === 0) {
|
|
11
|
+
notes.push(` no changelog entries shipped, see ${link}`)
|
|
12
|
+
}
|
|
13
|
+
for (const { version, body } of sections) {
|
|
14
|
+
const { action, rest } = splitActionRequired(body)
|
|
15
|
+
if (action) actions.push(`${name} ${version}\n${action}`)
|
|
16
|
+
if (rest) notes.push(` ${version}\n${rest.replace(/^(?=.)/gm, ' ')}`)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const lines = []
|
|
20
|
+
if (actions.length > 0) {
|
|
21
|
+
lines.push('ACTION REQUIRED', '', actions.join('\n\n'), '')
|
|
22
|
+
}
|
|
23
|
+
lines.push('Changes', '', notes.join('\n'))
|
|
24
|
+
return lines.join('\n')
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { lstat } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
// True when the stamp is absent or a regular file; a symlink or any other
|
|
4
|
+
// file kind is never written through.
|
|
5
|
+
export async function isReplaceableStamp(path) {
|
|
6
|
+
try {
|
|
7
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- The stamp path is the project's own file; lstat does not follow a symlink.
|
|
8
|
+
return (await lstat(path)).isFile()
|
|
9
|
+
} catch {
|
|
10
|
+
return true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { dirname, resolve } from 'node:path'
|
|
4
|
+
import { cwd, execPath } from 'node:process'
|
|
5
|
+
|
|
6
|
+
/** Resolve a Node CLI from the consumer, including hoisted workspace installs. */
|
|
7
|
+
export function localNodeToolCommand(name, directory = cwd()) {
|
|
8
|
+
const require = createRequire(resolve(directory, 'package.json'))
|
|
9
|
+
const manifestPath = require.resolve(`${name}/package.json`)
|
|
10
|
+
// The manifest belongs to the explicitly selected, installed tool.
|
|
11
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
12
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
13
|
+
const entry =
|
|
14
|
+
typeof manifest.bin === 'string' ? manifest.bin : manifest.bin?.[name]
|
|
15
|
+
if (typeof entry !== 'string')
|
|
16
|
+
throw new Error(`No installed CLI entry for ${name}`)
|
|
17
|
+
return [execPath, resolve(dirname(manifestPath), entry)]
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MAX_CRUISE_DEPTH = 3
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The `major.minor.patch` prefix of a version, or null when there is none.
|
|
2
|
+
// Used before printing, so text read from a committed file is never echoed.
|
|
3
|
+
export function normalizeVersion(text) {
|
|
4
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(
|
|
5
|
+
typeof text === 'string' ? text : '',
|
|
6
|
+
)
|
|
7
|
+
return match ? `${match[1]}.${match[2]}.${match[3]}` : null
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AUDIT_LEVELS } from './auditLevels.mjs'
|
|
2
|
+
|
|
3
|
+
export function parseAuditArguments(args) {
|
|
4
|
+
const levelIndex = args.indexOf('--level')
|
|
5
|
+
const fileIndex = args.indexOf('--file')
|
|
6
|
+
const level =
|
|
7
|
+
levelIndex === -1 ? 'moderate' : (args[levelIndex + 1] ?? 'moderate')
|
|
8
|
+
const file =
|
|
9
|
+
fileIndex === -1
|
|
10
|
+
? '.baseline-advisories.json'
|
|
11
|
+
: (args[fileIndex + 1] ?? '.baseline-advisories.json')
|
|
12
|
+
if (!AUDIT_LEVELS.includes(level)) {
|
|
13
|
+
throw new Error(`--level must be one of ${AUDIT_LEVELS.join(', ')}.`)
|
|
14
|
+
}
|
|
15
|
+
return { level, file }
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const VERSION_HEADING = /^## \[?(\d+\.\d+\.\d+)\]?/
|
|
2
|
+
|
|
3
|
+
// Splits a changelog into released sections. `## [Unreleased]` and any heading
|
|
4
|
+
// without a version number end the previous section and start none.
|
|
5
|
+
export function parseChangelog(text) {
|
|
6
|
+
const sections = []
|
|
7
|
+
let current = null
|
|
8
|
+
for (const line of text.split('\n')) {
|
|
9
|
+
if (line.startsWith('## ')) {
|
|
10
|
+
const version = VERSION_HEADING.exec(line)?.[1]
|
|
11
|
+
current = version ? { version, lines: [] } : null
|
|
12
|
+
if (current) sections.push(current)
|
|
13
|
+
} else if (current) {
|
|
14
|
+
current.lines.push(line)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return sections.map(({ version, lines }) => ({
|
|
18
|
+
version,
|
|
19
|
+
body: lines.join('\n').trim(),
|
|
20
|
+
}))
|
|
21
|
+
}
|