@syntopica/quality-config 0.12.1 → 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 +1 -1
- package/PUBLIC_API.md +10 -4
- package/README.md +10 -1
- package/bin/baseline-hooks-install.mjs +51 -0
- package/package.json +2 -1
- package/src/knip.ts +3 -1
package/LICENSE
CHANGED
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
|
|
42
|
-
|
|
|
43
|
-
| `baseline-env-init`
|
|
44
|
-
| `baseline-
|
|
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": "
|
|
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.
|
|
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
|
},
|
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
|
|
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 = [
|