@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/src/knip.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
|
|
|
10
10
|
import { matchedPresetPatterns } from './matchedPresetPatterns'
|
|
11
11
|
import { peersOfListedDependencies } from './peersOfListedDependencies'
|
|
12
12
|
import { PRODUCTION_PROJECT_EXCLUSIONS } from './PRODUCTION_PROJECT_EXCLUSIONS'
|
|
13
|
+
import { readInstalledDependencyNames } from './readInstalledDependencyNames'
|
|
13
14
|
import { readListedDependencies } from './readListedDependencies'
|
|
14
15
|
import { runnerDependenciesToIgnore } from './runnerDependenciesToIgnore'
|
|
15
16
|
|
|
@@ -103,6 +104,9 @@ export const createKnipConfig = (options: {
|
|
|
103
104
|
}): KnipConfiguration => {
|
|
104
105
|
const cwd = options.cwd ?? process.cwd()
|
|
105
106
|
const hostedPeers = peersOfListedDependencies(cwd)
|
|
107
|
+
const sharedConfigDependencies = new Set(
|
|
108
|
+
readInstalledDependencyNames(cwd, '@syntopica/eslint-config'),
|
|
109
|
+
)
|
|
106
110
|
const usesSharedEslint = readListedDependencies(cwd).includes(
|
|
107
111
|
'@syntopica/eslint-config',
|
|
108
112
|
)
|
|
@@ -138,10 +142,15 @@ export const createKnipConfig = (options: {
|
|
|
138
142
|
ignoreExportsUsedInFile: true,
|
|
139
143
|
ignoreBinaries: ['gitleaks', ...(options.ignoreBinaries ?? [])],
|
|
140
144
|
ignoreDependencies: [
|
|
141
|
-
...runnerDependenciesToIgnore(cwd)
|
|
145
|
+
...runnerDependenciesToIgnore(cwd).filter(
|
|
146
|
+
(dependency) => !hostedPeers.has(dependency),
|
|
147
|
+
),
|
|
142
148
|
...(FRAMEWORK_RUNTIME_PACKAGES[options.framework] ?? []),
|
|
143
149
|
...ESLINT_PEER_DEPENDENCIES.filter(
|
|
144
|
-
(dependency) =>
|
|
150
|
+
(dependency) =>
|
|
151
|
+
usesSharedEslint &&
|
|
152
|
+
!hostedPeers.has(dependency) &&
|
|
153
|
+
!sharedConfigDependencies.has(dependency),
|
|
145
154
|
),
|
|
146
155
|
...(options.ignoreDependencies ?? []),
|
|
147
156
|
],
|
package/src/lefthook.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { LefthookOptions } from './LefthookOptions'
|
|
2
|
+
import { TADU_BACKLOG_PATHS } from './TADU_BACKLOG_PATHS'
|
|
3
|
+
|
|
1
4
|
/** Shape of a lefthook.yml configuration document. */
|
|
2
5
|
type LefthookConfig = Record<string, unknown>
|
|
3
6
|
|
|
@@ -13,41 +16,62 @@ type LefthookConfig = Record<string, unknown>
|
|
|
13
16
|
* `lefthook.yml` files by hand — see the comment at the top of those files —
|
|
14
17
|
* and is what create-baseline uses to generate `lefthook.yml` for new
|
|
15
18
|
* projects it scaffolds.
|
|
19
|
+
*
|
|
20
|
+
* With `tadu`, the file checks exclude the backlog (tadu writes JSON that
|
|
21
|
+
* prettier rejects) and a `backlog` command runs `tadu doctor .` on it,
|
|
22
|
+
* skipped when tadu is not installed.
|
|
16
23
|
*/
|
|
17
|
-
export const createLefthookConfig = (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
export const createLefthookConfig = ({
|
|
25
|
+
tadu = false,
|
|
26
|
+
}: LefthookOptions = {}): LefthookConfig => {
|
|
27
|
+
const exclude = tadu ? { exclude: TADU_BACKLOG_PATHS } : {}
|
|
28
|
+
return {
|
|
29
|
+
'pre-commit': {
|
|
30
|
+
parallel: true,
|
|
31
|
+
commands: {
|
|
32
|
+
'lint:fast': {
|
|
33
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}',
|
|
34
|
+
...exclude,
|
|
35
|
+
run: 'pnpm exec oxlint --deny-warnings {staged_files}',
|
|
36
|
+
},
|
|
37
|
+
lint: {
|
|
38
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}',
|
|
39
|
+
...exclude,
|
|
40
|
+
run: 'pnpm exec eslint --max-warnings 0 --no-warn-ignored {staged_files}',
|
|
41
|
+
},
|
|
42
|
+
format: {
|
|
43
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs,json,md,css,yml,yaml}',
|
|
44
|
+
...exclude,
|
|
45
|
+
run: 'pnpm exec prettier --check {staged_files}',
|
|
46
|
+
},
|
|
47
|
+
...(tadu
|
|
48
|
+
? {
|
|
49
|
+
backlog: {
|
|
50
|
+
glob: TADU_BACKLOG_PATHS,
|
|
51
|
+
skip: [{ run: '! command -v tadu' }],
|
|
52
|
+
run: 'tadu doctor .',
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
: {}),
|
|
32
56
|
},
|
|
33
57
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
// The release tooling reads the commit type to pick the semver bump and to
|
|
59
|
+
// build the changelog, so a mistyped subject is a silent release defect.
|
|
60
|
+
// This is the only place it can be caught: by the time the tag is cut the
|
|
61
|
+
// message is already history.
|
|
62
|
+
'commit-msg': {
|
|
63
|
+
commands: {
|
|
64
|
+
commitlint: {
|
|
65
|
+
run: 'pnpm exec commitlint --edit {1}',
|
|
66
|
+
},
|
|
43
67
|
},
|
|
44
68
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
'pre-push': {
|
|
70
|
+
commands: {
|
|
71
|
+
secrets: {
|
|
72
|
+
run: 'gitleaks detect --no-banner --redact',
|
|
73
|
+
},
|
|
50
74
|
},
|
|
51
75
|
},
|
|
52
|
-
}
|
|
53
|
-
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/** Direct runtime dependencies owned by an installed package; unknown metadata gives none. */
|
|
5
|
+
export function readInstalledDependencyNames(
|
|
6
|
+
cwd: string,
|
|
7
|
+
name: string,
|
|
8
|
+
): string[] {
|
|
9
|
+
try {
|
|
10
|
+
const manifest = JSON.parse(
|
|
11
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- a listed dependency's manifest under the project's node_modules
|
|
12
|
+
readFileSync(join(cwd, 'node_modules', name, 'package.json'), 'utf8'),
|
|
13
|
+
) as { dependencies?: Record<string, unknown> }
|
|
14
|
+
const dependencies = manifest.dependencies
|
|
15
|
+
if (
|
|
16
|
+
!dependencies ||
|
|
17
|
+
typeof dependencies !== 'object' ||
|
|
18
|
+
Array.isArray(dependencies)
|
|
19
|
+
)
|
|
20
|
+
return []
|
|
21
|
+
const names: string[] = []
|
|
22
|
+
for (const [dependency, version] of Object.entries(dependencies)) {
|
|
23
|
+
if (typeof version === 'string' && version.trim().length > 0)
|
|
24
|
+
names.push(dependency)
|
|
25
|
+
}
|
|
26
|
+
return names
|
|
27
|
+
} catch {
|
|
28
|
+
return []
|
|
29
|
+
}
|
|
30
|
+
}
|