@coding-with-hassan/devkit 1.1.0 → 1.2.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/README.md CHANGED
@@ -139,6 +139,8 @@ export default lintStaged({ exclude: ['api-client'], extra: { 'scripts/**/*.mjs'
139
139
 
140
140
  Every project with an ESLint/Prettier config gets `pnpm -C <dir> exec …` entries (api: `**/*.ts`; spa/lib: `src/**/*.{ts,html}` and `src/**/*.{scss,css,json}`). No project list to maintain.
141
141
 
142
+ The hook never rewrites silently. lint-staged re-stages the fixes `eslint --fix` / `prettier --write` applied, so the hook snapshots the staged tree (`git write-tree`) before and after it runs: when the tree changed, the commit is **aborted** and the rewritten files are listed — the tree that gets committed and pushed must be one that was built and tested (an auto-fix such as `type` → `interface` can break a production build that was green locally). Fixers cascade (Prettier reformats what `eslint --fix` produced only on the next run), so lint-staged is re-run until the staged tree is stable (at most three extra passes) before the files are listed. The fixes stay staged: review them (`git diff --cached`), rebuild what they touch, then run the same `git commit` again — the second attempt on the unchanged tree passes. Clean commits pass in one go with no extra output.
143
+
142
144
  `hassan-devkit ci:doctor` fails when the installed devkit does not satisfy the declared range (stale `node_modules`), when the config block is invalid, or when the husky shims are missing.
143
145
 
144
146
  ### CI (`ci:*`)
@@ -148,7 +150,7 @@ Every project with an ESLint/Prettier config gets `pnpm -C <dir> exec …` entri
148
150
  - `hassan-devkit ci:commit-standards [--repo o/r --pr n]` — every non-merge PR commit must match `hassan-devkit commits:show` and, with `commits.requireSigned`, be Verified on GitHub. PRs by `commits.exemptAuthors` skip the check. Needs `GH_TOKEN`.
149
151
  - `hassan-devkit ci:cache attach|detach` — move Nx's task cache between `.nx` and the cacheable `.nx-ci-cache` folder, re-homing the machine-id-named index so restored entries are actually hit.
150
152
  - `hassan-devkit ci:check [--base --head]` — `ci:doctor`, then `format:check` for the projects owning a changed file (content files included), then every `ci.checks[]` whose `paths` regex matches a changed file runs its `run` command.
151
- - `hassan-devkit ci:affected [--targets lint,build] [--base --head] [--with-content] [--dry-run]` — graph targets (`build`) for touched projects and dependents, own-files targets (`lint`, `format:check`) only for projects owning a changed file; files no target reads (docs, `ci.affected.contentOnly`) are dropped first; `ci.affected.adopted` maps files outside any project to the project whose target reads them.
153
+ - `hassan-devkit ci:affected [--targets lint,build] [--base --head] [--with-content] [--dry-run]` — graph targets (`build`) for touched projects and dependents, own-files targets (`lint`, `format:check`) only for projects owning a changed file; files no target reads (docs, `ci.affected.contentOnly`) are dropped first; `ci.affected.adopted` maps files outside any project to the project whose target reads them — an adopted file always counts, even under `docs/` or a `contentOnly` glob (e.g. `"docs/testing/*.ts": "daz-i18n"` for acceptance-case data a lib's `format:check` covers).
152
154
 
153
155
  ### Claude Code layer
154
156
 
@@ -15,5 +15,36 @@ if git diff --cached --name-only | grep -q '^\.github/workflows/ci\.yml$'; then
15
15
  pnpm exec hassan-devkit ci:doctor || exit 1
16
16
  fi
17
17
 
18
- # 4. Per-project lint/format on staged files (targets derived from the workspace)
19
- pnpm exec lint-staged
18
+ # 4. Per-project lint/format on staged files (targets derived from the workspace). The hook
19
+ # never rewrites silently (README → "Pre-commit chain"): the staged tree (`git write-tree`)
20
+ # is compared before and after lint-staged; fixers cascade, so lint-staged is re-run until
21
+ # the tree is stable, then a changed tree aborts the commit with the rewritten files listed.
22
+ max_reruns=3
23
+ before=$(git write-tree) || exit 1
24
+ previous=$before
25
+ reruns=0
26
+ failed=0
27
+ stable=1
28
+ while :; do
29
+ pnpm exec lint-staged || failed=1
30
+ after=$(git write-tree) || exit 1
31
+ [ "$failed" -eq 1 ] && break
32
+ [ "$after" = "$previous" ] && break
33
+ if [ "$reruns" -ge "$max_reruns" ]; then stable=0; break; fi
34
+ previous=$after
35
+ reruns=$((reruns + 1))
36
+ done
37
+ if [ "$before" != "$after" ]; then
38
+ {
39
+ echo ""
40
+ echo "pre-commit: lint-staged rewrote staged files — the fixes are applied and staged, but the commit is aborted:"
41
+ git diff --name-only "$before" "$after" | sed 's/^/ /'
42
+ if [ "$stable" -eq 1 ]; then
43
+ echo "Review them (git diff --cached), rebuild what they touch, then run the same git commit again."
44
+ else
45
+ echo "The fixers were still changing these files after $max_reruns re-runs (conflicting prettier/eslint rules?) — review them (git diff --cached), then run the same git commit again."
46
+ fi
47
+ } >&2
48
+ exit 1
49
+ fi
50
+ exit "$failed"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coding-with-hassan/devkit",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "CLI for the developer workflow shared across Hassan's client projects: docker compose orchestration, db helpers, and husky hook installation.",
5
5
  "license": "MIT",
6
6
  "author": "Hassan Khousheish",
@@ -21,7 +21,9 @@ import { capture, run } from '../exec.js';
21
21
  *
22
22
  * Project-specific lists come from `ci.affected` in the config: `contentOnly` (globs of
23
23
  * files copied verbatim into outputs — skipped unless `--with-content`) and `adopted`
24
- * (glob → project that reads files outside every project root).
24
+ * (glob → project that reads files outside every project root). An adopted file is, by
25
+ * definition, read by a project target, so it is never dropped — not by the docs filter and
26
+ * not by `contentOnly` — even when it lives under `docs/` (acceptance-case data files, say).
25
27
  */
26
28
 
27
29
  export const DOCS_ONLY = [/\.md$/, /^docs\//];
@@ -53,9 +55,10 @@ export function classifyFiles(changed, { roots, contentOnly = [], adopted = {},
53
55
  const contentRes = contentOnly.map(globToRegExp);
54
56
  const adoptedRes = Object.entries(adopted).map(([glob, project]) => [globToRegExp(glob), project]);
55
57
  const ignore = withContent ? DOCS_ONLY : [...DOCS_ONLY, ...contentRes];
58
+ const isAdopted = (f) => adoptedRes.some(([re]) => re.test(f));
56
59
  const ignored = [];
57
60
  const files = [];
58
- for (const f of changed) (ignore.some((re) => re.test(f)) ? ignored : files).push(f);
61
+ for (const f of changed) (!isAdopted(f) && ignore.some((re) => re.test(f)) ? ignored : files).push(f);
59
62
  const touched = new Set();
60
63
  const globals = [];
61
64
  const unowned = [];