@astryxdesign/cli 0.7.2-canary.e26723d → 0.7.2-canary.e4bdd70
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 +9 -8
- package/api/docs/_adapter.d.mts +11 -0
- package/api/docs/_adapter.mjs +37 -0
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/add-contribution.mjs +1 -1
- package/api/integration/add-contribution.test.mjs +4 -2
- package/api/integration/check/check.d.mts +96 -0
- package/api/integration/check/check.mjs +357 -0
- package/api/integration/check/check.test.mjs +489 -0
- package/api/integration/integration-check.type.d.mts +118 -0
- package/api/integration/integration-check.type.mjs +84 -0
- package/api/integration/integrationCheck.doc.d.mts +10 -0
- package/api/integration/integrationCheck.doc.mjs +73 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +19 -4
- package/api/integration/validate-integration.mjs +8 -0
- package/api/integration/validate-integration.type.d.mts +8 -0
- package/api/integration/validate-integration.type.mjs +12 -1
- package/api/integration/validateIntegration.doc.mjs +17 -3
- package/api/search/search.d.mts +13 -6
- package/api/search/search.domain-priority.test.mjs +93 -18
- package/api/search/search.integration-check.test.mjs +24 -0
- package/api/search/search.mjs +33 -9
- package/api/theme/build/build.family.test.mjs +54 -6
- package/api/theme/build/build.mjs +110 -13
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/tree/add-a-component.doc.mjs +1 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
- package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
- package/assets/docs/tree/block-template.doc.mjs +8 -20
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +51 -0
- package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
- package/assets/docs/tree/checks.doc.mjs +21 -13
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +3 -5
- package/assets/docs/tree/component-imports.doc.mjs +2 -2
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
- package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
- package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
- package/assets/docs/tree/docs.doc.mjs +3 -3
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
- package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
- package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
- package/assets/docs/tree/integrations.doc.mjs +8 -0
- package/assets/docs/tree/links.doc.mjs +5 -4
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +4 -8
- package/assets/docs/tree/publishing.doc.mjs +1 -1
- package/assets/docs/tree/quick-start.doc.mjs +37 -21
- package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
- package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
- package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
- package/assets/docs/tree/single-component.doc.mjs +12 -4
- package/assets/docs/tree/start-a-template.doc.mjs +3 -3
- package/assets/docs/tree/subcomponent.doc.mjs +6 -6
- package/assets/docs/tree/template-assets.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +2 -2
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
- package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
- package/assets/docs/tree/upgrading.doc.mjs +3 -3
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +6 -6
- package/assets/docs/tree/write-the-template-file.doc.mjs +2 -2
- package/authoring/codemod/codemod.doc.mjs +7 -3
- package/authoring/config/config.doc.mjs +9 -6
- package/authoring/config/type.ts +4 -2
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
- package/authoring/doctypes/command/command.doc.mjs +14 -12
- package/authoring/doctypes/component/component.doc.mjs +28 -25
- package/authoring/doctypes/component/type.ts +7 -5
- package/authoring/doctypes/enum/enum.doc.mjs +7 -4
- package/authoring/doctypes/function/function.doc.mjs +9 -8
- package/authoring/doctypes/hook/hook.doc.mjs +5 -4
- package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
- package/authoring/doctypes/reference/reference.doc.mjs +11 -10
- package/authoring/doctypes/schema/schema.doc.mjs +9 -9
- package/authoring/doctypes/template/integration-template.doc.mjs +1 -1
- package/authoring/doctypes/template/template.doc.mjs +3 -3
- package/authoring/doctypes/theme/theme.doc.mjs +2 -2
- package/authoring/gap-report/gap-report.doc.mjs +2 -2
- package/authoring/identity/identity.doc.mjs +3 -3
- package/authoring/integration/integration.doc.mjs +4 -3
- package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
- package/clients/cli/commands/doctor-integration-components.doc.mjs +8 -3
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +11 -2
- package/clients/cli/commands/doctor-integration.test.mjs +447 -2
- package/clients/cli/commands/doctor.mjs +116 -0
- package/clients/cli/commands/integration-check.doc.mjs +85 -0
- package/clients/cli/commands/integration-check.test.mjs +267 -0
- package/clients/cli/commands/integration.doc.mjs +6 -2
- package/clients/cli/commands/integration.mjs +107 -1
- package/clients/cli/commands/text-json-parity.test.mjs +5 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/index.mjs +1 -0
- package/foundation/discovery/authoring-self-docs.mjs +1 -1
- package/foundation/discovery/doc-types.mjs +2 -2
- package/foundation/discovery/integration-doc-files.d.mts +22 -0
- package/foundation/discovery/integration-doc-files.mjs +231 -0
- package/foundation/discovery/integration-doc-files.test.mjs +246 -0
- package/foundation/discovery/prop-drift.d.mts +61 -3
- package/foundation/discovery/prop-drift.mjs +559 -61
- package/foundation/discovery/prop-drift.test.mjs +1032 -10
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -0
- package/foundation/response/response-types.doc.mjs +7 -2
- package/package.json +9 -9
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The doc files an integration package ships, by root: every doc its
|
|
5
|
+
* roots hold, so the doc type check covers each one an agent can open.
|
|
6
|
+
*
|
|
7
|
+
* Each root's reader names the docs it serves, with the kind it reads each
|
|
8
|
+
* as:
|
|
9
|
+
* - components: the doc each component discovery records;
|
|
10
|
+
* - templates: the doc of each template template discovery serves;
|
|
11
|
+
* - docs: the file of each topic, namespace and placed guide docs discovery
|
|
12
|
+
* serves, and each topic's and guide's `zh` and `dense` overlay that a docs
|
|
13
|
+
* read applies;
|
|
14
|
+
* - themes: each theme's descriptor, as theme discovery resolves it. A themes
|
|
15
|
+
* root that discovery cannot read serves no theme, and is listed with the
|
|
16
|
+
* reason.
|
|
17
|
+
* A doc no reader serves still ships: a `hidden` one, a second doc for one
|
|
18
|
+
* name, an overlay without its topic. It goes to its root's kind. A test
|
|
19
|
+
* fixture does not ship as a doc, and is only counted: a doc under
|
|
20
|
+
* `__tests__` in the components or docs root, which those readers skip.
|
|
21
|
+
* A file two roots hold goes to the deepest.
|
|
22
|
+
*
|
|
23
|
+
* @input A loaded integration and its resolved roots.
|
|
24
|
+
* @output DocFile entries for checkDocTypes, each with the root it belongs to,
|
|
25
|
+
* the roots a reader could not read, and how many test fixtures it left
|
|
26
|
+
* out.
|
|
27
|
+
* @position Read by `astryx doctor integration validate` before it checks
|
|
28
|
+
* each doc against its authoring type.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import * as fs from 'node:fs';
|
|
32
|
+
import * as path from 'node:path';
|
|
33
|
+
import {OVERLAY_LANGUAGES, overlayPath} from '../doc-compiler/read.mjs';
|
|
34
|
+
import {discoverIntegrationComponents} from './component-discovery.mjs';
|
|
35
|
+
import {discoverIntegrationDocs} from './docs-discovery.mjs';
|
|
36
|
+
import {discoverIntegrationTemplatesForOne} from './template-adapter.mjs';
|
|
37
|
+
import {discoverThemeDirectory} from './theme-discovery.mjs';
|
|
38
|
+
import {rootProblem} from '../integrations/validate-contributions.mjs';
|
|
39
|
+
|
|
40
|
+
/** @typedef {import('./doc-types.mjs').DocFile} DocFile */
|
|
41
|
+
/** @typedef {import('./doc-types.mjs').DocRoot} DocRoot */
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Every doc file an integration's roots hold, each assigned to the deepest
|
|
45
|
+
* root that holds it, each root a reader could not read, and how many test
|
|
46
|
+
* fixtures no reader serves.
|
|
47
|
+
* @param {any} integration a loaded integration
|
|
48
|
+
* @returns {Promise<{files: DocFile[], unread: Array<{path: string, reason: string}>, fixtures: number}>}
|
|
49
|
+
*/
|
|
50
|
+
export async function integrationDocFiles(integration) {
|
|
51
|
+
const {components, templates, docs, themes} = integration ?? {};
|
|
52
|
+
/** @type {Array<[DocRoot, string, string[]]>} */
|
|
53
|
+
const read = [];
|
|
54
|
+
/** @type {Array<{path: string, reason: string}>} */
|
|
55
|
+
const unread = [];
|
|
56
|
+
// A root `validate` already reports (missing, a file, unreadable) is left
|
|
57
|
+
// to that issue. A reader that fails inside a root, such as on a folder it
|
|
58
|
+
// cannot read, leaves the root listed with the reason.
|
|
59
|
+
/** @type {(root: string | undefined, label: string, files: () => Promise<Array<[DocRoot, string[]]>>) => Promise<void>} */
|
|
60
|
+
const take = async (root, label, files) => {
|
|
61
|
+
if (!root || rootProblem(root)) return;
|
|
62
|
+
try {
|
|
63
|
+
for (const [kind, list] of await files()) read.push([kind, root, list]);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
unread.push({
|
|
66
|
+
path: root,
|
|
67
|
+
reason: `the ${label} root does not load, so no doc in it was checked: ${err instanceof Error ? err.message : String(err)}`,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
await take(components, 'components', async () => [
|
|
72
|
+
[
|
|
73
|
+
'components',
|
|
74
|
+
discoverIntegrationComponents(integration).map(c => c.docPath),
|
|
75
|
+
],
|
|
76
|
+
]);
|
|
77
|
+
await take(templates, 'templates', async () => [
|
|
78
|
+
[
|
|
79
|
+
'templates',
|
|
80
|
+
(await discoverIntegrationTemplatesForOne(integration)).templates.map(
|
|
81
|
+
t => t.docPath,
|
|
82
|
+
),
|
|
83
|
+
],
|
|
84
|
+
]);
|
|
85
|
+
await take(docs, 'docs', async () => {
|
|
86
|
+
const found = await discoverIntegrationDocs(integration);
|
|
87
|
+
// Topics and placed guides are read with their overlays; a namespace
|
|
88
|
+
// names its file `<package name>/<path in the root>`.
|
|
89
|
+
const withOverlays = [
|
|
90
|
+
...found.records.map(record => record.path),
|
|
91
|
+
...found.guides.map(guide => guide.ref.topicFile),
|
|
92
|
+
];
|
|
93
|
+
const prefix = `${integration.name}/`;
|
|
94
|
+
const namespaces = found.namespaces.map(entry =>
|
|
95
|
+
path.join(
|
|
96
|
+
/** @type {string} */ (docs),
|
|
97
|
+
...(entry.source.startsWith(prefix)
|
|
98
|
+
? entry.source.slice(prefix.length)
|
|
99
|
+
: entry.source
|
|
100
|
+
).split('/'),
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
return [
|
|
104
|
+
['docs', [...withOverlays, ...namespaces]],
|
|
105
|
+
[
|
|
106
|
+
'docs-overlay',
|
|
107
|
+
withOverlays.flatMap(file =>
|
|
108
|
+
OVERLAY_LANGUAGES.map(lang => overlayPath(file, lang)).filter(
|
|
109
|
+
overlay => fs.existsSync(overlay),
|
|
110
|
+
),
|
|
111
|
+
),
|
|
112
|
+
],
|
|
113
|
+
];
|
|
114
|
+
});
|
|
115
|
+
await take(themes, 'themes', async () => [
|
|
116
|
+
[
|
|
117
|
+
'themes',
|
|
118
|
+
discoverThemeDirectory(
|
|
119
|
+
/** @type {string} */ (themes),
|
|
120
|
+
integration?.name ?? 'the package',
|
|
121
|
+
).map(theme => theme.docPath),
|
|
122
|
+
],
|
|
123
|
+
]);
|
|
124
|
+
/** @type {Map<string, {root: DocRoot, dir: string}>} */
|
|
125
|
+
const owners = new Map();
|
|
126
|
+
/** @type {(table: Map<string, {root: DocRoot, dir: string}>, root: DocRoot, dir: string, file: string) => void} */
|
|
127
|
+
const own = (table, root, dir, file) => {
|
|
128
|
+
const owner = table.get(file);
|
|
129
|
+
if (!owner || dir.length > owner.dir.length) table.set(file, {root, dir});
|
|
130
|
+
};
|
|
131
|
+
for (const [root, dir, files] of read) {
|
|
132
|
+
for (const file of files) own(owners, root, dir, file);
|
|
133
|
+
}
|
|
134
|
+
// The docs no reader serves, in each root a reader could read.
|
|
135
|
+
/** @type {Map<string, {root: DocRoot, dir: string}>} */
|
|
136
|
+
const shipped = new Map();
|
|
137
|
+
const readable = new Set(read.map(([, dir]) => dir));
|
|
138
|
+
for (const [
|
|
139
|
+
kind,
|
|
140
|
+
dir,
|
|
141
|
+
] of /** @type {Array<[DocRoot, string | undefined]>} */ ([
|
|
142
|
+
['components', components],
|
|
143
|
+
['templates', templates],
|
|
144
|
+
['docs', docs],
|
|
145
|
+
['themes', themes],
|
|
146
|
+
])) {
|
|
147
|
+
if (!dir || !readable.has(dir)) continue;
|
|
148
|
+
for (const file of docFilesUnder(dir)) {
|
|
149
|
+
const overlay = OVERLAY_LANGUAGES.some(lang =>
|
|
150
|
+
file.endsWith(`.doc.${lang}.mjs`),
|
|
151
|
+
);
|
|
152
|
+
if (overlay && kind !== 'docs') continue;
|
|
153
|
+
own(shipped, overlay ? 'docs-overlay' : kind, dir, file);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
let fixtures = 0;
|
|
157
|
+
for (const [file, owner] of shipped) {
|
|
158
|
+
if (owners.has(file)) continue;
|
|
159
|
+
if (isFixture(path.relative(owner.dir, file), owner.root)) fixtures++;
|
|
160
|
+
else owners.set(file, owner);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
files: [...owners]
|
|
164
|
+
.map(([file, {root}]) => ({path: file, root}))
|
|
165
|
+
.sort((a, b) => a.path.localeCompare(b.path)),
|
|
166
|
+
unread,
|
|
167
|
+
fixtures,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Whether a doc file is a test fixture: under `__tests__` in a root whose
|
|
173
|
+
* reader skips that folder (components and docs). The template reader reads
|
|
174
|
+
* it, so a template doc there is the package's like any other.
|
|
175
|
+
* @param {string} file its path relative to its root
|
|
176
|
+
* @param {DocRoot} root
|
|
177
|
+
*/
|
|
178
|
+
function isFixture(file, root) {
|
|
179
|
+
return (
|
|
180
|
+
root !== 'templates' &&
|
|
181
|
+
root !== 'themes' &&
|
|
182
|
+
file.split(path.sep).includes('__tests__')
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Every doc file under a folder: a `.doc.ts`, `.doc.mjs` or `.doc.js` file,
|
|
188
|
+
* or a `zh` or `dense` overlay, through its folders and linked files, but not
|
|
189
|
+
* `node_modules`, `.git` or a linked folder.
|
|
190
|
+
* @param {string} dir
|
|
191
|
+
* @returns {string[]}
|
|
192
|
+
*/
|
|
193
|
+
function docFilesUnder(dir) {
|
|
194
|
+
/** @type {string[]} */
|
|
195
|
+
const found = [];
|
|
196
|
+
/** @type {(folder: string) => void} */
|
|
197
|
+
const walk = folder => {
|
|
198
|
+
/** @type {fs.Dirent[]} */
|
|
199
|
+
let entries;
|
|
200
|
+
try {
|
|
201
|
+
entries = fs.readdirSync(folder, {withFileTypes: true});
|
|
202
|
+
} catch {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
for (const entry of entries) {
|
|
206
|
+
if (entry.name === 'node_modules' || entry.name === '.git') continue;
|
|
207
|
+
const full = path.join(folder, entry.name);
|
|
208
|
+
if (entry.isDirectory()) {
|
|
209
|
+
walk(full);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (entry.isSymbolicLink()) {
|
|
213
|
+
try {
|
|
214
|
+
if (!fs.statSync(full).isFile()) continue;
|
|
215
|
+
} catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
} else if (!entry.isFile()) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (
|
|
222
|
+
/\.doc\.(ts|mjs|js)$/.test(entry.name) ||
|
|
223
|
+
OVERLAY_LANGUAGES.some(lang => entry.name.endsWith(`.doc.${lang}.mjs`))
|
|
224
|
+
) {
|
|
225
|
+
found.push(full);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
walk(dir);
|
|
230
|
+
return found;
|
|
231
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file integrationDocFiles(): exactly the docs each root's reader serves, a
|
|
5
|
+
* nested root's files given to that root, and a root its reader cannot read.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import * as os from 'node:os';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
12
|
+
import {discoverIntegrationComponents} from './component-discovery.mjs';
|
|
13
|
+
import {integrationDocFiles} from './integration-doc-files.mjs';
|
|
14
|
+
|
|
15
|
+
/** @type {string} */
|
|
16
|
+
let pkg;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
pkg = fs.realpathSync(
|
|
20
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-doc-files-')),
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
fs.rmSync(pkg, {recursive: true, force: true});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} rel
|
|
30
|
+
* @param {string} text
|
|
31
|
+
*/
|
|
32
|
+
function write(rel, text) {
|
|
33
|
+
const file = path.join(pkg, rel);
|
|
34
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
35
|
+
fs.writeFileSync(file, text);
|
|
36
|
+
return file;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @param {string} name */
|
|
40
|
+
const component = name =>
|
|
41
|
+
`export default {type: 'component', name: '${name}', displayName: '${name}', usage: {description: 'x'}, props: []};\n`;
|
|
42
|
+
/** @param {string} name */
|
|
43
|
+
const topic = name =>
|
|
44
|
+
`export default {type: 'generic', name: '${name}', title: 'T', description: 'D', sections: [{title: 'S', content: [{type: 'prose', text: 'x'}]}]};\n`;
|
|
45
|
+
/** @param {string} rel a template doc, with its same-stem source */
|
|
46
|
+
const template = rel => {
|
|
47
|
+
write(rel.replace(/\.doc\.mjs$/, '.tsx'), 'export default () => null;\n');
|
|
48
|
+
return write(
|
|
49
|
+
rel,
|
|
50
|
+
`export default {type: 'block', name: '${path.basename(rel, '.doc.mjs')}', description: 'D'};\n`,
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** @param {Awaited<ReturnType<typeof integrationDocFiles>>['files']} files */
|
|
55
|
+
const listed = files =>
|
|
56
|
+
files
|
|
57
|
+
.map(f => [path.relative(pkg, f.path).split(path.sep).join('/'), f.root])
|
|
58
|
+
.sort();
|
|
59
|
+
|
|
60
|
+
describe('integrationDocFiles', () => {
|
|
61
|
+
it('reads a fixture folder relative to its root, so a package under a `__tests__` folder is checked', async () => {
|
|
62
|
+
write(
|
|
63
|
+
'__tests__/acme/components/Hidden.doc.mjs',
|
|
64
|
+
`${component('Hidden')}\n hidden: true\n`,
|
|
65
|
+
);
|
|
66
|
+
write(
|
|
67
|
+
'__tests__/acme/components/__tests__/Tested.doc.mjs',
|
|
68
|
+
component('Tested'),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const {files, fixtures} = await integrationDocFiles({
|
|
72
|
+
name: '@acme/widgets',
|
|
73
|
+
components: path.join(pkg, '__tests__', 'acme', 'components'),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(listed(files)).toEqual([
|
|
77
|
+
['__tests__/acme/components/Hidden.doc.mjs', 'components'],
|
|
78
|
+
]);
|
|
79
|
+
expect(fixtures).toBe(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("gives a nested root's files to that root", async () => {
|
|
83
|
+
write('src/Badge.doc.mjs', component('Badge'));
|
|
84
|
+
write('src/docs/guide.doc.mjs', topic('guide'));
|
|
85
|
+
write('src/docs/guide.doc.zh.mjs', 'export const docsZh = {};\n');
|
|
86
|
+
template('templates/hero.doc.mjs');
|
|
87
|
+
|
|
88
|
+
const {files, unread} = await integrationDocFiles({
|
|
89
|
+
name: '@acme/widgets',
|
|
90
|
+
components: path.join(pkg, 'src'),
|
|
91
|
+
docs: path.join(pkg, 'src', 'docs'),
|
|
92
|
+
templates: path.join(pkg, 'templates'),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(unread).toEqual([]);
|
|
96
|
+
expect(listed(files)).toEqual([
|
|
97
|
+
['src/Badge.doc.mjs', 'components'],
|
|
98
|
+
['src/docs/guide.doc.mjs', 'docs'],
|
|
99
|
+
['src/docs/guide.doc.zh.mjs', 'docs-overlay'],
|
|
100
|
+
['templates/hero.doc.mjs', 'templates'],
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('takes every doc the roots hold, served or not, and counts a test fixture no reader serves', async () => {
|
|
105
|
+
write('components/__fixtures__/Fixture.doc.mjs', component('Fixture'));
|
|
106
|
+
write('components/.drafts/Draft.doc.mjs', component('Draft'));
|
|
107
|
+
write('components/__tests__/Tested.doc.mjs', component('Tested'));
|
|
108
|
+
write(
|
|
109
|
+
'components/Hidden.doc.mjs',
|
|
110
|
+
`${component('Hidden')}\n hidden: true\n`,
|
|
111
|
+
);
|
|
112
|
+
write('components/Twice.doc.mjs', component('Twice'));
|
|
113
|
+
write('components/again/Twice.doc.mjs', component('Twice'));
|
|
114
|
+
write('shared/Linked.doc.mjs', component('Linked'));
|
|
115
|
+
fs.symlinkSync(
|
|
116
|
+
path.join(pkg, 'shared', 'Linked.doc.mjs'),
|
|
117
|
+
path.join(pkg, 'components', 'Linked.doc.mjs'),
|
|
118
|
+
);
|
|
119
|
+
template('templates/__tests__/tested.doc.mjs');
|
|
120
|
+
write('templates/orphan.doc.mjs', "export default {type: 'block'};\n");
|
|
121
|
+
// The template reader reads `__fixtures__`: a template doc there without
|
|
122
|
+
// its source is the package's, so it is checked.
|
|
123
|
+
write(
|
|
124
|
+
'templates/__fixtures__/bad.doc.mjs',
|
|
125
|
+
"export default {type: 'block'};\n",
|
|
126
|
+
);
|
|
127
|
+
write('docs/__tests__/sample.doc.mjs', topic('sample'));
|
|
128
|
+
write('docs/.drafts/topic.doc.mjs', topic('topic'));
|
|
129
|
+
write('docs/.drafts/topic.doc.zh.mjs', 'export const docsZh = {};\n');
|
|
130
|
+
write('docs/copy.doc.mjs', topic('topic'));
|
|
131
|
+
write('docs/orphan.doc.dense.mjs', 'export const docsDense = {};\n');
|
|
132
|
+
write('themes/oceanTheme.doc.mjs', 'export default {};\n');
|
|
133
|
+
const integration = {
|
|
134
|
+
name: '@acme/widgets',
|
|
135
|
+
components: path.join(pkg, 'components'),
|
|
136
|
+
templates: path.join(pkg, 'templates'),
|
|
137
|
+
docs: path.join(pkg, 'docs'),
|
|
138
|
+
themes: path.join(pkg, 'themes'),
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const {files, unread, fixtures} = await integrationDocFiles(integration);
|
|
142
|
+
|
|
143
|
+
// Component discovery skips `__tests__` and a `hidden` doc, and serves the
|
|
144
|
+
// first doc of a name; a template without its source, a second topic of
|
|
145
|
+
// a name, and an overlay without its topic are not served either. All of
|
|
146
|
+
// them ship, so all are checked, but a test fixture no reader serves.
|
|
147
|
+
const served = discoverIntegrationComponents(integration).map(c =>
|
|
148
|
+
path.relative(pkg, c.docPath),
|
|
149
|
+
);
|
|
150
|
+
expect(served.filter(file => file.endsWith('Twice.doc.mjs'))).toHaveLength(
|
|
151
|
+
1,
|
|
152
|
+
);
|
|
153
|
+
expect(listed(files)).toEqual(
|
|
154
|
+
[
|
|
155
|
+
...served.map(file => [file, 'components']),
|
|
156
|
+
['components/Hidden.doc.mjs', 'components'],
|
|
157
|
+
['components/again/Twice.doc.mjs', 'components'],
|
|
158
|
+
['docs/.drafts/topic.doc.mjs', 'docs'],
|
|
159
|
+
['docs/.drafts/topic.doc.zh.mjs', 'docs-overlay'],
|
|
160
|
+
['docs/copy.doc.mjs', 'docs'],
|
|
161
|
+
['docs/orphan.doc.dense.mjs', 'docs-overlay'],
|
|
162
|
+
['templates/__fixtures__/bad.doc.mjs', 'templates'],
|
|
163
|
+
['templates/__tests__/tested.doc.mjs', 'templates'],
|
|
164
|
+
['templates/orphan.doc.mjs', 'templates'],
|
|
165
|
+
].sort(),
|
|
166
|
+
);
|
|
167
|
+
// `components/__tests__/Tested` and `docs/__tests__/sample`.
|
|
168
|
+
expect(fixtures).toBe(2);
|
|
169
|
+
expect(served.sort()).toEqual(
|
|
170
|
+
expect.arrayContaining([
|
|
171
|
+
'components/.drafts/Draft.doc.mjs',
|
|
172
|
+
'components/Linked.doc.mjs',
|
|
173
|
+
'components/__fixtures__/Fixture.doc.mjs',
|
|
174
|
+
]),
|
|
175
|
+
);
|
|
176
|
+
expect(served.some(file => /Tested|Hidden/.test(file))).toBe(false);
|
|
177
|
+
// Theme discovery serves no theme from this root, so none is checked,
|
|
178
|
+
// and the root says why.
|
|
179
|
+
expect(unread).toEqual([
|
|
180
|
+
{
|
|
181
|
+
path: integration.themes,
|
|
182
|
+
reason: expect.stringMatching(
|
|
183
|
+
/^the themes root does not load, so no doc in it was checked: .*lower-kebab/,
|
|
184
|
+
),
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("takes a scoped package's namespace docs and placed guides where they are, with each guide's overlays", async () => {
|
|
190
|
+
write(
|
|
191
|
+
'docs/guides/guides.doc.mjs',
|
|
192
|
+
`export const docs = ${JSON.stringify({type: 'namespace', name: 'guides', title: 'Guides', summary: 'Every guide.', slots: {guides: {title: 'Guides', accepts: {kinds: ['generic']}}}})};\n`,
|
|
193
|
+
);
|
|
194
|
+
write(
|
|
195
|
+
'docs/guides/setup.doc.mjs',
|
|
196
|
+
`export const docs = ${JSON.stringify({type: 'generic', name: 'setup', title: 'Set up', description: 'D', placement: {parent: 'namespace:guides', slot: 'guides', order: 1}, sections: [{title: 'S', content: [{type: 'prose', text: 'x'}]}]})};\n`,
|
|
197
|
+
);
|
|
198
|
+
write('docs/guides/setup.doc.zh.mjs', 'export const docsZh = {};\n');
|
|
199
|
+
write('docs/guides/setup.doc.dense.mjs', 'export const docsDense = {};\n');
|
|
200
|
+
|
|
201
|
+
const {files, unread} = await integrationDocFiles({
|
|
202
|
+
name: '@acme/widgets',
|
|
203
|
+
docs: path.join(pkg, 'docs'),
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(unread).toEqual([]);
|
|
207
|
+
expect(listed(files)).toEqual([
|
|
208
|
+
['docs/guides/guides.doc.mjs', 'docs'],
|
|
209
|
+
['docs/guides/setup.doc.dense.mjs', 'docs-overlay'],
|
|
210
|
+
['docs/guides/setup.doc.mjs', 'docs'],
|
|
211
|
+
['docs/guides/setup.doc.zh.mjs', 'docs-overlay'],
|
|
212
|
+
]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('leaves a root validate reports to that issue, and lists a root whose reader fails inside it', async () => {
|
|
216
|
+
write('components/Badge.doc.mjs', component('Badge'));
|
|
217
|
+
write('components/locked/Inner.doc.mjs', component('Inner'));
|
|
218
|
+
write('docs/guide.doc.mjs', topic('guide'));
|
|
219
|
+
const locked = path.join(pkg, 'components', 'locked');
|
|
220
|
+
fs.chmodSync(path.join(pkg, 'docs'), 0o000);
|
|
221
|
+
fs.chmodSync(locked, 0o000);
|
|
222
|
+
try {
|
|
223
|
+
const {files, unread} = await integrationDocFiles({
|
|
224
|
+
name: '@acme/widgets',
|
|
225
|
+
components: path.join(pkg, 'components'),
|
|
226
|
+
docs: path.join(pkg, 'docs'),
|
|
227
|
+
templates: path.join(pkg, 'missing'),
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// `validate` reports the unreadable docs root and the missing templates
|
|
231
|
+
// root itself; the components root reads until its locked folder.
|
|
232
|
+
expect(files).toEqual([]);
|
|
233
|
+
expect(unread).toEqual([
|
|
234
|
+
{
|
|
235
|
+
path: path.join(pkg, 'components'),
|
|
236
|
+
reason: expect.stringMatching(
|
|
237
|
+
/^the components root does not load, so no doc in it was checked: .*EACCES/,
|
|
238
|
+
),
|
|
239
|
+
},
|
|
240
|
+
]);
|
|
241
|
+
} finally {
|
|
242
|
+
fs.chmodSync(path.join(pkg, 'docs'), 0o755);
|
|
243
|
+
fs.chmodSync(locked, 0o755);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -25,7 +25,7 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
|
|
|
25
25
|
loadDoc?: (docPath: string) => Promise<any>;
|
|
26
26
|
}): Promise<PropDriftReport>;
|
|
27
27
|
/**
|
|
28
|
-
* @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch'} PropDriftKind
|
|
28
|
+
* @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch' | 'type_mismatch'} PropDriftKind
|
|
29
29
|
*/
|
|
30
30
|
/**
|
|
31
31
|
* @typedef {object} PropDriftFinding
|
|
@@ -47,6 +47,15 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
|
|
|
47
47
|
* @property {string} doc the doc file, relative to the package root
|
|
48
48
|
* @property {string} reason why its props could not be read
|
|
49
49
|
*/
|
|
50
|
+
/**
|
|
51
|
+
* @typedef {object} PropDriftTypesNotCompared
|
|
52
|
+
* @property {string} component
|
|
53
|
+
* @property {string} doc the doc file, relative to the package root
|
|
54
|
+
* @property {string} reason why: not a form the check judges exactly, a
|
|
55
|
+
* field the prop's variants give different types, a standard prop
|
|
56
|
+
* (`className`, `style`, …), or a prop declared outside the package
|
|
57
|
+
* @property {string[]} props documented props whose types were not compared
|
|
58
|
+
*/
|
|
50
59
|
/**
|
|
51
60
|
* @typedef {object} PropDriftReport
|
|
52
61
|
* @property {'checked' | 'skipped'} status `skipped` means nothing was
|
|
@@ -54,12 +63,16 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
|
|
|
54
63
|
* @property {string} [reason]
|
|
55
64
|
* @property {string} [typescript] the version of the compiler that read the props
|
|
56
65
|
* @property {number} components how many documented prop tables were compared
|
|
66
|
+
* @property {number} typesCompared how many documented prop types were judged
|
|
67
|
+
* @property {string} [typesSkipped] why no prop type was judged
|
|
57
68
|
* @property {PropDriftFinding[]} findings
|
|
58
69
|
* @property {PropDriftUnchecked[]} unchecked documented components whose props
|
|
59
70
|
* could not be read from the source
|
|
60
71
|
* @property {Array<PropDriftUnchecked & {props: string[]}>} [propsNotChecked]
|
|
61
72
|
* props a mapped type builds from keys the check can't trace, which a doc
|
|
62
73
|
* leaving out draws no warning for
|
|
74
|
+
* @property {PropDriftTypesNotCompared[]} typesNotCompared every other
|
|
75
|
+
* documented prop type, grouped by why it was not judged
|
|
63
76
|
*/
|
|
64
77
|
/**
|
|
65
78
|
* @typedef {object} PropDriftTable
|
|
@@ -112,13 +125,28 @@ export type CodeProp = {
|
|
|
112
125
|
/**
|
|
113
126
|
* the compiler's renderings, computed on demand
|
|
114
127
|
*/
|
|
115
|
-
renderings: () => string[];
|
|
128
|
+
renderings: () => string[][];
|
|
116
129
|
/**
|
|
117
130
|
* the prop's type in each member of the props type
|
|
118
131
|
*/
|
|
119
132
|
types: () => any[];
|
|
133
|
+
/**
|
|
134
|
+
* one member declares it more than once (an
|
|
135
|
+
* intersection), so no one declaration's text is its type
|
|
136
|
+
*/
|
|
137
|
+
intersected: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* the type an index signature gives
|
|
140
|
+
* the name in each member that lacks the prop; null when two signatures
|
|
141
|
+
* in one member take it
|
|
142
|
+
*/
|
|
143
|
+
indexed: () => any[] | null;
|
|
144
|
+
/**
|
|
145
|
+
* where names in the prop's type resolve
|
|
146
|
+
*/
|
|
147
|
+
location: any;
|
|
120
148
|
};
|
|
121
|
-
export type PropDriftKind = "not_in_code" | "not_in_doc" | "required_mismatch";
|
|
149
|
+
export type PropDriftKind = "not_in_code" | "not_in_doc" | "required_mismatch" | "type_mismatch";
|
|
122
150
|
export type PropDriftFinding = {
|
|
123
151
|
/**
|
|
124
152
|
* the documented component (export) name
|
|
@@ -158,6 +186,23 @@ export type PropDriftUnchecked = {
|
|
|
158
186
|
*/
|
|
159
187
|
reason: string;
|
|
160
188
|
};
|
|
189
|
+
export type PropDriftTypesNotCompared = {
|
|
190
|
+
component: string;
|
|
191
|
+
/**
|
|
192
|
+
* the doc file, relative to the package root
|
|
193
|
+
*/
|
|
194
|
+
doc: string;
|
|
195
|
+
/**
|
|
196
|
+
* why: not a form the check judges exactly, a
|
|
197
|
+
* field the prop's variants give different types, a standard prop
|
|
198
|
+
* (`className`, `style`, …), or a prop declared outside the package
|
|
199
|
+
*/
|
|
200
|
+
reason: string;
|
|
201
|
+
/**
|
|
202
|
+
* documented props whose types were not compared
|
|
203
|
+
*/
|
|
204
|
+
props: string[];
|
|
205
|
+
};
|
|
161
206
|
export type PropDriftReport = {
|
|
162
207
|
/**
|
|
163
208
|
* `skipped` means nothing was
|
|
@@ -173,6 +218,14 @@ export type PropDriftReport = {
|
|
|
173
218
|
* how many documented prop tables were compared
|
|
174
219
|
*/
|
|
175
220
|
components: number;
|
|
221
|
+
/**
|
|
222
|
+
* how many documented prop types were judged
|
|
223
|
+
*/
|
|
224
|
+
typesCompared: number;
|
|
225
|
+
/**
|
|
226
|
+
* why no prop type was judged
|
|
227
|
+
*/
|
|
228
|
+
typesSkipped?: string | undefined;
|
|
176
229
|
findings: PropDriftFinding[];
|
|
177
230
|
/**
|
|
178
231
|
* documented components whose props
|
|
@@ -186,6 +239,11 @@ export type PropDriftReport = {
|
|
|
186
239
|
propsNotChecked?: (PropDriftUnchecked & {
|
|
187
240
|
props: string[];
|
|
188
241
|
})[] | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* every other
|
|
244
|
+
* documented prop type, grouped by why it was not judged
|
|
245
|
+
*/
|
|
246
|
+
typesNotCompared: PropDriftTypesNotCompared[];
|
|
189
247
|
};
|
|
190
248
|
export type PropDriftTable = {
|
|
191
249
|
/**
|