@syntopica/quality-config 0.13.0 → 0.13.1
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/package.json +8 -6
- package/src/RUNNER_BINARIES.ts +12 -0
- package/src/existingEntries.ts +19 -0
- package/src/knip.ts +12 -23
- package/src/readScriptWords.ts +23 -0
- package/src/runnerDependenciesToIgnore.ts +20 -0
- package/tsconfig.json +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syntopica/quality-config",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
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",
|
|
@@ -80,14 +80,16 @@
|
|
|
80
80
|
"eslint-plugin-regexp": "^3.3.1",
|
|
81
81
|
"knip": "^6.40.0",
|
|
82
82
|
"publint": "^0.3.25",
|
|
83
|
-
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
83
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
84
|
+
"vitest": "^5.0.3"
|
|
84
85
|
},
|
|
85
86
|
"scripts": {
|
|
86
87
|
"fix": "pnpm run lint:fix",
|
|
87
|
-
"lint": "eslint src bin --max-warnings 0",
|
|
88
|
-
"lint:fix": "eslint src bin --fix",
|
|
89
|
-
"lint:suppress": "eslint src bin --suppress-all",
|
|
90
|
-
"lint:prune": "eslint src bin --prune-suppressions",
|
|
88
|
+
"lint": "eslint src bin tests --max-warnings 0",
|
|
89
|
+
"lint:fix": "eslint src bin tests --fix",
|
|
90
|
+
"lint:suppress": "eslint src bin tests --suppress-all",
|
|
91
|
+
"lint:prune": "eslint src bin tests --prune-suppressions",
|
|
92
|
+
"test": "vitest run",
|
|
91
93
|
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
92
94
|
"publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm internal-resolution-error"
|
|
93
95
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The binaries each runner dependency provides, keyed by package name. A
|
|
3
|
+
* script that names one of them directly is something knip resolves on its
|
|
4
|
+
* own, so the package needs no `ignoreDependencies` entry; a script that only
|
|
5
|
+
* names the `baseline-*` runner hides it.
|
|
6
|
+
*/
|
|
7
|
+
export const RUNNER_BINARIES: Record<string, string[]> = {
|
|
8
|
+
jscpd: ['jscpd'],
|
|
9
|
+
'type-coverage': ['type-coverage'],
|
|
10
|
+
'dependency-cruiser': ['depcruise', 'dependency-cruise'],
|
|
11
|
+
lefthook: ['lefthook'],
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
const GLOB_CHARACTERS = /[*?{}[\]!]/u
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Drops the literal entry paths that do not exist in `cwd`; globs are kept,
|
|
8
|
+
* since whether they match is knip's call. Used for a preset's default entry
|
|
9
|
+
* when the caller names its own: a CLI package whose entry is
|
|
10
|
+
* `src/cli/main.ts` has no `src/index.ts`, and listing it is a "Refine entry
|
|
11
|
+
* pattern (no matches)" hint the caller cannot silence.
|
|
12
|
+
*/
|
|
13
|
+
export const existingEntries = (entries: string[], cwd: string): string[] =>
|
|
14
|
+
entries.filter(
|
|
15
|
+
(entry) =>
|
|
16
|
+
GLOB_CHARACTERS.test(entry) ||
|
|
17
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- the entry is the preset's own literal, resolved against the project root
|
|
18
|
+
existsSync(join(cwd, entry)),
|
|
19
|
+
)
|
package/src/knip.ts
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
// config without casting it first.
|
|
6
6
|
import type { KnipConfiguration } from 'knip'
|
|
7
7
|
|
|
8
|
+
import { existingEntries } from './existingEntries'
|
|
8
9
|
import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
|
|
10
|
+
import { runnerDependenciesToIgnore } from './runnerDependenciesToIgnore'
|
|
9
11
|
|
|
10
12
|
// Every template installs these as peer dependencies of
|
|
11
13
|
// @syntopica/eslint-config: the config factories (base.ts and friends)
|
|
@@ -30,26 +32,6 @@ import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
|
|
|
30
32
|
// not a gate failure. Do not filter the list consumer-side to silence it: the
|
|
31
33
|
// filter would drift the moment this list changes, and the cost of being wrong
|
|
32
34
|
// is a dependency that silently stops being checked.
|
|
33
|
-
// The tools this package's own runners spawn through `pnpm exec`:
|
|
34
|
-
// `baseline-dupes` spawns `jscpd`, `baseline-type-coverage` spawns
|
|
35
|
-
// `type-coverage`, `baseline-deps-graph` spawns `depcruise`,
|
|
36
|
-
// `baseline-hooks-install` spawns `lefthook`. A project that
|
|
37
|
-
// wires the runner into its scripts never names the underlying tool anywhere
|
|
38
|
-
// knip can see, so knip reports a real dependency as unused. Found in
|
|
39
|
-
// a consumer the moment its `type-coverage` script became
|
|
40
|
-
// `baseline-type-coverage`.
|
|
41
|
-
//
|
|
42
|
-
// `dependency-cruiser` is on the list even though a project calling
|
|
43
|
-
// `depcruise` directly resolves it fine: there knip emits a `Remove from
|
|
44
|
-
// ignoreDependencies` hint, which is a hint and not a gate failure, and the
|
|
45
|
-
// cost of leaving it off is a real dependency silently reported as dead.
|
|
46
|
-
const BASELINE_RUNNER_DEPENDENCIES = [
|
|
47
|
-
'jscpd',
|
|
48
|
-
'type-coverage',
|
|
49
|
-
'dependency-cruiser',
|
|
50
|
-
'lefthook',
|
|
51
|
-
]
|
|
52
|
-
|
|
53
35
|
const ESLINT_PEER_DEPENDENCIES = [
|
|
54
36
|
'@eslint/js',
|
|
55
37
|
'eslint-config-prettier',
|
|
@@ -104,7 +86,9 @@ export const createKnipConfig = (options: {
|
|
|
104
86
|
/**
|
|
105
87
|
* Extra entry globs, merged with the framework preset's `entry`. Same
|
|
106
88
|
* reasoning as `project`, for a root nobody's plugin registers - a worker,
|
|
107
|
-
* a CLI, a script the app spawns.
|
|
89
|
+
* a CLI, a script the app spawns. A preset entry that is a literal path
|
|
90
|
+
* missing from the project (`ts-package`'s `src/index.ts` in a CLI package)
|
|
91
|
+
* is dropped once this is set, so it cannot become a "no matches" hint.
|
|
108
92
|
*/
|
|
109
93
|
entry?: string[]
|
|
110
94
|
/**
|
|
@@ -122,12 +106,17 @@ export const createKnipConfig = (options: {
|
|
|
122
106
|
* only this does.
|
|
123
107
|
*/
|
|
124
108
|
drizzle?: false
|
|
109
|
+
/** The project root, for the checks that read it. Defaults to the cwd. */
|
|
110
|
+
cwd?: string
|
|
125
111
|
}): KnipConfiguration => {
|
|
112
|
+
const cwd = options.cwd ?? process.cwd()
|
|
126
113
|
const { entry, project, includeEntryExports } =
|
|
127
114
|
FRAMEWORK_ENTRIES[options.framework]
|
|
128
115
|
|
|
129
116
|
return {
|
|
130
|
-
entry:
|
|
117
|
+
entry: options.entry
|
|
118
|
+
? [...existingEntries(entry, cwd), ...options.entry]
|
|
119
|
+
: entry,
|
|
131
120
|
project: [...project, ...(options.project ?? [])],
|
|
132
121
|
...(options.ignore ? { ignore: options.ignore } : {}),
|
|
133
122
|
...(options.drizzle === false ? { drizzle: false } : {}),
|
|
@@ -151,7 +140,7 @@ export const createKnipConfig = (options: {
|
|
|
151
140
|
ignoreExportsUsedInFile: true,
|
|
152
141
|
ignoreBinaries: ['gitleaks', ...(options.ignoreBinaries ?? [])],
|
|
153
142
|
ignoreDependencies: [
|
|
154
|
-
...
|
|
143
|
+
...runnerDependenciesToIgnore(cwd),
|
|
155
144
|
...ESLINT_PEER_DEPENDENCIES,
|
|
156
145
|
...(options.ignoreDependencies ?? []),
|
|
157
146
|
],
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every word of every `package.json` script in `cwd`, so a caller can ask
|
|
6
|
+
* whether a binary is named anywhere. Unreadable or malformed manifests give
|
|
7
|
+
* an empty set: the caller then ignores the dependency, which is the safe side.
|
|
8
|
+
*/
|
|
9
|
+
export const readScriptWords = (cwd: string): Set<string> => {
|
|
10
|
+
try {
|
|
11
|
+
const manifest: unknown = JSON.parse(
|
|
12
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- fixed file name under the project root
|
|
13
|
+
readFileSync(join(cwd, 'package.json'), 'utf8'),
|
|
14
|
+
)
|
|
15
|
+
const scripts = (manifest as { scripts?: Record<string, unknown> }).scripts
|
|
16
|
+
const text = Object.values(scripts ?? {})
|
|
17
|
+
.filter((script): script is string => typeof script === 'string')
|
|
18
|
+
.join('\n')
|
|
19
|
+
return new Set(text.split(/[\s;&|()]+/u).filter(Boolean))
|
|
20
|
+
} catch {
|
|
21
|
+
return new Set()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RUNNER_BINARIES } from './RUNNER_BINARIES'
|
|
2
|
+
import { readScriptWords } from './readScriptWords'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The runner dependencies knip cannot see used, and so must be ignored.
|
|
6
|
+
*
|
|
7
|
+
* `baseline-dupes`, `baseline-type-coverage`, `baseline-deps-graph` and
|
|
8
|
+
* `baseline-hooks-install` spawn `jscpd`, `type-coverage`, `depcruise` and
|
|
9
|
+
* `lefthook` themselves, which hides a real dependency from knip. A project
|
|
10
|
+
* that also names the binary in a script (`"prepare": "lefthook install"`,
|
|
11
|
+
* `"deps:graph": "depcruise src"`) lets knip resolve it, and ignoring it then
|
|
12
|
+
* becomes a permanent `Remove from ignoreDependencies` hint no consumer can
|
|
13
|
+
* silence. So only the packages no script names directly are ignored.
|
|
14
|
+
*/
|
|
15
|
+
export const runnerDependenciesToIgnore = (cwd: string): string[] => {
|
|
16
|
+
const words = readScriptWords(cwd)
|
|
17
|
+
return Object.entries(RUNNER_BINARIES)
|
|
18
|
+
.filter(([, binaries]) => !binaries.some((binary) => words.has(binary)))
|
|
19
|
+
.map(([dependency]) => dependency)
|
|
20
|
+
}
|