@astryxdesign/cli 0.7.2-canary.4787e3f → 0.7.2-canary.4a2f608

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 (247) hide show
  1. package/README.md +74 -73
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/discover/_adapter.d.mts +119 -12
  4. package/api/discover/_adapter.mjs +449 -10
  5. package/api/discover/_adapter.test.mjs +599 -17
  6. package/api/discover/_catalog-view.d.mts +16 -5
  7. package/api/discover/_catalog-view.mjs +32 -8
  8. package/api/discover/discover.d.mts +11 -0
  9. package/api/discover/discover.doc.mjs +7 -6
  10. package/api/discover/discover.mjs +107 -19
  11. package/api/discover/discover.type.d.mts +18 -7
  12. package/api/discover/discover.type.mjs +15 -7
  13. package/api/discover/list/list.d.mts +4 -3
  14. package/api/discover/list/list.mjs +17 -10
  15. package/api/docs/_adapter.d.mts +11 -0
  16. package/api/docs/_adapter.mjs +244 -1
  17. package/api/docs/integrationDocs.test.mjs +124 -0
  18. package/api/doctor/doctor.mjs +27 -3
  19. package/api/doctor/doctor.test.mjs +43 -0
  20. package/api/doctor/theme-checks.mjs +1 -1
  21. package/api/doctor/theme-checks.test.mjs +136 -0
  22. package/api/gap-report/gap-report.d.mts +3 -0
  23. package/api/gap-report/gap-report.doc.mjs +11 -3
  24. package/api/gap-report/gap-report.mjs +152 -48
  25. package/api/gap-report/gap-report.test.mjs +233 -0
  26. package/api/gap-report/gap-report.type.d.mts +41 -0
  27. package/api/gap-report/gap-report.type.mjs +18 -0
  28. package/api/index.d.mts +2 -0
  29. package/api/index.mjs +2 -0
  30. package/api/init/run/run.mjs +2 -2
  31. package/api/integration/_adapter.d.mts +32 -0
  32. package/api/integration/_adapter.mjs +80 -0
  33. package/api/integration/add-contribution.mjs +1 -1
  34. package/api/integration/add-contribution.test.mjs +4 -2
  35. package/api/integration/authoring-checks.mjs +44 -4
  36. package/api/integration/authoring-checks.test.mjs +515 -0
  37. package/api/integration/authoring-checks.type.d.mts +95 -0
  38. package/api/integration/authoring-checks.type.mjs +53 -2
  39. package/api/integration/check/check.d.mts +96 -0
  40. package/api/integration/check/check.mjs +357 -0
  41. package/api/integration/check/check.test.mjs +489 -0
  42. package/api/integration/integration-check.type.d.mts +118 -0
  43. package/api/integration/integration-check.type.mjs +84 -0
  44. package/api/integration/integrationCheck.doc.d.mts +10 -0
  45. package/api/integration/integrationCheck.doc.mjs +73 -0
  46. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  47. package/api/integration/integrationDocConflicts.doc.mjs +19 -5
  48. package/api/integration/pack-check.mjs +292 -7
  49. package/api/integration/pack-check.test.mjs +341 -0
  50. package/api/integration/validate-integration.mjs +8 -0
  51. package/api/integration/validate-integration.test.mjs +11 -0
  52. package/api/integration/validate-integration.type.d.mts +8 -0
  53. package/api/integration/validate-integration.type.mjs +12 -1
  54. package/api/integration/validateIntegration.doc.mjs +19 -3
  55. package/api/search/search.d.mts +72 -12
  56. package/api/search/search.domain-priority.test.mjs +108 -18
  57. package/api/search/search.integration-check.test.mjs +24 -0
  58. package/api/search/search.mjs +501 -37
  59. package/api/search/search.test.mjs +139 -0
  60. package/api/theme/build/build.family.test.mjs +54 -6
  61. package/api/theme/build/build.mjs +114 -17
  62. package/api/theme/themeBuild.doc.mjs +4 -4
  63. package/api/upgrade/_adapter.d.mts +40 -2
  64. package/api/upgrade/_adapter.mjs +117 -4
  65. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  66. package/api/upgrade/run/run.mjs +30 -1
  67. package/api/upgrade/status/status.d.mts +21 -5
  68. package/api/upgrade/status/status.mjs +45 -8
  69. package/api/upgrade/upgrade.doc.mjs +5 -3
  70. package/api/upgrade/upgrade.type.d.mts +23 -0
  71. package/api/upgrade/upgrade.type.mjs +16 -1
  72. package/assets/codemods/runner.mjs +7 -1
  73. package/assets/discover/official-packages.json +367 -0
  74. package/assets/docs/README.md +10 -0
  75. package/assets/docs/author-a-theme.doc.mjs +3 -3
  76. package/assets/docs/browser-support.doc.mjs +1 -1
  77. package/assets/docs/getting-started.doc.mjs +3 -3
  78. package/assets/docs/styling-overview.doc.mjs +1 -1
  79. package/assets/docs/theme.doc.dense.mjs +1 -1
  80. package/assets/docs/theme.doc.mjs +2 -2
  81. package/assets/docs/theme.doc.zh.mjs +1 -1
  82. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  83. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  84. package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
  85. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  86. package/assets/docs/tree/block-template.doc.mjs +8 -20
  87. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  88. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  89. package/assets/docs/tree/check-your-docs.doc.mjs +61 -7
  90. package/assets/docs/tree/checks.doc.mjs +25 -17
  91. package/assets/docs/tree/codemods.doc.mjs +4 -4
  92. package/assets/docs/tree/component-family.doc.mjs +3 -5
  93. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  94. package/assets/docs/tree/components.doc.mjs +1 -1
  95. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
  96. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  97. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  98. package/assets/docs/tree/docs.doc.mjs +3 -3
  99. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  100. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  101. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  102. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  103. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  104. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  105. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  106. package/assets/docs/tree/integrations.doc.mjs +8 -0
  107. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  108. package/assets/docs/tree/layout.doc.mjs +6 -6
  109. package/assets/docs/tree/links.doc.mjs +6 -5
  110. package/assets/docs/tree/migration-setup.doc.mjs +3 -2
  111. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  112. package/assets/docs/tree/migration.doc.mjs +0 -1
  113. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  114. package/assets/docs/tree/page-template.doc.mjs +4 -8
  115. package/assets/docs/tree/publishing.doc.mjs +4 -4
  116. package/assets/docs/tree/quick-start.doc.mjs +38 -22
  117. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  118. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  119. package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
  120. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  121. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  122. package/assets/docs/tree/single-component.doc.mjs +14 -5
  123. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  124. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  125. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  126. package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
  127. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  128. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  129. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  130. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  131. package/assets/docs/tree/templates.doc.mjs +1 -1
  132. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  133. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  134. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  135. package/assets/docs/tree/troubleshooting.doc.mjs +8 -8
  136. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  137. package/assets/docs/tree/upgrading.doc.mjs +4 -4
  138. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  139. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  140. package/assets/docs/tree/versioning.doc.mjs +6 -6
  141. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  142. package/assets/docs/use-a-theme.doc.mjs +2 -2
  143. package/assets/theme.template.ts +1 -1
  144. package/authoring/codemod/codemod.doc.mjs +7 -3
  145. package/authoring/config/config.doc.mjs +9 -6
  146. package/authoring/config/type.ts +4 -2
  147. package/authoring/discover/discover.doc.mjs +1 -1
  148. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  149. package/authoring/doctypes/command/command.doc.mjs +14 -12
  150. package/authoring/doctypes/component/component.doc.mjs +29 -26
  151. package/authoring/doctypes/component/type.ts +7 -5
  152. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  153. package/authoring/doctypes/function/function.doc.mjs +9 -8
  154. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  155. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  156. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  157. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  158. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  159. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  160. package/authoring/doctypes/template/parse.d.mts +6 -2
  161. package/authoring/doctypes/template/parse.mjs +3 -1
  162. package/authoring/doctypes/template/template.doc.mjs +3 -3
  163. package/authoring/doctypes/template/type.ts +22 -0
  164. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  165. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  166. package/authoring/identity/identity.doc.mjs +3 -3
  167. package/authoring/index.d.ts +1 -0
  168. package/authoring/integration/integration.doc.mjs +12 -4
  169. package/authoring/integration/parse.test.mjs +10 -0
  170. package/authoring/integration/schema.d.mts +2 -0
  171. package/authoring/integration/schema.mjs +1 -0
  172. package/authoring/integration/type.ts +4 -0
  173. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  174. package/clients/cli/commands/build-theme.mjs +1 -1
  175. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  176. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  177. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  178. package/clients/cli/commands/discover.doc.mjs +1 -1
  179. package/clients/cli/commands/discover.mjs +144 -93
  180. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  181. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  182. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  183. package/clients/cli/commands/doctor-integration-docs.doc.mjs +18 -5
  184. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  185. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  186. package/clients/cli/commands/doctor.mjs +250 -3
  187. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  188. package/clients/cli/commands/gap-report.mjs +24 -2
  189. package/clients/cli/commands/gap-report.test.mjs +79 -0
  190. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  191. package/clients/cli/commands/integration-check.test.mjs +370 -0
  192. package/clients/cli/commands/integration.doc.mjs +6 -2
  193. package/clients/cli/commands/integration.mjs +106 -1
  194. package/clients/cli/commands/json-contract.test.mjs +5 -1
  195. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  196. package/clients/cli/commands/swizzle.mjs +5 -3
  197. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  198. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  199. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  200. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  201. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  202. package/clients/cli/index.mjs +30 -5
  203. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  204. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  205. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  206. package/foundation/agent-docs/agent-docs.mjs +8 -6
  207. package/foundation/config/project.mjs +82 -0
  208. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  209. package/foundation/discovery/component-discovery.d.mts +18 -0
  210. package/foundation/discovery/component-discovery.mjs +2 -2
  211. package/foundation/discovery/copied-passages.d.mts +216 -0
  212. package/foundation/discovery/copied-passages.mjs +720 -0
  213. package/foundation/discovery/copied-passages.test.mjs +124 -0
  214. package/foundation/discovery/doc-fluff.d.mts +112 -0
  215. package/foundation/discovery/doc-fluff.mjs +328 -0
  216. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  217. package/foundation/discovery/doc-types.d.mts +157 -0
  218. package/foundation/discovery/doc-types.mjs +1224 -0
  219. package/foundation/discovery/doc-types.test.mjs +700 -0
  220. package/foundation/discovery/docs-discovery.d.mts +88 -0
  221. package/foundation/discovery/docs-discovery.mjs +83 -2
  222. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  223. package/foundation/discovery/integration-doc-files.mjs +231 -0
  224. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  225. package/foundation/discovery/project-typescript.d.mts +11 -2
  226. package/foundation/discovery/project-typescript.mjs +32 -4
  227. package/foundation/discovery/prop-drift.d.mts +116 -3
  228. package/foundation/discovery/prop-drift.mjs +883 -41
  229. package/foundation/discovery/prop-drift.test.mjs +1738 -20
  230. package/foundation/discovery/type-match.d.mts +53 -0
  231. package/foundation/discovery/type-match.mjs +660 -0
  232. package/foundation/discovery/type-match.test.mjs +169 -0
  233. package/foundation/discovery/type-text.d.mts +68 -0
  234. package/foundation/discovery/type-text.mjs +658 -0
  235. package/foundation/discovery/type-text.test.mjs +196 -0
  236. package/foundation/doc-compiler/doc-loads.test.mjs +16 -2
  237. package/foundation/doc-compiler/links.d.mts +9 -5
  238. package/foundation/doc-compiler/links.mjs +4 -2
  239. package/foundation/env/package-manager.d.mts +32 -0
  240. package/foundation/env/package-manager.mjs +47 -0
  241. package/foundation/env/package-manager.test.mjs +194 -7
  242. package/foundation/fs/module-loader.d.mts +2 -1
  243. package/foundation/fs/module-loader.mjs +60 -4
  244. package/foundation/fs/module-loader.test.mjs +194 -0
  245. package/foundation/response/response-types.doc.mjs +14 -8
  246. package/package.json +11 -11
  247. package/scripts/postinstall.mjs +3 -3
@@ -0,0 +1,246 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file integrationDocFiles(): exactly the docs each root's reader serves, a
5
+ * nested root's files given to that root, and a root its reader cannot read.
6
+ */
7
+
8
+ import * as fs from 'node:fs';
9
+ import * as os from 'node:os';
10
+ import * as path from 'node:path';
11
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
12
+ import {discoverIntegrationComponents} from './component-discovery.mjs';
13
+ import {integrationDocFiles} from './integration-doc-files.mjs';
14
+
15
+ /** @type {string} */
16
+ let pkg;
17
+
18
+ beforeEach(() => {
19
+ pkg = fs.realpathSync(
20
+ fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-doc-files-')),
21
+ );
22
+ });
23
+
24
+ afterEach(() => {
25
+ fs.rmSync(pkg, {recursive: true, force: true});
26
+ });
27
+
28
+ /**
29
+ * @param {string} rel
30
+ * @param {string} text
31
+ */
32
+ function write(rel, text) {
33
+ const file = path.join(pkg, rel);
34
+ fs.mkdirSync(path.dirname(file), {recursive: true});
35
+ fs.writeFileSync(file, text);
36
+ return file;
37
+ }
38
+
39
+ /** @param {string} name */
40
+ const component = name =>
41
+ `export default {type: 'component', name: '${name}', displayName: '${name}', usage: {description: 'x'}, props: []};\n`;
42
+ /** @param {string} name */
43
+ const topic = name =>
44
+ `export default {type: 'generic', name: '${name}', title: 'T', description: 'D', sections: [{title: 'S', content: [{type: 'prose', text: 'x'}]}]};\n`;
45
+ /** @param {string} rel a template doc, with its same-stem source */
46
+ const template = rel => {
47
+ write(rel.replace(/\.doc\.mjs$/, '.tsx'), 'export default () => null;\n');
48
+ return write(
49
+ rel,
50
+ `export default {type: 'block', name: '${path.basename(rel, '.doc.mjs')}', description: 'D'};\n`,
51
+ );
52
+ };
53
+
54
+ /** @param {Awaited<ReturnType<typeof integrationDocFiles>>['files']} files */
55
+ const listed = files =>
56
+ files
57
+ .map(f => [path.relative(pkg, f.path).split(path.sep).join('/'), f.root])
58
+ .sort();
59
+
60
+ describe('integrationDocFiles', () => {
61
+ it('reads a fixture folder relative to its root, so a package under a `__tests__` folder is checked', async () => {
62
+ write(
63
+ '__tests__/acme/components/Hidden.doc.mjs',
64
+ `${component('Hidden')}\n hidden: true\n`,
65
+ );
66
+ write(
67
+ '__tests__/acme/components/__tests__/Tested.doc.mjs',
68
+ component('Tested'),
69
+ );
70
+
71
+ const {files, fixtures} = await integrationDocFiles({
72
+ name: '@acme/widgets',
73
+ components: path.join(pkg, '__tests__', 'acme', 'components'),
74
+ });
75
+
76
+ expect(listed(files)).toEqual([
77
+ ['__tests__/acme/components/Hidden.doc.mjs', 'components'],
78
+ ]);
79
+ expect(fixtures).toBe(1);
80
+ });
81
+
82
+ it("gives a nested root's files to that root", async () => {
83
+ write('src/Badge.doc.mjs', component('Badge'));
84
+ write('src/docs/guide.doc.mjs', topic('guide'));
85
+ write('src/docs/guide.doc.zh.mjs', 'export const docsZh = {};\n');
86
+ template('templates/hero.doc.mjs');
87
+
88
+ const {files, unread} = await integrationDocFiles({
89
+ name: '@acme/widgets',
90
+ components: path.join(pkg, 'src'),
91
+ docs: path.join(pkg, 'src', 'docs'),
92
+ templates: path.join(pkg, 'templates'),
93
+ });
94
+
95
+ expect(unread).toEqual([]);
96
+ expect(listed(files)).toEqual([
97
+ ['src/Badge.doc.mjs', 'components'],
98
+ ['src/docs/guide.doc.mjs', 'docs'],
99
+ ['src/docs/guide.doc.zh.mjs', 'docs-overlay'],
100
+ ['templates/hero.doc.mjs', 'templates'],
101
+ ]);
102
+ });
103
+
104
+ it('takes every doc the roots hold, served or not, and counts a test fixture no reader serves', async () => {
105
+ write('components/__fixtures__/Fixture.doc.mjs', component('Fixture'));
106
+ write('components/.drafts/Draft.doc.mjs', component('Draft'));
107
+ write('components/__tests__/Tested.doc.mjs', component('Tested'));
108
+ write(
109
+ 'components/Hidden.doc.mjs',
110
+ `${component('Hidden')}\n hidden: true\n`,
111
+ );
112
+ write('components/Twice.doc.mjs', component('Twice'));
113
+ write('components/again/Twice.doc.mjs', component('Twice'));
114
+ write('shared/Linked.doc.mjs', component('Linked'));
115
+ fs.symlinkSync(
116
+ path.join(pkg, 'shared', 'Linked.doc.mjs'),
117
+ path.join(pkg, 'components', 'Linked.doc.mjs'),
118
+ );
119
+ template('templates/__tests__/tested.doc.mjs');
120
+ write('templates/orphan.doc.mjs', "export default {type: 'block'};\n");
121
+ // The template reader reads `__fixtures__`: a template doc there without
122
+ // its source is the package's, so it is checked.
123
+ write(
124
+ 'templates/__fixtures__/bad.doc.mjs',
125
+ "export default {type: 'block'};\n",
126
+ );
127
+ write('docs/__tests__/sample.doc.mjs', topic('sample'));
128
+ write('docs/.drafts/topic.doc.mjs', topic('topic'));
129
+ write('docs/.drafts/topic.doc.zh.mjs', 'export const docsZh = {};\n');
130
+ write('docs/copy.doc.mjs', topic('topic'));
131
+ write('docs/orphan.doc.dense.mjs', 'export const docsDense = {};\n');
132
+ write('themes/oceanTheme.doc.mjs', 'export default {};\n');
133
+ const integration = {
134
+ name: '@acme/widgets',
135
+ components: path.join(pkg, 'components'),
136
+ templates: path.join(pkg, 'templates'),
137
+ docs: path.join(pkg, 'docs'),
138
+ themes: path.join(pkg, 'themes'),
139
+ };
140
+
141
+ const {files, unread, fixtures} = await integrationDocFiles(integration);
142
+
143
+ // Component discovery skips `__tests__` and a `hidden` doc, and serves the
144
+ // first doc of a name; a template without its source, a second topic of
145
+ // a name, and an overlay without its topic are not served either. All of
146
+ // them ship, so all are checked, but a test fixture no reader serves.
147
+ const served = discoverIntegrationComponents(integration).map(c =>
148
+ path.relative(pkg, c.docPath),
149
+ );
150
+ expect(served.filter(file => file.endsWith('Twice.doc.mjs'))).toHaveLength(
151
+ 1,
152
+ );
153
+ expect(listed(files)).toEqual(
154
+ [
155
+ ...served.map(file => [file, 'components']),
156
+ ['components/Hidden.doc.mjs', 'components'],
157
+ ['components/again/Twice.doc.mjs', 'components'],
158
+ ['docs/.drafts/topic.doc.mjs', 'docs'],
159
+ ['docs/.drafts/topic.doc.zh.mjs', 'docs-overlay'],
160
+ ['docs/copy.doc.mjs', 'docs'],
161
+ ['docs/orphan.doc.dense.mjs', 'docs-overlay'],
162
+ ['templates/__fixtures__/bad.doc.mjs', 'templates'],
163
+ ['templates/__tests__/tested.doc.mjs', 'templates'],
164
+ ['templates/orphan.doc.mjs', 'templates'],
165
+ ].sort(),
166
+ );
167
+ // `components/__tests__/Tested` and `docs/__tests__/sample`.
168
+ expect(fixtures).toBe(2);
169
+ expect(served.sort()).toEqual(
170
+ expect.arrayContaining([
171
+ 'components/.drafts/Draft.doc.mjs',
172
+ 'components/Linked.doc.mjs',
173
+ 'components/__fixtures__/Fixture.doc.mjs',
174
+ ]),
175
+ );
176
+ expect(served.some(file => /Tested|Hidden/.test(file))).toBe(false);
177
+ // Theme discovery serves no theme from this root, so none is checked,
178
+ // and the root says why.
179
+ expect(unread).toEqual([
180
+ {
181
+ path: integration.themes,
182
+ reason: expect.stringMatching(
183
+ /^the themes root does not load, so no doc in it was checked: .*lower-kebab/,
184
+ ),
185
+ },
186
+ ]);
187
+ });
188
+
189
+ it("takes a scoped package's namespace docs and placed guides where they are, with each guide's overlays", async () => {
190
+ write(
191
+ 'docs/guides/guides.doc.mjs',
192
+ `export const docs = ${JSON.stringify({type: 'namespace', name: 'guides', title: 'Guides', summary: 'Every guide.', slots: {guides: {title: 'Guides', accepts: {kinds: ['generic']}}}})};\n`,
193
+ );
194
+ write(
195
+ 'docs/guides/setup.doc.mjs',
196
+ `export const docs = ${JSON.stringify({type: 'generic', name: 'setup', title: 'Set up', description: 'D', placement: {parent: 'namespace:guides', slot: 'guides', order: 1}, sections: [{title: 'S', content: [{type: 'prose', text: 'x'}]}]})};\n`,
197
+ );
198
+ write('docs/guides/setup.doc.zh.mjs', 'export const docsZh = {};\n');
199
+ write('docs/guides/setup.doc.dense.mjs', 'export const docsDense = {};\n');
200
+
201
+ const {files, unread} = await integrationDocFiles({
202
+ name: '@acme/widgets',
203
+ docs: path.join(pkg, 'docs'),
204
+ });
205
+
206
+ expect(unread).toEqual([]);
207
+ expect(listed(files)).toEqual([
208
+ ['docs/guides/guides.doc.mjs', 'docs'],
209
+ ['docs/guides/setup.doc.dense.mjs', 'docs-overlay'],
210
+ ['docs/guides/setup.doc.mjs', 'docs'],
211
+ ['docs/guides/setup.doc.zh.mjs', 'docs-overlay'],
212
+ ]);
213
+ });
214
+
215
+ it('leaves a root validate reports to that issue, and lists a root whose reader fails inside it', async () => {
216
+ write('components/Badge.doc.mjs', component('Badge'));
217
+ write('components/locked/Inner.doc.mjs', component('Inner'));
218
+ write('docs/guide.doc.mjs', topic('guide'));
219
+ const locked = path.join(pkg, 'components', 'locked');
220
+ fs.chmodSync(path.join(pkg, 'docs'), 0o000);
221
+ fs.chmodSync(locked, 0o000);
222
+ try {
223
+ const {files, unread} = await integrationDocFiles({
224
+ name: '@acme/widgets',
225
+ components: path.join(pkg, 'components'),
226
+ docs: path.join(pkg, 'docs'),
227
+ templates: path.join(pkg, 'missing'),
228
+ });
229
+
230
+ // `validate` reports the unreadable docs root and the missing templates
231
+ // root itself; the components root reads until its locked folder.
232
+ expect(files).toEqual([]);
233
+ expect(unread).toEqual([
234
+ {
235
+ path: path.join(pkg, 'components'),
236
+ reason: expect.stringMatching(
237
+ /^the components root does not load, so no doc in it was checked: .*EACCES/,
238
+ ),
239
+ },
240
+ ]);
241
+ } finally {
242
+ fs.chmodSync(path.join(pkg, 'docs'), 0o755);
243
+ fs.chmodSync(locked, 0o755);
244
+ }
245
+ });
246
+ });
@@ -2,7 +2,9 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * Resolve the project's own `typescript`, trying each directory in order.
5
+ * Resolve the project's own `typescript`, trying each directory in order;
6
+ * where it has no JavaScript compiler API (TypeScript 7), the TypeScript 6
7
+ * API package installed beside it.
6
8
  * @param {Array<string | null | undefined>} dirs
7
9
  * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
8
10
  * `ts: null` when a TypeScript is installed but has no `createProgram`
@@ -16,8 +18,15 @@ export function resolveProjectTypeScript(dirs: Array<string | null | undefined>)
16
18
  } | null;
17
19
  /**
18
20
  * Why a check that needs the compiler did not run, when the TypeScript
19
- * installed has no JavaScript compiler API.
21
+ * installed has no JavaScript compiler API, and what to do.
20
22
  * @param {string} version
21
23
  * @param {string} outcome what was not done, such as `docs were not checked`
22
24
  */
23
25
  export function unusableTypeScriptReason(version: string, outcome: string): string;
26
+ /**
27
+ * What to do when the project's TypeScript is missing or cannot be used:
28
+ * beside TypeScript 7, the TypeScript 6 API package it ships for tools;
29
+ * otherwise a version every check here reads, 5.0 (the oldest that checks a
30
+ * JavaScript doc) through 6.
31
+ */
32
+ export const TYPESCRIPT_FIX: "On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.";
@@ -15,7 +15,16 @@ import * as path from 'node:path';
15
15
  import {createRequire} from 'node:module';
16
16
 
17
17
  /**
18
- * Resolve the project's own `typescript`, trying each directory in order.
18
+ * The package TypeScript publishes beside TypeScript 7 for tools that need a
19
+ * JavaScript compiler API: TypeScript 6's. Kept in a constant so the type
20
+ * check does not treat the load as a static import of an uninstalled package.
21
+ */
22
+ const TYPESCRIPT_6_API = '@typescript/typescript6';
23
+
24
+ /**
25
+ * Resolve the project's own `typescript`, trying each directory in order;
26
+ * where it has no JavaScript compiler API (TypeScript 7), the TypeScript 6
27
+ * API package installed beside it.
19
28
  * @param {Array<string | null | undefined>} dirs
20
29
  * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
21
30
  * `ts: null` when a TypeScript is installed but has no `createProgram`
@@ -43,19 +52,38 @@ export function resolveProjectTypeScript(dirs) {
43
52
  unusable ??= installed();
44
53
  } catch {
45
54
  // Not installed from here, or installed without an entry this CLI can
46
- // load; try the next directory.
55
+ // load.
47
56
  unusable ??= installed();
48
57
  }
58
+ // TypeScript 7 has no JavaScript compiler API; the package TypeScript
59
+ // ships beside it for tools that need one carries TypeScript 6's.
60
+ try {
61
+ const ts = require(TYPESCRIPT_6_API);
62
+ if (ts && typeof ts.createProgram === 'function') {
63
+ return {ts, version: String(ts.version)};
64
+ }
65
+ } catch {
66
+ // Not installed from here; try the next directory.
67
+ }
49
68
  }
50
69
  return unusable ? {ts: null, version: unusable} : null;
51
70
  }
52
71
 
72
+ /**
73
+ * What to do when the project's TypeScript is missing or cannot be used:
74
+ * beside TypeScript 7, the TypeScript 6 API package it ships for tools;
75
+ * otherwise a version every check here reads, 5.0 (the oldest that checks a
76
+ * JavaScript doc) through 6.
77
+ */
78
+ export const TYPESCRIPT_FIX =
79
+ 'On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.';
80
+
53
81
  /**
54
82
  * Why a check that needs the compiler did not run, when the TypeScript
55
- * installed has no JavaScript compiler API.
83
+ * installed has no JavaScript compiler API, and what to do.
56
84
  * @param {string} version
57
85
  * @param {string} outcome what was not done, such as `docs were not checked`
58
86
  */
59
87
  export function unusableTypeScriptReason(version, outcome) {
60
- return `TypeScript ${version} is installed in this project, but it has no JavaScript compiler API (\`createProgram\`) to read types with, so ${outcome}.`;
88
+ return `TypeScript ${version} is installed in this project, but it has no JavaScript compiler API (\`createProgram\`) to read types with (TypeScript 7 ships none), so ${outcome}. ${TYPESCRIPT_FIX}`;
61
89
  }
@@ -13,7 +13,19 @@ export function comparePropTables(tables: PropDriftTable[], options: {
13
13
  resolveFrom: Array<string | null | undefined>;
14
14
  }): PropDriftReport;
15
15
  /**
16
- * @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch'} PropDriftKind
16
+ * Compare documented props with each component's TypeScript props: find each
17
+ * doc's prop tables, then compare them (`comparePropTables`).
18
+ * @param {PropDriftComponent[]} components
19
+ * @param {{packageDir: string, resolveFrom: Array<string | null | undefined>, loadDoc?: (docPath: string) => Promise<any>}} options
20
+ * @returns {Promise<PropDriftReport>}
21
+ */
22
+ export function comparePropDocs(components: PropDriftComponent[], options: {
23
+ packageDir: string;
24
+ resolveFrom: Array<string | null | undefined>;
25
+ loadDoc?: (docPath: string) => Promise<any>;
26
+ }): Promise<PropDriftReport>;
27
+ /**
28
+ * @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch' | 'type_mismatch'} PropDriftKind
17
29
  */
18
30
  /**
19
31
  * @typedef {object} PropDriftFinding
@@ -24,6 +36,10 @@ export function comparePropTables(tables: PropDriftTable[], options: {
24
36
  * @property {string} message
25
37
  * @property {string} doc the doc file, relative to the package root
26
38
  * @property {string} source the source file, relative to the package root
39
+ * @property {string} [docType] the documented type, as written
40
+ * @property {string} [codeType] the type as the source declares it
41
+ * @property {boolean} [docRequired]
42
+ * @property {boolean} [codeRequired]
27
43
  */
28
44
  /**
29
45
  * @typedef {object} PropDriftUnchecked
@@ -31,6 +47,15 @@ export function comparePropTables(tables: PropDriftTable[], options: {
31
47
  * @property {string} doc the doc file, relative to the package root
32
48
  * @property {string} reason why its props could not be read
33
49
  */
50
+ /**
51
+ * @typedef {object} PropDriftTypesNotCompared
52
+ * @property {string} component
53
+ * @property {string} doc the doc file, relative to the package root
54
+ * @property {string} reason why: not a form the check judges exactly, a
55
+ * field the prop's variants give different types, a standard prop
56
+ * (`className`, `style`, …), or a prop declared outside the package
57
+ * @property {string[]} props documented props whose types were not compared
58
+ */
34
59
  /**
35
60
  * @typedef {object} PropDriftReport
36
61
  * @property {'checked' | 'skipped'} status `skipped` means nothing was
@@ -38,12 +63,16 @@ export function comparePropTables(tables: PropDriftTable[], options: {
38
63
  * @property {string} [reason]
39
64
  * @property {string} [typescript] the version of the compiler that read the props
40
65
  * @property {number} components how many documented prop tables were compared
66
+ * @property {number} typesCompared how many documented prop types were judged
67
+ * @property {string} [typesSkipped] why no prop type was judged
41
68
  * @property {PropDriftFinding[]} findings
42
69
  * @property {PropDriftUnchecked[]} unchecked documented components whose props
43
70
  * could not be read from the source
44
71
  * @property {Array<PropDriftUnchecked & {props: string[]}>} [propsNotChecked]
45
72
  * props a mapped type builds from keys the check can't trace, which a doc
46
73
  * leaving out draws no warning for
74
+ * @property {PropDriftTypesNotCompared[]} typesNotCompared every other
75
+ * documented prop type, grouped by why it was not judged
47
76
  */
48
77
  /**
49
78
  * @typedef {object} PropDriftTable
@@ -52,6 +81,14 @@ export function comparePropTables(tables: PropDriftTable[], options: {
52
81
  * @property {any[]} props the table's entries
53
82
  * @property {string[]} sources the files that may hold the export, in order
54
83
  */
84
+ /**
85
+ * @typedef {object} PropDriftComponent
86
+ * @property {string} name
87
+ * @property {string} docPath absolute path to the component's `.doc.*` file
88
+ * @property {string | null} sourcePath absolute path to its same-stem
89
+ * source, or null when no file in the package declares it (a family member
90
+ * only another folder or built output defines)
91
+ */
55
92
  /**
56
93
  * Props a doc never needs to list: the internal and styling props the
57
94
  * `ComponentPropDoc` authoring guidance says to skip, `ref`, which Core's
@@ -59,7 +96,7 @@ export function comparePropTables(tables: PropDriftTable[], options: {
59
96
  */
60
97
  export const PROPS_NOT_DOCUMENTED: readonly string[];
61
98
  /** The line both surfaces print when the compiler is missing. */
62
- export const TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so documented props were not compared with the code. Install typescript and run this check again.";
99
+ export const TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so documented props were not compared with the code. On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.";
63
100
  export type CodeProp = {
64
101
  name: string;
65
102
  /**
@@ -81,12 +118,35 @@ export type CodeProp = {
81
118
  * its declaration carries an internal JSDoc tag
82
119
  */
83
120
  skipTagged: boolean;
121
+ /**
122
+ * the type as written, per own declaration
123
+ */
124
+ declared: string[];
125
+ /**
126
+ * the compiler's renderings, computed on demand
127
+ */
128
+ renderings: () => string[][];
84
129
  /**
85
130
  * the prop's type in each member of the props type
86
131
  */
87
132
  types: () => any[];
133
+ /**
134
+ * one member declares it more than once (an
135
+ * intersection), so no one declaration's text is its type
136
+ */
137
+ intersected: boolean;
138
+ /**
139
+ * the type an index signature gives
140
+ * the name in each member that lacks the prop; null when two signatures
141
+ * in one member take it
142
+ */
143
+ indexed: () => any[] | null;
144
+ /**
145
+ * where names in the prop's type resolve
146
+ */
147
+ location: any;
88
148
  };
89
- export type PropDriftKind = "not_in_code" | "not_in_doc" | "required_mismatch";
149
+ export type PropDriftKind = "not_in_code" | "not_in_doc" | "required_mismatch" | "type_mismatch";
90
150
  export type PropDriftFinding = {
91
151
  /**
92
152
  * the documented component (export) name
@@ -104,6 +164,16 @@ export type PropDriftFinding = {
104
164
  * the source file, relative to the package root
105
165
  */
106
166
  source: string;
167
+ /**
168
+ * the documented type, as written
169
+ */
170
+ docType?: string | undefined;
171
+ /**
172
+ * the type as the source declares it
173
+ */
174
+ codeType?: string | undefined;
175
+ docRequired?: boolean | undefined;
176
+ codeRequired?: boolean | undefined;
107
177
  };
108
178
  export type PropDriftUnchecked = {
109
179
  component: string;
@@ -116,6 +186,23 @@ export type PropDriftUnchecked = {
116
186
  */
117
187
  reason: string;
118
188
  };
189
+ export type PropDriftTypesNotCompared = {
190
+ component: string;
191
+ /**
192
+ * the doc file, relative to the package root
193
+ */
194
+ doc: string;
195
+ /**
196
+ * why: not a form the check judges exactly, a
197
+ * field the prop's variants give different types, a standard prop
198
+ * (`className`, `style`, …), or a prop declared outside the package
199
+ */
200
+ reason: string;
201
+ /**
202
+ * documented props whose types were not compared
203
+ */
204
+ props: string[];
205
+ };
119
206
  export type PropDriftReport = {
120
207
  /**
121
208
  * `skipped` means nothing was
@@ -131,6 +218,14 @@ export type PropDriftReport = {
131
218
  * how many documented prop tables were compared
132
219
  */
133
220
  components: number;
221
+ /**
222
+ * how many documented prop types were judged
223
+ */
224
+ typesCompared: number;
225
+ /**
226
+ * why no prop type was judged
227
+ */
228
+ typesSkipped?: string | undefined;
134
229
  findings: PropDriftFinding[];
135
230
  /**
136
231
  * documented components whose props
@@ -144,6 +239,11 @@ export type PropDriftReport = {
144
239
  propsNotChecked?: (PropDriftUnchecked & {
145
240
  props: string[];
146
241
  })[] | undefined;
242
+ /**
243
+ * every other
244
+ * documented prop type, grouped by why it was not judged
245
+ */
246
+ typesNotCompared: PropDriftTypesNotCompared[];
147
247
  };
148
248
  export type PropDriftTable = {
149
249
  /**
@@ -163,3 +263,16 @@ export type PropDriftTable = {
163
263
  */
164
264
  sources: string[];
165
265
  };
266
+ export type PropDriftComponent = {
267
+ name: string;
268
+ /**
269
+ * absolute path to the component's `.doc.*` file
270
+ */
271
+ docPath: string;
272
+ /**
273
+ * absolute path to its same-stem
274
+ * source, or null when no file in the package declares it (a family member
275
+ * only another folder or built output defines)
276
+ */
277
+ sourcePath: string | null;
278
+ };