@astryxdesign/cli 0.6.3-canary.1f30d4e → 0.6.3-canary.1ffe66d
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/README.md +19 -17
- package/api/component/_adapter.d.mts +6 -12
- package/api/component/_adapter.mjs +20 -10
- package/api/component/component.mjs +60 -12
- package/api/component/list/list.mjs +3 -2
- package/api/docs/_adapter.d.mts +209 -28
- package/api/docs/_adapter.mjs +667 -35
- package/api/docs/detail/detail.mjs +11 -3
- package/api/docs/detail/section/section.mjs +20 -3
- package/api/docs/docs.d.mts +5 -3
- package/api/docs/docs.doc.mjs +35 -15
- package/api/docs/docs.mjs +44 -8
- package/api/docs/docs.test.mjs +158 -4
- package/api/docs/docs.type.d.mts +165 -2
- package/api/docs/docs.type.mjs +101 -3
- package/api/docs/index/index.mjs +11 -3
- package/api/docs/index/index.test.mjs +1 -1
- package/api/docs/integration-tree.test.mjs +547 -0
- package/api/docs/integrationDocs.test.mjs +14 -14
- package/api/docs/list/list.mjs +25 -5
- package/api/docs/node/node.d.mts +43 -0
- package/api/docs/node/node.mjs +192 -0
- package/api/doctor/doctor.d.mts +30 -2
- package/api/doctor/doctor.mjs +146 -7
- package/api/doctor/doctor.test.mjs +89 -1
- package/api/index.d.mts +1 -1
- package/api/index.mjs +1 -0
- package/api/init/init.doc.mjs +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +107 -5
- package/api/integration/add-contribution.test.mjs +137 -0
- package/api/integration/authoring-checks.mjs +125 -28
- package/api/integration/authoring-checks.test.mjs +171 -3
- package/api/integration/authoring-checks.type.mjs +6 -1
- package/api/integration/integration-authoring.type.d.mts +2 -0
- package/api/integration/integration-authoring.type.mjs +2 -0
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddDoc.doc.mjs +7 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationPackCheck.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
- package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
- package/api/integration/pack-check.mjs +34 -0
- package/api/integration/pack-check.test.mjs +121 -0
- package/api/integration/pack-check.type.d.mts +26 -2
- package/api/integration/pack-check.type.mjs +14 -1
- package/api/integration/template-conflict-compatibility.test.mjs +73 -0
- package/api/integration/validate-integration.test.mjs +3 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/json/index.ts +2 -0
- package/api/layout/_adapter.mjs +20 -5
- package/api/search/search.d.mts +26 -1
- package/api/search/search.doc.mjs +4 -3
- package/api/search/search.mjs +308 -29
- package/api/search/search.test.mjs +91 -2
- package/api/search/search.type.d.mts +13 -1
- package/api/search/search.type.mjs +4 -1
- package/api/template/list/list.mjs +1 -0
- package/api/template/template-integration.test.mjs +1022 -3
- package/api/template/template.doc.mjs +27 -7
- package/api/template/template.mjs +45 -8
- package/api/template/template.type.d.mts +6 -8
- package/api/template/template.type.mjs +3 -2
- package/api/theme/template/template.test.mjs +5 -0
- package/api/theme/themeTemplate.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/principles.doc.mjs +6 -6
- package/assets/docs/styling-libraries.doc.mjs +2 -2
- package/assets/docs/styling.doc.mjs +4 -4
- package/assets/docs/theme.doc.mjs +3 -3
- package/assets/docs/tokens.doc.mjs +1 -1
- package/assets/docs/tree/api.doc.mjs +30 -0
- package/assets/docs/tree/cli.doc.mjs +23 -0
- package/assets/docs/tree/commands.doc.mjs +25 -0
- package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
- package/assets/docs/tree/integrations.test.mjs +62 -0
- package/assets/docs/tree/writing-docs.doc.mjs +286 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
- package/authoring/doctypes/base/type.ts +6 -5
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/command/type.ts +2 -2
- package/authoring/doctypes/enum/enum.doc.mjs +1 -1
- package/authoring/doctypes/enum/type.ts +1 -1
- package/authoring/doctypes/function/function.doc.mjs +3 -2
- package/authoring/doctypes/function/type.ts +3 -2
- package/authoring/doctypes/namespace/namespace.doc.mjs +5 -9
- package/authoring/doctypes/reference/reference.doc.mjs +3 -3
- package/authoring/doctypes/reference/type.ts +3 -0
- package/authoring/doctypes/schema/schema.doc.mjs +1 -1
- package/authoring/doctypes/schema/type.ts +1 -1
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +4 -0
- package/authoring/doctypes/template/parse.test.mjs +18 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +8 -0
- package/authoring/identity/identity.doc.mjs +2 -2
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/commands/build-theme.mjs +1 -1
- package/clients/cli/commands/build.mjs +5 -2
- package/clients/cli/commands/component/index.mjs +1 -1
- package/clients/cli/commands/component-ownership.test.mjs +3 -3
- package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
- package/clients/cli/commands/discover.mjs +1 -1
- package/clients/cli/commands/docs.doc.mjs +20 -8
- package/clients/cli/commands/docs.mjs +175 -18
- package/clients/cli/commands/docs.test.mjs +114 -7
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
- package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
- package/clients/cli/commands/doctor-integration.test.mjs +75 -1
- package/clients/cli/commands/doctor.mjs +53 -16
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration.mjs +1 -0
- package/clients/cli/commands/search.mjs +11 -2
- package/clients/cli/commands/setup-nudge.test.mjs +6 -0
- package/clients/cli/commands/template.doc.mjs +23 -6
- package/clients/cli/commands/template.mjs +4 -91
- package/clients/cli/commands/text-json-parity.test.mjs +2 -1
- package/clients/cli/index.mjs +8 -0
- package/clients/cli/lib/manifest.mjs +9 -2
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +10 -1
- package/foundation/config/project.d.mts +12 -11
- package/foundation/config/project.mjs +73 -59
- package/foundation/config/project.test.mjs +141 -5
- package/foundation/discovery/authoring-self-docs.test.mjs +17 -7
- package/foundation/discovery/cli-self-docs.d.mts +40 -34
- package/foundation/discovery/cli-self-docs.mjs +91 -115
- package/foundation/discovery/cli-self-docs.test.mjs +104 -166
- package/foundation/discovery/component-discovery.d.mts +38 -0
- package/foundation/discovery/component-discovery.mjs +48 -0
- package/foundation/discovery/docs-discovery.d.mts +105 -8
- package/foundation/discovery/docs-discovery.mjs +177 -13
- package/foundation/discovery/docs-discovery.test.mjs +56 -17
- package/foundation/discovery/docs-output-budget.d.mts +2 -2
- package/foundation/discovery/docs-output-budget.mjs +1 -1
- package/foundation/discovery/docs-section-key.d.mts +9 -2
- package/foundation/discovery/docs-section-key.mjs +15 -1
- package/foundation/discovery/template-adapter.d.mts +92 -6
- package/foundation/discovery/template-adapter.mjs +453 -17
- package/foundation/discovery/template-adapter.test.mjs +42 -0
- package/foundation/discovery/template-conflict-release.d.mts +13 -0
- package/foundation/discovery/template-conflict-release.mjs +40 -0
- package/foundation/discovery/template-conflict-release.test.mjs +40 -0
- package/foundation/doc-compiler/bundle.mjs +61 -1
- package/foundation/doc-compiler/bundle.test.mjs +21 -10
- package/foundation/doc-compiler/compile.d.mts +113 -132
- package/foundation/doc-compiler/compile.mjs +52 -6
- package/foundation/doc-compiler/diagnostics.mjs +28 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
- package/foundation/doc-compiler/inputs.d.mts +2 -2
- package/foundation/doc-compiler/inputs.mjs +6 -1
- package/foundation/doc-compiler/ir.mjs +7 -0
- package/foundation/doc-compiler/lenses.d.mts +3 -2
- package/foundation/doc-compiler/lenses.mjs +2 -1
- package/foundation/doc-compiler/links.d.mts +135 -0
- package/foundation/doc-compiler/links.mjs +253 -0
- package/foundation/doc-compiler/links.test.mjs +139 -0
- package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
- package/foundation/doc-compiler/read.d.mts +3 -2
- package/foundation/doc-compiler/read.mjs +6 -1
- package/foundation/doc-compiler/tree.d.mts +288 -0
- package/foundation/doc-compiler/tree.mjs +876 -0
- package/foundation/doc-compiler/tree.test.mjs +598 -0
- package/foundation/integrations/autolink.test.mjs +1 -1
- package/foundation/integrations/cli-requirement.d.mts +45 -0
- package/foundation/integrations/cli-requirement.mjs +154 -0
- package/foundation/integrations/cli-requirement.test.mjs +109 -0
- package/foundation/integrations/contribution-inventory.d.mts +2 -1
- package/foundation/integrations/contribution-inventory.mjs +10 -4
- package/foundation/integrations/contribution-inventory.test.mjs +19 -0
- package/foundation/integrations/integration-warnings.d.mts +9 -2
- package/foundation/integrations/integration-warnings.mjs +51 -26
- package/foundation/integrations/integration-warnings.test.mjs +74 -1
- package/foundation/integrations/validate-contributions.mjs +25 -27
- package/foundation/response/response-types.doc.d.mts +5 -1
- package/foundation/response/response-types.doc.mjs +18 -9
- package/foundation/xle/expand.mjs +1 -1
- package/foundation/xle/xle.test.mjs +13 -0
- package/package.json +9 -9
- package/assets/docs/cli.doc.mjs +0 -15
|
@@ -27,6 +27,7 @@ const NODE_FIELDS = new Set([
|
|
|
27
27
|
'lang',
|
|
28
28
|
'provenance',
|
|
29
29
|
'sourceTitles',
|
|
30
|
+
'sectionProviders',
|
|
30
31
|
'doc',
|
|
31
32
|
]);
|
|
32
33
|
const RESOLVED_FIELDS = new Set([
|
|
@@ -170,6 +171,12 @@ function structureProblems(node) {
|
|
|
170
171
|
'provenance: expected {provider, replaces, extensions} naming packages, not paths',
|
|
171
172
|
);
|
|
172
173
|
}
|
|
174
|
+
const providers = isRecord(node.sectionProviders)
|
|
175
|
+
? node.sectionProviders
|
|
176
|
+
: null;
|
|
177
|
+
if (!providers || !Object.values(providers).every(isText)) {
|
|
178
|
+
problems.push('sectionProviders: expected section key -> provider id');
|
|
179
|
+
}
|
|
173
180
|
const titles = isRecord(node.sourceTitles) ? node.sourceTitles : null;
|
|
174
181
|
if (!titles || !Object.values(titles).every(isText)) {
|
|
175
182
|
problems.push('sourceTitles: expected section key -> authored title');
|
|
@@ -18,10 +18,11 @@ export function readerSections(node: import("./compile.mjs").CompiledReferenceNo
|
|
|
18
18
|
export function detailView(node: import("./compile.mjs").CompiledReferenceNode): any;
|
|
19
19
|
/**
|
|
20
20
|
* `docs.index`: what the topic is, and each section's key, title and summary.
|
|
21
|
+
* The index leaf adds the moves.
|
|
21
22
|
* @param {import('./compile.mjs').CompiledReferenceNode} node
|
|
22
|
-
* @returns {import('../../api/docs/docs.type.mjs').DocsIndex}
|
|
23
|
+
* @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'>}
|
|
23
24
|
*/
|
|
24
|
-
export function indexView(node: import("./compile.mjs").CompiledReferenceNode): import("../../api/docs/docs.type.mjs").DocsIndex
|
|
25
|
+
export function indexView(node: import("./compile.mjs").CompiledReferenceNode): Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links">;
|
|
25
26
|
/**
|
|
26
27
|
* `docs.detail.section`: one section with its token references inlined. A
|
|
27
28
|
* referenced section's content takes the reference's place; the section takes
|
|
@@ -62,8 +62,9 @@ export function detailView(node) {
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* `docs.index`: what the topic is, and each section's key, title and summary.
|
|
65
|
+
* The index leaf adds the moves.
|
|
65
66
|
* @param {import('./compile.mjs').CompiledReferenceNode} node
|
|
66
|
-
* @returns {import('../../api/docs/docs.type.mjs').DocsIndex}
|
|
67
|
+
* @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'>}
|
|
67
68
|
*/
|
|
68
69
|
export function indexView(node) {
|
|
69
70
|
return buildDocsIndexData(node.doc);
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} LinkTarget
|
|
6
|
+
* @property {string | null} provider the provider id it names, or null for the
|
|
7
|
+
* linking doc's own provider
|
|
8
|
+
* @property {string} kind
|
|
9
|
+
* @property {string} name
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The doc a link opens, as a docs read returns it.
|
|
13
|
+
* @typedef {object} DocLink
|
|
14
|
+
* @property {string} target the target as written: `[<provider>:]<kind>:<name>`
|
|
15
|
+
* @property {string} id the doc's identity (a DocId)
|
|
16
|
+
* @property {string} route what `astryx docs <route>` opens
|
|
17
|
+
* @property {string} title
|
|
18
|
+
* @property {string} summary
|
|
19
|
+
* @property {string} command the command that opens it, `astryx docs <route>`
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Finds the doc a target names, or says why none matches.
|
|
23
|
+
* @typedef {(target: string) => Promise<DocLink | {problem: string}>} LinkResolver
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} LinkProblem
|
|
27
|
+
* @property {string} target the target as written
|
|
28
|
+
* @property {string} message
|
|
29
|
+
* @property {string} [section] the key of the section the link sits in
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Parse `[<provider>:]<kind>:<name>`. A name may hold spaces
|
|
33
|
+
* (`command:theme build`); no part holds a colon.
|
|
34
|
+
* @param {unknown} target
|
|
35
|
+
* @returns {LinkTarget | {error: string}}
|
|
36
|
+
*/
|
|
37
|
+
export function parseLinkTarget(target: unknown): LinkTarget | {
|
|
38
|
+
error: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Text with each inline link replaced by its name, for indexes that must not
|
|
42
|
+
* read the link syntax as words.
|
|
43
|
+
* @param {string} text
|
|
44
|
+
* @returns {string}
|
|
45
|
+
*/
|
|
46
|
+
export function unlinkText(text: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Resolve every link in a list of content blocks, in order.
|
|
49
|
+
* @param {any[]} blocks
|
|
50
|
+
* @param {LinkResolver} resolve
|
|
51
|
+
* @param {{section?: string}} [at]
|
|
52
|
+
* @returns {Promise<{content: any[], problems: LinkProblem[]}>}
|
|
53
|
+
*/
|
|
54
|
+
export function linkBlocks(blocks: any[], resolve: LinkResolver, at?: {
|
|
55
|
+
section?: string;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
content: any[];
|
|
58
|
+
problems: LinkProblem[];
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Resolve every link in a topic's sections.
|
|
62
|
+
* @param {any[]} sections
|
|
63
|
+
* @param {LinkResolver} resolve
|
|
64
|
+
* @returns {Promise<{sections: any[], problems: LinkProblem[]}>}
|
|
65
|
+
*/
|
|
66
|
+
export function linkSections(sections: any[], resolve: LinkResolver): Promise<{
|
|
67
|
+
sections: any[];
|
|
68
|
+
problems: LinkProblem[];
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* @file Links between docs, named by doc identity (spec:AST-047 FR9).
|
|
72
|
+
*
|
|
73
|
+
* @input A link target, `[<provider>:]<kind>:<name>`, written as a `reference`
|
|
74
|
+
* block, in a `workflow` step's `references`, or inline in text as
|
|
75
|
+
* `{@link <target>}`; and a resolver that finds the doc a target names.
|
|
76
|
+
* @output The same content with every link resolved: an inline link becomes
|
|
77
|
+
* 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.
|
|
80
|
+
* @position Pure. The docs adapter owns the resolver (the project's docs tree
|
|
81
|
+
* and topic catalog) and applies this to every read and every doctor check.
|
|
82
|
+
*/
|
|
83
|
+
/** The kinds a link can name: every authored doc kind. */
|
|
84
|
+
export const LINK_KINDS: Set<string>;
|
|
85
|
+
/** An inline link in text: `{@link <target>}`. */
|
|
86
|
+
export const INLINE_LINK: RegExp;
|
|
87
|
+
export type LinkTarget = {
|
|
88
|
+
/**
|
|
89
|
+
* the provider id it names, or null for the
|
|
90
|
+
* linking doc's own provider
|
|
91
|
+
*/
|
|
92
|
+
provider: string | null;
|
|
93
|
+
kind: string;
|
|
94
|
+
name: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The doc a link opens, as a docs read returns it.
|
|
98
|
+
*/
|
|
99
|
+
export type DocLink = {
|
|
100
|
+
/**
|
|
101
|
+
* the target as written: `[<provider>:]<kind>:<name>`
|
|
102
|
+
*/
|
|
103
|
+
target: string;
|
|
104
|
+
/**
|
|
105
|
+
* the doc's identity (a DocId)
|
|
106
|
+
*/
|
|
107
|
+
id: string;
|
|
108
|
+
/**
|
|
109
|
+
* what `astryx docs <route>` opens
|
|
110
|
+
*/
|
|
111
|
+
route: string;
|
|
112
|
+
title: string;
|
|
113
|
+
summary: string;
|
|
114
|
+
/**
|
|
115
|
+
* the command that opens it, `astryx docs <route>`
|
|
116
|
+
*/
|
|
117
|
+
command: string;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Finds the doc a target names, or says why none matches.
|
|
121
|
+
*/
|
|
122
|
+
export type LinkResolver = (target: string) => Promise<DocLink | {
|
|
123
|
+
problem: string;
|
|
124
|
+
}>;
|
|
125
|
+
export type LinkProblem = {
|
|
126
|
+
/**
|
|
127
|
+
* the target as written
|
|
128
|
+
*/
|
|
129
|
+
target: string;
|
|
130
|
+
message: string;
|
|
131
|
+
/**
|
|
132
|
+
* the key of the section the link sits in
|
|
133
|
+
*/
|
|
134
|
+
section?: string | undefined;
|
|
135
|
+
};
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Links between docs, named by doc identity (spec:AST-047 FR9).
|
|
5
|
+
*
|
|
6
|
+
* @input A link target, `[<provider>:]<kind>:<name>`, written as a `reference`
|
|
7
|
+
* block, in a `workflow` step's `references`, or inline in text as
|
|
8
|
+
* `{@link <target>}`; and a resolver that finds the doc a target names.
|
|
9
|
+
* @output The same content with every link resolved: an inline link becomes
|
|
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.
|
|
13
|
+
* @position Pure. The docs adapter owns the resolver (the project's docs tree
|
|
14
|
+
* and topic catalog) and applies this to every read and every doctor check.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The kinds a link can name: every authored doc kind. */
|
|
18
|
+
export const LINK_KINDS = new Set([
|
|
19
|
+
'generic',
|
|
20
|
+
'command',
|
|
21
|
+
'function',
|
|
22
|
+
'schema',
|
|
23
|
+
'enum',
|
|
24
|
+
'namespace',
|
|
25
|
+
'component',
|
|
26
|
+
'page',
|
|
27
|
+
'block',
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
/** An inline link in text: `{@link <target>}`. */
|
|
31
|
+
export const INLINE_LINK = /\{@link\s+([^{}]+?)\s*\}/g;
|
|
32
|
+
|
|
33
|
+
/** Code spans in text, which show link syntax as written. */
|
|
34
|
+
const CODE_SPAN = /(`[^`]*`)/;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {object} LinkTarget
|
|
38
|
+
* @property {string | null} provider the provider id it names, or null for the
|
|
39
|
+
* linking doc's own provider
|
|
40
|
+
* @property {string} kind
|
|
41
|
+
* @property {string} name
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The doc a link opens, as a docs read returns it.
|
|
46
|
+
* @typedef {object} DocLink
|
|
47
|
+
* @property {string} target the target as written: `[<provider>:]<kind>:<name>`
|
|
48
|
+
* @property {string} id the doc's identity (a DocId)
|
|
49
|
+
* @property {string} route what `astryx docs <route>` opens
|
|
50
|
+
* @property {string} title
|
|
51
|
+
* @property {string} summary
|
|
52
|
+
* @property {string} command the command that opens it, `astryx docs <route>`
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Finds the doc a target names, or says why none matches.
|
|
57
|
+
* @typedef {(target: string) => Promise<DocLink | {problem: string}>} LinkResolver
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {object} LinkProblem
|
|
62
|
+
* @property {string} target the target as written
|
|
63
|
+
* @property {string} message
|
|
64
|
+
* @property {string} [section] the key of the section the link sits in
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Parse `[<provider>:]<kind>:<name>`. A name may hold spaces
|
|
69
|
+
* (`command:theme build`); no part holds a colon.
|
|
70
|
+
* @param {unknown} target
|
|
71
|
+
* @returns {LinkTarget | {error: string}}
|
|
72
|
+
*/
|
|
73
|
+
export function parseLinkTarget(target) {
|
|
74
|
+
if (typeof target !== 'string' || target.trim() === '') {
|
|
75
|
+
return {
|
|
76
|
+
error:
|
|
77
|
+
'a link target is a non-empty string: `[<provider>:]<kind>:<name>`',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const parts = target.trim().split(':');
|
|
81
|
+
if (parts.length < 2 || parts.length > 3 || parts.some(p => p.trim() === '')) {
|
|
82
|
+
return {error: `"${target}" is not \`[<provider>:]<kind>:<name>\``};
|
|
83
|
+
}
|
|
84
|
+
const provider = parts.length === 3 ? parts[0].trim() : null;
|
|
85
|
+
const kind = parts[parts.length - 2].trim();
|
|
86
|
+
const name = parts[parts.length - 1].trim();
|
|
87
|
+
if (!LINK_KINDS.has(kind)) {
|
|
88
|
+
return {
|
|
89
|
+
error: `"${target}" names the kind "${kind}"; a doc kind is one of ${[
|
|
90
|
+
...LINK_KINDS,
|
|
91
|
+
].join(', ')}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {provider, kind, name};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Text with each inline link replaced by its name, for indexes that must not
|
|
99
|
+
* read the link syntax as words.
|
|
100
|
+
* @param {string} text
|
|
101
|
+
* @returns {string}
|
|
102
|
+
*/
|
|
103
|
+
export function unlinkText(text) {
|
|
104
|
+
return text
|
|
105
|
+
.split(CODE_SPAN)
|
|
106
|
+
.map(part =>
|
|
107
|
+
part.startsWith('`')
|
|
108
|
+
? part
|
|
109
|
+
: part.replace(INLINE_LINK, (_, target) => {
|
|
110
|
+
const parsed = parseLinkTarget(target);
|
|
111
|
+
return 'error' in parsed ? target : parsed.name;
|
|
112
|
+
}),
|
|
113
|
+
)
|
|
114
|
+
.join('');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Resolve every link in a list of content blocks, in order.
|
|
119
|
+
* @param {any[]} blocks
|
|
120
|
+
* @param {LinkResolver} resolve
|
|
121
|
+
* @param {{section?: string}} [at]
|
|
122
|
+
* @returns {Promise<{content: any[], problems: LinkProblem[]}>}
|
|
123
|
+
*/
|
|
124
|
+
export async function linkBlocks(blocks, resolve, at = {}) {
|
|
125
|
+
/** @type {LinkProblem[]} */
|
|
126
|
+
const problems = [];
|
|
127
|
+
const where = at.section ? {section: at.section} : {};
|
|
128
|
+
/**
|
|
129
|
+
* @param {string} target
|
|
130
|
+
* @returns {Promise<DocLink | null>}
|
|
131
|
+
*/
|
|
132
|
+
const find = async target => {
|
|
133
|
+
const found = await resolve(target);
|
|
134
|
+
if ('problem' in found) {
|
|
135
|
+
problems.push({target, message: found.problem, ...where});
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return found;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* @param {unknown} text
|
|
142
|
+
* @returns {Promise<any>}
|
|
143
|
+
*/
|
|
144
|
+
const linkText = async text => {
|
|
145
|
+
if (typeof text !== 'string' || !text.includes('{@link')) return text;
|
|
146
|
+
let out = '';
|
|
147
|
+
// A link written inside code ticks is shown as written: it documents the
|
|
148
|
+
// syntax, it does not link.
|
|
149
|
+
for (const part of text.split(CODE_SPAN)) {
|
|
150
|
+
if (part.startsWith('`')) {
|
|
151
|
+
out += part;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
let last = 0;
|
|
155
|
+
for (const match of part.matchAll(INLINE_LINK)) {
|
|
156
|
+
const link = await find(match[1]);
|
|
157
|
+
const at = /** @type {number} */ (match.index);
|
|
158
|
+
out += part.slice(last, at);
|
|
159
|
+
// A link that names no doc prints as written: text that was never
|
|
160
|
+
// meant as a link reads the way it did, and doctor names the problem.
|
|
161
|
+
out += link ? `\`${link.command}\`` : match[0];
|
|
162
|
+
last = at + match[0].length;
|
|
163
|
+
}
|
|
164
|
+
out += part.slice(last);
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* @param {unknown[]} values
|
|
170
|
+
* @returns {Promise<any[]>}
|
|
171
|
+
*/
|
|
172
|
+
const linkAll = async values => {
|
|
173
|
+
const out = [];
|
|
174
|
+
for (const value of values) out.push(await linkText(value));
|
|
175
|
+
return out;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const content = [];
|
|
179
|
+
for (const block of blocks ?? []) {
|
|
180
|
+
switch (block?.type) {
|
|
181
|
+
case 'prose':
|
|
182
|
+
case 'heading':
|
|
183
|
+
content.push({...block, text: await linkText(block.text)});
|
|
184
|
+
break;
|
|
185
|
+
case 'list':
|
|
186
|
+
content.push({...block, items: await linkAll(block.items ?? [])});
|
|
187
|
+
break;
|
|
188
|
+
case 'table': {
|
|
189
|
+
const rows = [];
|
|
190
|
+
for (const row of block.rows ?? []) rows.push(await linkAll(row));
|
|
191
|
+
content.push({
|
|
192
|
+
...block,
|
|
193
|
+
headers: await linkAll(block.headers ?? []),
|
|
194
|
+
rows,
|
|
195
|
+
});
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
case 'reference':
|
|
199
|
+
content.push({...block, link: await find(block.target)});
|
|
200
|
+
break;
|
|
201
|
+
case 'workflow': {
|
|
202
|
+
const steps = [];
|
|
203
|
+
for (const step of block.steps ?? []) {
|
|
204
|
+
/** @type {any} */
|
|
205
|
+
const linked = {...step};
|
|
206
|
+
if (step.description != null) {
|
|
207
|
+
linked.description = await linkText(step.description);
|
|
208
|
+
}
|
|
209
|
+
if (Array.isArray(step.references)) {
|
|
210
|
+
const links = [];
|
|
211
|
+
for (const target of step.references) links.push(await find(target));
|
|
212
|
+
linked.links = links;
|
|
213
|
+
}
|
|
214
|
+
steps.push(linked);
|
|
215
|
+
}
|
|
216
|
+
content.push({...block, steps});
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case 'collection':
|
|
220
|
+
problems.push({
|
|
221
|
+
target: `collection:${block.source?.slot ?? ''}`,
|
|
222
|
+
message:
|
|
223
|
+
'a collection block is not rendered yet; link each doc with a reference block instead',
|
|
224
|
+
...where,
|
|
225
|
+
});
|
|
226
|
+
content.push(block);
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
content.push(block);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return {content, problems};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Resolve every link in a topic's sections.
|
|
237
|
+
* @param {any[]} sections
|
|
238
|
+
* @param {LinkResolver} resolve
|
|
239
|
+
* @returns {Promise<{sections: any[], problems: LinkProblem[]}>}
|
|
240
|
+
*/
|
|
241
|
+
export async function linkSections(sections, resolve) {
|
|
242
|
+
/** @type {LinkProblem[]} */
|
|
243
|
+
const problems = [];
|
|
244
|
+
const out = [];
|
|
245
|
+
for (const section of sections ?? []) {
|
|
246
|
+
const linked = await linkBlocks(section.content, resolve, {
|
|
247
|
+
section: section.id ?? section.title,
|
|
248
|
+
});
|
|
249
|
+
problems.push(...linked.problems);
|
|
250
|
+
out.push({...section, content: linked.content});
|
|
251
|
+
}
|
|
252
|
+
return {sections: out, problems};
|
|
253
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Links between docs (spec:AST-047 FR9): the target grammar, and how a
|
|
5
|
+
* list of blocks comes back with every link resolved or named as a problem.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {describe, expect, it} from 'vitest';
|
|
9
|
+
import {
|
|
10
|
+
linkBlocks,
|
|
11
|
+
linkSections,
|
|
12
|
+
parseLinkTarget,
|
|
13
|
+
unlinkText,
|
|
14
|
+
} from './links.mjs';
|
|
15
|
+
|
|
16
|
+
/** A resolver over two docs, the second from another provider. */
|
|
17
|
+
const resolve = async (/** @type {string} */ target) => {
|
|
18
|
+
const docs = {
|
|
19
|
+
'command:doctor': {route: 'cli/commands/doctor', title: 'astryx doctor'},
|
|
20
|
+
'@acme/kit:generic:setup': {route: 'acme/setup', title: 'Set up Acme'},
|
|
21
|
+
};
|
|
22
|
+
const doc = /** @type {any} */ (docs)[target];
|
|
23
|
+
return doc
|
|
24
|
+
? {
|
|
25
|
+
target,
|
|
26
|
+
id: `id:${target}`,
|
|
27
|
+
route: doc.route,
|
|
28
|
+
title: doc.title,
|
|
29
|
+
summary: `About ${doc.title}.`,
|
|
30
|
+
command: `astryx docs ${doc.route}`,
|
|
31
|
+
}
|
|
32
|
+
: {problem: `"${target}" names no doc`};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe('parseLinkTarget', () => {
|
|
36
|
+
it('reads a doc of the same provider, or of a named one', () => {
|
|
37
|
+
expect(parseLinkTarget('command:theme build')).toEqual({
|
|
38
|
+
provider: null,
|
|
39
|
+
kind: 'command',
|
|
40
|
+
name: 'theme build',
|
|
41
|
+
});
|
|
42
|
+
expect(parseLinkTarget('@astryxdesign/cli:function:search')).toEqual({
|
|
43
|
+
provider: '@astryxdesign/cli',
|
|
44
|
+
kind: 'function',
|
|
45
|
+
name: 'search',
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('refuses a target that is not `[<provider>:]<kind>:<name>`', () => {
|
|
50
|
+
for (const bad of ['', 'search', 'a:b:c:d', 'command:', 'widget:x']) {
|
|
51
|
+
expect(parseLinkTarget(bad)).toHaveProperty('error');
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('linkBlocks', () => {
|
|
57
|
+
it('reads an inline link as the command that opens its doc', async () => {
|
|
58
|
+
const {content, problems} = await linkBlocks(
|
|
59
|
+
[
|
|
60
|
+
{type: 'prose', text: 'Check it with {@link command:doctor}.'},
|
|
61
|
+
{type: 'list', style: 'unordered', items: ['See {@link @acme/kit:generic:setup}']},
|
|
62
|
+
{type: 'table', headers: ['Doc'], rows: [['{@link command:doctor}']]},
|
|
63
|
+
{type: 'code', lang: 'js', code: '{@link command:doctor}'},
|
|
64
|
+
],
|
|
65
|
+
resolve,
|
|
66
|
+
);
|
|
67
|
+
expect(problems).toEqual([]);
|
|
68
|
+
expect(content[0].text).toBe('Check it with `astryx docs cli/commands/doctor`.');
|
|
69
|
+
expect(content[1].items).toEqual(['See `astryx docs acme/setup`']);
|
|
70
|
+
expect(content[2].rows).toEqual([['`astryx docs cli/commands/doctor`']]);
|
|
71
|
+
// Code is an example: it is shown as written.
|
|
72
|
+
expect(content[3].code).toBe('{@link command:doctor}');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('shows a link written in code ticks as written', async () => {
|
|
76
|
+
const {content, problems} = await linkBlocks(
|
|
77
|
+
[{type: 'prose', text: 'Write `{@link <target>}` to link; {@link command:doctor} checks it.'}],
|
|
78
|
+
resolve,
|
|
79
|
+
);
|
|
80
|
+
expect(problems).toEqual([]);
|
|
81
|
+
expect(content[0].text).toBe(
|
|
82
|
+
'Write `{@link <target>}` to link; `astryx docs cli/commands/doctor` checks it.',
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('gives a reference block and each workflow step the doc they name', async () => {
|
|
87
|
+
const {content, problems} = await linkBlocks(
|
|
88
|
+
[
|
|
89
|
+
{type: 'reference', target: 'command:doctor'},
|
|
90
|
+
{
|
|
91
|
+
type: 'workflow',
|
|
92
|
+
steps: [{title: 'Check', references: ['command:doctor']}],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
resolve,
|
|
96
|
+
);
|
|
97
|
+
expect(problems).toEqual([]);
|
|
98
|
+
expect(content[0].link).toMatchObject({
|
|
99
|
+
route: 'cli/commands/doctor',
|
|
100
|
+
command: 'astryx docs cli/commands/doctor',
|
|
101
|
+
title: 'astryx doctor',
|
|
102
|
+
});
|
|
103
|
+
expect(content[1].steps[0].links[0].command).toBe(
|
|
104
|
+
'astryx docs cli/commands/doctor',
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('names every link that finds no doc, and never guesses', async () => {
|
|
109
|
+
const {content, problems} = await linkSections(
|
|
110
|
+
[
|
|
111
|
+
{
|
|
112
|
+
id: 'one',
|
|
113
|
+
title: 'One',
|
|
114
|
+
content: [
|
|
115
|
+
{type: 'prose', text: 'See {@link command:nope}.'},
|
|
116
|
+
{type: 'reference', target: 'generic:gone'},
|
|
117
|
+
{type: 'collection', source: {slot: 'guides'}},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
resolve,
|
|
122
|
+
).then(({sections, problems}) => ({content: sections[0].content, problems}));
|
|
123
|
+
expect(content[0].text).toBe('See {@link command:nope}.');
|
|
124
|
+
expect(content[1].link).toBeNull();
|
|
125
|
+
expect(problems.map(p => [p.section, p.target])).toEqual([
|
|
126
|
+
['one', 'command:nope'],
|
|
127
|
+
['one', 'generic:gone'],
|
|
128
|
+
['one', 'collection:guides'],
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('unlinkText', () => {
|
|
134
|
+
it('keeps the name of each link, for an index', () => {
|
|
135
|
+
expect(unlinkText('Run {@link command:theme build} or {@link x}.')).toBe(
|
|
136
|
+
'Run theme build or x.',
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -386,7 +386,10 @@ describe('parseCompiledDocNode and parseCompiledDocsBundle', () => {
|
|
|
386
386
|
it('accepts a node of every kind and a bundle, as given', () => {
|
|
387
387
|
const value = bundle();
|
|
388
388
|
expect(parseCompiledDocsBundle(value)).toBe(value);
|
|
389
|
-
expect(COMPILED_DOC_KINDS).toHaveLength(
|
|
389
|
+
expect(COMPILED_DOC_KINDS).toHaveLength(10);
|
|
390
|
+
// A namespace doc, which the docs tree reads, lowers to a node too.
|
|
391
|
+
const namespace = {...node(), kind: 'namespace'};
|
|
392
|
+
expect(parseCompiledDocNode(namespace)).toBe(namespace);
|
|
390
393
|
});
|
|
391
394
|
|
|
392
395
|
it('names schema skew with its own diagnostic, before anything else', () => {
|
|
@@ -413,7 +416,7 @@ describe('parseCompiledDocNode and parseCompiledDocsBundle', () => {
|
|
|
413
416
|
],
|
|
414
417
|
[
|
|
415
418
|
'an unknown kind',
|
|
416
|
-
(/** @type {any} */ n) => (n.kind = '
|
|
419
|
+
(/** @type {any} */ n) => (n.kind = 'workflow'),
|
|
417
420
|
/not a compiled doc kind/,
|
|
418
421
|
],
|
|
419
422
|
[
|
|
@@ -73,11 +73,12 @@ export const DOC_EXPORTS: Readonly<{
|
|
|
73
73
|
hooks: string[];
|
|
74
74
|
templates: string[];
|
|
75
75
|
'self-docs': string[];
|
|
76
|
+
tree: string[];
|
|
76
77
|
}>;
|
|
77
78
|
/** The localized overlays a docs read can apply. */
|
|
78
79
|
export const OVERLAY_LANGUAGES: string[];
|
|
79
80
|
export type ReadOptions = {
|
|
80
|
-
root: "components" | "hooks" | "templates" | "themes" | "self-docs";
|
|
81
|
+
root: "components" | "hooks" | "templates" | "themes" | "self-docs" | "tree";
|
|
81
82
|
/**
|
|
82
83
|
* overlay language; null reads the authored
|
|
83
84
|
* text
|
|
@@ -101,7 +102,7 @@ export type ReadOptions = {
|
|
|
101
102
|
* how to import the module (default
|
|
102
103
|
* `user`)
|
|
103
104
|
*/
|
|
104
|
-
loader?: "template" | "
|
|
105
|
+
loader?: "template" | "native" | "user" | undefined;
|
|
105
106
|
/**
|
|
106
107
|
* which exports name the doc, in
|
|
107
108
|
* precedence order, for a reader that has always read a narrower set than its
|
|
@@ -45,6 +45,8 @@ export const DOC_EXPORTS = Object.freeze({
|
|
|
45
45
|
hooks: ['default', 'docs'],
|
|
46
46
|
templates: ['default', 'doc'],
|
|
47
47
|
'self-docs': ['doc', 'docs', 'default'],
|
|
48
|
+
// The docs tree's own files: namespace docs and the guides it places.
|
|
49
|
+
tree: ['docs', 'default'],
|
|
48
50
|
});
|
|
49
51
|
|
|
50
52
|
/** How a reader imports a doc module. */
|
|
@@ -59,7 +61,7 @@ const LOADERS = Object.freeze({
|
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
63
|
* @typedef {object} ReadOptions
|
|
62
|
-
* @property {'components' | 'hooks' | 'templates' | 'themes' | 'self-docs'} root
|
|
64
|
+
* @property {'components' | 'hooks' | 'templates' | 'themes' | 'self-docs' | 'tree'} root
|
|
63
65
|
* @property {string | null} [lang] overlay language; null reads the authored
|
|
64
66
|
* text
|
|
65
67
|
* @property {string} [label] how a parse error names the file (default: its
|
|
@@ -307,14 +309,17 @@ export async function loadTopicInput(entry, lang) {
|
|
|
307
309
|
extensions.push({
|
|
308
310
|
...(await loadTopicFile(extension.path, lang)),
|
|
309
311
|
provider: extension.package,
|
|
312
|
+
providerId: extension.providerId ?? extension.package,
|
|
310
313
|
});
|
|
311
314
|
}
|
|
312
315
|
return {
|
|
313
316
|
id: entry.name,
|
|
314
317
|
provider: entry.package,
|
|
318
|
+
providerId: entry.providerId ?? entry.package,
|
|
315
319
|
replaces: entry.replaces ?? null,
|
|
316
320
|
lang,
|
|
317
321
|
base: await loadTopicFile(entry.path, lang),
|
|
318
322
|
extensions,
|
|
323
|
+
...(entry.tree === true ? {tree: true} : {}),
|
|
319
324
|
};
|
|
320
325
|
}
|