@astryxdesign/cli 0.6.6-canary.cc0df20 → 0.6.6-canary.cf59be8
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.
- package/api/component/component-replacement.test.mjs +12 -0
- package/api/component/component.doc.mjs +5 -2
- package/api/docs/detail/section/section.d.mts +44 -0
- package/api/docs/detail/section/section.mjs +164 -13
- package/api/docs/docs.doc.mjs +2 -2
- package/api/docs/docs.mjs +11 -16
- package/api/docs/docs.test.mjs +7 -8
- package/api/docs/namespace-section.test.mjs +260 -0
- package/api/doctor/doctor.d.mts +6 -0
- package/api/doctor/doctor.mjs +149 -40
- package/api/doctor/doctor.test.mjs +104 -0
- package/api/gap-report/gap-report.doc.mjs +2 -1
- package/api/integration/validate-integration.mjs +20 -4
- package/api/integration/validate-integration.test.mjs +73 -0
- package/api/search/search.d.mts +44 -0
- package/api/search/search.domain-priority.test.mjs +261 -0
- package/api/search/search.mjs +191 -29
- package/api/swizzle/swizzle.doc.mjs +5 -2
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/component-replacement.text.test.mjs +45 -0
- package/clients/cli/commands/docs.doc.mjs +2 -1
- package/clients/cli/commands/docs.test.mjs +12 -9
- package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +33 -0
- package/clients/cli/lib/component-format.mjs +13 -3
- package/foundation/env/package-manager.d.mts +3 -0
- package/foundation/env/package-manager.mjs +71 -3
- package/foundation/env/package-manager.test.mjs +82 -1
- package/foundation/integrations/validate-contributions.d.mts +16 -0
- package/foundation/integrations/validate-contributions.mjs +56 -8
- package/package.json +9 -9
|
@@ -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',
|
|
@@ -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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
}
|
package/api/docs/docs.doc.mjs
CHANGED
|
@@ -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
|
|
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: [
|
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 {
|
|
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
|
-
|
|
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
|
}
|
package/api/docs/docs.test.mjs
CHANGED
|
@@ -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
|
|
244
|
-
const err = await docs('cli', '
|
|
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
|
|
248
|
-
const
|
|
249
|
-
expect(
|
|
250
|
-
|
|
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 () => {
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A section read on a namespace (spec:AST-046 FR6): `astryx docs
|
|
5
|
+
* <namespace> <section>` answers from the one guide below the namespace that
|
|
6
|
+
* has the section, exactly as that guide's own section read does, so a section
|
|
7
|
+
* read that worked before a topic became a namespace still works.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
13
|
+
import {docs} from './docs.mjs';
|
|
14
|
+
import {oneGuide} from './detail/section/section.mjs';
|
|
15
|
+
|
|
16
|
+
const SLOW = 60_000;
|
|
17
|
+
|
|
18
|
+
/** @type {string} */
|
|
19
|
+
let tmpDir;
|
|
20
|
+
|
|
21
|
+
/** @param {Record<string, object>} files the integration's doc files */
|
|
22
|
+
function scaffold(files) {
|
|
23
|
+
fs.writeFileSync(
|
|
24
|
+
path.join(tmpDir, 'package.json'),
|
|
25
|
+
JSON.stringify({name: 'consumer'}),
|
|
26
|
+
);
|
|
27
|
+
fs.writeFileSync(
|
|
28
|
+
path.join(tmpDir, 'astryx.config.mjs'),
|
|
29
|
+
"export default {integrations: ['@acme/kit']};\n",
|
|
30
|
+
);
|
|
31
|
+
const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'kit');
|
|
32
|
+
fs.mkdirSync(path.join(pkgDir, 'docs'), {recursive: true});
|
|
33
|
+
fs.writeFileSync(
|
|
34
|
+
path.join(pkgDir, 'package.json'),
|
|
35
|
+
JSON.stringify({name: '@acme/kit', version: '1.0.0'}),
|
|
36
|
+
);
|
|
37
|
+
fs.writeFileSync(
|
|
38
|
+
path.join(pkgDir, 'astryx.integration.mjs'),
|
|
39
|
+
"export default {docs: './docs'};\n",
|
|
40
|
+
);
|
|
41
|
+
for (const [file, doc] of Object.entries(files)) {
|
|
42
|
+
fs.writeFileSync(
|
|
43
|
+
path.join(pkgDir, 'docs', file),
|
|
44
|
+
`export const docs = ${JSON.stringify(doc, null, 2)};\n`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} name
|
|
51
|
+
* @param {number} order
|
|
52
|
+
* @param {Array<{title: string, id?: string}>} sections
|
|
53
|
+
*/
|
|
54
|
+
function guide(name, order, sections) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'generic',
|
|
57
|
+
name,
|
|
58
|
+
title: `Acme ${name}`,
|
|
59
|
+
description: `The ${name} guide.`,
|
|
60
|
+
placement: {parent: 'namespace:acme', slot: 'guides', order},
|
|
61
|
+
sections: sections.map(section => ({
|
|
62
|
+
...section,
|
|
63
|
+
content: [{type: 'prose', text: `${section.title} text.`}],
|
|
64
|
+
})),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A namespace of two guides that both have a section titled "...setup". */
|
|
69
|
+
function kit() {
|
|
70
|
+
return {
|
|
71
|
+
'acme.doc.mjs': {
|
|
72
|
+
type: 'namespace',
|
|
73
|
+
name: 'acme',
|
|
74
|
+
title: 'Acme',
|
|
75
|
+
summary: 'Everything about the Acme kit.',
|
|
76
|
+
slots: {guides: {title: 'Guides', accepts: {kinds: ['generic']}}},
|
|
77
|
+
},
|
|
78
|
+
'install.doc.mjs': guide('install', 1, [
|
|
79
|
+
{title: 'Package setup', id: 'package-setup'},
|
|
80
|
+
{title: 'Verify'},
|
|
81
|
+
]),
|
|
82
|
+
'theme.doc.mjs': guide('theme', 2, [
|
|
83
|
+
{title: 'Theme setup'},
|
|
84
|
+
{title: 'Dark mode'},
|
|
85
|
+
]),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
tmpDir = fs.mkdtempSync(
|
|
91
|
+
path.join(process.cwd(), '.astryx-namespace-section-test-'),
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('a section read on a namespace', () => {
|
|
100
|
+
it(
|
|
101
|
+
'returns the one guide section, by key and by title, as the guide read does',
|
|
102
|
+
async () => {
|
|
103
|
+
for (const query of ['side-panels', 'Side panels', 'side panels']) {
|
|
104
|
+
const read = await docs('layout', query);
|
|
105
|
+
expect(read).toEqual(await docs('layout/side-panels', 'side-panels'));
|
|
106
|
+
expect(read).toMatchObject({
|
|
107
|
+
type: 'docs.detail.section',
|
|
108
|
+
package: '@astryxdesign/cli',
|
|
109
|
+
data: {id: 'side-panels', title: 'Side panels'},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// A section in a guide of its own, and a section past a guide's first.
|
|
113
|
+
expect((await docs('layout', 'shell')).data.id).toBe('shell');
|
|
114
|
+
expect((await docs('layout', 'responsive-contract')).data.id).toBe(
|
|
115
|
+
'responsive-contract',
|
|
116
|
+
);
|
|
117
|
+
},
|
|
118
|
+
SLOW,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
it(
|
|
122
|
+
'reads dense and Chinese the way the guide read does',
|
|
123
|
+
async () => {
|
|
124
|
+
for (const options of [{dense: true}, {zh: true}, {lang: 'dense'}]) {
|
|
125
|
+
expect(await docs('layout', 'side-panels', options)).toEqual(
|
|
126
|
+
await docs('layout/side-panels', 'side-panels', options),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
SLOW,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
it(
|
|
134
|
+
"prefers the guide whose section key is the query over another guide's title match",
|
|
135
|
+
async () => {
|
|
136
|
+
scaffold(kit());
|
|
137
|
+
const read = await docs('acme', 'package-setup', {cwd: tmpDir});
|
|
138
|
+
expect(read.data).toMatchObject({
|
|
139
|
+
id: 'package-setup',
|
|
140
|
+
title: 'Package setup',
|
|
141
|
+
});
|
|
142
|
+
expect(read.data.links.up).toBe('astryx docs acme/install --index');
|
|
143
|
+
expect((await docs('acme', 'dark mode', {cwd: tmpDir})).data.title).toBe(
|
|
144
|
+
'Dark mode',
|
|
145
|
+
);
|
|
146
|
+
},
|
|
147
|
+
SLOW,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
it(
|
|
151
|
+
'fails on a miss, naming every guide below the namespace',
|
|
152
|
+
async () => {
|
|
153
|
+
const err = await docs('layout', 'zzzz-nope').catch(e => e);
|
|
154
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
155
|
+
const names = err.suggestions.map(s => s.name);
|
|
156
|
+
expect(names).toContain('layout/scaffold');
|
|
157
|
+
expect(names).toContain('layout/side-panels');
|
|
158
|
+
expect(names.every(name => name.startsWith('layout/'))).toBe(true);
|
|
159
|
+
// At any depth: guides under nested namespaces are named, namespaces are not.
|
|
160
|
+
const cli = await docs('cli', 'zzzz-nope').catch(e => e);
|
|
161
|
+
expect(cli.code).toBe('ERR_UNKNOWN_SECTION');
|
|
162
|
+
expect(cli.suggestions.map(s => s.name)).toContain(
|
|
163
|
+
'cli/integrations/quick-start',
|
|
164
|
+
);
|
|
165
|
+
expect(cli.suggestions.map(s => s.name)).not.toContain(
|
|
166
|
+
'cli/integrations',
|
|
167
|
+
);
|
|
168
|
+
},
|
|
169
|
+
SLOW,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
it(
|
|
173
|
+
'still fails a section on a typed doc, naming the doc',
|
|
174
|
+
async () => {
|
|
175
|
+
const err = await docs('cli/commands/docs', 'anything').catch(e => e);
|
|
176
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
177
|
+
expect(err.suggestions.map(s => s.name)).toEqual(['cli/commands/docs']);
|
|
178
|
+
},
|
|
179
|
+
SLOW,
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('a namespace read answers what the guide read answers', () => {
|
|
184
|
+
/** A guide with a title match before a key match, and a second guide. */
|
|
185
|
+
function competing() {
|
|
186
|
+
return {
|
|
187
|
+
...kit(),
|
|
188
|
+
'install.doc.mjs': guide('install', 1, [
|
|
189
|
+
{title: 'Shell contract'},
|
|
190
|
+
{title: 'Shell'},
|
|
191
|
+
]),
|
|
192
|
+
'theme.doc.mjs': guide('theme', 2, [{title: 'Setup', id: 'setup'}]),
|
|
193
|
+
'extra.doc.mjs': guide('extra', 3, [{title: 'Theme setup'}]),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
it(
|
|
198
|
+
'returns the section the guide read returns, even when a later section has the key',
|
|
199
|
+
async () => {
|
|
200
|
+
scaffold(competing());
|
|
201
|
+
const own = await docs('acme/install', 'shell', {cwd: tmpDir});
|
|
202
|
+
const read = await docs('acme', 'shell', {cwd: tmpDir});
|
|
203
|
+
expect(read).toEqual(own);
|
|
204
|
+
expect(read.data.title).toBe('Shell contract');
|
|
205
|
+
},
|
|
206
|
+
SLOW,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
it(
|
|
210
|
+
"prefers the guide whose own match is the query's key over another guide's title match",
|
|
211
|
+
async () => {
|
|
212
|
+
scaffold(competing());
|
|
213
|
+
const read = await docs('acme', 'setup', {cwd: tmpDir});
|
|
214
|
+
expect(read).toEqual(await docs('acme/theme', 'setup', {cwd: tmpDir}));
|
|
215
|
+
expect(read.data).toMatchObject({id: 'setup', title: 'Setup'});
|
|
216
|
+
},
|
|
217
|
+
SLOW,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
it(
|
|
221
|
+
'names the children of a namespace with no guide below it',
|
|
222
|
+
async () => {
|
|
223
|
+
const err = await docs('cli/api', 'anything').catch(e => e);
|
|
224
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
225
|
+
const api = (await docs('cli/api')).data;
|
|
226
|
+
expect(err.suggestions.map(s => s.name)).toEqual(
|
|
227
|
+
api.slots.flatMap(slot => slot.children.map(child => child.route)),
|
|
228
|
+
);
|
|
229
|
+
expect(err.suggestions.length).toBeGreaterThan(0);
|
|
230
|
+
expect(err.message).toContain('Open one of its children');
|
|
231
|
+
},
|
|
232
|
+
SLOW,
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('a section query that matches sections in several guides', () => {
|
|
237
|
+
// It used to guess; now it asks. A flat topic's section read returns its
|
|
238
|
+
// first title match; across guides, the read names each guide instead.
|
|
239
|
+
it(
|
|
240
|
+
'asks which guide, naming each guide that matches',
|
|
241
|
+
async () => {
|
|
242
|
+
scaffold(kit());
|
|
243
|
+
const err = await docs('acme', 'setup', {cwd: tmpDir}).catch(e => e);
|
|
244
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
245
|
+
expect(err.suggestions).toEqual([
|
|
246
|
+
{name: 'acme/install', reason: 'has "Package setup"'},
|
|
247
|
+
{name: 'acme/theme', reason: 'has "Theme setup"'},
|
|
248
|
+
]);
|
|
249
|
+
},
|
|
250
|
+
SLOW,
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
it('decides in one place: oneGuide answers only a single match', () => {
|
|
254
|
+
const a = /** @type {any} */ ({guide: {route: 'acme/install'}});
|
|
255
|
+
const b = /** @type {any} */ ({guide: {route: 'acme/theme'}});
|
|
256
|
+
expect(oneGuide([a])).toBe(a);
|
|
257
|
+
expect(oneGuide([a, b])).toBeNull();
|
|
258
|
+
expect(oneGuide([])).toBeNull();
|
|
259
|
+
});
|
|
260
|
+
});
|
package/api/doctor/doctor.d.mts
CHANGED
|
@@ -266,5 +266,11 @@ export type DoctorContext = {
|
|
|
266
266
|
* path (e.g. multiple config files present), surfaced by checkConfig as a FAIL.
|
|
267
267
|
*/
|
|
268
268
|
configError?: Error | null | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* - Why the CLI could not load the
|
|
271
|
+
* project from its config, when it could not. Checks that need the loaded
|
|
272
|
+
* project quote it when they skip, so a skip says what was found.
|
|
273
|
+
*/
|
|
274
|
+
projectError?: string | null | undefined;
|
|
269
275
|
};
|
|
270
276
|
import { DocsCatalog } from '../../foundation/discovery/docs-discovery.mjs';
|