@syntopica/quality-config 0.12.0 → 0.13.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) BusiRocket
3
+ Copyright (c) Syntopica
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/PUBLIC_API.md CHANGED
@@ -38,10 +38,11 @@ then cruise separately with `scope: 'workspace'`.
38
38
 
39
39
  ## Stable executables (semver)
40
40
 
41
- | Binary | Purpose |
42
- | ------------------- | ---------------------------------------------------------- |
43
- | `baseline-env-init` | Seed a gitignored `.env` from the committed `.env.example` |
44
- | `baseline-dupes` | Run jscpd against this package's canonical `jscpd.json` |
41
+ | Binary | Purpose |
42
+ | ------------------------ | ---------------------------------------------------------- |
43
+ | `baseline-env-init` | Seed a gitignored `.env` from the committed `.env.example` |
44
+ | `baseline-hooks-install` | Run `lefthook install` only from the git repository root |
45
+ | `baseline-dupes` | Run jscpd against this package's canonical `jscpd.json` |
45
46
 
46
47
  `baseline-env-init` takes no arguments and always exits 0. It copies
47
48
  `.env.example` to `.env` in the current working directory, does nothing when
@@ -49,6 +50,11 @@ then cruise separately with `scope: 'workspace'`.
49
50
  into `prepare` so a freshly cloned project boots with the documented example
50
51
  values instead of failing its startup env validation.
51
52
 
53
+ `baseline-hooks-install` forwards its arguments to `lefthook install` and exits
54
+ with its status. It exits 0 without installing when the current directory is not
55
+ the git repository root (a package nested in a workspace, whose root owns the
56
+ hooks) or is not inside a git repository at all.
57
+
52
58
  `baseline-dupes` takes the paths to scan (a bare call scans `.`) and forwards
53
59
  every other argument to jscpd, where it wins over the config file. jscpd 5.x is
54
60
  a Rust binary with no JS config loader, which is why this gate ships as a JSON
package/README.md CHANGED
@@ -45,7 +45,7 @@ renders and reports a blank page rather than a useful error.
45
45
  ```json
46
46
  {
47
47
  "scripts": {
48
- "prepare": "lefthook install && baseline-env-init"
48
+ "prepare": "baseline-hooks-install && baseline-env-init"
49
49
  }
50
50
  }
51
51
  ```
@@ -54,6 +54,15 @@ Idempotent: an existing `.env` is never overwritten, and a project with no
54
54
  `.env.example` is a no-op. It never writes a value into version control - `.env`
55
55
  stays gitignored, `.env.example` stays the only committed copy.
56
56
 
57
+ ### `baseline-hooks-install`
58
+
59
+ Runs `lefthook install`, but only when the package is the root of its git
60
+ repository. A package nested in a workspace skips the install, because lefthook
61
+ would rewrite the enclosing repository's `.git/hooks`, and pnpm runs every
62
+ workspace package's `prepare` in parallel: two packages replacing the same hook
63
+ at once fail the install. Outside a git repository it skips too. Arguments are
64
+ forwarded to `lefthook install`.
65
+
57
66
  ### `baseline-dupes`
58
67
 
59
68
  Runs the cross-file duplication gate against this package's canonical
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ // Installs the project's lefthook git hooks, but only from the repository root.
3
+ //
4
+ // `prepare: lefthook install` is right for a standalone project and wrong for a
5
+ // package nested in a workspace: lefthook walks up to the enclosing repository
6
+ // and rewrites its `.git/hooks`, and pnpm runs every workspace package's
7
+ // `prepare` in parallel. In this monorepo eight templates did that at once, and
8
+ // two of them replacing the same hook raced:
9
+ // `could not replace the hook: remove .git/hooks/pre-push: no such file or directory`
10
+ // failed a CI `pnpm install --frozen-lockfile` (green on re-run). Even when it
11
+ // did not race, the last template to finish left the root's hooks pointing at
12
+ // its own lefthook binary.
13
+ //
14
+ // The repository root owns its hooks, so a nested package skips the install
15
+ // and says why. Outside any git repository (an unpacked tarball, a CI cache
16
+ // restore) there is nothing to install into, so it skips too. Any argument is
17
+ // forwarded to `lefthook install`.
18
+ import { spawnSync } from 'node:child_process'
19
+ import { realpathSync } from 'node:fs'
20
+ import { argv, cwd, exit, platform } from 'node:process'
21
+
22
+ const toplevel = spawnSync('git', ['rev-parse', '--show-toplevel'], {
23
+ encoding: 'utf8',
24
+ })
25
+
26
+ if (toplevel.status !== 0) {
27
+ console.log('baseline-hooks-install: not a git repository, skipped.')
28
+ exit(0)
29
+ }
30
+
31
+ // Both paths are the invoking repository's own, from git and the working
32
+ // directory - not untrusted input. Resolved so a symlinked checkout compares
33
+ // equal to itself.
34
+ /* eslint-disable security/detect-non-literal-fs-filename */
35
+ const root = realpathSync(toplevel.stdout.trim())
36
+ const here = realpathSync(cwd())
37
+ /* eslint-enable security/detect-non-literal-fs-filename */
38
+
39
+ if (root !== here) {
40
+ console.log(
41
+ `baseline-hooks-install: ${here} is nested in ${root}, which owns the hooks; skipped.`,
42
+ )
43
+ exit(0)
44
+ }
45
+
46
+ const install = spawnSync('lefthook', ['install', ...argv.slice(2)], {
47
+ stdio: 'inherit',
48
+ shell: platform === 'win32',
49
+ })
50
+
51
+ exit(install.status ?? 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syntopica/quality-config",
3
- "version": "0.12.0",
3
+ "version": "0.13.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",
@@ -25,6 +25,7 @@
25
25
  "baseline-deps-graph": "bin/baseline-deps-graph.mjs",
26
26
  "baseline-dupes": "bin/baseline-dupes.mjs",
27
27
  "baseline-env-init": "bin/baseline-env-init.mjs",
28
+ "baseline-hooks-install": "bin/baseline-hooks-install.mjs",
28
29
  "baseline-licenses": "bin/baseline-licenses.mjs",
29
30
  "baseline-type-coverage": "bin/baseline-type-coverage.mjs"
30
31
  },
@@ -72,13 +73,13 @@
72
73
  },
73
74
  "devDependencies": {
74
75
  "@arethetypeswrong/cli": "^0.18.5",
75
- "@syntopica/eslint-config": "0.8.0",
76
- "@types/node": "^26.6.3",
76
+ "@syntopica/eslint-config": "0.9.0",
77
+ "@types/node": "^26.6.4",
77
78
  "dependency-cruiser": "^18.5.0",
78
- "eslint": "^10.11.0",
79
+ "eslint": "^10.12.0",
79
80
  "eslint-plugin-regexp": "^3.3.1",
80
- "knip": "^6.39.0",
81
- "publint": "^0.3.24",
81
+ "knip": "^6.40.0",
82
+ "publint": "^0.3.25",
82
83
  "typescript": "npm:@typescript/typescript6@^6.0.2"
83
84
  },
84
85
  "scripts": {
@@ -46,14 +46,13 @@ export const FRAMEWORK_ENTRIES: Record<
46
46
  // Every file convention belongs in the one brace alternation rather than in a
47
47
  // pattern of its own, including the metadata routes (`sitemap`, `robots`,
48
48
  // `manifest`, the image generators): a pattern matching nothing is a hint, and
49
- // no project uses all of them. `middleware` and `proxy` share a pattern for
50
- // the same reason - Next 16 renamed the file, and a project has one or the
51
- // other, never both.
49
+ // no project uses all of them. `middleware` and `proxy` are left to knip's
50
+ // Next.js plugin, which registers both: listing them here only produced a
51
+ // "Refine entry pattern (no matches)" hint in a project that has neither.
52
52
  nextjs: {
53
53
  entry: [
54
54
  '{,src/}app/**/{page,layout,loading,error,global-error,not-found,route,template,default,sitemap,robots,manifest,icon,apple-icon,opengraph-image,twitter-image}.{ts,tsx}',
55
55
  'next.config.*',
56
- '{,src/}{middleware,proxy}.ts',
57
56
  ],
58
57
  project: ['{,src/}app/**/*.{ts,tsx}', 'src/**/*.{ts,tsx}'],
59
58
  includeEntryExports: false,
@@ -92,13 +91,15 @@ export const FRAMEWORK_ENTRIES: Record<
92
91
  project: ['src/**/*.ts'],
93
92
  includeEntryExports: true,
94
93
  },
94
+ // `src/main.*` is reached through index.html's module script; listing it as
95
+ // well was a "Remove redundant entry pattern" hint in both Vite templates.
95
96
  'vite-react': {
96
- entry: ['src/main.tsx', 'index.html', 'vite.config.*'],
97
+ entry: ['index.html', 'vite.config.*'],
97
98
  project: ['src/**/*.{ts,tsx}'],
98
99
  includeEntryExports: false,
99
100
  },
100
101
  'vite-vue': {
101
- entry: ['src/main.ts', 'index.html', 'vite.config.*'],
102
+ entry: ['index.html', 'vite.config.*'],
102
103
  project: ['src/**/*.{ts,vue}'],
103
104
  includeEntryExports: false,
104
105
  },
package/src/knip.ts CHANGED
@@ -32,7 +32,8 @@ import { FRAMEWORK_ENTRIES, type KnipFramework } from './knip-framework'
32
32
  // is a dependency that silently stops being checked.
33
33
  // The tools this package's own runners spawn through `pnpm exec`:
34
34
  // `baseline-dupes` spawns `jscpd`, `baseline-type-coverage` spawns
35
- // `type-coverage`, `baseline-deps-graph` spawns `depcruise`. A project that
35
+ // `type-coverage`, `baseline-deps-graph` spawns `depcruise`,
36
+ // `baseline-hooks-install` spawns `lefthook`. A project that
36
37
  // wires the runner into its scripts never names the underlying tool anywhere
37
38
  // knip can see, so knip reports a real dependency as unused. Found in
38
39
  // a consumer the moment its `type-coverage` script became
@@ -46,6 +47,7 @@ const BASELINE_RUNNER_DEPENDENCIES = [
46
47
  'jscpd',
47
48
  'type-coverage',
48
49
  'dependency-cruiser',
50
+ 'lefthook',
49
51
  ]
50
52
 
51
53
  const ESLINT_PEER_DEPENDENCIES = [
@@ -70,9 +72,12 @@ const ESLINT_PEER_DEPENDENCIES = [
70
72
  export const createKnipConfig = (options: {
71
73
  framework: KnipFramework
72
74
  /**
73
- * Binaries knip cannot resolve. Nothing is ignored by default: an entry for
74
- * a binary knip *can* resolve becomes a permanent `Remove from
75
- * ignoreBinaries` hint the consumer has no way to silence.
75
+ * Binaries knip cannot resolve, merged with `gitleaks`. That one is ignored
76
+ * by default because the baseline itself writes `gitleaks detect` into every
77
+ * project's `secrets:check`, and it is a system binary no package provides,
78
+ * so every template reported it as unlisted. Nothing else is: an entry for a
79
+ * binary knip *can* resolve becomes a permanent `Remove from ignoreBinaries`
80
+ * hint the consumer has no way to silence.
76
81
  */
77
82
  ignoreBinaries?: string[]
78
83
  /** Merged with the built-in lists, never replacing them. */
@@ -144,7 +149,7 @@ export const createKnipConfig = (options: {
144
149
  // boolean. It only hides an export that its own file already uses: an
145
150
  // export nothing references at all still fails the gate.
146
151
  ignoreExportsUsedInFile: true,
147
- ignoreBinaries: options.ignoreBinaries ?? [],
152
+ ignoreBinaries: ['gitleaks', ...(options.ignoreBinaries ?? [])],
148
153
  ignoreDependencies: [
149
154
  ...BASELINE_RUNNER_DEPENDENCIES,
150
155
  ...ESLINT_PEER_DEPENDENCIES,