@rexezuge/tooling 1.3.0 → 1.4.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/dist/eslint-boundaries.d.ts +12 -4
- package/dist/eslint-boundaries.d.ts.map +1 -1
- package/dist/eslint-boundaries.js +1 -224
- package/dist/eslint-boundaries.js.map +7 -1
- package/dist/eslint-rules.js +1 -273
- package/dist/eslint-rules.js.map +7 -1
- package/dist/eslint.js +1 -194
- package/dist/eslint.js.map +7 -1
- package/dist/functions/pages-proxy.d.ts.map +1 -1
- package/dist/functions/pages-proxy.js +1 -131
- package/dist/functions/pages-proxy.js.map +7 -1
- package/dist/index.js +1 -31
- package/dist/index.js.map +7 -1
- package/dist/scripts/backup/d1-target.d.ts +15 -5
- package/dist/scripts/backup/d1-target.d.ts.map +1 -1
- package/dist/scripts/backup/d1-target.js +1 -31
- package/dist/scripts/backup/d1-target.js.map +7 -1
- package/dist/scripts/backup/destination-config.d.ts +24 -8
- package/dist/scripts/backup/destination-config.d.ts.map +1 -1
- package/dist/scripts/backup/destination-config.js +1 -57
- package/dist/scripts/backup/destination-config.js.map +7 -1
- package/dist/scripts/backup/encrypt-backup.js +2 -97
- package/dist/scripts/backup/encrypt-backup.js.map +7 -1
- package/dist/scripts/backup/naming.d.ts +3 -1
- package/dist/scripts/backup/naming.d.ts.map +1 -1
- package/dist/scripts/backup/naming.js +1 -58
- package/dist/scripts/backup/naming.js.map +7 -1
- package/dist/scripts/check-god-files.d.ts +40 -14
- package/dist/scripts/check-god-files.d.ts.map +1 -1
- package/dist/scripts/check-god-files.js +2 -271
- package/dist/scripts/check-god-files.js.map +7 -1
- package/dist/scripts/ensure-spa-shell-stub.js +1 -29
- package/dist/scripts/ensure-spa-shell-stub.js.map +7 -1
- package/dist/scripts/init-secrets.d.ts +0 -16
- package/dist/scripts/init-secrets.d.ts.map +1 -1
- package/dist/scripts/init-secrets.js +2 -239
- package/dist/scripts/init-secrets.js.map +7 -1
- package/dist/scripts/lib/cli-args.d.ts.map +1 -1
- package/dist/scripts/lib/cli-args.js +1 -116
- package/dist/scripts/lib/cli-args.js.map +7 -1
- package/dist/scripts/lib/github-actions.js +3 -38
- package/dist/scripts/lib/github-actions.js.map +7 -1
- package/dist/scripts/lib/wrangler-table.d.ts.map +1 -1
- package/dist/scripts/lib/wrangler-table.js +2 -99
- package/dist/scripts/lib/wrangler-table.js.map +7 -1
- package/dist/scripts/migrations-lock.js +1 -44
- package/dist/scripts/migrations-lock.js.map +7 -1
- package/dist/scripts/prepare-wrangler-config.js +1 -49
- package/dist/scripts/prepare-wrangler-config.js.map +7 -1
- package/dist/scripts/spa-shell.d.ts +12 -4
- package/dist/scripts/spa-shell.d.ts.map +1 -1
- package/dist/scripts/spa-shell.js +3 -160
- package/dist/scripts/spa-shell.js.map +7 -1
- package/dist/scripts/validate-locales.d.ts +13 -5
- package/dist/scripts/validate-locales.d.ts.map +1 -1
- package/dist/scripts/validate-locales.js +4 -350
- package/dist/scripts/validate-locales.js.map +7 -1
- package/dist/scripts/verify-migrations.d.ts +27 -9
- package/dist/scripts/verify-migrations.d.ts.map +1 -1
- package/dist/scripts/verify-migrations.js +2 -312
- package/dist/scripts/verify-migrations.js.map +7 -1
- package/dist/scripts/verify-spa-shell.js +1 -52
- package/dist/scripts/verify-spa-shell.js.map +7 -1
- package/dist/scripts/wrangler-config/cli.js +3 -51
- package/dist/scripts/wrangler-config/cli.js.map +7 -1
- package/dist/scripts/wrangler-config/patches.d.ts +9 -3
- package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/patches.js +4 -141
- package/dist/scripts/wrangler-config/patches.js.map +7 -1
- package/dist/scripts/wrangler-config/resources.d.ts +18 -6
- package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/resources.js +1 -290
- package/dist/scripts/wrangler-config/resources.js.map +7 -1
- package/dist/scripts/wrangler-config/types.d.ts +24 -8
- package/dist/scripts/wrangler-config/types.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/types.js +1 -49
- package/dist/scripts/wrangler-config/types.js.map +7 -1
- package/dist/test/integration-migrations.d.ts +29 -12
- package/dist/test/integration-migrations.d.ts.map +1 -1
- package/dist/test/integration-migrations.js +2 -171
- package/dist/test/integration-migrations.js.map +7 -1
- package/dist/test/mocks/cloudflare-workers.js +1 -90
- package/dist/test/mocks/cloudflare-workers.js.map +7 -1
- package/dist/vite.d.ts +5 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +3 -125
- package/dist/vite.js.map +7 -1
- package/dist/vitest-aliases.d.ts.map +1 -1
- package/dist/vitest-aliases.js +1 -81
- package/dist/vitest-aliases.js.map +7 -1
- package/dist/vitest-integration.js +1 -64
- package/dist/vitest-integration.js.map +7 -1
- package/dist/vitest-repo.js +1 -146
- package/dist/vitest-repo.js.map +7 -1
- package/dist/vitest-web.js +1 -109
- package/dist/vitest-web.js.map +7 -1
- package/dist/vitest.js +1 -133
- package/dist/vitest.js.map +7 -1
- package/package.json +3 -3
- package/src/eslint-boundaries.ts +13 -5
- package/src/eslint.test.ts +18 -8
- package/src/functions/pages-proxy.test.ts +1 -1
- package/src/functions/pages-proxy.ts +4 -2
- package/src/scripts/backup/backup-rules.test.ts +1 -1
- package/src/scripts/backup/d1-target.ts +15 -5
- package/src/scripts/backup/destination-config.ts +27 -9
- package/src/scripts/backup/encrypt-backup.ts +10 -8
- package/src/scripts/backup/naming.ts +3 -1
- package/src/scripts/check-god-files.test.ts +18 -18
- package/src/scripts/check-god-files.ts +60 -31
- package/src/scripts/init-secrets.ts +17 -7
- package/src/scripts/lib/cli-args.ts +6 -3
- package/src/scripts/lib/wrangler-table.ts +5 -3
- package/src/scripts/migrations-lock.ts +1 -1
- package/src/scripts/spa-shell.test.ts +17 -17
- package/src/scripts/spa-shell.ts +26 -14
- package/src/scripts/validate-locales.test.ts +17 -17
- package/src/scripts/validate-locales.ts +43 -25
- package/src/scripts/verify-migrations.test.ts +7 -7
- package/src/scripts/verify-migrations.ts +47 -24
- package/src/scripts/wrangler-config/patches.ts +12 -4
- package/src/scripts/wrangler-config/resources.ts +30 -14
- package/src/scripts/wrangler-config/types.ts +24 -8
- package/src/test/integration-migrations.test.ts +6 -6
- package/src/test/integration-migrations.ts +33 -14
- package/src/vite.test.ts +24 -13
- package/src/vite.ts +5 -5
- package/src/vitest-aliases.ts +1 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-god-files.d.ts","sourceRoot":"","sources":["../../src/scripts/check-god-files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAQH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B
|
|
1
|
+
{"version":3,"file":"check-god-files.d.ts","sourceRoot":"","sources":["../../src/scripts/check-god-files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAQH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;MAEE;IACF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;MAEE;IACF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;MAEE;IACF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;MAEE;IACF,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C;;MAEE;IACF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;MAEE;IACF,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IAChD;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB;;MAEE;IACF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;MAEE;IACF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC;;MAEE;IACF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;MAEE;IACF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;MAEE;IACF,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;EAEE;AACF,eAAO,MAAM,UAAU,MAAM,CAAC;AAC9B;;EAEE;AACF,eAAO,MAAM,UAAU,MAAM,CAAC;AA+B9B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAc/C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAEhF;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAqB3C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CA+BpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,SAAS,MAAM,EAA0B,GAAG,MAAM,CA0BxF"}
|
|
@@ -1,271 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Provenance: converged from the seven `.mjs` copies (AWS-AccessBridge,
|
|
5
|
-
* CalDAV-Bridge, ChordDHT-Tracker, Durable-DAV, Durable-DAV-Router, Edge-Git,
|
|
6
|
-
* Mail-Meow, Mail-Otter) and the typed ratchet in Edge-Sonic.
|
|
7
|
-
*
|
|
8
|
-
* All seven `.mjs` copies are one script with two constants: soft 300 (warn),
|
|
9
|
-
* hard 400 (error). The typed variant is not a different rule so much as a
|
|
10
|
-
* different answer to "what does the gate enforce", and that is the decision this
|
|
11
|
-
* module has to take once for the whole family.
|
|
12
|
-
*
|
|
13
|
-
* ### The convergence: warn-only, with an allowlist
|
|
14
|
-
*
|
|
15
|
-
* The two source designs:
|
|
16
|
-
*
|
|
17
|
-
* - **Ceiling** (six repos) — 300 warn, 400 error, `exit 1` on 400. Durable-DAV's
|
|
18
|
-
* own `AGENTS.md` records what that measures: **ten** files sit just over 300
|
|
19
|
-
* and none is a god file, so `WARN` reports every run and `HARD` has never
|
|
20
|
-
* fired. A ceiling set above the largest file in the tree cannot tell a
|
|
21
|
-
* repository getting worse from one that never got better, and raising it is
|
|
22
|
-
* always available.
|
|
23
|
-
* - **Ratchet** (Edge-Sonic) — a committed baseline records every file's size; a
|
|
24
|
-
* file may shrink freely and grow only to its recorded size. It cannot be
|
|
25
|
-
* satisfied by raising a number, which is its whole strength.
|
|
26
|
-
*
|
|
27
|
-
* The ratchet is the better *rule*, and the ceiling is the better *gate*: the
|
|
28
|
-
* ratchet needs a baseline maintained per file and fails the first time somebody
|
|
29
|
-
* writes a legitimate 320-line module, which is the failure mode that trains
|
|
30
|
-
* everyone to ignore a report. So the converged script keeps the 300/400
|
|
31
|
-
* thresholds — every repo's CI already prints them — and makes the verdict
|
|
32
|
-
* **warn-only by default**, with two escape valves that are both visible in a
|
|
33
|
-
* diff:
|
|
34
|
-
*
|
|
35
|
-
* 1. `--fail-on-hard` turns the 400 line back into a failing gate, for a repo
|
|
36
|
-
* that has paid its debt and wants the ceiling enforced.
|
|
37
|
-
* 2. An **allowlist** records the files that are over the line and known, so the
|
|
38
|
-
* report names only the ones that are *new*. That is the ratchet's
|
|
39
|
-
* "recorded size" idea without its per-file bookkeeping: the allowlist is
|
|
40
|
-
* reviewed by the same commit that grows the file, because the diff shows what
|
|
41
|
-
* was added to it.
|
|
42
|
-
*
|
|
43
|
-
* Tests are excluded, as every source does. A double modelling the platform grows
|
|
44
|
-
* with the platform's surface, not with the complexity of the code it stands in
|
|
45
|
-
* for — Edge-Sonic's ratchet holds them too, and its own notes record a 4,343-line
|
|
46
|
-
* fixture, so this is a documented disagreement rather than an oversight.
|
|
47
|
-
*/
|
|
48
|
-
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
49
|
-
import { pathToFileURL } from 'node:url';
|
|
50
|
-
import { join, relative } from 'node:path';
|
|
51
|
-
import { fail } from "./lib/github-actions.js";
|
|
52
|
-
import { isSet, parseFlags, splitPositional, valueOf } from "./lib/cli-args.js";
|
|
53
|
-
/** Default soft limit, as every source repo uses. */
|
|
54
|
-
export const SOFT_LIMIT = 300;
|
|
55
|
-
/** Default hard limit, as every source repo uses. */
|
|
56
|
-
export const HARD_LIMIT = 400;
|
|
57
|
-
/**
|
|
58
|
-
* Directories the walker never enters.
|
|
59
|
-
*
|
|
60
|
-
* Build output and VCS state; `coverage` is here because a generated HTML report
|
|
61
|
-
* is thousands of "lines" of nothing.
|
|
62
|
-
*/
|
|
63
|
-
const EXCLUDE_DIRS = new Set(['node_modules', 'dist', '.wrangler', 'coverage', 'coverage-integration', 'coverage-web', '.git']);
|
|
64
|
-
/**
|
|
65
|
-
* Source extensions the guard counts.
|
|
66
|
-
*
|
|
67
|
-
* `css` is in the set because every source repo counts it, and a 400-line
|
|
68
|
-
* stylesheet is the same reading problem as a 400-line module.
|
|
69
|
-
*/
|
|
70
|
-
const SOURCE_EXTENSIONS = /\.(?:ts|tsx|js|mjs|cjs|css)$/;
|
|
71
|
-
/**
|
|
72
|
-
* The test-file suffixes the guard skips.
|
|
73
|
-
*
|
|
74
|
-
* `.test.tsx` matter as much as `.test.ts`: the walker collects both, so a list
|
|
75
|
-
* that only named the `.ts` forms let every React test file through the guard and
|
|
76
|
-
* reported them as god files — which is how Durable-DAV-Router discovered it.
|
|
77
|
-
* Built from the kinds and extensions rather than enumerated, so a new test
|
|
78
|
-
* extension cannot silently escape.
|
|
79
|
-
*/
|
|
80
|
-
const TEST_SUFFIXES = ['test', 'spec'].flatMap((kind) => ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'].map((ext) => `.${kind}${ext}`));
|
|
81
|
-
/**
|
|
82
|
-
* Whether a repo-relative path is exempt from the guard.
|
|
83
|
-
*
|
|
84
|
-
* Provenance: AWS-AccessBridge's version is the canonical one, because it
|
|
85
|
-
* documents and fixes two live bugs in the others.
|
|
86
|
-
*
|
|
87
|
-
* Every directory pattern is anchored with `(?:^|/)` rather than a bare leading
|
|
88
|
-
* `/`. `relative()` yields `test/helpers/x.ts` for a top-level test directory and
|
|
89
|
-
* `scripts/lib/x.ts` for the scripts directory — **no leading separator** — so a
|
|
90
|
-
* pattern written as `/\/(?:test|tests|__tests__)\//` never matches either one.
|
|
91
|
-
* It looks right, it does match when handed an absolute path, and against these
|
|
92
|
-
* layouts it is silently a no-op. Durable-DAV and ChordDHT-Tracker ship exactly
|
|
93
|
-
* that dead pattern.
|
|
94
|
-
*/
|
|
95
|
-
export function shouldSkip(rel) {
|
|
96
|
-
if (/(?:^|\/)(?:locales|generated)\//.test(rel))
|
|
97
|
-
return true;
|
|
98
|
-
if (/(?:^|\/)__(?:tests|mocks)__(?:\/|$)/.test(rel))
|
|
99
|
-
return true;
|
|
100
|
-
if (/(?:^|\/)scripts\//.test(rel))
|
|
101
|
-
return true;
|
|
102
|
-
if (/(?:^|\/)(?:test|tests|__tests__)\//.test(rel))
|
|
103
|
-
return true;
|
|
104
|
-
if (/\.config\.(?:m?[jt]s|cjs)$/.test(rel))
|
|
105
|
-
return true;
|
|
106
|
-
if (rel.endsWith('.d.ts'))
|
|
107
|
-
return true;
|
|
108
|
-
if (rel.endsWith('.json'))
|
|
109
|
-
return true;
|
|
110
|
-
if (rel.endsWith('.sql'))
|
|
111
|
-
return true;
|
|
112
|
-
if (rel.endsWith('.md'))
|
|
113
|
-
return true;
|
|
114
|
-
return TEST_SUFFIXES.some((suffix) => rel.endsWith(suffix));
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Whether a repo-relative path is on the allowlist.
|
|
118
|
-
*
|
|
119
|
-
* An entry ending in `/` exempts a whole directory; any other entry is matched
|
|
120
|
-
* exactly, so `apps/api/src/index.ts` does not exempt `apps/api/src/index.util.ts`.
|
|
121
|
-
*/
|
|
122
|
-
export function isAllowlisted(rel, allowlist) {
|
|
123
|
-
return allowlist.some((entry) => (entry.endsWith('/') ? rel.startsWith(entry) : rel === entry));
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Every source file under `root`, as repo-relative paths.
|
|
127
|
-
*
|
|
128
|
-
* Symlink-safe: a dangling symlink or a file removed mid-walk is skipped rather
|
|
129
|
-
* than thrown, because neither is a god-file problem.
|
|
130
|
-
*/
|
|
131
|
-
export function walk(root) {
|
|
132
|
-
const out = [];
|
|
133
|
-
const visit = (dir) => {
|
|
134
|
-
for (const entry of readdirSync(dir)) {
|
|
135
|
-
const full = join(dir, entry);
|
|
136
|
-
let stat;
|
|
137
|
-
try {
|
|
138
|
-
stat = statSync(full);
|
|
139
|
-
}
|
|
140
|
-
catch {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (stat.isDirectory()) {
|
|
144
|
-
if (EXCLUDE_DIRS.has(entry))
|
|
145
|
-
continue;
|
|
146
|
-
visit(full);
|
|
147
|
-
}
|
|
148
|
-
else if (SOURCE_EXTENSIONS.test(entry)) {
|
|
149
|
-
out.push(relative(root, full));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
visit(root);
|
|
154
|
-
return out;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Run the guard over a tree.
|
|
158
|
-
*
|
|
159
|
-
* Pure with respect to the verdict — the only I/O is the walk and a line count —
|
|
160
|
-
* so a test drives it against a temporary directory.
|
|
161
|
-
*/
|
|
162
|
-
export function checkGodFiles(options) {
|
|
163
|
-
const soft = options.soft ?? SOFT_LIMIT;
|
|
164
|
-
const hard = options.hard ?? HARD_LIMIT;
|
|
165
|
-
const allowlist = options.allowlist ?? [];
|
|
166
|
-
const scanned = walk(options.root).filter((rel) => !shouldSkip(rel));
|
|
167
|
-
const findings = [];
|
|
168
|
-
const allowlisted = [];
|
|
169
|
-
for (const rel of scanned) {
|
|
170
|
-
const lines = readFileSync(join(options.root, rel), 'utf8').split('\n').length;
|
|
171
|
-
if (lines <= soft)
|
|
172
|
-
continue;
|
|
173
|
-
const finding = { file: rel, lines, level: lines > hard ? 'critical' : 'warn' };
|
|
174
|
-
if (isAllowlisted(rel, allowlist)) {
|
|
175
|
-
allowlisted.push(finding);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
findings.push(finding);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
findings.sort((left, right) => right.lines - left.lines);
|
|
182
|
-
allowlisted.sort((left, right) => right.lines - left.lines);
|
|
183
|
-
const critical = findings.filter((finding) => finding.level === 'critical');
|
|
184
|
-
const passed = options.failOnHard !== true || critical.length === 0;
|
|
185
|
-
const reported = passed
|
|
186
|
-
? `God-file check passed (${scanned.length} files, ${findings.length} over soft limit ${soft}, ${allowlisted.length} allowlisted).`
|
|
187
|
-
: `God-file check failed: ${critical.length} file(s) exceed ${hard} LOC. Split them, or add them to the allowlist in the same commit that grows them.`;
|
|
188
|
-
return { findings, allowlisted, scanned: scanned.length, passed, reported };
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Read an allowlist file, or `[]` when it is absent.
|
|
192
|
-
*
|
|
193
|
-
* The file is `scripts/god-files.allowlist.json`: a JSON array of repo-relative
|
|
194
|
-
* paths. Absence is the normal case for a repo with no known offenders, so it is
|
|
195
|
-
* not an error — a guard that fails on a first run nobody has filled in yet is a
|
|
196
|
-
* guard that gets disabled.
|
|
197
|
-
*
|
|
198
|
-
* A malformed file is an error rather than an empty list, because "the allowlist
|
|
199
|
-
* is empty" silently un-reports every known offender.
|
|
200
|
-
*/
|
|
201
|
-
export function readAllowlist(path) {
|
|
202
|
-
let raw;
|
|
203
|
-
try {
|
|
204
|
-
raw = readFileSync(path, 'utf8');
|
|
205
|
-
}
|
|
206
|
-
catch {
|
|
207
|
-
return [];
|
|
208
|
-
}
|
|
209
|
-
let parsed;
|
|
210
|
-
try {
|
|
211
|
-
parsed = JSON.parse(raw);
|
|
212
|
-
}
|
|
213
|
-
catch (error) {
|
|
214
|
-
throw new Error(`${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
215
|
-
}
|
|
216
|
-
if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== 'string')) {
|
|
217
|
-
throw new Error(`${path} must be a JSON array of repo-relative path strings.`);
|
|
218
|
-
}
|
|
219
|
-
return parsed;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* CLI entry: `checkGodFilesCli(['.', '--fail-on-hard'])`.
|
|
223
|
-
*
|
|
224
|
-
* The directory is a positional argument **or** `--root <dir>`, because every other
|
|
225
|
-
* script in this tree takes its target positionally and a gate that has to be
|
|
226
|
-
* invoked one way in one script and another way in the next is a gate somebody
|
|
227
|
-
* invokes wrong. A second positional is an error.
|
|
228
|
-
*
|
|
229
|
-
* Flags (see FlagSpec): `--root <dir>` (default `.`), `--allowlist <file>`
|
|
230
|
-
* (default `scripts/god-files.allowlist.json` beside the root, absent = none),
|
|
231
|
-
* `--fail-on-hard` (default off, matching every source repo's warn-only gate).
|
|
232
|
-
* Returns 0 unless `--fail-on-hard` is set and a critical file is found.
|
|
233
|
-
*/
|
|
234
|
-
export function checkGodFilesCli(argv = process.argv.slice(2)) {
|
|
235
|
-
// Split before parsing, because parseFlags rejects anything that is not a declared
|
|
236
|
-
// flag and a positional directory is neither a mistake nor a flag.
|
|
237
|
-
const { positional, rest } = splitPositional(argv, ['root', 'allowlist']);
|
|
238
|
-
const flags = parseFlags(rest, {
|
|
239
|
-
value: ['root', 'allowlist'],
|
|
240
|
-
boolean: ['fail-on-hard'],
|
|
241
|
-
});
|
|
242
|
-
const root = valueOf(flags, 'root') ?? positional[0] ?? '.';
|
|
243
|
-
const allowlistPath = valueOf(flags, 'allowlist') ?? join(root, 'scripts/god-files.allowlist.json');
|
|
244
|
-
const report = checkGodFiles({
|
|
245
|
-
root,
|
|
246
|
-
allowlist: readAllowlist(allowlistPath),
|
|
247
|
-
failOnHard: isSet(flags, 'fail-on-hard'),
|
|
248
|
-
});
|
|
249
|
-
console.log(report.reported);
|
|
250
|
-
for (const finding of report.findings) {
|
|
251
|
-
console.log(`${finding.level === 'critical' ? 'CRITICAL' : 'WARN'} ${finding.lines} ${finding.file}`);
|
|
252
|
-
}
|
|
253
|
-
for (const finding of report.allowlisted) {
|
|
254
|
-
console.log(`ALLOWLISTED ${finding.lines} ${finding.file}`);
|
|
255
|
-
}
|
|
256
|
-
if (!report.passed) {
|
|
257
|
-
fail(`God-file check failed: run with --root ${root} to see the report.`);
|
|
258
|
-
}
|
|
259
|
-
return 0;
|
|
260
|
-
}
|
|
261
|
-
// Run only when this file is the entrypoint.
|
|
262
|
-
//
|
|
263
|
-
// The rules above are pure and the tests import them directly, so a module-level
|
|
264
|
-
// call would shell out (and exit) during a test run. The URL comparison rather than
|
|
265
|
-
// an unconditional call is the same guard Durable-DAV's init-secrets.ts uses, and
|
|
266
|
-
// it is what keeps the rule modules importable — which is the whole reason they are
|
|
267
|
-
// separate modules in the first place.
|
|
268
|
-
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
269
|
-
process.exit(checkGodFilesCli(process.argv.slice(2)));
|
|
270
|
-
}
|
|
271
|
-
//# sourceMappingURL=check-god-files.js.map
|
|
1
|
+
import{readdirSync as m,readFileSync as p,statSync as w}from"node:fs";import{pathToFileURL as S}from"node:url";import f from"node:path";import{fail as $}from"./lib/github-actions.js";import{isSet as v,parseFlags as j,splitPositional as _,valueOf as g}from"./lib/cli-args.js";const x=300,E=400,O=new Set(["node_modules","dist",".wrangler","coverage","coverage-integration","coverage-web",".git"]),y=/\.(?:ts|tsx|js|mjs|cjs|css)$/,I=["test","spec"].flatMap(t=>[".ts",".tsx",".js",".jsx",".mjs",".cjs"].map(s=>`.${t}${s}`));function L(t){return/(?:^|\/)(?:locales|generated)\//.test(t)||/(?:^|\/)__(?:tests|mocks)__(?:\/|$)/.test(t)||/(?:^|\/)scripts\//.test(t)||/(?:^|\/)(?:test|tests|__tests__)\//.test(t)||/\.config\.(?:m?[jt]s|cjs)$/.test(t)||t.endsWith(".d.ts")||t.endsWith(".json")||t.endsWith(".sql")||t.endsWith(".md")?!0:I.some(s=>t.endsWith(s))}function T(t,s){return s.some(e=>e.endsWith("/")?t.startsWith(e):t===e)}function W(t){const s=[],e=o=>{for(const r of m(o)){const n=f.join(o,r);let i;try{i=w(n)}catch{continue}if(i.isDirectory()){if(O.has(r))continue;e(n)}else y.test(r)&&s.push(f.relative(t,n))}};return e(t),s}function k(t){const s=t.soft??x,e=t.hard??E,o=t.allowlist??[],r=W(t.root).filter(l=>!L(l)),n=[],i=[];for(const l of r){const a=p(f.join(t.root,l),"utf8").split(`
|
|
2
|
+
`).length;if(a<=s)continue;const h={file:l,lines:a,level:a>e?"critical":"warn"};T(l,o)?i.push(h):n.push(h)}n.sort((l,a)=>a.lines-l.lines),i.sort((l,a)=>a.lines-l.lines);const c=n.filter(l=>l.level==="critical"),d=t.failOnHard!==!0||c.length===0,u=d?`God-file check passed (${r.length} files, ${n.length} over soft limit ${s}, ${i.length} allowlisted).`:`God-file check failed: ${c.length} file(s) exceed ${e} LOC. Split them, or add them to the allowlist in the same commit that grows them.`;return{findings:n,allowlisted:i,scanned:r.length,passed:d,reported:u}}function A(t){let s;try{s=p(t,"utf8")}catch{return[]}let e;try{e=JSON.parse(s)}catch(o){throw new Error(`${t} is not valid JSON: ${o instanceof Error?o.message:String(o)}`,{cause:o})}if(!Array.isArray(e)||e.some(o=>typeof o!="string"))throw new Error(`${t} must be a JSON array of repo-relative path strings.`);return e}function F(t=process.argv.slice(2)){const{positional:s,rest:e}=_(t,["root","allowlist"]),o=j(e,{value:["root","allowlist"],boolean:["fail-on-hard"]}),r=g(o,"root")??s[0]??".",n=g(o,"allowlist")??f.join(r,"scripts/god-files.allowlist.json"),i=k({root:r,allowlist:A(n),failOnHard:v(o,"fail-on-hard")});console.log(i.reported);for(const c of i.findings)console.log(`${c.level==="critical"?"CRITICAL":"WARN"} ${c.lines} ${c.file}`);for(const c of i.allowlisted)console.log(`ALLOWLISTED ${c.lines} ${c.file}`);return i.passed||$(`God-file check failed: run with --root ${r} to see the report.`),0}process.argv[1]!==void 0&&import.meta.url===S(process.argv[1]).href&&process.exit(F(process.argv.slice(2)));export{E as HARD_LIMIT,x as SOFT_LIMIT,k as checkGodFiles,F as checkGodFilesCli,T as isAllowlisted,A as readAllowlist,L as shouldSkip,W as walk};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"check-god-files.js","sourceRoot":"","sources":["../../src/scripts/check-god-files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAuDhF,qDAAqD;AACrD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAC9B,qDAAqD;AACrD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,YAAY,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O,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACxG,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,IAAI,CAAC,0CAA0C,IAAI,qBAAqB,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,6CAA6C;AAC7C,EAAE;AACF,iFAAiF;AACjF,oFAAoF;AACpF,kFAAkF;AAClF,oFAAoF;AACpF,uCAAuC;AACvC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7F,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/**\n * The rules behind `scripts/check-god-files.ts`.\n *\n * Provenance: converged from the seven `.mjs` copies (AWS-AccessBridge,\n * CalDAV-Bridge, ChordDHT-Tracker, Durable-DAV, Durable-DAV-Router, Edge-Git,\n * Mail-Meow, Mail-Otter) and the typed ratchet in Edge-Sonic.\n *\n * All seven `.mjs` copies are one script with two constants: soft 300 (warn),\n * hard 400 (error). The typed variant is not a different rule so much as a\n * different answer to \"what does the gate enforce\", and that is the decision this\n * module has to take once for the whole family.\n *\n * ### The convergence: warn-only, with an allowlist\n *\n * The two source designs:\n *\n * - **Ceiling** (six repos) — 300 warn, 400 error, `exit 1` on 400. Durable-DAV's\n * own `AGENTS.md` records what that measures: **ten** files sit just over 300\n * and none is a god file, so `WARN` reports every run and `HARD` has never\n * fired. A ceiling set above the largest file in the tree cannot tell a\n * repository getting worse from one that never got better, and raising it is\n * always available.\n * - **Ratchet** (Edge-Sonic) — a committed baseline records every file's size; a\n * file may shrink freely and grow only to its recorded size. It cannot be\n * satisfied by raising a number, which is its whole strength.\n *\n * The ratchet is the better *rule*, and the ceiling is the better *gate*: the\n * ratchet needs a baseline maintained per file and fails the first time somebody\n * writes a legitimate 320-line module, which is the failure mode that trains\n * everyone to ignore a report. So the converged script keeps the 300/400\n * thresholds — every repo's CI already prints them — and makes the verdict\n * **warn-only by default**, with two escape valves that are both visible in a\n * diff:\n *\n * 1. `--fail-on-hard` turns the 400 line back into a failing gate, for a repo\n * that has paid its debt and wants the ceiling enforced.\n * 2. An **allowlist** records the files that are over the line and known, so the\n * report names only the ones that are *new*. That is the ratchet's\n * \"recorded size\" idea without its per-file bookkeeping: the allowlist is\n * reviewed by the same commit that grows the file, because the diff shows what\n * was added to it.\n *\n * Tests are excluded, as every source does. A double modelling the platform grows\n * with the platform's surface, not with the complexity of the code it stands in\n * for — Edge-Sonic's ratchet holds them too, and its own notes record a 4,343-line\n * fixture, so this is a documented disagreement rather than an oversight.\n */\n\nimport { readdirSync, readFileSync, statSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport { join, relative } from 'node:path';\nimport { fail } from './lib/github-actions.ts';\nimport { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args.ts';\n\n/**\n * A file past a size the guard reports on.\n */\nexport interface GodFileFinding {\n /** Path relative to the root the check ran against. */\n readonly file: string;\n /** Lines it has. */\n readonly lines: number;\n /** `warn` past the soft limit, `critical` past the hard one. */\n readonly level: 'warn' | 'critical';\n}\n\n/**\n * The outcome of one run.\n */\nexport interface GodFileReport {\n /** Files over a limit, worst first, minus the allowlisted. */\n readonly findings: readonly GodFileFinding[];\n /** How many files the walk measured. */\n readonly scanned: number;\n /** Allowlisted files that are over a limit — reported, never counted. */\n readonly allowlisted: readonly GodFileFinding[];\n /**\n * Whether the tree may be committed as it stands.\n *\n * `true` in warn-only mode, which is the default; a `critical` finding fails\n * only when the caller asked for the gate.\n */\n readonly passed: boolean;\n /** The message to print, either way. */\n readonly reported: string;\n}\n\n/**\n * What `checkGodFiles` accepts.\n */\nexport interface GodFileOptions {\n /** Directory to walk. */\n readonly root: string;\n /**\n * Repo-relative paths (or directory prefixes ending in `/`) exempt from the\n * report. Defaults to `god-files.allowlist.json` beside the caller's script\n * when that file exists — see `readAllowlist`.\n */\n readonly allowlist?: readonly string[];\n /** Soft limit, past which a file is reported as `warn`. */\n readonly soft?: number;\n /** Hard limit, past which a file is reported as `critical`. */\n readonly hard?: number;\n /** Make a `critical` finding fail the run. */\n readonly failOnHard?: boolean;\n}\n\n/** Default soft limit, as every source repo uses. */\nexport const SOFT_LIMIT = 300;\n/** Default hard limit, as every source repo uses. */\nexport const HARD_LIMIT = 400;\n\n/**\n * Directories the walker never enters.\n *\n * Build output and VCS state; `coverage` is here because a generated HTML report\n * is thousands of \"lines\" of nothing.\n */\nconst EXCLUDE_DIRS = new Set(['node_modules', 'dist', '.wrangler', 'coverage', 'coverage-integration', 'coverage-web', '.git']);\n\n/**\n * Source extensions the guard counts.\n *\n * `css` is in the set because every source repo counts it, and a 400-line\n * stylesheet is the same reading problem as a 400-line module.\n */\nconst SOURCE_EXTENSIONS = /\\.(?:ts|tsx|js|mjs|cjs|css)$/;\n\n/**\n * The test-file suffixes the guard skips.\n *\n * `.test.tsx` matter as much as `.test.ts`: the walker collects both, so a list\n * that only named the `.ts` forms let every React test file through the guard and\n * reported them as god files — which is how Durable-DAV-Router discovered it.\n * Built from the kinds and extensions rather than enumerated, so a new test\n * extension cannot silently escape.\n */\nconst TEST_SUFFIXES: readonly string[] = ['test', 'spec'].flatMap((kind) =>\n ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'].map((ext) => `.${kind}${ext}`),\n);\n\n/**\n * Whether a repo-relative path is exempt from the guard.\n *\n * Provenance: AWS-AccessBridge's version is the canonical one, because it\n * documents and fixes two live bugs in the others.\n *\n * Every directory pattern is anchored with `(?:^|/)` rather than a bare leading\n * `/`. `relative()` yields `test/helpers/x.ts` for a top-level test directory and\n * `scripts/lib/x.ts` for the scripts directory — **no leading separator** — so a\n * pattern written as `/\\/(?:test|tests|__tests__)\\//` never matches either one.\n * It looks right, it does match when handed an absolute path, and against these\n * layouts it is silently a no-op. Durable-DAV and ChordDHT-Tracker ship exactly\n * that dead pattern.\n */\nexport function shouldSkip(rel: string): boolean {\n if (/(?:^|\\/)(?:locales|generated)\\//.test(rel)) return true;\n if (/(?:^|\\/)__(?:tests|mocks)__(?:\\/|$)/.test(rel)) return true;\n if (/(?:^|\\/)scripts\\//.test(rel)) return true;\n if (/(?:^|\\/)(?:test|tests|__tests__)\\//.test(rel)) return true;\n if (/\\.config\\.(?:m?[jt]s|cjs)$/.test(rel)) return true;\n if (rel.endsWith('.d.ts')) return true;\n if (rel.endsWith('.json')) return true;\n if (rel.endsWith('.sql')) return true;\n if (rel.endsWith('.md')) return true;\n return TEST_SUFFIXES.some((suffix) => rel.endsWith(suffix));\n}\n\n/**\n * Whether a repo-relative path is on the allowlist.\n *\n * An entry ending in `/` exempts a whole directory; any other entry is matched\n * exactly, so `apps/api/src/index.ts` does not exempt `apps/api/src/index.util.ts`.\n */\nexport function isAllowlisted(rel: string, allowlist: readonly string[]): boolean {\n return allowlist.some((entry) => (entry.endsWith('/') ? rel.startsWith(entry) : rel === entry));\n}\n\n/**\n * Every source file under `root`, as repo-relative paths.\n *\n * Symlink-safe: a dangling symlink or a file removed mid-walk is skipped rather\n * than thrown, because neither is a god-file problem.\n */\nexport function walk(root: string): string[] {\n const out: string[] = [];\n const visit = (dir: string): void => {\n for (const entry of readdirSync(dir)) {\n const full = join(dir, entry);\n let stat;\n try {\n stat = statSync(full);\n } catch {\n continue;\n }\n if (stat.isDirectory()) {\n if (EXCLUDE_DIRS.has(entry)) continue;\n visit(full);\n } else if (SOURCE_EXTENSIONS.test(entry)) {\n out.push(relative(root, full));\n }\n }\n };\n visit(root);\n return out;\n}\n\n/**\n * Run the guard over a tree.\n *\n * Pure with respect to the verdict — the only I/O is the walk and a line count —\n * so a test drives it against a temporary directory.\n */\nexport function checkGodFiles(options: GodFileOptions): GodFileReport {\n const soft = options.soft ?? SOFT_LIMIT;\n const hard = options.hard ?? HARD_LIMIT;\n const allowlist = options.allowlist ?? [];\n\n const scanned = walk(options.root).filter((rel) => !shouldSkip(rel));\n const findings: GodFileFinding[] = [];\n const allowlisted: GodFileFinding[] = [];\n\n for (const rel of scanned) {\n const lines = readFileSync(join(options.root, rel), 'utf8').split('\\n').length;\n if (lines <= soft) continue;\n const finding: GodFileFinding = { file: rel, lines, level: lines > hard ? 'critical' : 'warn' };\n if (isAllowlisted(rel, allowlist)) {\n allowlisted.push(finding);\n } else {\n findings.push(finding);\n }\n }\n\n findings.sort((left, right) => right.lines - left.lines);\n allowlisted.sort((left, right) => right.lines - left.lines);\n\n const critical = findings.filter((finding) => finding.level === 'critical');\n const passed = options.failOnHard !== true || critical.length === 0;\n\n const reported = passed\n ? `God-file check passed (${scanned.length} files, ${findings.length} over soft limit ${soft}, ${allowlisted.length} allowlisted).`\n : `God-file check failed: ${critical.length} file(s) exceed ${hard} LOC. Split them, or add them to the allowlist in the same commit that grows them.`;\n\n return { findings, allowlisted, scanned: scanned.length, passed, reported };\n}\n\n/**\n * Read an allowlist file, or `[]` when it is absent.\n *\n * The file is `scripts/god-files.allowlist.json`: a JSON array of repo-relative\n * paths. Absence is the normal case for a repo with no known offenders, so it is\n * not an error — a guard that fails on a first run nobody has filled in yet is a\n * guard that gets disabled.\n *\n * A malformed file is an error rather than an empty list, because \"the allowlist\n * is empty\" silently un-reports every known offender.\n */\nexport function readAllowlist(path: string): string[] {\n let raw: string;\n try {\n raw = readFileSync(path, 'utf8');\n } catch {\n return [];\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (error: unknown) {\n throw new Error(`${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });\n }\n if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== 'string')) {\n throw new Error(`${path} must be a JSON array of repo-relative path strings.`);\n }\n return parsed as string[];\n}\n\n/**\n * CLI entry: `checkGodFilesCli(['.', '--fail-on-hard'])`.\n *\n * The directory is a positional argument **or** `--root <dir>`, because every other\n * script in this tree takes its target positionally and a gate that has to be\n * invoked one way in one script and another way in the next is a gate somebody\n * invokes wrong. A second positional is an error.\n *\n * Flags (see FlagSpec): `--root <dir>` (default `.`), `--allowlist <file>`\n * (default `scripts/god-files.allowlist.json` beside the root, absent = none),\n * `--fail-on-hard` (default off, matching every source repo's warn-only gate).\n * Returns 0 unless `--fail-on-hard` is set and a critical file is found.\n */\nexport function checkGodFilesCli(argv: readonly string[] = process.argv.slice(2)): number {\n // Split before parsing, because parseFlags rejects anything that is not a declared\n // flag and a positional directory is neither a mistake nor a flag.\n const { positional, rest } = splitPositional(argv, ['root', 'allowlist']);\n const flags = parseFlags(rest, {\n value: ['root', 'allowlist'],\n boolean: ['fail-on-hard'],\n });\n const root = valueOf(flags, 'root') ?? positional[0] ?? '.';\n const allowlistPath = valueOf(flags, 'allowlist') ?? join(root, 'scripts/god-files.allowlist.json');\n const report = checkGodFiles({\n root,\n allowlist: readAllowlist(allowlistPath),\n failOnHard: isSet(flags, 'fail-on-hard'),\n });\n console.log(report.reported);\n for (const finding of report.findings) {\n console.log(`${finding.level === 'critical' ? 'CRITICAL' : 'WARN'} ${finding.lines} ${finding.file}`);\n }\n for (const finding of report.allowlisted) {\n console.log(`ALLOWLISTED ${finding.lines} ${finding.file}`);\n }\n if (!report.passed) {\n fail(`God-file check failed: run with --root ${root} to see the report.`);\n }\n return 0;\n}\n\n// Run only when this file is the entrypoint.\n//\n// The rules above are pure and the tests import them directly, so a module-level\n// call would shell out (and exit) during a test run. The URL comparison rather than\n// an unconditional call is the same guard Durable-DAV's init-secrets.ts uses, and\n// it is what keeps the rule modules importable — which is the whole reason they are\n// separate modules in the first place.\nif (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {\n process.exit(checkGodFilesCli(process.argv.slice(2)));\n}\n"]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/scripts/check-god-files.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The rules behind `scripts/check-god-files.ts`.\n *\n * Provenance: converged from the seven `.mjs` copies (AWS-AccessBridge,\n * CalDAV-Bridge, ChordDHT-Tracker, Durable-DAV, Durable-DAV-Router, Edge-Git,\n * Mail-Meow, Mail-Otter) and the typed ratchet in Edge-Sonic.\n *\n * All seven `.mjs` copies are one script with two constants: soft 300 (warn),\n * hard 400 (error). The typed variant is not a different rule so much as a\n * different answer to \"what does the gate enforce\", and that is the decision this\n * module has to take once for the whole family.\n *\n * ### The convergence: warn-only, with an allowlist\n *\n * The two source designs:\n *\n * - **Ceiling** (six repos) — 300 warn, 400 error, `exit 1` on 400. Durable-DAV's\n * own `AGENTS.md` records what that measures: **ten** files sit just over 300\n * and none is a god file, so `WARN` reports every run and `HARD` has never\n * fired. A ceiling set above the largest file in the tree cannot tell a\n * repository getting worse from one that never got better, and raising it is\n * always available.\n * - **Ratchet** (Edge-Sonic) — a committed baseline records every file's size; a\n * file may shrink freely and grow only to its recorded size. It cannot be\n * satisfied by raising a number, which is its whole strength.\n *\n * The ratchet is the better *rule*, and the ceiling is the better *gate*: the\n * ratchet needs a baseline maintained per file and fails the first time somebody\n * writes a legitimate 320-line module, which is the failure mode that trains\n * everyone to ignore a report. So the converged script keeps the 300/400\n * thresholds — every repo's CI already prints them — and makes the verdict\n * **warn-only by default**, with two escape valves that are both visible in a\n * diff:\n *\n * 1. `--fail-on-hard` turns the 400 line back into a failing gate, for a repo\n * that has paid its debt and wants the ceiling enforced.\n * 2. An **allowlist** records the files that are over the line and known, so the\n * report names only the ones that are *new*. That is the ratchet's\n * \"recorded size\" idea without its per-file bookkeeping: the allowlist is\n * reviewed by the same commit that grows the file, because the diff shows what\n * was added to it.\n *\n * Tests are excluded, as every source does. A double modelling the platform grows\n * with the platform's surface, not with the complexity of the code it stands in\n * for — Edge-Sonic's ratchet holds them too, and its own notes record a 4,343-line\n * fixture, so this is a documented disagreement rather than an oversight.\n */\n\nimport { readdirSync, readFileSync, statSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport path from 'node:path';\nimport { fail } from './lib/github-actions.ts';\nimport { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args.ts';\n\n/**\n * A file past a size the guard reports on.\n */\nexport interface GodFileFinding {\n /**\n Path relative to the root the check ran against.\n */\n readonly file: string;\n /**\n Lines it has.\n */\n readonly lines: number;\n /**\n `warn` past the soft limit, `critical` past the hard one.\n */\n readonly level: 'warn' | 'critical';\n}\n\n/**\n * The outcome of one run.\n */\nexport interface GodFileReport {\n /**\n Files over a limit, worst first, minus the allowlisted.\n */\n readonly findings: readonly GodFileFinding[];\n /**\n How many files the walk measured.\n */\n readonly scanned: number;\n /**\n Allowlisted files that are over a limit — reported, never counted.\n */\n readonly allowlisted: readonly GodFileFinding[];\n /**\n * Whether the tree may be committed as it stands.\n *\n * `true` in warn-only mode, which is the default; a `critical` finding fails\n * only when the caller asked for the gate.\n */\n readonly passed: boolean;\n /**\n The message to print, either way.\n */\n readonly reported: string;\n}\n\n/**\n * What `checkGodFiles` accepts.\n */\nexport interface GodFileOptions {\n /**\n Directory to walk.\n */\n readonly root: string;\n /**\n * Repo-relative paths (or directory prefixes ending in `/`) exempt from the\n * report. Defaults to `god-files.allowlist.json` beside the caller's script\n * when that file exists — see `readAllowlist`.\n */\n readonly allowlist?: readonly string[];\n /**\n Soft limit, past which a file is reported as `warn`.\n */\n readonly soft?: number;\n /**\n Hard limit, past which a file is reported as `critical`.\n */\n readonly hard?: number;\n /**\n Make a `critical` finding fail the run.\n */\n readonly failOnHard?: boolean;\n}\n\n/**\nDefault soft limit, as every source repo uses.\n*/\nexport const SOFT_LIMIT = 300;\n/**\nDefault hard limit, as every source repo uses.\n*/\nexport const HARD_LIMIT = 400;\n\n/**\n * Directories the walker never enters.\n *\n * Build output and VCS state; `coverage` is here because a generated HTML report\n * is thousands of \"lines\" of nothing.\n */\nconst EXCLUDE_DIRS = new Set(['node_modules', 'dist', '.wrangler', 'coverage', 'coverage-integration', 'coverage-web', '.git']);\n\n/**\n * Source extensions the guard counts.\n *\n * `css` is in the set because every source repo counts it, and a 400-line\n * stylesheet is the same reading problem as a 400-line module.\n */\nconst SOURCE_EXTENSIONS = /\\.(?:ts|tsx|js|mjs|cjs|css)$/;\n\n/**\n * The test-file suffixes the guard skips.\n *\n * `.test.tsx` matter as much as `.test.ts`: the walker collects both, so a list\n * that only named the `.ts` forms let every React test file through the guard and\n * reported them as god files — which is how Durable-DAV-Router discovered it.\n * Built from the kinds and extensions rather than enumerated, so a new test\n * extension cannot silently escape.\n */\nconst TEST_SUFFIXES: readonly string[] = ['test', 'spec'].flatMap((kind) =>\n ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'].map((ext) => `.${kind}${ext}`),\n);\n\n/**\n * Whether a repo-relative path is exempt from the guard.\n *\n * Provenance: AWS-AccessBridge's version is the canonical one, because it\n * documents and fixes two live bugs in the others.\n *\n * Every directory pattern is anchored with `(?:^|/)` rather than a bare leading\n * `/`. `relative()` yields `test/helpers/x.ts` for a top-level test directory and\n * `scripts/lib/x.ts` for the scripts directory — **no leading separator** — so a\n * pattern written as `/\\/(?:test|tests|__tests__)\\//` never matches either one.\n * It looks right, it does match when handed an absolute path, and against these\n * layouts it is silently a no-op. Durable-DAV and ChordDHT-Tracker ship exactly\n * that dead pattern.\n */\nexport function shouldSkip(rel: string): boolean {\n if (\n /(?:^|\\/)(?:locales|generated)\\//.test(rel) ||\n /(?:^|\\/)__(?:tests|mocks)__(?:\\/|$)/.test(rel) ||\n /(?:^|\\/)scripts\\//.test(rel) ||\n /(?:^|\\/)(?:test|tests|__tests__)\\//.test(rel) ||\n /\\.config\\.(?:m?[jt]s|cjs)$/.test(rel) ||\n rel.endsWith('.d.ts') ||\n rel.endsWith('.json') ||\n rel.endsWith('.sql') ||\n rel.endsWith('.md')\n )\n return true;\n return TEST_SUFFIXES.some((suffix) => rel.endsWith(suffix));\n}\n\n/**\n * Whether a repo-relative path is on the allowlist.\n *\n * An entry ending in `/` exempts a whole directory; any other entry is matched\n * exactly, so `apps/api/src/index.ts` does not exempt `apps/api/src/index.util.ts`.\n */\nexport function isAllowlisted(rel: string, allowlist: readonly string[]): boolean {\n return allowlist.some((entry) => (entry.endsWith('/') ? rel.startsWith(entry) : rel === entry));\n}\n\n/**\n * Every source file under `root`, as repo-relative paths.\n *\n * Symlink-safe: a dangling symlink or a file removed mid-walk is skipped rather\n * than thrown, because neither is a god-file problem.\n */\nexport function walk(root: string): string[] {\n const out: string[] = [];\n const visit = (dir: string): void => {\n for (const entry of readdirSync(dir)) {\n const full = path.join(dir, entry);\n let stat;\n try {\n stat = statSync(full);\n } catch {\n continue;\n }\n if (stat.isDirectory()) {\n if (EXCLUDE_DIRS.has(entry)) continue;\n visit(full);\n } else if (SOURCE_EXTENSIONS.test(entry)) {\n out.push(path.relative(root, full));\n }\n }\n };\n visit(root);\n return out;\n}\n\n/**\n * Run the guard over a tree.\n *\n * Pure with respect to the verdict — the only I/O is the walk and a line count —\n * so a test drives it against a temporary directory.\n */\nexport function checkGodFiles(options: GodFileOptions): GodFileReport {\n const soft = options.soft ?? SOFT_LIMIT;\n const hard = options.hard ?? HARD_LIMIT;\n const allowlist = options.allowlist ?? [];\n\n const scanned = walk(options.root).filter((rel) => !shouldSkip(rel));\n const findings: GodFileFinding[] = [];\n const allowlisted: GodFileFinding[] = [];\n\n for (const rel of scanned) {\n const lines = readFileSync(path.join(options.root, rel), 'utf8').split('\\n').length;\n if (lines <= soft) continue;\n const finding: GodFileFinding = { file: rel, lines, level: lines > hard ? 'critical' : 'warn' };\n if (isAllowlisted(rel, allowlist)) {\n allowlisted.push(finding);\n } else {\n findings.push(finding);\n }\n }\n\n findings.sort((left, right) => right.lines - left.lines);\n allowlisted.sort((left, right) => right.lines - left.lines);\n\n const critical = findings.filter((finding) => finding.level === 'critical');\n const passed = options.failOnHard !== true || critical.length === 0;\n\n const reported = passed\n ? `God-file check passed (${scanned.length} files, ${findings.length} over soft limit ${soft}, ${allowlisted.length} allowlisted).`\n : `God-file check failed: ${critical.length} file(s) exceed ${hard} LOC. Split them, or add them to the allowlist in the same commit that grows them.`;\n\n return { findings, allowlisted, scanned: scanned.length, passed, reported };\n}\n\n/**\n * Read an allowlist file, or `[]` when it is absent.\n *\n * The file is `scripts/god-files.allowlist.json`: a JSON array of repo-relative\n * paths. Absence is the normal case for a repo with no known offenders, so it is\n * not an error — a guard that fails on a first run nobody has filled in yet is a\n * guard that gets disabled.\n *\n * A malformed file is an error rather than an empty list, because \"the allowlist\n * is empty\" silently un-reports every known offender.\n */\nexport function readAllowlist(file: string): string[] {\n let raw: string;\n try {\n raw = readFileSync(file, 'utf8');\n } catch {\n return [];\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (error: unknown) {\n throw new Error(`${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });\n }\n if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== 'string')) {\n throw new Error(`${file} must be a JSON array of repo-relative path strings.`);\n }\n return parsed as string[];\n}\n\n/**\n * CLI entry: `checkGodFilesCli(['.', '--fail-on-hard'])`.\n *\n * The directory is a positional argument **or** `--root <dir>`, because every other\n * script in this tree takes its target positionally and a gate that has to be\n * invoked one way in one script and another way in the next is a gate somebody\n * invokes wrong. A second positional is an error.\n *\n * Flags (see FlagSpec): `--root <dir>` (default `.`), `--allowlist <file>`\n * (default `scripts/god-files.allowlist.json` beside the root, absent = none),\n * `--fail-on-hard` (default off, matching every source repo's warn-only gate).\n * Returns 0 unless `--fail-on-hard` is set and a critical file is found.\n */\nexport function checkGodFilesCli(argv: readonly string[] = process.argv.slice(2)): number {\n // Split before parsing, because parseFlags rejects anything that is not a declared\n // flag and a positional directory is neither a mistake nor a flag.\n const { positional, rest } = splitPositional(argv, ['root', 'allowlist']);\n const flags = parseFlags(rest, {\n value: ['root', 'allowlist'],\n boolean: ['fail-on-hard'],\n });\n const root = valueOf(flags, 'root') ?? positional[0] ?? '.';\n const allowlistPath = valueOf(flags, 'allowlist') ?? path.join(root, 'scripts/god-files.allowlist.json');\n const report = checkGodFiles({\n root,\n allowlist: readAllowlist(allowlistPath),\n failOnHard: isSet(flags, 'fail-on-hard'),\n });\n console.log(report.reported);\n for (const finding of report.findings) {\n console.log(`${finding.level === 'critical' ? 'CRITICAL' : 'WARN'} ${finding.lines} ${finding.file}`);\n }\n for (const finding of report.allowlisted) {\n console.log(`ALLOWLISTED ${finding.lines} ${finding.file}`);\n }\n if (!report.passed) {\n fail(`God-file check failed: run with --root ${root} to see the report.`);\n }\n return 0;\n}\n\n// Run only when this file is the entrypoint.\n//\n// The rules above are pure and the tests import them directly, so a module-level\n// call would shell out (and exit) during a test run. The URL comparison rather than\n// an unconditional call is the same guard Durable-DAV's init-secrets.ts uses, and\n// it is what keeps the rule modules importable — which is the whole reason they are\n// separate modules in the first place.\nif (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {\n process.exit(checkGodFilesCli(process.argv.slice(2)));\n}\n"],
|
|
5
|
+
"mappings": "AAgDA,OAAS,eAAAA,EAAa,gBAAAC,EAAc,YAAAC,MAAgB,UACpD,OAAS,iBAAAC,MAAqB,WAC9B,OAAOC,MAAU,YACjB,OAAS,QAAAC,MAAY,0BACrB,OAAS,SAAAC,EAAO,cAAAC,EAAY,mBAAAC,EAAiB,WAAAC,MAAe,oBAgFrD,MAAMC,EAAa,IAIbC,EAAa,IAQpBC,EAAe,IAAI,IAAI,CAAC,eAAgB,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CAAC,CAAC",
|
|
6
|
+
"names": ["readdirSync", "readFileSync", "statSync", "pathToFileURL", "path", "fail", "isSet", "parseFlags", "splitPositional", "valueOf", "SOFT_LIMIT", "HARD_LIMIT", "EXCLUDE_DIRS", "SOURCE_EXTENSIONS", "TEST_SUFFIXES", "kind", "ext", "shouldSkip", "rel", "suffix", "isAllowlisted", "allowlist", "entry", "walk", "root", "out", "visit", "dir", "full", "stat", "checkGodFiles", "options", "soft", "hard", "scanned", "findings", "allowlisted", "lines", "finding", "left", "right", "critical", "passed", "reported", "readAllowlist", "file", "raw", "parsed", "error", "checkGodFilesCli", "argv", "positional", "rest", "flags", "allowlistPath", "report"]
|
|
7
|
+
}
|
|
@@ -1,30 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env tsx
|
|
2
|
-
|
|
3
|
-
* Write a placeholder `apps/api/src/generated/spa-shell.ts` when it is absent.
|
|
4
|
-
*
|
|
5
|
-
* Provenance: Durable-DAV's `scripts/ensure-spa-shell-stub.mjs` and Edge-Sonic's
|
|
6
|
-
* `scripts/build/ensure-spa-shell-stub.ts`. The rule lives in `spa-shell.ts`; this
|
|
7
|
-
* is the entrypoint that runs it from `postinstall`.
|
|
8
|
-
*
|
|
9
|
-
* `pnpm install` runs this before `typegen` so the API worker typechecks in a
|
|
10
|
-
* fresh clone, where the real file has not been produced by the Vite build yet.
|
|
11
|
-
* It exits having done nothing when the file already exists, so a real build
|
|
12
|
-
* output is never overwritten — overwriting would erase the last build with a
|
|
13
|
-
* stub on the next install. The file is gitignored.
|
|
14
|
-
*
|
|
15
|
-
* Usage, from the repo root (typically wired as `postinstall`):
|
|
16
|
-
*
|
|
17
|
-
* ```bash
|
|
18
|
-
* pnpm exec tsx scripts/ensure-spa-shell-stub.ts [repo-root]
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
import path from 'node:path';
|
|
22
|
-
import { fileURLToPath } from 'node:url';
|
|
23
|
-
import { ensureSpaShellStub } from "./spa-shell.js";
|
|
24
|
-
const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
25
|
-
const root = process.argv[2] === undefined ? REPOSITORY_ROOT : path.resolve(process.argv[2]);
|
|
26
|
-
const result = ensureSpaShellStub({ root });
|
|
27
|
-
console.log(result.created
|
|
28
|
-
? `ensure-spa-shell-stub: created stub at ${result.path}`
|
|
29
|
-
: `ensure-spa-shell-stub: ${result.path} already present, left untouched`);
|
|
30
|
-
//# sourceMappingURL=ensure-spa-shell-stub.js.map
|
|
2
|
+
import e from"node:path";import{fileURLToPath as t}from"node:url";import{ensureSpaShellStub as s}from"./spa-shell.js";const o=e.resolve(e.dirname(t(import.meta.url)),".."),a=process.argv[2]===void 0?o:e.resolve(process.argv[2]),r=s({root:a});console.log(r.created?`ensure-spa-shell-stub: created stub at ${r.path}`:`ensure-spa-shell-stub: ${r.path} already present, left untouched`);
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/scripts/ensure-spa-shell-stub.ts"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env tsx\n/**\n * Write a placeholder `apps/api/src/generated/spa-shell.ts` when it is absent.\n *\n * Provenance: Durable-DAV's `scripts/ensure-spa-shell-stub.mjs` and Edge-Sonic's\n * `scripts/build/ensure-spa-shell-stub.ts`. The rule lives in `spa-shell.ts`; this\n * is the entrypoint that runs it from `postinstall`.\n *\n * `pnpm install` runs this before `typegen` so the API worker typechecks in a\n * fresh clone, where the real file has not been produced by the Vite build yet.\n * It exits having done nothing when the file already exists, so a real build\n * output is never overwritten — overwriting would erase the last build with a\n * stub on the next install. The file is gitignored.\n *\n * Usage, from the repo root (typically wired as `postinstall`):\n *\n * ```bash\n * pnpm exec tsx scripts/ensure-spa-shell-stub.ts [repo-root]\n * ```\n */\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { ensureSpaShellStub } from './spa-shell.ts';\n\nconst REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');\nconst root = process.argv[2] === undefined ? REPOSITORY_ROOT : path.resolve(process.argv[2]);\n\nconst result = ensureSpaShellStub({ root });\n\nconsole.log(\n result.created\n ? `ensure-spa-shell-stub: created stub at ${result.path}`\n : `ensure-spa-shell-stub: ${result.path} already present, left untouched`,\n);\n"],
|
|
5
|
+
"mappings": ";AAoBA,OAAOA,MAAU,YACjB,OAAS,iBAAAC,MAAqB,WAC9B,OAAS,sBAAAC,MAA0B,iBAEnC,MAAMC,EAAkBH,EAAK,QAAQA,EAAK,QAAQC,EAAc,YAAY,GAAG,CAAC,EAAG,IAAI,EACjFG,EAAO,QAAQ,KAAK,CAAC,IAAM,OAAYD,EAAkBH,EAAK,QAAQ,QAAQ,KAAK,CAAC,CAAC,EAErFK,EAASH,EAAmB,CAAE,KAAAE,CAAI,CAAE,EAE1C,QAAQ,IACNC,EAAO,QACH,0CAA0CA,EAAO,IAAI,GACrD,0BAA0BA,EAAO,IAAI,kCAAkC",
|
|
6
|
+
"names": ["path", "fileURLToPath", "ensureSpaShellStub", "REPOSITORY_ROOT", "root", "result"]
|
|
7
|
+
}
|
|
@@ -43,21 +43,5 @@
|
|
|
43
43
|
* config is missing, because a step reporting "Secret initialization complete"
|
|
44
44
|
* having created nothing is worse than a named error.
|
|
45
45
|
*/
|
|
46
|
-
import { type WranglerConfig } from './wrangler-config/types.ts';
|
|
47
|
-
/** Whether this script can produce a value for `secretName`. */
|
|
48
|
-
export declare function canProvisionSecret(secretName: string): boolean;
|
|
49
|
-
/** One secret to create, as the plan names it. */
|
|
50
|
-
interface PlannedSecret {
|
|
51
|
-
storeId: string;
|
|
52
|
-
secretName: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Turn the config's bindings into a validated work list.
|
|
56
|
-
*
|
|
57
|
-
* Every entry is checked *before* the first Cloudflare call, so an
|
|
58
|
-
* unprovisionable secret fails the step in milliseconds instead of after some other
|
|
59
|
-
* secret has already been created.
|
|
60
|
-
*/
|
|
61
|
-
export declare function planSecrets(config: WranglerConfig): PlannedSecret[];
|
|
62
46
|
export {};
|
|
63
47
|
//# sourceMappingURL=init-secrets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-secrets.d.ts","sourceRoot":"","sources":["../../src/scripts/init-secrets.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG
|
|
1
|
+
{"version":3,"file":"init-secrets.d.ts","sourceRoot":"","sources":["../../src/scripts/init-secrets.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG"}
|