@astryxdesign/cli 0.7.2-canary.6d4f178 → 0.7.2-canary.72db6f9

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 (276) hide show
  1. package/README.md +74 -73
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/component/_adapter.d.mts +31 -0
  4. package/api/component/_adapter.mjs +116 -0
  5. package/api/component/component.mjs +60 -10
  6. package/api/component/doc-links.test.mjs +386 -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/detail/doc/doc.mjs +9 -1
  13. package/api/discover/discover.d.mts +11 -0
  14. package/api/discover/discover.doc.mjs +7 -6
  15. package/api/discover/discover.mjs +107 -19
  16. package/api/discover/discover.type.d.mts +18 -7
  17. package/api/discover/discover.type.mjs +15 -7
  18. package/api/discover/list/list.d.mts +4 -3
  19. package/api/discover/list/list.mjs +17 -10
  20. package/api/docs/_adapter.d.mts +74 -0
  21. package/api/docs/_adapter.mjs +550 -14
  22. package/api/docs/integration-tree.test.mjs +22 -0
  23. package/api/docs/integrationDocs.test.mjs +124 -0
  24. package/api/docs/list/list.mjs +12 -2
  25. package/api/doctor/doctor.mjs +27 -3
  26. package/api/doctor/doctor.test.mjs +43 -0
  27. package/api/doctor/theme-checks.mjs +1 -1
  28. package/api/doctor/theme-checks.test.mjs +136 -0
  29. package/api/gap-report/gap-report.d.mts +3 -0
  30. package/api/gap-report/gap-report.doc.mjs +11 -3
  31. package/api/gap-report/gap-report.mjs +152 -48
  32. package/api/gap-report/gap-report.test.mjs +233 -0
  33. package/api/gap-report/gap-report.type.d.mts +41 -0
  34. package/api/gap-report/gap-report.type.mjs +18 -0
  35. package/api/index.d.mts +2 -0
  36. package/api/index.mjs +2 -0
  37. package/api/init/run/run.mjs +2 -2
  38. package/api/integration/_adapter.d.mts +45 -0
  39. package/api/integration/_adapter.mjs +112 -0
  40. package/api/integration/add-contribution.mjs +1 -1
  41. package/api/integration/add-contribution.test.mjs +4 -2
  42. package/api/integration/authoring-checks.mjs +108 -4
  43. package/api/integration/authoring-checks.test.mjs +808 -0
  44. package/api/integration/authoring-checks.type.d.mts +143 -0
  45. package/api/integration/authoring-checks.type.mjs +74 -2
  46. package/api/integration/check/check.d.mts +96 -0
  47. package/api/integration/check/check.mjs +357 -0
  48. package/api/integration/check/check.test.mjs +489 -0
  49. package/api/integration/integration-check.type.d.mts +118 -0
  50. package/api/integration/integration-check.type.mjs +84 -0
  51. package/api/integration/integrationCheck.doc.d.mts +10 -0
  52. package/api/integration/integrationCheck.doc.mjs +73 -0
  53. package/api/integration/integrationComponentConflicts.doc.mjs +45 -6
  54. package/api/integration/integrationDocConflicts.doc.mjs +22 -5
  55. package/api/integration/pack-check.mjs +296 -7
  56. package/api/integration/pack-check.test.mjs +367 -0
  57. package/api/integration/validate-integration-fixes.test.mjs +67 -0
  58. package/api/integration/validate-integration.mjs +36 -3
  59. package/api/integration/validate-integration.test.mjs +88 -8
  60. package/api/integration/validate-integration.type.d.mts +8 -0
  61. package/api/integration/validate-integration.type.mjs +12 -1
  62. package/api/integration/validateIntegration.doc.mjs +19 -3
  63. package/api/search/search.d.mts +72 -12
  64. package/api/search/search.domain-priority.test.mjs +108 -18
  65. package/api/search/search.integration-check.test.mjs +24 -0
  66. package/api/search/search.mjs +503 -38
  67. package/api/search/search.test.mjs +139 -0
  68. package/api/theme/build/build.family.test.mjs +54 -6
  69. package/api/theme/build/build.mjs +114 -17
  70. package/api/theme/themeBuild.doc.mjs +4 -4
  71. package/api/upgrade/_adapter.d.mts +40 -2
  72. package/api/upgrade/_adapter.mjs +117 -4
  73. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  74. package/api/upgrade/run/run.mjs +30 -1
  75. package/api/upgrade/status/status.d.mts +21 -5
  76. package/api/upgrade/status/status.mjs +45 -8
  77. package/api/upgrade/upgrade.doc.mjs +5 -3
  78. package/api/upgrade/upgrade.type.d.mts +23 -0
  79. package/api/upgrade/upgrade.type.mjs +16 -1
  80. package/assets/codemods/runner.mjs +7 -1
  81. package/assets/discover/official-packages.json +367 -0
  82. package/assets/docs/README.md +10 -0
  83. package/assets/docs/author-a-theme.doc.mjs +3 -3
  84. package/assets/docs/browser-support.doc.mjs +1 -1
  85. package/assets/docs/getting-started.doc.mjs +3 -3
  86. package/assets/docs/styling-overview.doc.mjs +1 -1
  87. package/assets/docs/theme.doc.dense.mjs +1 -1
  88. package/assets/docs/theme.doc.mjs +2 -2
  89. package/assets/docs/theme.doc.zh.mjs +1 -1
  90. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  91. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  92. package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
  93. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  94. package/assets/docs/tree/block-template.doc.mjs +8 -20
  95. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  96. package/assets/docs/tree/check-the-props.doc.mjs +201 -0
  97. package/assets/docs/tree/check-your-docs.doc.mjs +65 -7
  98. package/assets/docs/tree/checks.doc.mjs +25 -17
  99. package/assets/docs/tree/codemods.doc.mjs +4 -4
  100. package/assets/docs/tree/component-family.doc.mjs +3 -5
  101. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  102. package/assets/docs/tree/components.doc.mjs +1 -1
  103. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
  104. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  105. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  106. package/assets/docs/tree/docs.doc.mjs +3 -3
  107. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  108. package/assets/docs/tree/document-the-theme.doc.mjs +3 -3
  109. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  110. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  111. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  112. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  113. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  114. package/assets/docs/tree/integrations.doc.mjs +8 -0
  115. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  116. package/assets/docs/tree/layout.doc.mjs +6 -6
  117. package/assets/docs/tree/links.doc.mjs +6 -5
  118. package/assets/docs/tree/migration-setup.doc.mjs +3 -2
  119. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  120. package/assets/docs/tree/migration.doc.mjs +0 -1
  121. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  122. package/assets/docs/tree/page-template.doc.mjs +4 -8
  123. package/assets/docs/tree/publishing.doc.mjs +4 -4
  124. package/assets/docs/tree/quick-start.doc.mjs +38 -22
  125. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  126. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  127. package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
  128. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  129. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  130. package/assets/docs/tree/single-component.doc.mjs +14 -5
  131. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  132. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  133. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  134. package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
  135. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  136. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  137. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  138. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  139. package/assets/docs/tree/templates.doc.mjs +1 -1
  140. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  141. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  142. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  143. package/assets/docs/tree/troubleshooting.doc.mjs +8 -8
  144. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  145. package/assets/docs/tree/upgrading.doc.mjs +4 -4
  146. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  147. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  148. package/assets/docs/tree/versioning.doc.mjs +6 -6
  149. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  150. package/assets/docs/use-a-theme.doc.mjs +2 -2
  151. package/assets/theme.template.ts +1 -1
  152. package/authoring/codemod/codemod.doc.mjs +7 -3
  153. package/authoring/config/config.doc.mjs +9 -6
  154. package/authoring/config/type.ts +4 -2
  155. package/authoring/discover/discover.doc.mjs +1 -1
  156. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  157. package/authoring/doctypes/command/command.doc.mjs +14 -12
  158. package/authoring/doctypes/component/component.doc.mjs +29 -26
  159. package/authoring/doctypes/component/type.ts +15 -5
  160. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  161. package/authoring/doctypes/function/function.doc.mjs +9 -8
  162. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  163. package/authoring/doctypes/hook/type.ts +4 -0
  164. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  165. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  166. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  167. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  168. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  169. package/authoring/doctypes/template/parse.d.mts +6 -2
  170. package/authoring/doctypes/template/parse.mjs +3 -1
  171. package/authoring/doctypes/template/template.doc.mjs +3 -3
  172. package/authoring/doctypes/template/type.ts +22 -0
  173. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  174. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  175. package/authoring/identity/identity.doc.mjs +3 -3
  176. package/authoring/index.d.ts +1 -0
  177. package/authoring/integration/integration.doc.mjs +12 -4
  178. package/authoring/integration/parse.test.mjs +10 -0
  179. package/authoring/integration/schema.d.mts +2 -0
  180. package/authoring/integration/schema.mjs +1 -0
  181. package/authoring/integration/type.ts +4 -0
  182. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  183. package/clients/cli/commands/build-theme.mjs +1 -1
  184. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  185. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  186. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  187. package/clients/cli/commands/discover.doc.mjs +1 -1
  188. package/clients/cli/commands/discover.mjs +144 -93
  189. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  190. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  191. package/clients/cli/commands/doctor-integration-components.doc.mjs +18 -4
  192. package/clients/cli/commands/doctor-integration-docs.doc.mjs +19 -5
  193. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  194. package/clients/cli/commands/doctor-integration.test.mjs +884 -0
  195. package/clients/cli/commands/doctor.mjs +281 -5
  196. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  197. package/clients/cli/commands/gap-report.mjs +24 -2
  198. package/clients/cli/commands/gap-report.test.mjs +79 -0
  199. package/clients/cli/commands/integration-authoring.test.mjs +46 -0
  200. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  201. package/clients/cli/commands/integration-check.test.mjs +411 -0
  202. package/clients/cli/commands/integration.doc.mjs +6 -2
  203. package/clients/cli/commands/integration.mjs +116 -5
  204. package/clients/cli/commands/json-contract.test.mjs +5 -1
  205. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  206. package/clients/cli/commands/swizzle.mjs +5 -3
  207. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  208. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  209. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  210. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  211. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  212. package/clients/cli/index.mjs +30 -5
  213. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  214. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  215. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  216. package/foundation/agent-docs/agent-docs.mjs +8 -6
  217. package/foundation/config/project.mjs +82 -0
  218. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  219. package/foundation/discovery/component-discovery.d.mts +18 -0
  220. package/foundation/discovery/component-discovery.mjs +2 -2
  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-consistency.d.mts +34 -0
  225. package/foundation/discovery/doc-consistency.mjs +513 -0
  226. package/foundation/discovery/doc-consistency.test.mjs +347 -0
  227. package/foundation/discovery/doc-fluff.d.mts +112 -0
  228. package/foundation/discovery/doc-fluff.mjs +328 -0
  229. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  230. package/foundation/discovery/doc-types.d.mts +157 -0
  231. package/foundation/discovery/doc-types.mjs +1231 -0
  232. package/foundation/discovery/doc-types.test.mjs +744 -0
  233. package/foundation/discovery/docs-discovery.d.mts +88 -0
  234. package/foundation/discovery/docs-discovery.mjs +83 -2
  235. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  236. package/foundation/discovery/integration-doc-files.mjs +231 -0
  237. package/foundation/discovery/integration-doc-files.test.mjs +246 -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 +297 -0
  244. package/foundation/discovery/prop-drift.mjs +2428 -0
  245. package/foundation/discovery/prop-drift.test.mjs +2337 -0
  246. package/foundation/discovery/stray-pointers.d.mts +52 -0
  247. package/foundation/discovery/stray-pointers.mjs +293 -0
  248. package/foundation/discovery/stray-pointers.test.mjs +86 -0
  249. package/foundation/discovery/type-match.d.mts +53 -0
  250. package/foundation/discovery/type-match.mjs +660 -0
  251. package/foundation/discovery/type-match.test.mjs +169 -0
  252. package/foundation/discovery/type-text.d.mts +68 -0
  253. package/foundation/discovery/type-text.mjs +658 -0
  254. package/foundation/discovery/type-text.test.mjs +196 -0
  255. package/foundation/discovery/unresolved-references.d.mts +62 -0
  256. package/foundation/discovery/unresolved-references.mjs +790 -0
  257. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  258. package/foundation/doc-compiler/doc-loads.test.mjs +26 -0
  259. package/foundation/doc-compiler/links.d.mts +41 -5
  260. package/foundation/doc-compiler/links.mjs +167 -28
  261. package/foundation/doc-compiler/links.test.mjs +97 -4
  262. package/foundation/doc-compiler/tree.mjs +30 -1
  263. package/foundation/doc-compiler/tree.test.mjs +7 -0
  264. package/foundation/env/package-manager.d.mts +32 -0
  265. package/foundation/env/package-manager.mjs +47 -0
  266. package/foundation/env/package-manager.test.mjs +194 -7
  267. package/foundation/fs/module-loader.d.mts +2 -1
  268. package/foundation/fs/module-loader.mjs +60 -4
  269. package/foundation/fs/module-loader.test.mjs +194 -0
  270. package/foundation/integrations/contribution-inventory.d.mts +11 -0
  271. package/foundation/integrations/contribution-inventory.mjs +50 -2
  272. package/foundation/integrations/issue.ts +6 -0
  273. package/foundation/integrations/validate-contributions.mjs +30 -1
  274. package/foundation/response/response-types.doc.mjs +15 -9
  275. package/package.json +11 -11
  276. package/scripts/postinstall.mjs +3 -3
@@ -0,0 +1,210 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file readPackageTsconfig(): the package's own config, a solution-style
5
+ * config's references, a monorepo root's config for a local package but not
6
+ * an app's above an installed one, ambient declaration files, and a config
7
+ * with errors.
8
+ */
9
+
10
+ import * as fs from 'node:fs';
11
+ import * as os from 'node:os';
12
+ import * as path from 'node:path';
13
+ import {createRequire} from 'node:module';
14
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
15
+ import {readPackageTsconfig} from './package-tsconfig.mjs';
16
+
17
+ const require = createRequire(import.meta.url);
18
+ const ts = require('typescript');
19
+
20
+ /** @type {string} */
21
+ let root;
22
+
23
+ beforeEach(() => {
24
+ root = fs.realpathSync(
25
+ fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-tsconfig-')),
26
+ );
27
+ });
28
+
29
+ afterEach(() => {
30
+ fs.rmSync(root, {recursive: true, force: true});
31
+ });
32
+
33
+ /**
34
+ * @param {string} rel
35
+ * @param {string | object} content
36
+ */
37
+ function write(rel, content) {
38
+ const file = path.join(root, rel);
39
+ fs.mkdirSync(path.dirname(file), {recursive: true});
40
+ fs.writeFileSync(
41
+ file,
42
+ typeof content === 'string' ? content : JSON.stringify(content),
43
+ );
44
+ return file;
45
+ }
46
+
47
+ const OPTIONS = {strict: true, jsx: 'react-jsx', paths: {'@/*': ['./src/*']}};
48
+
49
+ describe('readPackageTsconfig', () => {
50
+ it('reads defaults without a config, and the config the package has, with the declaration files it includes', () => {
51
+ const source = write('src/Button.tsx', 'export {};\n');
52
+ const defaults = readPackageTsconfig(ts, root, [source]);
53
+ expect(defaults.options).toMatchObject({
54
+ jsx: ts.JsxEmit.ReactJSX,
55
+ strict: true,
56
+ noEmit: true,
57
+ });
58
+ expect(defaults.declarations).toEqual([]);
59
+ expect(defaults.error).toBeUndefined();
60
+
61
+ write('tsconfig.json', {
62
+ compilerOptions: OPTIONS,
63
+ include: ['src', 'types'],
64
+ });
65
+ const ambient = write('types/ambient.d.ts', 'interface A {}\n');
66
+ const global = write('src/global.ts', 'declare global {}\nexport {};\n');
67
+ // A script (no import or export) declares globals too, an `export`
68
+ // inside its namespace included.
69
+ const script = write('types/props.ts', 'interface ScriptProps {}\n');
70
+ const namespace = write(
71
+ 'types/acme.ts',
72
+ 'declare namespace Acme {\n export interface Props {}\n}\n',
73
+ );
74
+ write('src/module.ts', 'export interface ModuleProps {}\n');
75
+
76
+ const own = readPackageTsconfig(ts, root, [source]);
77
+
78
+ expect(own.options.paths).toEqual(OPTIONS.paths);
79
+ expect(own.declarations.sort()).toEqual(
80
+ [global, ambient, script, namespace].sort(),
81
+ );
82
+ });
83
+
84
+ it("follows a solution-style config's references, at any depth and through a cycle, to the config that includes the sources", () => {
85
+ const source = write('src/Button.tsx', 'export {};\n');
86
+ const chain = [
87
+ 'tsconfig.json',
88
+ 'l1.json',
89
+ 'l2.json',
90
+ 'l3.json',
91
+ 'l4.json',
92
+ 'l5.json',
93
+ ];
94
+ chain.forEach((file, i) =>
95
+ write(file, {
96
+ files: [],
97
+ // Each level also refers back to the root, a cycle tsc rejects but
98
+ // the walk must not loop on.
99
+ references: [
100
+ {path: `./${chain[i + 1] ?? 'app.json'}`},
101
+ {path: './tsconfig.json'},
102
+ ],
103
+ }),
104
+ );
105
+ write('app.json', {compilerOptions: OPTIONS, include: ['src']});
106
+
107
+ const project = readPackageTsconfig(ts, root, [source]);
108
+
109
+ expect(project.error).toBeUndefined();
110
+ expect(project.options.paths).toEqual(OPTIONS.paths);
111
+
112
+ // A reference that is missing or doesn't parse, when no config includes
113
+ // the sources, is the project's error, as `tsc` reports it.
114
+ write('tsconfig.json', {files: [], references: [{path: './gone.json'}]});
115
+ expect(readPackageTsconfig(ts, root, [source]).error).toMatch(
116
+ /^gone\.json: .*gone\.json/,
117
+ );
118
+ write('broken.json', '{"compilerOptions": ');
119
+ write('tsconfig.json', {files: [], references: [{path: './broken.json'}]});
120
+ expect(readPackageTsconfig(ts, root, [source]).error).toMatch(
121
+ /^broken\.json: /,
122
+ );
123
+ });
124
+
125
+ it("reads a monorepo root's config for a local package, and not an app's config for a package installed below it", () => {
126
+ write('tsconfig.json', {compilerOptions: OPTIONS});
127
+ const local = path.join(root, 'packages', 'local');
128
+ const installed = path.join(root, 'node_modules', '@acme', 'widgets');
129
+ const localSource = write('packages/local/src/Button.tsx', 'export {};\n');
130
+ const installedSource = write(
131
+ 'node_modules/@acme/widgets/src/Button.tsx',
132
+ 'export {};\n',
133
+ );
134
+
135
+ expect(readPackageTsconfig(ts, local, [localSource]).options.paths).toEqual(
136
+ OPTIONS.paths,
137
+ );
138
+ expect(
139
+ readPackageTsconfig(ts, installed, [installedSource]).options.paths,
140
+ ).toBeUndefined();
141
+ });
142
+
143
+ it('reports a config with errors instead of reading defaults', () => {
144
+ const source = write('src/Button.tsx', 'export {};\n');
145
+ write('tsconfig.json', {files: ['src/Button.tsx', 'src/missing.ts']});
146
+ expect(readPackageTsconfig(ts, root, [source]).error).toMatch(
147
+ /^tsconfig\.json: .*src\/missing\.ts.* not found/,
148
+ );
149
+
150
+ write('tsconfig.json', {extends: './missing-base.json'});
151
+ expect(readPackageTsconfig(ts, root, [source]).error).toMatch(
152
+ /^tsconfig\.json: .*missing-base\.json/,
153
+ );
154
+
155
+ write('tsconfig.json', '{"compilerOptions": ');
156
+ expect(readPackageTsconfig(ts, root, [source]).error).toMatch(
157
+ /^tsconfig\.json: /,
158
+ );
159
+ });
160
+
161
+ it('reads each `files` entry as `tsc` finds it', () => {
162
+ const source = write('src/Button.tsx', 'export {};\n');
163
+ write('src/Card.ts', 'export {};\n');
164
+ write('types/globals.ts', 'interface AcmeGlobal { tone?: string }\n');
165
+ write('configs/base.json', {files: ['${configDir}/src/Button.tsx']});
166
+ /** @type {(config: object) => any} */
167
+ const read = config => {
168
+ write('tsconfig.json', {compilerOptions: OPTIONS, ...config});
169
+ return readPackageTsconfig(ts, root, [source]);
170
+ };
171
+
172
+ // `${configDir}`, written in the package's config or in a shared base it
173
+ // extends, and an entry without its extension compile with `tsc -p`.
174
+ expect(
175
+ read({files: ['${configDir}/src/Button.tsx']}).error,
176
+ ).toBeUndefined();
177
+ expect(read({extends: './configs/base.json'}).error).toBeUndefined();
178
+ const bare = read({files: ['src/Button', 'src/Card', 'types/globals']});
179
+ expect(bare.error).toBeUndefined();
180
+ expect(bare.declarations).toEqual([path.join(root, 'types', 'globals.ts')]);
181
+
182
+ // An entry `tsc` can't find is an error: a missing file (TS6053), and a
183
+ // folder (TS6231).
184
+ expect(read({files: ['src/Button.tsx', 'src/gone.ts']}).error).toMatch(
185
+ /^tsconfig\.json: File 'src\/gone\.ts' not found\.$/,
186
+ );
187
+ expect(read({files: ['src']}).error).toMatch(
188
+ /^tsconfig\.json: Could not resolve the path 'src' with the extensions/,
189
+ );
190
+ });
191
+
192
+ it('reports only a missing `files` entry, not a file the `include` matched that is gone by the time it is read', () => {
193
+ const source = write('src/Button.tsx', 'export {};\n');
194
+ write('tsconfig.json', {compilerOptions: OPTIONS, include: ['src']});
195
+ // A file another process writes and removes while the config is read.
196
+ const gone = path.join(root, 'src', 'gone.ts');
197
+ const racing = {
198
+ ...ts,
199
+ sys: {
200
+ ...ts.sys,
201
+ readDirectory: (/** @type {any[]} */ ...args) => [
202
+ ...ts.sys.readDirectory(...args),
203
+ gone,
204
+ ],
205
+ },
206
+ };
207
+
208
+ expect(readPackageTsconfig(racing, root, [source]).error).toBeUndefined();
209
+ });
210
+ });
@@ -0,0 +1,32 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
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.
8
+ * @param {Array<string | null | undefined>} dirs
9
+ * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
10
+ * `ts: null` when a TypeScript is installed but has no `createProgram`
11
+ */
12
+ export function resolveProjectTypeScript(dirs: Array<string | null | undefined>): {
13
+ ts: any;
14
+ version: string;
15
+ } | {
16
+ ts: null;
17
+ version: string;
18
+ } | null;
19
+ /**
20
+ * Why a check that needs the compiler did not run, when the TypeScript
21
+ * installed has no JavaScript compiler API, and what to do.
22
+ * @param {string} version
23
+ * @param {string} outcome what was not done, such as `docs were not checked`
24
+ */
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.";
@@ -0,0 +1,89 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Find the project's own TypeScript compiler.
5
+ *
6
+ * @input Directories to resolve `typescript` from, in order.
7
+ * @output The compiler module and its version; or, when the only TypeScript
8
+ * installed has no JavaScript compiler API to read types with, its version
9
+ * alone; or null when none is installed.
10
+ * @position Shared by the author checks that read source with the project's
11
+ * compiler, so each finds it, and says why it cannot use it, the same way.
12
+ */
13
+
14
+ import * as path from 'node:path';
15
+ import {createRequire} from 'node:module';
16
+
17
+ /**
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.
28
+ * @param {Array<string | null | undefined>} dirs
29
+ * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
30
+ * `ts: null` when a TypeScript is installed but has no `createProgram`
31
+ */
32
+ export function resolveProjectTypeScript(dirs) {
33
+ /** @type {string | null} */
34
+ let unusable = null;
35
+ for (const dir of dirs) {
36
+ if (!dir) continue;
37
+ const require = createRequire(path.join(path.resolve(dir), 'package.json'));
38
+ /** The version of the `typescript` package installed here, or null. */
39
+ const installed = () => {
40
+ try {
41
+ const {version} = require('typescript/package.json');
42
+ return typeof version === 'string' && version !== '' ? version : null;
43
+ } catch {
44
+ return null;
45
+ }
46
+ };
47
+ try {
48
+ const ts = require('typescript');
49
+ if (ts && typeof ts.createProgram === 'function') {
50
+ return {ts, version: String(ts.version)};
51
+ }
52
+ unusable ??= installed();
53
+ } catch {
54
+ // Not installed from here, or installed without an entry this CLI can
55
+ // load.
56
+ unusable ??= installed();
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
+ }
68
+ }
69
+ return unusable ? {ts: null, version: unusable} : null;
70
+ }
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
+
81
+ /**
82
+ * Why a check that needs the compiler did not run, when the TypeScript
83
+ * installed has no JavaScript compiler API, and what to do.
84
+ * @param {string} version
85
+ * @param {string} outcome what was not done, such as `docs were not checked`
86
+ */
87
+ export function unusableTypeScriptReason(version, 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}`;
89
+ }
@@ -0,0 +1,297 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Compare each documented prop table with the TypeScript props of the export
6
+ * it describes.
7
+ * @param {PropDriftTable[]} tables
8
+ * @param {{packageDir: string, resolveFrom: Array<string | null | undefined>}} options
9
+ * @returns {PropDriftReport}
10
+ */
11
+ export function comparePropTables(tables: PropDriftTable[], options: {
12
+ packageDir: string;
13
+ resolveFrom: Array<string | null | undefined>;
14
+ }): PropDriftReport;
15
+ /**
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' | 'default_mismatch'} PropDriftKind
29
+ */
30
+ /**
31
+ * @typedef {object} PropDriftFinding
32
+ * @property {string} component the documented component (export) name
33
+ * @property {string} prop
34
+ * @property {PropDriftKind} kind
35
+ * @property {'warning'} severity
36
+ * @property {string} message
37
+ * @property {string} doc the doc file, relative to the package root
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]
43
+ * @property {string} [docDefault] the documented default, as written
44
+ * @property {string} [codeDefault] the literal default the code writes
45
+ * @property {string} [fix] what to change, ready to paste
46
+ */
47
+ /**
48
+ * @typedef {object} PropDriftUnchecked
49
+ * @property {string} component
50
+ * @property {string} doc the doc file, relative to the package root
51
+ * @property {string} reason why its props could not be read
52
+ */
53
+ /**
54
+ * @typedef {object} PropDriftTypesNotCompared
55
+ * @property {string} component
56
+ * @property {string} doc the doc file, relative to the package root
57
+ * @property {string} reason why: not a form the check judges exactly, a
58
+ * field the prop's variants give different types, a standard prop
59
+ * (`className`, `style`, …), a prop declared outside the package, or a
60
+ * default that is not a literal on one side
61
+ * @property {string[]} props documented props whose types, or defaults, were
62
+ * not compared
63
+ */
64
+ /**
65
+ * @typedef {object} PropDriftReport
66
+ * @property {'checked' | 'skipped'} status `skipped` means nothing was
67
+ * compared, and `reason` says why
68
+ * @property {string} [reason]
69
+ * @property {string} [typescript] the version of the compiler that read the props
70
+ * @property {number} components how many documented prop tables were compared
71
+ * @property {number} typesCompared how many documented prop types were judged
72
+ * @property {string} [typesSkipped] why no prop type was judged
73
+ * @property {PropDriftFinding[]} findings
74
+ * @property {PropDriftUnchecked[]} unchecked documented components whose props
75
+ * could not be read from the source
76
+ * @property {Array<PropDriftUnchecked & {props: string[]}>} [propsNotChecked]
77
+ * props a mapped type builds from keys the check can't trace, which a doc
78
+ * leaving out draws no warning for
79
+ * @property {PropDriftTypesNotCompared[]} typesNotCompared every other
80
+ * documented prop type, grouped by why it was not judged
81
+ */
82
+ /**
83
+ * @typedef {object} PropDriftTable
84
+ * @property {string} doc the doc file, relative to the package root
85
+ * @property {string} name the export the table documents
86
+ * @property {any[]} props the table's entries
87
+ * @property {string[]} sources the files that may hold the export, in order
88
+ */
89
+ /**
90
+ * @typedef {object} PropDriftComponent
91
+ * @property {string} name
92
+ * @property {string} docPath absolute path to the component's `.doc.*` file
93
+ * @property {string | null} sourcePath absolute path to its same-stem
94
+ * source, or null when no file in the package declares it (a family member
95
+ * only another folder or built output defines)
96
+ */
97
+ /**
98
+ * Props a doc never needs to list: the internal and styling props the
99
+ * `ComponentPropDoc` authoring guidance says to skip, `ref`, which Core's
100
+ * docs also leave out, and `key`, which React keeps for itself.
101
+ */
102
+ export const PROPS_NOT_DOCUMENTED: readonly string[];
103
+ /** The line both surfaces print when the compiler is missing. */
104
+ 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.";
105
+ export type CodeProp = {
106
+ name: string;
107
+ /**
108
+ * whether every caller must pass it: false
109
+ * when a member of the props type, an overload, or the package's
110
+ * `defaultProps` lets a caller leave it out
111
+ */
112
+ required: boolean;
113
+ /**
114
+ * declared in the package's own source, or built
115
+ * from keys it writes
116
+ */
117
+ own: boolean;
118
+ /**
119
+ * built from keys the check can't trace
120
+ */
121
+ untraced?: boolean | undefined;
122
+ /**
123
+ * its declaration carries an internal JSDoc tag
124
+ */
125
+ skipTagged: boolean;
126
+ /**
127
+ * the type as written, per own declaration
128
+ */
129
+ declared: string[];
130
+ /**
131
+ * the compiler's renderings, computed on demand
132
+ */
133
+ renderings: () => string[][];
134
+ /**
135
+ * the prop's type in each member of the props type
136
+ */
137
+ types: () => any[];
138
+ /**
139
+ * one member declares it more than once (an
140
+ * intersection), so no one declaration's text is its type
141
+ */
142
+ intersected: boolean;
143
+ /**
144
+ * the type an index signature gives
145
+ * the name in each member that lacks the prop; null when two signatures
146
+ * in one member take it
147
+ */
148
+ indexed: () => any[] | null;
149
+ /**
150
+ * where names in the prop's type resolve
151
+ */
152
+ location: any;
153
+ };
154
+ export type PropDriftKind = "not_in_code" | "not_in_doc" | "required_mismatch" | "type_mismatch" | "default_mismatch";
155
+ export type PropDriftFinding = {
156
+ /**
157
+ * the documented component (export) name
158
+ */
159
+ component: string;
160
+ prop: string;
161
+ kind: PropDriftKind;
162
+ severity: "warning";
163
+ message: string;
164
+ /**
165
+ * the doc file, relative to the package root
166
+ */
167
+ doc: string;
168
+ /**
169
+ * the source file, relative to the package root
170
+ */
171
+ source: string;
172
+ /**
173
+ * the documented type, as written
174
+ */
175
+ docType?: string | undefined;
176
+ /**
177
+ * the type as the source declares it
178
+ */
179
+ codeType?: string | undefined;
180
+ docRequired?: boolean | undefined;
181
+ codeRequired?: boolean | undefined;
182
+ /**
183
+ * the documented default, as written
184
+ */
185
+ docDefault?: string | undefined;
186
+ /**
187
+ * the literal default the code writes
188
+ */
189
+ codeDefault?: string | undefined;
190
+ /**
191
+ * what to change, ready to paste
192
+ */
193
+ fix?: string | undefined;
194
+ };
195
+ export type PropDriftUnchecked = {
196
+ component: string;
197
+ /**
198
+ * the doc file, relative to the package root
199
+ */
200
+ doc: string;
201
+ /**
202
+ * why its props could not be read
203
+ */
204
+ reason: string;
205
+ };
206
+ export type PropDriftTypesNotCompared = {
207
+ component: string;
208
+ /**
209
+ * the doc file, relative to the package root
210
+ */
211
+ doc: string;
212
+ /**
213
+ * why: not a form the check judges exactly, a
214
+ * field the prop's variants give different types, a standard prop
215
+ * (`className`, `style`, …), a prop declared outside the package, or a
216
+ * default that is not a literal on one side
217
+ */
218
+ reason: string;
219
+ /**
220
+ * documented props whose types, or defaults, were
221
+ * not compared
222
+ */
223
+ props: string[];
224
+ };
225
+ export type PropDriftReport = {
226
+ /**
227
+ * `skipped` means nothing was
228
+ * compared, and `reason` says why
229
+ */
230
+ status: "checked" | "skipped";
231
+ reason?: string | undefined;
232
+ /**
233
+ * the version of the compiler that read the props
234
+ */
235
+ typescript?: string | undefined;
236
+ /**
237
+ * how many documented prop tables were compared
238
+ */
239
+ components: number;
240
+ /**
241
+ * how many documented prop types were judged
242
+ */
243
+ typesCompared: number;
244
+ /**
245
+ * why no prop type was judged
246
+ */
247
+ typesSkipped?: string | undefined;
248
+ findings: PropDriftFinding[];
249
+ /**
250
+ * documented components whose props
251
+ * could not be read from the source
252
+ */
253
+ unchecked: PropDriftUnchecked[];
254
+ /**
255
+ * props a mapped type builds from keys the check can't trace, which a doc
256
+ * leaving out draws no warning for
257
+ */
258
+ propsNotChecked?: (PropDriftUnchecked & {
259
+ props: string[];
260
+ })[] | undefined;
261
+ /**
262
+ * every other
263
+ * documented prop type, grouped by why it was not judged
264
+ */
265
+ typesNotCompared: PropDriftTypesNotCompared[];
266
+ };
267
+ export type PropDriftTable = {
268
+ /**
269
+ * the doc file, relative to the package root
270
+ */
271
+ doc: string;
272
+ /**
273
+ * the export the table documents
274
+ */
275
+ name: string;
276
+ /**
277
+ * the table's entries
278
+ */
279
+ props: any[];
280
+ /**
281
+ * the files that may hold the export, in order
282
+ */
283
+ sources: string[];
284
+ };
285
+ export type PropDriftComponent = {
286
+ name: string;
287
+ /**
288
+ * absolute path to the component's `.doc.*` file
289
+ */
290
+ docPath: string;
291
+ /**
292
+ * absolute path to its same-stem
293
+ * source, or null when no file in the package declares it (a family member
294
+ * only another folder or built output defines)
295
+ */
296
+ sourcePath: string | null;
297
+ };