@syntopica/quality-config 0.11.0 → 0.12.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/PUBLIC_API.md +3 -3
- package/README.md +1 -1
- package/bin/baseline-audit.mjs +3 -1
- package/bin/baseline-deps-graph.mjs +5 -1
- package/bin/baseline-dupes.mjs +3 -1
- package/bin/baseline-type-coverage.mjs +23 -10
- package/bin/pnpmCommand.d.mts +7 -0
- package/bin/pnpmCommand.mjs +75 -0
- package/package.json +22 -22
- package/src/dependency-cruiser.ts +9 -2
- package/src/knip-framework.ts +23 -2
- package/src/knip.ts +9 -6
package/PUBLIC_API.md
CHANGED
|
@@ -56,9 +56,9 @@ file plus a runner rather than as a factory: the config is read in place, never
|
|
|
56
56
|
copied into the consuming repo.
|
|
57
57
|
|
|
58
58
|
`baseline-type-coverage` takes the directories to search and `--at-least <n>`, a
|
|
59
|
-
repo-local
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
repo-local bar: below the shared threshold for a project still climbing toward
|
|
60
|
+
it, above it to pin a project that has passed it (up to 100). It refuses a value
|
|
61
|
+
equal to the shared threshold, which would only restate it.
|
|
62
62
|
|
|
63
63
|
`--also-ignore <patterns>` adds ignore patterns **on top of** the shared list.
|
|
64
64
|
jscpd's own `--ignore` replaces that list instead, so without this a project
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ files/exports/dependencies (knip), module boundaries and dependency cycles
|
|
|
7
7
|
|
|
8
8
|
- **Public API (semver):** see [PUBLIC_API.md](./PUBLIC_API.md).
|
|
9
9
|
- **Platform decisions:**
|
|
10
|
-
[engineering-baseline/docs/platform-decisions.md](https://github.com/
|
|
10
|
+
[engineering-baseline/docs/platform-decisions.md](https://github.com/syntopica/codeality/blob/main/docs/platform-decisions.md).
|
|
11
11
|
|
|
12
12
|
## Requirements
|
|
13
13
|
|
package/bin/baseline-audit.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import { spawnSync } from 'node:child_process'
|
|
|
26
26
|
import { readFile } from 'node:fs/promises'
|
|
27
27
|
import { resolve } from 'node:path'
|
|
28
28
|
import { argv, cwd, exit } from 'node:process'
|
|
29
|
+
import { pnpmCommand } from './pnpmCommand.mjs'
|
|
29
30
|
|
|
30
31
|
const LEVELS = ['info', 'low', 'moderate', 'high', 'critical']
|
|
31
32
|
const DEFAULT_FILE = '.baseline-advisories.json'
|
|
@@ -48,7 +49,8 @@ const allowlist = await readAllowlist(resolve(root, flag('file', DEFAULT_FILE)))
|
|
|
48
49
|
|
|
49
50
|
// `pnpm audit` exits non-zero when it finds anything, which is the whole
|
|
50
51
|
// point, so its status is not an error condition here - the JSON is.
|
|
51
|
-
const
|
|
52
|
+
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
53
|
+
const result = spawnSync(pnpm, [...pnpmArgs, 'audit', '--json'], {
|
|
52
54
|
encoding: 'utf8',
|
|
53
55
|
maxBuffer: 64 * 1024 * 1024,
|
|
54
56
|
})
|
|
@@ -15,6 +15,7 @@ import { spawnSync } from 'node:child_process'
|
|
|
15
15
|
import { existsSync, readdirSync } from 'node:fs'
|
|
16
16
|
import { relative, resolve } from 'node:path'
|
|
17
17
|
import { argv, cwd, exit } from 'node:process'
|
|
18
|
+
import { pnpmCommand } from './pnpmCommand.mjs'
|
|
18
19
|
|
|
19
20
|
const DEFAULT_SOURCES = ['src', 'app', 'server', 'lib']
|
|
20
21
|
const SKIPPED_DIRECTORIES = new Set([
|
|
@@ -69,6 +70,8 @@ function findWorkspaces(root, depth = 0) {
|
|
|
69
70
|
return found
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
74
|
+
|
|
72
75
|
const failed = []
|
|
73
76
|
for (const workspace of findWorkspaces(cwd())) {
|
|
74
77
|
const present = sourceDirectories.filter((directory) =>
|
|
@@ -79,8 +82,9 @@ for (const workspace of findWorkspaces(cwd())) {
|
|
|
79
82
|
const label = relative(cwd(), workspace) || '.'
|
|
80
83
|
console.log(`deps-graph: cruising ${label} (${present.join(', ')})`)
|
|
81
84
|
const result = spawnSync(
|
|
82
|
-
|
|
85
|
+
pnpm,
|
|
83
86
|
[
|
|
87
|
+
...pnpmArgs,
|
|
84
88
|
'exec',
|
|
85
89
|
'depcruise',
|
|
86
90
|
...present,
|
package/bin/baseline-dupes.mjs
CHANGED
|
@@ -38,6 +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 { pnpmCommand } from './pnpmCommand.mjs'
|
|
41
42
|
|
|
42
43
|
const PACKAGED_CONFIG = fileURLToPath(new URL('../jscpd.json', import.meta.url))
|
|
43
44
|
|
|
@@ -108,7 +109,8 @@ if (found.value !== -1) args[found.value] = config
|
|
|
108
109
|
else if (found.inline !== -1) args[found.inline] = `--config=${config}`
|
|
109
110
|
else args.push('--config', config)
|
|
110
111
|
|
|
111
|
-
const
|
|
112
|
+
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
113
|
+
const result = spawnSync(pnpm, [...pnpmArgs, 'exec', 'jscpd', ...args], {
|
|
112
114
|
stdio: 'inherit',
|
|
113
115
|
})
|
|
114
116
|
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
// to `any` is the point. `--strict` is on, so an `any` reached through a
|
|
13
13
|
// generic argument counts as uncovered.
|
|
14
14
|
//
|
|
15
|
-
// `--at-least <n>`
|
|
16
|
-
//
|
|
17
|
-
// so the choice is an unenforced gate or none. Freezing at the
|
|
18
|
-
// makes coverage a ratchet - it cannot fall - and the number in
|
|
19
|
-
// is the debt, visible in every diff that changes it. Raise it as
|
|
20
|
-
// go; never lower it to get green.
|
|
15
|
+
// `--at-least <n>` sets the bar for one repo. Below the shared threshold it
|
|
16
|
+
// exists for adoption: a codebase under it cannot wire this gate at all
|
|
17
|
+
// otherwise, so the choice is an unenforced gate or none. Freezing at the
|
|
18
|
+
// measured value makes coverage a ratchet - it cannot fall - and the number in
|
|
19
|
+
// package.json is the debt, visible in every diff that changes it. Raise it as
|
|
20
|
+
// the `any`s go; never lower it to get green. Above the shared threshold it
|
|
21
|
+
// pins a repo that has already climbed past it (to 100, say), so its coverage
|
|
22
|
+
// cannot slide back to the shared floor unnoticed.
|
|
21
23
|
//
|
|
22
24
|
// `--ignore-files <glob>` adds to the two exclusions above. Repeatable. It is
|
|
23
25
|
// for generated or vendored code the project already excludes elsewhere -
|
|
@@ -27,12 +29,14 @@
|
|
|
27
29
|
// baseline-type-coverage # every workspace under the cwd
|
|
28
30
|
// baseline-type-coverage packages apps # only under these directories
|
|
29
31
|
// baseline-type-coverage --at-least 97 # freeze below the shared bar
|
|
32
|
+
// baseline-type-coverage --at-least 100 # pin above it
|
|
30
33
|
// baseline-type-coverage --ignore-files 'migrations/**'
|
|
31
34
|
import { spawnSync } from 'node:child_process'
|
|
32
35
|
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
33
36
|
import { dirname, relative, resolve } from 'node:path'
|
|
34
37
|
import { argv, cwd, exit } from 'node:process'
|
|
35
38
|
import { fileURLToPath } from 'node:url'
|
|
39
|
+
import { pnpmCommand } from './pnpmCommand.mjs'
|
|
36
40
|
|
|
37
41
|
const IGNORED_FILES = ['.next/**', '.nuxt/**', 'tests/**', '**/*.test.*']
|
|
38
42
|
const SKIPPED_DIRECTORIES = new Set([
|
|
@@ -73,10 +77,16 @@ if (atLeastIndex !== -1 && !/^\d+(?:\.\d+)?$/.test(override ?? '')) {
|
|
|
73
77
|
)
|
|
74
78
|
exit(1)
|
|
75
79
|
}
|
|
76
|
-
if (override !== undefined && Number(override) >
|
|
80
|
+
if (override !== undefined && Number(override) > 100) {
|
|
77
81
|
console.error(
|
|
78
|
-
`baseline-type-coverage: --at-least ${override} is above
|
|
79
|
-
|
|
82
|
+
`baseline-type-coverage: --at-least ${override} is above 100 percent.`,
|
|
83
|
+
)
|
|
84
|
+
exit(1)
|
|
85
|
+
}
|
|
86
|
+
if (override !== undefined && Number(override) === Number(declared[1])) {
|
|
87
|
+
console.error(
|
|
88
|
+
`baseline-type-coverage: --at-least ${override} restates the shared ` +
|
|
89
|
+
`threshold. Drop the flag.`,
|
|
80
90
|
)
|
|
81
91
|
exit(1)
|
|
82
92
|
}
|
|
@@ -207,12 +217,15 @@ if (!workspaces.length) {
|
|
|
207
217
|
exit(1)
|
|
208
218
|
}
|
|
209
219
|
|
|
220
|
+
const [pnpm, ...pnpmArgs] = pnpmCommand()
|
|
221
|
+
|
|
210
222
|
let failed = false
|
|
211
223
|
for (const workspace of workspaces) {
|
|
212
224
|
const label = relative(cwd(), workspace.project ?? workspace.directory) || '.'
|
|
213
225
|
const result = spawnSync(
|
|
214
|
-
|
|
226
|
+
pnpm,
|
|
215
227
|
[
|
|
228
|
+
...pnpmArgs,
|
|
216
229
|
'exec',
|
|
217
230
|
'type-coverage',
|
|
218
231
|
'--strict',
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The argv prefix that runs pnpm: `[command, ...leadingArguments]`.
|
|
3
|
+
*
|
|
4
|
+
* Spread it ahead of pnpm's own arguments, so a machine whose `pnpm` on PATH
|
|
5
|
+
* is the shebang-less pnpm placeholder is still reachable from Node.
|
|
6
|
+
*/
|
|
7
|
+
export declare function pnpmCommand(): [string, ...string[]]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// How to spawn pnpm from a Node program, on a machine where `pnpm` on PATH is
|
|
2
|
+
// not executable by the kernel.
|
|
3
|
+
//
|
|
4
|
+
// pnpm 11 puts a shebang-less `sh` script at its bin path and replaces it with
|
|
5
|
+
// the native binary during installation. The file says so itself: a bin shim
|
|
6
|
+
// and a shell both retry it under `sh`, "Apple's libc does not, so on macOS a
|
|
7
|
+
// program that spawns this path itself gets ENOEXEC". A Homebrew install that
|
|
8
|
+
// never ran that replacement leaves the placeholder in place, and then every
|
|
9
|
+
// `spawnSync('pnpm', ...)` here fails with `spawnSync pnpm ENOEXEC` - measured
|
|
10
|
+
// on 2026-09-21, where it surfaced as `type-coverage: FAIL .` with no output
|
|
11
|
+
// on a repository at 99.82% coverage, and as `baseline-dupes: could not run
|
|
12
|
+
// jscpd`. The gate reported the subject as broken when the subject was fine.
|
|
13
|
+
//
|
|
14
|
+
// So the runner resolves an entry point Node can always execute:
|
|
15
|
+
// 1. `npm_execpath`, which pnpm sets for its own scripts and which points at
|
|
16
|
+
// a JavaScript file, run under this Node.
|
|
17
|
+
// 2. otherwise the `pnpm` on PATH, if the kernel can exec it - a shebang or
|
|
18
|
+
// a real binary.
|
|
19
|
+
// 3. otherwise the `bin/pnpm.mjs` the placeholder itself hands over to.
|
|
20
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'
|
|
21
|
+
import { delimiter, dirname, join } from 'node:path'
|
|
22
|
+
import { env, execPath, platform } from 'node:process'
|
|
23
|
+
|
|
24
|
+
const JS_ENTRY = /\.[cm]?js$/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The argv prefix that runs pnpm: `[command, ...leadingArguments]`.
|
|
28
|
+
* @returns {[string, ...string[]]} Spread it ahead of pnpm's own arguments.
|
|
29
|
+
*/
|
|
30
|
+
export function pnpmCommand() {
|
|
31
|
+
const fromNpm = env.npm_execpath
|
|
32
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
33
|
+
if (fromNpm && JS_ENTRY.test(fromNpm) && existsSync(fromNpm)) {
|
|
34
|
+
return [execPath, fromNpm]
|
|
35
|
+
}
|
|
36
|
+
const onPath = resolveOnPath('pnpm')
|
|
37
|
+
if (!onPath) return ['pnpm']
|
|
38
|
+
if (isKernelExecutable(onPath)) return ['pnpm']
|
|
39
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
40
|
+
const handover = join(dirname(realpathSync(onPath)), 'bin', 'pnpm.mjs')
|
|
41
|
+
return existsSync(handover) ? [execPath, handover] : ['pnpm']
|
|
42
|
+
/* eslint-enable security/detect-non-literal-fs-filename */
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The first `name` on PATH, or undefined. Windows keeps its own extensions. */
|
|
46
|
+
function resolveOnPath(name) {
|
|
47
|
+
const suffixes = platform === 'win32' ? ['.cmd', '.exe', '.bat', ''] : ['']
|
|
48
|
+
for (const directory of (env.PATH ?? '').split(delimiter).filter(Boolean)) {
|
|
49
|
+
for (const suffix of suffixes) {
|
|
50
|
+
const candidate = join(directory, `${name}${suffix}`)
|
|
51
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
52
|
+
if (existsSync(candidate) && statSync(candidate).isFile()) {
|
|
53
|
+
return candidate
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return undefined
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Whether `execve` can run this file: a shebang, or anything not plain text. */
|
|
61
|
+
function isKernelExecutable(path) {
|
|
62
|
+
if (platform === 'win32') return true
|
|
63
|
+
let head
|
|
64
|
+
try {
|
|
65
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
66
|
+
head = readFileSync(path).subarray(0, 2)
|
|
67
|
+
} catch {
|
|
68
|
+
return true
|
|
69
|
+
}
|
|
70
|
+
if (head[0] === 0x23 && head[1] === 0x21) return true
|
|
71
|
+
// Mach-O, ELF and the fat binaries macOS ships all start outside printable
|
|
72
|
+
// ASCII: not text, so not the placeholder. Only a text file without a
|
|
73
|
+
// shebang is the case this exists for.
|
|
74
|
+
return head[0] >= 0x7f
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syntopica/quality-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"private": false,
|
|
5
|
-
"packageManager": "pnpm@11.25.0",
|
|
6
5
|
"license": "MIT",
|
|
7
6
|
"description": "Shared configuration for cross-file quality gates: knip, dependency-cruiser, type-coverage, jscpd, lefthook",
|
|
8
7
|
"repository": {
|
|
9
8
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/syntopica/codeality.git",
|
|
11
10
|
"directory": "packages/quality-config"
|
|
12
11
|
},
|
|
13
|
-
"homepage": "https://github.com/
|
|
12
|
+
"homepage": "https://github.com/syntopica/codeality/tree/main/packages/quality-config#readme",
|
|
14
13
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/
|
|
14
|
+
"url": "https://github.com/syntopica/codeality/issues"
|
|
16
15
|
},
|
|
17
16
|
"publishConfig": {
|
|
18
17
|
"access": "public"
|
|
@@ -47,16 +46,8 @@
|
|
|
47
46
|
"./lefthook": "./src/lefthook.ts",
|
|
48
47
|
"./jscpd": "./jscpd.json",
|
|
49
48
|
"./commitlint": "./src/commitlint.ts",
|
|
50
|
-
"./oxlint": "./oxlintrc.json"
|
|
51
|
-
|
|
52
|
-
"scripts": {
|
|
53
|
-
"fix": "pnpm run lint:fix",
|
|
54
|
-
"lint": "eslint src bin --max-warnings 0",
|
|
55
|
-
"lint:fix": "eslint src bin --fix",
|
|
56
|
-
"lint:suppress": "eslint src bin --suppress-all",
|
|
57
|
-
"lint:prune": "eslint src bin --prune-suppressions",
|
|
58
|
-
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
59
|
-
"publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm internal-resolution-error"
|
|
49
|
+
"./oxlint": "./oxlintrc.json",
|
|
50
|
+
"./pnpm-command": "./bin/pnpmCommand.mjs"
|
|
60
51
|
},
|
|
61
52
|
"peerDependencies": {
|
|
62
53
|
"@commitlint/config-conventional": ">=21.0.0",
|
|
@@ -81,13 +72,22 @@
|
|
|
81
72
|
},
|
|
82
73
|
"devDependencies": {
|
|
83
74
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
84
|
-
"@syntopica/eslint-config": "
|
|
85
|
-
"@types/node": "^26.
|
|
86
|
-
"dependency-cruiser": "^18.
|
|
87
|
-
"eslint": "^10.
|
|
88
|
-
"eslint-plugin-regexp": "^3.
|
|
89
|
-
"knip": "^6.
|
|
75
|
+
"@syntopica/eslint-config": "0.8.0",
|
|
76
|
+
"@types/node": "^26.6.3",
|
|
77
|
+
"dependency-cruiser": "^18.5.0",
|
|
78
|
+
"eslint": "^10.11.0",
|
|
79
|
+
"eslint-plugin-regexp": "^3.3.1",
|
|
80
|
+
"knip": "^6.39.0",
|
|
90
81
|
"publint": "^0.3.24",
|
|
91
82
|
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"fix": "pnpm run lint:fix",
|
|
86
|
+
"lint": "eslint src bin --max-warnings 0",
|
|
87
|
+
"lint:fix": "eslint src bin --fix",
|
|
88
|
+
"lint:suppress": "eslint src bin --suppress-all",
|
|
89
|
+
"lint:prune": "eslint src bin --prune-suppressions",
|
|
90
|
+
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
91
|
+
"publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm internal-resolution-error"
|
|
92
92
|
}
|
|
93
|
-
}
|
|
93
|
+
}
|
|
@@ -21,7 +21,10 @@ const NEXT_FILE_CONVENTIONS =
|
|
|
21
21
|
// optional-directory group.
|
|
22
22
|
const ORPHAN_EXEMPTIONS = [
|
|
23
23
|
'(^|/)\\.[^/]+\\.(js|cjs|mjs|ts|json)$',
|
|
24
|
-
|
|
24
|
+
// Declaration files of every extension: `.d.ts`, and the `.d.mts`/`.d.cts`
|
|
25
|
+
// a package ships beside an `.mjs`/`.cjs` entry point. They carry types, not
|
|
26
|
+
// modules, so nothing imports them.
|
|
27
|
+
'\\.d\\.[cm]?ts$',
|
|
25
28
|
'(^|/)tsconfig\\.json$',
|
|
26
29
|
// Framework/tooling config files: loaded directly by that tool's own
|
|
27
30
|
// runtime, never imported by application code. Being an orphan in the module
|
|
@@ -131,7 +134,11 @@ export const createDepCruiserConfig = (
|
|
|
131
134
|
options: {
|
|
132
135
|
doNotFollow: { path: 'node_modules' },
|
|
133
136
|
exclude: {
|
|
134
|
-
|
|
137
|
+
// `.venv` is here because a Python workspace vendors JavaScript: urllib3
|
|
138
|
+
// ships an Emscripten fetch worker, and cruising a repository that holds
|
|
139
|
+
// a uv project reported four of those as orphan modules - errors about
|
|
140
|
+
// files the repository does not own and cannot remove.
|
|
141
|
+
path: '(^|/)(dist|coverage|\\.next|\\.nuxt|\\.output|\\.astro|\\.venv|target)/',
|
|
135
142
|
},
|
|
136
143
|
tsPreCompilationDeps: true,
|
|
137
144
|
tsConfig: options.tsConfigPath
|
package/src/knip-framework.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Entry and project globs per template framework, consumed by createKnipConfig.
|
|
3
|
+
*
|
|
4
|
+
* `includeEntryExports` says whether an entry file's own exports are checked.
|
|
5
|
+
* It is true only where the entries are hand-written (`src/main.ts`,
|
|
6
|
+
* `src/index.ts`), which is where a dead export is a real finding. Where the
|
|
7
|
+
* framework owns the entry - a config file's `export default defineConfig(...)`,
|
|
8
|
+
* a Next.js route's `export default function Page()`, its `metadata` - the
|
|
9
|
+
* export exists because the framework reads it, and nothing in the project
|
|
10
|
+
* imports it by design. knip 6.35 started applying `includeEntryExports` to
|
|
11
|
+
* the files its own plugins register, so a blanket `true` failed the gate in
|
|
12
|
+
* six of the eight templates with exports no project can remove.
|
|
13
|
+
*/
|
|
2
14
|
export type KnipFramework =
|
|
3
15
|
| 'astro'
|
|
4
16
|
| 'nestjs'
|
|
@@ -12,15 +24,17 @@ export type KnipFramework =
|
|
|
12
24
|
|
|
13
25
|
export const FRAMEWORK_ENTRIES: Record<
|
|
14
26
|
KnipFramework,
|
|
15
|
-
{ entry: string[]; project: string[] }
|
|
27
|
+
{ entry: string[]; project: string[]; includeEntryExports: boolean }
|
|
16
28
|
> = {
|
|
17
29
|
astro: {
|
|
18
30
|
entry: ['src/pages/**/*.{astro,ts,tsx}', 'astro.config.*'],
|
|
19
31
|
project: ['src/**/*.{astro,ts,tsx}'],
|
|
32
|
+
includeEntryExports: false,
|
|
20
33
|
},
|
|
21
34
|
nestjs: {
|
|
22
35
|
entry: ['src/main.ts', 'src/**/*.module.ts'],
|
|
23
36
|
project: ['src/**/*.ts'],
|
|
37
|
+
includeEntryExports: true,
|
|
24
38
|
},
|
|
25
39
|
// The App Router lives at either `app/` or `src/app/`, and the proxy follows
|
|
26
40
|
// it. `{,src/}` matches both in one pattern, so neither layout produces a
|
|
@@ -42,10 +56,12 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
42
56
|
'{,src/}{middleware,proxy}.ts',
|
|
43
57
|
],
|
|
44
58
|
project: ['{,src/}app/**/*.{ts,tsx}', 'src/**/*.{ts,tsx}'],
|
|
59
|
+
includeEntryExports: false,
|
|
45
60
|
},
|
|
46
61
|
nuxt: {
|
|
47
62
|
entry: ['app/**/*.vue', 'server/**/*.ts', 'nuxt.config.*'],
|
|
48
63
|
project: ['app/**/*.{ts,vue}', 'server/**/*.ts'],
|
|
64
|
+
includeEntryExports: false,
|
|
49
65
|
},
|
|
50
66
|
// TanStack Start has no index.html and no src/main.tsx: the router is the
|
|
51
67
|
// root of the graph and the framework generates routeTree.gen.ts from the
|
|
@@ -61,6 +77,7 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
61
77
|
'vite.config.*',
|
|
62
78
|
],
|
|
63
79
|
project: ['src/**/*.{ts,tsx}'],
|
|
80
|
+
includeEntryExports: false,
|
|
64
81
|
},
|
|
65
82
|
tauri: {
|
|
66
83
|
// The scaffolded tauri-app frontend is React, so its entry is
|
|
@@ -68,17 +85,21 @@ export const FRAMEWORK_ENTRIES: Record<
|
|
|
68
85
|
// Tauri frontend also matches.
|
|
69
86
|
entry: ['src/main.{ts,tsx}', 'vite.config.*'],
|
|
70
87
|
project: ['src/**/*.{ts,tsx}'],
|
|
88
|
+
includeEntryExports: false,
|
|
71
89
|
},
|
|
72
90
|
'ts-package': {
|
|
73
91
|
entry: ['src/index.ts'],
|
|
74
92
|
project: ['src/**/*.ts'],
|
|
93
|
+
includeEntryExports: true,
|
|
75
94
|
},
|
|
76
95
|
'vite-react': {
|
|
77
96
|
entry: ['src/main.tsx', 'index.html', 'vite.config.*'],
|
|
78
97
|
project: ['src/**/*.{ts,tsx}'],
|
|
98
|
+
includeEntryExports: false,
|
|
79
99
|
},
|
|
80
100
|
'vite-vue': {
|
|
81
101
|
entry: ['src/main.ts', 'index.html', 'vite.config.*'],
|
|
82
102
|
project: ['src/**/*.{ts,vue}'],
|
|
103
|
+
includeEntryExports: false,
|
|
83
104
|
},
|
|
84
105
|
}
|
package/src/knip.ts
CHANGED
|
@@ -35,7 +35,7 @@ import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
|
|
|
35
35
|
// `type-coverage`, `baseline-deps-graph` spawns `depcruise`. A project that
|
|
36
36
|
// wires the runner into its scripts never names the underlying tool anywhere
|
|
37
37
|
// knip can see, so knip reports a real dependency as unused. Found in
|
|
38
|
-
//
|
|
38
|
+
// a consumer the moment its `type-coverage` script became
|
|
39
39
|
// `baseline-type-coverage`.
|
|
40
40
|
//
|
|
41
41
|
// `dependency-cruiser` is on the list even though a project calling
|
|
@@ -103,9 +103,11 @@ export const createKnipConfig = (options: {
|
|
|
103
103
|
*/
|
|
104
104
|
entry?: string[]
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
106
|
+
* Whether an entry file's own exports are checked. Defaults per framework
|
|
107
|
+
* (see FRAMEWORK_ENTRIES): true where the entries are hand-written, false
|
|
108
|
+
* where the framework owns them. Set `false` for a package that is finished
|
|
109
|
+
* but not wired up yet - with `true` its entire public API reports as unused
|
|
110
|
+
* exports, and the obvious reading of that report is "delete this package".
|
|
109
111
|
*/
|
|
110
112
|
includeEntryExports?: boolean
|
|
111
113
|
/**
|
|
@@ -116,7 +118,8 @@ export const createKnipConfig = (options: {
|
|
|
116
118
|
*/
|
|
117
119
|
drizzle?: false
|
|
118
120
|
}): KnipConfiguration => {
|
|
119
|
-
const { entry, project } =
|
|
121
|
+
const { entry, project, includeEntryExports } =
|
|
122
|
+
FRAMEWORK_ENTRIES[options.framework]
|
|
120
123
|
|
|
121
124
|
return {
|
|
122
125
|
entry: [...entry, ...(options.entry ?? [])],
|
|
@@ -130,7 +133,7 @@ export const createKnipConfig = (options: {
|
|
|
130
133
|
// fail `nextjs-app` (app/page.tsx), `vite-react-app` (src/main.tsx) or
|
|
131
134
|
// `vue-app` (src/main.ts) - files a knip framework plugin registers as an
|
|
132
135
|
// entry of its own, which the option does not reach.
|
|
133
|
-
includeEntryExports: options.includeEntryExports ??
|
|
136
|
+
includeEntryExports: options.includeEntryExports ?? includeEntryExports,
|
|
134
137
|
// The Primary Unit Rule (code-policy/no-hidden-top-level-declarations)
|
|
135
138
|
// forbids a hidden top-level declaration, so a helper an entry file uses
|
|
136
139
|
// only itself still has to be exported - NestJS's `bootstrap`, called by
|