@astryxdesign/cli 0.6.3-canary.f839b67 → 0.6.4-canary.06c8fa3

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 (189) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +64 -66
  3. package/api/component/_adapter.d.mts +25 -0
  4. package/api/component/_adapter.mjs +59 -5
  5. package/api/component/component.d.mts +6 -3
  6. package/api/component/component.doc.mjs +23 -10
  7. package/api/component/component.mjs +249 -9
  8. package/api/component/component.type.d.mts +25 -0
  9. package/api/component/component.type.mjs +44 -0
  10. package/api/discover/_adapter.d.mts +114 -6
  11. package/api/discover/_adapter.mjs +372 -17
  12. package/api/discover/_adapter.test.mjs +215 -0
  13. package/api/discover/_catalog-view.d.mts +115 -0
  14. package/api/discover/_catalog-view.mjs +203 -0
  15. package/api/discover/_catalog-view.test.mjs +128 -0
  16. package/api/discover/detail/detail.d.mts +18 -6
  17. package/api/discover/detail/detail.mjs +67 -13
  18. package/api/discover/detail/detail.test.mjs +85 -0
  19. package/api/discover/detail/item/item.d.mts +26 -0
  20. package/api/discover/detail/item/item.mjs +78 -0
  21. package/api/discover/detail/item/item.test.mjs +73 -0
  22. package/api/discover/discover.d.mts +3 -9
  23. package/api/discover/discover.doc.mjs +61 -18
  24. package/api/discover/discover.mjs +220 -36
  25. package/api/discover/discover.test.mjs +11 -2
  26. package/api/discover/discover.type.d.mts +147 -8
  27. package/api/discover/discover.type.mjs +102 -12
  28. package/api/discover/list/list.d.mts +20 -6
  29. package/api/discover/list/list.mjs +45 -12
  30. package/api/discover/list/list.test.mjs +46 -0
  31. package/api/discover/search/search.d.mts +18 -16
  32. package/api/discover/search/search.mjs +102 -56
  33. package/api/discover/search/search.test.mjs +144 -10
  34. package/api/docs/_adapter.d.mts +49 -7
  35. package/api/docs/_adapter.mjs +284 -33
  36. package/api/docs/docs.doc.mjs +4 -3
  37. package/api/docs/docs.test.mjs +2 -0
  38. package/api/docs/docs.type.d.mts +21 -5
  39. package/api/docs/docs.type.mjs +21 -5
  40. package/api/docs/integration-tree.test.mjs +9 -1
  41. package/api/docs/reference-blocks.test.mjs +406 -0
  42. package/api/doctor/doctor.d.mts +8 -3
  43. package/api/doctor/doctor.mjs +95 -10
  44. package/api/doctor/doctor.test.mjs +122 -10
  45. package/api/index.d.mts +1 -2
  46. package/api/index.mjs +4 -4
  47. package/api/integration/add-helpers.d.mts +5 -2
  48. package/api/integration/add-helpers.mjs +36 -9
  49. package/api/integration/authoring-checks.mjs +14 -1
  50. package/api/integration/pack-check.lifecycle-output.test.mjs +105 -0
  51. package/api/integration/pack-check.mjs +28 -3
  52. package/api/json/index.ts +0 -1
  53. package/api/search/search.test.mjs +18 -0
  54. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  55. package/api/template/template-integration.test.mjs +1 -65
  56. package/api/template/template.mjs +1 -1
  57. package/api/theme/add/add.mjs +17 -25
  58. package/api/theme/add/add.rollback.test.mjs +158 -0
  59. package/api/theme/add/add.staging.test.mjs +40 -23
  60. package/api/theme/build/build.family.test.mjs +7 -12
  61. package/api/theme/build/build.mjs +8 -18
  62. package/api/theme/build/build.rollback.test.mjs +148 -0
  63. package/api/upgrade/run/files-changed.test.mjs +111 -0
  64. package/api/upgrade/run/run.mjs +6 -4
  65. package/api/upgrade/upgrade.type.mjs +2 -2
  66. package/assets/codemods/__tests__/registry.test.mjs +1 -0
  67. package/assets/codemods/__tests__/runner.test.mjs +3 -1
  68. package/assets/codemods/file-count.test.mjs +163 -0
  69. package/assets/codemods/integration-runner.mjs +3 -3
  70. package/assets/codemods/registry.mjs +1 -0
  71. package/assets/codemods/runner.mjs +5 -4
  72. package/assets/codemods/transforms/next/index.mjs +1 -19
  73. package/assets/codemods/transforms/v0.6.4/index.mjs +31 -0
  74. package/assets/docs/internationalization.doc.mjs +7 -5
  75. package/assets/docs/styling-libraries.doc.mjs +1 -1
  76. package/assets/docs/theme.doc.mjs +1 -1
  77. package/assets/docs/tree/component-lookups.doc.mjs +149 -0
  78. package/assets/docs/tree/integrations.doc.mjs +20 -1
  79. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  80. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  81. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  82. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  83. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  84. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  85. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  86. package/authoring/config/config.doc.mjs +9 -1
  87. package/authoring/config/parse.d.mts +2 -0
  88. package/authoring/config/parse.mjs +19 -0
  89. package/authoring/config/parse.test.mjs +8 -0
  90. package/authoring/config/type.ts +13 -2
  91. package/authoring/discover/discover.doc.d.mts +13 -0
  92. package/authoring/discover/discover.doc.mjs +138 -0
  93. package/authoring/discover/parse.d.mts +24 -0
  94. package/authoring/discover/parse.mjs +128 -0
  95. package/authoring/discover/parse.test.mjs +124 -0
  96. package/authoring/discover/type.ts +87 -0
  97. package/authoring/doctypes/_schema.d.mts +72 -0
  98. package/authoring/doctypes/_schema.mjs +25 -1
  99. package/authoring/doctypes/command/command.doc.mjs +1 -1
  100. package/authoring/doctypes/command/type.ts +1 -1
  101. package/authoring/doctypes/load-contract.test.mjs +25 -0
  102. package/authoring/doctypes/reference/reference.doc.mjs +31 -4
  103. package/authoring/doctypes/reference/type.ts +20 -5
  104. package/authoring/index.d.mts +1 -0
  105. package/authoring/index.d.ts +10 -0
  106. package/authoring/index.mjs +1 -0
  107. package/clients/cli/command-result-coverage.test.mjs +7 -7
  108. package/clients/cli/commands/component/index.mjs +152 -55
  109. package/clients/cli/commands/component-batch.test.mjs +341 -0
  110. package/clients/cli/commands/component-ownership.test.mjs +89 -0
  111. package/clients/cli/commands/component.doc.mjs +23 -6
  112. package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
  113. package/clients/cli/commands/discover.doc.mjs +53 -9
  114. package/clients/cli/commands/discover.mjs +393 -118
  115. package/clients/cli/commands/discover.sources.test.mjs +267 -0
  116. package/clients/cli/commands/docs.mjs +2 -2
  117. package/clients/cli/commands/docs.test.mjs +29 -0
  118. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  119. package/clients/cli/commands/text-json-parity.test.mjs +0 -17
  120. package/clients/cli/index.mjs +0 -4
  121. package/clients/cli/lib/exit-codes.test.mjs +1 -8
  122. package/clients/cli/lib/json-shim.mjs +24 -14
  123. package/clients/cli/lib/json-shim.test.mjs +6 -20
  124. package/clients/cli/lib/manifest.mjs +3 -8
  125. package/clients/cli/lib/manifest.test.mjs +5 -2
  126. package/clients/cli/lib/parse-error-format.test.mjs +81 -0
  127. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  128. package/foundation/discovery/authoring-self-docs.mjs +21 -8
  129. package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
  130. package/foundation/discovery/docs-discovery.d.mts +4 -1
  131. package/foundation/discovery/docs-discovery.mjs +40 -6
  132. package/foundation/discovery/docs-discovery.test.mjs +40 -0
  133. package/foundation/discovery/template-adapter.mjs +1 -1
  134. package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
  135. package/foundation/doc-compiler/lenses.d.mts +5 -3
  136. package/foundation/doc-compiler/lenses.mjs +48 -3
  137. package/foundation/doc-compiler/links.d.mts +30 -3
  138. package/foundation/doc-compiler/links.mjs +46 -5
  139. package/foundation/doc-compiler/links.test.mjs +53 -0
  140. package/foundation/doc-compiler/tree.test.mjs +9 -1
  141. package/foundation/integrations/cli-requirement.test.mjs +17 -42
  142. package/foundation/integrations/integrations.d.mts +14 -1
  143. package/foundation/integrations/integrations.mjs +41 -1
  144. package/foundation/integrations/integrations.test.mjs +31 -0
  145. package/foundation/response/batch.type.d.mts +33 -0
  146. package/foundation/response/batch.type.mjs +34 -0
  147. package/foundation/response/response-types.doc.mjs +15 -21
  148. package/foundation/response/response-types.doc.test.mjs +23 -0
  149. package/foundation/xle/browser.d.mts +3 -3
  150. package/foundation/xle/browser.mjs +3 -3
  151. package/foundation/xle/expand.mjs +2 -2
  152. package/foundation/xle/parse.mjs +1 -1
  153. package/foundation/xle/print.mjs +2 -2
  154. package/foundation/xle/splice.mjs +1 -1
  155. package/package.json +9 -9
  156. package/api/layout/_adapter.d.mts +0 -34
  157. package/api/layout/_adapter.mjs +0 -148
  158. package/api/layout/check/check.d.mts +0 -16
  159. package/api/layout/check/check.mjs +0 -40
  160. package/api/layout/expand/expand.d.mts +0 -22
  161. package/api/layout/expand/expand.mjs +0 -155
  162. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  163. package/api/layout/grammar/grammar.d.mts +0 -13
  164. package/api/layout/grammar/grammar.mjs +0 -87
  165. package/api/layout/layout.d.mts +0 -6
  166. package/api/layout/layout.mjs +0 -17
  167. package/api/layout/layout.test.mjs +0 -297
  168. package/api/layout/layout.type.d.mts +0 -89
  169. package/api/layout/layout.type.mjs +0 -103
  170. package/api/layout/layoutCheck.doc.d.mts +0 -11
  171. package/api/layout/layoutCheck.doc.mjs +0 -85
  172. package/api/layout/layoutExpand.doc.d.mts +0 -11
  173. package/api/layout/layoutExpand.doc.mjs +0 -107
  174. package/api/layout/layoutGrammar.doc.d.mts +0 -11
  175. package/api/layout/layoutGrammar.doc.mjs +0 -57
  176. package/clients/cli/commands/layout-check.doc.mjs +0 -65
  177. package/clients/cli/commands/layout-expand.doc.mjs +0 -83
  178. package/clients/cli/commands/layout-grammar.doc.mjs +0 -30
  179. package/clients/cli/commands/layout.doc.mjs +0 -34
  180. package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
  181. package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
  182. package/clients/cli/commands/layout.mjs +0 -275
  183. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  184. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  185. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
  186. /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -0
  187. /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -0
  188. /package/assets/codemods/transforms/{next → v0.6.4}/migrate-native-picker-to-presentation.mjs +0 -0
  189. /package/assets/codemods/transforms/{next → v0.6.4}/migrate-theme-catalog-to-descriptors.mjs +0 -0
@@ -24,6 +24,18 @@ export function loadAuthoringSelfDocs(sources?: string[], root?: string): Promis
24
24
  error: string;
25
25
  }[];
26
26
  }>;
27
+ /**
28
+ * A schema's fields as the table its section prints, each nested field on the
29
+ * row after its parent; null when there are none. A reference block that
30
+ * names some of a schema's fields includes this table of just those.
31
+ * @param {any[]} fields
32
+ * @returns {{type: 'table', headers: string[], rows: string[][]} | null}
33
+ */
34
+ export function schemaFieldTable(fields: any[]): {
35
+ type: "table";
36
+ headers: string[];
37
+ rows: string[][];
38
+ } | null;
27
39
  /**
28
40
  * One self-doc as a topic section, keyed by the doc's own name.
29
41
  * @param {any} doc
@@ -33,6 +33,7 @@ export const AUTHORING_SELF_DOCS = [
33
33
  'config/config.doc.mjs',
34
34
  'debug/debug.doc.mjs',
35
35
  'gap-report/gap-report.doc.mjs',
36
+ 'discover/discover.doc.mjs',
36
37
  'codemod/codemod.doc.mjs',
37
38
  'identity/identity.doc.mjs',
38
39
  'doctypes/base/graph-fields.doc.mjs',
@@ -133,6 +134,24 @@ function fieldRows(fields) {
133
134
  ]);
134
135
  }
135
136
 
137
+ /**
138
+ * A schema's fields as the table its section prints, each nested field on the
139
+ * row after its parent; null when there are none. A reference block that
140
+ * names some of a schema's fields includes this table of just those.
141
+ * @param {any[]} fields
142
+ * @returns {{type: 'table', headers: string[], rows: string[][]} | null}
143
+ */
144
+ export function schemaFieldTable(fields) {
145
+ const rows = fieldRows(fields);
146
+ return rows.length > 0
147
+ ? {
148
+ type: 'table',
149
+ headers: ['Field', 'Type', 'Required', 'Description'],
150
+ rows,
151
+ }
152
+ : null;
153
+ }
154
+
136
155
  /**
137
156
  * One self-doc as a topic section, keyed by the doc's own name.
138
157
  * @param {any} doc
@@ -144,14 +163,8 @@ export function selfDocSection(doc) {
144
163
  if (doc.appliesTo) {
145
164
  content.push({type: 'prose', text: `Applies to: ${doc.appliesTo}`});
146
165
  }
147
- const rows = fieldRows(doc.fields ?? []);
148
- if (rows.length > 0) {
149
- content.push({
150
- type: 'table',
151
- headers: ['Field', 'Type', 'Required', 'Description'],
152
- rows,
153
- });
154
- }
166
+ const table = schemaFieldTable(doc.fields ?? []);
167
+ if (table) content.push(table);
155
168
  for (const example of doc.examples ?? []) {
156
169
  if (typeof example?.code !== 'string' || example.code.trim() === '')
157
170
  continue;
@@ -82,15 +82,20 @@ describe('what the authoring docs say about the docs tree', () => {
82
82
  expect(graphFieldsDoc.description).toMatch(/not built yet/);
83
83
  });
84
84
 
85
- it('keeps graph blocks behind the separate GraphContentBlock type', () => {
85
+ it('keeps graph blocks behind the separate GraphContentBlock type, and a section takes a reference block', () => {
86
86
  const content = referenceDoc.fields
87
87
  .flatMap(field => [field, ...(field.fields ?? [])])
88
88
  .find(field => field.name === 'sections[].content');
89
- expect(content.type).toBe('ReferenceContentBlock[]');
89
+ expect(content.type).toBe('(ReferenceContentBlock | ReferenceDocBlock)[]');
90
90
  expect(content.description).toContain('GraphContentBlock');
91
91
  for (const type of GRAPH_BLOCK_TYPES) {
92
92
  expect(content.description).toContain(type);
93
93
  }
94
+ // A section's reference block reads as the doc it includes.
95
+ expect(GRAPH_BLOCK_TYPES.has('reference')).toBe(false);
96
+ expect(content.description).toMatch(
97
+ /A `reference` block .* includes another doc/,
98
+ );
94
99
  });
95
100
 
96
101
  it('says where namespace docs live: the CLI tree, and each integration', () => {
@@ -122,7 +122,10 @@ export { withSourceTitle };
122
122
  * unlike component discovery, whose built-ins belong to core.
123
123
  */
124
124
  export const BUILTIN_DOCS_PACKAGE: import("../../authoring/index.js").ProviderId;
125
- /** Blocks that are valid authoring but require the compiled graph renderer. */
125
+ /**
126
+ * Blocks that are valid authoring but require the compiled graph renderer: a
127
+ * namespace doc's `blocks` hold them, a topic section does not.
128
+ */
126
129
  export const GRAPH_BLOCK_TYPES: Set<string>;
127
130
  /**
128
131
  * Doc fields only the docs tree reads. A flat topic that sets one fails to
@@ -145,14 +145,15 @@ const BLOCK_FIELDS = {
145
145
  table: ['headers', 'rows'],
146
146
  list: ['style', 'items'],
147
147
  'token-ref': ['topic', 'section'],
148
+ // A read inlines it as the doc it names includes (spec:AST-047 FR9).
149
+ reference: ['target'],
148
150
  };
149
151
 
150
- /** Blocks that are valid authoring but require the compiled graph renderer. */
151
- export const GRAPH_BLOCK_TYPES = new Set([
152
- 'workflow',
153
- 'collection',
154
- 'reference',
155
- ]);
152
+ /**
153
+ * Blocks that are valid authoring but require the compiled graph renderer: a
154
+ * namespace doc's `blocks` hold them, a topic section does not.
155
+ */
156
+ export const GRAPH_BLOCK_TYPES = new Set(['workflow', 'collection']);
156
157
 
157
158
  /**
158
159
  * Doc fields only the docs tree reads. A flat topic that sets one fails to
@@ -168,6 +169,7 @@ export const GRAPH_ONLY_FIELDS = ['placement', 'aliases', 'audience'];
168
169
  /** @type {Record<string, string[]>} */
169
170
  const OPTIONAL_BLOCK_FIELDS = {
170
171
  code: ['label'],
172
+ reference: ['projection', 'presentation'],
171
173
  };
172
174
 
173
175
  /**
@@ -179,8 +181,12 @@ const OPTIONAL_BLOCK_FIELDS = {
179
181
  const BLOCK_FIELD_VALUES = {
180
182
  heading: {level: [3, 4, 5, 6]},
181
183
  list: {style: ['ordered', 'unordered', 'do', 'dont']},
184
+ reference: {presentation: ['summary', 'compact', 'full']},
182
185
  };
183
186
 
187
+ /** The parts of a doc a reference block's `projection` may select. */
188
+ const PROJECTION_FIELDS = ['fields', 'sections'];
189
+
184
190
  /** Keys a section may carry. */
185
191
  const SECTION_FIELDS = ['id', 'title', 'category', 'content', 'previewType'];
186
192
 
@@ -325,6 +331,34 @@ export function problemsInTopic(doc, {placement = false} = {}) {
325
331
  );
326
332
  }
327
333
  }
334
+ // A projection names the parts of the doc to include, so each part
335
+ // it names is a non-empty list of names.
336
+ if (block.type === 'reference' && block.projection != null) {
337
+ const projection = block.projection;
338
+ if (typeof projection !== 'object' || Array.isArray(projection)) {
339
+ problems.push(
340
+ `${blockAt}.projection: expected {fields?, sections?}, naming the parts of the doc to include`,
341
+ );
342
+ } else {
343
+ for (const [key, names] of Object.entries(projection)) {
344
+ if (!PROJECTION_FIELDS.includes(key)) {
345
+ problems.push(
346
+ `${blockAt}.projection.${key}: not a field of a projection`,
347
+ );
348
+ } else if (
349
+ !Array.isArray(names) ||
350
+ names.length === 0 ||
351
+ names.some(
352
+ name => typeof name !== 'string' || name.trim() === '',
353
+ )
354
+ ) {
355
+ problems.push(
356
+ `${blockAt}.projection.${key}: expected a non-empty array of names`,
357
+ );
358
+ }
359
+ }
360
+ }
361
+ }
328
362
  },
329
363
  );
330
364
  },
@@ -310,6 +310,46 @@ describe('problemsInTopic', () => {
310
310
  }
311
311
  });
312
312
 
313
+ it('takes a reference block, and checks its projection and presentation', () => {
314
+ /** @param {any[]} content */
315
+ const withBlocks = content =>
316
+ problemsInTopic(topic({sections: [{title: 'Overview', content}]}));
317
+ expect(
318
+ withBlocks([
319
+ {type: 'reference', target: 'schema:integration'},
320
+ {
321
+ type: 'reference',
322
+ target: '@astryxdesign/cli:schema:integration',
323
+ projection: {fields: ['docs']},
324
+ presentation: 'compact',
325
+ },
326
+ ]),
327
+ ).toEqual([]);
328
+ expect(
329
+ withBlocks([
330
+ {type: 'reference', target: ''},
331
+ {type: 'reference', target: 'schema:x', presentation: 'card'},
332
+ {type: 'reference', target: 'schema:x', projection: {fields: []}},
333
+ {type: 'reference', target: 'schema:x', projection: {rows: ['a']}},
334
+ {type: 'reference', target: 'schema:x', projection: ['docs']},
335
+ {type: 'reference', target: 'schema:x', link: {}},
336
+ ]),
337
+ ).toEqual([
338
+ 'sections[0].content[0].target: expected a non-empty string',
339
+ 'sections[0].content[1].presentation: "card" is not one of summary, compact, full',
340
+ 'sections[0].content[2].projection.fields: expected a non-empty array of names',
341
+ 'sections[0].content[3].projection.rows: not a field of a projection',
342
+ 'sections[0].content[4].projection: expected {fields?, sections?}, naming the parts of the doc to include',
343
+ 'sections[0].content[5].link: not a field of a reference block',
344
+ ]);
345
+ // Workflow and collection blocks stay in a namespace doc's `blocks`.
346
+ for (const type of ['workflow', 'collection']) {
347
+ expect(withBlocks([{type}]).join('\n')).toContain(
348
+ 'requires the compiled graph renderer',
349
+ );
350
+ }
351
+ });
352
+
313
353
  it('rejects a name that is not URL-safe', () => {
314
354
  expect(problemsInTopic(topic({name: 'not a topic'})).join('\n')).toContain(
315
355
  'URL-safe',
@@ -4,7 +4,7 @@
4
4
  * @file Shared template discovery + IO.
5
5
  *
6
6
  * Owns everything the template leaves (list/show/skeleton/copy) AND other
7
- * commands (component, layout, search, init, discover, Doctor integration)
7
+ * commands (component, search, init, discover, Doctor integration)
8
8
  * share: template discovery across core/external/integration sources, the
9
9
  * template-spec loaders, and the cross-command helpers (stripTemplateAssetRefs,
10
10
  * findShowcase, findRelatedBlocks, extractComponents, listTemplates). The
@@ -191,18 +191,6 @@ const RUNNERS = {
191
191
  'import ./integration.doc.mjs',
192
192
  ],
193
193
  },
194
- 'clients/cli/commands/layout.mjs': {
195
- runs: SELF_DOCS,
196
- sites: [
197
- 'import ../../../api/layout/layoutCheck.doc.mjs',
198
- 'import ../../../api/layout/layoutExpand.doc.mjs',
199
- 'import ../../../api/layout/layoutGrammar.doc.mjs',
200
- 'import ./layout-check.doc.mjs',
201
- 'import ./layout-expand.doc.mjs',
202
- 'import ./layout-grammar.doc.mjs',
203
- 'import ./layout.doc.mjs',
204
- ],
205
- },
206
194
  'clients/cli/commands/search.mjs': {
207
195
  runs: SELF_DOCS,
208
196
  sites: [
@@ -24,9 +24,11 @@ export function detailView(node: import("./compile.mjs").CompiledReferenceNode):
24
24
  */
25
25
  export function indexView(node: import("./compile.mjs").CompiledReferenceNode): Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links">;
26
26
  /**
27
- * `docs.detail.section`: one section with its token references inlined. A
28
- * referenced section's content takes the reference's place; the section takes
29
- * the preview type of the last reference that has one, unless it has its own.
27
+ * `docs.detail.section`: one section with its token references and reference
28
+ * blocks inlined, so a read returns only the stable block kinds. A referenced
29
+ * section's content takes the token reference's place; the section takes the
30
+ * preview type of the last reference that has one, unless it has its own. A
31
+ * reference block becomes the content it includes (see referenceView).
30
32
  * @param {import('./compile.mjs').CompiledReferenceNode} node
31
33
  * @param {any} section a linked section of `node`
32
34
  * @returns {any}
@@ -71,9 +71,11 @@ export function indexView(node) {
71
71
  }
72
72
 
73
73
  /**
74
- * `docs.detail.section`: one section with its token references inlined. A
75
- * referenced section's content takes the reference's place; the section takes
76
- * the preview type of the last reference that has one, unless it has its own.
74
+ * `docs.detail.section`: one section with its token references and reference
75
+ * blocks inlined, so a read returns only the stable block kinds. A referenced
76
+ * section's content takes the token reference's place; the section takes the
77
+ * preview type of the last reference that has one, unless it has its own. A
78
+ * reference block becomes the content it includes (see referenceView).
77
79
  * @param {import('./compile.mjs').CompiledReferenceNode} node
78
80
  * @param {any} section a linked section of `node`
79
81
  * @returns {any}
@@ -84,6 +86,10 @@ export function sectionView(node, section) {
84
86
  /** @type {string | null} */
85
87
  let previewType = null;
86
88
  for (const block of section.content) {
89
+ if (block?.type === 'reference') {
90
+ content.push(...referenceView(node, block));
91
+ continue;
92
+ }
87
93
  if (block?.type !== 'token-ref') {
88
94
  content.push(structuredClone(block));
89
95
  continue;
@@ -126,3 +132,42 @@ export function sectionView(node, section) {
126
132
  view.content = content;
127
133
  return withSourceTitle(view, authoredTitle(node, section));
128
134
  }
135
+
136
+ /**
137
+ * A reference block as a read shows it (spec:AST-047 FR9): the content it
138
+ * includes, then where that content comes from and the command that opens it.
139
+ * A reference that includes nothing (a summary, or a doc that is not included
140
+ * whole) shows the doc's title and summary; one whose doc is missing says so
141
+ * where its content would be, as a token reference does.
142
+ * @param {import('./compile.mjs').CompiledReferenceNode} node
143
+ * @param {any} block a linked reference block
144
+ * @returns {any[]}
145
+ */
146
+ function referenceView(node, block) {
147
+ if (!('link' in block)) {
148
+ throw new Error(
149
+ `The reference to "${block.target}" in "${node.id}" was read before it was linked.`,
150
+ );
151
+ }
152
+ const link = block.link;
153
+ if (link == null) {
154
+ return [
155
+ {type: 'prose', text: `[reference: "${block.target}" names no doc]`},
156
+ ];
157
+ }
158
+ const included = (block.content ?? []).map((/** @type {any} */ each) =>
159
+ structuredClone(each),
160
+ );
161
+ if (included.length === 0) {
162
+ const summary = String(link.summary ?? '').trim();
163
+ const lead =
164
+ summary === ''
165
+ ? link.title
166
+ : `${link.title}: ${summary}${/[.!?]$/.test(summary) ? '' : '.'}`;
167
+ return [{type: 'prose', text: `${lead} Read it with \`${link.command}\`.`}];
168
+ }
169
+ return [
170
+ ...included,
171
+ {type: 'prose', text: `From ${link.title}: \`${link.command}\``},
172
+ ];
173
+ }
@@ -27,6 +27,15 @@
27
27
  * @property {string} target the target as written
28
28
  * @property {string} message
29
29
  * @property {string} [section] the key of the section the link sits in
30
+ * @property {true} [include] the problem is in a `reference` block, which
31
+ * includes content rather than linking to it: a reader loses that content,
32
+ * so the authoring check fails on it
33
+ */
34
+ /**
35
+ * What a `reference` block in a topic section includes of the doc it names:
36
+ * stable content blocks, with anything it could not include named in
37
+ * `problems`.
38
+ * @typedef {(block: any) => Promise<{content: any[], problems: string[]}>} DocIncluder
30
39
  */
31
40
  /**
32
41
  * Parse `[<provider>:]<kind>:<name>`. A name may hold spaces
@@ -49,11 +58,13 @@ export function unlinkText(text: string): string;
49
58
  * @param {any[]} blocks
50
59
  * @param {LinkResolver} resolve
51
60
  * @param {{section?: string}} [at]
61
+ * @param {DocIncluder} [include] how a `reference` block includes the doc it
62
+ * names; without it, the block only carries its `link`
52
63
  * @returns {Promise<{content: any[], problems: LinkProblem[]}>}
53
64
  */
54
65
  export function linkBlocks(blocks: any[], resolve: LinkResolver, at?: {
55
66
  section?: string;
56
- }): Promise<{
67
+ }, include?: DocIncluder): Promise<{
57
68
  content: any[];
58
69
  problems: LinkProblem[];
59
70
  }>;
@@ -75,8 +86,9 @@ export function linkSections(sections: any[], resolve: LinkResolver): Promise<{
75
86
  * `{@link <target>}`; and a resolver that finds the doc a target names.
76
87
  * @output The same content with every link resolved: an inline link becomes
77
88
  * the `astryx docs` command that opens its doc, and a block carries a `link`
78
- * with the doc's identity, route, title, summary, and command. A link that
79
- * names no doc is a problem, never a guess.
89
+ * with the doc's identity, route, title, summary, and command. A reference
90
+ * block in a topic section also carries the `content` it includes. A link
91
+ * that names no doc is a problem, never a guess.
80
92
  * @position Pure. The docs adapter owns the resolver (the project's docs tree
81
93
  * and topic catalog) and applies this to every read and every doctor check.
82
94
  */
@@ -132,4 +144,19 @@ export type LinkProblem = {
132
144
  * the key of the section the link sits in
133
145
  */
134
146
  section?: string | undefined;
147
+ /**
148
+ * the problem is in a `reference` block, which
149
+ * includes content rather than linking to it: a reader loses that content,
150
+ * so the authoring check fails on it
151
+ */
152
+ include?: true | undefined;
135
153
  };
154
+ /**
155
+ * What a `reference` block in a topic section includes of the doc it names:
156
+ * stable content blocks, with anything it could not include named in
157
+ * `problems`.
158
+ */
159
+ export type DocIncluder = (block: any) => Promise<{
160
+ content: any[];
161
+ problems: string[];
162
+ }>;
@@ -8,8 +8,9 @@
8
8
  * `{@link <target>}`; and a resolver that finds the doc a target names.
9
9
  * @output The same content with every link resolved: an inline link becomes
10
10
  * the `astryx docs` command that opens its doc, and a block carries a `link`
11
- * with the doc's identity, route, title, summary, and command. A link that
12
- * names no doc is a problem, never a guess.
11
+ * with the doc's identity, route, title, summary, and command. A reference
12
+ * block in a topic section also carries the `content` it includes. A link
13
+ * that names no doc is a problem, never a guess.
13
14
  * @position Pure. The docs adapter owns the resolver (the project's docs tree
14
15
  * and topic catalog) and applies this to every read and every doctor check.
15
16
  */
@@ -62,6 +63,16 @@ const CODE_SPAN = /(`[^`]*`)/;
62
63
  * @property {string} target the target as written
63
64
  * @property {string} message
64
65
  * @property {string} [section] the key of the section the link sits in
66
+ * @property {true} [include] the problem is in a `reference` block, which
67
+ * includes content rather than linking to it: a reader loses that content,
68
+ * so the authoring check fails on it
69
+ */
70
+
71
+ /**
72
+ * What a `reference` block in a topic section includes of the doc it names:
73
+ * stable content blocks, with anything it could not include named in
74
+ * `problems`.
75
+ * @typedef {(block: any) => Promise<{content: any[], problems: string[]}>} DocIncluder
65
76
  */
66
77
 
67
78
  /**
@@ -119,9 +130,11 @@ export function unlinkText(text) {
119
130
  * @param {any[]} blocks
120
131
  * @param {LinkResolver} resolve
121
132
  * @param {{section?: string}} [at]
133
+ * @param {DocIncluder} [include] how a `reference` block includes the doc it
134
+ * names; without it, the block only carries its `link`
122
135
  * @returns {Promise<{content: any[], problems: LinkProblem[]}>}
123
136
  */
124
- export async function linkBlocks(blocks, resolve, at = {}) {
137
+ export async function linkBlocks(blocks, resolve, at = {}, include) {
125
138
  /** @type {LinkProblem[]} */
126
139
  const problems = [];
127
140
  const where = at.section ? {section: at.section} : {};
@@ -195,9 +208,37 @@ export async function linkBlocks(blocks, resolve, at = {}) {
195
208
  });
196
209
  break;
197
210
  }
198
- case 'reference':
199
- content.push({...block, link: await find(block.target)});
211
+ case 'reference': {
212
+ // A reference includes content, so what it cannot include is a
213
+ // problem the authoring check fails on, not one that prints as written.
214
+ const found = await resolve(block.target);
215
+ if ('problem' in found) {
216
+ problems.push({
217
+ target: block.target,
218
+ message: found.problem,
219
+ include: true,
220
+ ...where,
221
+ });
222
+ content.push({...block, link: null});
223
+ break;
224
+ }
225
+ /** @type {any} */
226
+ const linked = {...block, link: found};
227
+ if (include) {
228
+ const included = await include(block);
229
+ for (const message of included.problems) {
230
+ problems.push({
231
+ target: block.target,
232
+ message,
233
+ include: true,
234
+ ...where,
235
+ });
236
+ }
237
+ linked.content = included.content;
238
+ }
239
+ content.push(linked);
200
240
  break;
241
+ }
201
242
  case 'workflow': {
202
243
  const steps = [];
203
244
  for (const step of block.steps ?? []) {
@@ -105,6 +105,59 @@ describe('linkBlocks', () => {
105
105
  );
106
106
  });
107
107
 
108
+ it('includes what a reference block names, and marks what it cannot include', async () => {
109
+ /** @type {any[]} */
110
+ const asked = [];
111
+ const include = async (/** @type {any} */ block) => {
112
+ asked.push(block.target);
113
+ return {
114
+ content: [{type: 'prose', text: 'The doctor command.'}],
115
+ problems: block.projection ? ['projection.fields: no such field'] : [],
116
+ };
117
+ };
118
+ const {content, problems} = await linkBlocks(
119
+ [
120
+ {type: 'reference', target: 'command:doctor'},
121
+ {
122
+ type: 'reference',
123
+ target: 'command:doctor',
124
+ projection: {fields: ['--nope']},
125
+ },
126
+ {type: 'reference', target: 'command:gone'},
127
+ ],
128
+ resolve,
129
+ {section: 'check'},
130
+ include,
131
+ );
132
+ // A target that names no doc is never handed to the includer.
133
+ expect(asked).toEqual(['command:doctor', 'command:doctor']);
134
+ expect(content[0]).toMatchObject({
135
+ link: {command: 'astryx docs cli/commands/doctor'},
136
+ content: [{type: 'prose', text: 'The doctor command.'}],
137
+ });
138
+ expect(content[2]).toEqual({
139
+ type: 'reference',
140
+ target: 'command:gone',
141
+ link: null,
142
+ });
143
+ // Both are the authoring check's: the block includes content, where a
144
+ // link only points at it.
145
+ expect(problems).toEqual([
146
+ {
147
+ target: 'command:doctor',
148
+ message: 'projection.fields: no such field',
149
+ include: true,
150
+ section: 'check',
151
+ },
152
+ {
153
+ target: 'command:gone',
154
+ message: '"command:gone" names no doc',
155
+ include: true,
156
+ section: 'check',
157
+ },
158
+ ]);
159
+ });
160
+
108
161
  it('names every link that finds no doc, and never guesses', async () => {
109
162
  const {content, problems} = await linkSections(
110
163
  [
@@ -497,7 +497,14 @@ describe("the CLI's own docs tree", () => {
497
497
  expect(
498
498
  tree.get('cli')?.slots.map(slot => [slot.name, slot.children]),
499
499
  ).toEqual([
500
- ['guides', ['cli/integrations', 'cli/writing-docs']],
500
+ [
501
+ 'guides',
502
+ [
503
+ 'cli/component-lookups',
504
+ 'cli/integrations',
505
+ 'cli/writing-docs',
506
+ ],
507
+ ],
501
508
  ['reference', ['cli/commands', 'cli/api']],
502
509
  ]);
503
510
  expect(tree.get('cli/api')?.slots[0].children).toEqual([
@@ -566,6 +573,7 @@ describe("the CLI's own docs tree", () => {
566
573
  'commands',
567
574
  ]);
568
575
  expect(inputs.docs.map(d => [d.name, d.placement?.parent])).toEqual([
576
+ ['component-lookups', 'namespace:cli'],
569
577
  ['integrations', 'namespace:cli'],
570
578
  ['writing-docs', 'namespace:cli'],
571
579
  ]);
@@ -1,10 +1,6 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  import {describe, expect, it} from 'vitest';
4
- import * as fs from 'node:fs';
5
- import * as path from 'node:path';
6
- import {CLI_ROOT} from '../fs/paths.mjs';
7
- import {semverCompare} from '../env/semver.mjs';
8
4
  import {
9
5
  DOCS_TREE_CLI,
10
6
  lowestAdmitted,
@@ -55,55 +51,34 @@ describe('docsTreeCliProblem', () => {
55
51
 
56
52
  it('declares the peer as optional, and keeps what the package says of it', () => {
57
53
  const declared = withDocsTreeCli({name: '@acme/kit'});
58
- expect(declared.peerDependencies).toEqual({'@astryxdesign/cli': `>=${DOCS_TREE_CLI}`});
59
- expect(declared.peerDependenciesMeta).toEqual({'@astryxdesign/cli': {optional: true}});
54
+ expect(declared.peerDependencies).toEqual({
55
+ '@astryxdesign/cli': `>=${DOCS_TREE_CLI}`,
56
+ });
57
+ expect(declared.peerDependenciesMeta).toEqual({
58
+ '@astryxdesign/cli': {optional: true},
59
+ });
60
60
  expect(docsTreeCliProblem(declared)).toBeNull();
61
61
  const required = withDocsTreeCli({
62
62
  peerDependencies: {react: '^19.0.0', '@astryxdesign/cli': '^0.6.0'},
63
63
  peerDependenciesMeta: {'@astryxdesign/cli': {optional: false}},
64
64
  });
65
65
  expect(required.peerDependencies.react).toBe('^19.0.0');
66
- expect(required.peerDependenciesMeta['@astryxdesign/cli']).toEqual({optional: false});
66
+ expect(required.peerDependenciesMeta['@astryxdesign/cli']).toEqual({
67
+ optional: false,
68
+ });
67
69
  });
68
70
  });
69
71
 
70
72
  describe('replacesCliProblem', () => {
71
73
  it('asks a package that sets replaces for a CLI that reads the field', () => {
72
- expect(replacesCliProblem({name: '@acme/kit'})).toContain('sets `replaces`');
73
- expect(replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '^0.6.0'}})).toContain(
74
- 'admits a CLI older than',
75
- );
76
- expect(replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '>=0.7.0'}})).toBeNull();
77
- });
78
- });
79
-
80
- describe('DOCS_TREE_CLI', () => {
81
- it('is no later than the release the pending changesets make', () => {
82
- const {version} = JSON.parse(
83
- fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
74
+ expect(replacesCliProblem({name: '@acme/kit'})).toContain(
75
+ 'sets `replaces`',
84
76
  );
85
- const dir = path.join(CLI_ROOT, '..', '..', '.changeset');
86
- /** @type {Record<string, number>} */
87
- const rank = {patch: 1, minor: 2, major: 3};
88
- let bump = 0;
89
- for (const file of fs.readdirSync(dir)) {
90
- if (!file.endsWith('.md') || file === 'README.md') continue;
91
- const head = fs.readFileSync(path.join(dir, file), 'utf-8').split('---')[1] ?? '';
92
- const m = /['"]@astryxdesign\/cli['"]\s*:\s*(patch|minor|major)/.exec(head);
93
- if (m) bump = Math.max(bump, rank[m[1]]);
94
- }
95
- const [major, minor, patch] = version.split('-')[0].split('.').map(Number);
96
- const next =
97
- bump === 3
98
- ? `${major + 1}.0.0`
99
- : bump === 2
100
- ? `${major}.${minor + 1}.0`
101
- : bump === 1
102
- ? `${major}.${minor}.${patch + 1}`
103
- : version;
104
- // The first release that reads namespace docs is this one or an earlier
105
- // one; a later constant would make every author wait for a CLI that does
106
- // not exist yet.
107
- expect(semverCompare(DOCS_TREE_CLI, next)).toBeLessThanOrEqual(0);
77
+ expect(
78
+ replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '^0.6.0'}}),
79
+ ).toContain('admits a CLI older than');
80
+ expect(
81
+ replacesCliProblem({peerDependencies: {'@astryxdesign/cli': '>=0.7.0'}}),
82
+ ).toBeNull();
108
83
  });
109
84
  });