@syntopica/quality-config 0.16.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 ADDED
@@ -0,0 +1,519 @@
1
+ # @syntopica/quality-config
2
+
3
+ ## 0.17.0
4
+
5
+ - feat: `baseline-changes` compares the installed `@syntopica/*` and
6
+ `eslint-plugin-code-policy` versions with `.baseline-versions.json` and prints
7
+ the `CHANGELOG.md` sections of every release in between, each
8
+ `### Action required` subsection first, then records the installed versions.
9
+ It exits 0, and does not write under `CI` or with `--no-write`.
10
+ - The published package now includes `CHANGELOG.md`.
11
+
12
+ - feat: `createLefthookConfig({ tadu: true })` excludes the tadu backlog from
13
+ the lint and format hooks and adds a `backlog` hook that runs `tadu doctor .`
14
+ when tadu is installed.
15
+
16
+ ## 0.16.0
17
+
18
+ - fix: include imported CSS in Vite React, Vite Vue, Tauri and Nuxt project
19
+ patterns so Knip follows compiled stylesheet imports in normal and production
20
+ analysis.
21
+
22
+ - fix: resolve the consumer-installed jscpd and type-coverage CLI entries
23
+ directly, including hoisted workspace dependencies, instead of requiring pnpm
24
+ or invoking another package manager.
25
+
26
+ - Export `@syntopica/quality-config/cruise-tsconfig` to preserve TypeScript
27
+ alias origins for dependency-cruiser.
28
+
29
+ - Validate the structure of package audit reports and report incomplete results.
30
+
31
+ - Keep runtime-used development dependencies visible in Knip production analysis
32
+ and remove stale compatibility hints.
33
+
34
+ ## 0.15.0
35
+
36
+ ### Patch Changes
37
+
38
+ - fix: omit missing preset entry files and source roots from Knip configuration,
39
+ while preserving caller-supplied patterns. Custom ESLint configurations no
40
+ longer inherit dependency exemptions intended for `@syntopica/eslint-config`
41
+ consumers.
42
+
43
+ ### Minor Changes
44
+
45
+ - feat: `jscpd.json` scans `dart` and `swift` too, and ignores generated Dart
46
+ (`*.g.dart`, `*.freezed.dart`) and Dart/Swift build output (`.dart_tool`,
47
+ `build`, `.build`). `codeality-dart` and `codeality-swift` embed these
48
+ defaults, kept in step by `pnpm sync-jscpd:check`.
49
+
50
+ ## 0.14.0
51
+
52
+ ### Minor Changes
53
+
54
+ - feat: `createDepCruiserConfig({ moduleRoots })` adds
55
+ `no-deep-cross-module-import`: under each named root, a module may reach
56
+ another only through its `index`, judged on resolved paths. Opt-in.
57
+ - feat: `createKnipConfig` supports `knip --production`. Each preset marks its
58
+ runtime entries and sources as production code and excludes tests, mocks and
59
+ stories in that mode, so it no longer reports runtime dependencies (`vue`,
60
+ `zod`, `@nestjs/core`) as unused. Framework packages read only by their config
61
+ (`astro`, `nuxt`) are ignored in production mode only. The default run is
62
+ unchanged.
63
+
64
+ ## 0.13.2
65
+
66
+ ### Patch Changes
67
+
68
+ - fix: `createKnipConfig` no longer fails a template whose `check:quality` runs
69
+ `pnpm type-coverage`. A word that only runs another `package.json` script
70
+ (`pnpm <script>`, `pnpm run <script>`) is no longer read as naming the binary,
71
+ so `type-coverage` stays ignored instead of reported unused.
72
+ - fix: `lefthook` is left out of `ignoreDependencies` when a Lefthook
73
+ configuration file exists, since knip's Lefthook plugin then resolves it
74
+ itself (from `CI`, or from the installed git hooks).
75
+ - fix: an ESLint peer another installed dependency declares as its own peer
76
+ (`typescript-eslint`, hosted by `eslint-plugin-astro`) is no longer ignored:
77
+ knip counts it as used, so the entry was a `Remove from ignoreDependencies`
78
+ hint.
79
+
80
+ ## 0.13.1
81
+
82
+ ### Patch Changes
83
+
84
+ - fix: `createKnipConfig` no longer leaves configuration hints in a CLI-shaped
85
+ `ts-package` consumer. A caller-supplied `entry` now drops the preset's
86
+ default `src/index.ts` when that file does not exist (it is kept when it does,
87
+ so a library with both an index and a CLI behaves as before), and
88
+ `dependency-cruiser`, `lefthook`, `jscpd` and `type-coverage` are added to
89
+ `ignoreDependencies` only when no `package.json` script names their binary
90
+ directly. When a script does (`"prepare": "lefthook install"`,
91
+ `"deps:graph": "depcruise src"`), knip resolves the package itself and the
92
+ entry used to be a permanent `Remove from ignoreDependencies` hint. New
93
+ optional `cwd` option (defaults to the process cwd) for the project root.
94
+
95
+ ## 0.13.0
96
+
97
+ ### Minor Changes
98
+
99
+ - feat: `baseline-hooks-install` runs `lefthook install` only from the git
100
+ repository root. Wired into `prepare` instead of a bare `lefthook install`, it
101
+ stops a workspace's packages from rewriting the root's `.git/hooks` in
102
+ parallel, which failed `pnpm install` with
103
+ `could not replace the hook: remove .git/hooks/pre-push`.
104
+
105
+ ## 0.12.1
106
+
107
+ ### Patch Changes
108
+
109
+ - fix: knip findings every template reported. `gitleaks`, a system binary the
110
+ baseline wires into `secrets:check`, is ignored by default; the nextjs preset
111
+ no longer lists `middleware` and `proxy`, which knip's Next plugin registers;
112
+ the Vite presets no longer list `src/main`, which `index.html` already
113
+ reaches.
114
+
115
+ ## 0.12.0
116
+
117
+ ### Minor Changes
118
+
119
+ - feat: `baseline-type-coverage --at-least` accepts a value above the shared
120
+ threshold, up to 100, so a repository that has climbed past the shared floor
121
+ can pin its coverage there. A value equal to the shared threshold is still
122
+ refused as a restatement.
123
+
124
+ ## 0.11.1
125
+
126
+ ### Patch Changes
127
+
128
+ - fix: knip's `includeEntryExports` now defaults per framework.
129
+
130
+ knip 6.35 started applying the option to the files its own plugins register,
131
+ so `export default defineConfig(...)` in a vite, astro or nuxt config, and a
132
+ Next.js route's `default`/`metadata`, all reported as unused exports - in six
133
+ of the eight templates, with no export a project could remove. It is now true
134
+ only where the entries are hand-written (`nestjs`, `ts-package`), which is
135
+ where the check ever found anything, and false where the framework owns them.
136
+
137
+ - fix: dependency-cruiser excludes `.venv` and exempts `.d.mts`/`.d.cts`.
138
+
139
+ A repository with a uv project cruised the virtualenv's vendored JavaScript
140
+ and failed on four orphan modules it does not own; a package shipping types
141
+ beside an `.mjs` entry failed on the declaration file itself.
142
+
143
+ - fix: run pnpm through an entry point Node can execute.
144
+
145
+ `baseline-type-coverage`, `baseline-dupes`, `baseline-audit` and
146
+ `baseline-deps-graph` spawned `pnpm` directly. pnpm 11 puts a shebang-less
147
+ `sh` script at its bin path and replaces it with the native binary during
148
+ installation; where that replacement never ran, macOS answers `ENOEXEC` and
149
+ every one of those gates failed with empty output - `type-coverage: FAIL .` on
150
+ a repository measured at 99.82%, and `baseline-dupes: could not run jscpd`.
151
+ The gate blamed its subject for a broken launcher. The runners now resolve
152
+ `npm_execpath`, the executable `pnpm` on PATH, or the `bin/pnpm.mjs` the
153
+ placeholder hands over to, in that order.
154
+
155
+ ## 0.11.0
156
+
157
+ ### Minor Changes
158
+
159
+ - feat: `baseline-audit` - advisory waivers that expire.
160
+
161
+ `pnpm audit --audit-level=high` has one lever, and silencing a judged finding
162
+ means raising it for everything. `baseline-audit` reads
163
+ `.baseline-advisories.json`, keyed by GitHub advisory id, where each entry
164
+ carries a required `reason` and a required `expires`. An expired waiver fails
165
+ the build; an entry missing either field is rejected rather than honoured.
166
+ Because a judged finding now has somewhere to live, the default gate is
167
+ `moderate` rather than `high` - strictly stricter than before.
168
+
169
+ - feat: `baseline-licenses` - a licence gate for published packages.
170
+
171
+ Walks one package's _production_ closure and asserts every licence is
172
+ permissive, with the same `reason`/`expires` allowlist shape. Dev dependencies
173
+ are excluded on purpose: a copyleft test runner is not distributed, a copyleft
174
+ transitive runtime dependency of an MIT package is. `pnpm licenses list` is
175
+ not usable here - inside a workspace it reports the whole store, 986 packages
176
+ for a config package with eight direct dependencies.
177
+
178
+ - feat: `/commitlint` - conventional-commit rules for the `commit-msg` hook.
179
+
180
+ The release tooling already derived the semver bump and the changelog from
181
+ commit subjects, so a subject typed `feature:` instead of `feat:` silently
182
+ dropped a change out of the release notes. Nothing verified it. Two rules from
183
+ the conventional preset are off because they fight how commits are written
184
+ here: `body-max-line-length` rejects a pasted stack trace, `subject-case`
185
+ rejects a subject starting with `TypeScript` or `GitHub`.
186
+
187
+ - feat: `/oxlint` - a pre-filter config, one category wide.
188
+
189
+ `correctness` only. That is the set whose findings ESLint would also reject,
190
+ so oxlint can fail a build in seconds without introducing a second opinion.
191
+ Measured on this repository: `correctness` reported nothing, `suspicious` and
192
+ `pedantic` reported 19 findings, none of which ESLint considers a problem. See
193
+ `OXLINT.md` for why the scope is not wider.
194
+
195
+ - feat: `createLefthookConfig()` gains a `commit-msg` hook and a `lint:fast`
196
+ pre-commit command.
197
+
198
+ The typed lint stays the authority; the two-second pass runs first.
199
+
200
+ ## 0.10.0
201
+
202
+ ### Minor Changes
203
+
204
+ - fix: `baseline-type-coverage` measured nothing on a solution-style
205
+ `tsconfig.json` and reported `ok`.
206
+
207
+ A root `{"files": [], "references": [...]}` contributes no source of its own,
208
+ so type-coverage measured 0 identifiers and exited 0 -- a green gate over an
209
+ entire repository. consumer-g reported `ok . 0 / 0` and had to keep a
210
+ hand-written runner. Solution configs now contribute their referenced projects
211
+ instead, each measured with `-p`: the same tree reports 194,942 / 195,652,
212
+ 41,214 / 41,415 and 184,008 / 184,671.
213
+
214
+ - fix: discovery descended into gitignored directories.
215
+
216
+ consumer-g's `artifacts/bamboobox-findings`, a vendored tree deliberately
217
+ excluded from its root quality scans, was reported as a checked workspace.
218
+ Candidate directories are now put to `git check-ignore` in one pass; a repo
219
+ without git excludes nothing, as before.
220
+
221
+ - feat: `--ignore-files <glob>`, repeatable, merged with the two built-in
222
+ exclusions.
223
+
224
+ For generated or vendored code a project already excludes elsewhere -- a
225
+ migrations directory is the standing case, and it is why consumer-y kept its
226
+ own runner. Not a way to hide `any`s: it adds to the built-in list and cannot
227
+ replace it.
228
+
229
+ ## 0.9.0
230
+
231
+ ### Minor Changes
232
+
233
+ - feat: `tanstack-start` knip preset.
234
+
235
+ TanStack Start has no `index.html` and no `src/main.tsx`: the router is the
236
+ root of the graph and the framework generates `routeTree.gen.ts` from
237
+ file-based routes. Adopting consumer-h under the `vite-react` preset left two
238
+ permanent "Refine entry pattern (no matches)" hints and reached the graph only
239
+ by accident.
240
+
241
+ ## 0.8.1
242
+
243
+ ### Patch Changes
244
+
245
+ - fix: `createKnipConfig` returns `KnipConfiguration`, not `KnipConfig`.
246
+
247
+ `KnipConfig` is a union that also admits a function, so a project spreading
248
+ the factory's result to override one rule got
249
+ `Property 'rules' does not exist on type 'RawConfigurationOrFn'` and had to
250
+ cast the value first. Consumer-s and consumer-m both hit it. Returning the
251
+ object shape makes extending the config the ordinary thing it looks like.
252
+
253
+ ## 0.8.0
254
+
255
+ ### Minor Changes
256
+
257
+ - feat: `createKnipConfig` accepts `project` and `entry` globs, merged with the
258
+ framework preset.
259
+
260
+ Every preset assumes the framework's own layout -- for Next.js, `src/` and
261
+ `app/`. consumer-m predates that convention: `actions/`, `components/`,
262
+ `hooks/`, `services/`, `types/` and six more sit at the repo root, so knip saw
263
+ only `app/` and reported 34 live dependencies as unused. The factory had no
264
+ override, so a repo in that shape could either delete the gate or carry a
265
+ permanent 34-line false report.
266
+
267
+ Both options merge rather than replace: a project can tell knip where its
268
+ extra code lives, but cannot silently stop it scanning the directories the
269
+ framework does own.
270
+
271
+ ## 0.7.0
272
+
273
+ ### Minor Changes
274
+
275
+ - feat: `baseline-type-coverage --at-least <n>` freezes a repo below the shared
276
+ threshold.
277
+
278
+ The bar is 99% and the runner had no way to say otherwise, so a codebase that
279
+ measures 96.93% could not wire this gate at all: the choice was an unenforced
280
+ gate or none. Found adopting consumer-k, whose 25 uncovered expressions sit
281
+ almost entirely in one database row mapper -- a real boundary, not sloppiness.
282
+
283
+ Freezing at the measured value makes coverage a ratchet: it cannot fall, and
284
+ the number in `package.json` is the debt, visible in every diff that changes
285
+ it. The flag refuses a value above the shared threshold, so it can only ever
286
+ lower the bar for a project that needs it, never restate or raise it.
287
+
288
+ ## 0.6.1
289
+
290
+ ### Patch Changes
291
+
292
+ - fix: `createKnipConfig` ignores every tool this package's runners spawn.
293
+
294
+ `baseline-dupes` spawns `jscpd`, `baseline-type-coverage` spawns
295
+ `type-coverage`, `baseline-deps-graph` spawns `depcruise` - all through
296
+ `pnpm exec`, so a project that wires the runner into its scripts never names
297
+ the underlying tool anywhere knip can see and knip reports a real dependency
298
+ as unused. Only `jscpd` was on the list; found in a consumer the moment its
299
+ `type-coverage` script became `baseline-type-coverage` and `pnpm knip` went
300
+ red on a dependency it uses on every run.
301
+
302
+ `dependency-cruiser` is included even though a project calling `depcruise`
303
+ directly resolves it fine: there knip emits a `Remove from ignoreDependencies`
304
+ hint, which is a hint and not a gate failure, and the cost of leaving it off
305
+ is a real dependency silently reported as dead.
306
+
307
+ ## 0.6.0
308
+
309
+ ### Minor Changes
310
+
311
+ - feat: `baseline-dupes --also-ignore` adds ignore patterns on top of the shared
312
+ list.
313
+
314
+ jscpd's own `--ignore` replaces the config's list rather than merging into it.
315
+ Measured on this repo: a config that also ignored `**/cargo-baseline/**`
316
+ scanned 61 files and found 1 clone; adding an unrelated `--ignore` took it to
317
+ 109 files and 4 clones, the shared patterns gone.
318
+
319
+ That left a project with one generated directory to exclude - committed
320
+ Supabase types, a migrations folder, a cpanel build - restating every shared
321
+ pattern in its own `package.json`, which is the duplication this runner exists
322
+ to remove. Five of the nine repos surveyed carried exactly such an entry.
323
+ `--also-ignore` merges through a generated config that is deleted again on the
324
+ way out, and extends a caller-supplied `--config` when there is one.
325
+
326
+ ### Patch Changes
327
+
328
+ - fix: `baseline-dupes` no longer mistakes a flag's value for a scan path.
329
+
330
+ It split arguments into paths and flags on a leading `-`, which cannot work:
331
+ `--min-tokens 120` and `--config x.json` carry a value that looks like
332
+ neither, so `120` was handed to jscpd as a directory to scan and a `--config`
333
+ value shifted the flag list, silently dropping the flag after it. Arguments
334
+ are now forwarded in the order given, untouched apart from `--also-ignore`;
335
+ the only argument the runner adds is `--config`, and only when the caller did
336
+ not pass one.
337
+
338
+ ## 0.5.0
339
+
340
+ ### Minor Changes
341
+
342
+ - feat: the jscpd gate ships from here, as `jscpd.json` plus a `baseline-dupes`
343
+ runner.
344
+
345
+ `.jscpd.json` was copied byte for byte into the repo root and all eight
346
+ templates, and every adopting project had to copy it again - the only quality
347
+ gate in the set that was hand-maintained duplication rather than shared
348
+ config. It is now one file in this package, read in place.
349
+
350
+ jscpd 5.x is a Rust binary that reads JSON only, with no JS config loader, so
351
+ this gate cannot be a factory the way `createKnipConfig` is. `baseline-dupes`
352
+ points jscpd at the packaged config and forwards any extra flag, which wins
353
+ over the file. The config is also resolvable directly, as
354
+ `@busirocket/quality-config/jscpd`.
355
+
356
+ `jscpd` stays a devDependency of the consuming project; the runner invokes it
357
+ rather than vendoring it.
358
+
359
+ - feat: `createKnipConfig` takes options instead of forcing every consumer to
360
+ restate the preset.
361
+
362
+ `ignoreBinaries`, `ignoreDependencies`, `ignore`, `includeEntryExports` and
363
+ `drizzle` are now settable. `ignoreDependencies` merges with the ESLint peer
364
+ list rather than replacing it, so a consumer whose layout hides a caller adds
365
+ one entry instead of copying the whole array.
366
+
367
+ The four cases that drove this, all found adopting the baseline in real repos:
368
+
369
+ - A **drizzle schema aggregator** reports every table as a dead export,
370
+ because `drizzle.config.ts` is the only consumer. Acting on that report
371
+ makes the next generated migration emit `DROP TABLE`. `ignore` excludes the
372
+ file.
373
+ - knip's **drizzle plugin loads `drizzle.config.ts`**, which throws by design
374
+ without `DATABASE_URL`, so the gate needed a live database in CI. Adding the
375
+ file to `ignore` does not stop the plugin; `drizzle: false` does.
376
+ - A **package that is finished but not wired up** reports its entire public
377
+ API as unused under `includeEntryExports: true`, and the obvious reading is
378
+ "delete this package". It can now be set per workspace.
379
+ - `ignoreBinaries` **no longer defaults to `['turbo', 'lhci']`**. Both resolve
380
+ in every template that has them, so the entries only ever produced a
381
+ `Remove from ignoreBinaries` hint a consumer could not silence.
382
+
383
+ - feat: ship the two runners consumers were copying by hand.
384
+
385
+ `baseline-type-coverage` runs `type-coverage --strict` in every workspace with
386
+ a `tsconfig.json`, reading the threshold from the package's own
387
+ `TYPE_COVERAGE_THRESHOLD` so the constant and the gate cannot drift. The
388
+ package exported that number and nothing else, so each consumer wrote its own
389
+ per-workspace loop.
390
+
391
+ `baseline-deps-graph` cruises each workspace with that workspace's own
392
+ tsconfig. A single repo-wide cruise takes one `tsConfig`, so in a monorepo it
393
+ resolves at most one `@/*` mapping and `no-orphans` then reports everything it
394
+ could not follow - which is why one adopter dropped dependency-cruiser
395
+ entirely.
396
+
397
+ ### Patch Changes
398
+
399
+ - fix: drop `@vitest/eslint-plugin` and `eslint-plugin-testing-library` from the
400
+ shared `ignoreDependencies` list.
401
+
402
+ knip resolved the real caller for both in all eight templates, so the entries
403
+ were redundant everywhere while still printing a hint.
404
+ `eslint-config-prettier` and the rest stay: they are redundant in four of the
405
+ eight layouts and load-bearing in the other four, which is what the list is
406
+ for. Template hints went from 21 to 5.
407
+
408
+ ## 0.4.0
409
+
410
+ ### Minor Changes
411
+
412
+ - fix: complete the Next.js file conventions in both knip and
413
+ dependency-cruiser.
414
+
415
+ Adopting the standard in a real Next.js 16 project surfaced two presets that
416
+ had fallen behind the framework.
417
+
418
+ `createKnipConfig({ framework: 'nextjs' })` listed `middleware.ts`, which Next
419
+ 16 renamed to `proxy.ts`. In a project that followed the rename, the proxy was
420
+ reachable from no entry point, so knip reported it and everything only it
421
+ imports as **unused files** while the pattern that no longer matched anything
422
+ produced a `Refine entry pattern (no matches)` hint. The entry now reads
423
+ `{,src/}{middleware,proxy}.ts` - one pattern, because a project has one file
424
+ or the other - and the App Router metadata routes (`sitemap`, `robots`,
425
+ `manifest`, `icon`, `apple-icon`, `opengraph-image`, `twitter-image`) plus
426
+ `global-error` join the existing brace alternation for the same reason.
427
+
428
+ `createDepCruiserConfig`'s `no-orphans` exemptions covered `sitemap` and
429
+ `robots` and nothing else of the App Router, so a normal project reported one
430
+ orphan error per route file. Every convention is exempt now, at any depth
431
+ below `app/`, and so is `middleware`/`proxy`.
432
+
433
+ The exemptions are written as two patterns - a direct-child form and a nested
434
+ `.*/` form - rather than one with an optional `(.*/)?` directory group,
435
+ because dependency-cruiser runs every `pathNot` entry through safe-regex and
436
+ **abandons the entire rule** when one is rejected, rather than skipping that
437
+ pattern. A nested quantifier there does not narrow the orphan check, it turns
438
+ it off. That trap is now documented in the factory and in
439
+ `docs/standards/quality-gates.md`.
440
+
441
+ A Next.js consumer on 0.3.0 that had patched around either gap can delete
442
+ those local patches; a consumer that had not will see false findings
443
+ disappear, so this is a behavior change rather than a patch.
444
+
445
+ ## 0.3.0
446
+
447
+ ### Minor Changes
448
+
449
+ - fix: cover the `src/app` layout in the knip Next.js preset. (`361dbf3`)
450
+
451
+ `createKnipConfig({ framework: 'nextjs' })` rooted its entry globs at `app/`,
452
+ so a project using `src/app/` matched none of them. The consequence is not a
453
+ quiet pass: with no entry matching, knip reports the application's own route
454
+ files as **unused files** and never checks their exports.
455
+
456
+ The globs now carry both roots in one pattern
457
+ (`{,src/}app/**/{page,layout,...}.{ts,tsx}`, `{,src/}middleware.ts`), which
458
+ also means neither layout produces a `Refine entry pattern (no matches)` hint.
459
+ `next.config.*` stays root-only, where Next.js requires it.
460
+
461
+ A `src/app` project on 0.2.0 that adopts this will see its knip output
462
+ change - the false "unused files" disappear and real dead exports start
463
+ failing the gate - so this is a behavior change, not a patch.
464
+
465
+ ## 0.2.0
466
+
467
+ ### Minor Changes
468
+
469
+ - feat: check entry-file exports in `createKnipConfig`.
470
+
471
+ The generated config now sets `includeEntryExports: true`, so a dead export
472
+ added to a project's entry file (`src/main.ts`, `src/index.ts`) fails the gate
473
+ instead of passing silently. It also sets `ignoreExportsUsedInFile: true`,
474
+ which is the pairing the Primary Unit Rule requires: a top-level declaration
475
+ may not be hidden, so an entry-point helper a file uses only itself still has
476
+ to be exported. An export nothing references at all still fails.
477
+
478
+ A project on 0.1.0 that adopts this may start failing `knip` - that is the
479
+ ratchet working, but it is a behavior change, not a patch.
480
+
481
+ Coverage is real but partial: it does not reach files a knip framework plugin
482
+ registers as an entry of its own (a Next.js `page.tsx`, a Vite `main.tsx`
483
+ loaded from `index.html`).
484
+
485
+ - feat: drop `src/app/index.ts` from the `vite-vue` entry list.
486
+
487
+ It was there to work around knip not resolving a path-aliased bare `@/app` to
488
+ the directory's `index.ts`. A Vue project should import its composition root
489
+ as `@/app/index` explicitly instead; the extra entry made knip refuse to count
490
+ the entry-to-entry import as usage.
491
+
492
+ ## 0.1.0
493
+
494
+ ### Minor Changes
495
+
496
+ - feat: initial release. Shared configuration factories for the cross-file
497
+ quality gates, plus one executable.
498
+
499
+ - `createKnipConfig` (`/knip`) - unused files, exports and dependencies, with
500
+ per-framework entry globs.
501
+ - `createDepCruiserConfig` (`/dependency-cruiser`) - import cycles, orphan
502
+ modules, package/template boundary, devDependency-in-production, and
503
+ deprecated Node core modules. Takes `scope` (`'repo'` for the whole graph,
504
+ `'workspace'` for a single-workspace orphan check), `tsConfigPath`, and
505
+ `orphanExemptions` for project-specific exemptions. The factory itself
506
+ encodes no directory name belonging to any particular repository.
507
+ - `TYPE_COVERAGE_THRESHOLD` (`/type-coverage`) - minimum non-`any` coverage.
508
+ - `createLefthookConfig` (`/lefthook`) - shared git hook pipeline.
509
+ - `baseline-env-init` - seeds a gitignored `.env` from the committed
510
+ `.env.example`, so a freshly cloned project boots on the documented example
511
+ values rather than failing its startup env validation. Bundlers inline
512
+ `VITE_*`/`NEXT_PUBLIC_*` at build time, so without it a project with no
513
+ `.env` builds a bundle that throws before it renders and shows a blank page
514
+ rather than a useful error. Idempotent, and a no-op without an
515
+ `.env.example`.
516
+
517
+ Every export resolves to TypeScript source; consumers load it with ESM and a
518
+ TypeScript-aware runner such as `jiti`. `knip` and `dependency-cruiser` are
519
+ optional peers, needed only for the gates you actually use.
package/PUBLIC_API.md CHANGED
@@ -14,6 +14,14 @@ are **private** and may change without a major bump.
14
14
  | `@syntopica/quality-config/lefthook` | `createLefthookConfig` — shared git hook pipeline |
15
15
  | `@syntopica/quality-config/jscpd` | `jscpd.json` — cross-file duplication gate config |
16
16
 
17
+ ### `createLefthookConfig(options)`
18
+
19
+ `options.tadu` (default `false`) is for a repository that keeps a tadu backlog.
20
+ The lint and format commands then exclude `todo/**`, `TODO.md`, `TODO_LOG.md`
21
+ and `TODO_HISTORY_INDEX.jsonl`, and a `backlog` command runs `tadu doctor .` on
22
+ those paths, skipped when `tadu` is not installed. Without it the output is
23
+ unchanged.
24
+
17
25
  ### `createDepCruiserConfig(options)`
18
26
 
19
27
  Every option is optional and every default is project-agnostic: the factory
package/README.md CHANGED
@@ -136,6 +136,31 @@ the same file through `@syntopica/quality-config/jscpd`.
136
136
  `jscpd` itself stays a devDependency of the consuming project: the runner
137
137
  invokes it, it does not vendor it.
138
138
 
139
+ ### `baseline-changes`
140
+
141
+ Installed copies of these packages carry their `CHANGELOG.md`, and pnpm 10+ does
142
+ not run dependency lifecycle scripts, so a package cannot announce its own
143
+ upgrade. `baseline-changes` runs from the project's gate instead: it compares
144
+ the installed versions with `.baseline-versions.json`, prints the changelog
145
+ sections of every release in between with each `### Action required` subsection
146
+ first, then records the installed versions. The notice appears once, in the
147
+ first run after the upgrade. It always exits 0 and never writes under `CI` or
148
+ with `--no-write`. Commit `.baseline-versions.json`.
149
+
150
+ ```json
151
+ {
152
+ "scripts": {
153
+ "changes": "baseline-changes",
154
+ "check:ci": "pnpm changes && ..."
155
+ }
156
+ }
157
+ ```
158
+
159
+ A release that needs the consumer to do something (a breaking change, a new
160
+ config file, a migration) says so under `### Action required` in its changelog
161
+ section. The same file also records `syntopica-codeality-py` and
162
+ `cargo-baseline` versions, written by those tools.
163
+
139
164
  ## Related
140
165
 
141
166
  - **Lint / TS configs:** `@syntopica/eslint-config`, `@syntopica/tsconfig`.
@@ -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
+ }
@@ -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,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,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,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,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
+ }
@@ -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,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,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syntopica/quality-config",
3
- "version": "0.16.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",
@@ -77,7 +79,7 @@
77
79
  },
78
80
  "devDependencies": {
79
81
  "@arethetypeswrong/cli": "^0.18.5",
80
- "@syntopica/eslint-config": "0.10.1",
82
+ "@syntopica/eslint-config": "0.10.2",
81
83
  "@types/node": "^26.6.6",
82
84
  "@typescript/native": "npm:typescript@^7.0.2",
83
85
  "dependency-cruiser": "^18.9.0",
@@ -0,0 +1,5 @@
1
+ /** Options of `createLefthookConfig`. */
2
+ export type LefthookOptions = {
3
+ /** The repository keeps a tadu backlog: validate it, and keep prettier off it. */
4
+ tadu?: boolean
5
+ }
@@ -0,0 +1,7 @@
1
+ /** Backlog paths of a tadu repository, all at the repository root. */
2
+ export const TADU_BACKLOG_PATHS: readonly string[] = [
3
+ 'todo/**',
4
+ 'TODO.md',
5
+ 'TODO_LOG.md',
6
+ 'TODO_HISTORY_INDEX.jsonl',
7
+ ]
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 = (): LefthookConfig => ({
18
- 'pre-commit': {
19
- parallel: true,
20
- commands: {
21
- 'lint:fast': {
22
- glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}',
23
- run: 'pnpm exec oxlint --deny-warnings {staged_files}',
24
- },
25
- lint: {
26
- glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}',
27
- run: 'pnpm exec eslint --max-warnings 0 --no-warn-ignored {staged_files}',
28
- },
29
- format: {
30
- glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs,json,md,css,yml,yaml}',
31
- run: 'pnpm exec prettier --check {staged_files}',
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
- // The release tooling reads the commit type to pick the semver bump and to
36
- // build the changelog, so a mistyped subject is a silent release defect.
37
- // This is the only place it can be caught: by the time the tag is cut the
38
- // message is already history.
39
- 'commit-msg': {
40
- commands: {
41
- commitlint: {
42
- run: 'pnpm exec commitlint --edit {1}',
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
- 'pre-push': {
47
- commands: {
48
- secrets: {
49
- run: 'gitleaks detect --no-banner --redact',
69
+ 'pre-push': {
70
+ commands: {
71
+ secrets: {
72
+ run: 'gitleaks detect --no-banner --redact',
73
+ },
50
74
  },
51
75
  },
52
- },
53
- })
76
+ }
77
+ }