@astryxdesign/cli 0.7.2-canary.ab79547 → 0.7.2-canary.acfd1ff

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 (269) hide show
  1. package/README.md +74 -73
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/component/_adapter.d.mts +41 -1
  4. package/api/component/_adapter.mjs +93 -7
  5. package/api/component/component.mjs +22 -5
  6. package/api/component/integration-export-name.test.mjs +644 -0
  7. package/api/discover/_adapter.d.mts +119 -12
  8. package/api/discover/_adapter.mjs +449 -10
  9. package/api/discover/_adapter.test.mjs +599 -17
  10. package/api/discover/_catalog-view.d.mts +16 -5
  11. package/api/discover/_catalog-view.mjs +32 -8
  12. package/api/discover/discover.d.mts +11 -0
  13. package/api/discover/discover.doc.mjs +7 -6
  14. package/api/discover/discover.mjs +107 -19
  15. package/api/discover/discover.type.d.mts +18 -7
  16. package/api/discover/discover.type.mjs +15 -7
  17. package/api/discover/list/list.d.mts +4 -3
  18. package/api/discover/list/list.mjs +17 -10
  19. package/api/docs/_adapter.d.mts +11 -0
  20. package/api/docs/_adapter.mjs +244 -1
  21. package/api/docs/integrationDocs.test.mjs +124 -0
  22. package/api/doctor/doctor.mjs +27 -3
  23. package/api/doctor/doctor.test.mjs +43 -0
  24. package/api/doctor/theme-checks.mjs +1 -1
  25. package/api/doctor/theme-checks.test.mjs +136 -0
  26. package/api/gap-report/gap-report.d.mts +3 -0
  27. package/api/gap-report/gap-report.doc.mjs +11 -3
  28. package/api/gap-report/gap-report.mjs +219 -52
  29. package/api/gap-report/gap-report.test.mjs +233 -0
  30. package/api/gap-report/gap-report.type.d.mts +41 -0
  31. package/api/gap-report/gap-report.type.mjs +18 -0
  32. package/api/index.d.mts +2 -0
  33. package/api/index.mjs +2 -0
  34. package/api/init/run/run.mjs +2 -2
  35. package/api/integration/_adapter.d.mts +32 -0
  36. package/api/integration/_adapter.mjs +80 -0
  37. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  38. package/api/integration/add-contribution.mjs +8 -4
  39. package/api/integration/add-contribution.test.mjs +4 -2
  40. package/api/integration/authoring-checks.mjs +44 -4
  41. package/api/integration/authoring-checks.test.mjs +515 -0
  42. package/api/integration/authoring-checks.type.d.mts +95 -0
  43. package/api/integration/authoring-checks.type.mjs +53 -2
  44. package/api/integration/check/check.d.mts +96 -0
  45. package/api/integration/check/check.mjs +357 -0
  46. package/api/integration/check/check.test.mjs +489 -0
  47. package/api/integration/integration-check.type.d.mts +118 -0
  48. package/api/integration/integration-check.type.mjs +84 -0
  49. package/api/integration/integrationCheck.doc.d.mts +10 -0
  50. package/api/integration/integrationCheck.doc.mjs +73 -0
  51. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  52. package/api/integration/integrationDocConflicts.doc.mjs +19 -5
  53. package/api/integration/pack-check.mjs +343 -104
  54. package/api/integration/pack-check.test.mjs +726 -0
  55. package/api/integration/validate-integration-fixes.test.mjs +67 -0
  56. package/api/integration/validate-integration.mjs +8 -0
  57. package/api/integration/validate-integration.test.mjs +41 -0
  58. package/api/integration/validate-integration.type.d.mts +8 -0
  59. package/api/integration/validate-integration.type.mjs +12 -1
  60. package/api/integration/validateIntegration.doc.mjs +19 -3
  61. package/api/search/search.d.mts +81 -12
  62. package/api/search/search.domain-priority.test.mjs +108 -18
  63. package/api/search/search.integration-check.test.mjs +24 -0
  64. package/api/search/search.mjs +601 -50
  65. package/api/search/search.test.mjs +139 -0
  66. package/api/swizzle/copy/copy.mjs +28 -14
  67. package/api/theme/build/build.family.test.mjs +54 -6
  68. package/api/theme/build/build.mjs +114 -17
  69. package/api/theme/themeBuild.doc.mjs +4 -4
  70. package/api/upgrade/_adapter.d.mts +40 -2
  71. package/api/upgrade/_adapter.mjs +117 -4
  72. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  73. package/api/upgrade/run/run.mjs +30 -1
  74. package/api/upgrade/status/status.d.mts +21 -5
  75. package/api/upgrade/status/status.mjs +45 -8
  76. package/api/upgrade/upgrade.doc.mjs +5 -3
  77. package/api/upgrade/upgrade.type.d.mts +23 -0
  78. package/api/upgrade/upgrade.type.mjs +16 -1
  79. package/assets/codemods/runner.mjs +7 -1
  80. package/assets/discover/official-packages.json +367 -0
  81. package/assets/docs/README.md +10 -0
  82. package/assets/docs/author-a-theme.doc.mjs +3 -3
  83. package/assets/docs/browser-support.doc.mjs +1 -1
  84. package/assets/docs/getting-started.doc.mjs +3 -3
  85. package/assets/docs/styling-overview.doc.mjs +1 -1
  86. package/assets/docs/theme.doc.dense.mjs +1 -1
  87. package/assets/docs/theme.doc.mjs +2 -2
  88. package/assets/docs/theme.doc.zh.mjs +1 -1
  89. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  90. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  91. package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
  92. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  93. package/assets/docs/tree/block-template.doc.mjs +8 -20
  94. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  95. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  96. package/assets/docs/tree/check-your-docs.doc.mjs +61 -7
  97. package/assets/docs/tree/checks.doc.mjs +26 -18
  98. package/assets/docs/tree/codemods.doc.mjs +4 -4
  99. package/assets/docs/tree/component-family.doc.mjs +8 -6
  100. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  101. package/assets/docs/tree/components.doc.mjs +1 -1
  102. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
  103. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  104. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  105. package/assets/docs/tree/docs.doc.mjs +3 -3
  106. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  107. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  108. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  109. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  110. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  111. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  112. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  113. package/assets/docs/tree/integrations.doc.mjs +8 -0
  114. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  115. package/assets/docs/tree/layout.doc.mjs +6 -6
  116. package/assets/docs/tree/links.doc.mjs +6 -5
  117. package/assets/docs/tree/migration-setup.doc.mjs +3 -2
  118. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  119. package/assets/docs/tree/migration.doc.mjs +0 -1
  120. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  121. package/assets/docs/tree/page-template.doc.mjs +4 -8
  122. package/assets/docs/tree/publishing.doc.mjs +4 -4
  123. package/assets/docs/tree/quick-start.doc.mjs +38 -22
  124. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  125. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  126. package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
  127. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  128. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  129. package/assets/docs/tree/single-component.doc.mjs +15 -6
  130. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  131. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  132. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  133. package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
  134. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  135. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  136. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  137. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  138. package/assets/docs/tree/templates.doc.mjs +1 -1
  139. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  140. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  141. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  142. package/assets/docs/tree/troubleshooting.doc.mjs +16 -8
  143. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  144. package/assets/docs/tree/upgrading.doc.mjs +4 -4
  145. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  146. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  147. package/assets/docs/tree/versioning.doc.mjs +7 -6
  148. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  149. package/assets/docs/use-a-theme.doc.mjs +2 -2
  150. package/assets/theme.template.ts +1 -1
  151. package/authoring/codemod/codemod.doc.mjs +7 -3
  152. package/authoring/config/config.doc.mjs +9 -6
  153. package/authoring/config/type.ts +4 -2
  154. package/authoring/discover/discover.doc.mjs +1 -1
  155. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  156. package/authoring/doctypes/command/command.doc.mjs +14 -12
  157. package/authoring/doctypes/component/component.doc.mjs +30 -27
  158. package/authoring/doctypes/component/type.ts +13 -8
  159. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  160. package/authoring/doctypes/function/function.doc.mjs +9 -8
  161. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  162. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  163. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  164. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  165. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  166. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  167. package/authoring/doctypes/template/parse.d.mts +6 -2
  168. package/authoring/doctypes/template/parse.mjs +3 -1
  169. package/authoring/doctypes/template/template.doc.mjs +3 -3
  170. package/authoring/doctypes/template/type.ts +22 -0
  171. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  172. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  173. package/authoring/identity/identity.doc.mjs +3 -3
  174. package/authoring/index.d.ts +1 -0
  175. package/authoring/integration/integration.doc.mjs +12 -4
  176. package/authoring/integration/parse.test.mjs +10 -0
  177. package/authoring/integration/schema.d.mts +2 -0
  178. package/authoring/integration/schema.mjs +1 -0
  179. package/authoring/integration/type.ts +4 -0
  180. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  181. package/clients/cli/commands/build-theme.mjs +1 -1
  182. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  183. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  184. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  185. package/clients/cli/commands/discover.doc.mjs +1 -1
  186. package/clients/cli/commands/discover.mjs +144 -93
  187. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  188. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  189. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  190. package/clients/cli/commands/doctor-integration-docs.doc.mjs +18 -5
  191. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  192. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  193. package/clients/cli/commands/doctor.mjs +250 -3
  194. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  195. package/clients/cli/commands/gap-report.mjs +24 -2
  196. package/clients/cli/commands/gap-report.test.mjs +79 -0
  197. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  198. package/clients/cli/commands/integration-check.test.mjs +370 -0
  199. package/clients/cli/commands/integration.doc.mjs +6 -2
  200. package/clients/cli/commands/integration.mjs +106 -1
  201. package/clients/cli/commands/json-contract.test.mjs +5 -1
  202. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  203. package/clients/cli/commands/swizzle.mjs +5 -3
  204. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  205. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  206. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  207. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  208. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  209. package/clients/cli/index.mjs +30 -5
  210. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  211. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  212. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  213. package/foundation/agent-docs/agent-docs.mjs +8 -6
  214. package/foundation/config/project.mjs +82 -0
  215. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  216. package/foundation/discovery/component-discovery.d.mts +178 -10
  217. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  218. package/foundation/discovery/component-discovery.mjs +659 -62
  219. package/foundation/discovery/component-replacement.mjs +18 -0
  220. package/foundation/discovery/component-replacement.test.mjs +40 -0
  221. package/foundation/discovery/copied-passages.d.mts +216 -0
  222. package/foundation/discovery/copied-passages.mjs +720 -0
  223. package/foundation/discovery/copied-passages.test.mjs +124 -0
  224. package/foundation/discovery/doc-fluff.d.mts +112 -0
  225. package/foundation/discovery/doc-fluff.mjs +328 -0
  226. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  227. package/foundation/discovery/doc-types.d.mts +157 -0
  228. package/foundation/discovery/doc-types.mjs +1224 -0
  229. package/foundation/discovery/doc-types.test.mjs +700 -0
  230. package/foundation/discovery/docs-discovery.d.mts +88 -0
  231. package/foundation/discovery/docs-discovery.mjs +83 -2
  232. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  233. package/foundation/discovery/integration-doc-files.mjs +231 -0
  234. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  235. package/foundation/discovery/module-exports.d.mts +27 -0
  236. package/foundation/discovery/module-exports.mjs +356 -31
  237. package/foundation/discovery/module-exports.test.mjs +172 -0
  238. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  239. package/foundation/discovery/package-tsconfig.mjs +228 -0
  240. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  241. package/foundation/discovery/project-typescript.d.mts +32 -0
  242. package/foundation/discovery/project-typescript.mjs +89 -0
  243. package/foundation/discovery/prop-drift.d.mts +278 -0
  244. package/foundation/discovery/prop-drift.mjs +2263 -0
  245. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  246. package/foundation/discovery/type-match.d.mts +53 -0
  247. package/foundation/discovery/type-match.mjs +660 -0
  248. package/foundation/discovery/type-match.test.mjs +169 -0
  249. package/foundation/discovery/type-text.d.mts +68 -0
  250. package/foundation/discovery/type-text.mjs +658 -0
  251. package/foundation/discovery/type-text.test.mjs +196 -0
  252. package/foundation/discovery/unresolved-references.d.mts +62 -0
  253. package/foundation/discovery/unresolved-references.mjs +790 -0
  254. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  255. package/foundation/doc-compiler/doc-loads.test.mjs +18 -0
  256. package/foundation/doc-compiler/links.d.mts +9 -5
  257. package/foundation/doc-compiler/links.mjs +4 -2
  258. package/foundation/env/package-manager.d.mts +32 -0
  259. package/foundation/env/package-manager.mjs +47 -0
  260. package/foundation/env/package-manager.test.mjs +194 -7
  261. package/foundation/fs/module-loader.d.mts +2 -1
  262. package/foundation/fs/module-loader.mjs +60 -4
  263. package/foundation/fs/module-loader.test.mjs +194 -0
  264. package/foundation/integrations/contribution-inventory.d.mts +11 -0
  265. package/foundation/integrations/contribution-inventory.mjs +56 -3
  266. package/foundation/integrations/validate-contributions.mjs +30 -1
  267. package/foundation/response/response-types.doc.mjs +14 -8
  268. package/package.json +11 -11
  269. package/scripts/postinstall.mjs +3 -3
@@ -37,6 +37,8 @@ const componentDoc = name =>
37
37
  `export default {type: 'component', name: '${name}', displayName: '${name}', usage: {description: '${name}.'}, props: []};\n`;
38
38
  /** @param {string} name */
39
39
  const componentSource = name => `export function ${name}() { return null; }\n`;
40
+ const templateSource = name =>
41
+ `export default function ${name}() { return null; }\n`;
40
42
  /** @param {string} name */
41
43
  const topic = name =>
42
44
  `export default ${JSON.stringify({
@@ -1131,6 +1133,71 @@ describe('source_without_component_doc fixes hold when followed', () => {
1131
1133
  });
1132
1134
  });
1133
1135
 
1136
+ describe('source_without_template_doc fixes hold when followed', () => {
1137
+ it('adds the named doc, which resolves the warning', async () => {
1138
+ const dir = writePackage({
1139
+ [MANIFEST]: manifest({templates: './templates'}),
1140
+ 'templates/hero.tsx': templateSource('Hero'),
1141
+ 'templates/hero.test.tsx': templateSource('HeroTest'),
1142
+ });
1143
+
1144
+ const message = only(await issuesOf(dir), 'source_without_template_doc');
1145
+ expect(message).toBe(
1146
+ "Template source \"hero.tsx\" has no same-stem metadata file hero.doc.mjs, so `astryx template` never lists it. Fix: add hero.doc.mjs beside it with type: 'page' or 'block'; `astryx docs authoring integration-template-doc` lists its fields. If it is not a template, move it out of the templates root.",
1147
+ );
1148
+
1149
+ const fixed = follow(dir, {
1150
+ write: {
1151
+ 'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
1152
+ },
1153
+ });
1154
+ expect(await issuesOf(fixed)).toEqual([]);
1155
+ });
1156
+
1157
+ it('checks a dotted template id, but no test, spec or story file', async () => {
1158
+ const dir = writePackage({
1159
+ [MANIFEST]: manifest({templates: './templates'}),
1160
+ 'templates/landing.page.tsx': templateSource('LandingPage'),
1161
+ 'templates/hero.test.tsx': templateSource('HeroTest'),
1162
+ 'templates/hero.spec.tsx': templateSource('HeroSpec'),
1163
+ 'templates/hero.stories.tsx': templateSource('HeroStories'),
1164
+ });
1165
+
1166
+ const message = only(await issuesOf(dir), 'source_without_template_doc');
1167
+ expect(message).toContain(
1168
+ 'Template source "landing.page.tsx" has no same-stem metadata file landing.page.doc.mjs',
1169
+ );
1170
+
1171
+ const fixed = follow(dir, {
1172
+ write: {
1173
+ 'templates/landing.page.doc.mjs': `export default {type: 'page', name: 'landing.page', displayName: 'Landing'};\n`,
1174
+ },
1175
+ });
1176
+ expect(await issuesOf(fixed)).toEqual([]);
1177
+ });
1178
+
1179
+ it('never flags a helper in a subfolder of the templates root', async () => {
1180
+ const dir = writePackage({
1181
+ [MANIFEST]: manifest({templates: './templates'}),
1182
+ 'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
1183
+ 'templates/hero.tsx': templateSource('Hero'),
1184
+ 'templates/hero/HeroCard.tsx': templateSource('HeroCard'),
1185
+ });
1186
+
1187
+ expect(await issuesOf(dir)).toEqual([]);
1188
+ });
1189
+
1190
+ it('accepts a released .template.mjs spec as the metadata', async () => {
1191
+ const dir = writePackage({
1192
+ [MANIFEST]: manifest({templates: './templates'}),
1193
+ 'templates/hero.tsx': templateSource('Hero'),
1194
+ 'templates/hero.template.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
1195
+ });
1196
+
1197
+ expect(await issuesOf(dir)).toEqual([]);
1198
+ });
1199
+ });
1200
+
1134
1201
  describe('codemod fixes hold when followed', () => {
1135
1202
  it('moves a stray codemod into a version folder, and renames a mis-named one', async () => {
1136
1203
  const dir = writePackage({
@@ -34,6 +34,7 @@
34
34
  import * as fs from 'node:fs';
35
35
  import * as path from 'node:path';
36
36
  import {assertWithin} from '../../foundation/fs/path-safety.mjs';
37
+ import {integrationDocTypes} from '../docs/_adapter.mjs';
37
38
  import {
38
39
  THEME_SLUG_RE,
39
40
  unreadThemeFolders,
@@ -461,6 +462,12 @@ export async function validateIntegration(pkg, options = {}) {
461
462
  const result = pkg
462
463
  ? await validateInstalledIntegration(pkg, cwd)
463
464
  : await validateLocalIntegration(cwd);
465
+ // Each doc the package ships, against the published authoring type for its
466
+ // kind, read with the project's own compiler. Findings are warnings only.
467
+ const integration = result.found ? result.integration : undefined;
468
+ const docTypes = integration
469
+ ? await integrationDocTypes(integration, cwd)
470
+ : undefined;
464
471
  return {
465
472
  type: 'integration.validate',
466
473
  data: {
@@ -472,6 +479,7 @@ export async function validateIntegration(pkg, options = {}) {
472
479
  issues: result.reason === 'no_package_json'
473
480
  ? [{code: 'no_package', severity: 'error', message: 'No package.json found. Run this command inside a package directory.'}]
474
481
  : result.issues,
482
+ ...(docTypes ? {docTypes} : {}),
475
483
  },
476
484
  };
477
485
  }
@@ -176,6 +176,17 @@ describe('validate-integration API', () => {
176
176
  expect(agentDocsIssues[0].severity).toBe('error');
177
177
  });
178
178
 
179
+ it('reports nothing for a docsiteUrl', async () => {
180
+ const pkgDir = path.join(tmpDir, 'pkg');
181
+ writePackage(pkgDir, {
182
+ manifest: `export default {docsiteUrl: 'https://widgets.example.com'};\n`,
183
+ });
184
+
185
+ const result = await validateLocalIntegration(pkgDir);
186
+
187
+ expect(result.issues).toEqual([]);
188
+ });
189
+
179
190
  it('flags a broken codemod as invalid_codemod error', async () => {
180
191
  const pkgDir = path.join(tmpDir, 'pkg');
181
192
  writePackage(pkgDir, {
@@ -310,6 +321,36 @@ export default {type: 'theme', name: 'ocean', displayName: 'Ocean', description:
310
321
  );
311
322
  });
312
323
 
324
+ it('warns when a template source has no same-stem metadata, skipping test files', async () => {
325
+ const pkgDir = path.join(tmpDir, 'pkg');
326
+ writePackage(pkgDir, {
327
+ manifest: `export default { templates: './templates' };\n`,
328
+ });
329
+ fs.mkdirSync(path.join(pkgDir, 'templates'));
330
+ fs.writeFileSync(
331
+ path.join(pkgDir, 'templates', 'stray.tsx'),
332
+ 'export default function Stray() { return null; }\n',
333
+ );
334
+ fs.writeFileSync(
335
+ path.join(pkgDir, 'templates', 'stray.test.tsx'),
336
+ "import {it} from 'vitest';\nit('renders', () => {});\n",
337
+ );
338
+
339
+ const result = await validateLocalIntegration(pkgDir);
340
+
341
+ const warnings = byCode(result.issues, 'source_without_template_doc');
342
+ expect(warnings).toEqual([
343
+ expect.objectContaining({
344
+ severity: 'warning',
345
+ message: expect.stringContaining('"stray.tsx"'),
346
+ }),
347
+ ]);
348
+ expect(warnings[0].message).not.toContain('stray.test.tsx');
349
+ expect(warnings[0].message).toContain(
350
+ "Fix: add stray.doc.mjs beside it with type: 'page' or 'block'",
351
+ );
352
+ });
353
+
313
354
  it('reports codemods outside semver folders and invalid folder names', async () => {
314
355
  const pkgDir = path.join(tmpDir, 'pkg');
315
356
  writePackage(pkgDir, {
@@ -39,5 +39,13 @@ export type ValidateIntegrationResponse = {
39
39
  name: string | null;
40
40
  version: string | null;
41
41
  issues: import("../../foundation/integrations/issue").AstryxIntegrationIssue[];
42
+ docTypes?: DocTypesReport;
42
43
  };
43
44
  };
45
+ /**
46
+ * `fixtures`: how many test fixture docs (under `__tests__` in the
47
+ * components or docs root, which those readers skip) were not checked
48
+ */
49
+ export type DocTypesReport = import("../../foundation/discovery/doc-types.mjs").DocTypesReport & {
50
+ fixtures?: number;
51
+ };
@@ -38,7 +38,18 @@
38
38
  * "healthy" — the two are otherwise byte-identical.
39
39
  * @typedef {object} ValidateIntegrationResponse
40
40
  * @property {'integration.validate'} type
41
- * @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[]}} data
41
+ * @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], docTypes?: DocTypesReport}} data
42
+ */
43
+
44
+ /**
45
+ * Each doc the package ships, checked against the published authoring type
46
+ * for its kind. Present when the manifest loads. `status: 'skipped'`
47
+ * means nothing was checked (no TypeScript in the project) and `reason` says
48
+ * why. Every finding is a warning.
49
+ *
50
+ * @typedef {import('../../foundation/discovery/doc-types.mjs').DocTypesReport & {fixtures?: number}} DocTypesReport
51
+ * `fixtures`: how many test fixture docs (under `__tests__` in the
52
+ * components or docs root, which those readers skip) were not checked
42
53
  */
43
54
 
44
55
  export {};
@@ -23,11 +23,27 @@ export const doc = {
23
23
  'declared contribution root exists, and runs the codemod/template/component/' +
24
24
  'docs/theme validators, returning every finding as an AstryxIntegrationIssue. A missing ' +
25
25
  'local manifest is guidance (name null, no issues), not an error, so callers ' +
26
- 'can stay exit-0 in a non-integration directory.',
26
+ 'can stay exit-0 in a non-integration directory. It also checks every doc the ' +
27
+ 'package ships under its roots (component, template, docs topic, theme, and translation, served or not) against ' +
28
+ "the published authoring type for its kind, as `tsc` would, with the project's " +
29
+ 'own `typescript` (or, where `typescript` is missing or has no JavaScript compiler ' +
30
+ 'API, as TypeScript 7 does, the `@typescript/typescript6` it installs): an unknown ' +
31
+ 'field, a missing required field, or a value outside ' +
32
+ "a field's type is a warning in `docTypes` naming the field and a fix. A test " +
33
+ 'fixture under `__tests__` in the components or docs root is counted, not checked. ' +
34
+ 'Without TypeScript, `docTypes` is `skipped` with a reason.',
27
35
  importPath: '@astryxdesign/cli/api',
28
36
  signature:
29
37
  'validateIntegration(pkg?: string, options?: ValidateIntegrationOptions): Promise<ValidateIntegrationResponse>',
30
- keywords: ['integration', 'validate', 'manifest', 'lint', 'check'],
38
+ keywords: [
39
+ 'integration',
40
+ 'validate',
41
+ 'manifest',
42
+ 'lint',
43
+ 'check',
44
+ 'types',
45
+ 'typecheck',
46
+ ],
31
47
  params: [
32
48
  {
33
49
  name: 'pkg',
@@ -46,7 +62,7 @@ export const doc = {
46
62
  {
47
63
  type: 'integration.validate',
48
64
  description:
49
- 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
65
+ 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked.',
50
66
  },
51
67
  ],
52
68
  examples: [
@@ -16,6 +16,48 @@ export function stem(w: string): string;
16
16
  * @returns {boolean}
17
17
  */
18
18
  export function sameWord(a: string, b: string): boolean;
19
+ /**
20
+ * A query with its camelCase and PascalCase identifiers spelled as words, so
21
+ * `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
22
+ * table pagination state". Plain words, and identifiers joined with `_` or `-`, are
23
+ * unchanged: a joined token that matches nothing stays unmatched.
24
+ * @param {string} query - The query as typed, before lowercasing.
25
+ * @returns {string} Lowercased.
26
+ */
27
+ export function spellIdentifiers(query: string): string;
28
+ /**
29
+ * The strongest hit a run of two or more adjacent query words has when it is
30
+ * read as one joined word, and the query words it covers. Readers type a
31
+ * compound name as separate words (`table header cell` is TableHeaderCell,
32
+ * `number field` the keyword `numberfield`), and no single word of the run
33
+ * matches on its own.
34
+ *
35
+ * - 100: the run joins to a component, hook, or template name, or its plural
36
+ * (`table header cells` is TableHeaderCell), or a hook name without its
37
+ * `use` prefix (`table sticky columns` is useTableStickyColumns).
38
+ * - 90: the run joins to a one-word keyword (`number field` is
39
+ * `numberfield`).
40
+ * - 95: the run joins to most of a name, cut short (`dropdown menu radio` is
41
+ * DropdownMenuRadioItem); 92: it is a name's leading words, covering at least half
42
+ * of it (`top nav mega` is TopNavMegaMenu); 70: it is two or more adjacent
43
+ * words of a name that cover at least half of it (`header cell` in
44
+ * TableHeaderCell), the same coverage a word prefix needs. These three
45
+ * are for components and hooks only.
46
+ *
47
+ * A doc's name is a route or key, so docs are left out.
48
+ * @param {string[]} words - The query's words, stopwords included.
49
+ * @param {Candidate} candidate
50
+ * @returns {{score: number, reason: string, covered: Set<string>, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
51
+ * `covered` holds the run's words and every stretch of them joined. `alias`
52
+ * marks a hit on part of a name or on a keyword, not on the whole name.
53
+ */
54
+ export function compoundHit(words: string[], candidate: Candidate): {
55
+ score: number;
56
+ reason: string;
57
+ covered: Set<string>;
58
+ alias?: "partial" | "keyword";
59
+ aliasWords?: number;
60
+ } | null;
19
61
  /**
20
62
  * Split a query into meaningful content tokens (lowercased, stopwords + very
21
63
  * short words removed). Empty for single-word queries (callers fall back to
@@ -40,19 +82,20 @@ export function tokenizeQuery(term: string): string[];
40
82
  * typography/font-setup, `side panel` is "Side panels");
41
83
  * - 1: a word of the query is the topic's name (`illustration` in a longer
42
84
  * question is the illustrations guide);
85
+ * - 1: a query of two or more words is one of the topic's own declared
86
+ * keywords, whatever the plural (`code review` on a guide that declares it);
43
87
  * - 1: the query holds one of the doc's titles whole (`resizable side panels`
44
88
  * names "Side panels"; `light dark mode button` names "Light/Dark Mode");
45
89
  * - 1: the doc matches every word of the query and one of them is a word of
46
90
  * its title (`switch to a dark theme` and "Use a theme").
47
91
  * A section answers to its topic's name.
48
92
  *
49
- * A doc that matched only by keyword, by a heading holding the query, or by
93
+ * A doc that matched only by a heading holding the query, by one word, or by
50
94
  * words spread through its text has no priority. Docs are split into many
51
- * small topics, and each declares its own keywords and headings, so a common
52
- * phrase such as `font size` hits a guide's keyword or heading exactly
53
- * (170-190) while the component the reader is after matches one word by
54
- * keyword (`Text`, 98). Ranked on text alone, every split adds another doc
55
- * above the component. Broad reference pages match every word of many queries
95
+ * small topics, each with its own headings, so a common phrase such as
96
+ * `font size` hits a heading exactly (170) while the component the reader is
97
+ * after matches one word by keyword (`Text`, 98). Ranked on text alone, every
98
+ * split adds another doc above the component. Broad reference pages match every word of many queries
56
99
  * in their text the same way. The score stays the text-match strength the
57
100
  * result reports, so callers that gate on it (`build`) see the same numbers.
58
101
  *
@@ -67,7 +110,7 @@ export function domainPriority(term: string, tokens: string[], candidate: Candid
67
110
  score: number;
68
111
  matched: number;
69
112
  total: number;
70
- }): 0 | 1 | 2;
113
+ }, queryWords?: string[]): 0 | 1 | 2;
71
114
  /**
72
115
  * The first title or heading that holds every word of the query, in order and
73
116
  * side by side, or null.
@@ -89,18 +132,26 @@ export function titleInQuery(term: string, titles: string[] | undefined): string
89
132
  * @param {string} term - Lowercased full query.
90
133
  * @param {string[]} tokens - Content tokens from tokenizeQuery(term).
91
134
  * @param {Candidate} candidate
92
- * @returns {{score: number, reason: string, matched: number, total: number} | null}
135
+ * @param {string[]} [words] - The query's words for compound names (see
136
+ * compoundHit); empty when the query names an entry outright.
137
+ * @param {{plain?: boolean}} [opts] - `plain`: score without matches on part
138
+ * of a name or a joined keyword.
139
+ * @returns {{score: number, reason: string, matched: number, total: number, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
93
140
  * `matched`/`total` are the query concepts this candidate answered, out of
94
141
  * the concepts the query had. Callers that must distinguish "matched one word
95
142
  * of three" from "matched all three" — `build`, which gates its pages group
96
143
  * on coverage — cannot recover that from the score, because a single strong
97
144
  * hit and a broad weak one land on the same number.
98
145
  */
99
- export function scoreQuery(term: string, tokens: string[], candidate: Candidate): {
146
+ export function scoreQuery(term: string, tokens: string[], candidate: Candidate, words?: string[], { plain }?: {
147
+ plain?: boolean;
148
+ }): {
100
149
  score: number;
101
150
  reason: string;
102
151
  matched: number;
103
152
  total: number;
153
+ alias?: "partial" | "keyword";
154
+ aliasWords?: number;
104
155
  } | null;
105
156
  /**
106
157
  * Score a single candidate against the search term across name, keywords,
@@ -118,8 +169,9 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
118
169
  * @param {string} [candidate.description]
119
170
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
120
171
  * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
121
- * @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
122
- * @returns {{score: number, reason: string} | null}
172
+ * @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
173
+ * @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
174
+ * `alias` marks a hit that read the query's words joined.
123
175
  */
124
176
  export function scoreCandidate(term: string, { name, aliases, domain, keywords, weakKeywords, description, prose, guidance, }: {
125
177
  name: string;
@@ -130,11 +182,13 @@ export function scoreCandidate(term: string, { name, aliases, domain, keywords,
130
182
  description?: string | undefined;
131
183
  prose?: string[] | undefined;
132
184
  guidance?: string[] | undefined;
133
- }, { fuzzy }?: {
185
+ }, { fuzzy, joins }?: {
134
186
  fuzzy?: boolean;
187
+ joins?: boolean;
135
188
  }): {
136
189
  score: number;
137
190
  reason: string;
191
+ alias?: "partial" | "keyword";
138
192
  } | null;
139
193
  /**
140
194
  * The components (name and keywords) a search response was scored against, or
@@ -213,6 +267,12 @@ export type Candidate = {
213
267
  */
214
268
  aliases?: string[] | undefined;
215
269
  keywords?: string[] | undefined;
270
+ /**
271
+ * - A doc's own declared keywords: what its
272
+ * author lists in `keywords`, without the code terms and table cells its
273
+ * other keywords add.
274
+ */
275
+ _declared?: string[] | undefined;
216
276
  weakKeywords?: string[] | undefined;
217
277
  description?: string | undefined;
218
278
  prose?: string[] | undefined;
@@ -252,4 +312,13 @@ export type Candidate = {
252
312
  _kind?: "page" | "block" | undefined;
253
313
  _resultName?: string | undefined;
254
314
  _commandName?: string | undefined;
315
+ /**
316
+ * - How an integration component holds its
317
+ * name, for the owner rule.
318
+ */
319
+ _hold?: "file" | "doc" | undefined;
320
+ /**
321
+ * - An integration component's doc.
322
+ */
323
+ _docPath?: string | undefined;
255
324
  };
@@ -75,14 +75,75 @@ async function placedGuides(route, seen = new Set()) {
75
75
  }
76
76
 
77
77
  describe('search domain priority — the rule', () => {
78
- it('gives a doc no priority for a keyword or heading match', () => {
78
+ it('gives a doc no priority for a heading match or a one-word keyword', () => {
79
79
  const topic = {
80
80
  domain: 'doc',
81
81
  name: 'typography/font-setup',
82
- keywords: ['font size'],
82
+ keywords: ['size'],
83
83
  titles: ['Font Setup', 'Font Sizes'],
84
84
  };
85
85
  expect(priority('font size', topic)).toBe(0);
86
+ expect(priority('size', topic)).toBe(0);
87
+ });
88
+
89
+ it('gives a doc priority when the query is one of its declared keywords', () => {
90
+ const guide = {
91
+ domain: 'doc',
92
+ name: 'guides/quality',
93
+ titles: ['Is my code good?'],
94
+ keywords: ['code review', 'review my code'],
95
+ _declared: ['code review', 'review my code'],
96
+ };
97
+ expect(priority('code review', guide)).toBe(1);
98
+ expect(priority('Code Reviews', guide)).toBe(1);
99
+ expect(priority('review my code', guide)).toBe(1);
100
+ // A section's keywords are its headings and code terms.
101
+ const section = {
102
+ ...guide,
103
+ name: 'before-you-ship',
104
+ _topic: 'guides/quality',
105
+ _section: 'before-you-ship',
106
+ };
107
+ expect(priority('code review', section)).toBe(0);
108
+ });
109
+
110
+ it("gives a doc no priority for a code term or table cell it didn't declare", () => {
111
+ // A typed doc's keywords hold the first column of its tables and the code
112
+ // terms its text mentions; `missing_field` reads as two words.
113
+ const reference = {
114
+ domain: 'doc',
115
+ name: 'cli/api/functions/validate-integration',
116
+ titles: ['validateIntegration'],
117
+ keywords: ['validate-integration', 'missing_field', 'file required'],
118
+ _declared: [],
119
+ _topic: 'cli/api/functions/validate-integration',
120
+ };
121
+ expect(priority('missing field', reference)).toBe(0);
122
+ expect(priority('file required', reference)).toBe(0);
123
+ expect(
124
+ priority('missing field', {...reference, _declared: ['missing field']}),
125
+ ).toBe(1);
126
+ });
127
+
128
+ it('keeps a component the query names exactly above a doc that declares it', async () => {
129
+ const tokens = tokenizeQuery('empty state');
130
+ const component = {domain: 'component', name: 'EmptyState'};
131
+ const doc = {
132
+ domain: 'doc',
133
+ name: 'illustrations',
134
+ keywords: ['empty state'],
135
+ _declared: ['empty state'],
136
+ };
137
+ const c = scoreQuery('empty state', tokens, component);
138
+ const d = scoreQuery('empty state', tokens, doc);
139
+ expect(
140
+ domainPriority('empty state', tokens, /** @type {any} */ (component), c),
141
+ ).toBe(1);
142
+ expect(
143
+ domainPriority('empty state', tokens, /** @type {any} */ (doc), d),
144
+ ).toBe(1);
145
+ // Both have priority, so the stronger match wins: the exact name.
146
+ expect(c?.score).toBeGreaterThan(d?.score ?? 0);
86
147
  });
87
148
 
88
149
  it('gives a doc priority when the query names it', () => {
@@ -190,32 +251,61 @@ describe('search domain priority — the rule', () => {
190
251
 
191
252
  describe('search domain priority — real docs and components', () => {
192
253
  it(
193
- 'finds the Text component before the typography guides for `font size`',
254
+ 'finds a guide that declares the whole phrase above a component that matches one word',
194
255
  async () => {
195
- for (const q of ['font size', 'font weight']) {
196
- const results = (await search(q, {cwd})).data.results;
197
- expect(results[0], q).toMatchObject({
198
- domain: 'component',
199
- name: 'Text',
200
- });
201
- const guide = results.findIndex(
202
- r => r.domain === 'doc' && /^typography(?:\/|$)/.test(r.name),
203
- );
204
- // The guide still matches, below the component.
205
- expect(guide, q).toBeGreaterThan(0);
256
+ const results = (await search('font size', {cwd})).data.results;
257
+ expect(results[0]).toMatchObject({domain: 'doc'});
258
+ expect(results[0].name).toMatch(/^typography(?:\/|$)/);
259
+ // The component the phrase points to stays near the top.
260
+ expect(
261
+ results
262
+ .slice(0, 3)
263
+ .some(r => r.domain === 'component' && r.name === 'Text'),
264
+ ).toBe(true);
265
+ },
266
+ SLOW,
267
+ );
268
+
269
+ it(
270
+ 'keeps a component above a reference doc whose table or code terms hold the phrase',
271
+ async () => {
272
+ for (const q of ['missing field', 'file required']) {
273
+ const [top] = (await search(q, {cwd})).data.results;
274
+ expect(top, q).toMatchObject({domain: 'component', name: 'Field'});
206
275
  }
207
276
  },
208
277
  SLOW,
209
278
  );
210
279
 
211
280
  it(
212
- 'reports the text-match score unchanged',
281
+ 'opens the guide that answers a declared phrase, not one that only mentions it',
282
+ async () => {
283
+ const [layers] = (await search('cascade layers', {cwd})).data.results;
284
+ expect(layers).toMatchObject({
285
+ domain: 'doc',
286
+ name: 'migration/migration-setup',
287
+ });
288
+ const [keyboard] = (await search('keyboard navigation', {cwd})).data
289
+ .results;
290
+ expect(keyboard?.name).not.toBe('migration/migration-verification');
291
+ },
292
+ SLOW,
293
+ );
294
+
295
+ it(
296
+ 'keeps a component above docs that match only by a heading, with scores unchanged',
213
297
  async () => {
214
298
  const results = (await search('font size', {cwd})).data.results;
215
- const guide = results.find(
216
- r => r.domain === 'doc' && /^typography(?:\/|$)/.test(r.name),
299
+ const text = results.findIndex(
300
+ r => r.domain === 'component' && r.name === 'Text',
217
301
  );
218
- expect(guide?.score).toBeGreaterThan(results[0].score);
302
+ expect(text).toBeGreaterThanOrEqual(0);
303
+ // A doc below Text outscores it on text alone: priority moved it, not the score.
304
+ expect(
305
+ results
306
+ .slice(text + 1)
307
+ .some(r => r.domain === 'doc' && r.score > results[text].score),
308
+ ).toBe(true);
219
309
  },
220
310
  SLOW,
221
311
  );
@@ -0,0 +1,24 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file A reader looking for the check a build runs finds
5
+ * `astryx integration check` first.
6
+ */
7
+
8
+ import {describe, expect, it} from 'vitest';
9
+ import {search} from './search.mjs';
10
+
11
+ describe('search finds integration check for CI', () => {
12
+ it.each([
13
+ 'ci',
14
+ 'continuous integration',
15
+ 'typecheck integration',
16
+ 'integration check',
17
+ ])('`%s` ranks it first', async query => {
18
+ const {results} = (await search(query)).data;
19
+ expect(results[0], JSON.stringify(results.slice(0, 3))).toMatchObject({
20
+ domain: 'doc',
21
+ name: 'cli/commands/integration-check',
22
+ });
23
+ });
24
+ });