@starci/eslint-canon-be 3.18.4 → 3.19.1

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 (211) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/comments.js +1 -1
  4. package/dist/explicit-surface.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/jwt-alg.js +1 -1
  7. package/dist/lib/edition.d.ts +1 -1
  8. package/dist/lib/edition.js +1 -1
  9. package/dist/lib/hfs-view.d.ts +5 -0
  10. package/dist/lib/hfs.d.ts +0 -6
  11. package/dist/lib/hfs.js +7 -5
  12. package/dist/lib/runtime-root.d.ts +6 -1
  13. package/dist/lib/runtime-root.js +8 -2
  14. package/dist/lib/subject-values.js +1 -1
  15. package/dist/module-layering.js +2 -2
  16. package/dist/project-graph.js +1 -1
  17. package/dist/schema-authority.js +66 -2
  18. package/dist/third-party-owner.js +1 -1
  19. package/package.json +3 -1
  20. package/runtime/bundle.json +1 -190
  21. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  22. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  23. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  24. package/runtime/config.example.yaml +0 -194
  25. package/runtime/engine/by-code-unit.mjs +0 -12
  26. package/runtime/engine/config.mjs +0 -461
  27. package/runtime/engine/invalid-config.mjs +0 -15
  28. package/runtime/engine/model-config.mjs +0 -112
  29. package/runtime/engine/orca-config.mjs +0 -34
  30. package/runtime/engine/plain-object.mjs +0 -5
  31. package/runtime/engine/release-config.mjs +0 -32
  32. package/runtime/engine/removed-vocabulary.mjs +0 -27
  33. package/runtime/engine/resources-config.mjs +0 -59
  34. package/runtime/engine/runtime-root.mjs +0 -138
  35. package/runtime/engine/secrets.mjs +0 -202
  36. package/runtime/engine/sonar-config.mjs +0 -24
  37. package/runtime/engine/temp-root.mjs +0 -26
  38. package/runtime/engine/yaml.mjs +0 -161
  39. package/runtime/knowledge/grammars/index.yaml +0 -114
  40. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  41. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  42. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  43. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  44. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  45. package/runtime/knowledge/sonar-gate.yaml +0 -151
  46. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  47. package/runtime/modules/models/registry.yaml +0 -221
  48. package/runtime/modules/models/runtimes.yaml +0 -556
  49. package/runtime/modules/models/tiers.yaml +0 -66
  50. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  51. package/runtime/scripts/api/git/config-get.mjs +0 -9
  52. package/runtime/scripts/api/git/diff.mjs +0 -4
  53. package/runtime/scripts/api/git/lib.mjs +0 -80
  54. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  55. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  56. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  57. package/runtime/scripts/api/git/remote.mjs +0 -4
  58. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  59. package/runtime/scripts/api/git/show.mjs +0 -5
  60. package/runtime/scripts/api/git/tag.mjs +0 -4
  61. package/runtime/scripts/hfs/allows.mjs +0 -77
  62. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  63. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  64. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  65. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  66. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  67. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  68. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  69. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  70. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  71. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  72. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  73. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  74. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  75. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  76. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  77. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  78. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  79. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  80. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  81. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  82. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  83. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  84. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  85. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  86. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  87. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  88. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  89. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  90. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  91. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  92. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  93. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  94. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  95. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  96. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  97. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  98. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  99. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  100. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  101. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  102. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  103. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  104. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  105. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  106. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  107. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  108. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  109. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  110. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  111. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  112. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  113. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  114. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  115. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  116. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  117. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  118. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  119. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  120. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  121. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  122. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  123. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  124. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  125. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  126. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  127. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  128. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  129. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  130. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  132. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  133. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  134. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  135. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  136. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  137. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  138. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  139. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  140. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  141. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  142. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  143. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  144. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  145. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  146. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  147. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  148. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  149. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  150. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  151. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  152. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  153. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  154. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  155. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  156. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  157. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  158. package/runtime/scripts/hfs/param-names.mjs +0 -13
  159. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  160. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  161. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  162. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  163. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  164. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  165. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  166. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  167. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  168. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  169. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  170. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  171. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  172. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  173. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  174. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  175. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  176. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  177. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  178. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  179. package/runtime/scripts/hfs/slots.mjs +0 -306
  180. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  181. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  182. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  183. package/runtime/scripts/hfs/view.mjs +0 -180
  184. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  185. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  186. package/runtime/scripts/lib/env.mjs +0 -18
  187. package/runtime/scripts/lib/event-contract.mjs +0 -102
  188. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  189. package/runtime/scripts/lib/git.mjs +0 -35
  190. package/runtime/scripts/lib/glob.mjs +0 -32
  191. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  192. package/runtime/scripts/lib/i18n.mjs +0 -82
  193. package/runtime/scripts/lib/in-order.mjs +0 -90
  194. package/runtime/scripts/lib/json-clone.mjs +0 -70
  195. package/runtime/scripts/lib/json.mjs +0 -44
  196. package/runtime/scripts/lib/language.mjs +0 -233
  197. package/runtime/scripts/lib/list.mjs +0 -26
  198. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  199. package/runtime/scripts/lib/package-at.mjs +0 -62
  200. package/runtime/scripts/lib/path-key.mjs +0 -124
  201. package/runtime/scripts/lib/read-text.mjs +0 -47
  202. package/runtime/scripts/lib/regex.mjs +0 -3
  203. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  204. package/runtime/scripts/lib/same-text.mjs +0 -4
  205. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  206. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  207. package/runtime/scripts/lib/stack-services.mjs +0 -191
  208. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  209. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  210. package/runtime/scripts/lib/walk.mjs +0 -45
  211. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,164 +0,0 @@
1
- // slot-match.mjs - the slot path patterns of the HFS manifest compiled to regular expressions, and the matching of a path against them:
2
- // the variants that match it, the most specific one, and the nearest slot of an unknown path. Pure; slot-classify.mjs asks it.
3
- import path from 'node:path';
4
- import { braceVariants } from '../lib/glob.mjs';
5
- import { captureNames } from '../lib/i18n.mjs';
6
- const VAR = /<([A-Za-z][A-Za-z0-9-]*)>/g;
7
- export const varsOf = (text) => captureNames(text, VAR);
8
- const hasWildcard = (segment) => /[*?]/.test(segment);
9
- /** `text` with the `<name>` variables filled from `bindings` (an unbound one stays as written). */
10
- export function fillVars(text, bindings) {
11
- const bound = (whole, name) => bindings[name] ?? whole;
12
- return `${text}`.replace(VAR, bound);
13
- }
14
- /** Weight of one pattern segment: literal 4, literal mixed with a variable 3, a bare variable 2, a wildcard 1, `**` 0. */
15
- function segmentWeight(segment) {
16
- if (segment === '**')
17
- return 0;
18
- if (hasWildcard(segment))
19
- return 1;
20
- if (/^<[^>]+>$/.test(segment))
21
- return 2;
22
- if (segment.includes('<'))
23
- return 3;
24
- return 4;
25
- }
26
- /** The RegExp source of one pattern segment (no separators); variables capture, and are listed in `names`. */
27
- function segmentSource(segment, names) {
28
- let source = '', variableEnd = -1;
29
- for (let i = 0; i < segment.length; i += 1) {
30
- const c = segment[i];
31
- if (i <= variableEnd)
32
- continue;
33
- if (c === '<') {
34
- variableEnd = segment.indexOf('>', i);
35
- names.push(segment.slice(i + 1, variableEnd));
36
- source += '([^/]+?)';
37
- }
38
- else if (c === '*')
39
- source += '[^/]*';
40
- else if (c === '?')
41
- source += '[^/]';
42
- else
43
- source += /[.+^${}()|[\]\\]/.test(c) ? `\\${c}` : c;
44
- }
45
- return source;
46
- }
47
- /** One brace-free pattern compiled: `dir` patterns (trailing /) own everything below their root. */
48
- export function compileVariant(slot, pattern) {
49
- const dir = pattern.endsWith('/');
50
- const body = dir ? pattern.slice(0, -1) : pattern;
51
- const segments = body.split('/');
52
- const names = [];
53
- let source = '';
54
- segments.forEach((segment, index) => {
55
- const last = index === segments.length - 1;
56
- if (segment === '**')
57
- source += last ? '.*' : '(?:.*/)?';
58
- else
59
- source += segmentSource(segment, names) + (last ? '' : '/');
60
- });
61
- return {
62
- slot,
63
- pattern,
64
- dir,
65
- segments,
66
- names,
67
- score: segments.reduce((sum, s) => sum + segmentWeight(s), 0),
68
- wildcards: segments.filter(hasWildcard).length,
69
- regex: new RegExp(`^(${source})${dir ? '(?:/.*)?' : ''}$`),
70
- segmentRegexes: segments.map((s) => (s === '**' ? null : new RegExp(`^${segmentSource(s, [])}$`))),
71
- };
72
- }
73
- export const variantsOf = (slot) => braceVariants(slot.path).map((pattern) => compileVariant(slot, pattern));
74
- const levenshtein = (a, b) => {
75
- const row = Array.from({ length: b.length + 1 }, (_, i) => i);
76
- for (let i = 1; i <= a.length; i += 1) {
77
- let prev = row[0];
78
- row[0] = i;
79
- for (let j = 1; j <= b.length; j += 1) {
80
- const held = row[j];
81
- row[j] = Math.min(row[j] + 1, row[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
82
- prev = held;
83
- }
84
- }
85
- return row[b.length];
86
- };
87
- /** The match of `p` against one variant: its slot, root and bindings, or null (not matching, filtered out, or an app-kind slot of another kind). */
88
- function matchVariant(variant, p, only, appKind) {
89
- if (only && !only(variant.slot))
90
- return null;
91
- const m = variant.regex.exec(p);
92
- if (!m)
93
- return null;
94
- const bindings = {};
95
- variant.names.forEach((name, i) => { bindings[name] = m[i + 2]; });
96
- if (variant.slot.appKind !== undefined && appKind.get(bindings.app) !== variant.slot.appKind)
97
- return null;
98
- const root = variant.dir ? m[1] : path.posix.dirname(m[1]);
99
- return { variant, slot: variant.slot, root: root === '.' ? '' : root, bindings };
100
- }
101
- /** Every variant matching `p`, with its root and bindings, minus app-kind slots of another kind, the most specific first. */
102
- export function matchVariants({ variants, appKind }, p, only) {
103
- const found = [];
104
- for (const variant of variants) {
105
- const hit = matchVariant(variant, p, only, appKind);
106
- if (hit)
107
- found.push(hit);
108
- }
109
- return found.sort((a, b) => b.variant.score - a.variant.score || a.variant.wildcards - b.variant.wildcards);
110
- }
111
- /** The single most specific match of a sorted list: {hit, ambiguous}; two slots of equal specificity are ambiguous. */
112
- export function bestMatch(found) {
113
- if (!found.length)
114
- return { hit: null, ambiguous: [] };
115
- const first = found[0];
116
- const top = found.filter((f) => f.variant.score === first.variant.score && f.variant.wildcards === first.variant.wildcards);
117
- const distinct = [...new Set(top.map((f) => f.slot.id))];
118
- return distinct.length > 1 ? { hit: null, ambiguous: distinct } : { hit: top[0], ambiguous: [] };
119
- }
120
- /** How many leading segments of `parts` a variant accepts. */
121
- function acceptedDepth(variant, parts) {
122
- let depth = 0;
123
- while (depth < parts.length && depth < variant.segments.length) {
124
- const rx = variant.segmentRegexes[depth];
125
- if (rx === null || !rx.test(parts[depth]))
126
- break;
127
- depth += 1;
128
- }
129
- return depth;
130
- }
131
- /** Whether `cand` is nearer to the path than `winner`: deeper, then closer in shape, then in spelling, then more specific. */
132
- function nearerCandidate(cand, winner) {
133
- if (!winner)
134
- return true;
135
- if (cand.depth !== winner.depth)
136
- return cand.depth > winner.depth;
137
- if (cand.shape !== winner.shape)
138
- return cand.shape < winner.shape;
139
- if (cand.distance !== winner.distance)
140
- return cand.distance < winner.distance;
141
- return cand.variant.score > winner.variant.score;
142
- }
143
- /** The leading segments of `p` a variant accepts, and how far it got; how the nearest slot of an unknown path is found. */
144
- export function nearestSlot(variants, p) {
145
- const parts = p.split('/');
146
- let winner = null;
147
- for (const variant of variants) {
148
- const depth = acceptedDepth(variant, parts);
149
- const expected = variant.segments[depth] ?? '';
150
- const distance = levenshtein(parts[depth] ?? '', expected.replace(VAR, ''));
151
- const cand = { variant, depth, shape: Math.abs(variant.segments.length - parts.length), distance };
152
- if (nearerCandidate(cand, winner))
153
- winner = cand;
154
- }
155
- if (!winner)
156
- return null;
157
- return {
158
- slot: winner.variant.slot.id,
159
- pattern: winner.variant.pattern,
160
- matchedDepth: winner.depth,
161
- matchedPrefix: parts.slice(0, winner.depth).join('/'),
162
- expectedNext: winner.variant.segments[winner.depth] ?? null,
163
- };
164
- }
@@ -1,6 +0,0 @@
1
- // slot-path.mjs - normalize a slot-relative path for resolver comparisons.
2
- import { posixPath } from '../lib/path-key.mjs';
3
- const SLASH = '/';
4
- const END = '$';
5
- const TRAILING_SLASHES = new RegExp(`${SLASH}+${END}`);
6
- export const cleanSlotPath = (value) => posixPath(value).replace(TRAILING_SLASHES, '');
@@ -1,95 +0,0 @@
1
- // slot-required.mjs - what a scope (the app root or one side) must contain, without walking it: the files an instance of a slot
2
- // requires, and the paths and minimum instance counts of every required slot. A scope is the one slots.mjs builds.
3
- import path from 'node:path';
4
- import { braceVariants } from '../lib/glob.mjs';
5
- import { classifyIn, slotEnabled } from './slot-classify.mjs';
6
- import { fillVars, varsOf } from './slot-match.mjs';
7
- /** A populated fe.modules instance needs its index.ts only when it contains TypeScript, including nested files. */
8
- export function requiredFileApplies(slotId, target, files) {
9
- if (!/^fe\.modules(?:\.|$)/u.test(slotId) || path.posix.basename(target) !== 'index.ts')
10
- return true;
11
- const prefix = `${path.posix.dirname(target)}/`;
12
- let populated = false;
13
- for (const file of files) {
14
- if (!file.startsWith(prefix))
15
- continue;
16
- populated = true;
17
- if (/\.tsx?$/u.test(file))
18
- return true;
19
- }
20
- return !populated;
21
- }
22
- /** One `requires` entry of a slot placed under `root`: a leading / makes it repository-relative, the variables are filled from `bindings`. */
23
- function requiredEntry(entry, bindings, root) {
24
- const rooted = entry.startsWith('/');
25
- const filled = fillVars(rooted ? entry.slice(1) : entry, bindings);
26
- return rooted || !root || root === '.' ? filled : `${root}/${filled}`;
27
- }
28
- /** The files and directories the instance holding `p` must contain (directories end with /); {path} entries are repo-relative. */
29
- export function requiredFilesIn(scope, input) {
30
- const c = classifyIn(scope, input);
31
- if (!c.slot)
32
- return [];
33
- const slot = scope.byId.get(c.slot);
34
- return (slot.requires ?? []).map((entry) => requiredEntry(entry, c.bindings, c.root));
35
- }
36
- function growBindings(combos, name, values) {
37
- const next = [];
38
- for (const combo of combos) {
39
- for (const value of values)
40
- next.push({ ...combo, [name]: value });
41
- }
42
- combos.splice(0, combos.length, ...next);
43
- }
44
- const expandApps = (repo, slot) => repo.apps.filter((a) => slot.appKind === undefined || a.kind === slot.appKind);
45
- function appendRequiredVariantPaths(repo, slot, variant, paths) {
46
- const names = [...new Set(varsOf(variant))];
47
- const fixed = { ...slot.requiredInstances };
48
- const open = names.filter((name) => name !== 'app' && !(name in fixed));
49
- if (open.length)
50
- return;
51
- const combos = [{}];
52
- if (names.includes('app'))
53
- growBindings(combos, 'app', expandApps(repo, slot).map((app) => app.name));
54
- for (const [name, values] of Object.entries(fixed))
55
- growBindings(combos, name, values);
56
- const isInstance = names.length > 0;
57
- for (const bindings of combos) {
58
- const target = fillVars(variant, bindings);
59
- paths.push({ slot: slot.id, path: target, via: isInstance ? 'instance' : 'slot' });
60
- const root = target.endsWith('/') ? target.slice(0, -1) : path.posix.dirname(target);
61
- for (const entry of slot.requires ?? [])
62
- paths.push({ slot: slot.id, path: requiredEntry(entry, bindings, root), via: 'requires' });
63
- }
64
- }
65
- function appendRequiredSlotPaths(scope, slot, paths, minimums) {
66
- if (slot.presence !== 'required' || !slotEnabled(scope, slot))
67
- return;
68
- if (slot.requiredWhen === 'connections' && !scope.repo.connections.length)
69
- return;
70
- if (slot.minInstances)
71
- minimums.push({ slot: slot.id, min: slot.minInstances, ...(slot.appKind ? { appKind: slot.appKind } : {}) });
72
- for (const variant of braceVariants(slot.path))
73
- appendRequiredVariantPaths(scope.repo, slot, variant, paths);
74
- }
75
- function uniqueRequiredPaths(paths) {
76
- const seen = new Set();
77
- return paths.filter((entry) => {
78
- const key = `${entry.slot}|${entry.path}`;
79
- if (seen.has(key))
80
- return false;
81
- seen.add(key);
82
- return true;
83
- });
84
- }
85
- /**
86
- * What the repository must contain, without walking it: {paths: [{slot, path, via}], minimums: [{slot, min}]}.
87
- * via is slot (a fixed path), instance (a requiredInstances or app-kind root) or requires (a file an instance needs).
88
- */
89
- export function requiredPathsIn(scope) {
90
- const paths = [];
91
- const minimums = [];
92
- for (const slot of scope.slots)
93
- appendRequiredSlotPaths(scope, slot, paths, minimums);
94
- return { paths: uniqueRequiredPaths(paths), minimums };
95
- }
@@ -1,175 +0,0 @@
1
- // slot-semantic-problems.mjs - semantic checks for the HFS slot manifest.
2
- import { isPlainObject } from '../../engine/plain-object.mjs';
3
- import { triggerProblems } from './declaration-slots.mjs';
4
- import { litePresenceOf, slotInEdition } from './edition-slots.mjs';
5
- import { manifestKind, RUNTIME_KIND, runtimeSemanticProblems, tierKindProblems } from './manifest-shape.mjs';
6
- import { APP_SCOPE, isSide, PROFILES } from './slot-manifest-shape.mjs';
7
- function checkAppRootSlot(slot, bad) {
8
- for (const key of ['appKind', 'owner', 'layers', 'kinds', 'composedBy', 'requiredWhen', 'requiredInstances']) {
9
- if (slot[key] !== undefined)
10
- bad.push(`slot ${slot.id}: an app-root slot has no ${key}`);
11
- }
12
- if (slot.tier !== 'none')
13
- bad.push(`slot ${slot.id}: an app-root slot has tier none`);
14
- }
15
- function checkSideSlot(slot, profile, manifest, bad) {
16
- const tiers = manifest.tiers[profile];
17
- if (slot.tier !== 'none' && slot.tier !== 'inherit' && !(slot.tier in tiers))
18
- bad.push(`slot ${slot.id}: tier ${slot.tier} is not a ${profile} tier`);
19
- if (slot.appKind !== undefined && !manifest.appKinds[profile].includes(slot.appKind))
20
- bad.push(`slot ${slot.id}: app kind ${slot.appKind} is not a ${profile} kind`);
21
- bad.push(...triggerProblems(slot, manifest.triggerKinds));
22
- }
23
- function claimSlotPatterns(slot, profile, claimed, bad, braceVariants) {
24
- if (slot.appKind !== undefined)
25
- return;
26
- for (const variant of braceVariants(slot.path)) {
27
- const key = `${profile}:${variant}`;
28
- if (claimed.has(key))
29
- bad.push(`slots ${claimed.get(key)} and ${slot.id} claim the same pattern ${variant} on ${profile}`);
30
- else
31
- claimed.set(key, slot.id);
32
- }
33
- }
34
- function checkSlotProfiles(slot, manifest, claimed, bad, braceVariants) {
35
- for (const profile of slot.profiles) {
36
- if (profile === APP_SCOPE)
37
- checkAppRootSlot(slot, bad);
38
- else
39
- checkSideSlot(slot, profile, manifest, bad);
40
- claimSlotPatterns(slot, profile, claimed, bad, braceVariants);
41
- }
42
- }
43
- function checkLitePath(slot, pathVars, varsOf, bad, braceVariants, compileVariant) {
44
- if (slot.lite?.path === undefined)
45
- return;
46
- for (const name of varsOf(slot.lite.path))
47
- if (!pathVars.has(name))
48
- bad.push(`slot ${slot.id}: lite.path binds <${name}>, which the path does not`);
49
- for (const variant of braceVariants(slot.lite.path)) {
50
- try {
51
- compileVariant(slot, variant);
52
- }
53
- catch (error) {
54
- bad.push(`slot ${slot.id}: lite.path ${variant} does not compile (${error.message})`);
55
- }
56
- }
57
- }
58
- function checkNamedPathBindings(slot, pathVars, varsOf, bad) {
59
- for (const name of Object.keys(slot.requiredInstances ?? {})) {
60
- if (!pathVars.has(name))
61
- bad.push(`slot ${slot.id}: requiredInstances names <${name}>, which the path does not bind`);
62
- }
63
- for (const file of Object.values(slot.roles ?? {})) {
64
- for (const name of varsOf(file))
65
- if (!pathVars.has(name))
66
- bad.push(`slot ${slot.id}: roles names <${name}> in ${file}, which the path does not bind`);
67
- }
68
- for (const entry of slot.requires ?? []) {
69
- for (const name of varsOf(entry))
70
- if (!pathVars.has(name))
71
- bad.push(`slot ${slot.id}: requires ${entry} uses <${name}>, which the path does not bind`);
72
- }
73
- }
74
- function checkSlotPatternCompilation(slot, bad, braceVariants, compileVariant) {
75
- for (const variant of braceVariants(slot.path)) {
76
- try {
77
- compileVariant(slot, variant);
78
- }
79
- catch (error) {
80
- bad.push(`slot ${slot.id}: pattern ${variant} does not compile (${error.message})`);
81
- }
82
- }
83
- }
84
- function checkSlotComposition(slot, manifest, bad) {
85
- for (const kind of slot.composedBy ?? []) {
86
- if (!slot.profiles.every((profile) => manifest.appKinds[profile].includes(kind)))
87
- bad.push(`slot ${slot.id}: composedBy names ${kind}, which is not an app kind of every profile of the slot`);
88
- }
89
- if (slot.layers !== undefined && slot.tier !== 'none' && !slot.profiles.every((profile) => manifest.tiers[profile][slot.tier]?.lowerLayerOnly))
90
- bad.push(`slot ${slot.id}: layers need a lowerLayerOnly tier`);
91
- }
92
- function checkLiteDeclaration(slot, manifest, bad) {
93
- if (!slotInEdition(manifest, slot, 'lite') && (slot.litePresence !== undefined || slot.lite !== undefined))
94
- bad.push(`slot ${slot.id}: litePresence/lite on a slot lite never sees (editions)`);
95
- if (isPlainObject(slot.litePresence) && slot.profiles.includes(APP_SCOPE))
96
- bad.push(`slot ${slot.id}: an app-root slot takes a bare litePresence, not a per-side map`);
97
- for (const profile of slot.profiles) {
98
- if (litePresenceOf(slot, profile) === 'forbidden' && typeof slot.goesTo !== 'string')
99
- bad.push(`slot ${slot.id}: forbidden in lite for ${profile}, so it says where the content goes (goesTo)`);
100
- }
101
- }
102
- function checkSlotSemantics(slot, manifest, claimed, bad, helpers) {
103
- if (claimed.ids.has(slot.id))
104
- bad.push(`slot id ${slot.id} appears twice`);
105
- claimed.ids.add(slot.id);
106
- const pathVars = new Set(helpers.varsOf(slot.path));
107
- checkSlotProfiles(slot, manifest, claimed.patterns, bad, helpers.braceVariants);
108
- if (slot.appKind !== undefined && !pathVars.has('app'))
109
- bad.push(`slot ${slot.id}: an app-kind slot binds <app> in its path`);
110
- if (slot.requiredWhen !== undefined && slot.presence !== 'required')
111
- bad.push(`slot ${slot.id}: requiredWhen belongs to a required slot`);
112
- checkLiteDeclaration(slot, manifest, bad);
113
- checkLitePath(slot, pathVars, helpers.varsOf, bad, helpers.braceVariants, helpers.compileVariant);
114
- checkNamedPathBindings(slot, pathVars, helpers.varsOf, bad);
115
- checkSlotPatternCompilation(slot, bad, helpers.braceVariants, helpers.compileVariant);
116
- checkSlotComposition(slot, manifest, bad);
117
- }
118
- /** The problem of one declared side read, or null when a slot of the side it names (or of the app root) owns the path. */
119
- function sideReadProblem(manifest, side, read, braceVariants) {
120
- const [owner, ...rest] = read.split('/');
121
- if (owner === side)
122
- return `sides.${side}.reads names ${read}, which is its own side`;
123
- const ownedBySide = isSide(owner);
124
- const profile = ownedBySide ? owner : APP_SCOPE;
125
- const prefix = ownedBySide ? rest.join('/') : read;
126
- const owned = manifest.slots.some((slot) => slot.profiles.includes(profile) && slot.presence !== 'forbidden' && braceVariants(slot.path).some((variant) => variant.startsWith(prefix)));
127
- const ownerName = ownedBySide ? owner : 'app-root';
128
- return owned ? null : `sides.${side}.reads names ${read}, which no ${ownerName} slot owns`;
129
- }
130
- function checkSideReads(manifest, bad, braceVariants) {
131
- for (const side of PROFILES) {
132
- for (const read of manifest.sides[side].reads) {
133
- const problem = sideReadProblem(manifest, side, read, braceVariants);
134
- if (problem)
135
- bad.push(problem);
136
- }
137
- }
138
- }
139
- function checkProfileTierTargets(manifest, profile, bad) {
140
- bad.push(...tierKindProblems(manifest, profile));
141
- for (const [tier, def] of Object.entries(manifest.tiers[profile])) {
142
- for (const target of def.mayImport) {
143
- if (!(target in manifest.tiers[profile]))
144
- bad.push(`tiers.${profile}.${tier}.mayImport names ${target}, which is not a ${profile} tier`);
145
- }
146
- }
147
- }
148
- function checkProfileAppKinds(manifest, profile, bad) {
149
- for (const kind of manifest.appKinds[profile]) {
150
- const owners = manifest.slots.filter((slot) => slot.profiles.includes(profile) && slot.appKind === kind);
151
- if (owners.length !== 1)
152
- bad.push(`${profile} app kind ${kind} must have exactly one slot (found ${owners.length})`);
153
- }
154
- }
155
- function checkProfileMaps(manifest, bad) {
156
- for (const profile of PROFILES) {
157
- checkProfileTierTargets(manifest, profile, bad);
158
- checkProfileAppKinds(manifest, profile, bad);
159
- }
160
- }
161
- /** The rules a JSON Schema cannot state: unique ids, tiers named and reachable, app kinds, variables, no duplicate pattern. */
162
- export function manifestSemanticProblems(manifest, helpers) {
163
- const bad = [];
164
- const claimed = { ids: new Set(), patterns: new Map() };
165
- for (const slot of manifest.slots)
166
- checkSlotSemantics(slot, manifest, claimed, bad, helpers);
167
- if (manifestKind(manifest) === RUNTIME_KIND)
168
- return [...bad, ...runtimeSemanticProblems(manifest)];
169
- checkSideReads(manifest, bad, helpers.braceVariants);
170
- checkProfileMaps(manifest, bad);
171
- const major = Number(manifest.version.split('.')[0]);
172
- if (String(manifest.schema) !== `starci/hfs-slots@${major}`)
173
- bad.push(`schema ${manifest.schema} does not carry the major of version ${manifest.version}`);
174
- return bad;
175
- }
@@ -1,32 +0,0 @@
1
- // slot-side-problems.mjs - declaration checks for one app side against the HFS manifest.
2
- import { backingProblems, optionalSlotProblems } from './declaration-slots.mjs';
3
- function sideAppKindProblems(manifest, side, apps) {
4
- const bad = [];
5
- for (const app of apps)
6
- if (!manifest.appKinds[side].includes(app.kind))
7
- bad.push(`${side} app ${app.name} has kind ${app.kind}, which is not a ${side} kind (${manifest.appKinds[side].join(', ')})`);
8
- return bad;
9
- }
10
- function requiredAppKindProblems(manifest, side, declaration) {
11
- const bad = [];
12
- const connections = declaration.connections ?? [];
13
- for (const slot of manifest.slots) {
14
- if (slot.appKind === undefined || !slot.profiles.includes(side) || slot.presence !== 'required')
15
- continue;
16
- if (slot.requiredWhen === 'connections' && !connections.length)
17
- continue;
18
- if (!declaration.apps.some((app) => app.kind === slot.appKind))
19
- bad.push(`no ${side} app of kind ${slot.appKind} is declared (${slot.id} is required${slot.requiredWhen ? ' once a connection is declared' : ''})`);
20
- }
21
- return bad;
22
- }
23
- /** Problems for one side declaration, preserving the manifest's checks and their order. */
24
- export function sideProblems(manifest, side, declaration, edition = 'full') {
25
- const bad = sideAppKindProblems(manifest, side, declaration.apps);
26
- bad.push(...optionalSlotProblems(manifest, side, declaration), ...backingProblems(manifest, side, declaration, edition));
27
- for (const read of declaration.reads ?? [])
28
- if (!manifest.sides[side].reads.includes(read))
29
- bad.push(`sides.${side}.reads names ${read}; ${side} may read only ${manifest.sides[side].reads.join(', ') || 'nothing of the other side'}`);
30
- bad.push(...requiredAppKindProblems(manifest, side, declaration));
31
- return bad;
32
- }