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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +74 -73
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/discover/_adapter.d.mts +119 -12
  4. package/api/discover/_adapter.mjs +449 -10
  5. package/api/discover/_adapter.test.mjs +599 -17
  6. package/api/discover/_catalog-view.d.mts +16 -5
  7. package/api/discover/_catalog-view.mjs +32 -8
  8. package/api/discover/discover.d.mts +11 -0
  9. package/api/discover/discover.doc.mjs +7 -6
  10. package/api/discover/discover.mjs +107 -19
  11. package/api/discover/discover.type.d.mts +18 -7
  12. package/api/discover/discover.type.mjs +15 -7
  13. package/api/discover/list/list.d.mts +4 -3
  14. package/api/discover/list/list.mjs +17 -10
  15. package/api/docs/_adapter.d.mts +11 -0
  16. package/api/docs/_adapter.mjs +244 -1
  17. package/api/docs/integrationDocs.test.mjs +124 -0
  18. package/api/doctor/doctor.mjs +27 -3
  19. package/api/doctor/doctor.test.mjs +43 -0
  20. package/api/doctor/theme-checks.mjs +1 -1
  21. package/api/doctor/theme-checks.test.mjs +136 -0
  22. package/api/gap-report/gap-report.d.mts +3 -0
  23. package/api/gap-report/gap-report.doc.mjs +11 -3
  24. package/api/gap-report/gap-report.mjs +152 -48
  25. package/api/gap-report/gap-report.test.mjs +233 -0
  26. package/api/gap-report/gap-report.type.d.mts +41 -0
  27. package/api/gap-report/gap-report.type.mjs +18 -0
  28. package/api/index.d.mts +2 -0
  29. package/api/index.mjs +2 -0
  30. package/api/init/run/run.mjs +2 -2
  31. package/api/integration/_adapter.d.mts +32 -0
  32. package/api/integration/_adapter.mjs +80 -0
  33. package/api/integration/add-contribution.mjs +1 -1
  34. package/api/integration/add-contribution.test.mjs +4 -2
  35. package/api/integration/authoring-checks.mjs +44 -4
  36. package/api/integration/authoring-checks.test.mjs +515 -0
  37. package/api/integration/authoring-checks.type.d.mts +95 -0
  38. package/api/integration/authoring-checks.type.mjs +53 -2
  39. package/api/integration/check/check.d.mts +96 -0
  40. package/api/integration/check/check.mjs +357 -0
  41. package/api/integration/check/check.test.mjs +489 -0
  42. package/api/integration/integration-check.type.d.mts +118 -0
  43. package/api/integration/integration-check.type.mjs +84 -0
  44. package/api/integration/integrationCheck.doc.d.mts +10 -0
  45. package/api/integration/integrationCheck.doc.mjs +73 -0
  46. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  47. package/api/integration/integrationDocConflicts.doc.mjs +19 -5
  48. package/api/integration/pack-check.mjs +292 -7
  49. package/api/integration/pack-check.test.mjs +341 -0
  50. package/api/integration/validate-integration.mjs +8 -0
  51. package/api/integration/validate-integration.test.mjs +11 -0
  52. package/api/integration/validate-integration.type.d.mts +8 -0
  53. package/api/integration/validate-integration.type.mjs +12 -1
  54. package/api/integration/validateIntegration.doc.mjs +19 -3
  55. package/api/search/search.d.mts +72 -12
  56. package/api/search/search.domain-priority.test.mjs +108 -18
  57. package/api/search/search.integration-check.test.mjs +24 -0
  58. package/api/search/search.mjs +501 -37
  59. package/api/search/search.test.mjs +139 -0
  60. package/api/theme/build/build.family.test.mjs +54 -6
  61. package/api/theme/build/build.mjs +114 -17
  62. package/api/theme/themeBuild.doc.mjs +4 -4
  63. package/api/upgrade/_adapter.d.mts +40 -2
  64. package/api/upgrade/_adapter.mjs +117 -4
  65. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  66. package/api/upgrade/run/run.mjs +30 -1
  67. package/api/upgrade/status/status.d.mts +21 -5
  68. package/api/upgrade/status/status.mjs +45 -8
  69. package/api/upgrade/upgrade.doc.mjs +5 -3
  70. package/api/upgrade/upgrade.type.d.mts +23 -0
  71. package/api/upgrade/upgrade.type.mjs +16 -1
  72. package/assets/codemods/runner.mjs +7 -1
  73. package/assets/discover/official-packages.json +367 -0
  74. package/assets/docs/README.md +10 -0
  75. package/assets/docs/author-a-theme.doc.mjs +3 -3
  76. package/assets/docs/browser-support.doc.mjs +1 -1
  77. package/assets/docs/getting-started.doc.mjs +3 -3
  78. package/assets/docs/styling-overview.doc.mjs +1 -1
  79. package/assets/docs/theme.doc.dense.mjs +1 -1
  80. package/assets/docs/theme.doc.mjs +2 -2
  81. package/assets/docs/theme.doc.zh.mjs +1 -1
  82. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  83. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  84. package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
  85. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  86. package/assets/docs/tree/block-template.doc.mjs +8 -20
  87. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  88. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  89. package/assets/docs/tree/check-your-docs.doc.mjs +61 -7
  90. package/assets/docs/tree/checks.doc.mjs +25 -17
  91. package/assets/docs/tree/codemods.doc.mjs +4 -4
  92. package/assets/docs/tree/component-family.doc.mjs +3 -5
  93. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  94. package/assets/docs/tree/components.doc.mjs +1 -1
  95. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
  96. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  97. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  98. package/assets/docs/tree/docs.doc.mjs +3 -3
  99. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  100. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  101. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  102. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  103. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  104. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  105. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  106. package/assets/docs/tree/integrations.doc.mjs +8 -0
  107. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  108. package/assets/docs/tree/layout.doc.mjs +6 -6
  109. package/assets/docs/tree/links.doc.mjs +6 -5
  110. package/assets/docs/tree/migration-setup.doc.mjs +3 -2
  111. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  112. package/assets/docs/tree/migration.doc.mjs +0 -1
  113. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  114. package/assets/docs/tree/page-template.doc.mjs +4 -8
  115. package/assets/docs/tree/publishing.doc.mjs +4 -4
  116. package/assets/docs/tree/quick-start.doc.mjs +38 -22
  117. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  118. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  119. package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
  120. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  121. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  122. package/assets/docs/tree/single-component.doc.mjs +14 -5
  123. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  124. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  125. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  126. package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
  127. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  128. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  129. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  130. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  131. package/assets/docs/tree/templates.doc.mjs +1 -1
  132. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  133. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  134. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  135. package/assets/docs/tree/troubleshooting.doc.mjs +8 -8
  136. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  137. package/assets/docs/tree/upgrading.doc.mjs +4 -4
  138. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  139. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  140. package/assets/docs/tree/versioning.doc.mjs +6 -6
  141. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  142. package/assets/docs/use-a-theme.doc.mjs +2 -2
  143. package/assets/theme.template.ts +1 -1
  144. package/authoring/codemod/codemod.doc.mjs +7 -3
  145. package/authoring/config/config.doc.mjs +9 -6
  146. package/authoring/config/type.ts +4 -2
  147. package/authoring/discover/discover.doc.mjs +1 -1
  148. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  149. package/authoring/doctypes/command/command.doc.mjs +14 -12
  150. package/authoring/doctypes/component/component.doc.mjs +29 -26
  151. package/authoring/doctypes/component/type.ts +7 -5
  152. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  153. package/authoring/doctypes/function/function.doc.mjs +9 -8
  154. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  155. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  156. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  157. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  158. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  159. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  160. package/authoring/doctypes/template/parse.d.mts +6 -2
  161. package/authoring/doctypes/template/parse.mjs +3 -1
  162. package/authoring/doctypes/template/template.doc.mjs +3 -3
  163. package/authoring/doctypes/template/type.ts +22 -0
  164. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  165. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  166. package/authoring/identity/identity.doc.mjs +3 -3
  167. package/authoring/index.d.ts +1 -0
  168. package/authoring/integration/integration.doc.mjs +12 -4
  169. package/authoring/integration/parse.test.mjs +10 -0
  170. package/authoring/integration/schema.d.mts +2 -0
  171. package/authoring/integration/schema.mjs +1 -0
  172. package/authoring/integration/type.ts +4 -0
  173. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  174. package/clients/cli/commands/build-theme.mjs +1 -1
  175. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  176. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  177. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  178. package/clients/cli/commands/discover.doc.mjs +1 -1
  179. package/clients/cli/commands/discover.mjs +144 -93
  180. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  181. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  182. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  183. package/clients/cli/commands/doctor-integration-docs.doc.mjs +18 -5
  184. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  185. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  186. package/clients/cli/commands/doctor.mjs +250 -3
  187. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  188. package/clients/cli/commands/gap-report.mjs +24 -2
  189. package/clients/cli/commands/gap-report.test.mjs +79 -0
  190. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  191. package/clients/cli/commands/integration-check.test.mjs +370 -0
  192. package/clients/cli/commands/integration.doc.mjs +6 -2
  193. package/clients/cli/commands/integration.mjs +106 -1
  194. package/clients/cli/commands/json-contract.test.mjs +5 -1
  195. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  196. package/clients/cli/commands/swizzle.mjs +5 -3
  197. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  198. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  199. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  200. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  201. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  202. package/clients/cli/index.mjs +30 -5
  203. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  204. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  205. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  206. package/foundation/agent-docs/agent-docs.mjs +8 -6
  207. package/foundation/config/project.mjs +82 -0
  208. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  209. package/foundation/discovery/component-discovery.d.mts +18 -0
  210. package/foundation/discovery/component-discovery.mjs +2 -2
  211. package/foundation/discovery/copied-passages.d.mts +216 -0
  212. package/foundation/discovery/copied-passages.mjs +720 -0
  213. package/foundation/discovery/copied-passages.test.mjs +124 -0
  214. package/foundation/discovery/doc-fluff.d.mts +112 -0
  215. package/foundation/discovery/doc-fluff.mjs +328 -0
  216. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  217. package/foundation/discovery/doc-types.d.mts +157 -0
  218. package/foundation/discovery/doc-types.mjs +1224 -0
  219. package/foundation/discovery/doc-types.test.mjs +700 -0
  220. package/foundation/discovery/docs-discovery.d.mts +88 -0
  221. package/foundation/discovery/docs-discovery.mjs +83 -2
  222. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  223. package/foundation/discovery/integration-doc-files.mjs +231 -0
  224. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  225. package/foundation/discovery/project-typescript.d.mts +11 -2
  226. package/foundation/discovery/project-typescript.mjs +32 -4
  227. package/foundation/discovery/prop-drift.d.mts +116 -3
  228. package/foundation/discovery/prop-drift.mjs +883 -41
  229. package/foundation/discovery/prop-drift.test.mjs +1738 -20
  230. package/foundation/discovery/type-match.d.mts +53 -0
  231. package/foundation/discovery/type-match.mjs +660 -0
  232. package/foundation/discovery/type-match.test.mjs +169 -0
  233. package/foundation/discovery/type-text.d.mts +68 -0
  234. package/foundation/discovery/type-text.mjs +658 -0
  235. package/foundation/discovery/type-text.test.mjs +196 -0
  236. package/foundation/doc-compiler/doc-loads.test.mjs +16 -2
  237. package/foundation/doc-compiler/links.d.mts +9 -5
  238. package/foundation/doc-compiler/links.mjs +4 -2
  239. package/foundation/env/package-manager.d.mts +32 -0
  240. package/foundation/env/package-manager.mjs +47 -0
  241. package/foundation/env/package-manager.test.mjs +194 -7
  242. package/foundation/fs/module-loader.d.mts +2 -1
  243. package/foundation/fs/module-loader.mjs +60 -4
  244. package/foundation/fs/module-loader.test.mjs +194 -0
  245. package/foundation/response/response-types.doc.mjs +14 -8
  246. package/package.json +11 -11
  247. package/scripts/postinstall.mjs +3 -3
@@ -0,0 +1,124 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+
5
+ import {
6
+ PASSAGE_WORDS,
7
+ contentWords,
8
+ passageWords,
9
+ wordSpans,
10
+ proseWords,
11
+ sharedPassages,
12
+ } from './copied-passages.mjs';
13
+
14
+ const words = (/** @type {string} */ text) =>
15
+ passageWords(text).map(word => ({word, section: null, block: 1}));
16
+
17
+ describe('passageWords', () => {
18
+ it('sets aside case, links, and Markdown emphasis', () => {
19
+ expect(
20
+ passageWords('Use **`Button`** for {@link component:Button} actions.'),
21
+ ).toEqual(['use', 'button', 'for', 'actions.']);
22
+ });
23
+ });
24
+
25
+ describe('proseWords', () => {
26
+ it('reads prose with its section, and skips code, references, and names', () => {
27
+ const doc = {
28
+ type: 'generic',
29
+ name: 'acme-guide',
30
+ title: 'Acme guide',
31
+ description: 'Intro words.',
32
+ sections: [
33
+ {
34
+ title: 'Setup',
35
+ content: [
36
+ {type: 'prose', text: 'Install it.'},
37
+ {type: 'code', lang: 'sh', code: 'npm install acme'},
38
+ {type: 'reference', ref: 'generic:other'},
39
+ {type: 'list', items: ['First step.']},
40
+ ],
41
+ },
42
+ ],
43
+ };
44
+ expect(proseWords(doc)).toEqual([
45
+ {word: 'intro', section: null, block: 1},
46
+ {word: 'words.', section: null, block: 1},
47
+ {word: 'install', section: 'Setup', block: 2},
48
+ {word: 'it.', section: 'Setup', block: 2},
49
+ {word: 'first', section: 'Setup', block: 3},
50
+ {word: 'step.', section: 'Setup', block: 3},
51
+ ]);
52
+ });
53
+ });
54
+
55
+ describe('sharedPassages', () => {
56
+ const passage = Array.from(
57
+ {length: PASSAGE_WORDS + 5},
58
+ (_, i) => `w${i}`,
59
+ ).join(' ');
60
+
61
+ it('finds the longest shared run', () => {
62
+ expect(
63
+ sharedPassages(words(`a b ${passage} c`), words(`x ${passage} y`)),
64
+ ).toEqual([{start: 2, length: PASSAGE_WORDS + 5}]);
65
+ });
66
+
67
+ it('never runs a passage from one string into the next', () => {
68
+ const half = Math.ceil(PASSAGE_WORDS / 2);
69
+ const first = passage.split(' ').slice(0, half).join(' ');
70
+ const second = passage.split(' ').slice(half, PASSAGE_WORDS).join(' ');
71
+ const split = [
72
+ ...passageWords(first).map(word => ({word, section: null, block: 1})),
73
+ ...passageWords(second).map(word => ({word, section: null, block: 2})),
74
+ ];
75
+ expect(sharedPassages(split, words(`${first} ${second}`))).toEqual([]);
76
+ });
77
+
78
+ it('ignores a run shorter than the passage size', () => {
79
+ const short = passage
80
+ .split(' ')
81
+ .slice(0, PASSAGE_WORDS - 1)
82
+ .join(' ');
83
+ expect(
84
+ sharedPassages(words(`a ${short} b`), words(`c ${short} d`)),
85
+ ).toEqual([]);
86
+ });
87
+ });
88
+
89
+ describe('contentWords', () => {
90
+ it('counts distinct words that are not function words', () => {
91
+ const run = words('and it is in the way that you can do it for them');
92
+ expect(contentWords(run, 0, run.length)).toBe(1);
93
+ const fact = words('Name each codemod folder after the Core version.');
94
+ expect(contentWords(fact, 0, fact.length)).toBe(5);
95
+ });
96
+ });
97
+
98
+ describe('wordSpans', () => {
99
+ it('reads the words passageWords reads, with where each sits as written', () => {
100
+ const text = 'Run `astryx docs`, then {@link generic:theme} *now*.';
101
+ const spans = wordSpans(text);
102
+ expect(spans.map(span => span.word)).toEqual(passageWords(text));
103
+ expect(text.slice(spans[1].start, spans[2].end)).toBe('`astryx docs`');
104
+ });
105
+ });
106
+
107
+ describe('passageWords and pointers', () => {
108
+ it('reads a link and a written docs command as no words', () => {
109
+ expect(
110
+ passageWords(
111
+ 'See {@link generic:theme} or `astryx docs theme` (Share it).',
112
+ ),
113
+ ).toEqual(['see', 'or', 'share', 'it']);
114
+ });
115
+
116
+ it('counts no punctuation-only token as a word', () => {
117
+ expect(
118
+ passageWords('Set the theme first, see {@link generic:theme}.'),
119
+ ).toEqual(['set', 'the', 'theme', 'first', 'see']);
120
+ expect(
121
+ wordSpans('Read it - then {@link generic:theme}.').map(s => s.word),
122
+ ).toEqual(['read', 'it', 'then']);
123
+ });
124
+ });
@@ -0,0 +1,112 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * A prose string with what is not prose blanked out, length kept: `{@link}`
6
+ * pointers, inline code, and quoted text. A quoted phrase is mentioned, not
7
+ * used ("cut 'in order to'").
8
+ *
9
+ * @param {string} text
10
+ * @returns {string}
11
+ */
12
+ export function maskProse(text: string): string;
13
+ /**
14
+ * Each padding phrase in a text, outside inline code and quotes, in order,
15
+ * with its offset in the text.
16
+ *
17
+ * `thatAfter` is true when the phrase is followed by a "that" a reader cuts
18
+ * with it ("It is worth noting that the cache is shared").
19
+ *
20
+ * @param {string} text
21
+ * @returns {{phrase: string, at: number, thatAfter: boolean}[]}
22
+ */
23
+ export function fillerAt(text: string): {
24
+ phrase: string;
25
+ at: number;
26
+ thatAfter: boolean;
27
+ }[];
28
+ /**
29
+ * Each padding phrase in a text, outside inline code and quotes, in order.
30
+ *
31
+ * @param {string} text
32
+ * @returns {string[]}
33
+ */
34
+ export function fillerIn(text: string): string[];
35
+ /**
36
+ * The share of a doc's prose words that are content words.
37
+ *
38
+ * @param {{word: string}[]} words
39
+ * @returns {number}
40
+ */
41
+ export function density(words: {
42
+ word: string;
43
+ }[]): number;
44
+ /**
45
+ * A number rounded down to `places` decimals, so a share under the floor
46
+ * never reads as the floor.
47
+ *
48
+ * @param {number} value
49
+ * @param {number} places
50
+ * @returns {number}
51
+ */
52
+ export function floorTo(value: number, places: number): number;
53
+ /**
54
+ * A share as a percent with one decimal, rounded down ("49.5%").
55
+ *
56
+ * @param {number} share
57
+ * @returns {string}
58
+ */
59
+ export function sharePercent(share: number): string;
60
+ /**
61
+ * The words a topic's density is measured on: its prose, without what the
62
+ * phrase check also leaves unread (links, inline code, quoted text).
63
+ *
64
+ * @param {unknown} doc
65
+ * @returns {{word: string}[]}
66
+ */
67
+ export function densityWords(doc: unknown): {
68
+ word: string;
69
+ }[];
70
+ /**
71
+ * The median density of Core's own guides of at least
72
+ * {@link DENSITY_MIN_WORDS} words.
73
+ *
74
+ * @returns {Promise<number>}
75
+ */
76
+ export function coreDensityMedian(): Promise<number>;
77
+ /**
78
+ * Fluff in a package's topics: every padding phrase, with its section and
79
+ * file line, and every topic of at least {@link DENSITY_MIN_WORDS} words
80
+ * whose density is below {@link MIN_DENSITY}.
81
+ *
82
+ * @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[]}} discovered
83
+ * the package's docs, as discoverIntegrationDocs returns them
84
+ * @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').DocFluff[]>}
85
+ */
86
+ export function findFluff(discovered: {
87
+ records: {
88
+ name: string;
89
+ path: string;
90
+ }[];
91
+ guides?: {
92
+ name: string;
93
+ ref?: {
94
+ topicFile?: string;
95
+ };
96
+ }[];
97
+ }): Promise<import("../../api/integration/authoring-checks.type.mjs").DocFluff[]>;
98
+ /**
99
+ * Padding phrases: each can be cut, or replaced by a shorter word, without
100
+ * losing meaning. Only phrases that are padding in every use are listed;
101
+ * words such as "just", "simply" or "really", and phrases such as "whether or
102
+ * not" or "keep in mind", which carry meaning in a correct sentence ("not
103
+ * simply a wrapper", "regardless of whether"), are not.
104
+ */
105
+ export const FILLER_PHRASES: string[];
106
+ /** A guide shorter than this many prose words is not scored for density. */
107
+ export const DENSITY_MIN_WORDS: 80;
108
+ /**
109
+ * A guide whose share of content words is below this is mostly glue. Core's
110
+ * own guides score from about 0.51 up, with a median near 0.62.
111
+ */
112
+ export const MIN_DENSITY: 0.5;
@@ -0,0 +1,328 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * Fluff in docs: padding phrases that add words and no meaning, and guides
5
+ * whose prose is mostly function words. Docs are read by people and agents
6
+ * with a budget, so every word should carry something.
7
+ *
8
+ * Only prose is read (the same strings copied passages compare), and inline
9
+ * code and quoted text are set aside, so a phrase inside a command, or one
10
+ * quoted as an example, never counts.
11
+ */
12
+
13
+ import fs from 'node:fs';
14
+
15
+ import {builtinGuideFiles} from './docs-discovery.mjs';
16
+ import {
17
+ contentWords,
18
+ fileWords,
19
+ lineAtOffset,
20
+ locateWords,
21
+ loadQuietly,
22
+ proseStrings,
23
+ passageWords,
24
+ textWords,
25
+ } from './copied-passages.mjs';
26
+
27
+ /**
28
+ * Padding phrases: each can be cut, or replaced by a shorter word, without
29
+ * losing meaning. Only phrases that are padding in every use are listed;
30
+ * words such as "just", "simply" or "really", and phrases such as "whether or
31
+ * not" or "keep in mind", which carry meaning in a correct sentence ("not
32
+ * simply a wrapper", "regardless of whether"), are not.
33
+ */
34
+ export const FILLER_PHRASES = [
35
+ "it's important to note",
36
+ 'it is important to note',
37
+ 'important to note that',
38
+ "it's worth noting",
39
+ 'it is worth noting',
40
+ 'worth noting that',
41
+ 'it should be noted',
42
+ 'please note',
43
+ 'note that',
44
+ 'as mentioned above',
45
+ 'as mentioned earlier',
46
+ 'as mentioned before',
47
+ 'as noted above',
48
+ 'as you can see',
49
+ 'needless to say',
50
+ 'in order to',
51
+ 'due to the fact that',
52
+ 'for the purpose of',
53
+ 'at this point in time',
54
+ 'in other words',
55
+ 'basically',
56
+ 'essentially',
57
+ 'obviously',
58
+ ];
59
+
60
+ /** What to write instead, where a phrase is not simply cut. */
61
+ const INSTEAD = {
62
+ 'in order to': 'to',
63
+ 'due to the fact that': 'because',
64
+ 'for the purpose of': 'to or for',
65
+ 'at this point in time': 'now',
66
+ };
67
+
68
+ /** A guide shorter than this many prose words is not scored for density. */
69
+ export const DENSITY_MIN_WORDS = 80;
70
+
71
+ /**
72
+ * A guide whose share of content words is below this is mostly glue. Core's
73
+ * own guides score from about 0.51 up, with a median near 0.62.
74
+ */
75
+ export const MIN_DENSITY = 0.5;
76
+
77
+ /**
78
+ * @param {string} phrase
79
+ * @returns {RegExp}
80
+ */
81
+ function phrasePattern(phrase) {
82
+ const escaped = phrase.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
83
+ // "note that" is padding as a sentence opener ("Note that X"), not inside
84
+ // one ("a note that explains").
85
+ return phrase === 'note that'
86
+ ? new RegExp(`(?:^|[.;:!?]\\s+)${escaped}\\b`, 'gi')
87
+ : // A hyphen joins words ("non-obviously"), so it bounds no phrase.
88
+ new RegExp(`(?<![a-z'-])${escaped}(?![a-z-])`, 'gi');
89
+ }
90
+
91
+ const PATTERNS = FILLER_PHRASES.map(phrase => ({
92
+ phrase,
93
+ pattern: phrasePattern(phrase),
94
+ }));
95
+
96
+ /**
97
+ * A prose string with what is not prose blanked out, length kept: `{@link}`
98
+ * pointers, inline code, and quoted text. A quoted phrase is mentioned, not
99
+ * used ("cut 'in order to'").
100
+ *
101
+ * @param {string} text
102
+ * @returns {string}
103
+ */
104
+ export function maskProse(text) {
105
+ // A quoted phrase is mentioned, not used ("cut 'in order to'"), so quotes
106
+ // are set aside along with inline code. Each mask keeps the text's length,
107
+ // so an offset in the masked text is an offset in the text.
108
+ const blank = (/** @type {string} */ span) => ' '.repeat(span.length);
109
+ return (
110
+ text
111
+ // A pointer names a doc, and its target is no prose ("{@link
112
+ // generic:obviously-fast}").
113
+ .replace(/\{@link\s[^}]*\}/g, blank)
114
+ .replace(/`[^`]*`/g, blank)
115
+ .replace(/"[^"]*"|“[^”]*”|‘[^’]*’/g, blank)
116
+ .replace(/’/g, "'")
117
+ // A single-quoted span opens and closes beside a non-letter, so the
118
+ // apostrophe in "don't" or "it's" opens nothing.
119
+ .replace(/(?<![A-Za-z])'[^']*'(?![A-Za-z])/g, blank)
120
+ );
121
+ }
122
+
123
+ /**
124
+ * Each padding phrase in a text, outside inline code and quotes, in order,
125
+ * with its offset in the text.
126
+ *
127
+ * `thatAfter` is true when the phrase is followed by a "that" a reader cuts
128
+ * with it ("It is worth noting that the cache is shared").
129
+ *
130
+ * @param {string} text
131
+ * @returns {{phrase: string, at: number, thatAfter: boolean}[]}
132
+ */
133
+ export function fillerAt(text) {
134
+ const prose = maskProse(text);
135
+ /** @type {{phrase: string, at: number, thatAfter: boolean}[]} */
136
+ const found = [];
137
+ for (const {phrase, pattern} of PATTERNS) {
138
+ for (const match of prose.matchAll(pattern)) {
139
+ // A phrase inside a longer listed one ("note that" in "worth noting
140
+ // that") is the longer one's.
141
+ const at = match.index + match[0].toLowerCase().indexOf(phrase);
142
+ if (
143
+ !found.some(each => at >= each.at && at < each.at + each.phrase.length)
144
+ ) {
145
+ found.push({
146
+ phrase,
147
+ at,
148
+ // Only a phrase that ends in note or noting leads into a "that"
149
+ // clause the reader cuts with it; "Obviously that works" and "As
150
+ // noted above that flag" keep their "that".
151
+ thatAfter:
152
+ /\bnot(?:e|ed|ing)$/.test(phrase) &&
153
+ !phrase.endsWith('that') &&
154
+ /^\s+that\b/i.test(prose.slice(at + phrase.length)),
155
+ });
156
+ }
157
+ }
158
+ }
159
+ return found.sort((a, b) => a.at - b.at);
160
+ }
161
+
162
+ /**
163
+ * Each padding phrase in a text, outside inline code and quotes, in order.
164
+ *
165
+ * @param {string} text
166
+ * @returns {string[]}
167
+ */
168
+ export function fillerIn(text) {
169
+ return fillerAt(text).map(each => each.phrase);
170
+ }
171
+
172
+ /**
173
+ * The share of a doc's prose words that are content words.
174
+ *
175
+ * @param {{word: string}[]} words
176
+ * @returns {number}
177
+ */
178
+ export function density(words) {
179
+ if (words.length === 0) return 1;
180
+ let content = 0;
181
+ for (let i = 0; i < words.length; i++) {
182
+ if (contentWords(words, i, 1) === 1) content++;
183
+ }
184
+ return content / words.length;
185
+ }
186
+
187
+ /**
188
+ * A number rounded down to `places` decimals, so a share under the floor
189
+ * never reads as the floor.
190
+ *
191
+ * @param {number} value
192
+ * @param {number} places
193
+ * @returns {number}
194
+ */
195
+ export function floorTo(value, places) {
196
+ const scale = 10 ** places;
197
+ return Math.floor(value * scale + 1e-9) / scale;
198
+ }
199
+
200
+ /**
201
+ * A share as a percent with one decimal, rounded down ("49.5%").
202
+ *
203
+ * @param {number} share
204
+ * @returns {string}
205
+ */
206
+ export function sharePercent(share) {
207
+ return `${floorTo(share * 100, 1).toFixed(1)}%`;
208
+ }
209
+
210
+ /**
211
+ * The words a topic's density is measured on: its prose, without what the
212
+ * phrase check also leaves unread (links, inline code, quoted text).
213
+ *
214
+ * @param {unknown} doc
215
+ * @returns {{word: string}[]}
216
+ */
217
+ export function densityWords(doc) {
218
+ return proseStrings(doc).flatMap(({text}) =>
219
+ passageWords(maskProse(text)).map(word => ({word})),
220
+ );
221
+ }
222
+
223
+ /**
224
+ * The median density of Core's own guides of at least
225
+ * {@link DENSITY_MIN_WORDS} words.
226
+ *
227
+ * @returns {Promise<number>}
228
+ */
229
+ export async function coreDensityMedian() {
230
+ // Core's guides are measured the way a package's topics are.
231
+ /** @type {number[]} */
232
+ const scores = [];
233
+ for (const file of builtinGuideFiles()) {
234
+ const doc = await loadQuietly(file);
235
+ if (typeof doc?.name !== 'string') continue;
236
+ const words = densityWords(doc);
237
+ if (words.length >= DENSITY_MIN_WORDS) scores.push(density(words));
238
+ }
239
+ scores.sort((a, b) => a - b);
240
+ return scores.length === 0 ? 0 : scores[Math.floor(scores.length / 2)];
241
+ }
242
+
243
+ /**
244
+ * Fluff in a package's topics: every padding phrase, with its section and
245
+ * file line, and every topic of at least {@link DENSITY_MIN_WORDS} words
246
+ * whose density is below {@link MIN_DENSITY}.
247
+ *
248
+ * @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[]}} discovered
249
+ * the package's docs, as discoverIntegrationDocs returns them
250
+ * @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').DocFluff[]>}
251
+ */
252
+ export async function findFluff(discovered) {
253
+ const topics = [
254
+ ...discovered.records.map(record => ({
255
+ name: record.name,
256
+ file: record.path,
257
+ })),
258
+ ...(discovered.guides ?? []).map(guide => ({
259
+ name: guide.name,
260
+ file: guide.ref?.topicFile,
261
+ })),
262
+ ];
263
+ /** @type {import('../../api/integration/authoring-checks.type.mjs').DocFluff[]} */
264
+ const found = [];
265
+ /** @type {number | null} */
266
+ let median = null;
267
+ for (const {name, file} of topics) {
268
+ const doc = file ? await loadQuietly(file) : null;
269
+ if (!doc || !file) continue;
270
+ /** @type {{word: string, line: number}[]} */
271
+ let source = [];
272
+ try {
273
+ source = fileWords(fs.readFileSync(file, 'utf8'));
274
+ } catch {
275
+ // No line numbers; each finding still names its section.
276
+ }
277
+ // Each string is found by its whole run of words, from where the last
278
+ // one was found, so two strings that open alike keep their own lines.
279
+ let cursor = 0;
280
+ for (const {text, section} of proseStrings(doc)) {
281
+ const words = textWords(text);
282
+ let index = locateWords(source, words, cursor);
283
+ if (index < 0) index = locateWords(source, words);
284
+ if (index >= 0) cursor = index + words.length;
285
+ for (const {phrase, at, thatAfter} of fillerAt(text)) {
286
+ const line = index < 0 ? null : lineAtOffset(source, index, words, at);
287
+ const where = section ? ` (section "${section}")` : '';
288
+ const instead = /** @type {Record<string, string>} */ (INSTEAD)[phrase];
289
+ found.push({
290
+ topic: name,
291
+ kind: 'phrase',
292
+ phrase,
293
+ section,
294
+ file,
295
+ line,
296
+ density: null,
297
+ message:
298
+ `"${name}"${where} pads its prose with "${phrase}"` +
299
+ `${line == null ? '' : ` (line ${line})`}. ` +
300
+ (instead
301
+ ? `Write "${instead}" instead.`
302
+ : thatAfter
303
+ ? 'Cut it and the "that" after it; the sentence says the same without them.'
304
+ : 'Cut it; the sentence says the same without it.'),
305
+ });
306
+ }
307
+ }
308
+ const words = densityWords(doc);
309
+ if (words.length < DENSITY_MIN_WORDS) continue;
310
+ const score = density(words);
311
+ if (score >= MIN_DENSITY) continue;
312
+ median ??= await coreDensityMedian();
313
+ found.push({
314
+ topic: name,
315
+ kind: 'density',
316
+ phrase: null,
317
+ section: null,
318
+ file,
319
+ line: null,
320
+ density: floorTo(score, 3),
321
+ message:
322
+ `"${name}" is mostly glue: ${sharePercent(score)} of its ${words.length} prose words carry content, ` +
323
+ `under the ${Math.round(MIN_DENSITY * 100)}% floor (Core's guides have a median of ${Math.round(median * 100)}%). ` +
324
+ 'Cut filler and restated context until each sentence states one thing.',
325
+ });
326
+ }
327
+ return found;
328
+ }
@@ -0,0 +1,142 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+
5
+ import {
6
+ density,
7
+ densityWords,
8
+ fillerAt,
9
+ fillerIn,
10
+ floorTo,
11
+ sharePercent,
12
+ } from './doc-fluff.mjs';
13
+ import {passageWords} from './copied-passages.mjs';
14
+
15
+ const words = (/** @type {string} */ text) =>
16
+ passageWords(text).map(word => ({word}));
17
+
18
+ describe('fillerIn', () => {
19
+ it('finds padding phrases in order, the longest one only', () => {
20
+ expect(
21
+ fillerIn(
22
+ 'In order to start, it is worth noting that you basically run it. Note that it builds.',
23
+ ),
24
+ ).toEqual(['in order to', 'it is worth noting', 'basically', 'note that']);
25
+ });
26
+
27
+ it('leaves inline code, quotes, a noun "note", and ambiguous words alone', () => {
28
+ expect(
29
+ fillerIn(
30
+ 'Run `basically --in order to`. Cut "in order to" and “basically”. Add a note that explains it. Copy just this one file; it really is the source.',
31
+ ),
32
+ ).toEqual([]);
33
+ });
34
+
35
+ it('sets aside single-quoted text, but not an apostrophe', () => {
36
+ expect(
37
+ fillerIn(
38
+ "Avoid ‘basically’ and ‘obviously’. Don't write 'it is worth noting that' in a guide.",
39
+ ),
40
+ ).toEqual([]);
41
+ expect(fillerIn("Don't pad: it's important to note the order.")).toEqual([
42
+ "it's important to note",
43
+ ]);
44
+ });
45
+
46
+ it('lists no phrase that carries meaning in a correct sentence', () => {
47
+ expect(
48
+ fillerIn(
49
+ 'It is not simply a wrapper. Every app gets a theme whether or not anyone picks one. Keep in mind the order. Feel free to skip it.',
50
+ ),
51
+ ).toEqual([]);
52
+ });
53
+
54
+ it('reads a curly apostrophe like a straight one', () => {
55
+ expect(fillerIn('It’s important to note the order.')).toEqual([
56
+ "it's important to note",
57
+ ]);
58
+ });
59
+ });
60
+
61
+ describe('fillerAt', () => {
62
+ it('reads no phrase inside a link target or a hyphenated word', () => {
63
+ expect(
64
+ fillerIn(
65
+ 'Read {@link generic:obviously-fast} before you tune the build.',
66
+ ),
67
+ ).toEqual([]);
68
+ expect(fillerIn('A non-obviously slow build still passes.')).toEqual([]);
69
+ expect(fillerIn('It is obviously slow.')).toEqual(['obviously']);
70
+ });
71
+
72
+ it('marks a "that" the reader cuts with the phrase', () => {
73
+ expect(
74
+ fillerAt('It is worth noting that the cache is shared.').map(
75
+ each => each.thatAfter,
76
+ ),
77
+ ).toEqual([true]);
78
+ expect(
79
+ fillerAt('Basically, the cache is shared.').map(each => each.thatAfter),
80
+ ).toEqual([false]);
81
+ // Only a note or noting phrase leads a clause the reader cuts.
82
+ expect(
83
+ fillerAt('Obviously that works only in a browser.').map(
84
+ each => each.thatAfter,
85
+ ),
86
+ ).toEqual([false]);
87
+ expect(
88
+ fillerAt('As noted above that flag is required.').map(
89
+ each => each.thatAfter,
90
+ ),
91
+ ).toEqual([false]);
92
+ });
93
+ });
94
+
95
+ describe('densityWords', () => {
96
+ it('measures prose only, not quoted text, inline code or links', () => {
97
+ const doc = {
98
+ sections: [
99
+ {
100
+ title: 'Overview',
101
+ content: [
102
+ {
103
+ type: 'prose',
104
+ text: 'Theme tokens set colors. Write "it is in the" or `of the` as {@link generic:theme} shows.',
105
+ },
106
+ ],
107
+ },
108
+ ],
109
+ };
110
+ expect(densityWords(doc).map(each => each.word)).toEqual([
111
+ 'theme',
112
+ 'tokens',
113
+ 'set',
114
+ 'colors.',
115
+ 'write',
116
+ 'or',
117
+ 'as',
118
+ 'shows.',
119
+ ]);
120
+ });
121
+ });
122
+
123
+ describe('share rounding', () => {
124
+ it('rounds a share under the floor down, never up to it', () => {
125
+ expect(floorTo(0.4995, 3)).toBe(0.499);
126
+ expect(sharePercent(0.4995)).toBe('49.9%');
127
+ expect(sharePercent(0.5)).toBe('50.0%');
128
+ });
129
+ });
130
+
131
+ describe('density', () => {
132
+ it('scores a padded sentence well below a dense one', () => {
133
+ const padded = words(
134
+ 'So that is why it is the one that you would want to use if you can.',
135
+ );
136
+ const dense = words(
137
+ 'Name each codemod folder after the Core version whose upgrade runs it.',
138
+ );
139
+ expect(density(padded)).toBeLessThan(0.3);
140
+ expect(density(dense)).toBeGreaterThan(0.6);
141
+ });
142
+ });