@rexezuge/tooling 1.2.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.
Files changed (153) hide show
  1. package/README.md +66 -10
  2. package/dist/eslint-boundaries.d.ts +31 -7
  3. package/dist/eslint-boundaries.d.ts.map +1 -1
  4. package/dist/eslint-boundaries.js +1 -138
  5. package/dist/eslint-boundaries.js.map +7 -1
  6. package/dist/eslint-rules.js +1 -273
  7. package/dist/eslint-rules.js.map +7 -1
  8. package/dist/eslint.d.ts +12 -7
  9. package/dist/eslint.d.ts.map +1 -1
  10. package/dist/eslint.js +1 -189
  11. package/dist/eslint.js.map +7 -1
  12. package/dist/functions/pages-proxy.d.ts.map +1 -1
  13. package/dist/functions/pages-proxy.js +1 -131
  14. package/dist/functions/pages-proxy.js.map +7 -1
  15. package/dist/index.d.ts +20 -14
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -28
  18. package/dist/index.js.map +7 -1
  19. package/dist/scripts/backup/d1-target.d.ts +15 -5
  20. package/dist/scripts/backup/d1-target.d.ts.map +1 -1
  21. package/dist/scripts/backup/d1-target.js +1 -31
  22. package/dist/scripts/backup/d1-target.js.map +7 -1
  23. package/dist/scripts/backup/destination-config.d.ts +24 -8
  24. package/dist/scripts/backup/destination-config.d.ts.map +1 -1
  25. package/dist/scripts/backup/destination-config.js +1 -57
  26. package/dist/scripts/backup/destination-config.js.map +7 -1
  27. package/dist/scripts/backup/encrypt-backup.js +2 -97
  28. package/dist/scripts/backup/encrypt-backup.js.map +7 -1
  29. package/dist/scripts/backup/naming.d.ts +3 -1
  30. package/dist/scripts/backup/naming.d.ts.map +1 -1
  31. package/dist/scripts/backup/naming.js +1 -58
  32. package/dist/scripts/backup/naming.js.map +7 -1
  33. package/dist/scripts/check-god-files.d.ts +40 -14
  34. package/dist/scripts/check-god-files.d.ts.map +1 -1
  35. package/dist/scripts/check-god-files.js +2 -271
  36. package/dist/scripts/check-god-files.js.map +7 -1
  37. package/dist/scripts/ensure-spa-shell-stub.js +1 -29
  38. package/dist/scripts/ensure-spa-shell-stub.js.map +7 -1
  39. package/dist/scripts/init-secrets.d.ts +0 -16
  40. package/dist/scripts/init-secrets.d.ts.map +1 -1
  41. package/dist/scripts/init-secrets.js +2 -239
  42. package/dist/scripts/init-secrets.js.map +7 -1
  43. package/dist/scripts/lib/cli-args.d.ts.map +1 -1
  44. package/dist/scripts/lib/cli-args.js +1 -116
  45. package/dist/scripts/lib/cli-args.js.map +7 -1
  46. package/dist/scripts/lib/github-actions.js +3 -38
  47. package/dist/scripts/lib/github-actions.js.map +7 -1
  48. package/dist/scripts/lib/wrangler-table.d.ts.map +1 -1
  49. package/dist/scripts/lib/wrangler-table.js +2 -99
  50. package/dist/scripts/lib/wrangler-table.js.map +7 -1
  51. package/dist/scripts/migrations-lock.js +1 -44
  52. package/dist/scripts/migrations-lock.js.map +7 -1
  53. package/dist/scripts/prepare-wrangler-config.js +1 -49
  54. package/dist/scripts/prepare-wrangler-config.js.map +7 -1
  55. package/dist/scripts/spa-shell.d.ts +12 -4
  56. package/dist/scripts/spa-shell.d.ts.map +1 -1
  57. package/dist/scripts/spa-shell.js +3 -160
  58. package/dist/scripts/spa-shell.js.map +7 -1
  59. package/dist/scripts/validate-locales.d.ts +13 -5
  60. package/dist/scripts/validate-locales.d.ts.map +1 -1
  61. package/dist/scripts/validate-locales.js +4 -350
  62. package/dist/scripts/validate-locales.js.map +7 -1
  63. package/dist/scripts/verify-migrations.d.ts +27 -9
  64. package/dist/scripts/verify-migrations.d.ts.map +1 -1
  65. package/dist/scripts/verify-migrations.js +2 -312
  66. package/dist/scripts/verify-migrations.js.map +7 -1
  67. package/dist/scripts/verify-spa-shell.js +1 -52
  68. package/dist/scripts/verify-spa-shell.js.map +7 -1
  69. package/dist/scripts/wrangler-config/cli.js +3 -51
  70. package/dist/scripts/wrangler-config/cli.js.map +7 -1
  71. package/dist/scripts/wrangler-config/patches.d.ts +10 -4
  72. package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
  73. package/dist/scripts/wrangler-config/patches.js +4 -141
  74. package/dist/scripts/wrangler-config/patches.js.map +7 -1
  75. package/dist/scripts/wrangler-config/resources.d.ts +19 -7
  76. package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
  77. package/dist/scripts/wrangler-config/resources.js +1 -290
  78. package/dist/scripts/wrangler-config/resources.js.map +7 -1
  79. package/dist/scripts/wrangler-config/types.d.ts +24 -8
  80. package/dist/scripts/wrangler-config/types.d.ts.map +1 -1
  81. package/dist/scripts/wrangler-config/types.js +1 -49
  82. package/dist/scripts/wrangler-config/types.js.map +7 -1
  83. package/dist/test/integration-migrations.d.ts +29 -12
  84. package/dist/test/integration-migrations.d.ts.map +1 -1
  85. package/dist/test/integration-migrations.js +2 -171
  86. package/dist/test/integration-migrations.js.map +7 -1
  87. package/dist/test/mocks/cloudflare-workers.js +1 -90
  88. package/dist/test/mocks/cloudflare-workers.js.map +7 -1
  89. package/dist/vite.d.ts +5 -3
  90. package/dist/vite.d.ts.map +1 -1
  91. package/dist/vite.js +3 -125
  92. package/dist/vite.js.map +7 -1
  93. package/dist/vitest-aliases.d.ts +90 -0
  94. package/dist/vitest-aliases.d.ts.map +1 -0
  95. package/dist/vitest-aliases.js +1 -0
  96. package/dist/vitest-aliases.js.map +7 -0
  97. package/dist/vitest-integration.d.ts +96 -0
  98. package/dist/vitest-integration.d.ts.map +1 -0
  99. package/dist/vitest-integration.js +1 -0
  100. package/dist/vitest-integration.js.map +7 -0
  101. package/dist/vitest-repo.d.ts +154 -0
  102. package/dist/vitest-repo.d.ts.map +1 -0
  103. package/dist/vitest-repo.js +1 -0
  104. package/dist/vitest-repo.js.map +7 -0
  105. package/dist/vitest-web.d.ts +76 -19
  106. package/dist/vitest-web.d.ts.map +1 -1
  107. package/dist/vitest-web.js +1 -72
  108. package/dist/vitest-web.js.map +7 -1
  109. package/dist/vitest.d.ts +70 -19
  110. package/dist/vitest.d.ts.map +1 -1
  111. package/dist/vitest.js +1 -128
  112. package/dist/vitest.js.map +7 -1
  113. package/package.json +9 -3
  114. package/src/eslint-boundaries.ts +112 -11
  115. package/src/eslint.test.ts +40 -9
  116. package/src/eslint.ts +14 -9
  117. package/src/functions/pages-proxy.test.ts +3 -3
  118. package/src/functions/pages-proxy.ts +4 -2
  119. package/src/index.ts +23 -14
  120. package/src/scripts/backup/backup-rules.test.ts +4 -4
  121. package/src/scripts/backup/d1-target.ts +16 -6
  122. package/src/scripts/backup/destination-config.ts +27 -9
  123. package/src/scripts/backup/encrypt-backup.ts +12 -10
  124. package/src/scripts/backup/naming.ts +3 -1
  125. package/src/scripts/check-god-files.test.ts +19 -19
  126. package/src/scripts/check-god-files.ts +62 -33
  127. package/src/scripts/ensure-spa-shell-stub.ts +1 -1
  128. package/src/scripts/init-secrets.ts +20 -10
  129. package/src/scripts/lib/cli-args.ts +6 -3
  130. package/src/scripts/lib/wrangler-table.ts +5 -3
  131. package/src/scripts/migrations-lock.ts +2 -2
  132. package/src/scripts/prepare-wrangler-config.ts +3 -3
  133. package/src/scripts/spa-shell.test.ts +18 -18
  134. package/src/scripts/spa-shell.ts +26 -14
  135. package/src/scripts/validate-locales.test.ts +18 -18
  136. package/src/scripts/validate-locales.ts +43 -25
  137. package/src/scripts/verify-migrations.test.ts +8 -8
  138. package/src/scripts/verify-migrations.ts +47 -24
  139. package/src/scripts/verify-spa-shell.ts +1 -1
  140. package/src/scripts/wrangler-config/patches.ts +13 -5
  141. package/src/scripts/wrangler-config/resources.ts +34 -18
  142. package/src/scripts/wrangler-config/types.ts +24 -8
  143. package/src/test/integration-migrations.test.ts +7 -7
  144. package/src/test/integration-migrations.ts +33 -14
  145. package/src/vite.test.ts +25 -14
  146. package/src/vite.ts +5 -5
  147. package/src/vitest-aliases.test.ts +53 -0
  148. package/src/vitest-aliases.ts +125 -0
  149. package/src/vitest-factories.test.ts +127 -0
  150. package/src/vitest-integration.ts +118 -0
  151. package/src/vitest-repo.ts +269 -0
  152. package/src/vitest-web.ts +110 -28
  153. package/src/vitest.ts +96 -47
package/dist/vitest.js CHANGED
@@ -1,128 +1 @@
1
- /**
2
- * The unit-test Vitest config for the worker-and-packages half of the suite.
3
- *
4
- * Provenance: converged from the eight repos' `vitest.config.mts`. The coverage
5
- * block is Durable-DAV-Router's (the most complete: v8 provider, explicit
6
- * include/exclude patterns, thresholds with the reasoning for why they sit just
7
- * under the measured value); the alias block is Durable-DAV's, which is the only
8
- * one that also aliases `cloudflare:workers` and `cloudflare:sockets` to the
9
- * Node mocks.
10
- *
11
- * Canonical decisions:
12
- *
13
- * 1. **Every file matching `include` is reported** — Vitest 4 removed
14
- * `coverage.all`, and an explicit `include` now covers files no test
15
- * imported. That is the behaviour the source repos configured `all: true` for,
16
- * and the reason it mattered: without it a brand-new module with no test is
17
- * invisible rather than counted as zero, which is the exact regression this
18
- * gate exists to catch.
19
- * 2. **The SPA is excluded here**, so this config and `defineWebVitestConfig()`
20
- * partition the suite rather than each running all of it. Every SPA suite is
21
- * named `web-*`. One number could not honestly describe both halves: the SPA's
22
- * presentational modules pulled a shared floor down 16 points, so a change
23
- * adding legitimate code in `apps/api` could fail the gate on the strength of
24
- * files two directories away.
25
- * 3. **A custom `exclude` re-lists `node_modules`** — `test/` is a workspace
26
- * project and therefore has its own, so without the re-list the glob reaches
27
- * into `test/node_modules` and tries to run other packages' suites.
28
- * 4. **Thresholds are a consumer argument**, not a kit default. A floor is a
29
- * per-repo ratchet measured against that repo's suite; the kit cannot know a
30
- * number, and guessing one is how floors get lowered.
31
- */
32
- import { defineConfig } from 'vitest/config';
33
- import { fileURLToPath } from 'node:url';
34
- /**
35
- * The SPA's suites, excluded here so the two configs partition the suite.
36
- *
37
- * Every SPA suite is named `web-*`. `defineWebVitestConfig()` includes the same
38
- * glob, so a file is collected by exactly one config.
39
- */
40
- const SPA_FILES = 'test/**/web-*.test.{ts,tsx}';
41
- /**
42
- * The canonical alias set.
43
- *
44
- * Built relative to the consumer's repo root rather than the kit's directory,
45
- * so the factory describes *their* layout. A Vitest config is a standalone file
46
- * with no module graph to share through, and a suite resolving a workspace
47
- * import differently from its sibling fails in a way that looks like a product
48
- * bug — which is why these are stated once, here, rather than duplicated.
49
- */
50
- function canonicalAliases(root) {
51
- const at = (relative) => fileURLToPath(new URL(relative, root));
52
- return [
53
- { find: 'cloudflare:workers', replacement: at('test/mocks/cloudflare-workers.ts') },
54
- { find: 'cloudflare:sockets', replacement: at('test/mocks/cloudflare-sockets.ts') },
55
- { find: /^@\//, replacement: `${at('apps/api/src')}/` },
56
- { find: /^~\//, replacement: `${at('apps/web/src')}/` },
57
- ];
58
- }
59
- /**
60
- * Coverage `exclude` globs converged from the source repos.
61
- *
62
- * The categories: build and test tooling (`scripts/` grows with project surface,
63
- * not complexity, and the god-file guard excludes it for the same reason), test
64
- * files, declarations, re-export barrels (`index.ts` carries no logic of its
65
- * own), model records, generated files (the SPA shell is a one-line HTML blob
66
- * with no logic to exercise), and type-only modules.
67
- */
68
- const CANONICAL_COVERAGE_EXCLUDE = [
69
- 'scripts/**',
70
- '**/*.test.ts',
71
- '**/*.d.ts',
72
- '**/index.ts',
73
- '**/types.d.ts',
74
- '**/model/**',
75
- '**/generated/**',
76
- '**/D1Types.ts',
77
- '**/ServiceEnv.ts',
78
- '**/env.d.ts',
79
- ];
80
- /**
81
- * Build the unit-test config.
82
- *
83
- * ```ts
84
- * // vitest.config.mts
85
- * import { defineUnitVitestConfig } from '@rexezuge/tooling/vitest';
86
- * export default defineUnitVitestConfig();
87
- * ```
88
- */
89
- export function defineUnitVitestConfig(options = {}) {
90
- const root = options.root ?? new URL('.', import.meta.url).href;
91
- const coverageInclude = options.coverageInclude ?? ['apps/api/src/**/*.ts', 'apps/background/src/**/*.ts', 'packages/**/src/**/*.ts'];
92
- const coverageExclude = [...CANONICAL_COVERAGE_EXCLUDE, ...(options.coverageExclude ?? [])];
93
- const aliases = [...canonicalAliases(root), ...(options.aliases ?? [])];
94
- return defineConfig({
95
- resolve: { alias: aliases },
96
- test: {
97
- globals: true,
98
- environment: 'node',
99
- include: ['test/**/*.test.{ts,tsx}'],
100
- // `test` is a workspace project and therefore has its own node_modules;
101
- // without the re-list, the glob reaches into it.
102
- exclude: ['**/node_modules/**', '**/dist/**', 'test/integration/**', SPA_FILES],
103
- server: {
104
- deps: {
105
- // A `node_modules` dependency is externalized by default, so Node's
106
- // own ESM loader resolves a `cloudflare:workers` specifier and rejects
107
- // the scheme before `resolve.alias` is ever consulted. Inlining routes
108
- // it back through Vite, where the alias applies.
109
- inline: ['dofs'],
110
- },
111
- },
112
- coverage: {
113
- provider: 'v8',
114
- // Vitest 4 removed `coverage.all`; an explicit `include` now reports
115
- // every matching file whether or not a test imported it, which is the
116
- // behaviour the source repos' `all: true` was there to get: a brand-new
117
- // module with no test is counted as zero rather than being invisible,
118
- // which is the exact regression this gate exists to catch.
119
- reporter: ['text', 'lcov', 'html'],
120
- reportsDirectory: options.reportsDirectory ?? './coverage',
121
- include: [...coverageInclude],
122
- exclude: coverageExclude,
123
- ...(options.thresholds !== undefined && { thresholds: { ...options.thresholds } }),
124
- },
125
- },
126
- });
127
- }
128
- //# sourceMappingURL=vitest.js.map
1
+ import{defineConfig as n}from"vitest/config";import{DEFAULT_CLOUDFLARE_MOCKS as l,DEFAULT_WORKSPACE_PACKAGES as a,KIT_NO_EXTERNAL as u,workspaceAliases as i}from"./vitest-aliases.js";const g=["test/web/**","test/**/web-*.test.{ts,tsx}","apps/web/**/*.test.{ts,tsx}"],o=["scripts/**","**/*.test.ts","**/*.test.tsx","**/*.d.ts","**/index.ts","**/types.d.ts","**/model/**","**/generated/**","**/D1Types.ts","**/ServiceEnv.ts","**/env.d.ts"];function v(e={}){const t=e.root??new URL(".",import.meta.url).href,r=e.coverageInclude??["apps/api/src/**/*.ts","apps/background/src/**/*.ts","packages/**/src/**/*.ts"],c=[...o,...e.coverageExclude??[]],d=[...i({scope:e.scope??"@unused",root:t,packages:e.scope===void 0?[]:e.packages??a,mocks:e.mocks??l}).filter(s=>typeof s.find!="string"||!s.find.startsWith("@unused")),...e.aliases??[]];return n({...e.plugins!==void 0&&{plugins:[...e.plugins]},resolve:{alias:d,noExternal:[...u,...e.noExternal??[]]},test:{globals:!0,environment:"node",include:[...e.include??["test/**/*.test.{ts,tsx}"]],exclude:[...e.exclude??["**/node_modules/**","**/dist/**","test/integration/**",...g]],...e.setupFiles!==void 0&&{setupFiles:[...e.setupFiles]},server:{deps:{inline:[...e.serverDepsInline??["dofs"]]}},coverage:{provider:"v8",reporter:["text","lcov","html"],reportsDirectory:e.reportsDirectory??"./coverage",include:[...r],exclude:c,...e.thresholds!==void 0&&{thresholds:{...e.thresholds}}}}})}export{v as defineUnitVitestConfig};
@@ -1 +1,7 @@
1
- {"version":3,"file":"vitest.js","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAsDzC;;;;;GAKG;AACH,MAAM,SAAS,GAAG,6BAA6B,CAAC;AAEhD;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,IAAY;IACpC,MAAM,EAAE,GAAG,CAAC,QAAgB,EAAU,EAAE,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAChF,OAAO;QACL,EAAE,IAAI,EAAE,oBAAoB,EAAE,WAAW,EAAE,EAAE,CAAC,kCAAkC,CAAC,EAAE;QACnF,EAAE,IAAI,EAAE,oBAAoB,EAAE,WAAW,EAAE,EAAE,CAAC,kCAAkC,CAAC,EAAE;QACnF,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE;QACvD,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE;KACxD,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,0BAA0B,GAAsB;IACpD,YAAY;IACZ,cAAc;IACd,WAAW;IACX,aAAa;IACb,eAAe;IACf,aAAa;IACb,iBAAiB;IACjB,eAAe;IACf,kBAAkB;IAClB,aAAa;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAmC,EAAE;IAC1E,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IAChE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,CAAC,sBAAsB,EAAE,6BAA6B,EAAE,yBAAyB,CAAC,CAAC;IACtI,MAAM,eAAe,GAAG,CAAC,GAAG,0BAA0B,EAAE,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5F,MAAM,OAAO,GAAG,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;IAExE,OAAO,YAAY,CAAC;QAClB,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;QAC3B,IAAI,EAAE;YACJ,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,MAAM;YACnB,OAAO,EAAE,CAAC,yBAAyB,CAAC;YACpC,wEAAwE;YACxE,iDAAiD;YACjD,OAAO,EAAE,CAAC,oBAAoB,EAAE,YAAY,EAAE,qBAAqB,EAAE,SAAS,CAAC;YAC/E,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,oEAAoE;oBACpE,uEAAuE;oBACvE,uEAAuE;oBACvE,iDAAiD;oBACjD,MAAM,EAAE,CAAC,MAAM,CAAC;iBACjB;aACF;YACD,QAAQ,EAAE;gBACR,QAAQ,EAAE,IAAI;gBACd,qEAAqE;gBACrE,sEAAsE;gBACtE,wEAAwE;gBACxE,sEAAsE;gBACtE,2DAA2D;gBAC3D,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;gBAClC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,YAAY;gBAC1D,OAAO,EAAE,CAAC,GAAG,eAAe,CAAC;gBAC7B,OAAO,EAAE,eAAe;gBACxB,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;aACnF;SACF;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * The unit-test Vitest config for the worker-and-packages half of the suite.\n *\n * Provenance: converged from the eight repos' `vitest.config.mts`. The coverage\n * block is Durable-DAV-Router's (the most complete: v8 provider, explicit\n * include/exclude patterns, thresholds with the reasoning for why they sit just\n * under the measured value); the alias block is Durable-DAV's, which is the only\n * one that also aliases `cloudflare:workers` and `cloudflare:sockets` to the\n * Node mocks.\n *\n * Canonical decisions:\n *\n * 1. **Every file matching `include` is reported** — Vitest 4 removed\n * `coverage.all`, and an explicit `include` now covers files no test\n * imported. That is the behaviour the source repos configured `all: true` for,\n * and the reason it mattered: without it a brand-new module with no test is\n * invisible rather than counted as zero, which is the exact regression this\n * gate exists to catch.\n * 2. **The SPA is excluded here**, so this config and `defineWebVitestConfig()`\n * partition the suite rather than each running all of it. Every SPA suite is\n * named `web-*`. One number could not honestly describe both halves: the SPA's\n * presentational modules pulled a shared floor down 16 points, so a change\n * adding legitimate code in `apps/api` could fail the gate on the strength of\n * files two directories away.\n * 3. **A custom `exclude` re-lists `node_modules`** — `test/` is a workspace\n * project and therefore has its own, so without the re-list the glob reaches\n * into `test/node_modules` and tries to run other packages' suites.\n * 4. **Thresholds are a consumer argument**, not a kit default. A floor is a\n * per-repo ratchet measured against that repo's suite; the kit cannot know a\n * number, and guessing one is how floors get lowered.\n */\n\nimport { defineConfig } from 'vitest/config';\nimport { fileURLToPath } from 'node:url';\n\n/**\n * One `{ find, replacement }` pair for Vitest's resolver.\n */\nexport interface VitestAlias {\n readonly find: string | RegExp;\n readonly replacement: string;\n}\n\n/**\n * Coverage thresholds, in the four figures Vitest gates on.\n */\nexport interface CoverageThresholds {\n readonly statements?: number;\n readonly branches?: number;\n readonly functions?: number;\n readonly lines?: number;\n}\n\n/**\n * What `defineUnitVitestConfig` accepts. Every field is optional: the defaults\n * cover the canonical monorepo layout, and a consumer overrides only what its\n * tree actually differs in.\n */\nexport interface UnitVitestConfigOptions {\n /**\n * Extra resolver entries, applied after the canonical ones.\n */\n readonly aliases?: readonly VitestAlias[];\n /**\n * Where the repo root is, as a file URL. Defaults to the directory this\n * factory is *called* from, which is the repo root's `vitest.config.mts`.\n */\n readonly root?: string;\n /**\n * Coverage `include` globs. Defaults to the worker plus every workspace\n * package's `src`.\n */\n readonly coverageInclude?: readonly string[];\n /**\n * Coverage `exclude` globs, merged with the canonical set.\n */\n readonly coverageExclude?: readonly string[];\n /**\n * Coverage floors. Omitted by default; a repo that wants them sets them.\n */\n readonly thresholds?: CoverageThresholds;\n /**\n * Where the coverage report is written.\n */\n readonly reportsDirectory?: string;\n}\n\n/**\n * The SPA's suites, excluded here so the two configs partition the suite.\n *\n * Every SPA suite is named `web-*`. `defineWebVitestConfig()` includes the same\n * glob, so a file is collected by exactly one config.\n */\nconst SPA_FILES = 'test/**/web-*.test.{ts,tsx}';\n\n/**\n * The canonical alias set.\n *\n * Built relative to the consumer's repo root rather than the kit's directory,\n * so the factory describes *their* layout. A Vitest config is a standalone file\n * with no module graph to share through, and a suite resolving a workspace\n * import differently from its sibling fails in a way that looks like a product\n * bug — which is why these are stated once, here, rather than duplicated.\n */\nfunction canonicalAliases(root: string): VitestAlias[] {\n const at = (relative: string): string => fileURLToPath(new URL(relative, root));\n return [\n { find: 'cloudflare:workers', replacement: at('test/mocks/cloudflare-workers.ts') },\n { find: 'cloudflare:sockets', replacement: at('test/mocks/cloudflare-sockets.ts') },\n { find: /^@\\//, replacement: `${at('apps/api/src')}/` },\n { find: /^~\\//, replacement: `${at('apps/web/src')}/` },\n ];\n}\n\n/**\n * Coverage `exclude` globs converged from the source repos.\n *\n * The categories: build and test tooling (`scripts/` grows with project surface,\n * not complexity, and the god-file guard excludes it for the same reason), test\n * files, declarations, re-export barrels (`index.ts` carries no logic of its\n * own), model records, generated files (the SPA shell is a one-line HTML blob\n * with no logic to exercise), and type-only modules.\n */\nconst CANONICAL_COVERAGE_EXCLUDE: readonly string[] = [\n 'scripts/**',\n '**/*.test.ts',\n '**/*.d.ts',\n '**/index.ts',\n '**/types.d.ts',\n '**/model/**',\n '**/generated/**',\n '**/D1Types.ts',\n '**/ServiceEnv.ts',\n '**/env.d.ts',\n];\n\n/**\n * Build the unit-test config.\n *\n * ```ts\n * // vitest.config.mts\n * import { defineUnitVitestConfig } from '@rexezuge/tooling/vitest';\n * export default defineUnitVitestConfig();\n * ```\n */\nexport function defineUnitVitestConfig(options: UnitVitestConfigOptions = {}): ReturnType<typeof defineConfig> {\n const root = options.root ?? new URL('.', import.meta.url).href;\n const coverageInclude = options.coverageInclude ?? ['apps/api/src/**/*.ts', 'apps/background/src/**/*.ts', 'packages/**/src/**/*.ts'];\n const coverageExclude = [...CANONICAL_COVERAGE_EXCLUDE, ...(options.coverageExclude ?? [])];\n const aliases = [...canonicalAliases(root), ...(options.aliases ?? [])];\n\n return defineConfig({\n resolve: { alias: aliases },\n test: {\n globals: true,\n environment: 'node',\n include: ['test/**/*.test.{ts,tsx}'],\n // `test` is a workspace project and therefore has its own node_modules;\n // without the re-list, the glob reaches into it.\n exclude: ['**/node_modules/**', '**/dist/**', 'test/integration/**', SPA_FILES],\n server: {\n deps: {\n // A `node_modules` dependency is externalized by default, so Node's\n // own ESM loader resolves a `cloudflare:workers` specifier and rejects\n // the scheme before `resolve.alias` is ever consulted. Inlining routes\n // it back through Vite, where the alias applies.\n inline: ['dofs'],\n },\n },\n coverage: {\n provider: 'v8',\n // Vitest 4 removed `coverage.all`; an explicit `include` now reports\n // every matching file whether or not a test imported it, which is the\n // behaviour the source repos' `all: true` was there to get: a brand-new\n // module with no test is counted as zero rather than being invisible,\n // which is the exact regression this gate exists to catch.\n reporter: ['text', 'lcov', 'html'],\n reportsDirectory: options.reportsDirectory ?? './coverage',\n include: [...coverageInclude],\n exclude: coverageExclude,\n ...(options.thresholds !== undefined && { thresholds: { ...options.thresholds } }),\n },\n },\n });\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/vitest.ts"],
4
+ "sourcesContent": ["/**\n * The unit-test Vitest config for the worker-and-packages half of the suite.\n *\n * Provenance: converged from all nine repos' `vitest.config.mts`. The coverage\n * block is Durable-DAV-Router's (the most complete: v8 provider, explicit\n * include/exclude patterns, thresholds with the reasoning for why they sit just\n * under the measured value); the alias block is the union of Durable-DAV's\n * `cloudflare:*` mocks, every repo's `@scope/* → src` workspace table, and the\n * shared `@/` + `~/` prefixes — see {@link ./vitest-aliases.js}.\n *\n * Canonical decisions:\n *\n * 1. **Every file matching `include` is reported** — Vitest 4 removed\n * `coverage.all`, and an explicit `include` now covers files no test\n * imported. That is the behaviour the source repos configured `all: true` for,\n * and the reason it mattered: without it a brand-new module with no test is\n * invisible rather than counted as zero, which is the exact regression this\n * gate exists to catch.\n * 2. **The SPA is excluded here**, so this config and `defineWebVitestConfig()`\n * partition the suite rather than each running all of it. The default covers\n * every suite shape the family uses (`test/web/**`, `test/**​/web-*`,\n * `apps/web/**`); see `defineRepoVitestConfig()` for the single-file\n * `projects` composition the AWS/Mail-Meow/CalDAV repos use.\n * 3. **A custom `exclude` re-lists `node_modules`** — `test/` is a workspace\n * project and therefore has its own, so without the re-list the glob reaches\n * into `test/node_modules` and tries to run other packages' suites.\n * 4. **Thresholds are a consumer argument**, not a kit default. A floor is a\n * per-repo ratchet measured against that repo's suite; the kit cannot know a\n * number, and guessing one is how floors get lowered.\n * 5. **`@rexezuge/*` is never externalized** — see `KIT_NO_EXTERNAL`: the kit\n * ships ESM `dist/` with bundler-style extensionless imports, which Node's\n * resolver refuses, so the kit stays inside Vite's pipeline (the same\n * resolver that bundles the worker).\n */\n\nimport { defineConfig, type Plugin } from 'vitest/config';\nimport { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';\nimport type { VitestAlias } from './vitest-aliases.ts';\n\nexport type { VitestAlias } from './vitest-aliases.ts';\n\n/**\n * Coverage thresholds, in the four figures Vitest gates on.\n */\nexport interface CoverageThresholds {\n readonly statements?: number;\n readonly branches?: number;\n readonly functions?: number;\n readonly lines?: number;\n}\n\n/**\n * What `defineUnitVitestConfig` accepts. Every field is optional: the defaults\n * cover the canonical monorepo layout, and a consumer overrides only what its\n * tree actually differs in.\n */\nexport interface UnitVitestConfigOptions {\n /**\n * The consuming repo's npm scope, e.g. `'@myapp'`. When supplied, `@scope/*`\n * workspace aliases are generated from `packages` (plus `background` under\n * `apps/`); when omitted, only the `cloudflare:*`, `@/` and `~/` aliases\n * apply and `aliases` carries the workspace table by hand.\n */\n readonly scope?: string;\n /**\n * Workspace package directory names. Defaults to the family superset; a repo\n * without a domain package keeps the default harmlessly (its alias never\n * matches).\n */\n readonly packages?: readonly string[];\n /**\n * Which `cloudflare:*` mocks to alias. Defaults to workers/sockets/workflows.\n */\n readonly mocks?: readonly string[];\n /**\n * Extra resolver entries, applied after the canonical ones (e.g. the `hono`\n * dedupe two repos carry, or an `/index.ts` exact entry).\n */\n readonly aliases?: readonly VitestAlias[];\n /**\n * Where the repo root is, as a file URL. Defaults to the directory this\n * factory is *called* from, which is the repo root's `vitest.config.mts`.\n * Pass `new URL('.', import.meta.url).href` explicitly from the caller —\n * never rely on this module's own URL, which points into `node_modules`.\n */\n readonly root?: string;\n /**\n * Which suites to collect. Defaults to the whole unit suite.\n */\n readonly include?: readonly string[];\n /**\n * Suite paths to skip, replacing the default. Defaults re-list\n * `node_modules`/`dist`/`integration` plus every SPA shape.\n */\n readonly exclude?: readonly string[];\n /**\n * `node_modules` specifiers to inline through Vite rather than externalize.\n * Defaults to `['dofs']` (Durable-DAV: `dofs` imports `cloudflare:workers`,\n * which Node rejects before `resolve.alias` is consulted).\n */\n readonly serverDepsInline?: readonly string[];\n /**\n * Resolver `noExternal` patterns. Defaults to keeping `@rexezuge/*` inside\n * Vite's pipeline; see `KIT_NO_EXTERNAL`.\n */\n readonly noExternal?: readonly (string | RegExp)[];\n /**\n * Vite plugins for the suite (rare on the backend half; the SPA half passes\n * `react()` here).\n */\n readonly plugins?: readonly Plugin[];\n /**\n * Setup files run before each test file (e.g. AWS's floci guard, Meow's\n * backend/web setups).\n */\n readonly setupFiles?: readonly string[];\n /**\n * Coverage `include` globs. Defaults to the worker plus every workspace\n * package's `src`.\n */\n readonly coverageInclude?: readonly string[];\n /**\n * Coverage `exclude` globs, merged with the canonical set.\n */\n readonly coverageExclude?: readonly string[];\n /**\n * Coverage floors. Omitted by default; a repo that wants them sets them.\n */\n readonly thresholds?: CoverageThresholds;\n /**\n * Where the coverage report is written.\n */\n readonly reportsDirectory?: string;\n}\n\n/**\n * The SPA's suites, excluded here so the two configs partition the suite.\n *\n * Every shape the family uses: the `test/web/**` directory convention\n * (CalDAV-Bridge, Mail-Meow), the root-suite `web-*` naming convention\n * (Durable-DAV-Router), and suites bundled under `apps/web` (Mail-Otter).\n * `defineWebVitestConfig()` includes the same globs, so a file is collected by\n * exactly one config.\n */\nconst SPA_FILES: readonly string[] = ['test/web/**', 'test/**/web-*.test.{ts,tsx}', 'apps/web/**/*.test.{ts,tsx}'];\n\n/**\n * Coverage `exclude` globs converged from the source repos.\n *\n * The categories: build and test tooling (`scripts/` grows with project surface,\n * not complexity, and the god-file guard excludes it for the same reason), test\n * files, declarations, re-export barrels (`index.ts` carries no logic of its\n * own), model records, generated files (the SPA shell is a one-line HTML blob\n * with no logic to exercise), and type-only modules.\n */\nconst CANONICAL_COVERAGE_EXCLUDE: readonly string[] = [\n 'scripts/**',\n '**/*.test.ts',\n '**/*.test.tsx',\n '**/*.d.ts',\n '**/index.ts',\n '**/types.d.ts',\n '**/model/**',\n '**/generated/**',\n '**/D1Types.ts',\n '**/ServiceEnv.ts',\n '**/env.d.ts',\n];\n\n/**\n * Build the unit-test config.\n *\n * ```ts\n * // vitest.config.mts\n * import { defineUnitVitestConfig } from '@rexezuge/tooling/vitest';\n * export default defineUnitVitestConfig({\n * scope: '@myapp',\n * thresholds: { statements: 60, branches: 55, functions: 65, lines: 60 },\n * });\n * ```\n */\nexport function defineUnitVitestConfig(options: UnitVitestConfigOptions = {}): ReturnType<typeof defineConfig> {\n const root = options.root ?? new URL('.', import.meta.url).href;\n const coverageInclude = options.coverageInclude ?? ['apps/api/src/**/*.ts', 'apps/background/src/**/*.ts', 'packages/**/src/**/*.ts'];\n const coverageExclude = [...CANONICAL_COVERAGE_EXCLUDE, ...(options.coverageExclude ?? [])];\n const baseAliases = workspaceAliases({\n scope: options.scope ?? '@unused',\n root,\n packages: options.scope === undefined ? [] : (options.packages ?? DEFAULT_WORKSPACE_PACKAGES),\n mocks: options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS,\n });\n // A placeholder scope contributes no `@unused/*` entries; the mocks plus\n // `@/`/`~/` survive either way.\n const aliases = [\n ...baseAliases.filter((alias) => typeof alias.find !== 'string' || !alias.find.startsWith('@unused')),\n ...(options.aliases ?? []),\n ];\n\n return defineConfig({\n ...(options.plugins !== undefined && { plugins: [...options.plugins] }),\n resolve: { alias: aliases, noExternal: [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])] },\n test: {\n globals: true,\n environment: 'node',\n include: [...(options.include ?? ['test/**/*.test.{ts,tsx}'])],\n // `test` is a workspace project and therefore has its own node_modules;\n // without the re-list, the glob reaches into it.\n exclude: [...(options.exclude ?? ['**/node_modules/**', '**/dist/**', 'test/integration/**', ...SPA_FILES])],\n ...(options.setupFiles !== undefined && { setupFiles: [...options.setupFiles] }),\n server: {\n deps: {\n // A `node_modules` dependency is externalized by default, so Node's\n // own ESM loader resolves a `cloudflare:workers` specifier and rejects\n // the scheme before `resolve.alias` is ever consulted. Inlining routes\n // it back through Vite, where the alias applies.\n inline: [...(options.serverDepsInline ?? ['dofs'])],\n },\n },\n coverage: {\n provider: 'v8',\n // Vitest 4 removed `coverage.all`; an explicit `include` now reports\n // every matching file whether or not a test imported it, which is the\n // behaviour the source repos' `all: true` was there to get: a brand-new\n // module with no test is counted as zero rather than being invisible,\n // which is the exact regression this gate exists to catch.\n reporter: ['text', 'lcov', 'html'],\n reportsDirectory: options.reportsDirectory ?? './coverage',\n include: [...coverageInclude],\n exclude: coverageExclude,\n ...(options.thresholds !== undefined && { thresholds: { ...options.thresholds } }),\n },\n },\n });\n}\n"],
5
+ "mappings": "AAmCA,OAAS,gBAAAA,MAAiC,gBAC1C,OAAS,4BAAAC,EAA0B,8BAAAC,EAA4B,mBAAAC,EAAiB,oBAAAC,MAAwB,sBA4GxG,MAAMC,EAA+B,CAAC,cAAe,8BAA+B,6BAA6B,EAW3GC,EAAgD,CACpD,aACA,eACA,gBACA,YACA,cACA,gBACA,cACA,kBACA,gBACA,mBACA,eAeI,SAAUC,EAAuBC,EAAmC,CAAA,EAAE,CAC1E,MAAMC,EAAOD,EAAQ,MAAQ,IAAI,IAAI,IAAK,YAAY,GAAG,EAAE,KACrDE,EAAkBF,EAAQ,iBAAmB,CAAC,uBAAwB,8BAA+B,yBAAyB,EAC9HG,EAAkB,CAAC,GAAGL,EAA4B,GAAIE,EAAQ,iBAAmB,CAAA,CAAG,EASpFI,EAAU,CACd,GATkBR,EAAiB,CACnC,MAAOI,EAAQ,OAAS,UACxB,KAAAC,EACA,SAAUD,EAAQ,QAAU,OAAY,CAAA,EAAMA,EAAQ,UAAYN,EAClE,MAAOM,EAAQ,OAASP,EACzB,EAIgB,OAAQY,GAAU,OAAOA,EAAM,MAAS,UAAY,CAACA,EAAM,KAAK,WAAW,SAAS,CAAC,EACpG,GAAIL,EAAQ,SAAW,CAAA,GAGzB,OAAOR,EAAa,CAClB,GAAIQ,EAAQ,UAAY,QAAa,CAAE,QAAS,CAAC,GAAGA,EAAQ,OAAO,CAAC,EACpE,QAAS,CAAE,MAAOI,EAAS,WAAY,CAAC,GAAGT,EAAiB,GAAIK,EAAQ,YAAc,CAAA,CAAG,CAAC,EAC1F,KAAM,CACJ,QAAS,GACT,YAAa,OACb,QAAS,CAAC,GAAIA,EAAQ,SAAW,CAAC,yBAAyB,CAAE,EAG7D,QAAS,CAAC,GAAIA,EAAQ,SAAW,CAAC,qBAAsB,aAAc,sBAAuB,GAAGH,CAAS,CAAE,EAC3G,GAAIG,EAAQ,aAAe,QAAa,CAAE,WAAY,CAAC,GAAGA,EAAQ,UAAU,CAAC,EAC7E,OAAQ,CACN,KAAM,CAKJ,OAAQ,CAAC,GAAIA,EAAQ,kBAAoB,CAAC,MAAM,CAAE,IAGtD,SAAU,CACR,SAAU,KAMV,SAAU,CAAC,OAAQ,OAAQ,MAAM,EACjC,iBAAkBA,EAAQ,kBAAoB,aAC9C,QAAS,CAAC,GAAGE,CAAe,EAC5B,QAASC,EACT,GAAIH,EAAQ,aAAe,QAAa,CAAE,WAAY,CAAE,GAAGA,EAAQ,UAAU,CAAE,IAGpF,CACH",
6
+ "names": ["defineConfig", "DEFAULT_CLOUDFLARE_MOCKS", "DEFAULT_WORKSPACE_PACKAGES", "KIT_NO_EXTERNAL", "workspaceAliases", "SPA_FILES", "CANONICAL_COVERAGE_EXCLUDE", "defineUnitVitestConfig", "options", "root", "coverageInclude", "coverageExclude", "aliases", "alias"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexezuge/tooling",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,10 +26,16 @@
26
26
  "src"
27
27
  ],
28
28
  "dependencies": {
29
- "@rexezuge/d1": "1.2.0"
29
+ "@rexezuge/d1": "1.4.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "eslint": "^10.0.0",
33
+ "eslint-config-prettier": "^10.1.8",
34
+ "eslint-plugin-prettier": "^5.5.6",
35
+ "eslint-plugin-regexp": "^3.3.1",
36
+ "eslint-plugin-sonarjs": "^4.2.2",
37
+ "eslint-plugin-unicorn": "^76.0.0",
38
+ "globals": "^17.13.0",
33
39
  "jsonc-parser": "^3.3.1",
34
40
  "prettier": "^3.9.0",
35
41
  "typescript": "^6.0.0",
@@ -54,7 +60,7 @@
54
60
  },
55
61
  "description": "Config factories, repo scripts, test helpers, and CI templates for the Rexezuge-CloudflareWorkers family.",
56
62
  "scripts": {
57
- "build": "tsc -p tsconfig.json",
63
+ "build": "tsc -p tsconfig.json && node ../../scripts/minify-dist.mjs",
58
64
  "typecheck": "tsc -p tsconfig.test.json --noEmit",
59
65
  "test": "vitest run"
60
66
  }
@@ -9,10 +9,20 @@ import type tseslint from 'typescript-eslint';
9
9
  * argues about — are their own module rather than the tail of a 640-line
10
10
  * config file.
11
11
  *
12
+ * Converged across all nine family repos: `provider-clients` (AWS-AccessBridge,
13
+ * CalDAV-Bridge, Mail-Meow, Mail-Otter), `webdav`/`dav-store` (Durable-DAV,
14
+ * Durable-DAV-Router, Edge-Sonic), `git-protocol`/`git-service` (Edge-Git).
15
+ * `media-tags`/`subsonic` (Edge-Sonic) carry no boundary block in their source
16
+ * repo — they are unconstrained utility leaves — so they have no layer here.
17
+ *
12
18
  * The table is data rather than inline blocks so the dynamic-`import()` guard
13
19
  * is generated from the same list: a rule that derived its banned set from
14
20
  * another rule's configuration would be a second source of truth for the layer
15
21
  * table, and that table is what the docs describe.
22
+ *
23
+ * The table is a superset: a repo without a domain package simply never imports
24
+ * it, so its ban never fires. A layer entry for a directory that does not exist
25
+ * in the consumer matches no file and costs nothing.
16
26
  */
17
27
 
18
28
  /**
@@ -27,6 +37,11 @@ export const DEFAULT_PROJECT_DIRS: readonly string[] = [
27
37
  'packages/backend-errors',
28
38
  'packages/backend-runtime',
29
39
  'packages/backend-data',
40
+ 'packages/provider-clients',
41
+ 'packages/webdav',
42
+ 'packages/dav-store',
43
+ 'packages/git-protocol',
44
+ 'packages/git-service',
30
45
  'packages/backend-services',
31
46
  'apps/api',
32
47
  'apps/background',
@@ -36,19 +51,33 @@ export const DEFAULT_PROJECT_DIRS: readonly string[] = [
36
51
  /**
37
52
  * One layer's ban list, as the repo-relative package suffixes it may not import.
38
53
  *
39
- * Converged from the four source stacks. `backend-data` and `backend-services`
40
- * appear in all four; `webdav`/`dav-store` are Durable-DAV's, `provider-clients`
41
- * is Mail-Meow's and AWS's. A layer only bans what exists in its repo, so the
54
+ * Converged from all nine family repos. `backend-data` and `backend-services`
55
+ * appear in all nine; `provider-clients` is AWS-AccessBridge's, CalDAV-Bridge's,
56
+ * Mail-Meow's and Mail-Otter's; `webdav`/`dav-store` are Durable-DAV's,
57
+ * Durable-DAV-Router's and Edge-Sonic's; `git-protocol`/`git-service` are
58
+ * Edge-Git's. A layer only bans what exists in its repo, so the
42
59
  * union is safe: a repo without `provider-clients` simply never imports it.
60
+ *
61
+ * One `dir` may appear in several entries (see `apps/api` below): each entry
62
+ * carries its own message and `allowTypeImports`, because the DAO ban allows
63
+ * type-only imports and the direct-client bans do not.
43
64
  */
44
65
  export interface LayerBan {
45
- /** Directory the rule is scoped to. */
66
+ /**
67
+ Directory the rule is scoped to.
68
+ */
46
69
  readonly dir: string;
47
- /** Package suffixes (relative to `scope`) that may not be imported from here. */
70
+ /**
71
+ Package suffixes (relative to `scope`) that may not be imported from here.
72
+ */
48
73
  readonly ban: readonly string[];
49
- /** Message shown when the rule fires. */
74
+ /**
75
+ Message shown when the rule fires.
76
+ */
50
77
  readonly message: string;
51
- /** Type-only imports are allowed, for the DAO boundary in `apps/api`. */
78
+ /**
79
+ Type-only imports are allowed, for the DAO boundary in `apps/api`.
80
+ */
52
81
  readonly allowTypeImports?: boolean;
53
82
  }
54
83
 
@@ -70,14 +99,65 @@ export function layerBans(scope: string): readonly LayerBan[] {
70
99
  },
71
100
  {
72
101
  dir: 'packages/backend-runtime',
73
- ban: [at('backend-data'), at('webdav'), at('backend-services'), at('api'), at('background')],
102
+ ban: [
103
+ at('backend-data'),
104
+ at('provider-clients'),
105
+ at('webdav'),
106
+ at('dav-store'),
107
+ at('git-protocol'),
108
+ at('git-service'),
109
+ at('backend-services'),
110
+ at('api'),
111
+ at('background'),
112
+ ],
74
113
  message: 'backend-runtime must not import from a higher layer',
75
114
  },
76
115
  {
77
116
  dir: 'packages/backend-data',
78
- ban: [at('backend-runtime'), at('webdav'), at('backend-services'), at('api'), at('background')],
117
+ ban: [
118
+ at('backend-runtime'),
119
+ at('provider-clients'),
120
+ at('webdav'),
121
+ at('dav-store'),
122
+ at('git-protocol'),
123
+ at('git-service'),
124
+ at('backend-services'),
125
+ at('api'),
126
+ at('background'),
127
+ ],
79
128
  message: 'backend-data must not import from a higher layer',
80
129
  },
130
+ // Domain protocol layers (layer 2, beside backend-data): each bans the DAO
131
+ // layer, the runtime, its store counterpart where it has one, the service
132
+ // layer and the apps. Sources: provider-clients (AWS-AccessBridge,
133
+ // Mail-Meow), webdav (Durable-DAV, Edge-Sonic), git-protocol (Edge-Git).
134
+ {
135
+ dir: 'packages/provider-clients',
136
+ ban: [at('backend-data'), at('backend-runtime'), at('backend-services'), at('api'), at('background')],
137
+ message: 'provider-clients must not import DAOs from backend-data',
138
+ },
139
+ {
140
+ dir: 'packages/webdav',
141
+ ban: [at('backend-data'), at('backend-runtime'), at('dav-store'), at('backend-services'), at('api'), at('background')],
142
+ message: 'webdav must not import DAOs from backend-data',
143
+ },
144
+ {
145
+ dir: 'packages/git-protocol',
146
+ ban: [at('backend-data'), at('backend-runtime'), at('git-service'), at('backend-services'), at('api'), at('background')],
147
+ message: 'git-protocol must not import DAOs from backend-data',
148
+ },
149
+ // Domain store layers (layer 2-3): only layers 0-2, never services or apps.
150
+ // Sources: dav-store (Durable-DAV), git-service (Edge-Git).
151
+ {
152
+ dir: 'packages/dav-store',
153
+ ban: [at('backend-services'), at('api'), at('background')],
154
+ message: 'dav-store must not import from backend-services (higher layer)',
155
+ },
156
+ {
157
+ dir: 'packages/git-service',
158
+ ban: [at('backend-services'), at('api'), at('background')],
159
+ message: 'git-service must not import from backend-services (higher layer)',
160
+ },
81
161
  {
82
162
  dir: 'packages/backend-services',
83
163
  ban: [at('api'), at('background')],
@@ -87,7 +167,28 @@ export function layerBans(scope: string): readonly LayerBan[] {
87
167
  dir: 'apps/api',
88
168
  ban: [at('backend-data/dao'), at('backend-data')],
89
169
  allowTypeImports: true,
90
- message: 'apps/api must not import DAOs or backend-data values directly; use backend-services instead',
170
+ message:
171
+ 'apps/api must not import DAOs or backend-data values directly; use backend-services instead (type-only imports are allowed)',
172
+ },
173
+ // Direct-client bans: one entry per client package so each message names
174
+ // the correct alternative. A repo holds at most one of these packages, so
175
+ // the other two never fire. Sources: provider-clients (AWS-AccessBridge,
176
+ // Mail-Meow, Mail-Otter, CalDAV-Bridge), dav-store (Durable-DAV),
177
+ // git-service (Edge-Git).
178
+ {
179
+ dir: 'apps/api',
180
+ ban: [at('provider-clients')],
181
+ message: `apps/api must not import provider-clients directly; use ${scope}/backend-services instead`,
182
+ },
183
+ {
184
+ dir: 'apps/api',
185
+ ban: [at('dav-store')],
186
+ message: `apps/api must not import dav-store directly; use ${scope}/webdav + DO RPC via ${scope}/background instead`,
187
+ },
188
+ {
189
+ dir: 'apps/api',
190
+ ban: [at('git-service')],
191
+ message: `apps/api must not import git-service directly; use ${scope}/git-protocol + DO RPC via ${scope}/background instead`,
91
192
  },
92
193
  {
93
194
  dir: 'apps/background',
@@ -160,7 +261,7 @@ export function restrictedDynamicImports(bans: readonly LayerBan[]): ConfigInput
160
261
  'no-restricted-syntax': [
161
262
  'error',
162
263
  ...ban.map((specifier) => ({
163
- selector: `ImportExpression[source.type='Literal'][source.value=/^${specifier.replaceAll('/', '\\/')}/]`,
264
+ selector: `ImportExpression[source.type='Literal'][source.value=/^${specifier.replaceAll('/', String.raw`\/`)}/]`,
164
265
  message: `A dynamic import() is not covered by no-restricted-imports, so this layer reaches \`${specifier}\` through the one syntax that gate does not see. Both say no: ${message}`,
165
266
  })),
166
267
  ],
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { defineRepoLintConfig } from './eslint';
2
+ import { defineRepoLintConfig } from './eslint.ts';
3
3
 
4
4
  /**
5
5
  * Structural checks on the produced flat config.
@@ -12,11 +12,14 @@ import { defineRepoLintConfig } from './eslint';
12
12
  * those is a config that silently stops gating something.
13
13
  */
14
14
 
15
- /** The only glob syntax the config uses: `**`, `*`, and `{a,b}` alternation. */
15
+ /**
16
+ The only glob syntax the config uses: `**`, `*`, and `{a,b}` alternation.
17
+ */
16
18
  function globToRegExp(pattern: string): RegExp {
17
19
  const escape = (char: string): string => char.replaceAll(/[$()+.?[\\\]^{|}]/g, String.raw`\$&`);
18
20
  let out = '';
19
- for (let index = 0; index < pattern.length; index += 1) {
21
+ let index = 0;
22
+ while (index < pattern.length) {
20
23
  const char = pattern[index] as string;
21
24
  if (char === '*' && pattern[index + 1] === '*') {
22
25
  out += '.*';
@@ -35,11 +38,14 @@ function globToRegExp(pattern: string): RegExp {
35
38
  } else {
36
39
  out += escape(char);
37
40
  }
41
+ index += 1;
38
42
  }
39
43
  return new RegExp(`^${out}$`);
40
44
  }
41
45
 
42
- /** Every config object in the array, flattened through any nested arrays. */
46
+ /**
47
+ Every config object in the array, flattened through any nested arrays.
48
+ */
43
49
  function entries(config: unknown): Array<Record<string, unknown>> {
44
50
  const out: Array<Record<string, unknown>> = [];
45
51
  for (const entry of config as unknown[]) {
@@ -65,7 +71,9 @@ function covers(entry: Record<string, unknown>, path: string): boolean {
65
71
  return files.some((pattern) => typeof pattern === 'string' && globToRegExp(pattern).test(path));
66
72
  }
67
73
 
68
- /** Every rule that applies to `path`, later entries winning. */
74
+ /**
75
+ Every rule that applies to `path`, later entries winning.
76
+ */
69
77
  function rulesOf(config: unknown, path: string): Record<string, unknown> {
70
78
  const rules: Record<string, unknown> = {};
71
79
  for (const entry of entries(config)) {
@@ -74,7 +82,9 @@ function rulesOf(config: unknown, path: string): Record<string, unknown> {
74
82
  return rules;
75
83
  }
76
84
 
77
- /** JSON of every rule block in the config. Rules are plain data; plugins are not. */
85
+ /**
86
+ JSON of every rule block in the config. Rules are plain data; plugins are not.
87
+ */
78
88
  function rulesJson(config: unknown): string {
79
89
  return entries(config)
80
90
  .map((entry) => JSON.stringify(entry['rules'] ?? {}))
@@ -104,9 +114,9 @@ describe('defineRepoLintConfig', () => {
104
114
  // read as undefined globals — and the vitest web config runs those suites under
105
115
  // jsdom, so the lint environment disagreed with the execution environment.
106
116
  const webEntries = entries(config).filter((entry) => covers(entry, 'apps/web/src/main.tsx'));
107
- const browser = webEntries
108
- .map((entry) => Object.keys((entry as { languageOptions?: { globals?: Record<string, unknown> } }).languageOptions?.globals ?? {}))
109
- .flat();
117
+ const browser = webEntries.flatMap((entry) =>
118
+ Object.keys((entry as { languageOptions?: { globals?: Record<string, unknown> } }).languageOptions?.globals ?? {}),
119
+ );
110
120
  expect(browser).toContain('window');
111
121
  expect(browser).toContain('document');
112
122
  // And the node globals survive: a shared file touching both still lints.
@@ -155,6 +165,27 @@ describe('defineRepoLintConfig', () => {
155
165
  );
156
166
  });
157
167
 
168
+ it('covers the family superset of domain layers', () => {
169
+ // provider-clients (AWS/CalDAV/Meow/Otter), webdav/dav-store (DAV/Router/Sonic),
170
+ // git-protocol/git-service (Git): a repo without the package never imports it,
171
+ // so the union is safe and no repo needs extraLayers for a known package.
172
+ const rules = rulesJson(config);
173
+ expect(rules).toContain('@fixture/provider-clients');
174
+ expect(rules).toContain('@fixture/webdav');
175
+ expect(rules).toContain('@fixture/dav-store');
176
+ expect(rules).toContain('@fixture/git-protocol');
177
+ expect(rules).toContain('@fixture/git-service');
178
+ });
179
+
180
+ it('bans direct client imports from apps/api with the per-client alternative', () => {
181
+ const rules = rulesJson(config);
182
+ expect(rules).toContain('must not import provider-clients directly');
183
+ expect(rules).toContain('must not import dav-store directly');
184
+ expect(rules).toContain('must not import git-service directly');
185
+ // And the DAO ban still allows type-only imports beside them.
186
+ expect(rules).toContain('allowTypeImports');
187
+ });
188
+
158
189
  it('accepts extra layers without losing the canonical ones', () => {
159
190
  const extended = defineRepoLintConfig({
160
191
  scope: '@fixture',
package/src/eslint.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * The converged ESLint flat config for a monorepo in the Rexezuge family.
3
3
  *
4
- * Provenance: the base is Durable-DAV's `eslint.config.mjs` (380+ lines, the most
4
+ * Provenance: the base is Durable-DAV's `eslint.config.mjs` (the most
5
5
  * elaborate of the nine repos, with the layered `no-restricted-imports` boundary
6
- * rules). Merged in from the other three stacks that share the same plugin set:
6
+ * rules). Merged in from the stacks that share the same plugin set:
7
7
  *
8
8
  * - **Edge-Sonic** — `test/**` is *not* ignored (it is linted like everything else,
9
9
  * with a narrow override block for Vitest idioms), and `unicorn/prefer-ternary`
@@ -14,6 +14,9 @@
14
14
  * `allowTypeImports` where the source repos do not. It is also the source for
15
15
  * the anchored skip patterns and the symlink-safe walk that came out of its own
16
16
  * backlog.
17
+ * - **CalDAV-Bridge, Mail-Otter, Durable-DAV-Router, Edge-Git, Agent-Router** —
18
+ * the `provider-clients` / `webdav`+`dav-store` / `git-protocol`+`git-service`
19
+ * layers and the per-client `apps/api` alternatives in the boundary table.
17
20
  *
18
21
  * Canonical decisions, and why each one:
19
22
  *
@@ -21,9 +24,11 @@
21
24
  * `warn`, which under `eslint --quiet` is unenforceable — a gate nobody can see
22
25
  * is a gate that has never run. Formatting drift is therefore a hard failure.
23
26
  * 2. **The layered boundary rules are parameterized by `scope`.** Every source
24
- * repo wrote the same seven blocks with a different npm scope hardcoded; the
27
+ * repo wrote the same blocks with a different npm scope hardcoded; the
25
28
  * factory takes `scope` (`'@myapp'`) and generates the `@myapp/*` patterns.
26
- * The table itself lives in {@link ./eslint-boundaries}.
29
+ * The table itself lives in {@link ./eslint-boundaries.ts} and covers the
30
+ * family superset — a repo without a domain package never triggers its ban,
31
+ * so no repo needs `extraLayers` for a known package.
27
32
  * 3. **`test/**` is linted, not ignored.** Durable-DAV/AWS/Mail-Meow ignored it;
28
33
  * Edge-Sonic does not, and records why: ~200 KB of test code had accumulated
29
34
  * violations that nothing reported.
@@ -39,8 +44,8 @@
39
44
  * zero-dependency, and the plugin belongs to the app that has JSX. A consumer
40
45
  * appends it — the README shows the four lines.
41
46
  *
42
- * The rule bodies live in {@link ./eslint-rules} and the boundary table in
43
- * {@link ./eslint-boundaries}; this file is the assembly. A repo that needs a
47
+ * The rule bodies live in {@link ./eslint-rules.ts} and the boundary table in
48
+ * {@link ./eslint-boundaries.ts}; this file is the assembly. A repo that needs a
44
49
  * boundary the canonical table does not name passes `extraLayers` — see
45
50
  * {@link RepoLintConfigOptions}.
46
51
  */
@@ -53,9 +58,9 @@ import pluginRegexp from 'eslint-plugin-regexp';
53
58
  import eslintConfigPrettier from 'eslint-config-prettier';
54
59
  import prettier from 'eslint-plugin-prettier';
55
60
  import type { FlatConfig } from 'typescript-eslint';
56
- import { DEFAULT_PROJECT_DIRS, layerBans, restrictedDynamicImports, restrictedImports } from './eslint-boundaries';
57
- import type { LayerBan } from './eslint-boundaries';
58
- import { SONARJS_RULES, TEST_RULES, TYPESCRIPT_RULES, UNICORN_RULES } from './eslint-rules';
61
+ import { DEFAULT_PROJECT_DIRS, layerBans, restrictedDynamicImports, restrictedImports } from './eslint-boundaries.ts';
62
+ import type { LayerBan } from './eslint-boundaries.ts';
63
+ import { SONARJS_RULES, TEST_RULES, TYPESCRIPT_RULES, UNICORN_RULES } from './eslint-rules.ts';
59
64
 
60
65
  /**
61
66
  * What `defineRepoLintConfig` accepts.
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { createPagesProxy } from './pages-proxy';
3
- import type { PagesProxyEnv } from './pages-proxy';
2
+ import { createPagesProxy } from './pages-proxy.ts';
3
+ import type { PagesProxyEnv } from './pages-proxy.ts';
4
4
 
5
5
  function fakeEnv(): { env: PagesProxyEnv; seen: { url: string; method: string; headers: Headers; body: string | null }[] } {
6
6
  const seen: { url: string; method: string; headers: Headers; body: string | null }[] = [];
@@ -25,7 +25,7 @@ const onRequest = createPagesProxy();
25
25
  describe('createPagesProxy', () => {
26
26
  it('forwards the URL verbatim and rewrites the three X-Forwarded headers', async () => {
27
27
  const { env, seen } = fakeEnv();
28
- const request = new Request('https://pages.example.com/user/volumes?page=2', { method: 'GET' });
28
+ const request = new Request('https://pages.example.com/user/volumes?page=2');
29
29
  const response = await onRequest({ request, env } as never);
30
30
  expect(response.status).toBe(200);
31
31
  expect(seen[0]?.url).toBe('https://pages.example.com/user/volumes?page=2');
@@ -115,7 +115,9 @@ const CLIENT_FORWARDING_HEADERS: readonly string[] = [
115
115
  'X-Real-Ip',
116
116
  ];
117
117
 
118
- /** The header Cloudflare sets with the socket's peer address. */
118
+ /**
119
+ The header Cloudflare sets with the socket's peer address.
120
+ */
119
121
  const CF_CONNECTING_IP_HEADER = 'CF-Connecting-IP';
120
122
 
121
123
  /**
@@ -180,7 +182,7 @@ export function createPagesProxy(options: PagesProxyOptions = {}): PagesFunction
180
182
  // worse answer than one assertion.
181
183
  ...(hasBody && { duplex: 'half' }),
182
184
  redirect: request.redirect,
183
- } as RequestInit);
185
+ });
184
186
 
185
187
  return env.API_WORKER.fetch(proxyRequest);
186
188
  };