@astryxdesign/cli 0.6.6-canary.7189141 → 0.6.6-canary.7c8ddf2

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 (115) hide show
  1. package/api/component/component-replacement.test.mjs +12 -0
  2. package/api/component/component.doc.mjs +5 -2
  3. package/api/docs/_adapter.mjs +48 -1
  4. package/api/docs/compiled-topics.test.mjs +1 -1
  5. package/api/docs/detail/section/section.d.mts +44 -0
  6. package/api/docs/detail/section/section.mjs +164 -13
  7. package/api/docs/detail/section/section.test.mjs +4 -4
  8. package/api/docs/docOverlays.test.mjs +28 -17
  9. package/api/docs/docs.doc.mjs +3 -3
  10. package/api/docs/docs.mjs +11 -16
  11. package/api/docs/docs.test.mjs +9 -10
  12. package/api/docs/integration-tree.test.mjs +26 -26
  13. package/api/docs/integrationDocs.test.mjs +2 -2
  14. package/api/docs/namespace-section.test.mjs +260 -0
  15. package/api/docs/token-tables.test.mjs +93 -0
  16. package/api/doctor/doctor.d.mts +6 -0
  17. package/api/doctor/doctor.mjs +149 -40
  18. package/api/doctor/doctor.test.mjs +104 -0
  19. package/api/gap-report/gap-report.doc.mjs +2 -1
  20. package/api/integration/validate-integration.mjs +20 -4
  21. package/api/integration/validate-integration.test.mjs +73 -0
  22. package/api/search/search.d.mts +44 -0
  23. package/api/search/search.domain-priority.test.mjs +261 -0
  24. package/api/search/search.mjs +191 -29
  25. package/api/swizzle/swizzle.doc.mjs +5 -2
  26. package/assets/docs/author-a-theme.doc.mjs +4 -4
  27. package/assets/docs/getting-started.doc.mjs +2 -2
  28. package/assets/docs/principles.doc.dense.mjs +3 -3
  29. package/assets/docs/principles.doc.mjs +4 -4
  30. package/assets/docs/principles.doc.zh.mjs +3 -3
  31. package/assets/docs/styling-overview.doc.mjs +5 -5
  32. package/assets/docs/tree/component-migration.doc.mjs +107 -0
  33. package/assets/docs/tree/css-and-stylex.doc.mjs +150 -0
  34. package/assets/docs/tree/font-setup.doc.mjs +122 -0
  35. package/assets/docs/tree/headers-and-footers.doc.mjs +0 -1
  36. package/assets/docs/tree/i18n-library-integration.doc.mjs +167 -0
  37. package/assets/docs/tree/i18n-quick-start.doc.mjs +101 -0
  38. package/assets/docs/{internationalization.doc.mjs → tree/i18n-rtl-and-testing.doc.mjs} +17 -223
  39. package/assets/docs/tree/internationalization.doc.mjs +29 -0
  40. package/assets/docs/tree/layout.doc.mjs +3 -0
  41. package/assets/docs/{migration.doc.mjs → tree/migration-setup.doc.mjs} +24 -129
  42. package/assets/docs/tree/migration-verification.doc.mjs +67 -0
  43. package/assets/docs/tree/migration.doc.mjs +28 -0
  44. package/assets/docs/tree/non-css-processing.doc.mjs +112 -0
  45. package/assets/docs/tree/other-libraries.doc.mjs +218 -0
  46. package/assets/docs/tree/responsive.doc.mjs +0 -4
  47. package/assets/docs/tree/scaffold.doc.mjs +0 -5
  48. package/assets/docs/tree/side-panels.doc.mjs +0 -1
  49. package/assets/docs/tree/structure.doc.mjs +0 -4
  50. package/assets/docs/tree/styling-advanced.doc.mjs +159 -0
  51. package/assets/docs/tree/styling-basics.doc.mjs +181 -0
  52. package/assets/docs/tree/styling-libraries.doc.mjs +30 -0
  53. package/assets/docs/tree/styling.doc.mjs +29 -0
  54. package/assets/docs/tree/tailwind.doc.mjs +65 -0
  55. package/assets/docs/tree/tokens-and-setup.doc.mjs +128 -0
  56. package/assets/docs/tree/tokens-border.doc.mjs +46 -0
  57. package/assets/docs/tree/tokens-color.doc.dense.mjs +10 -0
  58. package/assets/docs/tree/tokens-color.doc.mjs +438 -0
  59. package/assets/docs/tree/tokens-color.doc.zh.mjs +10 -0
  60. package/assets/docs/tree/tokens-data.doc.mjs +323 -0
  61. package/assets/docs/tree/tokens-duration.doc.mjs +78 -0
  62. package/assets/docs/tree/tokens-ease.doc.mjs +46 -0
  63. package/assets/docs/tree/tokens-focus.doc.mjs +57 -0
  64. package/assets/docs/tree/tokens-font-weight.doc.mjs +58 -0
  65. package/assets/docs/tree/tokens-radius.doc.dense.mjs +10 -0
  66. package/assets/docs/tree/tokens-radius.doc.mjs +70 -0
  67. package/assets/docs/tree/tokens-radius.doc.zh.mjs +10 -0
  68. package/assets/docs/tree/tokens-shadow.doc.dense.mjs +10 -0
  69. package/assets/docs/tree/tokens-shadow.doc.mjs +74 -0
  70. package/assets/docs/tree/tokens-shadow.doc.zh.mjs +10 -0
  71. package/assets/docs/tree/tokens-size.doc.dense.mjs +10 -0
  72. package/assets/docs/tree/tokens-size.doc.mjs +54 -0
  73. package/assets/docs/tree/tokens-size.doc.zh.mjs +10 -0
  74. package/assets/docs/tree/tokens-spacing.doc.dense.mjs +10 -0
  75. package/assets/docs/tree/tokens-spacing.doc.mjs +102 -0
  76. package/assets/docs/tree/tokens-spacing.doc.zh.mjs +10 -0
  77. package/assets/docs/tree/tokens-syntax.doc.mjs +98 -0
  78. package/assets/docs/tree/tokens-text-size.doc.mjs +90 -0
  79. package/assets/docs/tree/tokens-type-scale.doc.mjs +210 -0
  80. package/assets/docs/tree/tokens-typography.doc.mjs +54 -0
  81. package/assets/docs/tree/tokens-usage.doc.dense.mjs +10 -0
  82. package/assets/docs/tree/tokens-usage.doc.mjs +36 -0
  83. package/assets/docs/tree/tokens-usage.doc.zh.mjs +10 -0
  84. package/assets/docs/tree/tokens.doc.mjs +28 -0
  85. package/assets/docs/tree/type-scale.doc.mjs +147 -0
  86. package/assets/docs/tree/typography-best-practices.doc.mjs +55 -0
  87. package/assets/docs/tree/typography.doc.mjs +29 -0
  88. package/assets/theme.template.ts +4 -3
  89. package/clients/cli/commands/component/index.mjs +4 -1
  90. package/clients/cli/commands/component-replacement.text.test.mjs +45 -0
  91. package/clients/cli/commands/docs.doc.mjs +2 -1
  92. package/clients/cli/commands/docs.test.mjs +13 -11
  93. package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -1
  94. package/clients/cli/commands/doctor.test.mjs +33 -0
  95. package/clients/cli/lib/component-format.mjs +13 -3
  96. package/foundation/agent-docs/agent-docs.mjs +14 -1
  97. package/foundation/config/project.test.mjs +1 -1
  98. package/foundation/discovery/docs-discovery.test.mjs +1 -1
  99. package/foundation/doc-compiler/bundle.mjs +52 -1
  100. package/foundation/doc-compiler/split-topic-keywords.test.mjs +73 -0
  101. package/foundation/doc-compiler/tree.d.mts +10 -0
  102. package/foundation/doc-compiler/tree.mjs +22 -0
  103. package/foundation/doc-compiler/tree.test.mjs +3 -2
  104. package/foundation/env/package-manager.d.mts +3 -0
  105. package/foundation/env/package-manager.mjs +71 -3
  106. package/foundation/env/package-manager.test.mjs +82 -1
  107. package/foundation/integrations/validate-contributions.d.mts +16 -0
  108. package/foundation/integrations/validate-contributions.mjs +56 -8
  109. package/package.json +9 -9
  110. package/assets/docs/styling-libraries.doc.mjs +0 -469
  111. package/assets/docs/styling.doc.mjs +0 -412
  112. package/assets/docs/tokens.doc.dense.mjs +0 -15
  113. package/assets/docs/tokens.doc.mjs +0 -1491
  114. package/assets/docs/tokens.doc.zh.mjs +0 -15
  115. package/assets/docs/typography.doc.mjs +0 -286
@@ -12,6 +12,7 @@ import * as path from 'node:path';
12
12
  import {component} from './component.mjs';
13
13
  import {componentKeywords, search} from '../search/search.mjs';
14
14
  import {swizzleCopy} from '../swizzle/copy/copy.mjs';
15
+ import {swizzle} from '../swizzle/swizzle.mjs';
15
16
  import {integrationComponentConflicts} from '../integration/authoring-checks.mjs';
16
17
  import {GAP_REPORT_CATEGORIES, gapReport} from '../gap-report/gap-report.mjs';
17
18
  import {Project} from '../../foundation/config/project.mjs';
@@ -248,6 +249,17 @@ describe('a package that declares the CLI floor', () => {
248
249
  SLOW,
249
250
  );
250
251
 
252
+ it(
253
+ 'leaves the swizzle list naming Core components, the replaced one included',
254
+ async () => {
255
+ const listed = await swizzle(undefined, {cwd: tmpDir, list: true});
256
+ expect(listed.type).toBe('swizzle.list');
257
+ expect(listed.data).toContain('SideNav');
258
+ expect(listed.data).not.toContain('AcmeSideNav');
259
+ },
260
+ SLOW,
261
+ );
262
+
251
263
  it(
252
264
  'routes issues and reports no findings for a valid replacement',
253
265
  async () => {
@@ -21,7 +21,10 @@ export const doc = {
21
21
  'integration packages; an array returns one ordered result row per selector at ' +
22
22
  'every array length; and no name returns the catalog grouped by category. ' +
23
23
  'Boolean flags narrow each resolved component to just its props, source, ' +
24
- 'showcase, or example blocks.',
24
+ 'showcase, or example blocks. An integration component that replaces a Core ' +
25
+ 'component (its doc sets replaces, and its package declares the CLI range that ' +
26
+ 'turns replacement on) answers to the Core name in detail, batch, and list ' +
27
+ "results; use options.package '@astryxdesign/core' for the original.",
25
28
  importPath: '@astryxdesign/cli/api',
26
29
  signature:
27
30
  'component(name?: string | string[], options?: ComponentOptions): Promise<ComponentListResponse | ComponentBatchResponse | ComponentDetailResponse | ComponentDetailPropsResponse | ComponentDetailSourceResponse | ComponentDetailShowcaseResponse | ComponentDetailBlocksResponse>',
@@ -62,7 +65,7 @@ export const doc = {
62
65
  name: 'options.package',
63
66
  type: 'string',
64
67
  description:
65
- "Scope lookup to a specific external package (e.g. '@acme/widgets').",
68
+ "Scope lookup to a specific external package (e.g. '@acme/widgets'). Use '@astryxdesign/core' to select an original replaced by an integration component.",
66
69
  },
67
70
  {
68
71
  name: 'options.props',
@@ -732,10 +732,57 @@ export async function packageDocsProblems(integration, discovered) {
732
732
  export function referenceTargets(catalog, lang) {
733
733
  return async topic => {
734
734
  const target = catalog.resolve(topic);
735
- return target ? lowerTopic(catalog, target, lang) : null;
735
+ if (target) return lowerTopic(catalog, target, lang);
736
+ return namespaceReferenceTarget(catalog, topic, lang);
736
737
  };
737
738
  }
738
739
 
740
+ /**
741
+ * A docs-tree namespace as the target of a token reference: every guide placed
742
+ * below it, lowered for `lang` and read in tree order as one topic. A flat
743
+ * topic split into a namespace keeps answering the references its readers
744
+ * wrote, so `{type: 'token-ref', topic: 'tokens', section: 'Color Tokens'}`
745
+ * finds the guide that now holds that table. Null for any other route.
746
+ * @param {DocsCatalog} catalog
747
+ * @param {string} route
748
+ * @param {string | null} lang
749
+ * @returns {Promise<import('../../foundation/doc-compiler/compile.mjs').CompiledReferenceNode | null>}
750
+ */
751
+ async function namespaceReferenceTarget(catalog, route, lang) {
752
+ const tree = await projectTree(catalog);
753
+ const node = tree.get(route) ?? tree.getFolded(route);
754
+ if (!node || node.kind !== 'namespace' || node.generated) return null;
755
+ /** @type {any[]} */
756
+ const sections = [];
757
+ /** @type {Record<string, string>} */
758
+ const sourceTitles = {};
759
+ /** @param {TreeNode} parent */
760
+ const walk = async parent => {
761
+ for (const slot of parent.slots) {
762
+ for (const childRoute of slot.children) {
763
+ const child = tree.get(childRoute);
764
+ if (!child || child.parent !== parent.route) continue;
765
+ if (child.kind === 'namespace') {
766
+ await walk(child);
767
+ } else if (child.kind === 'generic' && child.ref?.topicFile) {
768
+ const lowered = await lowerTopic(catalog, guideEntry(child), lang);
769
+ sections.push(...lowered.doc.sections);
770
+ for (const [key, title] of Object.entries(lowered.sourceTitles)) {
771
+ sourceTitles[key] ??= title;
772
+ }
773
+ }
774
+ }
775
+ }
776
+ };
777
+ await walk(node);
778
+ if (sections.length === 0) return null;
779
+ return /** @type {any} */ ({
780
+ id: node.route,
781
+ doc: {sections},
782
+ sourceTitles,
783
+ });
784
+ }
785
+
739
786
  /**
740
787
  * Each reference block in one integration's docs that cannot include what it
741
788
  * names (spec:AST-047 FR9): a target that names no doc, a field its schema
@@ -53,7 +53,7 @@ describe('reads that share a catalog', () => {
53
53
  'never let one read change another',
54
54
  async () => {
55
55
  const catalog = await loadDocsCatalog();
56
- const tokens = catalog.resolve('tokens');
56
+ const tokens = catalog.resolve('color');
57
57
  const first = detailView(await compileTopic(catalog, tokens));
58
58
  for (const section of first.sections) {
59
59
  section.title = 'EDITED';
@@ -17,3 +17,47 @@ export function section(topic: string, sectionName: string, options?: {
17
17
  dense?: boolean | undefined;
18
18
  cwd?: string | undefined;
19
19
  }): Promise<import("../../docs.type.mjs").DocsDetailSectionResponse>;
20
+ /**
21
+ * @typedef {object} GuideMatch
22
+ * @property {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} guide
23
+ * @property {Awaited<ReturnType<typeof resolveTopicDocs>>} resolved
24
+ * @property {any[]} sections the guide's reader sections
25
+ * @property {any} match the section it has
26
+ */
27
+ /**
28
+ * One section of a namespace (spec:AST-046 FR6): the section read of the one
29
+ * guide below the namespace, at any depth, that has it. Each guide answers
30
+ * with the section its own section read returns for the query; when that
31
+ * section's key (its `id`, else the key its title derives) is the query in
32
+ * some guides, those guides answer first. No guide, or several, fail with ERR_UNKNOWN_SECTION, naming
33
+ * the guides to read instead.
34
+ * @param {import('../../../../foundation/doc-compiler/tree.mjs').DocsTree} tree
35
+ * @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} namespace
36
+ * @param {string} sectionName
37
+ * @param {object} [options] as {@link section}
38
+ * @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
39
+ */
40
+ export function namespaceSection(tree: import("../../../../foundation/doc-compiler/tree.mjs").DocsTree, namespace: import("../../../../foundation/doc-compiler/tree.mjs").TreeNode, sectionName: string, options?: object): Promise<import("../../docs.type.mjs").DocsDetailSectionResponse>;
41
+ /**
42
+ * The guide a namespace section read answers from, or null to ask. When the
43
+ * query matches sections in several guides, the read asks the reader which
44
+ * guide they mean (spec:AST-046 FR6), where a flat topic's section read
45
+ * returned its first title match. To return the first match in tree order
46
+ * instead, return `matches[0]` here.
47
+ * @param {GuideMatch[]} matches in tree order
48
+ * @returns {GuideMatch | null}
49
+ */
50
+ export function oneGuide(matches: GuideMatch[]): GuideMatch | null;
51
+ export type GuideMatch = {
52
+ guide: import("../../../../foundation/doc-compiler/tree.mjs").TreeNode;
53
+ resolved: Awaited<ReturnType<typeof resolveTopicDocs>>;
54
+ /**
55
+ * the guide's reader sections
56
+ */
57
+ sections: any[];
58
+ /**
59
+ * the section it has
60
+ */
61
+ match: any;
62
+ };
63
+ import { resolveTopicDocs } from '../../_adapter.mjs';
@@ -11,6 +11,9 @@
11
11
  * token-ref blocks inlined — matching `astryx --json docs <topic> <section>`.
12
12
  * Throws ERR_UNKNOWN_SECTION when nothing matches, or when the query matches
13
13
  * more than one section (the candidates come back as suggestions).
14
+ * A namespace's section read (spec:AST-046 FR6) finds the one guide below the
15
+ * namespace that has the section and answers exactly as that guide's section
16
+ * read does.
14
17
  * @position Leaf nested under api/docs/detail. Shares topic resolution with the
15
18
  * detail leaf via _adapter.mjs and reads through the compiler's lenses.
16
19
  */
@@ -20,6 +23,8 @@ import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';
20
23
  import {
21
24
  findDocSection,
22
25
  sectionKey,
26
+ sectionTitleKey,
27
+ sourceTitle,
23
28
  } from '../../../../foundation/discovery/docs-section-key.mjs';
24
29
  import {linkReferenceSection} from '../../../../foundation/doc-compiler/compile.mjs';
25
30
  import {
@@ -43,19 +48,9 @@ import {
43
48
  * @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
44
49
  */
45
50
  export async function section(topic, sectionName, options = {}) {
46
- // An empty section name must error, not resolve to the first section. The
47
- // docs() dispatcher routes a falsy section to the topic, but the leaf must be
48
- // safe on its own; a non-string would otherwise throw a raw TypeError.
49
- if (typeof sectionName !== 'string' || !sectionName.trim()) {
50
- throw new AstryxError(
51
- 'A section name is required',
52
- undefined,
53
- ERROR_CODES.ERR_UNKNOWN_SECTION,
54
- );
55
- }
56
-
57
- const {catalog, node, lang, entry} = await resolveTopicDocs(topic, options);
58
- const sections = readerSections(node);
51
+ requireSectionName(sectionName);
52
+ const resolved = await resolveTopicDocs(topic, options);
53
+ const sections = readerSections(resolved.node);
59
54
  const {section: match} = findDocSection(sections, sectionName);
60
55
  if (!match) {
61
56
  throw new AstryxError(
@@ -68,6 +63,33 @@ export async function section(topic, sectionName, options = {}) {
68
63
  );
69
64
  }
70
65
 
66
+ return sectionResponse(resolved, sections, match);
67
+ }
68
+
69
+ /**
70
+ * An empty section name must error, not resolve to the first section. The
71
+ * docs() dispatcher routes a falsy section to the topic, but a leaf must be
72
+ * safe on its own; a non-string would otherwise throw a raw TypeError.
73
+ * @param {unknown} sectionName
74
+ */
75
+ function requireSectionName(sectionName) {
76
+ if (typeof sectionName !== 'string' || !sectionName.trim()) {
77
+ throw new AstryxError(
78
+ 'A section name is required',
79
+ undefined,
80
+ ERROR_CODES.ERR_UNKNOWN_SECTION,
81
+ );
82
+ }
83
+ }
84
+
85
+ /**
86
+ * The docs.detail.section response for one section of a resolved topic.
87
+ * @param {Awaited<ReturnType<typeof resolveTopicDocs>>} resolved
88
+ * @param {any[]} sections the topic's reader sections
89
+ * @param {any} match one of them
90
+ * @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
91
+ */
92
+ async function sectionResponse({catalog, node, lang, entry}, sections, match) {
71
93
  // A section read on its own inlines its token refs, as the whole topic does;
72
94
  // otherwise a section that is only a token-ref prints blank. Only this
73
95
  // section is linked, so a broken reference elsewhere cannot fail the read.
@@ -93,3 +115,132 @@ export async function section(topic, sectionName, options = {}) {
93
115
  data: {...sectionView(node, linked), links},
94
116
  };
95
117
  }
118
+
119
+ /**
120
+ * @typedef {object} GuideMatch
121
+ * @property {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} guide
122
+ * @property {Awaited<ReturnType<typeof resolveTopicDocs>>} resolved
123
+ * @property {any[]} sections the guide's reader sections
124
+ * @property {any} match the section it has
125
+ */
126
+
127
+ /**
128
+ * One section of a namespace (spec:AST-046 FR6): the section read of the one
129
+ * guide below the namespace, at any depth, that has it. Each guide answers
130
+ * with the section its own section read returns for the query; when that
131
+ * section's key (its `id`, else the key its title derives) is the query in
132
+ * some guides, those guides answer first. No guide, or several, fail with ERR_UNKNOWN_SECTION, naming
133
+ * the guides to read instead.
134
+ * @param {import('../../../../foundation/doc-compiler/tree.mjs').DocsTree} tree
135
+ * @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} namespace
136
+ * @param {string} sectionName
137
+ * @param {object} [options] as {@link section}
138
+ * @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
139
+ */
140
+ export async function namespaceSection(
141
+ tree,
142
+ namespace,
143
+ sectionName,
144
+ options = {},
145
+ ) {
146
+ requireSectionName(sectionName);
147
+ const guides = guidesBelow(tree, namespace);
148
+ /** @type {Omit<GuideMatch, 'match'>[]} */
149
+ const reads = [];
150
+ for (const guide of guides) {
151
+ const resolved = await resolveTopicDocs(guide.route, options);
152
+ reads.push({guide, resolved, sections: readerSections(resolved.node)});
153
+ }
154
+
155
+ const wanted = sectionName.trim();
156
+ const derived = sectionTitleKey(wanted);
157
+ /** @type {GuideMatch[]} */
158
+ const byKey = [];
159
+ /** @type {GuideMatch[]} */
160
+ const found = [];
161
+ for (const read of reads) {
162
+ // The section the guide's own section read returns for this query, so the
163
+ // namespace read answers exactly what `astryx docs <guide> <section>` does.
164
+ const {section: match} = findDocSection(read.sections, wanted);
165
+ if (!match) continue;
166
+ found.push({...read, match});
167
+ if (
168
+ sectionKey(match) === wanted ||
169
+ (derived !== '' && sectionTitleKey(sourceTitle(match)) === derived)
170
+ ) {
171
+ byKey.push({...read, match});
172
+ }
173
+ }
174
+ const matches = byKey.length > 0 ? byKey : found;
175
+ const chosen = oneGuide(matches);
176
+ if (chosen)
177
+ return sectionResponse(chosen.resolved, chosen.sections, chosen.match);
178
+
179
+ if (guides.length === 0) {
180
+ // A namespace with no guide below it (a reference level such as cli/api)
181
+ // has no sections to read: name its children, as before.
182
+ throw new AstryxError(
183
+ `"${namespace.route}" has no sections. Open one of its children instead.`,
184
+ namespace.slots.flatMap(slot =>
185
+ slot.children.map(route => ({
186
+ name: route,
187
+ reason: tree.get(route)?.summary ?? '',
188
+ })),
189
+ ),
190
+ ERROR_CODES.ERR_UNKNOWN_SECTION,
191
+ );
192
+ }
193
+ if (matches.length === 0) {
194
+ throw new AstryxError(
195
+ `Section "${sectionName}" is not in any guide under "${namespace.route}". Open one of its guides instead.`,
196
+ guides.map(guide => ({name: guide.route, reason: guide.summary})),
197
+ ERROR_CODES.ERR_UNKNOWN_SECTION,
198
+ );
199
+ }
200
+ throw new AstryxError(
201
+ `Section "${sectionName}" matches sections in more than one guide under "${namespace.route}". Read it from one of them.`,
202
+ matches.map(({guide, match}) => ({
203
+ name: guide.route,
204
+ reason: `has "${match.title}"`,
205
+ })),
206
+ ERROR_CODES.ERR_UNKNOWN_SECTION,
207
+ );
208
+ }
209
+
210
+ /**
211
+ * The guide a namespace section read answers from, or null to ask. When the
212
+ * query matches sections in several guides, the read asks the reader which
213
+ * guide they mean (spec:AST-046 FR6), where a flat topic's section read
214
+ * returned its first title match. To return the first match in tree order
215
+ * instead, return `matches[0]` here.
216
+ * @param {GuideMatch[]} matches in tree order
217
+ * @returns {GuideMatch | null}
218
+ */
219
+ export function oneGuide(matches) {
220
+ return matches.length === 1 ? matches[0] : null;
221
+ }
222
+
223
+ /**
224
+ * Every guide below a namespace, at any depth, in tree order.
225
+ * @param {import('../../../../foundation/doc-compiler/tree.mjs').DocsTree} tree
226
+ * @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} namespace
227
+ * @returns {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode[]}
228
+ */
229
+ function guidesBelow(tree, namespace) {
230
+ /** @type {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode[]} */
231
+ const guides = [];
232
+ /** @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} parent */
233
+ const walk = parent => {
234
+ for (const slot of parent.slots) {
235
+ for (const route of slot.children) {
236
+ const child = tree.get(route);
237
+ if (!child || child.parent !== parent.route) continue;
238
+ if (child.kind === 'namespace') walk(child);
239
+ else if (child.kind === 'generic' && child.ref?.topicFile)
240
+ guides.push(child);
241
+ }
242
+ }
243
+ };
244
+ walk(namespace);
245
+ return guides;
246
+ }
@@ -16,7 +16,7 @@ const SLOW = 30_000;
16
16
 
17
17
  describe('docs.detail.section leaf', () => {
18
18
  it('resolves a named section (case-insensitive) into a docs.detail.section envelope', async () => {
19
- const res = await section('tokens', 'spacing');
19
+ const res = await section('tokens/tokens-spacing', 'spacing');
20
20
  expect(res.type).toBe('docs.detail.section');
21
21
  expect(res.data.title.toLowerCase()).toContain('spacing');
22
22
  }, SLOW);
@@ -24,7 +24,7 @@ describe('docs.detail.section leaf', () => {
24
24
  it('throws ERR_UNKNOWN_SECTION for an unknown section', async () => {
25
25
  let err;
26
26
  try {
27
- await section('tokens', 'zzzznope');
27
+ await section('tokens/tokens-spacing', 'zzzznope');
28
28
  } catch (e) {
29
29
  err = e;
30
30
  }
@@ -44,10 +44,10 @@ describe('docs.detail.section leaf', () => {
44
44
  }, SLOW);
45
45
 
46
46
  it('does not return the first section for an empty section name', async () => {
47
- await expect(section('tokens', '')).rejects.toMatchObject({
47
+ await expect(section('tokens/tokens-spacing', '')).rejects.toMatchObject({
48
48
  code: 'ERR_UNKNOWN_SECTION',
49
49
  });
50
- await expect(section('tokens', ' ')).rejects.toMatchObject({
50
+ await expect(section('tokens/tokens-spacing', ' ')).rejects.toMatchObject({
51
51
  code: 'ERR_UNKNOWN_SECTION',
52
52
  });
53
53
  }, SLOW);
@@ -114,26 +114,37 @@ describe('reference doc overlays (#2182)', () => {
114
114
 
115
115
  describe('the reported defect: docs tokens --dense (#2182)', () => {
116
116
  it('does not print the colour table under the Spacing heading', async () => {
117
- const result = await docs('tokens', null, {dense: true});
118
- const spacing = result.data.sections.find(s => /spacing/i.test(s.title));
119
- expect(spacing, 'tokens docs should have a spacing section').toBeTruthy();
120
-
121
- const text = JSON.stringify(spacing);
122
- expect(
123
- text.includes('--color-'),
124
- `The "${spacing.title}" section of \`docs tokens --dense\` contains ` +
125
- `colour tokens. An agent reading this learns that spacing tokens are ` +
126
- `named --color-*.`,
127
- ).toBe(false);
128
- expect(text).toContain('--spacing-');
117
+ // The spacing table lives in its own guide; the spacing topic shows it
118
+ // through a token reference to the tokens namespace. Both, read dense.
119
+ for (const topic of ['tokens/tokens-spacing', 'spacing']) {
120
+ const result = await docs(topic, null, {dense: true});
121
+ const spacing = result.data.sections.find(s =>
122
+ JSON.stringify(s).includes('--spacing-'),
123
+ );
124
+ expect(spacing, `${topic} --dense should show the spacing table`).toBeTruthy();
125
+ const text = JSON.stringify(spacing);
126
+ expect(
127
+ text.includes('--color-'),
128
+ `The "${spacing.title}" section of \`docs ${topic} --dense\` contains ` +
129
+ `colour tokens. An agent reading this learns that spacing tokens are ` +
130
+ `named --color-*.`,
131
+ ).toBe(false);
132
+ }
129
133
  });
130
134
 
131
135
  it('keeps every base section reachable, even without an overlay entry', async () => {
132
- // The tokens overlay compresses only 6 of 13 sections. The other 7 must
133
- // still render (in English), not vanish or absorb a neighbour's title.
134
- const full = await docs('tokens', null, {});
135
- const dense = await docs('tokens', null, {dense: true});
136
- expect(dense.data.sections.length).toBe(full.data.sections.length);
136
+ // The tokens overlays compress 5 of 15 category tables. Read through the
137
+ // namespace, the other 10 must still render (in English), not vanish or
138
+ // absorb a neighbour's title.
139
+ const full = await docs('tokens', null, {depth: 'all', detail: 'full'});
140
+ const dense = await docs('tokens', null, {depth: 'all', detail: 'full', dense: true});
141
+ const titles = read =>
142
+ read.data.slots.flatMap(slot =>
143
+ slot.children.flatMap(child => (child.sections ?? []).map(s => s.title)),
144
+ );
145
+ expect(titles(dense).length).toBe(titles(full).length);
146
+ expect(titles(dense)).toContain('Color');
147
+ expect(titles(dense)).toContain('Font Size Tokens');
137
148
  });
138
149
 
139
150
  it('does not lose a section from docs theme --dense', async () => {
@@ -121,7 +121,7 @@ export const doc = {
121
121
  {
122
122
  type: 'docs.detail.section',
123
123
  description:
124
- 'One ReferenceSection of the topic, found by key or title, with token-ref and reference blocks inlined.',
124
+ 'One ReferenceSection of the topic, found by key or title, with token-ref and reference blocks inlined. Asked of a docs-tree namespace, it is the section read of the one guide below the namespace that has the section.',
125
125
  },
126
126
  {
127
127
  type: 'docs.node',
@@ -144,7 +144,7 @@ export const doc = {
144
144
  },
145
145
  {
146
146
  code: 'ERR_UNKNOWN_SECTION',
147
- when: 'a section is requested but is empty, matches no section, matches more than one, or is asked of a docs-tree namespace or typed doc, which have no sections',
147
+ when: 'a section is requested but is empty, matches no section, or matches more than one; asked of a docs-tree namespace, when no guide below it or more than one has the section (suggestions name those guides); or asked of a typed doc, which has no sections',
148
148
  },
149
149
  ],
150
150
  examples: [
@@ -168,7 +168,7 @@ export const doc = {
168
168
  label: 'A whole guide from the docs tree',
169
169
  code: "await docs('cli/integrations/quick-start');",
170
170
  },
171
- {label: 'One section by key', code: "await docs('tokens', 'spacing');"},
171
+ {label: 'One section by key', code: "await docs('spacing', 'scale');"},
172
172
  ],
173
173
  command: 'docs',
174
174
  related: ['search', 'component', 'hook', 'template'],
package/api/docs/docs.mjs CHANGED
@@ -26,7 +26,10 @@
26
26
  import {list} from './list/list.mjs';
27
27
  import {index} from './index/index.mjs';
28
28
  import {detail} from './detail/detail.mjs';
29
- import {section as sectionLeaf} from './detail/section/section.mjs';
29
+ import {
30
+ namespaceSection,
31
+ section as sectionLeaf,
32
+ } from './detail/section/section.mjs';
30
33
  import {node as nodeLeaf, nodeView} from './node/node.mjs';
31
34
  import {resolveDocsArgument} from './_adapter.mjs';
32
35
  import {AstryxError} from '../error.mjs';
@@ -98,23 +101,15 @@ export async function docs(topic, section, options = {}) {
98
101
  if (!topic) return list(options);
99
102
  const found = await resolveDocsArgument(topic, options);
100
103
  if (found.kind === 'node') {
101
- // A namespace or a typed doc has no sections: it is one read. `--index`
102
- // asks for what the node read already is.
103
104
  if (section) {
105
+ // A namespace answers a section read from the one guide below it that
106
+ // has the section (spec:AST-046 FR6). A typed doc is one read.
107
+ if (found.node.kind === 'namespace') {
108
+ return namespaceSection(found.tree, found.node, section, options);
109
+ }
104
110
  throw new AstryxError(
105
- `"${found.node.route}" has no sections. ${
106
- found.node.kind === 'namespace'
107
- ? 'Open one of its children instead.'
108
- : `Read it whole: astryx docs ${found.node.route}.`
109
- }`,
110
- found.node.kind === 'namespace'
111
- ? found.node.slots.flatMap(slot =>
112
- slot.children.map(route => ({
113
- name: route,
114
- reason: found.tree.get(route)?.summary ?? '',
115
- })),
116
- )
117
- : [{name: found.node.route, reason: found.node.summary}],
111
+ `"${found.node.route}" has no sections. Read it whole: astryx docs ${found.node.route}.`,
112
+ [{name: found.node.route, reason: found.node.summary}],
118
113
  ERROR_CODES.ERR_UNKNOWN_SECTION,
119
114
  );
120
115
  }
@@ -53,7 +53,7 @@ describe('docs() dispatcher routing', () => {
53
53
 
54
54
  it('reads a shortened section by its old key, which its title still derives', async () => {
55
55
  const r = await docs(
56
- 'styling',
56
+ 'styling/tokens-and-setup',
57
57
  'stylex-build-setup-required-for-swizzled-components',
58
58
  );
59
59
  expect(r.type).toBe('docs.detail.section');
@@ -92,7 +92,7 @@ describe('docs() dispatcher routing', () => {
92
92
 
93
93
  it("lists the docs tree's namespaces in meta, so every data entry reads as a topic", async () => {
94
94
  const res = await docs();
95
- expect(res.meta.namespaces.map(entry => entry.topic)).toEqual(['cli', 'layout', 'unorganized']);
95
+ expect(res.meta.namespaces.map(entry => entry.topic)).toEqual(['cli', 'internationalization', 'layout', 'migration', 'styling', 'styling-libraries', 'tokens', 'typography', 'unorganized']);
96
96
  for (const entry of res.data) {
97
97
  expect((await docs(entry.topic)).type).toBe('docs.detail');
98
98
  }
@@ -240,16 +240,15 @@ describe('docs() dispatcher routing', () => {
240
240
  );
241
241
  }, SLOW);
242
242
 
243
- it('a section of a namespace -> ERR_UNKNOWN_SECTION, naming its children', async () => {
244
- const err = await docs('cli', 'commands').catch(e => e);
243
+ it('a section no guide of a namespace has -> ERR_UNKNOWN_SECTION, naming its guides', async () => {
244
+ const err = await docs('cli', 'zzzz-nope').catch(e => e);
245
245
  expect(err).toBeInstanceOf(AstryxError);
246
246
  expect(err.code).toBe('ERR_UNKNOWN_SECTION');
247
- // It names the namespace's children, in the order its slots list them.
248
- const cli = (await docs('cli')).data;
249
- expect(err.suggestions.map(s => s.name)).toEqual(
250
- cli.slots.flatMap(slot => slot.children.map(child => child.route)),
251
- );
252
- expect(err.suggestions.map(s => s.name)).toContain('cli/commands');
247
+ // It names every guide below the namespace, at any depth.
248
+ const names = err.suggestions.map(s => s.name);
249
+ expect(names).toContain('cli/component-lookups');
250
+ expect(names).toContain('cli/integrations/quick-start');
251
+ expect(names.every(name => name.startsWith('cli/'))).toBe(true);
253
252
  }, SLOW);
254
253
 
255
254
  it('an unknown route suggests the children of the deepest namespace it reaches', async () => {