@astryxdesign/cli 0.7.6-canary.df8928a → 0.7.6-canary.e0548a6

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 (541) hide show
  1. package/README.md +2 -2
  2. package/api/component/detail/showcase/showcase.mjs +9 -3
  3. package/api/search/_adapter.d.mts +3 -1
  4. package/api/search/_adapter.mjs +19 -19
  5. package/api/template/copy/copy.mjs +13 -7
  6. package/api/template/show/show.mjs +12 -8
  7. package/api/template/skeleton/skeleton.mjs +14 -5
  8. package/api/template/template.d.mts +1 -1
  9. package/api/template/template.doc.mjs +2 -2
  10. package/api/template/template.mjs +1 -0
  11. package/api/template/template.type.d.mts +2 -0
  12. package/api/template/template.type.mjs +2 -0
  13. package/assets/docs/author-a-theme.doc.mjs +3 -3
  14. package/assets/docs/motion.doc.mjs +40 -4
  15. package/assets/docs/tree/tokens-duration.doc.mjs +2 -2
  16. package/assets/docs/tree/tokens-ease.doc.mjs +10 -2
  17. package/assets/docs/tree/tokens.doc.mjs +1 -1
  18. package/assets/templates/blocks/components/BottomSheet/BottomSheetShowcase.doc.mjs +1 -1
  19. package/assets/templates/blocks/components/BottomSheet/BottomSheetShowcase.tsx +12 -12
  20. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
  21. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +14 -10
  22. package/assets/templates/blocks/components/Hooks/useCollatorHookUsage.doc.mjs +20 -0
  23. package/assets/templates/blocks/components/Hooks/useCollatorHookUsage.tsx +55 -0
  24. package/assets/templates/blocks/components/Hooks/useListFocusHookUsage.doc.mjs +14 -0
  25. package/assets/templates/blocks/components/Hooks/useListFocusHookUsage.tsx +42 -0
  26. package/assets/templates/blocks/components/Hooks/usePressFeedbackHookUsage.doc.mjs +14 -0
  27. package/assets/templates/blocks/components/Hooks/usePressFeedbackHookUsage.tsx +41 -0
  28. package/assets/templates/blocks/components/Hooks/useTranslatorHookUsage.doc.mjs +22 -0
  29. package/assets/templates/blocks/components/Hooks/useTranslatorHookUsage.tsx +88 -0
  30. package/assets/templates/blocks/components/Toast/useToastHookUsage.doc.mjs +14 -0
  31. package/assets/templates/blocks/components/Toast/useToastHookUsage.tsx +65 -0
  32. package/assets/theme.template.ts +20 -5
  33. package/clients/cli/commands/template.mjs +29 -3
  34. package/foundation/config/theme-private-vars.mjs +26 -6
  35. package/foundation/discovery/package-tsconfig.mjs +34 -0
  36. package/foundation/discovery/template-adapter.d.mts +76 -1
  37. package/foundation/discovery/template-adapter.mjs +418 -13
  38. package/foundation/discovery/template-icons.mjs +7 -89
  39. package/foundation/discovery/template-source-tree.d.mts +48 -0
  40. package/foundation/discovery/template-source-tree.mjs +159 -0
  41. package/foundation/fs/read-record.d.mts +4 -1
  42. package/foundation/fs/read-record.mjs +9 -5
  43. package/foundation/response/response-types.doc.mjs +2 -2
  44. package/package.json +24 -10
  45. package/api/api-docs-parse.test.mjs +0 -47
  46. package/api/blog/_adapter.test.mjs +0 -183
  47. package/api/blog/blog.test.mjs +0 -144
  48. package/api/blog/detail/detail.test.mjs +0 -118
  49. package/api/blog/list/list.test.mjs +0 -81
  50. package/api/build/blocks/blocks.test.mjs +0 -238
  51. package/api/build/build.test.mjs +0 -569
  52. package/api/build/kit/answer.test.mjs +0 -108
  53. package/api/build/kit/rank.test.mjs +0 -380
  54. package/api/build/kit/weights.test.mjs +0 -286
  55. package/api/build/tree.test.mjs +0 -185
  56. package/api/component/component-replacement.test.mjs +0 -616
  57. package/api/component/component.test.mjs +0 -532
  58. package/api/component/doc-links.test.mjs +0 -419
  59. package/api/component/integration-export-name.test.mjs +0 -644
  60. package/api/component/integration-import-agreement.test.mjs +0 -474
  61. package/api/discover/_adapter.test.mjs +0 -839
  62. package/api/discover/_catalog-view.test.mjs +0 -129
  63. package/api/discover/_package-scanner.test.mjs +0 -117
  64. package/api/discover/detail/detail.test.mjs +0 -145
  65. package/api/discover/detail/doc/doc.test.mjs +0 -93
  66. package/api/discover/detail/item/item.test.mjs +0 -75
  67. package/api/discover/discover.test.mjs +0 -100
  68. package/api/discover/list/list.test.mjs +0 -107
  69. package/api/discover/search/search.test.mjs +0 -319
  70. package/api/docs/compiled-topics.test.mjs +0 -94
  71. package/api/docs/detail/section/section.test.mjs +0 -92
  72. package/api/docs/docOverlays.test.mjs +0 -189
  73. package/api/docs/docs-homes.test.mjs +0 -127
  74. package/api/docs/docs.depth.test.mjs +0 -134
  75. package/api/docs/docs.test.mjs +0 -315
  76. package/api/docs/guide-route-targets.test.mjs +0 -1002
  77. package/api/docs/index/index.test.mjs +0 -67
  78. package/api/docs/integration-tree.test.mjs +0 -616
  79. package/api/docs/integrationDocs.test.mjs +0 -546
  80. package/api/docs/namespace-section.test.mjs +0 -260
  81. package/api/docs/react-version-sync.test.mjs +0 -79
  82. package/api/docs/reference-blocks.test.mjs +0 -404
  83. package/api/docs/token-tables.test.mjs +0 -93
  84. package/api/doctor/built-checks.test.mjs +0 -531
  85. package/api/doctor/doctor.test.mjs +0 -1651
  86. package/api/doctor/icon-sets.test.mjs +0 -111
  87. package/api/doctor/release-checks.test.mjs +0 -156
  88. package/api/doctor/theme-checks.test.mjs +0 -884
  89. package/api/gap-report/gap-report.test.mjs +0 -1549
  90. package/api/hook/detail/detail.test.mjs +0 -53
  91. package/api/hook/detail/params/params.test.mjs +0 -39
  92. package/api/hook/hook.test.mjs +0 -75
  93. package/api/icon/all-or-nothing.test.mjs +0 -283
  94. package/api/icon/error-codes.test.mjs +0 -341
  95. package/api/icon/experimental-markers.test.mjs +0 -93
  96. package/api/icon/icon.test.mjs +0 -506
  97. package/api/icon/new-definition/new-definition.undo.test.mjs +0 -97
  98. package/api/icon/new-set/new-set.test.mjs +0 -398
  99. package/api/icon/option-pairs.test.mjs +0 -368
  100. package/api/init/init.test.mjs +0 -319
  101. package/api/init/remove/remove.test.mjs +0 -124
  102. package/api/init/user/user.test.mjs +0 -232
  103. package/api/integration/add-contribution.component-names.test.mjs +0 -186
  104. package/api/integration/add-contribution.test.mjs +0 -990
  105. package/api/integration/add-helpers.test.mjs +0 -161
  106. package/api/integration/add-theme.test.mjs +0 -676
  107. package/api/integration/authoring-checks.test.mjs +0 -1683
  108. package/api/integration/check/check.test.mjs +0 -538
  109. package/api/integration/doc-stability.test.mjs +0 -216
  110. package/api/integration/example-checks.no-npm.test.mjs +0 -140
  111. package/api/integration/example-checks.test.mjs +0 -776
  112. package/api/integration/integration-block-exports.test.mjs +0 -248
  113. package/api/integration/pack-check.component-replaces.test.mjs +0 -126
  114. package/api/integration/pack-check.lifecycle-output.test.mjs +0 -149
  115. package/api/integration/pack-check.test.mjs +0 -2512
  116. package/api/integration/public-api.test.mjs +0 -21
  117. package/api/integration/template-conflict-compatibility.test.mjs +0 -73
  118. package/api/integration/validate-installed-icon-sets.test.mjs +0 -67
  119. package/api/integration/validate-integration-case-disk.test.mjs +0 -123
  120. package/api/integration/validate-integration-fixes.test.mjs +0 -1457
  121. package/api/integration/validate-integration-gaps.test.mjs +0 -1999
  122. package/api/integration/validate-integration.test.mjs +0 -835
  123. package/api/integration/validate-unread-theme-folders.test.mjs +0 -111
  124. package/api/json/envelope-types.test.mjs +0 -76
  125. package/api/json/parse.test.mjs +0 -76
  126. package/api/render/render.test.mjs +0 -1155
  127. package/api/search/_adapter.test.mjs +0 -192
  128. package/api/search/_doc-searcher.test.mjs +0 -36
  129. package/api/search/_entries.test.mjs +0 -48
  130. package/api/search/_main-searcher.test.mjs +0 -106
  131. package/api/search/_order.test.mjs +0 -72
  132. package/api/search/_template-searcher.test.mjs +0 -40
  133. package/api/search/search-return-type.test.mjs +0 -54
  134. package/api/search/search.domain-priority.test.mjs +0 -351
  135. package/api/search/search.family-members.test.mjs +0 -124
  136. package/api/search/search.family-word.test.mjs +0 -146
  137. package/api/search/search.integration-block.test.mjs +0 -100
  138. package/api/search/search.integration-check.test.mjs +0 -24
  139. package/api/search/search.test.mjs +0 -1007
  140. package/api/search/search.tie-order.test.mjs +0 -39
  141. package/api/search/tree.test.mjs +0 -66
  142. package/api/swizzle/_github.test.mjs +0 -53
  143. package/api/swizzle/copy/copy.test.mjs +0 -60
  144. package/api/swizzle/swizzle.test.mjs +0 -157
  145. package/api/template/cdn/cdn.test.mjs +0 -108
  146. package/api/template/checkout-wizard.test.mjs +0 -87
  147. package/api/template/copy/copy.receipt.test.mjs +0 -77
  148. package/api/template/copy/copy.test.mjs +0 -77
  149. package/api/template/data-token-fallbacks.test.mjs +0 -85
  150. package/api/template/discover-integration-templates.test.mjs +0 -56
  151. package/api/template/form-wizard-dialog.test.mjs +0 -47
  152. package/api/template/inline-wizard-template.test.mjs +0 -24
  153. package/api/template/list/list.test.mjs +0 -52
  154. package/api/template/show/show.test.mjs +0 -76
  155. package/api/template/table-filter-view-tabs.test.mjs +0 -45
  156. package/api/template/table-floating-bulk-actions.test.mjs +0 -66
  157. package/api/template/template-integration.test.mjs +0 -1274
  158. package/api/template/template-suffix.test.mjs +0 -286
  159. package/api/template/template.test.mjs +0 -222
  160. package/api/template/tokenizer-showcase.test.mjs +0 -47
  161. package/api/template/unknown-name.test.mjs +0 -63
  162. package/api/theme/add/add.test.mjs +0 -363
  163. package/api/theme/add/add.types.test.mjs +0 -150
  164. package/api/theme/build/build.adaptation-core-compat.test.mjs +0 -394
  165. package/api/theme/build/build.adaptation-enrollment.test.mjs +0 -219
  166. package/api/theme/build/build.core-on-demand.test.mjs +0 -113
  167. package/api/theme/build/build.family.test.mjs +0 -503
  168. package/api/theme/build/build.font-warning.test.mjs +0 -170
  169. package/api/theme/build/build.heading-core-compat.test.mjs +0 -68
  170. package/api/theme/build/build.icon-entry-variants.test.mjs +0 -134
  171. package/api/theme/build/build.icon-function-entries.test.mjs +0 -499
  172. package/api/theme/build/build.icon-lineage.test.mjs +0 -117
  173. package/api/theme/build/build.icon-preservation.test.mjs +0 -639
  174. package/api/theme/build/build.icon-variants.test.mjs +0 -105
  175. package/api/theme/build/build.icons-specifier.test.mjs +0 -149
  176. package/api/theme/build/build.packed-old-core.test.mjs +0 -1512
  177. package/api/theme/build/build.project-core.test.mjs +0 -220
  178. package/api/theme/build/build.public-component-vars.test.mjs +0 -151
  179. package/api/theme/build/build.receipt-doc.test.mjs +0 -111
  180. package/api/theme/build/build.rollback.test.mjs +0 -148
  181. package/api/theme/build/build.test.mjs +0 -1258
  182. package/api/theme/build/font-warning.test.mjs +0 -268
  183. package/api/theme/eject/eject.binary.test.mjs +0 -90
  184. package/api/theme/eject/eject.copy-compat.test.mjs +0 -168
  185. package/api/theme/eject/eject.rollback.test.mjs +0 -158
  186. package/api/theme/eject/eject.staging.test.mjs +0 -83
  187. package/api/theme/eject/eject.test.mjs +0 -160
  188. package/api/theme/integration-themes.test.mjs +0 -218
  189. package/api/theme/list/list.test.mjs +0 -271
  190. package/api/theme/palette/generate/generate.test.mjs +0 -445
  191. package/api/theme/palette/generate/generator.test.mjs +0 -385
  192. package/api/theme/palette/generate/preview.test.mjs +0 -55
  193. package/api/theme/remove/remove.test.mjs +0 -94
  194. package/api/theme/targets/targets.test.mjs +0 -91
  195. package/api/theme/template/template.test.mjs +0 -102
  196. package/api/theme/use/use.test.mjs +0 -98
  197. package/api/upgrade/list/list.test.mjs +0 -73
  198. package/api/upgrade/project-context.test.mjs +0 -272
  199. package/api/upgrade/provider-agreement.test.mjs +0 -152
  200. package/api/upgrade/registry/registry.test.mjs +0 -911
  201. package/api/upgrade/run/authoring-codemod-reachable.test.mjs +0 -99
  202. package/api/upgrade/run/cli-behind-core.test.mjs +0 -438
  203. package/api/upgrade/run/failure-receipt.test.mjs +0 -212
  204. package/api/upgrade/run/files-changed.test.mjs +0 -111
  205. package/api/upgrade/run/outcomes.test.mjs +0 -646
  206. package/api/upgrade/run/run.test.mjs +0 -511
  207. package/api/upgrade/upgrade.test.mjs +0 -594
  208. package/assets/codemods/__tests__/registry.test.mjs +0 -77
  209. package/assets/codemods/__tests__/rename-imperative-ref-to-handleRef.test.mjs +0 -65
  210. package/assets/codemods/__tests__/rename-isStreaming-to-isStopShown.test.mjs +0 -58
  211. package/assets/codemods/__tests__/rename-section-wash-to-muted.test.mjs +0 -103
  212. package/assets/codemods/__tests__/runner.symlinks.test.mjs +0 -205
  213. package/assets/codemods/__tests__/runner.test.mjs +0 -559
  214. package/assets/codemods/__tests__/runner.unparseable.test.mjs +0 -457
  215. package/assets/codemods/__tests__/toolbar-density-to-size.test.mjs +0 -69
  216. package/assets/codemods/__tests__/validation.test.mjs +0 -108
  217. package/assets/codemods/file-count.test.mjs +0 -163
  218. package/assets/codemods/integration-discovery.test.mjs +0 -360
  219. package/assets/codemods/integration-runner.protection.test.mjs +0 -206
  220. package/assets/codemods/outcome.test.mjs +0 -40
  221. package/assets/codemods/term-log.test.mjs +0 -80
  222. package/assets/codemods/transform-prop.test.mjs +0 -130
  223. package/assets/codemods/transforms/v0.0.10/__tests__/remove-size-props.test.mjs +0 -144
  224. package/assets/codemods/transforms/v0.0.12/__tests__/add-is-icon-only.test.mjs +0 -193
  225. package/assets/codemods/transforms/v0.0.13/__tests__/icon-name-deprecations.test.mjs +0 -81
  226. package/assets/codemods/transforms/v0.0.13/__tests__/rename-attachments-to-drawer.test.mjs +0 -126
  227. package/assets/codemods/transforms/v0.0.14/__tests__/rename-action-props.test.mjs +0 -129
  228. package/assets/codemods/transforms/v0.0.14/__tests__/rename-status-variants.test.mjs +0 -126
  229. package/assets/codemods/transforms/v0.0.15/__tests__/migrate-item-children-to-endcontent.test.mjs +0 -95
  230. package/assets/codemods/transforms/v0.0.15/__tests__/migrate-selector-children-to-render-option.test.mjs +0 -109
  231. package/assets/codemods/transforms/v0.0.15/__tests__/migrate-theme-selectors-to-data-attrs.test.mjs +0 -44
  232. package/assets/codemods/transforms/v0.0.15/__tests__/rename-date-picker-to-input.test.mjs +0 -110
  233. package/assets/codemods/transforms/v0.0.15/__tests__/rename-stack-element-to-as.test.mjs +0 -71
  234. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-badge-dot-to-statusdot.test.mjs +0 -137
  235. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-gap-to-numeric.test.mjs +0 -161
  236. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-isFullBleed-to-padding.test.mjs +0 -137
  237. package/assets/codemods/transforms/v0.0.2/__tests__/migrate-useXDSIcon-to-getIcon.test.mjs +0 -110
  238. package/assets/codemods/transforms/v0.0.2/__tests__/rename-banner-endButton-to-endContent.test.mjs +0 -61
  239. package/assets/codemods/transforms/v0.0.2/__tests__/rename-form-tooltip-startIcon.test.mjs +0 -130
  240. package/assets/codemods/transforms/v0.0.2/__tests__/rename-isShown-to-isOpen.test.mjs +0 -89
  241. package/assets/codemods/transforms/v0.0.2/__tests__/rename-selector-items-to-options.test.mjs +0 -74
  242. package/assets/codemods/transforms/v0.0.2/__tests__/rename-sidenav-header-to-heading.test.mjs +0 -140
  243. package/assets/codemods/transforms/v0.0.2/__tests__/rename-topnav-title-to-heading.test.mjs +0 -116
  244. package/assets/codemods/transforms/v0.0.2/__tests__/unify-uncontrolled-to-defaultX.test.mjs +0 -79
  245. package/assets/codemods/transforms/v0.0.2/__tests__/unify-visibility-to-onOpenChange.test.mjs +0 -130
  246. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-badge-children-to-label.test.mjs +0 -46
  247. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-collapse-to-collapsible.test.mjs +0 -72
  248. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-radius-tokens.test.mjs +0 -98
  249. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-shadow-tokens.test.mjs +0 -117
  250. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-skeleton-radius.test.mjs +0 -75
  251. package/assets/codemods/transforms/v0.0.6/__tests__/migrate-token-names.test.mjs +0 -275
  252. package/assets/codemods/transforms/v0.0.7/__tests__/rename-banner-variant-to-container.test.mjs +0 -85
  253. package/assets/codemods/transforms/v0.0.8/__tests__/migrate-token-renames.test.mjs +0 -327
  254. package/assets/codemods/transforms/v0.0.8/__tests__/rename-endslot-to-endcontent.test.mjs +0 -98
  255. package/assets/codemods/transforms/v0.1.0/__tests__/drop-xds-prefix-imports.test.mjs +0 -460
  256. package/assets/codemods/transforms/v0.1.0/__tests__/migrate-xds-css-surfaces.test.mjs +0 -103
  257. package/assets/codemods/transforms/v0.1.0/__tests__/migrate-xds-declare-module.test.mjs +0 -61
  258. package/assets/codemods/transforms/v0.1.0/__tests__/migrate-xds-module-specifiers.test.mjs +0 -123
  259. package/assets/codemods/transforms/v0.1.0/__tests__/v0.1.0-ordering.test.mjs +0 -104
  260. package/assets/codemods/transforms/v0.1.2/__tests__/rename-text-color-active-to-accent.test.mjs +0 -120
  261. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +0 -574
  262. package/assets/codemods/transforms/v0.1.5/__tests__/rename-switch-label-spacing-default-to-hug.test.mjs +0 -93
  263. package/assets/codemods/transforms/v0.1.7/__tests__/migrate-table-tableprops-to-direct-props.test.mjs +0 -120
  264. package/assets/codemods/transforms/v0.1.7/__tests__/rename-table-renderprops-styles-to-xstyle.test.mjs +0 -112
  265. package/assets/codemods/transforms/v0.1.8/__tests__/rename-avatar-size-scale.test.mjs +0 -129
  266. package/assets/codemods/transforms/v0.2.0/__tests__/remove-tablist-orientation.test.mjs +0 -81
  267. package/assets/codemods/transforms/v0.2.1/__tests__/migrate-dialog-position-to-logical.test.mjs +0 -119
  268. package/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.e2e.test.mjs +0 -296
  269. package/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.tsc.test.mjs +0 -139
  270. package/assets/codemods/transforms/v0.3.0/__tests__/migrate-authoring-imports.test.mjs +0 -80
  271. package/assets/codemods/transforms/v0.3.0/__tests__/migrate-grid-minchildwidth-to-columns.test.mjs +0 -82
  272. package/assets/codemods/transforms/v0.3.0/__tests__/next-codemods.test.mjs +0 -64
  273. package/assets/codemods/transforms/v0.3.0/__tests__/rename-authoring-doctypes.test.mjs +0 -94
  274. package/assets/codemods/transforms/v0.3.0/__tests__/rename-radiogroup-arialabel-to-label.test.mjs +0 -86
  275. package/assets/codemods/transforms/v0.3.0/__tests__/unwrap-authoring-factories.test.mjs +0 -170
  276. package/assets/codemods/transforms/v0.4.0/__tests__/migrate-table-rowexpansion-to-tree.test.mjs +0 -201
  277. package/assets/codemods/transforms/v0.4.0/__tests__/next-codemods.test.mjs +0 -154
  278. package/assets/codemods/transforms/v0.5.0/__tests__/next-codemods.test.mjs +0 -127
  279. package/assets/codemods/transforms/v0.6.0/__tests__/migrate-astryx-theme-selectors-to-data-attrs.test.mjs +0 -398
  280. package/assets/codemods/transforms/v0.6.0/__tests__/next-codemods.test.mjs +0 -270
  281. package/assets/codemods/transforms/v0.6.4/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -63
  282. package/assets/codemods/transforms/v0.6.4/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -220
  283. package/assets/codemods/transforms/v0.6.7/__tests__/migrate-copied-themes-to-descriptors.test.mjs +0 -129
  284. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +0 -523
  285. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-field-input-styling.test.mjs +0 -108
  286. package/assets/codemods/transforms/v0.7.0/__tests__/preserve-bottom-sheet-content-padding.test.mjs +0 -178
  287. package/assets/codemods/transforms/v0.7.0/__tests__/rename-empty-search-results-text.test.mjs +0 -202
  288. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +0 -168
  289. package/assets/codemods/transforms/v0.7.2/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +0 -120
  290. package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +0 -130
  291. package/authoring/_shared/errors.test.mjs +0 -49
  292. package/authoring/codemod/parse.test.mjs +0 -99
  293. package/authoring/config/debug-composition.test.mjs +0 -92
  294. package/authoring/config/parse.test.mjs +0 -121
  295. package/authoring/debug/parse.test.mjs +0 -187
  296. package/authoring/discover/parse.test.mjs +0 -158
  297. package/authoring/doctypes/doc-stability-types.test.mjs +0 -91
  298. package/authoring/doctypes/doctypes-new.test.mjs +0 -162
  299. package/authoring/doctypes/icon-definition/parse.test.mjs +0 -78
  300. package/authoring/doctypes/icon-set/icon-names.test.mjs +0 -26
  301. package/authoring/doctypes/icon-set/parse.test.mjs +0 -179
  302. package/authoring/doctypes/load-contract.test.mjs +0 -246
  303. package/authoring/doctypes/namespace/parse.test.mjs +0 -163
  304. package/authoring/doctypes/parse.test.mjs +0 -422
  305. package/authoring/doctypes/template/parse.test.mjs +0 -198
  306. package/authoring/gap-report/parse.test.mjs +0 -172
  307. package/authoring/integration/parse.test.mjs +0 -184
  308. package/authoring/shadcn/receipt.test.mjs +0 -187
  309. package/authoring/shadcn/source-variants.test.mjs +0 -120
  310. package/clients/cli/__tests__/cliManifest.test.ts +0 -37
  311. package/clients/cli/cli-command.test.mjs +0 -166
  312. package/clients/cli/cli-exit-codes.test.mjs +0 -163
  313. package/clients/cli/command-load-failure.test.mjs +0 -83
  314. package/clients/cli/command-result-coverage.test.mjs +0 -136
  315. package/clients/cli/commands/blog.test.mjs +0 -138
  316. package/clients/cli/commands/build-theme.adaptations.test.mjs +0 -773
  317. package/clients/cli/commands/build-theme.ascii-output.test.mjs +0 -198
  318. package/clients/cli/commands/build-theme.batch-report.test.mjs +0 -349
  319. package/clients/cli/commands/build-theme.color-scheme.test.mjs +0 -136
  320. package/clients/cli/commands/build-theme.data-tokens.test.mjs +0 -92
  321. package/clients/cli/commands/build-theme.flag-docs.test.mjs +0 -110
  322. package/clients/cli/commands/build-theme.font-warning.test.mjs +0 -170
  323. package/clients/cli/commands/build-theme.icons-specifier.test.mjs +0 -350
  324. package/clients/cli/commands/build-theme.import-path.test.mjs +0 -103
  325. package/clients/cli/commands/build-theme.multi.test.mjs +0 -148
  326. package/clients/cli/commands/build-theme.outside-project.test.mjs +0 -140
  327. package/clients/cli/commands/build-theme.path-safety.test.mjs +0 -398
  328. package/clients/cli/commands/build-theme.prose.test.mjs +0 -103
  329. package/clients/cli/commands/build-theme.registry.test.mjs +0 -160
  330. package/clients/cli/commands/build-theme.variants.test.mjs +0 -560
  331. package/clients/cli/commands/build-theme.watch.test.mjs +0 -320
  332. package/clients/cli/commands/build.error-codes.test.mjs +0 -50
  333. package/clients/cli/commands/build.exit-codes-doc.test.mjs +0 -54
  334. package/clients/cli/commands/build.playbook.test.mjs +0 -75
  335. package/clients/cli/commands/build.text-fields.test.mjs +0 -81
  336. package/clients/cli/commands/cli-postinstall.test.mjs +0 -90
  337. package/clients/cli/commands/component-batch.test.mjs +0 -341
  338. package/clients/cli/commands/component-ownership.test.mjs +0 -384
  339. package/clients/cli/commands/component-package.test.mjs +0 -169
  340. package/clients/cli/commands/component-replacement.text.test.mjs +0 -316
  341. package/clients/cli/commands/component-resolution.test.mjs +0 -204
  342. package/clients/cli/commands/component.test.mjs +0 -612
  343. package/clients/cli/commands/debug-result-summary.test.mjs +0 -214
  344. package/clients/cli/commands/detail-levels.test.mjs +0 -145
  345. package/clients/cli/commands/dialog-adaptive-template.test.mjs +0 -24
  346. package/clients/cli/commands/discover.broken-integration.test.mjs +0 -163
  347. package/clients/cli/commands/discover.components-flag.test.mjs +0 -97
  348. package/clients/cli/commands/discover.icon-sets.test.mjs +0 -133
  349. package/clients/cli/commands/discover.no-source.test.mjs +0 -490
  350. package/clients/cli/commands/discover.sources.test.mjs +0 -292
  351. package/clients/cli/commands/discover.text-projection.test.mjs +0 -103
  352. package/clients/cli/commands/docs.depth.test.mjs +0 -219
  353. package/clients/cli/commands/docs.test.mjs +0 -385
  354. package/clients/cli/commands/doctor-integration.package-json.test.mjs +0 -53
  355. package/clients/cli/commands/doctor-integration.test.mjs +0 -1483
  356. package/clients/cli/commands/doctor.test.mjs +0 -509
  357. package/clients/cli/commands/empty-argument.test.mjs +0 -16
  358. package/clients/cli/commands/external-showcase.test.mjs +0 -121
  359. package/clients/cli/commands/gap-report.test.mjs +0 -412
  360. package/clients/cli/commands/hook.text-projection.test.mjs +0 -45
  361. package/clients/cli/commands/icon-authoring.test.mjs +0 -2845
  362. package/clients/cli/commands/icon-options-wiring.test.mjs +0 -158
  363. package/clients/cli/commands/icon-sets-guide.test.mjs +0 -186
  364. package/clients/cli/commands/icon.test.mjs +0 -96
  365. package/clients/cli/commands/import-hint-correctness.test.mjs +0 -293
  366. package/clients/cli/commands/init.behavior.test.mjs +0 -434
  367. package/clients/cli/commands/init.flag-help.test.mjs +0 -151
  368. package/clients/cli/commands/init.next-steps.test.mjs +0 -41
  369. package/clients/cli/commands/integration-add.controls.test.mjs +0 -132
  370. package/clients/cli/commands/integration-authoring.test.mjs +0 -288
  371. package/clients/cli/commands/integration-check.test.mjs +0 -522
  372. package/clients/cli/commands/integration-real-world.test.mjs +0 -661
  373. package/clients/cli/commands/interactive-guard.test.mjs +0 -143
  374. package/clients/cli/commands/json-contract.test.mjs +0 -216
  375. package/clients/cli/commands/no-prompt-wording.test.mjs +0 -94
  376. package/clients/cli/commands/option-pair-refusals.test.mjs +0 -37
  377. package/clients/cli/commands/outside-project.test.mjs +0 -874
  378. package/clients/cli/commands/search.test.mjs +0 -514
  379. package/clients/cli/commands/setup-nudge.test.mjs +0 -280
  380. package/clients/cli/commands/silent-success-refusals.test.mjs +0 -15
  381. package/clients/cli/commands/swizzle.path-safety.test.mjs +0 -137
  382. package/clients/cli/commands/swizzle.routing.test.mjs +0 -342
  383. package/clients/cli/commands/template-cdn.behavior.test.mjs +0 -113
  384. package/clients/cli/commands/template.copy-receipt.test.mjs +0 -60
  385. package/clients/cli/commands/template.flag-help.test.mjs +0 -124
  386. package/clients/cli/commands/template.icons.test.mjs +0 -132
  387. package/clients/cli/commands/template.path-help.test.mjs +0 -40
  388. package/clients/cli/commands/template.path-safety.test.mjs +0 -82
  389. package/clients/cli/commands/template.show-media.test.mjs +0 -62
  390. package/clients/cli/commands/template.test.mjs +0 -62
  391. package/clients/cli/commands/text-json-parity.test.mjs +0 -850
  392. package/clients/cli/commands/theme-add-lifecycle.test.mjs +0 -228
  393. package/clients/cli/commands/theme-list.behavior.test.mjs +0 -51
  394. package/clients/cli/commands/theme-palette-generate.test.mjs +0 -154
  395. package/clients/cli/commands/theme-targets.behavior.test.mjs +0 -84
  396. package/clients/cli/commands/theme-template.behavior.test.mjs +0 -97
  397. package/clients/cli/commands/upgrade.ascii-output.test.mjs +0 -101
  398. package/clients/cli/commands/upgrade.config-ordering.test.mjs +0 -342
  399. package/clients/cli/commands/upgrade.file-protection.test.mjs +0 -404
  400. package/clients/cli/commands/upgrade.flag-help.test.mjs +0 -221
  401. package/clients/cli/commands/upgrade.hook-output.test.mjs +0 -89
  402. package/clients/cli/commands/upgrade.integration-policy.test.mjs +0 -581
  403. package/clients/cli/commands/upgrade.older-cli.test.mjs +0 -160
  404. package/clients/cli/commands/upgrade.outcomes.test.mjs +0 -350
  405. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +0 -97
  406. package/clients/cli/commands/upgrade.test.mjs +0 -361
  407. package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +0 -67
  408. package/clients/cli/commands/write-failure.test.mjs +0 -175
  409. package/clients/cli/e2e-smoke.test.mjs +0 -162
  410. package/clients/cli/error-envelope-code.test.mjs +0 -38
  411. package/clients/cli/formatters/index.test.mjs +0 -262
  412. package/clients/cli/latest-version-env.test.mjs +0 -50
  413. package/clients/cli/lib/cli-error.test.mjs +0 -206
  414. package/clients/cli/lib/component-format.test.mjs +0 -246
  415. package/clients/cli/lib/define-command.test.mjs +0 -103
  416. package/clients/cli/lib/doc-text-ascii.test.mjs +0 -85
  417. package/clients/cli/lib/exit-codes.test.mjs +0 -111
  418. package/clients/cli/lib/hook-format.test.mjs +0 -35
  419. package/clients/cli/lib/json-shim.test.mjs +0 -268
  420. package/clients/cli/lib/manifest.test.mjs +0 -346
  421. package/clients/cli/lib/parse-error-format.test.mjs +0 -81
  422. package/clients/cli/lib/resolve-theme.test.mjs +0 -543
  423. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +0 -1550
  424. package/foundation/agent-docs/agent-docs.test.mjs +0 -1937
  425. package/foundation/agent-docs/app-theme-workflow.test.mjs +0 -16
  426. package/foundation/agent-docs/computer-agent-text.test.mjs +0 -699
  427. package/foundation/config/config-cache.test.mjs +0 -83
  428. package/foundation/config/config-writer.test.mjs +0 -84
  429. package/foundation/config/integration-debug.test.mjs +0 -218
  430. package/foundation/config/project-themes.test.mjs +0 -119
  431. package/foundation/config/project.test.mjs +0 -931
  432. package/foundation/config/theme-private-vars.test.mjs +0 -55
  433. package/foundation/config/theme-state.test.mjs +0 -182
  434. package/foundation/debug/debug-fields.test.mjs +0 -327
  435. package/foundation/debug/integration-handlers.test.mjs +0 -267
  436. package/foundation/debug/on-event.test.mjs +0 -643
  437. package/foundation/debug/privacy-contract.test.mjs +0 -195
  438. package/foundation/debug/redact.test.mjs +0 -534
  439. package/foundation/discovery/authoring-self-docs.test.mjs +0 -202
  440. package/foundation/discovery/authoring-surface.test.mjs +0 -392
  441. package/foundation/discovery/cli-self-docs.test.mjs +0 -396
  442. package/foundation/discovery/component-discovery.export-names.test.mjs +0 -832
  443. package/foundation/discovery/component-discovery.importpath.test.mjs +0 -59
  444. package/foundation/discovery/component-discovery.test.mjs +0 -336
  445. package/foundation/discovery/component-loader.test.mjs +0 -190
  446. package/foundation/discovery/component-replacement.test.mjs +0 -520
  447. package/foundation/discovery/componentDocOverlay.test.mjs +0 -159
  448. package/foundation/discovery/copied-passages.test.mjs +0 -124
  449. package/foundation/discovery/doc-consistency.test.mjs +0 -347
  450. package/foundation/discovery/doc-fluff.test.mjs +0 -142
  451. package/foundation/discovery/doc-types.test.mjs +0 -774
  452. package/foundation/discovery/docs-discovery.test.mjs +0 -707
  453. package/foundation/discovery/docs-section-key.test.mjs +0 -246
  454. package/foundation/discovery/hook-discovery.test.mjs +0 -216
  455. package/foundation/discovery/icon-set-checks.test.mjs +0 -1018
  456. package/foundation/discovery/icon-set-discovery.test.mjs +0 -320
  457. package/foundation/discovery/icon-set-writer.test.mjs +0 -26
  458. package/foundation/discovery/integration-doc-files.test.mjs +0 -275
  459. package/foundation/discovery/module-exports.test.mjs +0 -209
  460. package/foundation/discovery/package-tsconfig.test.mjs +0 -210
  461. package/foundation/discovery/prop-drift.test.mjs +0 -2337
  462. package/foundation/discovery/runner-commands.test.mjs +0 -131
  463. package/foundation/discovery/stray-pointers.test.mjs +0 -92
  464. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +0 -284
  465. package/foundation/discovery/template-adapter.integration-isolation.test.mjs +0 -94
  466. package/foundation/discovery/template-adapter.test.mjs +0 -223
  467. package/foundation/discovery/template-conflict-release.test.mjs +0 -40
  468. package/foundation/discovery/template-icons.test.mjs +0 -560
  469. package/foundation/discovery/template-needs.test.mjs +0 -306
  470. package/foundation/discovery/theme-discovery.test.mjs +0 -775
  471. package/foundation/discovery/theme-imports.test.mjs +0 -173
  472. package/foundation/discovery/theming-targets.test.mjs +0 -328
  473. package/foundation/discovery/type-match.test.mjs +0 -169
  474. package/foundation/discovery/type-text.test.mjs +0 -196
  475. package/foundation/discovery/unresolved-references.test.mjs +0 -567
  476. package/foundation/doc-compiler/bundle.test.mjs +0 -266
  477. package/foundation/doc-compiler/doc-compiler.test.mjs +0 -714
  478. package/foundation/doc-compiler/doc-loads.test.mjs +0 -1762
  479. package/foundation/doc-compiler/doc-syntax.test.mjs +0 -383
  480. package/foundation/doc-compiler/inputs.test.mjs +0 -298
  481. package/foundation/doc-compiler/links.test.mjs +0 -285
  482. package/foundation/doc-compiler/lower-doc.test.mjs +0 -495
  483. package/foundation/doc-compiler/read.test.mjs +0 -380
  484. package/foundation/doc-compiler/split-topic-keywords.test.mjs +0 -74
  485. package/foundation/doc-compiler/tree.test.mjs +0 -691
  486. package/foundation/env/cli-command.test.mjs +0 -129
  487. package/foundation/env/node-version.test.mjs +0 -103
  488. package/foundation/env/package-manager.global.test.mjs +0 -66
  489. package/foundation/env/package-manager.test.mjs +0 -910
  490. package/foundation/env/search-path.test.mjs +0 -122
  491. package/foundation/env/semver.test.mjs +0 -111
  492. package/foundation/env/user-dirs.test.mjs +0 -72
  493. package/foundation/env/user-settings.test.mjs +0 -64
  494. package/foundation/fs/file-protection.test.mjs +0 -250
  495. package/foundation/fs/listing-cache.test.mjs +0 -88
  496. package/foundation/fs/module-loader.stdout.test.mjs +0 -333
  497. package/foundation/fs/module-loader.test.mjs +0 -410
  498. package/foundation/fs/path-safety.test.mjs +0 -222
  499. package/foundation/fs/paths.test.mjs +0 -725
  500. package/foundation/fs/publish-file-eperm-mutation.test.mjs +0 -64
  501. package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +0 -142
  502. package/foundation/fs/publish-file.test.mjs +0 -136
  503. package/foundation/fs/read-record.test.mjs +0 -164
  504. package/foundation/identity/provider-identity.test.mjs +0 -254
  505. package/foundation/integrations/autolink.test.mjs +0 -430
  506. package/foundation/integrations/cli-peer-version.test.mjs +0 -354
  507. package/foundation/integrations/cli-requirement.test.mjs +0 -383
  508. package/foundation/integrations/computer-integrations.test.mjs +0 -292
  509. package/foundation/integrations/contribution-inventory.test.mjs +0 -420
  510. package/foundation/integrations/integration-warnings.test.mjs +0 -191
  511. package/foundation/integrations/integrations.test.mjs +0 -818
  512. package/foundation/integrations/manifest-writer.test.mjs +0 -271
  513. package/foundation/integrations/provider-conflicts.test.mjs +0 -125
  514. package/foundation/integrations/provider-ledger.test.mjs +0 -275
  515. package/foundation/integrations/provider-resolution.test.mjs +0 -369
  516. package/foundation/integrations/public-imports.test.mjs +0 -1818
  517. package/foundation/release/cache.test.mjs +0 -923
  518. package/foundation/release/choose.test.mjs +0 -427
  519. package/foundation/release/global-state.test.mjs +0 -381
  520. package/foundation/release/handoff.e2e.test.mjs +0 -278
  521. package/foundation/release/notices.test.mjs +0 -586
  522. package/foundation/release/project.test.mjs +0 -288
  523. package/foundation/render/render.test.mjs +0 -117
  524. package/foundation/response/error-codes.test.mjs +0 -297
  525. package/foundation/response/json-contract.test.mjs +0 -235
  526. package/foundation/response/json-serialize.test.mjs +0 -66
  527. package/foundation/response/response-types.doc.test.mjs +0 -278
  528. package/foundation/route/route.test.mjs +0 -153
  529. package/foundation/runtime/hosted-runtime.test.mjs +0 -403
  530. package/foundation/runtime/package-set.test.mjs +0 -432
  531. package/foundation/text/copyright-header.test.mjs +0 -58
  532. package/foundation/text/levenshtein.test.mjs +0 -53
  533. package/foundation/text/string-utils.test.mjs +0 -175
  534. package/foundation/text/suggest-order.test.mjs +0 -312
  535. package/foundation/xle/browser-imports.test.mjs +0 -74
  536. package/foundation/xle/expand.test.mjs +0 -54
  537. package/foundation/xle/print.test.mjs +0 -50
  538. package/foundation/xle/registry.test.mjs +0 -28
  539. package/foundation/xle/xle.test.mjs +0 -382
  540. package/host/door-conformance.test.mjs +0 -274
  541. package/host/index.test.mjs +0 -302
@@ -1,2337 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Documented props against a component's TypeScript props: each kind
5
- * of finding, the loose type rules, the props a doc never needs, and the
6
- * visible skip when the project has no TypeScript.
7
- */
8
-
9
- import * as fs from 'node:fs';
10
- import * as os from 'node:os';
11
- import * as path from 'node:path';
12
- import {createRequire} from 'node:module';
13
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
14
- import {
15
- comparePropDocs,
16
- comparePropTables,
17
- PROPS_NOT_DOCUMENTED,
18
- TYPESCRIPT_MISSING_REASON,
19
- } from './prop-drift.mjs';
20
- import {unusableTypeScriptReason} from './project-typescript.mjs';
21
-
22
- const require = createRequire(import.meta.url);
23
- const TYPESCRIPT_DIR = path.dirname(require.resolve('typescript/package.json'));
24
-
25
- /** @type {string} */
26
- let pkg;
27
-
28
- beforeEach(() => {
29
- pkg = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-prop-drift-'));
30
- fs.writeFileSync(
31
- path.join(pkg, 'package.json'),
32
- JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
33
- );
34
- fs.writeFileSync(
35
- path.join(pkg, 'tsconfig.json'),
36
- JSON.stringify({
37
- compilerOptions: {
38
- strict: true,
39
- jsx: 'react-jsx',
40
- module: 'esnext',
41
- moduleResolution: 'bundler',
42
- target: 'es2022',
43
- },
44
- }),
45
- );
46
- });
47
-
48
- afterEach(() => {
49
- fs.rmSync(pkg, {recursive: true, force: true});
50
- });
51
-
52
- function withTypeScript() {
53
- fs.mkdirSync(path.join(pkg, 'node_modules'), {recursive: true});
54
- fs.symlinkSync(
55
- TYPESCRIPT_DIR,
56
- path.join(pkg, 'node_modules', 'typescript'),
57
- 'dir',
58
- );
59
- }
60
-
61
- /**
62
- * TypeScript 7 (no JavaScript compiler API) with the TypeScript 6 API package
63
- * beside it, which re-exports a real TypeScript.
64
- */
65
- function withTypeScript7AndItsTypeScript6Api() {
66
- const ts7 = path.join(pkg, 'node_modules', 'typescript');
67
- fs.mkdirSync(ts7, {recursive: true});
68
- fs.writeFileSync(
69
- path.join(ts7, 'package.json'),
70
- JSON.stringify({
71
- name: 'typescript',
72
- version: '7.0.2',
73
- exports: {'./package.json': './package.json'},
74
- }),
75
- );
76
- const ts6 = path.join(pkg, 'node_modules', '@typescript', 'typescript6');
77
- fs.mkdirSync(ts6, {recursive: true});
78
- fs.writeFileSync(
79
- path.join(ts6, 'package.json'),
80
- JSON.stringify({
81
- name: '@typescript/typescript6',
82
- version: '6.0.2',
83
- main: 'index.js',
84
- }),
85
- );
86
- fs.writeFileSync(
87
- path.join(ts6, 'index.js'),
88
- `module.exports = require(${JSON.stringify(TYPESCRIPT_DIR)});\n`,
89
- );
90
- }
91
-
92
- /**
93
- * Write `components/<name>.tsx` and its doc; returns its prop table, which
94
- * also carries the component record (name, docPath, sourcePath).
95
- * @param {string} name
96
- * @param {string} source
97
- * @param {Record<string, any>} doc
98
- */
99
- function component(name, source, doc) {
100
- const dir = path.join(pkg, 'components');
101
- fs.mkdirSync(dir, {recursive: true});
102
- const sourcePath = path.join(dir, `${name}.tsx`);
103
- const docPath = path.join(dir, `${name}.doc.mjs`);
104
- fs.writeFileSync(sourcePath, source);
105
- fs.writeFileSync(
106
- docPath,
107
- `export default ${JSON.stringify({
108
- type: 'component',
109
- name,
110
- displayName: name,
111
- description: 'Fixture.',
112
- ...doc,
113
- })};\n`,
114
- );
115
- return {
116
- name,
117
- docPath,
118
- sourcePath,
119
- doc: `components/${name}.doc.mjs`,
120
- props: doc.props ?? [],
121
- sources: [sourcePath],
122
- };
123
- }
124
-
125
- /**
126
- * @param {string} name
127
- * @param {string} type
128
- * @param {Record<string, unknown>} [extra]
129
- */
130
- const prop = (name, type, extra = {}) => ({
131
- name,
132
- type,
133
- description: 'Fixture prop.',
134
- ...extra,
135
- });
136
-
137
- /** @param {import('./prop-drift.mjs').PropDriftTable[]} tables */
138
- function compare(tables) {
139
- return comparePropTables(tables, {packageDir: pkg, resolveFrom: [pkg]});
140
- }
141
-
142
- /** @param {{findings: Array<{component: string, prop: string, kind: string}>}} report */
143
- const kinds = report =>
144
- report.findings.map(f => `${f.component}.${f.prop} ${f.kind}`);
145
-
146
- describe('comparePropTables', () => {
147
- it('judges the type of a prop a mapped type of the package builds, and says why one another package builds is not judged', async () => {
148
- withTypeScript();
149
- const sizes = path.join(pkg, 'node_modules', '@acme', 'sizes');
150
- fs.mkdirSync(sizes, {recursive: true});
151
- fs.writeFileSync(
152
- path.join(sizes, 'package.json'),
153
- JSON.stringify({name: '@acme/sizes', types: 'index.d.ts'}),
154
- );
155
- fs.writeFileSync(
156
- path.join(sizes, 'index.d.ts'),
157
- "export type Sizes = Partial<Record<'sm' | 'md', string>>;\n",
158
- );
159
- const tables = [
160
- component(
161
- 'Mapped',
162
- "export function Mapped(props: Partial<Record<'a' | 'b', 'x' | 'y'>>) { return null; }",
163
- {props: [prop('a', "'x' | 'z'"), prop('b', "'x' | 'y'")]},
164
- ),
165
- component(
166
- 'HandledCell',
167
- "import type {Sizes} from '@acme/sizes';\nexport function HandledCell(props: Sizes) { return null; }",
168
- {props: [prop('sm', 'number')]},
169
- ),
170
- // Keys the check can't trace, and a doc type that does not parse; and
171
- // a name that starts with another's sorts after it.
172
- component(
173
- 'Handled',
174
- "type A = string;\nexport function Handled(props: {[K in `on${'Open' | 'Close'}`]?: () => void} & {items?: ((items: A[]) => A)[]}) { return null; }",
175
- {props: [prop('onOpen', '() => A'), prop('items', '((A[]) => A)[]')]},
176
- ),
177
- ];
178
-
179
- const report = await compare(tables);
180
-
181
- expect(kinds(report)).toEqual(['Mapped.a type_mismatch']);
182
- expect(report.typesNotCompared).toEqual(
183
- [
184
- ['Handled', 'not a form the check judges exactly', ['items', 'onOpen']],
185
- ['HandledCell', 'declared outside the package, not compared', ['sm']],
186
- ].map(([component, reason, props]) => ({
187
- component,
188
- doc: `components/${component}.doc.mjs`,
189
- reason,
190
- props,
191
- })),
192
- );
193
- });
194
-
195
- it('judges no prop type, and says why, with a TypeScript older than 4.8', async () => {
196
- const dir = path.join(pkg, 'node_modules', 'typescript');
197
- fs.mkdirSync(dir, {recursive: true});
198
- fs.writeFileSync(path.join(dir, 'package.json'), '{"version": "4.7.4"}');
199
- const real = JSON.stringify(TYPESCRIPT_DIR);
200
- fs.writeFileSync(
201
- path.join(dir, 'index.js'),
202
- `module.exports = {...require(${real}), version: '4.7.4'};`,
203
- );
204
- const source = 'export function Badge(p: {size?: string}) { return null; }';
205
- const doc = {props: [prop('size', 'number')]};
206
-
207
- expect(await compare([component('Badge', source, doc)])).toMatchObject({
208
- findings: [],
209
- typesCompared: 0,
210
- typesSkipped:
211
- 'TypeScript 4.7.4 is older than 4.8, the oldest the type comparison reads; install TypeScript 5.0 through 6 (`npm install -D typescript@6`), or on TypeScript 7 add `@typescript/typescript6`, to judge them',
212
- });
213
- });
214
-
215
- it("judges a prop a package's mapping rewrites by its type, and keeps the text of one a mapping copies", async () => {
216
- withTypeScript();
217
- const types = `interface Base { size: 'sm' | 'md' }
218
- interface Opt { tone?: 'info' | undefined }
219
- type Many<T> = {[K in keyof T]: T[K][]};
220
- type Nullable<T> = {[K in keyof T]: T[K] | null};
221
- interface Pickable<T = string> { pick?: (value: T) => void }
222
- type ChooserProps<T extends string = string> = {pick?: string} & {
223
- change?: (value: readonly T[]) => void | Promise<void>;
224
- };
225
- interface ListProps<T> { value?: T; onChange?: (v: T) => void }
226
- type MultiProps<T> = ListProps<T[]>;
227
- import type {Item as Imported} from './item';
228
- import type * as NS from './item';
229
- interface Item { a: string }
230
- interface ItemList<Item> { items?: Item[] }`;
231
- const size = {props: [prop('size', "'sm' | 'md'", {required: true})]};
232
- const pick = {props: [prop('pick', '(value: T) => void')]};
233
- const tables = [
234
- ['Many', 'Many<Base>', size],
235
- ['Nulls', 'Nullable<Base>', size],
236
- ['Picked', "Pick<Base, 'size'>", size],
237
- [
238
- 'Strict',
239
- 'Required<Opt>',
240
- {props: [prop('tone', "'info' | undefined", {required: true})]},
241
- ],
242
- // A generic component's prop keeps its declaration's text; one a
243
- // concrete type instantiates does not.
244
- ['Boxed', 'Pickable<number>', pick],
245
- [
246
- 'Chooser',
247
- 'ChooserProps<T>',
248
- {
249
- props: [
250
- prop('pick', 'string'),
251
- prop('change', '(value: readonly T[]) => void | Promise<void>'),
252
- ],
253
- },
254
- '<T extends string = string>',
255
- ],
256
- // Instantiated with a type built from the component's own parameter,
257
- // the declaration's `T` is no longer the prop's type.
258
- // A type argument that prints with the parameter's name elsewhere is
259
- // still another type here.
260
- ['Renamed', 'ItemList<Imported>', {props: [prop('items', 'Item[]')]}],
261
- ['Spaced', 'ItemList<NS.Item>', {props: [prop('items', 'Item[]')]}],
262
- ['Owned', 'ItemList<Item>', {props: [prop('items', 'Item[]')]}],
263
- ...[
264
- ['Listed', 'ListProps<T[]>', 'T', '(v: T) => void'],
265
- ['Maybe', 'ListProps<T | null>', 'T', '(v: T) => void'],
266
- ['Multi', 'MultiProps<T>', 'T[]', '(v: T[]) => void'],
267
- ].map(([name, props, value, onChange]) => [
268
- name,
269
- props,
270
- {props: [prop('value', value), prop('onChange', onChange)]},
271
- '<T>',
272
- ]),
273
- ].map(([name, props, doc, generics = '']) =>
274
- component(
275
- name,
276
- `${types}\nexport function ${name}${generics}(props: ${props}) { return null; }`,
277
- doc,
278
- ),
279
- );
280
-
281
- fs.writeFileSync(
282
- path.join(pkg, 'components', 'item.ts'),
283
- 'export interface Item { b: number }\n',
284
- );
285
- const report = await compare(tables);
286
-
287
- expect(kinds(report)).toEqual([
288
- 'Many.size type_mismatch',
289
- 'Nulls.size type_mismatch',
290
- 'Strict.tone type_mismatch',
291
- ]);
292
- // A message shows the type the mapping makes, not the source's text.
293
- expect(report.findings.map(f => f.codeType)).toEqual([
294
- "('sm' | 'md')[]",
295
- "'sm' | 'md' | null",
296
- "'info'",
297
- ]);
298
- expect(report.typesNotCompared).toEqual(
299
- [
300
- ['Boxed', ['pick']],
301
- ['Listed', ['onChange', 'value']],
302
- ['Maybe', ['onChange', 'value']],
303
- ['Renamed', ['items']],
304
- ['Spaced', ['items']],
305
- ].map(([component, props]) => ({
306
- component,
307
- doc: `components/${component}.doc.mjs`,
308
- reason: 'not a form the check judges exactly',
309
- props,
310
- })),
311
- );
312
- });
313
-
314
- it("reports a prop missing from the code, one missing from the doc, a wrong required flag, and a wrong type, each component's together", async () => {
315
- withTypeScript();
316
- const badge = component(
317
- 'Badge',
318
- `export type Tone = 'neutral' | 'info' | 'danger';
319
- export interface BadgeProps {
320
- label: string;
321
- tone?: Tone;
322
- count?: number;
323
- }
324
- export function Badge(props: BadgeProps) { return null; }`,
325
- {
326
- props: [
327
- prop('label', 'string'),
328
- prop('tone', "'neutral' | 'info'"),
329
- prop('size', "'sm' | 'md'"),
330
- ],
331
- },
332
- );
333
- // A name that starts with another's sorts after all of the other's.
334
- const count = component(
335
- 'BadgeCount',
336
- 'export function BadgeCount(props: {amount?: number}) { return null; }',
337
- {props: []},
338
- );
339
-
340
- const report = await compare([count, badge]);
341
-
342
- expect(report.status).toBe('checked');
343
- expect(report.typescript).toMatch(/^\d+\.\d+/);
344
- expect(report.components).toBe(2);
345
- expect(kinds(report)).toEqual([
346
- 'Badge.count not_in_doc',
347
- 'Badge.label required_mismatch',
348
- 'Badge.size not_in_code',
349
- 'Badge.tone type_mismatch',
350
- 'BadgeCount.amount not_in_doc',
351
- ]);
352
- expect(report.findings.every(f => f.severity === 'warning')).toBe(true);
353
- expect(report.findings.find(f => f.kind === 'type_mismatch')).toMatchObject(
354
- {
355
- docType: "'neutral' | 'info'",
356
- codeType: 'Tone',
357
- doc: 'components/Badge.doc.mjs',
358
- source: 'components/Badge.tsx',
359
- message: expect.stringContaining(
360
- "Tone ('neutral' | 'info' | 'danger')",
361
- ),
362
- },
363
- );
364
- expect(
365
- report.findings.find(f => f.kind === 'required_mismatch'),
366
- ).toMatchObject({docRequired: false, codeRequired: true});
367
- });
368
-
369
- it('compares a documented default with a literal default in the props destructuring, quotes and whitespace aside, and skips any other default', async () => {
370
- withTypeScript();
371
- const widget = component(
372
- 'Widget',
373
- `const SIZE = 'md';
374
- export interface WidgetProps { size?: 'sm' | 'md'; tone?: string; count?: number; open?: boolean; label?: string; gap?: number; mode?: string }
375
- export function Widget({size = 'md', tone = "info", count = -2, open = false, label = SIZE, gap = 4, mode}: WidgetProps) { return null; }`,
376
- {
377
- props: [
378
- prop('size', "'sm' | 'md'", {default: "'sm'"}),
379
- prop('tone', 'string', {default: ' "info" '}),
380
- prop('count', 'number', {default: '-2'}),
381
- prop('open', 'boolean', {default: 'true'}),
382
- prop('label', 'string', {default: "'x'"}),
383
- prop('gap', 'number', {default: 'the theme gap'}),
384
- prop('mode', 'string', {default: "'a'"}),
385
- ],
386
- },
387
- );
388
- const forwarded = component(
389
- 'Forwarded',
390
- `declare function forwardRef<T>(render: T): T;
391
- export const Forwarded = forwardRef(function Forwarded({variant = 'solid'}: {variant?: string}) { return null; });`,
392
- {props: [prop('variant', 'string', {default: "'ghost'"})]},
393
- );
394
-
395
- const report = await compare([widget, forwarded]);
396
-
397
- expect(kinds(report)).toEqual([
398
- 'Forwarded.variant default_mismatch',
399
- 'Widget.open default_mismatch',
400
- 'Widget.size default_mismatch',
401
- ]);
402
- // A default that is not a literal on either side is listed, not skipped.
403
- expect(report.typesNotCompared).toEqual(
404
- expect.arrayContaining([
405
- expect.objectContaining({
406
- component: 'Widget',
407
- reason: expect.stringContaining(
408
- 'default in the code is not a literal',
409
- ),
410
- props: ['label'],
411
- }),
412
- expect.objectContaining({
413
- component: 'Widget',
414
- reason: expect.stringContaining(
415
- 'documented default is not a literal',
416
- ),
417
- props: ['gap'],
418
- }),
419
- ]),
420
- );
421
- expect(report.typesNotCompared.flatMap(entry => entry.props)).not.toContain(
422
- 'mode',
423
- );
424
- expect(report.findings.find(f => f.prop === 'size')).toMatchObject({
425
- severity: 'warning',
426
- message:
427
- "\"size\" is documented with default 'sm', but the code defaults it to 'md'.",
428
- fix: 'In components/Widget.doc.mjs, set the "size" prop\'s default to the code\'s: default: "\'md\'".',
429
- docDefault: "'sm'",
430
- codeDefault: "'md'",
431
- });
432
- });
433
-
434
- it("judges a field, a name an index signature takes, and a prop declared in another file by the type's name where the prop is declared, not by the name the type was declared with", async () => {
435
- withTypeScript();
436
- const dir = path.join(pkg, 'components');
437
- fs.mkdirSync(dir, {recursive: true});
438
- fs.writeFileSync(
439
- path.join(dir, 'base.ts'),
440
- "export interface Item { id: string }\nexport type Size = 'sm' | 'md';\n",
441
- );
442
- // Another file imports the same types under other names, and declares
443
- // its own `Item` and `Size`.
444
- fs.writeFileSync(
445
- path.join(dir, 'types.ts'),
446
- [
447
- "import type {Item as BaseItem, Size as BaseSize} from './base';",
448
- 'interface Item { label: string }',
449
- "type Size = 'lg';",
450
- 'export type ElsewhereProps = { size?: BaseSize; item?: BaseItem; onPick?: (item: BaseItem) => void; cfg?: {item: BaseItem}; [key: `size-${string}`]: BaseSize | undefined } & Required<Partial<{tone: BaseSize; entry: BaseItem}>>;',
451
- ].join('\n'),
452
- );
453
- const here = component(
454
- 'Renamed',
455
- [
456
- "import type {Item as BaseItem, Size as BaseSize} from './base';",
457
- 'interface Item { label: string }',
458
- "type Size = 'lg';",
459
- 'export function Renamed(props: {cfg?: {item: BaseItem}; [key: `size-${string}`]: BaseSize | undefined}) { return null; }',
460
- ].join('\n'),
461
- {props: [prop('cfg.item', 'Item'), prop('size-a', 'Size')]},
462
- );
463
- const elsewhere = component(
464
- 'Elsewhere',
465
- "import type {ElsewhereProps} from './types';\nexport function Elsewhere(props: ElsewhereProps) { return null; }",
466
- {
467
- props: [
468
- prop('size', 'Size'),
469
- prop('tone', 'Size', {required: true}),
470
- prop('entry', 'Item', {required: true}),
471
- prop('item', 'Item'),
472
- prop('onPick', '(item: Item) => void'),
473
- prop('cfg.item', 'Item'),
474
- prop('size-a', 'Size'),
475
- ],
476
- },
477
- );
478
- // The same docs, naming the types as each file does, are judged matches.
479
- const named = component(
480
- 'Named',
481
- [
482
- "import type {Item as BaseItem, Size as BaseSize} from './base';",
483
- 'export function Named(props: {cfg?: {item: BaseItem}; [key: `size-${string}`]: BaseSize | undefined}) { return null; }',
484
- ].join('\n'),
485
- {props: [prop('cfg.item', 'BaseItem'), prop('size-a', 'BaseSize')]},
486
- );
487
-
488
- const report = await compare([here, elsewhere, named]);
489
-
490
- // `Size` is `'lg'` where each prop is declared, which TypeScript rejects
491
- // for `'sm' | 'md'`; `Item` is an object type there, not compared.
492
- expect(kinds(report)).toEqual([
493
- 'Elsewhere.size type_mismatch',
494
- 'Elsewhere.size-a type_mismatch',
495
- 'Elsewhere.tone type_mismatch',
496
- 'Renamed.size-a type_mismatch',
497
- ]);
498
- expect(report.typesNotCompared).toEqual([
499
- expect.objectContaining({
500
- component: 'Elsewhere',
501
- props: ['cfg.item', 'entry', 'item', 'onPick'],
502
- }),
503
- expect.objectContaining({component: 'Renamed', props: ['cfg.item']}),
504
- ]);
505
- expect(report.typesCompared).toBe(6);
506
- });
507
-
508
- it("reads `React.X` as React's own where the prop is declared, never as a bare name that means another type there", async () => {
509
- withTypeScript();
510
- fs.mkdirSync(path.join(pkg, 'node_modules', '@types'), {recursive: true});
511
- fs.symlinkSync(
512
- path.dirname(require.resolve('@types/react/package.json')),
513
- path.join(pkg, 'node_modules', '@types', 'react'),
514
- 'dir',
515
- );
516
- const keys = component(
517
- 'Keys',
518
- [
519
- "import * as React from 'react';",
520
- "type Key = 'a' | 'b';",
521
- 'export function Keys(props: {onKey?: (event: KeyboardEvent) => void; rowKey?: string | number | bigint; pick?: Key; native?: React.Key}) { return null; }',
522
- ].join('\n'),
523
- {
524
- props: [
525
- prop('onKey', '(event: React.KeyboardEvent) => void'),
526
- prop('rowKey', 'React.Key'),
527
- prop('pick', 'React.Key'),
528
- prop('native', 'React.Key'),
529
- ],
530
- },
531
- );
532
- // React's global namespace, with no import.
533
- const global = component(
534
- 'GlobalKeys',
535
- 'export function GlobalKeys(props: {rowKey?: string | number | bigint}) { return null; }',
536
- {props: [prop('rowKey', 'React.Key')]},
537
- );
538
-
539
- const report = await compare([keys, global]);
540
-
541
- // The DOM's `KeyboardEvent` is not React's, and the file's own `Key` is
542
- // not `React.Key`.
543
- expect(kinds(report)).toEqual(['Keys.pick type_mismatch']);
544
- expect(report.typesNotCompared).toEqual([
545
- expect.objectContaining({component: 'Keys', props: ['onKey']}),
546
- ]);
547
- expect(report.typesCompared).toBe(4);
548
- });
549
-
550
- it('judges primitives, literals, arrays, string enums, and names for them exactly, in any order', async () => {
551
- withTypeScript();
552
- const card = component(
553
- 'Card',
554
- [
555
- "type Tone = 'neutral' | 'info';",
556
- "export enum Color { Red = 'red', Blue = 'blue' } export enum Hue { Red = 'red', Blue = 'blue' }",
557
- 'export interface CardProps {',
558
- ' label: string;',
559
- ' tone?: Tone;',
560
- ' items?: ReadonlyArray<string>;',
561
- ' isOpen?: boolean;',
562
- " size?: 'sm' | 'md' | number;",
563
- ' color?: Color;',
564
- ' count?: number;',
565
- ' ids?: string[];',
566
- ' hue?: Color;',
567
- " shade?: Color; shades?: Color[]; pick?: 'red' | 'blue';",
568
- '}',
569
- 'export function Card(props: CardProps) { return null; }',
570
- ].join('\n'),
571
- {
572
- props: [
573
- prop('label', 'string', {required: true}),
574
- prop('tone', '\'info\' | "neutral"'),
575
- prop('items', 'Array<string>'),
576
- prop('isOpen', 'true | false'),
577
- prop('size', "number | 'md' | 'sm'"),
578
- prop('color', 'Color'),
579
- prop('count', 'string'),
580
- prop('ids', 'number[]'),
581
- prop('hue', "'red' | 'blue'"),
582
- prop('shade', 'Hue'),
583
- prop('shades', 'Hue[]'),
584
- prop('pick', 'Color'),
585
- ],
586
- },
587
- );
588
-
589
- const report = await compare([card]);
590
-
591
- // TypeScript takes neither `'red'` nor another enum's `Hue.Red` where the
592
- // enum `Color` is expected, and `Color` does not take the `'red'` `pick` does.
593
- expect(kinds(report)).toEqual([
594
- 'Card.count type_mismatch',
595
- 'Card.hue type_mismatch',
596
- 'Card.ids type_mismatch',
597
- 'Card.pick type_mismatch',
598
- 'Card.shade type_mismatch',
599
- 'Card.shades type_mismatch',
600
- ]);
601
- expect(report.typesCompared).toBe(12);
602
- expect(report.typesNotCompared).toEqual([]);
603
- });
604
-
605
- it('reads a union the way TypeScript reduces it, and a default after `=` as no alias', async () => {
606
- withTypeScript();
607
- const icon = component(
608
- 'Icon',
609
- [
610
- "type IconName = 'add' | 'close';",
611
- "export enum Color { Red = 'red', Blue = 'blue' }",
612
- 'type Step = 1 | 2;',
613
- "type Size = 'sm' | 'md' | 'lg';",
614
- 'export interface IconProps {',
615
- ' icon?: IconName | string;',
616
- ' color?: Color | string;',
617
- ' step?: Step | number;',
618
- ' isOpen?: boolean;',
619
- ' icons?: string[];',
620
- ' size?: Size;',
621
- ' limit?: 1000 | 2000;',
622
- ' width?: number | string;',
623
- '}',
624
- 'export function Icon(props: IconProps) { return null; }',
625
- ].join('\n'),
626
- {
627
- props: [
628
- prop('icon', 'IconName | string'),
629
- prop('color', 'Color | string'),
630
- prop('step', 'Step | number'),
631
- prop('isOpen', 'boolean = false'),
632
- prop('icons', '(IconName | string)[]'),
633
- prop('size', "Size = 'md'"),
634
- prop('limit', '1_000 | 2_000'),
635
- prop('width', 'number (or a CSS length)'),
636
- ],
637
- },
638
- );
639
-
640
- const report = await compare([icon]);
641
-
642
- expect(report.findings).toEqual([]);
643
- expect(report.typesCompared).toBe(7);
644
- });
645
-
646
- it('sets aside null and undefined when the project has no strict null checks', async () => {
647
- withTypeScript();
648
- fs.writeFileSync(
649
- path.join(pkg, 'tsconfig.json'),
650
- JSON.stringify({compilerOptions: {strict: false, jsx: 'react-jsx'}}),
651
- );
652
- const loose = component(
653
- 'Loose',
654
- [
655
- 'type MaybeNum = number | null;',
656
- 'export function Loose(props: {count?: MaybeNum; counts?: MaybeNum[]}) { return null; }',
657
- ].join('\n'),
658
- {
659
- props: [
660
- prop('count', 'number | null'),
661
- prop('counts', '(number | null)[]'),
662
- ],
663
- },
664
- );
665
-
666
- const report = await compare([loose]);
667
-
668
- expect(report.findings).toEqual([]);
669
- expect(report.typesCompared).toBe(2);
670
- });
671
-
672
- it('respects exactOptionalPropertyTypes: an optional prop takes undefined only when its type says so', async () => {
673
- withTypeScript();
674
- const tsconfig = path.join(pkg, 'tsconfig.json');
675
- const config = JSON.parse(fs.readFileSync(tsconfig, 'utf8'));
676
- config.compilerOptions.exactOptionalPropertyTypes = true;
677
- fs.writeFileSync(tsconfig, JSON.stringify(config));
678
- const exact = component(
679
- 'Exact',
680
- "type MaybeTone = 'a' | 'b' | 'c' | undefined;\nexport function Exact(props: {size?: 'sm' | 'md'; tone?: 'a' | undefined; mode?: 'x'; status?: {tone?: 'a' | 'b' | undefined; mode?: 'x'}; labels?: Record<string, string | undefined>; hue?: 'a' | 'b' | undefined; t6?: MaybeTone; [key: `x${string}`]: string | undefined}) { return null; }\n",
681
- {
682
- props: [
683
- prop('size', "'sm' | 'md' | undefined"),
684
- prop('tone', "'a' | undefined"),
685
- prop('mode', "'x'"),
686
- prop('status.tone', "'a' | 'b'"),
687
- prop('status.mode', "'x'"),
688
- prop('labels.close', 'string'),
689
- prop('xTone', 'string'),
690
- prop('hue', "'a' | 'b'"),
691
- prop('t6', "'a' | 'b' | 'c'"),
692
- ],
693
- },
694
- );
695
- const variant = component(
696
- 'Variant',
697
- "export function Variant(props: {kind: 'a'; size?: 'sm' | undefined} | {kind: 'b'; size?: 'md' | undefined}) { return null; }\n",
698
- {
699
- props: [
700
- prop('kind', "'a' | 'b'", {required: true}),
701
- prop('size', "'sm' | 'md'"),
702
- ],
703
- },
704
- );
705
-
706
- const report = await compare([exact, variant]);
707
-
708
- // TypeScript rejects `size={undefined}` here, and takes the others; a
709
- // field that declares `undefined` takes it too, unlike its doc. A name an
710
- // index signature takes is held to the index's type the same way as a
711
- // field or as a prop.
712
- expect(kinds(report)).toEqual([
713
- 'Exact.hue type_mismatch',
714
- 'Exact.size type_mismatch',
715
- 'Exact.status.tone type_mismatch',
716
- 'Exact.t6 type_mismatch',
717
- 'Variant.size type_mismatch',
718
- ]);
719
- expect(report.typesCompared).toBe(11);
720
- // The message shows the `undefined` the code declares, written once or by
721
- // each member of a union, in the type and in its expansion.
722
- for (const finding of report.findings.filter(
723
- f => f.component === 'Variant' || f.prop === 'hue',
724
- )) {
725
- expect(finding.codeType).toMatch(/undefined/);
726
- const declared = finding.message.split('but the code declares ')[1];
727
- expect(declared).toMatch(/undefined/);
728
- expect(declared.match(/\((.*)\)\.$/)?.[1] ?? 'undefined').toMatch(
729
- /undefined/,
730
- );
731
- }
732
- // Through an alias, the expansion shows it.
733
- expect(report.findings.find(f => f.prop === 't6')?.message).toMatch(
734
- /declares MaybeTone \(.*undefined.*\)\.$/,
735
- );
736
- });
737
-
738
- it('holds a name an index signature takes, a field a Record takes, and a readonly array to the type TypeScript checks, and lists a field only an index takes and an `a / b` entry whose one type does not split', async () => {
739
- withTypeScript();
740
- const held = component(
741
- 'Held',
742
- [
743
- 'export function Held(props: {',
744
- ' labels?: Record<string, string>;',
745
- ' tags?: string[];',
746
- ' ids?: ReadonlyArray<string>;',
747
- ' keys?: readonly string[];',
748
- ' grid?: readonly string[][];',
749
- ' rows?: (readonly string[])[];',
750
- ' onPick?: (values: readonly string[]) => void;',
751
- ' onDrop?: (values: readonly string[]) => void;',
752
- ' pinned?: {readonly ids: readonly string[]};',
753
- ' item?: {tags: readonly string[]};',
754
- ' mix?: string[] | readonly number[];',
755
- ' min?: number; max?: number; status?: {a: number};',
756
- ' [key: `x${string}`]: string; [key: `y${string}`]: {color: string};',
757
- '}) { return null; }',
758
- ].join('\n'),
759
- {
760
- props: [
761
- prop('labels.close', 'string | undefined'),
762
- prop('xTone', 'string | undefined'),
763
- prop('tags', 'readonly string[]'),
764
- prop('ids', 'readonly string[]'),
765
- prop('keys', 'string[]'),
766
- prop('grid', '(readonly string[])[]'),
767
- prop('rows', 'readonly string[][]'),
768
- prop('onPick', '(values: string[]) => void'),
769
- prop('onDrop', '(values: readonly string[])=>void'),
770
- prop('pinned', '{readonly ids: readonly string[]}'),
771
- prop('item', '{tags: string[]}'),
772
- prop('mix', 'readonly string[] | number[]'),
773
- prop('min / max', 'number'),
774
- prop('status.a / status.b', 'number'),
775
- prop('yTone.color', 'string'),
776
- ],
777
- },
778
- );
779
-
780
- const report = await compare([held]);
781
-
782
- // TypeScript passes no `undefined` through an index that does not take
783
- // it, and no readonly array where a mutable one is taken; a mutable
784
- // array passes where a readonly one is.
785
- expect(kinds(report)).toEqual([
786
- 'Held.labels.close type_mismatch',
787
- 'Held.status.b not_in_code',
788
- 'Held.tags type_mismatch',
789
- 'Held.xTone type_mismatch',
790
- ]);
791
- expect(report.typesCompared).toBe(7);
792
- // `readonly` written as the code writes it matches; written somewhere
793
- // else, at another depth, in a callback's parameter, in an object's
794
- // field, or on another union member, it is not placed: listed, never a
795
- // match, as are a field only an index takes and `a / b` with one type.
796
- expect(
797
- report.typesNotCompared.map(e => `${e.reason}: ${e.props.join(' ')}`),
798
- ).toEqual([
799
- 'not a form the check judges exactly: grid item max min mix onPick rows status.a yTone.color',
800
- ]);
801
- });
802
-
803
- it('reads strict null checks as the TypeScript version defaults them', async () => {
804
- withTypeScript();
805
- fs.writeFileSync(
806
- path.join(pkg, 'tsconfig.json'),
807
- JSON.stringify({compilerOptions: {jsx: 'react-jsx'}}),
808
- );
809
- // The TypeScript the test links in: 6 checks strict null by default.
810
- const ts = require(TYPESCRIPT_DIR);
811
- const strictByDefault = ts.getStrictOptionValue({}, 'strictNullChecks');
812
- const maybe = component(
813
- 'Maybe',
814
- 'export function Maybe(props: {count?: number | null}) { return null; }\n',
815
- {props: [prop('count', 'number')]},
816
- );
817
-
818
- const report = await compare([maybe]);
819
-
820
- expect(kinds(report)).toEqual(
821
- strictByDefault ? ['Maybe.count type_mismatch'] : [],
822
- );
823
- });
824
-
825
- it("lists a name two index signatures take and a field documented with one variant's type, and reads a default for one union member", async () => {
826
- withTypeScript();
827
- const pick = component(
828
- 'Pick',
829
- [
830
- "export enum SizeE { Sm = 'sm', Md = 'md' }",
831
- 'type Sel = {kind: "single"; value: string} | {kind: "multi"; value: string[]};',
832
- 'export type PickProps = {',
833
- ' sizeE?: SizeE;',
834
- ' sel?: Sel;',
835
- ' tri?: {v: string} | {v: number} | {v: boolean};',
836
- ' sev?: {v: 1} | {v: 2} | {v: 3} | {v: 4} | {v: 5} | {v: 6} | {v: 7};',
837
- ' labels?: {close: string} | Record<string, number>;',
838
- ' [key: `data-${string}`]: string | number | undefined;',
839
- ' [key: `data-track${string}`]: string | undefined;',
840
- '} & ({mode: "str"; [key: `x${string}`]: string} | {mode: "num"; [key: `x${string}`]: number});',
841
- 'export function Pick(props: PickProps) { return null; }',
842
- ].join('\n'),
843
- {
844
- props: [
845
- prop('sizeE', 'SizeE = SizeE.Md'),
846
- prop('sel.value', 'string'),
847
- prop('tri.v', 'string | number'),
848
- prop('sev.v', '1 | 2'),
849
- prop('labels.close', 'string | number'),
850
- prop('data-tracker', 'string'),
851
- prop('mode', "'str' | 'num'", {required: true}),
852
- prop('xValue', 'number'),
853
- ],
854
- },
855
- );
856
-
857
- const report = await compare([pick]);
858
-
859
- // TypeScript holds `data-tracker` to both signatures that take it, and
860
- // `xValue` to the one of the member it is passed with; `sel.value`,
861
- // `tri.v` and `sev.v` (past six variants, never reported) take every
862
- // variant's type, and `labels.close` is documented with both.
863
- expect(report.findings).toEqual([]);
864
- expect(report.typesNotCompared).toEqual([
865
- expect.objectContaining({
866
- props: ['data-tracker', 'xValue'],
867
- reason: 'not a form the check judges exactly',
868
- }),
869
- expect.objectContaining({
870
- props: ['sel.value', 'sev.v', 'tri.v'],
871
- reason: "the prop's variants give this field different types",
872
- }),
873
- ]);
874
- expect(report.typesCompared).toBe(3);
875
- });
876
-
877
- it('reads fields in arrays of unions, a name one member indexes, and names only where the code can mean them', async () => {
878
- withTypeScript();
879
- const rows = component(
880
- 'Rows',
881
- [
882
- 'type Items = number[];',
883
- 'export type RowsProps = {',
884
- " items?: Array<{kind: 'a'; value: string} | {kind: 'b'; value: number}>;",
885
- ' list?: Items;',
886
- " behavior?: 'auto' | 'smooth';",
887
- ' [key: `data-${string}`]: string | undefined;',
888
- "} & ({mode: 'fixed'; xSize: number} | ({mode: 'free'} & {[k: `x${string}`]: string}));",
889
- 'export function Rows(props: RowsProps) { return null; }',
890
- ].join('\n'),
891
- {
892
- props: [
893
- prop('items[].value', 'string | number'),
894
- prop('list', 'Items = string[]'),
895
- prop('behavior', 'ScrollBehavior'),
896
- prop('data-section', 'string'),
897
- prop('mode', "'fixed' | 'free'", {required: true}),
898
- prop('xSize', 'number | string'),
899
- ],
900
- },
901
- );
902
-
903
- const report = await compare([rows]);
904
-
905
- // `ScrollBehavior` is the DOM's, which the code never names.
906
- expect(kinds(report)).toEqual(['Rows.list type_mismatch']);
907
- expect(report.typesNotCompared).toEqual([
908
- expect.objectContaining({props: ['behavior']}),
909
- ]);
910
- });
911
-
912
- it('judges a prop two intersected types declare by the type they narrow it to, and undefined on a required prop', async () => {
913
- withTypeScript();
914
- const narrow = component(
915
- 'Narrow',
916
- [
917
- "type A = {size?: 'sm'; tone?: 'a' | 'b'};",
918
- "type B = {size?: 'sm' | 'md'; tone?: 'a' | 'b'};",
919
- 'export type NarrowProps = B & A & {isOpen: boolean; label: string | undefined};',
920
- 'export function Narrow(props: NarrowProps) { return null; }',
921
- ].join('\n'),
922
- {
923
- props: [
924
- prop('size', "'sm' | 'md'"),
925
- prop('tone', "'b' | 'a'"),
926
- prop('isOpen', 'boolean | undefined', {required: true}),
927
- prop('label', 'string', {required: true}),
928
- ],
929
- },
930
- );
931
-
932
- const report = await compare([narrow]);
933
-
934
- // TypeScript takes only 'sm' for `size`, rejects `isOpen={undefined}`,
935
- // and accepts `label={undefined}`.
936
- expect(kinds(report)).toEqual([
937
- 'Narrow.isOpen type_mismatch',
938
- 'Narrow.label type_mismatch',
939
- 'Narrow.size type_mismatch',
940
- ]);
941
- expect(report.findings.find(f => f.prop === 'size')?.codeType).toBe("'sm'");
942
- });
943
-
944
- it('lists every other form of type as not compared, never as a mismatch', async () => {
945
- withTypeScript();
946
- const thread = component(
947
- 'Thread',
948
- [
949
- 'interface IconShape { path: string }',
950
- 'type MaybePromise<T> = T | Promise<T>;',
951
- 'type Parts = {a?: string; b?: number};',
952
- "type A = {a: string}; type B = {b: number}; enum Color { Red = 'red' } namespace Theme { export enum Color { Red = 'red' } }",
953
- 'export interface ThreadProps {',
954
- ' onSubmit?: (text: string, files?: File[]) => MaybePromise<void>;',
955
- ' onPick?: (value: string, index: number) => void;',
956
- ' item?: A & B;',
957
- ' parts?: Partial<Parts>;',
958
- ' key2?: keyof (A & B);',
959
- ' key3?: keyof (A & B);',
960
- " target?: '_self' | '_blank' | (string & {});",
961
- ' range?: [number, number?];',
962
- ' labels?: Record<string, string>;',
963
- ' icon?: IconShape;',
964
- ' data?: any;',
965
- ' extra?: unknown; tint?: Theme.Color;',
966
- '}',
967
- 'export function Thread(props: ThreadProps) { return null; }',
968
- ].join('\n'),
969
- {
970
- props: [
971
- prop('onSubmit', '(text: string) => Promise<number>'),
972
- prop('onPick', '(value: string, index: number) => void'),
973
- prop('item', '{a: string; b: number}'),
974
- prop('parts', 'Parts'),
975
- prop('key2', 'keyof (A & B)'),
976
- prop('key3', "'a' | 'b'"),
977
- prop('target', "'_self' | '_blank'"),
978
- prop('range', '[number]'),
979
- prop('labels', '{[key: string]: number}'),
980
- prop('icon', 'IconName'),
981
- prop('data', 'string'),
982
- prop('data.id', 'string'),
983
- prop('extra.kind', 'string'),
984
- prop('tint', 'Color'),
985
- ],
986
- },
987
- );
988
-
989
- const report = await compare([thread]);
990
-
991
- expect(report.findings).toEqual([]);
992
- // Written exactly as the source writes them, or a literal union the
993
- // code's type resolves to (`keyof (A & B)` is `'a' | 'b'`).
994
- expect(report.typesCompared).toBe(3);
995
- expect(
996
- report.typesNotCompared.map(e => `${e.reason}: ${e.props.join(' ')}`),
997
- ).toEqual([
998
- 'not a form the check judges exactly: data data.id extra.kind icon item labels onSubmit parts range target tint',
999
- ]);
1000
- });
1001
-
1002
- it("compares a documented field's type, and a name an index signature takes, with the type the code gives it", async () => {
1003
- withTypeScript();
1004
- const note = component(
1005
- 'Note',
1006
- [
1007
- 'export interface NoteProps {',
1008
- " status?: {type: 'error' | 'warning'; message?: string};",
1009
- ' items?: Array<{id: string; label: string}>;',
1010
- ' labels?: Record<string, string>;',
1011
- ' [key: `data-${string}`]: string | undefined;',
1012
- ' [key: `aria-${string}`]: string | number | undefined;',
1013
- '}',
1014
- 'export function Note(props: NoteProps) { return null; }',
1015
- ].join('\n'),
1016
- {
1017
- props: [
1018
- prop('status.type', "'error' | 'info'"),
1019
- prop('items[].label', 'number'),
1020
- prop('labels.open', 'string'),
1021
- prop('labels.close', 'number'),
1022
- prop('data-section', 'string'),
1023
- prop('data-count', 'number'),
1024
- prop('aria-busy', 'boolean'),
1025
- ],
1026
- },
1027
- );
1028
-
1029
- const report = await compare([note]);
1030
-
1031
- expect(kinds(report)).toEqual([
1032
- 'Note.aria-busy type_mismatch',
1033
- 'Note.data-count type_mismatch',
1034
- 'Note.items[].label type_mismatch',
1035
- 'Note.labels.close type_mismatch',
1036
- 'Note.status.type type_mismatch',
1037
- ]);
1038
- expect(report.typesCompared).toBe(7);
1039
- });
1040
-
1041
- it('accepts an alias spelled out beside its name, and reports one whose spelled-out values are stale', async () => {
1042
- withTypeScript();
1043
- const links = ["'link' | 'token'", "'link' | 'token' | 'button'"].map(
1044
- (values, i) =>
1045
- component(
1046
- `Link${i}`,
1047
- `export type LinkVariant = ${values};\nexport function Link${i}(props: {variant?: LinkVariant; tone?: LinkVariant}) { return null; }`,
1048
- {
1049
- props: [
1050
- prop('variant', "LinkVariant = 'link' | 'token'"),
1051
- prop('tone', "LinkVariant ('link' | 'token')"),
1052
- ],
1053
- },
1054
- ),
1055
- );
1056
-
1057
- expect(kinds(await compare(links))).toEqual([
1058
- 'Link1.tone type_mismatch',
1059
- 'Link1.variant type_mismatch',
1060
- ]);
1061
- });
1062
-
1063
- it("reads an optional prop documented with `| undefined` as the code reads it, and names an alias's members in the source's order", async () => {
1064
- withTypeScript();
1065
- const badge = component(
1066
- 'Badge',
1067
- [
1068
- "type Tone = 'neutral' | 'info';",
1069
- 'export function Badge(props: {tone?: Tone}) { return null; }',
1070
- ].join('\n'),
1071
- {props: [prop('tone', "'neutral' | 'info' | undefined")]},
1072
- );
1073
- const chip = component(
1074
- 'Chip',
1075
- "export function Chip(props: {tone?: 'a' | 'b' | undefined}) { return null; }\n",
1076
- {props: [prop('tone', "'a' | 'c'")]},
1077
- );
1078
-
1079
- // The same literals, made first in another order, would set the
1080
- // compiler's own order.
1081
- const status = component(
1082
- 'Status',
1083
- [
1084
- "type Other = 'detached' | 'attached' | 'tooltip';",
1085
- 'export type Unrelated = Other;',
1086
- "type StatusVariant = 'tooltip' | 'attached' | 'detached';",
1087
- 'export function Status(props: {variant?: StatusVariant}) { return null; }',
1088
- ].join('\n'),
1089
- {props: [prop('variant', "'attached' | 'detached'")]},
1090
- );
1091
-
1092
- expect(kinds(await compare([badge]))).toEqual([]);
1093
- // The optional prop's `undefined` the expansion sets aside is shown once.
1094
- const [finding] = (await compare([chip])).findings;
1095
- expect(finding.message).toMatch(/declares 'a' \| 'b' \| undefined\.$/);
1096
- expect((await compare([status])).findings.map(f => f.message)).toEqual([
1097
- `"variant" is documented as 'attached' | 'detached', but the code declares StatusVariant ('tooltip' | 'attached' | 'detached').`,
1098
- ]);
1099
- });
1100
-
1101
- it('judges a className the package declares, and lists standard props and props from other packages as not compared', async () => {
1102
- withTypeScript();
1103
- const base = path.join(pkg, 'node_modules', '@acme', 'base');
1104
- fs.mkdirSync(base, {recursive: true});
1105
- fs.writeFileSync(
1106
- path.join(base, 'package.json'),
1107
- JSON.stringify({name: '@acme/base', types: 'index.d.ts'}),
1108
- );
1109
- fs.writeFileSync(
1110
- path.join(base, 'index.d.ts'),
1111
- 'export interface BaseProps { style?: object; id?: string; tone?: {level: number}; [key: `data-${string}`]: string | undefined }\n',
1112
- );
1113
- // A name only another package's index signature, or a mapped type's,
1114
- // takes is not judged either.
1115
- const card = component(
1116
- 'Card',
1117
- "import type {BaseProps} from '@acme/base';\nexport function Card(props: BaseProps & {className?: string} & Record<`aria-${string}`, string>) { return null; }\n",
1118
- {
1119
- props: [
1120
- prop('className', 'number'),
1121
- prop('style', 'string'),
1122
- prop('id', 'number'),
1123
- prop('tone.level', 'string'),
1124
- prop('tone.missing', 'string'),
1125
- prop('data-variant', "'solid' | 'outline'"),
1126
- prop('aria-note', 'number'),
1127
- ],
1128
- },
1129
- );
1130
-
1131
- const report = await compare([card]);
1132
-
1133
- expect(kinds(report)).toEqual([
1134
- 'Card.className type_mismatch',
1135
- 'Card.tone.missing not_in_code',
1136
- ]);
1137
- expect(report.typesCompared).toBe(1);
1138
- expect(
1139
- report.typesNotCompared.map(e => `${e.reason}: ${e.props.join(' ')}`),
1140
- ).toEqual([
1141
- 'declared outside the package, not compared: data-variant id tone.level',
1142
- 'not a form the check judges exactly: aria-note',
1143
- 'standard prop, not compared: style',
1144
- ]);
1145
- });
1146
-
1147
- it('does not ask a doc for props from other packages, or for the props the authoring guidance skips', async () => {
1148
- expect(PROPS_NOT_DOCUMENTED).toEqual([
1149
- 'className',
1150
- 'style',
1151
- 'xstyle',
1152
- 'data-testid',
1153
- 'ref',
1154
- 'key',
1155
- ]);
1156
- withTypeScript();
1157
- const base = path.join(pkg, 'node_modules', '@acme', 'base');
1158
- fs.mkdirSync(base, {recursive: true});
1159
- fs.writeFileSync(
1160
- path.join(base, 'package.json'),
1161
- JSON.stringify({name: '@acme/base', types: 'index.d.ts'}),
1162
- );
1163
- fs.writeFileSync(
1164
- path.join(base, 'index.d.ts'),
1165
- [
1166
- 'export interface BaseProps { id?: string; onBlur?: () => void }',
1167
- "export type Sizes = Partial<Record<'sm' | 'md', string>>;",
1168
- "export interface Spacing extends Partial<Record<'gap', number>> {}",
1169
- "export type Tone = 'info' | 'danger';",
1170
- 'export type Flags<K extends string> = {[P in K]?: boolean};',
1171
- 'export type FC<P> = (props: P) => null;',
1172
- "export type Responsive<T> = {[K in 'sm' | 'lg']?: T};",
1173
- "export type Breakpoint = 'sm' | 'lg';",
1174
- 'export declare const BREAKPOINTS: readonly Breakpoint[];',
1175
- 'export declare function memo<T extends (p: any) => null>(c: T): {(p: Parameters<T>[0]): null; $$typeof: symbol; type: T};',
1176
- 'export declare function forwardRef<P>(render: (props: P, ref: unknown) => null): (props: P) => null;',
1177
- ].join('\n'),
1178
- );
1179
- const panel = component(
1180
- 'Panel',
1181
- [
1182
- "import type {BaseProps} from '@acme/base';",
1183
- 'export interface PanelProps extends BaseProps {',
1184
- ' title?: string;',
1185
- ' className?: string;',
1186
- ' style?: {color?: string};',
1187
- ' xstyle?: unknown;',
1188
- " 'data-testid'?: string;",
1189
- ' ref?: unknown;',
1190
- ' key?: string;',
1191
- ' /** @deprecated Use `title`. */',
1192
- ' heading?: string;',
1193
- ' /** @internal */',
1194
- ' debugName?: string;',
1195
- '}',
1196
- 'export function Panel(props: PanelProps) { return null; }',
1197
- ].join('\n'),
1198
- {props: [prop('title', 'string'), prop('id', 'number')]},
1199
- );
1200
-
1201
- // A prop a mapped type builds is the package's own when its key traces
1202
- // to the package's source: through aliases, `Exclude`, a generic's
1203
- // arguments, and a component `memo` or `forwardRef` wraps. A key another
1204
- // package defines, behind an alias or not, is that package's, and one
1205
- // the check can't trace is listed, not asked for.
1206
- const mapped = Object.entries({
1207
- Styled:
1208
- '(props: {[K in StyleKey]?: BaseProps[K]} & Partial<Record<StyleKey, number>>)',
1209
- Inlined: '(props: {[K in keyof BaseProps]?: BaseProps[K]})',
1210
- Spread: '(props: Responsive<number>)',
1211
- Memoed: ' = memo(Inner)',
1212
- Forwarded: ' = forwardRef(Impl)',
1213
- Excluded: "(props: {[K in Exclude<'a' | 'b' | 'c', 'c'>]?: string})",
1214
- Templated: "(props: {[K in `on${Capitalize<'open'>}`]?: () => void})",
1215
- // Another package's keys through an own interface's property, an
1216
- // `infer`, or a constant bound to its value stay that package's.
1217
- Indexed: "(props: {[K in Opts['size']]?: number})",
1218
- Inferred: '(props: {[K in KeysOf<Record<Breakpoint, 1>>]?: number})',
1219
- Rebound: '(props: {[K in (typeof SIZES)[number]]?: number})',
1220
- Inline: "(props: {[K in 'a' | 'b']?: string})",
1221
- Recorded: "(props: Partial<Record<'a' | 'b', string>>)",
1222
- Remapped: "(props: {[K in 'open' as `on${Capitalize<K>}`]?: () => void})",
1223
- Toned:
1224
- "(props: Partial<Record<Tone | 'xl', boolean>> & {[K in Tone]?: string} & Partial<Record<keyof BaseProps, string>> & {[K in keyof BaseProps as `x${Capitalize<K>}`]?: boolean})",
1225
- Flagged: "(props: Flags<'bold'>)",
1226
- Extended: '(props: ExtendedProps)',
1227
- Sized: '(props: Spaced & Partial<Sizes>)',
1228
- }).map(([name, props]) =>
1229
- component(
1230
- name,
1231
- [
1232
- "import {type BaseProps, type Sizes, type Spacing, type Tone, type Flags, type FC, type Responsive, type Breakpoint, BREAKPOINTS, memo, forwardRef} from '@acme/base';",
1233
- "interface ExtendedProps extends Partial<Record<'a', string>> {}",
1234
- 'interface Spaced extends Spacing {}',
1235
- 'type StyleKey = keyof BaseProps;',
1236
- 'interface Opts { size: Breakpoint }',
1237
- 'type KeysOf<T> = T extends Record<infer K, unknown> ? K : never;',
1238
- 'const SIZES = BREAKPOINTS;',
1239
- "function Inner(props: {[K in 'top' | 'bottom']?: number}) { return null; }",
1240
- "function Impl(props: Partial<Record<'left', number>>, ref: unknown) { return null; }",
1241
- props.startsWith(' =')
1242
- ? `export const ${name}${props};`
1243
- : `export function ${name}${props} { return null; }`,
1244
- `export const Typed: FC<Partial<Record<'a', string>>> = () => null;`,
1245
- ].join('\n'),
1246
- {props: []},
1247
- ),
1248
- );
1249
-
1250
- // A deprecated prop is still a prop the component accepts.
1251
- const typed = {...mapped[0], name: 'Typed'};
1252
- const report = await compare([panel, ...mapped, typed]);
1253
- expect(kinds(report)).toEqual([
1254
- 'Excluded.a not_in_doc',
1255
- 'Excluded.b not_in_doc',
1256
- 'Extended.a not_in_doc',
1257
- 'Flagged.bold not_in_doc',
1258
- 'Forwarded.left not_in_doc',
1259
- 'Inline.a not_in_doc',
1260
- 'Inline.b not_in_doc',
1261
- 'Memoed.bottom not_in_doc',
1262
- 'Memoed.top not_in_doc',
1263
- 'Panel.heading not_in_doc',
1264
- 'Recorded.a not_in_doc',
1265
- 'Recorded.b not_in_doc',
1266
- 'Remapped.onOpen not_in_doc',
1267
- 'Toned.xl not_in_doc',
1268
- 'Typed.a not_in_doc',
1269
- ]);
1270
- expect(report.propsNotChecked).toEqual([
1271
- expect.objectContaining({component: 'Templated', props: ['onOpen']}),
1272
- expect.objectContaining({component: 'Inferred', props: ['lg', 'sm']}),
1273
- ]);
1274
- // The alias and the inline form give the same answer: nothing asked.
1275
- for (const name of ['Styled', 'Inlined']) {
1276
- expect(kinds(report).filter(kind => kind.startsWith(name))).toEqual([]);
1277
- }
1278
- });
1279
-
1280
- it('reads every overload, one without props included, matches a doc that describes one member of a discriminated union, reads a prop only some members require as optional, and holds every prop one entry names to its `required`', async () => {
1281
- withTypeScript();
1282
- const picker = component(
1283
- 'Picker',
1284
- `type Single = {isMulti?: false; value: string; onChange: (value: string) => void};
1285
- type Multi = {isMulti: true; value: string[]; onChange: (value: string[]) => void};
1286
- export type PickerProps = (Single | Multi) & {label: string};
1287
- export function Picker(props: PickerProps) { return null; }`,
1288
- {
1289
- props: [
1290
- prop('label', 'string', {required: true}),
1291
- prop('isMulti', 'boolean'),
1292
- prop('value', 'string', {required: true}),
1293
- prop('onChange', '(value: string) => void', {required: true}),
1294
- ],
1295
- },
1296
- );
1297
-
1298
- const select = component(
1299
- 'Select',
1300
- `type Single = {multiple?: false; value?: string};
1301
- type Multi = {multiple: true; value?: string[]; max?: number};
1302
- export function Select(props: Single): null;
1303
- export function Select(props: Multi): null;
1304
- export function Select(props: Single | Multi) { return null; }`,
1305
- {
1306
- props: [
1307
- prop('multiple', 'boolean'),
1308
- prop('value', 'string | string[]'),
1309
- prop('max', 'number'),
1310
- ],
1311
- },
1312
- );
1313
- // An overload that takes no props makes every prop optional; a typed
1314
- // props type beside a `Record<string, any>` or a mapped `any` index is
1315
- // compared as it is beside an inline `[key: string]: any`.
1316
- const propless = component(
1317
- 'Propless',
1318
- 'export function Propless(): null;\nexport function Propless(props: {label: string}): null;\nexport function Propless(props?: {label: string}) { return null; }',
1319
- {props: [prop('label', 'string', {required: true})]},
1320
- );
1321
- const open = [
1322
- 'Record<string, any>',
1323
- 'Record<`data-${string}`, any>',
1324
- '{[K in string]?: any}',
1325
- ].map((index, i) =>
1326
- component(
1327
- `Open${i}`,
1328
- `export function Open${i}(props: {label?: string; size?: number} & ${index}) { return null; }`,
1329
- {props: [prop('label', 'string')]},
1330
- ),
1331
- );
1332
-
1333
- // Required in one variant only: a caller may leave it out, so optional.
1334
- const menu = component(
1335
- 'Menu',
1336
- 'export function Menu(props: {items: string[]} | {alt: string}) { return null; }',
1337
- {props: [prop('items', 'X[]', {required: true}), prop('alt', 'X')]},
1338
- );
1339
- // One entry's `required` is a claim about every prop it names.
1340
- const pairs = ['label: string', 'label?: string'].map((label, i) =>
1341
- component(
1342
- `Pair${i}`,
1343
- `export function Pair${i}(props: {value: string; ${label}}) { return null; }`,
1344
- {props: [prop('value / label', 'string / string', {required: true})]},
1345
- ),
1346
- );
1347
- // Typed `any` through the package's own alias of `Omit`, written in the
1348
- // signature, as a named alias, or as an interface's base.
1349
- const without = ['Without<any>', 'P', 'Q', 'R'].map((props, i) =>
1350
- component(
1351
- `Without${i}`,
1352
- `type Without<T> = Omit<T, 'as'>; type P = Without<any>; interface Q extends Omit<any, 'as'> {} type R = Omit<P, 'ref'>;\nexport function Without${i}(props: ${props}) { return null; }`,
1353
- {props: [prop('label', 'string')]},
1354
- ),
1355
- );
1356
-
1357
- const tables = [
1358
- picker,
1359
- select,
1360
- propless,
1361
- ...open,
1362
- menu,
1363
- ...pairs,
1364
- ...without,
1365
- ];
1366
- const report = await compare(tables);
1367
-
1368
- expect(kinds(report)).toEqual([
1369
- 'Menu.items required_mismatch',
1370
- 'Open0.size not_in_doc',
1371
- 'Open1.size not_in_doc',
1372
- 'Open2.size not_in_doc',
1373
- 'Pair1.label required_mismatch',
1374
- 'Propless.label required_mismatch',
1375
- ]);
1376
- expect(report.components).toBe(9);
1377
- expect(report.propsNotChecked).toBeUndefined();
1378
- expect(report.unchecked.map(entry => entry.reason)).toEqual(
1379
- [0, 1, 2, 3].map(i =>
1380
- expect.stringMatching(`^Without${i}'s props are typed`),
1381
- ),
1382
- );
1383
- });
1384
-
1385
- it('shows a method prop the doc leaves out with its function type, optional or not', async () => {
1386
- withTypeScript();
1387
- const picker = component(
1388
- 'Picker',
1389
- `export interface PickerProps {
1390
- label?: string;
1391
- onPick(value: string, index: number): void;
1392
- onClear?(reason: string): void;
1393
- get size(): number;
1394
- }
1395
- export function Picker(props: PickerProps) { return null; }`,
1396
- {props: [prop('label', 'string')]},
1397
- );
1398
-
1399
- const report = await compare([picker]);
1400
-
1401
- expect(
1402
- report.findings.map(f => `${f.prop} ${f.kind}: ${f.codeType}`),
1403
- ).toEqual([
1404
- 'onClear not_in_doc: (reason: string) => void',
1405
- 'onPick not_in_doc: (value: string, index: number) => void',
1406
- 'size not_in_doc: number',
1407
- ]);
1408
- });
1409
-
1410
- it("prints a union's members in the order the source declares them", async () => {
1411
- withTypeScript();
1412
- // The same literals, made first in another order, would set the
1413
- // compiler's own order.
1414
- const ordered = component(
1415
- 'Ordered',
1416
- [
1417
- "type Other = 'md' | 'sm' | 'lg';",
1418
- 'export type Unrelated = Other;',
1419
- "type Small = 'lg' | 'sm';",
1420
- "export function Ordered(props: {size?: Small} | {size?: 'md'; label?: string}) { return null; }",
1421
- ].join('\n'),
1422
- {props: [prop('label', 'string')]},
1423
- );
1424
-
1425
- const report = await compare([ordered]);
1426
-
1427
- expect(
1428
- report.findings.find(finding => finding.prop === 'size')?.codeType,
1429
- ).toBe("'lg' | 'sm' | 'md'");
1430
- });
1431
-
1432
- it("reads a prop that the package's defaultProps fills as optional", async () => {
1433
- withTypeScript();
1434
- // A library type that declares an optional `defaultProps`, as React's
1435
- // component types do, fills nothing; without strict null checks it reads
1436
- // as filling every prop.
1437
- const lib = path.join(pkg, 'node_modules', '@acme', 'lib');
1438
- fs.mkdirSync(lib, {recursive: true});
1439
- fs.writeFileSync(
1440
- path.join(lib, 'package.json'),
1441
- JSON.stringify({name: '@acme/lib', types: 'index.d.ts'}),
1442
- );
1443
- fs.writeFileSync(
1444
- path.join(lib, 'index.d.ts'),
1445
- `export interface Kind<P> { new (props: P): {}; defaultProps?: Partial<P> }
1446
- export declare function memo<T extends (p: any) => any>(c: T): {(p: Parameters<T>[0]): null; $$typeof: symbol; type: T};
1447
- export declare function lazy<T extends (p: any) => any>(f: () => Promise<{default: T}>): {(p: Parameters<T>[0]): null; $$typeof: symbol; _result: T};\n`,
1448
- );
1449
- fs.writeFileSync(
1450
- path.join(pkg, 'tsconfig.json'),
1451
- JSON.stringify({compilerOptions: {strict: false, jsx: 'react-jsx'}}),
1452
- );
1453
- const source = `import {type Kind, lazy, memo} from '@acme/lib';
1454
- declare class Component<P> { constructor(props: P); props: P }
1455
- export class Klass extends Component<{label: string; size: number}> {
1456
- static defaultProps = {size: 1};
1457
- }
1458
- export function Fn(props: {label: string; size: number}) { return null; }
1459
- Fn.defaultProps = {size: 1};
1460
- export function Gn(props: {label: string; size: number}) { return null; }
1461
- Gn.defaultProps = {size: 1};
1462
- export declare const Typed: Kind<{label: string; size: number}>;
1463
- export const Memoed = memo(Fn);
1464
- export const Lazied = lazy(() => Promise.resolve({default: Fn}));
1465
- export const Thrice = memo(memo(memo(Fn)));
1466
- export class Loose extends Component<{label: string; size: number}> { static defaultProps: any = {}; }`;
1467
- const props = [
1468
- prop('label', 'string'),
1469
- prop('size', 'number', {required: true}),
1470
- ];
1471
-
1472
- const report = await compare([
1473
- ...'Klass Fn Typed Memoed Lazied Thrice Loose'
1474
- .split(' ')
1475
- .map(name => component(name, source, {props})),
1476
- component('Gn', source, {
1477
- props: [prop('label', 'string'), prop('size', 'number')],
1478
- }),
1479
- ]);
1480
-
1481
- // JSX callers may leave out a prop defaultProps fills (for `memo` and
1482
- // `lazy`, the wrapped component's, two layers deep as React's types read
1483
- // it; `any` fills every prop), so a doc that marks it required disagrees
1484
- // with the code, and one that doesn't agrees.
1485
- expect(kinds(report)).toEqual([
1486
- 'Fn.label required_mismatch',
1487
- 'Fn.size required_mismatch',
1488
- 'Gn.label required_mismatch',
1489
- 'Klass.label required_mismatch',
1490
- 'Klass.size required_mismatch',
1491
- 'Lazied.label required_mismatch',
1492
- 'Lazied.size required_mismatch',
1493
- 'Loose.size required_mismatch',
1494
- 'Memoed.label required_mismatch',
1495
- 'Memoed.size required_mismatch',
1496
- 'Thrice.label required_mismatch',
1497
- 'Typed.label required_mismatch',
1498
- ]);
1499
- expect(
1500
- report.findings.find(f => f.component === 'Fn' && f.prop === 'size'),
1501
- ).toMatchObject({docRequired: true, codeRequired: false});
1502
- });
1503
-
1504
- it('lists each component whose props it cannot read as not compared', async () => {
1505
- withTypeScript();
1506
- const tsconfig = path.join(pkg, 'tsconfig.json');
1507
- const config = JSON.parse(fs.readFileSync(tsconfig, 'utf8'));
1508
- config.compilerOptions.allowJs = true;
1509
- fs.writeFileSync(tsconfig, JSON.stringify(config));
1510
- /** @param {Record<string, string>} sources each component's props types */
1511
- const missing = sources =>
1512
- Object.entries(sources).map(([name, types]) =>
1513
- component(
1514
- name,
1515
- `import type {MissingProps} from '@acme/not-installed';\n${types}\nexport function ${name}(props: ${name}Props) { return null; }`,
1516
- {props: [prop('label', 'string')]},
1517
- ),
1518
- );
1519
- const unread = [
1520
- ...missing({
1521
- Ghost:
1522
- 'export interface GhostProps extends MissingProps { label?: string }',
1523
- Omitted:
1524
- "export interface OmittedProps extends Omit<MissingProps, 'title'> { label?: string }",
1525
- Phantom:
1526
- 'export type PhantomProps = Partial<MissingProps> & {label?: string};',
1527
- Named:
1528
- "type Base = Omit<MissingProps, 'title'>; export interface NamedProps extends Base { label?: string }",
1529
- Joined:
1530
- "type Base = Omit<MissingProps, 'title'>; export type JoinedProps = Base & {label?: string};",
1531
- Bare: "type Base = Omit<MissingProps, 'title'>; export type BareProps = Base;",
1532
- Mapped:
1533
- 'export type MappedProps = {[K in keyof MissingProps]?: string};',
1534
- Prefixed:
1535
- 'type On<K extends string> = {[P in `on${K}`]?: () => void}; export type PrefixedProps = On<MissingProps> & {label?: string};',
1536
- Picked:
1537
- "type Base = Pick<MissingProps, 'title'>; export type PickedProps = Base;",
1538
- Kept: "type W<T> = T & {label?: string}; export type KeptProps = W<Required<Pick<MissingProps, 'title'>>>;",
1539
- Nested:
1540
- "export type NestedProps = Partial<Omit<MissingProps, 'title'>> & {label?: string};",
1541
- Deep: 'interface L1 extends MissingProps {} interface L2 extends L1 {} interface L3 extends L2 {} interface L4 extends L3 {} interface L5 extends L4 {} export interface DeepProps extends L5 { label?: string }',
1542
- }),
1543
- component(
1544
- 'Wrapped',
1545
- `import {forwardRef} from 'react';
1546
- export const Wrapped = forwardRef<HTMLButtonElement, {label?: string}>((props, ref) => null);`,
1547
- {props: [prop('label', 'string')]},
1548
- ),
1549
- component(
1550
- 'Classy',
1551
- "import {MissingBase} from '@acme/not-installed';\nexport class Classy extends MissingBase<{label?: string}> {}\n",
1552
- {props: [prop('label', 'string')]},
1553
- ),
1554
- ];
1555
- // Each of these is the only reference in its files that does not resolve:
1556
- // a name its module does not export, a dependency's own missing import, a
1557
- // missing type package, and a side-effect import.
1558
- fs.writeFileSync(
1559
- path.join(pkg, 'components', 'theme.ts'),
1560
- 'export interface Theme { tone?: string }\n',
1561
- );
1562
- const dep = path.join(pkg, 'node_modules', '@acme', 'dep');
1563
- fs.mkdirSync(dep, {recursive: true});
1564
- fs.writeFileSync(
1565
- path.join(dep, 'package.json'),
1566
- JSON.stringify({name: '@acme/dep', types: 'index.d.ts'}),
1567
- );
1568
- fs.writeFileSync(
1569
- path.join(dep, 'index.d.ts'),
1570
- "import type {MissingProps} from '@acme/not-installed';\nexport type DepProps = MissingProps & {label?: string};\n",
1571
- );
1572
- const references = Object.entries({
1573
- Unnamed:
1574
- "import type {Gone} from './theme';\nexport function Unnamed(props: {label?: string; tone?: Gone}) { return null; }\n",
1575
- Peered:
1576
- "import type {DepProps} from '@acme/dep';\nexport function Peered(props: DepProps) { return null; }\n",
1577
- Referenced:
1578
- '/// <reference types="@acme/not-installed-types" />\nexport function Referenced(props: {label?: string}) { return null; }\n',
1579
- Effect:
1580
- "import '@acme/not-installed-effect';\nexport function Effect(props: {label?: string}) { return null; }\n",
1581
- // A type name declared nowhere, which only `keyof`, a `Record`'s keys
1582
- // or a template literal key reaches.
1583
- Omitting:
1584
- 'export function Omitting(props: Omit<{label: string; size?: number}, keyof NowhereProps>) { return null; }\n',
1585
- Recorded:
1586
- 'export function Recorded(props: Partial<Record<keyof NowhereProps, string>>) { return null; }\n',
1587
- Handlers:
1588
- 'export function Handlers(props: {[K in `on${NowhereKey}`]?: () => void}) { return null; }\n',
1589
- Aliased:
1590
- 'type Keys = keyof NowhereProps;\nexport function Aliased(props: {[K in Keys]?: string}) { return null; }\n',
1591
- // A value declared nowhere behind a binding, and a property that
1592
- // doesn't exist: the compiler can only give either its error type.
1593
- Valued:
1594
- 'const d = missingValue;\nexport function Valued(props: Omit<{label: string; size?: number}, keyof typeof d>) { return null; }\n',
1595
- Sized:
1596
- "interface Theme { colors: {a: string} }\nexport function Sized(props: Partial<Record<keyof Theme['sizes'], string>>) { return null; }\n",
1597
- // A value the compiler can't type, spread into an object, makes the
1598
- // object `any`.
1599
- Spread:
1600
- 'interface Theme { colors: {a: string} }\ndeclare const theme: Theme;\nconst defaults = {...theme.sizes};\nexport function Spread(props: Omit<{label: string; size?: number}, keyof typeof defaults>) { return null; }\n',
1601
- Toned:
1602
- 'const tones = {...undeclaredTones};\nexport function Toned(props: Partial<Record<keyof typeof tones, string>>) { return null; }\n',
1603
- }).map(([name, source]) =>
1604
- component(name, source, {props: [prop('label', 'string')]}),
1605
- );
1606
- // A name declared nowhere in a JavaScript component's JSDoc, which `tsc`
1607
- // doesn't report there.
1608
- const documented = component(
1609
- 'Documented',
1610
- '/** @param {Omit<{label: string; size?: number}, keyof NowhereJs>} props */\nexport function Documented(props) { return null; }\n',
1611
- {props: [prop('label', 'string')]},
1612
- );
1613
- const jsx = documented.sourcePath.replace(/\.tsx$/, '.jsx');
1614
- fs.renameSync(documented.sourcePath, jsx);
1615
- references.push({...documented, sourcePath: jsx, sources: [jsx]});
1616
- // A module found without types resolves: its names are `any`.
1617
- const untypedDir = path.join(pkg, 'node_modules', 'untyped-dep');
1618
- fs.mkdirSync(untypedDir, {recursive: true});
1619
- fs.writeFileSync(
1620
- path.join(untypedDir, 'package.json'),
1621
- JSON.stringify({name: 'untyped-dep', main: 'index.js'}),
1622
- );
1623
- fs.writeFileSync(
1624
- path.join(untypedDir, 'index.js'),
1625
- 'export const fmt = text => text;\n',
1626
- );
1627
- const untyped = component(
1628
- 'Untyped',
1629
- "import {fmt} from 'untyped-dep';\nexport function Untyped(props: {label?: string}) { fmt(props.label); return null; }\n",
1630
- {props: [prop('label', 'string')]},
1631
- );
1632
- const lonely = component(
1633
- 'Lonely',
1634
- 'export function Other(props: {label: string}) { return null; }\n',
1635
- {props: [prop('label', 'string', {required: true})]},
1636
- );
1637
- // An `any` index signature the package declares itself is no reason.
1638
- const open = component(
1639
- 'Open',
1640
- 'export function Open(props: {label?: string; [key: string]: any}) { return null; }\n',
1641
- {props: [prop('label', 'string')]},
1642
- );
1643
- // A missing import in the files a component comes from lists it, however
1644
- // the props reach it: only a member's type, a value's property, a
1645
- // conditional, `??`, a comma, or an own HOC that maps over `keyof P`.
1646
- const reached = Object.entries({
1647
- Member:
1648
- 'interface Holder<T> { label?: T } export function Member(props: Holder<MissingProps>) { return null; }',
1649
- Header:
1650
- 'function Inner(props: {label?: string}) { return null; } const Card = Object.assign(Inner, {Header: Inner}); export const Header = Card.Header;',
1651
- Chosen:
1652
- 'function Inner(props: {label?: string}) { return null; } export const Chosen = (globalThis as {x?: 1}).x ? Inner : Inner;',
1653
- Fallback:
1654
- 'function Inner(props: {label?: string}) { return null; } export const Fallback = (undefined as typeof Inner | undefined) ?? Inner;',
1655
- Comma:
1656
- 'function Inner(props: {label?: string}) { return null; } export const Comma = (0, Inner);',
1657
- Keyed:
1658
- 'function withKeys<P>(c: (props: P) => null) { return (props: {[K in keyof P]?: string}) => c(props as P); } export const Keyed = withKeys((props: MissingProps) => null);',
1659
- }).map(([name, source]) =>
1660
- component(
1661
- name,
1662
- `import type {MissingProps} from '@acme/not-installed';\n${source}\n`,
1663
- {props: [prop('label', 'string')]},
1664
- ),
1665
- );
1666
-
1667
- // Props that take names from a type parameter, such as the element a
1668
- // component renders, accept any name until it is used.
1669
- const PROPS_OF = [
1670
- 'interface Intrinsic { div: {title?: string}; span: {lang?: string} }',
1671
- 'type ElementType = keyof Intrinsic | ((props: any) => unknown);',
1672
- 'type PropsOf<E> = E extends (props: infer P) => unknown ? P : E extends keyof Intrinsic ? Intrinsic[E] : {};',
1673
- "type Prefixed<N extends string> = {[K in 'value' | 'change' as `${N}${Capitalize<K>}`]: string};",
1674
- "type Pair<N extends string> = {label: string} & {[K in 'a' | 'b' as `${N}${K}`]: string};",
1675
- 'type Relayed<M extends string> = Prefixed<M>;',
1676
- 'type Except<O, X extends keyof O> = {[K in keyof O as K extends X ? never : K]: O[K]};',
1677
- 'type PickByValue<O, V> = {[K in keyof O as O[K] extends V ? K : never]: O[K]};',
1678
- ];
1679
- const generics = Object.entries({
1680
- Poly: "export type PolyProps<E extends ElementType> = {as?: E; padding?: number} & Omit<PropsOf<E>, 'as' | 'padding'>; export function Poly<E extends ElementType = 'div'>(props: PolyProps<E>) { return null; }",
1681
- Joint:
1682
- "export function Joint<E extends ElementType = 'div'>(props: {as?: E} & PropsOf<E>) { return null; }",
1683
- Partly:
1684
- "export function Partly<E extends ElementType = 'div'>(props: Partial<PropsOf<E>>) { return null; }",
1685
- Remapped:
1686
- 'export function Remapped<T extends Record<string, unknown> = {value: string}>(props: {[K in keyof T & string as `on${Capitalize<K>}Change`]?: (value: T[K]) => void}) { return null; }',
1687
- Inferred:
1688
- 'interface InferredBase { label?: string } export function Inferred<P extends InferredBase>(props: P) { return null; }',
1689
- // An `as` clause that names props from one: through an alias (in an
1690
- // intersection, or through another alias), inline, or behind a
1691
- // condition; and keys made from one.
1692
- PrefixAlias:
1693
- 'export function PrefixAlias<N extends string>(props: Prefixed<N>) { return null; }',
1694
- PrefixNested:
1695
- 'export function PrefixNested<N extends string>(props: Pair<N>) { return null; }',
1696
- PrefixDeep:
1697
- 'export function PrefixDeep<N extends string>(props: Relayed<N>) { return null; }',
1698
- Templated:
1699
- 'export function Templated<K extends string>(props: {[P in `on${K}`]?: () => void}) { return null; }',
1700
- PrefixInline:
1701
- "export function PrefixInline<N extends string>(props: {[K in 'value' | 'change' as `${N}${Capitalize<K>}`]?: string}) { return null; }",
1702
- PrefixGated:
1703
- "export function PrefixGated<T extends boolean>(props: {[K in 'value' | 'change' as T extends true ? K : never]?: string}) { return null; }",
1704
- // Props made from one that show the compiler no members at all.
1705
- Bagged:
1706
- 'interface Bag<T> {} export function Bagged<T>(props: Bag<T>) { return null; }',
1707
- }).map(([name, source]) =>
1708
- component(name, [...PROPS_OF, source].join('\n'), {
1709
- props: [prop('elevation', 'number')],
1710
- }),
1711
- );
1712
- // A generic whose own props take any name, or map keys of its own (an
1713
- // `as` clause over its own key, or an alias or key filter given fixed
1714
- // arguments), has names of its own: compared.
1715
- const own = (/** @type {string} */ names) =>
1716
- names.split(' ').map(name => prop(name, 'X', {required: true}));
1717
- const owned = [
1718
- ['GenericOpen', '{items: T[]; [key: string]: any}', 'items'],
1719
- ['GenericRecord', '{items: T[]} & Record<string, any>', 'items'],
1720
- ['GenericRecordKeys', "Record<'value' | 'initial', T>", 'initial value'],
1721
- ['GenericFiltered', "{[K in 'a' | 'b' as Exclude<K, 'b'>]: T}", 'a'],
1722
- ['GenericPrefixed', "Prefixed<'my'>", 'myChange myValue'],
1723
- ['GenericPair', "Pair<'my'>", 'label mya myb'],
1724
- ['GenericRelayed', "Relayed<'my'>", 'myChange myValue'],
1725
- [
1726
- 'GenericExcept',
1727
- "{items: T[]} & Except<{a: string; b: string}, 'b'>",
1728
- 'a items',
1729
- ],
1730
- [
1731
- 'GenericByValue',
1732
- '{items: T[]} & PickByValue<{onPick: () => void; size: number}, Function>',
1733
- 'items onPick',
1734
- ],
1735
- ].map(([name, props, names]) =>
1736
- component(
1737
- name,
1738
- [
1739
- ...PROPS_OF,
1740
- `export function ${name}<T>(props: ${props}) { return null; }`,
1741
- ].join('\n'),
1742
- {props: own(names)},
1743
- ),
1744
- );
1745
- // Props that are plainly empty, generic or not, are compared: TypeScript
1746
- // takes none of the documented props.
1747
- const empty = ['NoProps', 'NoPropsT<T>'].map(name =>
1748
- component(
1749
- name.replace('<T>', ''),
1750
- `export function ${name}(props: {}) { return null; }\n`,
1751
- {props: [prop('label', 'string')]},
1752
- ),
1753
- );
1754
-
1755
- const report = await compare([
1756
- ...unread,
1757
- lonely,
1758
- open,
1759
- ...reached,
1760
- ...references,
1761
- untyped,
1762
- ...generics,
1763
- ...owned,
1764
- ...empty,
1765
- ]);
1766
-
1767
- expect(kinds(report)).toEqual([
1768
- 'NoProps.label not_in_code',
1769
- 'NoPropsT.label not_in_code',
1770
- ]);
1771
- expect(report.components).toBe(13);
1772
- const generic_ =
1773
- 'Bagged Inferred Joint Partly Poly PrefixAlias PrefixDeep PrefixGated PrefixInline PrefixNested Remapped Templated'.split(
1774
- ' ',
1775
- );
1776
- expect(report.unchecked.map(u => u.component)).toEqual(
1777
- 'Aliased Bagged Bare Chosen Classy Comma Deep Documented Effect Fallback Ghost Handlers Header Inferred Joined Joint Kept Keyed Lonely Mapped Member Named Nested Omitted Omitting Partly Peered Phantom Picked Poly PrefixAlias PrefixDeep Prefixed PrefixGated PrefixInline PrefixNested Recorded Referenced Remapped Sized Spread Templated Toned Unnamed Valued Wrapped'.split(
1778
- ' ',
1779
- ),
1780
- );
1781
- // A type the compiler can't work out, though every reference resolves.
1782
- const untyped_ =
1783
- 'Aliased Documented Handlers Omitting Recorded Sized Spread Toned Valued'.split(
1784
- ' ',
1785
- );
1786
- for (const {component: name, reason} of report.unchecked) {
1787
- expect(reason).toContain(
1788
- name === 'Lonely'
1789
- ? 'Lonely.tsx has no export named Lonely'
1790
- : generic_.includes(name)
1791
- ? 'from a type parameter'
1792
- : untyped_.includes(name)
1793
- ? "a type the compiler can't work out"
1794
- : 'could not resolve',
1795
- );
1796
- }
1797
- });
1798
- });
1799
-
1800
- /**
1801
- * A multi-component doc's entry.
1802
- * @param {string} name
1803
- * @param {any[]} props
1804
- */
1805
- const entry = (name, props) => ({
1806
- name,
1807
- displayName: name,
1808
- description: 'Fixture.',
1809
- props,
1810
- });
1811
-
1812
- /** @param {import('./prop-drift.mjs').PropDriftComponent[]} components */
1813
- function compareDocs(components) {
1814
- return comparePropDocs(components, {packageDir: pkg, resolveFrom: [pkg]});
1815
- }
1816
-
1817
- describe('comparePropDocs', () => {
1818
- it('compares each entry of a multi-component doc against its own export, and skips hooks', async () => {
1819
- withTypeScript();
1820
- const tabs = component(
1821
- 'Tabs',
1822
- `export function Tabs(props: {value: string}) { return null; }
1823
- export function Tab(props: {value: string; isDisabled?: boolean}) { return null; }
1824
- export function useTabs(options: {value: string}) { return options; }`,
1825
- {
1826
- components: [
1827
- entry('Tabs', [prop('value', 'string', {required: true})]),
1828
- entry('Tab', [
1829
- prop('value', 'string', {required: true}),
1830
- prop('isSelected', 'boolean'),
1831
- ]),
1832
- {
1833
- name: 'useTabs',
1834
- displayName: 'useTabs',
1835
- description: 'Fixture.',
1836
- params: [
1837
- {
1838
- name: 'options',
1839
- type: '{value: string}',
1840
- description: 'Fixture.',
1841
- },
1842
- ],
1843
- },
1844
- ],
1845
- },
1846
- );
1847
-
1848
- const report = await compareDocs([tabs]);
1849
-
1850
- expect(report.components).toBe(2);
1851
- expect(kinds(report)).toEqual([
1852
- 'Tab.isDisabled not_in_doc',
1853
- 'Tab.isSelected not_in_code',
1854
- ]);
1855
- });
1856
-
1857
- it('compares a member record only against its own source, and the family record leaves that member alone', async () => {
1858
- withTypeScript();
1859
- const status = component(
1860
- 'Status',
1861
- 'export function Status(props: {value: string}) { return null; }\n',
1862
- {
1863
- components: [
1864
- entry('Status', [prop('value', 'string', {required: true})]),
1865
- entry('StatusGlyph', [
1866
- prop('size', 'number'),
1867
- prop('tone', 'string'),
1868
- ]),
1869
- ],
1870
- },
1871
- );
1872
- const glyphSource = path.join(pkg, 'components', 'StatusView.tsx');
1873
- fs.writeFileSync(
1874
- glyphSource,
1875
- 'export function StatusGlyph(props: {size?: number}) { return null; }\n',
1876
- );
1877
-
1878
- const report = await compareDocs([
1879
- status,
1880
- {...status, name: 'StatusGlyph', sourcePath: glyphSource},
1881
- ]);
1882
-
1883
- expect(report.unchecked).toEqual([]);
1884
- expect(report.components).toBe(2);
1885
- expect(kinds(report)).toEqual(['StatusGlyph.tone not_in_code']);
1886
- expect(report.findings[0].source).toBe('components/StatusView.tsx');
1887
- });
1888
-
1889
- it('lists a member record that no file in the package declares as not compared', async () => {
1890
- withTypeScript();
1891
- const status = component(
1892
- 'Status',
1893
- 'export function Status(props: {value: string}) { return null; }\n',
1894
- {
1895
- components: [
1896
- entry('Status', [prop('value', 'string', {required: true})]),
1897
- entry('StatusGlyph', [prop('size', 'number')]),
1898
- ],
1899
- },
1900
- );
1901
-
1902
- // Only another folder, or built output, declares the member.
1903
- const report = await compareDocs([
1904
- status,
1905
- {...status, name: 'StatusGlyph', sourcePath: null},
1906
- ]);
1907
-
1908
- expect(report.components).toBe(1);
1909
- expect(report.findings).toEqual([]);
1910
- expect(report.unchecked).toEqual([
1911
- {
1912
- component: 'StatusGlyph',
1913
- doc: 'components/Status.doc.mjs',
1914
- reason: 'no source file for StatusGlyph',
1915
- },
1916
- ]);
1917
- });
1918
-
1919
- it('compares every entry of a family doc named after another export, and lists one with no source as not compared', async () => {
1920
- withTypeScript();
1921
- const menu = component(
1922
- 'Menu',
1923
- [
1924
- 'export function MenuRoot(props: {open?: boolean}) { return null; }',
1925
- 'export function MenuItem(props: {value: string}) { return null; }',
1926
- ].join('\n'),
1927
- {
1928
- name: 'MenuRoot',
1929
- hiddenComponents: ['MenuItem', 'MenuPart'],
1930
- components: [
1931
- entry('MenuItem', [prop('label', 'string')]),
1932
- entry('MenuGhost', [prop('tone', 'string')]),
1933
- entry('MenuPart', [prop('tone', 'string')]),
1934
- ],
1935
- },
1936
- );
1937
- // A hidden entry declared in another file of the doc's folder.
1938
- fs.writeFileSync(
1939
- path.join(pkg, 'components', 'menu-parts.tsx'),
1940
- 'export function MenuPart(props: {depth?: number}) { return null; }\n',
1941
- );
1942
-
1943
- // Discovery records the doc under `MenuRoot` and leaves the hidden
1944
- // `MenuItem` and `MenuPart` and the unbuilt `MenuGhost` without records
1945
- // of their own.
1946
- const report = await compareDocs([{...menu, name: 'MenuRoot'}]);
1947
-
1948
- expect(kinds(report)).toEqual([
1949
- 'MenuItem.label not_in_code',
1950
- 'MenuItem.value not_in_doc',
1951
- 'MenuPart.depth not_in_doc',
1952
- 'MenuPart.tone not_in_code',
1953
- ]);
1954
- expect(report.unchecked).toEqual([
1955
- {
1956
- component: 'MenuGhost',
1957
- doc: 'components/Menu.doc.mjs',
1958
- reason: 'Menu.tsx has no export named MenuGhost',
1959
- },
1960
- ]);
1961
- });
1962
-
1963
- it("compares a doc's own props with the export its name names, which another file can hold", async () => {
1964
- withTypeScript();
1965
- const status = component(
1966
- 'Status',
1967
- 'export function Status(props: {value: string}) { return null; }\n',
1968
- {name: 'StatusView', props: [prop('size', 'number')]},
1969
- );
1970
- const viewSource = path.join(pkg, 'components', 'StatusView.tsx');
1971
- fs.writeFileSync(
1972
- viewSource,
1973
- 'export function StatusView(props: {size?: number}) { return null; }\n',
1974
- );
1975
-
1976
- // Discovery names the record after the file, or after the export.
1977
- const byFile = await compareDocs([status]);
1978
- const byExport = await compareDocs([
1979
- {...status, name: 'StatusView', sourcePath: viewSource},
1980
- ]);
1981
-
1982
- for (const report of [byFile, byExport]) {
1983
- expect(report.unchecked).toEqual([]);
1984
- expect(report.components).toBe(1);
1985
- expect(report.findings).toEqual([]);
1986
- }
1987
- });
1988
-
1989
- it('compares a table for one component in each doc that has one', async () => {
1990
- withTypeScript();
1991
- const title = prop('title', 'string', {required: true});
1992
- const list = component(
1993
- 'List',
1994
- 'export function List(props: {label: string}) { return null; }\n',
1995
- {
1996
- components: [
1997
- entry('List', [prop('label', 'string', {required: true})]),
1998
- entry('ListGroup', [title]),
1999
- ],
2000
- },
2001
- );
2002
- const group = component(
2003
- 'ListGroup',
2004
- 'export function ListGroup(props: {title: string}) { return null; }\n',
2005
- {props: [title, prop('stale', 'string')]},
2006
- );
2007
-
2008
- const report = await compareDocs([list, group]);
2009
-
2010
- expect(report.components).toBe(3);
2011
- expect(kinds(report)).toEqual(['ListGroup.stale not_in_code']);
2012
- expect(report.findings[0].doc).toBe('components/ListGroup.doc.mjs');
2013
- });
2014
-
2015
- it('lists every component as not compared when a declaration file the config includes, or a type package it names, does not resolve', async () => {
2016
- withTypeScript();
2017
- const tsconfig = path.join(pkg, 'tsconfig.json');
2018
- const config = JSON.parse(fs.readFileSync(tsconfig, 'utf8'));
2019
- /** @param {object} options */
2020
- const configure = options =>
2021
- fs.writeFileSync(
2022
- tsconfig,
2023
- JSON.stringify({
2024
- ...config,
2025
- compilerOptions: {...config.compilerOptions, ...options},
2026
- include: ['components', 'types'],
2027
- }),
2028
- );
2029
- fs.mkdirSync(path.join(pkg, 'types'));
2030
- const globals = path.join(pkg, 'types', 'globals.d.ts');
2031
- const tables = () => [
2032
- component(
2033
- 'Omitted',
2034
- 'export function Omitted(props: Omit<{label: string; size?: number}, keyof MissingProps>) { return null; }\n',
2035
- {
2036
- props: [
2037
- prop('label', 'string', {required: true}),
2038
- prop('size', 'number'),
2039
- ],
2040
- },
2041
- ),
2042
- component(
2043
- 'Plain',
2044
- 'export function Plain(props: {label?: string}) { return null; }\n',
2045
- {props: [prop('label', 'string')]},
2046
- ),
2047
- ];
2048
- /** @param {RegExp} reason */
2049
- const unread = reason =>
2050
- ['Omitted', 'Plain'].map(name => ({
2051
- component: name,
2052
- doc: `components/${name}.doc.mjs`,
2053
- reason: expect.stringMatching(reason),
2054
- }));
2055
-
2056
- // A global type made from a package that isn't installed.
2057
- configure({});
2058
- fs.writeFileSync(
2059
- globals,
2060
- "import type {Props} from '@acme/not-installed';\ndeclare global { type MissingProps = Props; }\n",
2061
- );
2062
- let report = await compare(tables());
2063
- expect(report.findings).toEqual([]);
2064
- expect(report.unchecked).toEqual(
2065
- unread(
2066
- /depends on `@acme\/not-installed` \(imported in \.\.\/types\/globals\.d\.ts\)/,
2067
- ),
2068
- );
2069
-
2070
- // A global type made from a name declared nowhere.
2071
- fs.writeFileSync(
2072
- globals,
2073
- 'declare global { type MissingProps = NowhereProps; }\nexport {};\n',
2074
- );
2075
- report = await compare(tables());
2076
- expect(report.findings).toEqual([]);
2077
- expect(report.unchecked).toEqual(
2078
- unread(
2079
- /depends on `NowhereProps` \(used in \.\.\/types\/globals\.d\.ts\)/,
2080
- ),
2081
- );
2082
-
2083
- // A type package the config names that isn't installed.
2084
- fs.writeFileSync(
2085
- globals,
2086
- 'declare global { type MissingProps = {id?: string}; }\nexport {};\n',
2087
- );
2088
- configure({types: ['@acme/not-installed-globals']});
2089
- report = await compare(tables());
2090
- expect(report.findings).toEqual([]);
2091
- expect(report.unchecked).toEqual(
2092
- unread(
2093
- /depends on the types `@acme\/not-installed-globals` \(named in \.\.\/tsconfig\.json\)/,
2094
- ),
2095
- );
2096
-
2097
- // Both resolved: compared.
2098
- configure({types: []});
2099
- report = await compare(tables());
2100
- expect(report.unchecked).toEqual([]);
2101
- expect(report.components).toBe(2);
2102
- });
2103
-
2104
- it("lists every table, with the error, when the package's TypeScript config has an error", async () => {
2105
- withTypeScript();
2106
- fs.writeFileSync(
2107
- path.join(pkg, 'tsconfig.json'),
2108
- JSON.stringify({extends: './missing-base.json'}),
2109
- );
2110
- const titled = component(
2111
- 'Titled',
2112
- 'export function Titled(props: {title?: string}) { return null; }\n',
2113
- {props: [prop('title', 'string')]},
2114
- );
2115
-
2116
- const report = await compare([titled]);
2117
-
2118
- expect(report.components).toBe(0);
2119
- expect(report.unchecked).toEqual([
2120
- expect.objectContaining({
2121
- component: 'Titled',
2122
- reason: expect.stringMatching(
2123
- /config has an error.*missing-base\.json/,
2124
- ),
2125
- }),
2126
- ]);
2127
- });
2128
-
2129
- it('accepts a name through an index signature only as TypeScript would', async () => {
2130
- withTypeScript();
2131
- const keyed = component(
2132
- 'Keyed',
2133
- [
2134
- 'export interface KeyedProps {',
2135
- ' [key: `data-${string}`]: string | undefined;',
2136
- ' [key: `${string}:${string}`]: string;',
2137
- ' [key: `col${number}`]: number;',
2138
- ' [key: `on${Capitalize<string>}`]: () => void;',
2139
- '}',
2140
- 'export function Keyed(props: KeyedProps) { return null; }',
2141
- ].join('\n'),
2142
- {
2143
- props: [
2144
- prop('data-section', 'string'),
2145
- prop('a:b', 'string'),
2146
- prop('col2', 'number'),
2147
- prop('onClick', '() => void'),
2148
- prop('elevation', 'string'),
2149
- prop('colSpan', 'string'),
2150
- prop('onclick', 'string'),
2151
- ],
2152
- },
2153
- );
2154
- const empty = component(
2155
- 'Empty',
2156
- `interface EmptyProps { label?: string }
2157
- export function Empty(props: EmptyProps | Record<string, never>) { return null; }`,
2158
- {props: [prop('label', 'string'), prop('elevation', 'number')]},
2159
- );
2160
- const typedAny = component(
2161
- 'TypedAny',
2162
- 'export function TypedAny(props: any) { return null; }\n',
2163
- {props: [prop('label', 'string')]},
2164
- );
2165
- const anyConst = component(
2166
- 'AnyConst',
2167
- 'export const AnyConst: any = null;\n',
2168
- {props: [prop('label', 'string')]},
2169
- );
2170
-
2171
- const report = await compare([keyed, empty, typedAny, anyConst]);
2172
-
2173
- expect(kinds(report)).toEqual([
2174
- 'Empty.elevation not_in_code',
2175
- 'Keyed.colSpan not_in_code',
2176
- 'Keyed.elevation not_in_code',
2177
- 'Keyed.onclick not_in_code',
2178
- ]);
2179
- expect(report.unchecked.map(u => [u.component, u.reason])).toEqual([
2180
- ['AnyConst', expect.stringContaining('typed `any`')],
2181
- ['TypedAny', expect.stringContaining('typed `any`')],
2182
- ]);
2183
- });
2184
-
2185
- it("reads props through React's component types, lists the ones typed any or named by the element they render, and loads the ambient types tsconfig includes", async () => {
2186
- withTypeScript();
2187
- fs.mkdirSync(path.join(pkg, 'node_modules', '@types'), {recursive: true});
2188
- fs.symlinkSync(
2189
- path.dirname(require.resolve('@types/react/package.json')),
2190
- path.join(pkg, 'node_modules', '@types', 'react'),
2191
- 'dir',
2192
- );
2193
- const tsconfig = path.join(pkg, 'tsconfig.json');
2194
- const config = JSON.parse(fs.readFileSync(tsconfig, 'utf8'));
2195
- fs.writeFileSync(
2196
- tsconfig,
2197
- JSON.stringify({...config, include: ['components', 'types']}),
2198
- );
2199
- fs.mkdirSync(path.join(pkg, 'types'));
2200
- fs.writeFileSync(
2201
- path.join(pkg, 'types', 'ambient.d.ts'),
2202
- 'interface AmbientProps { label?: string }\n',
2203
- );
2204
- const source = `import {forwardRef, memo, type FC, type ComponentType, type ComponentPropsWithoutRef, type ElementType} from 'react';
2205
- export function Poly<E extends ElementType = 'div'>(props: {as?: E; padding?: number} & Omit<ComponentPropsWithoutRef<E>, 'as' | 'padding'>) { return null; }
2206
- export const Fc: FC<any> = () => null;
2207
- export const Memo = memo((props: any) => null);
2208
- export const Fwd = forwardRef<HTMLDivElement, any>((props, ref) => null);
2209
- export const FwdOmit = forwardRef<HTMLDivElement, Omit<any, 'as'>>((props, ref) => null);
2210
- export const FwdPartial = memo(forwardRef<HTMLDivElement, Partial<any>>((props, ref) => null));
2211
- export function Ambient(props: AmbientProps) { return null; }
2212
- export const Typed: ComponentType<{label?: string}> = () => null;
2213
- const withName = <P,>(c: ComponentType<P>): ComponentType<P> => c;
2214
- export const Hoc = withName((props: {label?: string}) => null);`;
2215
- const props = [prop('label', 'string'), prop('elevation', 'number')];
2216
-
2217
- const report = await compare(
2218
- 'Fc Memo Fwd FwdOmit FwdPartial Poly Ambient Typed Hoc'
2219
- .split(' ')
2220
- .map(name => component(name, source, {props})),
2221
- );
2222
-
2223
- expect(kinds(report)).toEqual(
2224
- 'Ambient Hoc Typed'
2225
- .split(' ')
2226
- .map(name => `${name}.elevation not_in_code`),
2227
- );
2228
- expect(report.unchecked.map(u => [u.component, u.reason])).toEqual(
2229
- ['Fc', 'Fwd', 'FwdOmit', 'FwdPartial', 'Memo', 'Poly'].map(name => [
2230
- name,
2231
- expect.stringContaining(
2232
- name === 'Poly' ? 'from a type parameter' : 'typed `any`',
2233
- ),
2234
- ]),
2235
- );
2236
- });
2237
-
2238
- it('reads names that list several props, spreads, and fields through arrays, tuples, unions and index signatures', async () => {
2239
- withTypeScript();
2240
- const menu = component(
2241
- 'Menu',
2242
- [
2243
- 'export interface MenuProps {',
2244
- ' onOpen?: () => void;',
2245
- ' onClose?: () => void;',
2246
- ' value?: {label: string; items: ReadonlyArray<{id: string}>};',
2247
- ' labels?: Record<string, string>;',
2248
- ' slots?: {[key: `slot-${string}`]: string};',
2249
- " rows?: Array<{kind: 'a'; total: string} | {kind: 'b'}>;",
2250
- ' grid?: Array<Array<{id: string}>>;',
2251
- ' pair?: readonly [{id: string}, {id: number}];',
2252
- '}',
2253
- 'export function Menu(props: MenuProps) { return null; }',
2254
- ].join('\n'),
2255
- {
2256
- props: [
2257
- prop('onOpen / onClose', '() => void / () => void'),
2258
- prop('...rest', 'Omit<OtherProps, "x">'),
2259
- ...['value.label', 'value.items[].id', 'value.missing'].map(name =>
2260
- prop(name, 'string'),
2261
- ),
2262
- ...['labels.close', 'slots.slot-a', 'slots.other'].map(name =>
2263
- prop(name, 'string'),
2264
- ),
2265
- ...['rows[].total', 'grid[][].id', 'grid[][].size', 'pair[].id'].map(
2266
- name => prop(name, 'string'),
2267
- ),
2268
- ],
2269
- },
2270
- );
2271
-
2272
- expect(kinds(await compare([menu]))).toEqual([
2273
- 'Menu.grid[][].size not_in_code',
2274
- 'Menu.slots.other not_in_code',
2275
- 'Menu.value.missing not_in_code',
2276
- ]);
2277
- });
2278
-
2279
- it("compares with TypeScript 7's TypeScript 6 API package when the project has one", async () => {
2280
- const badge = component(
2281
- 'Badge',
2282
- 'export function Badge(props: {label: string}) { return null; }\n',
2283
- {props: [prop('label', 'number')]},
2284
- );
2285
- withTypeScript7AndItsTypeScript6Api();
2286
-
2287
- const report = await compare([badge]);
2288
-
2289
- expect(report.status).toBe('checked');
2290
- // The comparison ran: the documented `number` is judged against `string`.
2291
- expect(
2292
- report.findings.map(f => `${f.component}.${f.prop} ${f.kind}`),
2293
- ).toContain('Badge.label type_mismatch');
2294
- });
2295
-
2296
- it('skips with a reason, and compares nothing, without a TypeScript it can use', async () => {
2297
- const badge = component(
2298
- 'Badge',
2299
- 'export function Badge(props: {label: string}) { return null; }\n',
2300
- {props: [prop('label', 'number')]},
2301
- );
2302
- const skipped = (/** @type {string} */ reason) => ({
2303
- status: 'skipped',
2304
- reason,
2305
- components: 0,
2306
- typesCompared: 0,
2307
- findings: [],
2308
- unchecked: [],
2309
- typesNotCompared: [],
2310
- });
2311
-
2312
- expect(await compare([badge])).toEqual(skipped(TYPESCRIPT_MISSING_REASON));
2313
- expect(TYPESCRIPT_MISSING_REASON).toContain('npm install -D typescript@6');
2314
- // TypeScript 7 has no JavaScript compiler API to load.
2315
- const dir = path.join(pkg, 'node_modules', 'typescript');
2316
- fs.mkdirSync(dir, {recursive: true});
2317
- fs.writeFileSync(
2318
- path.join(dir, 'package.json'),
2319
- JSON.stringify({
2320
- name: 'typescript',
2321
- version: '7.0.0',
2322
- exports: {'./package.json': './package.json'},
2323
- }),
2324
- );
2325
- const report = await compare([badge]);
2326
- expect(report.reason).toContain('TypeScript 7.0.0');
2327
- expect(report.reason).toContain('npm install -D @typescript/typescript6');
2328
- expect(report).toEqual(
2329
- skipped(
2330
- unusableTypeScriptReason(
2331
- '7.0.0',
2332
- 'documented props were not compared with the code',
2333
- ),
2334
- ),
2335
- );
2336
- });
2337
- });