@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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
export function parseCruiseArguments(args, root) {
|
|
4
|
+
const remaining = []
|
|
5
|
+
let cwdOnly = false
|
|
6
|
+
for (const argument of args) {
|
|
7
|
+
if (argument === '--cwd-only') {
|
|
8
|
+
if (cwdOnly) throw new Error('Duplicate --cwd-only option')
|
|
9
|
+
cwdOnly = true
|
|
10
|
+
} else {
|
|
11
|
+
remaining.push(argument)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const configIndex = remaining.indexOf('--config')
|
|
15
|
+
const configPath = resolve(
|
|
16
|
+
root,
|
|
17
|
+
configIndex === -1
|
|
18
|
+
? '.dependency-cruiser.cjs'
|
|
19
|
+
: (remaining[configIndex + 1] ?? ''),
|
|
20
|
+
)
|
|
21
|
+
const sources = (
|
|
22
|
+
configIndex === -1
|
|
23
|
+
? remaining
|
|
24
|
+
: [
|
|
25
|
+
...remaining.slice(0, configIndex),
|
|
26
|
+
...remaining.slice(configIndex + 2),
|
|
27
|
+
]
|
|
28
|
+
).filter(Boolean)
|
|
29
|
+
return { configPath, sources, cwdOnly }
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
export function presentCruiseSources(workspace, sources) {
|
|
5
|
+
const present = []
|
|
6
|
+
for (const directory of sources) {
|
|
7
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- Source paths are selected by the invoking CLI; this call only probes their existence.
|
|
8
|
+
if (existsSync(resolve(workspace, directory))) present.push(directory)
|
|
9
|
+
}
|
|
10
|
+
return present
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
export async function readAuditAllowlist(path) {
|
|
4
|
+
let raw
|
|
5
|
+
try {
|
|
6
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
7
|
+
raw = await readFile(path, 'utf8')
|
|
8
|
+
} catch {
|
|
9
|
+
return {}
|
|
10
|
+
}
|
|
11
|
+
let parsed
|
|
12
|
+
try {
|
|
13
|
+
parsed = JSON.parse(raw)
|
|
14
|
+
} catch {
|
|
15
|
+
throw new Error('Invalid advisory allowlist JSON.')
|
|
16
|
+
}
|
|
17
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
18
|
+
throw new Error('Advisory allowlist must be an object.')
|
|
19
|
+
}
|
|
20
|
+
for (const [id, entry] of Object.entries(parsed)) {
|
|
21
|
+
if (!entry?.reason || !entry?.expires) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`allowlist entry ${id} needs both \`reason\` and \`expires\`.`,
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return parsed
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { validateAuditReport } from './validateAuditReport.mjs'
|
|
2
|
+
|
|
3
|
+
export function readAuditReport(result) {
|
|
4
|
+
if (
|
|
5
|
+
result.error ||
|
|
6
|
+
result.signal ||
|
|
7
|
+
(result.status !== 0 && result.status !== 1)
|
|
8
|
+
) {
|
|
9
|
+
throw new Error('Could not complete pnpm audit.')
|
|
10
|
+
}
|
|
11
|
+
let report
|
|
12
|
+
try {
|
|
13
|
+
report = JSON.parse(result.stdout)
|
|
14
|
+
} catch {
|
|
15
|
+
throw new Error('pnpm audit did not return JSON.')
|
|
16
|
+
}
|
|
17
|
+
return validateAuditReport(report)
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import ts from 'typescript'
|
|
3
|
+
import { throwCruiseConfigDiagnostic } from './throwCruiseConfigDiagnostic.mjs'
|
|
4
|
+
|
|
5
|
+
export function readCruiseCompilerOptions(configPath) {
|
|
6
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(
|
|
7
|
+
resolve(configPath),
|
|
8
|
+
{},
|
|
9
|
+
{
|
|
10
|
+
...ts.sys,
|
|
11
|
+
onUnRecoverableConfigFileDiagnostic: throwCruiseConfigDiagnostic,
|
|
12
|
+
},
|
|
13
|
+
)
|
|
14
|
+
if (!parsed)
|
|
15
|
+
throw new Error(`Cannot read TypeScript configuration: ${configPath}`)
|
|
16
|
+
if (parsed.errors.length > 0) throwCruiseConfigDiagnostic(parsed.errors[0])
|
|
17
|
+
return parsed.options
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
const SCOPE = '@syntopica'
|
|
5
|
+
// The one package of this repository published outside the scope.
|
|
6
|
+
const UNSCOPED = ['eslint-plugin-code-policy']
|
|
7
|
+
|
|
8
|
+
async function readPackage(directory) {
|
|
9
|
+
try {
|
|
10
|
+
const manifest = JSON.parse(
|
|
11
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
12
|
+
await readFile(join(directory, 'package.json'), 'utf8'),
|
|
13
|
+
)
|
|
14
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- The directory is a node_modules entry of the project being checked.
|
|
15
|
+
const changelog = await readFile(
|
|
16
|
+
join(directory, 'CHANGELOG.md'),
|
|
17
|
+
'utf8',
|
|
18
|
+
).catch(() => null)
|
|
19
|
+
return {
|
|
20
|
+
name: manifest.name,
|
|
21
|
+
version: manifest.version,
|
|
22
|
+
changelog,
|
|
23
|
+
directory: manifest.repository?.directory,
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The packages of this repository installed directly in `root`'s node_modules,
|
|
31
|
+
// with their version and the CHANGELOG.md they ship, when they ship one.
|
|
32
|
+
export async function readInstalledPackages(root) {
|
|
33
|
+
const modules = join(root, 'node_modules')
|
|
34
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- The root is the project directory the invoking CLI names.
|
|
35
|
+
const scoped = await readdir(join(modules, SCOPE)).catch(() => [])
|
|
36
|
+
const directories = [
|
|
37
|
+
...scoped.map((name) => join(modules, SCOPE, name)),
|
|
38
|
+
...UNSCOPED.map((name) => join(modules, name)),
|
|
39
|
+
]
|
|
40
|
+
const packages = await Promise.all(directories.map(readPackage))
|
|
41
|
+
return packages.filter((entry) => entry?.name && entry.version)
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
// The versions recorded by the last run, or null when this project has none.
|
|
4
|
+
export async function readVersionStamp(path) {
|
|
5
|
+
try {
|
|
6
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
7
|
+
return JSON.parse(await readFile(path, 'utf8'))
|
|
8
|
+
} catch {
|
|
9
|
+
return null
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
export function rebaseCruisePaths(options) {
|
|
4
|
+
if (options.paths === undefined) return undefined
|
|
5
|
+
// TypeScript preserves the declaring config's origin in this internal field.
|
|
6
|
+
// Never substitute process.cwd() when a compiler omits that metadata.
|
|
7
|
+
const origin = options.baseUrl ?? options.pathsBasePath
|
|
8
|
+
if (typeof origin !== 'string' || !isAbsolute(origin)) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
'Unsupported TypeScript paths origin: an absolute baseUrl or pathsBasePath is required',
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
if (
|
|
14
|
+
options.paths === null ||
|
|
15
|
+
typeof options.paths !== 'object' ||
|
|
16
|
+
Array.isArray(options.paths)
|
|
17
|
+
) {
|
|
18
|
+
throw new Error('TypeScript paths must be an alias map')
|
|
19
|
+
}
|
|
20
|
+
const paths = Object.create(null)
|
|
21
|
+
for (const [alias, targets] of Object.entries(options.paths)) {
|
|
22
|
+
if (!Array.isArray(targets) || targets.length === 0) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`TypeScript paths targets must be a nonempty array: ${alias}`,
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
paths[alias] = []
|
|
28
|
+
for (const target of targets) {
|
|
29
|
+
if (typeof target !== 'string' || target.length === 0) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`TypeScript paths target must be a nonempty string: ${alias}`,
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
paths[alias].push(resolve(origin, target))
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return options.baseUrl === undefined
|
|
38
|
+
? { paths }
|
|
39
|
+
: { baseUrl: options.baseUrl, paths }
|
|
40
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function reportAuditOutcome(advisories, outcome, level) {
|
|
2
|
+
for (const { advisory, entry } of outcome.waived) {
|
|
3
|
+
console.log(
|
|
4
|
+
`waived ${advisory.severity.padEnd(8)} ${advisory.github_advisory_id} ` +
|
|
5
|
+
`${advisory.module_name} (expires ${entry.expires})\n ${entry.reason}`,
|
|
6
|
+
)
|
|
7
|
+
}
|
|
8
|
+
for (const { advisory, entry } of outcome.stale) {
|
|
9
|
+
console.error(
|
|
10
|
+
`EXPIRED ${advisory.severity.padEnd(8)} ${advisory.github_advisory_id} ` +
|
|
11
|
+
`${advisory.module_name} (expired ${entry.expires})\n ${entry.reason}\n` +
|
|
12
|
+
' Re-check it, then renew the entry or remove it.',
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
for (const advisory of outcome.failures) {
|
|
16
|
+
console.error(
|
|
17
|
+
`FAIL ${advisory.severity.padEnd(8)} ${advisory.github_advisory_id} ` +
|
|
18
|
+
`${advisory.module_name} ${advisory.vulnerable_versions}\n` +
|
|
19
|
+
` patched in ${advisory.patched_versions} - ${advisory.url}\n` +
|
|
20
|
+
` via ${(advisory.findings?.[0]?.paths ?? []).slice(0, 2).join(', ')}`,
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
console.log(
|
|
24
|
+
`\nbaseline-audit: ${advisories.length} advisories, gate at ${level}: ` +
|
|
25
|
+
`${outcome.failures.length} unwaived, ${outcome.stale.length} expired, ${outcome.waived.length} waived.`,
|
|
26
|
+
)
|
|
27
|
+
return outcome.failures.length + outcome.stale.length > 0 ? 1 : 0
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { pnpmCommand } from './pnpmCommand.mjs'
|
|
3
|
+
import { readAuditReport } from './readAuditReport.mjs'
|
|
4
|
+
|
|
5
|
+
export function runPackageAudit() {
|
|
6
|
+
const [pnpm, ...args] = pnpmCommand()
|
|
7
|
+
return readAuditReport(
|
|
8
|
+
spawnSync(pnpm, [...args, 'audit', '--json'], {
|
|
9
|
+
encoding: 'utf8',
|
|
10
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
11
|
+
}),
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function runSynchronousCruise(operation, configPath) {
|
|
2
|
+
const result = operation(configPath)
|
|
3
|
+
if (
|
|
4
|
+
result !== null &&
|
|
5
|
+
(typeof result === 'object' || typeof result === 'function') &&
|
|
6
|
+
typeof result.then === 'function'
|
|
7
|
+
) {
|
|
8
|
+
throw new TypeError('withCruiseTsconfig requires a synchronous operation')
|
|
9
|
+
}
|
|
10
|
+
return result
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { compareVersions } from './compareVersions.mjs'
|
|
2
|
+
|
|
3
|
+
// The releases after `from` up to and including `to`, newest first.
|
|
4
|
+
export function sectionsBetween(sections, from, to) {
|
|
5
|
+
return sections
|
|
6
|
+
.filter(
|
|
7
|
+
({ version }) =>
|
|
8
|
+
compareVersions(version, from) > 0 && compareVersions(version, to) <= 0,
|
|
9
|
+
)
|
|
10
|
+
.toSorted((a, b) => compareVersions(b.version, a.version))
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const ACTION_HEADING = /^#{3,4} action required\s*$/i
|
|
2
|
+
const ANY_HEADING = /^#{1,4} /
|
|
3
|
+
|
|
4
|
+
// Separates the `### Action required` subsection of one release from the rest
|
|
5
|
+
// of its notes, so the printer can show what a person must do before what
|
|
6
|
+
// merely changed.
|
|
7
|
+
export function splitActionRequired(body) {
|
|
8
|
+
const action = []
|
|
9
|
+
const rest = []
|
|
10
|
+
let inAction = false
|
|
11
|
+
for (const line of body.split('\n')) {
|
|
12
|
+
if (ACTION_HEADING.test(line)) {
|
|
13
|
+
inAction = true
|
|
14
|
+
} else if (ANY_HEADING.test(line)) {
|
|
15
|
+
inAction = false
|
|
16
|
+
}
|
|
17
|
+
if (inAction && !ACTION_HEADING.test(line)) action.push(line)
|
|
18
|
+
else if (!inAction) rest.push(line)
|
|
19
|
+
}
|
|
20
|
+
return { action: action.join('\n').trim(), rest: rest.join('\n').trim() }
|
|
21
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AUDIT_LEVELS } from './auditLevels.mjs'
|
|
2
|
+
|
|
3
|
+
export function validateAuditReport(report) {
|
|
4
|
+
if (
|
|
5
|
+
report === null ||
|
|
6
|
+
typeof report !== 'object' ||
|
|
7
|
+
Array.isArray(report) ||
|
|
8
|
+
'error' in report
|
|
9
|
+
) {
|
|
10
|
+
throw new Error('pnpm audit returned an error or invalid report.')
|
|
11
|
+
}
|
|
12
|
+
if (
|
|
13
|
+
report.advisories === null ||
|
|
14
|
+
typeof report.advisories !== 'object' ||
|
|
15
|
+
Array.isArray(report.advisories)
|
|
16
|
+
) {
|
|
17
|
+
throw new Error('pnpm audit report is missing its advisory map.')
|
|
18
|
+
}
|
|
19
|
+
const metadata = report.metadata
|
|
20
|
+
if (
|
|
21
|
+
metadata === null ||
|
|
22
|
+
typeof metadata !== 'object' ||
|
|
23
|
+
Array.isArray(metadata)
|
|
24
|
+
) {
|
|
25
|
+
throw new Error('pnpm audit report is missing metadata.')
|
|
26
|
+
}
|
|
27
|
+
const counts = metadata.vulnerabilities
|
|
28
|
+
if (counts === null || typeof counts !== 'object' || Array.isArray(counts)) {
|
|
29
|
+
throw new Error('pnpm audit report is missing vulnerability counts.')
|
|
30
|
+
}
|
|
31
|
+
for (const key of [
|
|
32
|
+
'dependencies',
|
|
33
|
+
'devDependencies',
|
|
34
|
+
'optionalDependencies',
|
|
35
|
+
'totalDependencies',
|
|
36
|
+
]) {
|
|
37
|
+
if (!Number.isInteger(metadata[key]) || metadata[key] < 0)
|
|
38
|
+
throw new Error('Invalid audit dependency counts.')
|
|
39
|
+
}
|
|
40
|
+
for (const key of Object.keys(counts)) {
|
|
41
|
+
if (!AUDIT_LEVELS.includes(key))
|
|
42
|
+
throw new Error('Unknown audit vulnerability count severity.')
|
|
43
|
+
}
|
|
44
|
+
const observed = Object.create(null)
|
|
45
|
+
for (const level of AUDIT_LEVELS) {
|
|
46
|
+
if (!Number.isInteger(counts[level]) || counts[level] < 0)
|
|
47
|
+
throw new Error('Invalid audit vulnerability counts.')
|
|
48
|
+
observed[level] = 0
|
|
49
|
+
}
|
|
50
|
+
for (const advisory of Object.values(report.advisories)) {
|
|
51
|
+
if (
|
|
52
|
+
advisory === null ||
|
|
53
|
+
typeof advisory !== 'object' ||
|
|
54
|
+
Array.isArray(advisory)
|
|
55
|
+
) {
|
|
56
|
+
throw new Error('Invalid audit advisory.')
|
|
57
|
+
}
|
|
58
|
+
if (
|
|
59
|
+
!AUDIT_LEVELS.includes(advisory.severity) ||
|
|
60
|
+
typeof advisory.module_name !== 'string' ||
|
|
61
|
+
!advisory.module_name ||
|
|
62
|
+
!['number', 'string'].includes(typeof advisory.id)
|
|
63
|
+
) {
|
|
64
|
+
throw new Error('Invalid audit advisory identity or severity.')
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
advisory.github_advisory_id !== undefined &&
|
|
68
|
+
typeof advisory.github_advisory_id !== 'string'
|
|
69
|
+
) {
|
|
70
|
+
throw new Error('Invalid GitHub advisory identity.')
|
|
71
|
+
}
|
|
72
|
+
for (const key of ['title', 'url', 'vulnerable_versions']) {
|
|
73
|
+
if (typeof advisory[key] !== 'string')
|
|
74
|
+
throw new Error('Incomplete audit advisory.')
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
!Object.hasOwn(advisory, 'patched_versions') ||
|
|
78
|
+
(advisory.patched_versions !== null &&
|
|
79
|
+
typeof advisory.patched_versions !== 'string')
|
|
80
|
+
) {
|
|
81
|
+
throw new Error('Invalid patched-version metadata.')
|
|
82
|
+
}
|
|
83
|
+
if (!Array.isArray(advisory.findings))
|
|
84
|
+
throw new Error('Incomplete audit dependency findings.')
|
|
85
|
+
for (const finding of advisory.findings) {
|
|
86
|
+
if (
|
|
87
|
+
finding === null ||
|
|
88
|
+
typeof finding !== 'object' ||
|
|
89
|
+
!Array.isArray(finding.paths)
|
|
90
|
+
) {
|
|
91
|
+
throw new Error('Incomplete audit dependency paths.')
|
|
92
|
+
}
|
|
93
|
+
for (const path of finding.paths) {
|
|
94
|
+
if (typeof path !== 'string')
|
|
95
|
+
throw new Error('Invalid audit dependency path.')
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
observed[advisory.severity] += 1
|
|
99
|
+
}
|
|
100
|
+
for (const level of AUDIT_LEVELS) {
|
|
101
|
+
if (observed[level] !== counts[level])
|
|
102
|
+
throw new Error('Audit advisory counts do not match metadata.')
|
|
103
|
+
}
|
|
104
|
+
return report
|
|
105
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import { closeSync, openSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { readCruiseCompilerOptions } from './readCruiseCompilerOptions.mjs'
|
|
5
|
+
import { rebaseCruisePaths } from './rebaseCruisePaths.mjs'
|
|
6
|
+
import { runSynchronousCruise } from './runSynchronousCruise.mjs'
|
|
7
|
+
|
|
8
|
+
export function withCruiseTsconfig(
|
|
9
|
+
configPath,
|
|
10
|
+
operation,
|
|
11
|
+
{ requirePaths = false } = {},
|
|
12
|
+
) {
|
|
13
|
+
const original = resolve(configPath)
|
|
14
|
+
const compilerOptions = rebaseCruisePaths(readCruiseCompilerOptions(original))
|
|
15
|
+
if (!compilerOptions) {
|
|
16
|
+
if (requirePaths)
|
|
17
|
+
throw new Error(`No TypeScript paths reachable from ${original}`)
|
|
18
|
+
return runSynchronousCruise(operation, original)
|
|
19
|
+
}
|
|
20
|
+
// The same directory preserves TypeScript's implicit include location.
|
|
21
|
+
const generated = join(
|
|
22
|
+
dirname(original),
|
|
23
|
+
`.baseline-depcruise-${randomUUID()}.json`,
|
|
24
|
+
)
|
|
25
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- A random filename stays beside the parsed tsconfig; wx rejects preexisting paths.
|
|
26
|
+
const descriptor = openSync(generated, 'wx', 0o600)
|
|
27
|
+
try {
|
|
28
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- descriptor is the numeric fd from the exclusive open above, not a filename.
|
|
29
|
+
writeFileSync(
|
|
30
|
+
descriptor,
|
|
31
|
+
JSON.stringify({ extends: original, compilerOptions }),
|
|
32
|
+
)
|
|
33
|
+
return runSynchronousCruise(operation, generated)
|
|
34
|
+
} finally {
|
|
35
|
+
try {
|
|
36
|
+
closeSync(descriptor)
|
|
37
|
+
} finally {
|
|
38
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- This filename was created by the successful exclusive open and is cleaned in finally.
|
|
39
|
+
unlinkSync(generated)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import { rename, rm, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { isReplaceableStamp } from './isReplaceableStamp.mjs'
|
|
4
|
+
|
|
5
|
+
// Keys other ecosystems' tools keep in the same file are left as they are. A
|
|
6
|
+
// stamp that is a symlink or not a regular file is left alone, so a committed
|
|
7
|
+
// link cannot redirect the write; the file is replaced by renaming a temporary one.
|
|
8
|
+
export async function writeVersionStamp(path, stamp, installed) {
|
|
9
|
+
if (!(await isReplaceableStamp(path))) return
|
|
10
|
+
const next = { ...stamp }
|
|
11
|
+
for (const { name, version } of installed) next[name] = version
|
|
12
|
+
const sorted = Object.fromEntries(
|
|
13
|
+
Object.entries(next).toSorted(([a], [b]) => a.localeCompare(b)),
|
|
14
|
+
)
|
|
15
|
+
const temporary = `${path}.${randomUUID()}.tmp`
|
|
16
|
+
try {
|
|
17
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- A random name beside the stamp; written once, then renamed over it.
|
|
18
|
+
await writeFile(temporary, `${JSON.stringify(sorted, null, 2)}\n`, {
|
|
19
|
+
flag: 'wx',
|
|
20
|
+
})
|
|
21
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- Both paths were built above from the stamp path.
|
|
22
|
+
await rename(temporary, path)
|
|
23
|
+
} catch (error) {
|
|
24
|
+
await rm(temporary, { force: true })
|
|
25
|
+
throw error
|
|
26
|
+
}
|
|
27
|
+
}
|
package/jscpd.json
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"astro",
|
|
11
11
|
"rust",
|
|
12
12
|
"dart",
|
|
13
|
-
"swift"
|
|
13
|
+
"swift",
|
|
14
|
+
"go"
|
|
14
15
|
],
|
|
15
16
|
"gitignore": true,
|
|
16
17
|
"ignore": [
|
|
@@ -24,7 +25,11 @@
|
|
|
24
25
|
"**/*.freezed.dart",
|
|
25
26
|
"**/.build/**",
|
|
26
27
|
"**/build/**",
|
|
27
|
-
"**/.dart_tool/**"
|
|
28
|
+
"**/.dart_tool/**",
|
|
29
|
+
"**/vendor/**",
|
|
30
|
+
"**/testdata/**",
|
|
31
|
+
"**/*.pb.go",
|
|
32
|
+
"**/*_gen.go"
|
|
28
33
|
],
|
|
29
34
|
"reporters": ["console"]
|
|
30
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syntopica/quality-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Shared configuration for cross-file quality gates: knip, dependency-cruiser, type-coverage, jscpd, lefthook",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"bin": {
|
|
24
24
|
"baseline-audit": "bin/baseline-audit.mjs",
|
|
25
|
+
"baseline-changes": "bin/baseline-changes.mjs",
|
|
25
26
|
"baseline-deps-graph": "bin/baseline-deps-graph.mjs",
|
|
26
27
|
"baseline-dupes": "bin/baseline-dupes.mjs",
|
|
27
28
|
"baseline-env-init": "bin/baseline-env-init.mjs",
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
"jscpd.json",
|
|
38
39
|
"oxlintrc.json",
|
|
39
40
|
"src",
|
|
40
|
-
"tsconfig.json"
|
|
41
|
+
"tsconfig.json",
|
|
42
|
+
"CHANGELOG.md"
|
|
41
43
|
],
|
|
42
44
|
"exports": {
|
|
43
45
|
".": "./src/index.ts",
|
|
@@ -48,7 +50,11 @@
|
|
|
48
50
|
"./jscpd": "./jscpd.json",
|
|
49
51
|
"./commitlint": "./src/commitlint.ts",
|
|
50
52
|
"./oxlint": "./oxlintrc.json",
|
|
51
|
-
"./pnpm-command": "./bin/pnpmCommand.mjs"
|
|
53
|
+
"./pnpm-command": "./bin/pnpmCommand.mjs",
|
|
54
|
+
"./cruise-tsconfig": {
|
|
55
|
+
"types": "./bin/withCruiseTsconfig.d.mts",
|
|
56
|
+
"default": "./bin/withCruiseTsconfig.mjs"
|
|
57
|
+
}
|
|
52
58
|
},
|
|
53
59
|
"peerDependencies": {
|
|
54
60
|
"@commitlint/config-conventional": ">=21.0.0",
|
|
@@ -73,16 +79,16 @@
|
|
|
73
79
|
},
|
|
74
80
|
"devDependencies": {
|
|
75
81
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
76
|
-
"@syntopica/eslint-config": "0.10.
|
|
77
|
-
"@types/node": "^26.6.
|
|
82
|
+
"@syntopica/eslint-config": "0.10.2",
|
|
83
|
+
"@types/node": "^26.6.6",
|
|
78
84
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
79
|
-
"dependency-cruiser": "^18.
|
|
80
|
-
"eslint": "^10.
|
|
81
|
-
"eslint-plugin-regexp": "^3.3.
|
|
82
|
-
"knip": "^6.
|
|
85
|
+
"dependency-cruiser": "^18.9.0",
|
|
86
|
+
"eslint": "^10.15.0",
|
|
87
|
+
"eslint-plugin-regexp": "^3.3.3",
|
|
88
|
+
"knip": "^6.47.0",
|
|
83
89
|
"publint": "^0.3.25",
|
|
84
90
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
85
|
-
"vitest": "^5.
|
|
91
|
+
"vitest": "^5.1.1"
|
|
86
92
|
},
|
|
87
93
|
"dependencies": {
|
|
88
94
|
"tinyglobby": "^0.2.17"
|
|
@@ -80,7 +80,10 @@ const REPO_SCOPE_RULES: IForbiddenRuleType[] = [
|
|
|
80
80
|
comment:
|
|
81
81
|
'A devDependency imported by shipped code will be missing at runtime for consumers.',
|
|
82
82
|
from: { path: '^packages/[^/]+/src/', pathNot: '\\.(test|spec)\\.ts$' },
|
|
83
|
-
to: {
|
|
83
|
+
to: {
|
|
84
|
+
dependencyTypes: ['npm-dev'],
|
|
85
|
+
dependencyTypesNot: ['type-only', 'npm-peer'],
|
|
86
|
+
},
|
|
84
87
|
},
|
|
85
88
|
{
|
|
86
89
|
name: 'no-deprecated-core',
|
package/src/knip-framework.ts
CHANGED
|
@@ -70,7 +70,7 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
70
70
|
},
|
|
71
71
|
nuxt: {
|
|
72
72
|
entry: ['app/**/*.vue!', 'server/**/*.ts!', 'nuxt.config.*'],
|
|
73
|
-
project: ['app/**/*.{ts,vue}!', 'server/**/*.ts!'],
|
|
73
|
+
project: ['app/**/*.{ts,vue,css}!', 'server/**/*.ts!'],
|
|
74
74
|
includeEntryExports: false,
|
|
75
75
|
},
|
|
76
76
|
// TanStack Start has no index.html and no src/main.tsx: the router is the
|
|
@@ -94,7 +94,7 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
94
94
|
// src/main.tsx, not src/main.ts; keep both extensions so a plain-TS
|
|
95
95
|
// Tauri frontend also matches.
|
|
96
96
|
entry: ['src/main.{ts,tsx}!', 'vite.config.*'],
|
|
97
|
-
project: ['src/**/*.{ts,tsx}!'],
|
|
97
|
+
project: ['src/**/*.{ts,tsx,css}!'],
|
|
98
98
|
includeEntryExports: false,
|
|
99
99
|
},
|
|
100
100
|
'ts-package': {
|
|
@@ -106,12 +106,12 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
106
106
|
// well was a "Remove redundant entry pattern" hint in both Vite templates.
|
|
107
107
|
'vite-react': {
|
|
108
108
|
entry: ['index.html!', 'vite.config.*'],
|
|
109
|
-
project: ['src/**/*.{ts,tsx}!'],
|
|
109
|
+
project: ['src/**/*.{ts,tsx,css}!'],
|
|
110
110
|
includeEntryExports: false,
|
|
111
111
|
},
|
|
112
112
|
'vite-vue': {
|
|
113
113
|
entry: ['index.html!', 'vite.config.*'],
|
|
114
|
-
project: ['src/**/*.{ts,vue}!'],
|
|
114
|
+
project: ['src/**/*.{ts,vue,css}!'],
|
|
115
115
|
includeEntryExports: false,
|
|
116
116
|
},
|
|
117
117
|
}
|