@starci/eslint-canon-be 3.8.19 → 3.9.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 (164) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -5,186 +5,189 @@ import { readJsonFile as readJson } from '../../lib/json.mjs';
5
5
  import { exportTargetStrings, isUnshadowedCommonJsRequire, relativePath } from './typescript.mjs';
6
6
  import { byCodeUnit } from '../../lib/list.mjs';
7
7
  import { sameOrUnder } from '../../lib/path-key.mjs';
8
-
9
8
  function grammarExport(manifest, packageName, specifier) {
10
- const key = specifier === packageName ? '.' : `.${specifier.slice(packageName.length)}`;
11
- const value = manifest?.exports?.[key];
12
- const targets = exportTargetStrings(value);
13
- return targets.length > 0 && targets.every(target => target.startsWith('./') && !target.includes('\\') && !target.split('/').includes('..'));
9
+ const key = specifier === packageName ? '.' : `.${specifier.slice(packageName.length)}`;
10
+ const value = manifest?.exports?.[key];
11
+ const targets = exportTargetStrings(value);
12
+ return targets.length > 0 && targets.every(target => target.startsWith('./') && !target.includes('\\') && !target.split('/').includes('..'));
14
13
  }
15
-
16
14
  function grammarExportTargets(manifest, packageRoot, packageName, specifier) {
17
- const key = specifier === packageName ? '.' : `.${specifier.slice(packageName.length)}`;
18
- return exportTargetStrings(manifest?.exports?.[key]).filter(target => target.startsWith('./') && !target.includes('\\') && !target.split('/').includes('..'))
19
- .map(target => canonical(path.resolve(packageRoot, target)));
15
+ const key = specifier === packageName ? '.' : `.${specifier.slice(packageName.length)}`;
16
+ return exportTargetStrings(manifest?.exports?.[key]).filter(target => target.startsWith('./') && !target.includes('\\') && !target.split('/').includes('..'))
17
+ .map(target => canonical(path.resolve(packageRoot, target)));
20
18
  }
21
-
22
19
  function literalModules(ts, sourceFile, checker) {
23
- const modules = [];
24
- const visit = node => {
25
- if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) {
26
- modules.push({ node: node.moduleSpecifier, specifier: node.moduleSpecifier.text });
27
- } else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
28
- && node.moduleReference.expression && ts.isStringLiteralLike(node.moduleReference.expression)) {
29
- modules.push({ node: node.moduleReference.expression, specifier: node.moduleReference.expression.text });
30
- } else if (ts.isCallExpression(node) && node.arguments.length > 0 && ts.isStringLiteralLike(node.arguments[0])
31
- && (node.expression.kind === ts.SyntaxKind.ImportKeyword || isUnshadowedCommonJsRequire(ts, checker, node.expression))) {
32
- modules.push({ node: node.arguments[0], specifier: node.arguments[0].text });
33
- }
34
- ts.forEachChild(node, visit);
35
- };
36
- visit(sourceFile);
37
- return modules;
20
+ const modules = [];
21
+ const visit = (node) => {
22
+ if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) {
23
+ modules.push({ node: node.moduleSpecifier, specifier: node.moduleSpecifier.text });
24
+ }
25
+ else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
26
+ && node.moduleReference.expression && ts.isStringLiteralLike(node.moduleReference.expression)) {
27
+ modules.push({ node: node.moduleReference.expression, specifier: node.moduleReference.expression.text });
28
+ }
29
+ else if (ts.isCallExpression(node) && node.arguments.length > 0 && node.arguments[0] !== undefined && ts.isStringLiteralLike(node.arguments[0])
30
+ && (node.expression.kind === ts.SyntaxKind.ImportKeyword || isUnshadowedCommonJsRequire(ts, checker, node.expression))) {
31
+ modules.push({ node: node.arguments[0], specifier: node.arguments[0].text });
32
+ }
33
+ ts.forEachChild(node, visit);
34
+ };
35
+ visit(sourceFile);
36
+ return modules;
38
37
  }
39
-
40
38
  function cssImports(content) {
41
- const imports = [];
42
- const withoutComments = content.replace(/\/\*[\s\S]*?\*\//g, match => match.replace(/[^\r\n]/g, ' '));
43
- const pattern = new RegExp([String.raw`@import\s+(?:url\(\s*(?:(["'])`, String.raw`(.*?)\1|([^\s)]+))\s*\)|(["'])(.*?)\4)`].join(''), 'gi');
44
- for (const match of withoutComments.matchAll(pattern)) {
45
- imports.push({ specifier: match[2] ?? match[3] ?? match[5], index: match.index });
46
- }
47
- return imports;
48
- }
49
-
39
+ const imports = [];
40
+ const withoutComments = content.replace(/\/\*[\s\S]*?\*\//g, match => match.replace(/[^\r\n]/g, ' '));
41
+ const pattern = new RegExp([String.raw `@import\s+(?:url\(\s*(?:(["'])`, String.raw `(.*?)\1|([^\s)]+))\s*\)|(["'])(.*?)\4)`].join(''), 'gi');
42
+ for (const match of withoutComments.matchAll(pattern)) {
43
+ const specifier = match[2] ?? match[3] ?? match[5];
44
+ if (specifier === undefined || match.index === undefined)
45
+ continue; // one alternative of the pattern always matches
46
+ imports.push({ specifier, index: match.index });
47
+ }
48
+ return imports;
49
+ }
50
50
  function installRootFor(config) {
51
- return config.packageRoot ?? config.root;
51
+ return config.packageRoot ?? config.root;
52
52
  }
53
-
54
53
  function installedPackageRoot(installRoot, packageName, from) {
55
- for (let dir = from; isInside(installRoot, dir); dir = path.dirname(dir)) {
56
- const candidate = path.join(dir, 'node_modules', ...packageName.split('/'));
57
- if (fs.existsSync(path.join(candidate, 'package.json'))) return candidate;
58
- if (dir === installRoot || path.dirname(dir) === dir) break;
59
- }
60
- return path.join(installRoot, 'node_modules', ...packageName.split('/'));
61
- }
62
-
54
+ for (let dir = from; isInside(installRoot, dir); dir = path.dirname(dir)) {
55
+ const candidate = path.join(dir, 'node_modules', ...packageName.split('/'));
56
+ if (fs.existsSync(path.join(candidate, 'package.json')))
57
+ return candidate;
58
+ if (dir === installRoot || path.dirname(dir) === dir)
59
+ break;
60
+ }
61
+ return path.join(installRoot, 'node_modules', ...packageName.split('/'));
62
+ }
63
63
  function grammarConsumers(config, grammar, local, installRoot) {
64
- return grammar.consumerManifests.map(relative => {
65
- const root = path.dirname(path.join(config.root, ...relative.split('/')));
66
- const packageRoot = local?.root ?? installedPackageRoot(installRoot, grammar.package, root);
67
- return { relative, root, packageRoot, packageManifest: readJson(path.join(packageRoot, 'package.json')),
68
- manifest: readJson(path.join(config.root, ...relative.split('/'))) ?? {} };
69
- });
70
- }
71
-
64
+ return grammar.consumerManifests.map((relative) => {
65
+ const root = path.dirname(path.join(config.root, ...relative.split('/')));
66
+ const packageRoot = local?.root ?? installedPackageRoot(installRoot, grammar.package, root);
67
+ return { relative, root, packageRoot, packageManifest: readJson(path.join(packageRoot, 'package.json')),
68
+ manifest: readJson(path.join(config.root, ...relative.split('/'))) ?? {} };
69
+ });
70
+ }
72
71
  function uniqueGrammarInstalls(consumers) {
73
- return [...new Map(consumers.map(consumer => [consumer.packageRoot, consumer])).values()];
72
+ return [...new Map(consumers.map((consumer) => [consumer.packageRoot, consumer])).values()];
74
73
  }
75
-
76
74
  function grammarPackageRoot(installs, local, installRoot, packageName) {
77
- return installs[0]?.packageRoot ?? local?.root ?? path.join(installRoot, 'node_modules', ...packageName.split('/'));
75
+ return installs[0]?.packageRoot ?? local?.root ?? path.join(installRoot, 'node_modules', ...packageName.split('/'));
78
76
  }
79
-
80
77
  function addInstallContractProblems(install, installs, grammar, configRoot, problems) {
81
- const where = installs.length > 1 ? ` (as ${install.relative} resolves it, ${relativePath(configRoot, install.packageRoot)})` : '';
82
- if (install.packageManifest?.name !== grammar.package) problems.push(`installed package ${grammar.package} is unavailable or has a different name${where}`);
83
- if (!grammarExport(install.packageManifest, grammar.package, grammar.entry)) problems.push(`${grammar.entry} is not a safe declared package export${where}`);
84
- if (!grammarExport(install.packageManifest, grammar.package, grammar.styleEntry)) problems.push(`${grammar.styleEntry} is not a safe declared style export${where}`);
85
- const actualPeers = Object.keys(install.packageManifest?.peerDependencies ?? {}).sort(byCodeUnit);
86
- const selectedPeers = [...grammar.peers].sort(byCodeUnit);
87
- if (JSON.stringify(actualPeers) !== JSON.stringify(selectedPeers)) {
88
- problems.push(`${grammar.package} peerDependencies must exactly match the selected peers ${selectedPeers.join(', ')}${where}`);
89
- }
90
- }
91
-
78
+ const where = installs.length > 1 ? ` (as ${install.relative} resolves it, ${relativePath(configRoot, install.packageRoot)})` : '';
79
+ if (install.packageManifest?.name !== grammar.package)
80
+ problems.push(`installed package ${grammar.package} is unavailable or has a different name${where}`);
81
+ if (!grammarExport(install.packageManifest, grammar.package, grammar.entry))
82
+ problems.push(`${grammar.entry} is not a safe declared package export${where}`);
83
+ if (!grammarExport(install.packageManifest, grammar.package, grammar.styleEntry))
84
+ problems.push(`${grammar.styleEntry} is not a safe declared style export${where}`);
85
+ const actualPeers = Object.keys(install.packageManifest?.peerDependencies ?? {}).sort(byCodeUnit);
86
+ const selectedPeers = [...grammar.peers].sort(byCodeUnit);
87
+ if (JSON.stringify(actualPeers) !== JSON.stringify(selectedPeers)) {
88
+ problems.push(`${grammar.package} peerDependencies must exactly match the selected peers ${selectedPeers.join(', ')}${where}`);
89
+ }
90
+ }
92
91
  function addConsumerDependencyProblems(grammar, consumers, problems) {
93
- for (const consumer of consumers) if (!Object.hasOwn(consumer.manifest.dependencies ?? {}, grammar.package)) {
94
- problems.push(`${consumer.relative} does not declare ${grammar.package} as a runtime dependency`);
95
- }
96
- for (const peer of grammar.peers) {
97
- for (const consumer of consumers) if (!Object.hasOwn(consumer.manifest.dependencies ?? {}, peer) && !Object.hasOwn(consumer.manifest.peerDependencies ?? {}, peer)) {
98
- problems.push(`${consumer.relative} does not declare Grammar peer ${peer}`);
92
+ for (const consumer of consumers)
93
+ if (!Object.hasOwn(consumer.manifest.dependencies ?? {}, grammar.package)) {
94
+ problems.push(`${consumer.relative} does not declare ${grammar.package} as a runtime dependency`);
95
+ }
96
+ for (const peer of grammar.peers) {
97
+ for (const consumer of consumers)
98
+ if (!Object.hasOwn(consumer.manifest.dependencies ?? {}, peer) && !Object.hasOwn(consumer.manifest.peerDependencies ?? {}, peer)) {
99
+ problems.push(`${consumer.relative} does not declare Grammar peer ${peer}`);
100
+ }
99
101
  }
100
- }
101
102
  }
102
-
103
103
  function addGrammarStyleProblems(config, grammar, problems, styleBypasses) {
104
- for (const source of grammar.styleSources) {
105
- const content = fs.readFileSync(path.join(config.root, ...source.split('/')), 'utf8');
106
- const grammarStyles = cssImports(content).filter(item => item.specifier === grammar.package || item.specifier.startsWith(`${grammar.package}/`));
107
- if (!grammarStyles.some(item => item.specifier === grammar.styleEntry)) problems.push(`${source} does not import ${grammar.styleEntry}`);
108
- for (const imported of grammarStyles) if (imported.specifier !== grammar.styleEntry) {
109
- problems.push(`${source} imports Grammar style ${imported.specifier} outside the selected style entry`);
110
- styleBypasses.push({ ruleId: 'ARCH_GRAMMAR_EXPORT_BYPASS', path: source,
111
- line: content.slice(0, imported.index).split(/\r?\n/u).length, column: 1, package: grammar.package, specifier: imported.specifier,
112
- message: `Style source must use the selected Grammar style entry ${grammar.styleEntry}; ${imported.specifier} is outside that contract.` });
104
+ for (const source of grammar.styleSources) {
105
+ const content = fs.readFileSync(path.join(config.root, ...source.split('/')), 'utf8');
106
+ const grammarStyles = cssImports(content).filter(item => item.specifier === grammar.package || item.specifier.startsWith(`${grammar.package}/`));
107
+ if (!grammarStyles.some(item => item.specifier === grammar.styleEntry))
108
+ problems.push(`${source} does not import ${grammar.styleEntry}`);
109
+ for (const imported of grammarStyles)
110
+ if (imported.specifier !== grammar.styleEntry) {
111
+ problems.push(`${source} imports Grammar style ${imported.specifier} outside the selected style entry`);
112
+ styleBypasses.push({ ruleId: 'ARCH_GRAMMAR_EXPORT_BYPASS', path: source,
113
+ line: content.slice(0, imported.index).split(/\r?\n/u).length, column: 1, package: grammar.package, specifier: imported.specifier,
114
+ message: `Style source must use the selected Grammar style entry ${grammar.styleEntry}; ${imported.specifier} is outside that contract.` });
115
+ }
113
116
  }
114
- }
115
117
  }
116
-
117
118
  function grammarOwner(consumers, fileName) {
118
- return consumers.filter(consumer => isInside(consumer.root, fileName))
119
- .sort((a, b) => b.root.length - a.root.length)[0] ?? null;
119
+ return consumers.filter(consumer => isInside(consumer.root, fileName))
120
+ .sort((a, b) => b.root.length - a.root.length)[0] ?? null;
120
121
  }
121
-
122
122
  function sourceEdges(context, sourceFile) {
123
- return new Map((context.edges.get(path.resolve(sourceFile.fileName)) ?? []).map(edge => [edge.node.getStart(sourceFile), edge]));
123
+ return new Map((context.edges.get(path.resolve(sourceFile.fileName)) ?? []).map((edge) => [edge.node.getStart(sourceFile), edge]));
124
124
  }
125
-
126
125
  function grammarReferenceAllowed(reference, sourceFile, owner, edgesByStart, grammar, allowed) {
127
- if (!allowed.has(reference.specifier)) return false;
128
- const edge = edgesByStart.get(reference.node.getStart(sourceFile));
129
- const expected = grammarExportTargets(owner.packageManifest, owner.packageRoot, grammar.package, reference.specifier);
130
- return !edge || expected.includes(canonical(edge.to));
126
+ if (!allowed.has(reference.specifier))
127
+ return false;
128
+ const edge = edgesByStart.get(reference.node.getStart(sourceFile));
129
+ const expected = grammarExportTargets(owner.packageManifest, owner.packageRoot, grammar.package, reference.specifier);
130
+ return !edge || expected.includes(canonical(edge.to));
131
131
  }
132
-
133
132
  function reportGrammarReference(scan, sourceFile, reference, owner, edgesByStart) {
134
- const { config, grammar, allowed, violations, makeViolation } = scan;
135
- if (!sameOrUnder(reference.specifier, grammar.package)) return;
136
- if (grammarReferenceAllowed(reference, sourceFile, owner, edgesByStart, grammar, allowed)) return;
137
- violations.push(makeViolation(config, sourceFile, reference.node, 'ARCH_GRAMMAR_EXPORT_BYPASS',
138
- `Product source must import the selected Grammar code entry ${grammar.entry} or style entry ${grammar.styleEntry}; ${reference.specifier} is outside that contract.`,
139
- { specifier: reference.specifier, package: grammar.package }));
140
- }
141
-
133
+ const { config, grammar, allowed, violations, makeViolation } = scan;
134
+ if (!sameOrUnder(reference.specifier, grammar.package))
135
+ return;
136
+ if (grammarReferenceAllowed(reference, sourceFile, owner, edgesByStart, grammar, allowed))
137
+ return;
138
+ violations.push(makeViolation(config, sourceFile, reference.node, 'ARCH_GRAMMAR_EXPORT_BYPASS', `Product source must import the selected Grammar code entry ${grammar.entry} or style entry ${grammar.styleEntry}; ${reference.specifier} is outside that contract.`, { specifier: reference.specifier, package: grammar.package }));
139
+ }
142
140
  function inspectGrammarSource(scan, sourceFile) {
143
- const { context, consumers, installs } = scan;
144
- if (installs.some(install => isInside(install.packageRoot, sourceFile.fileName))) return;
145
- const owner = grammarOwner(consumers, sourceFile.fileName);
146
- if (!owner) return;
147
- const edgesByStart = sourceEdges(context, sourceFile);
148
- const references = literalModules(context.ts, sourceFile, context.checkerFor(sourceFile.fileName));
149
- for (const reference of references) reportGrammarReference(scan, sourceFile, reference, owner, edgesByStart);
150
- }
151
-
141
+ const { context, consumers, installs } = scan;
142
+ if (installs.some(install => isInside(install.packageRoot, sourceFile.fileName)))
143
+ return;
144
+ const owner = grammarOwner(consumers, sourceFile.fileName);
145
+ if (!owner)
146
+ return;
147
+ const edgesByStart = sourceEdges(context, sourceFile);
148
+ const references = literalModules(context.ts, sourceFile, context.checkerFor(sourceFile.fileName));
149
+ for (const reference of references)
150
+ reportGrammarReference(scan, sourceFile, reference, owner, edgesByStart);
151
+ }
152
152
  function addGrammarContractFinding(config, grammar, manifestFile, problems, violations) {
153
- if (!problems.length) return;
154
- violations.push({
155
- ruleId: 'ARCH_GRAMMAR_CONTRACT_INVALID',
156
- path: fs.existsSync(manifestFile) && isInside(config.root, manifestFile) ? relativePath(config.root, manifestFile) : 'package.json',
157
- line: 1,
158
- column: 1,
159
- package: grammar.package,
160
- message: `Grammar contract is invalid: ${problems.join('; ')}.`,
161
- });
162
- }
163
-
153
+ if (!problems.length)
154
+ return;
155
+ violations.push({
156
+ ruleId: 'ARCH_GRAMMAR_CONTRACT_INVALID',
157
+ path: fs.existsSync(manifestFile) && isInside(config.root, manifestFile) ? relativePath(config.root, manifestFile) : 'package.json',
158
+ line: 1,
159
+ column: 1,
160
+ package: grammar.package,
161
+ message: `Grammar contract is invalid: ${problems.join('; ')}.`,
162
+ });
163
+ }
164
164
  export function checkGrammar(config, context, makeViolation) {
165
- const grammar = config.frontend.grammar;
166
- if (!grammar) return [];
167
- const violations = [];
168
- const local = context.workspaces.find(workspace => workspace.name === grammar.package);
169
- // Node resolution per consumer: in an npm-workspaces monorepo a consumer whose range differs from the
170
- // hoisted copy gets its own apps/<app>/node_modules/<package> (one consumer: apps/app on 0.5.0 beside a hoisted
171
- // 0.4.11). Every consumer is judged against the copy it actually resolves, never the hoisted one alone.
172
- // An app installs once, at its root (config.packageRoot): a side folder has no node_modules of its own.
173
- const installRoot = installRootFor(config);
174
- const consumers = grammarConsumers(config, grammar, local, installRoot);
175
- const installs = uniqueGrammarInstalls(consumers);
176
- const packageRoot = grammarPackageRoot(installs, local, installRoot, grammar.package);
177
- const manifestFile = path.join(packageRoot, 'package.json');
178
- readJson(manifestFile);
179
- const contractProblems = [];
180
- const styleBypasses = [];
181
- for (const install of installs) addInstallContractProblems(install, installs, grammar, config.root, contractProblems);
182
- addConsumerDependencyProblems(grammar, consumers, contractProblems);
183
- addGrammarStyleProblems(config, grammar, contractProblems, styleBypasses);
184
- addGrammarContractFinding(config, grammar, manifestFile, contractProblems, violations);
185
- const allowed = new Set([grammar.entry, grammar.styleEntry]);
186
- violations.push(...styleBypasses);
187
- const scan = { config, context, grammar, consumers, installs, allowed, violations, makeViolation };
188
- for (const sourceFile of context.files) inspectGrammarSource(scan, sourceFile);
189
- return violations;
165
+ const grammar = config.frontend.grammar;
166
+ if (!grammar)
167
+ return [];
168
+ const violations = [];
169
+ const local = context.workspaces.find(workspace => workspace.name === grammar.package);
170
+ // Node resolution per consumer: in an npm-workspaces monorepo a consumer whose range differs from the
171
+ // hoisted copy gets its own apps/<app>/node_modules/<package> (one consumer: apps/app on 0.5.0 beside a hoisted
172
+ // 0.4.11). Every consumer is judged against the copy it actually resolves, never the hoisted one alone.
173
+ // An app installs once, at its root (config.packageRoot): a side folder has no node_modules of its own.
174
+ const installRoot = installRootFor(config);
175
+ const consumers = grammarConsumers(config, grammar, local, installRoot);
176
+ const installs = uniqueGrammarInstalls(consumers);
177
+ const packageRoot = grammarPackageRoot(installs, local, installRoot, grammar.package);
178
+ const manifestFile = path.join(packageRoot, 'package.json');
179
+ readJson(manifestFile);
180
+ const contractProblems = [];
181
+ const styleBypasses = [];
182
+ for (const install of installs)
183
+ addInstallContractProblems(install, installs, grammar, config.root, contractProblems);
184
+ addConsumerDependencyProblems(grammar, consumers, contractProblems);
185
+ addGrammarStyleProblems(config, grammar, contractProblems, styleBypasses);
186
+ addGrammarContractFinding(config, grammar, manifestFile, contractProblems, violations);
187
+ const allowed = new Set([grammar.entry, grammar.styleEntry]);
188
+ violations.push(...styleBypasses);
189
+ const scan = { config, context, grammar, consumers, installs, allowed, violations, makeViolation };
190
+ for (const sourceFile of context.files)
191
+ inspectGrammarSource(scan, sourceFile);
192
+ return violations;
190
193
  }