@astryxdesign/cli 0.7.2-canary.ba80461 → 0.7.2-canary.bd72a5f
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 +74 -73
- package/api/build/help/help.mjs +1 -1
- package/api/component/_adapter.d.mts +72 -1
- package/api/component/_adapter.mjs +209 -7
- package/api/component/component.mjs +82 -15
- package/api/component/doc-links.test.mjs +386 -0
- package/api/component/integration-export-name.test.mjs +644 -0
- package/api/discover/_adapter.d.mts +119 -12
- package/api/discover/_adapter.mjs +449 -10
- package/api/discover/_adapter.test.mjs +599 -17
- package/api/discover/_catalog-view.d.mts +16 -5
- package/api/discover/_catalog-view.mjs +32 -8
- package/api/discover/detail/doc/doc.mjs +9 -1
- package/api/discover/discover.d.mts +11 -0
- package/api/discover/discover.doc.mjs +7 -6
- package/api/discover/discover.mjs +107 -19
- package/api/discover/discover.type.d.mts +18 -7
- package/api/discover/discover.type.mjs +15 -7
- package/api/discover/list/list.d.mts +4 -3
- package/api/discover/list/list.mjs +17 -10
- package/api/docs/_adapter.d.mts +74 -0
- package/api/docs/_adapter.mjs +550 -14
- package/api/docs/integration-tree.test.mjs +22 -0
- package/api/docs/integrationDocs.test.mjs +124 -0
- package/api/docs/list/list.mjs +12 -2
- package/api/doctor/doctor.mjs +27 -3
- package/api/doctor/doctor.test.mjs +43 -0
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/doctor/theme-checks.test.mjs +136 -0
- package/api/gap-report/gap-report.d.mts +3 -0
- package/api/gap-report/gap-report.doc.mjs +11 -3
- package/api/gap-report/gap-report.mjs +219 -52
- package/api/gap-report/gap-report.test.mjs +233 -0
- package/api/gap-report/gap-report.type.d.mts +41 -0
- package/api/gap-report/gap-report.type.mjs +18 -0
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/init/run/run.mjs +2 -2
- package/api/integration/_adapter.d.mts +45 -0
- package/api/integration/_adapter.mjs +112 -0
- package/api/integration/add-contribution.component-names.test.mjs +66 -0
- package/api/integration/add-contribution.mjs +8 -4
- package/api/integration/add-contribution.test.mjs +4 -2
- package/api/integration/authoring-checks.mjs +108 -4
- package/api/integration/authoring-checks.test.mjs +808 -0
- package/api/integration/authoring-checks.type.d.mts +143 -0
- package/api/integration/authoring-checks.type.mjs +74 -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 +45 -6
- package/api/integration/integrationDocConflicts.doc.mjs +22 -5
- package/api/integration/pack-check.mjs +347 -104
- package/api/integration/pack-check.test.mjs +726 -0
- package/api/integration/validate-integration-fixes.test.mjs +67 -0
- package/api/integration/validate-integration.mjs +36 -3
- package/api/integration/validate-integration.test.mjs +88 -8
- 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 +19 -3
- package/api/search/search.d.mts +81 -12
- package/api/search/search.domain-priority.test.mjs +108 -18
- package/api/search/search.integration-check.test.mjs +24 -0
- package/api/search/search.mjs +603 -51
- package/api/search/search.test.mjs +139 -0
- package/api/swizzle/copy/copy.mjs +28 -14
- package/api/theme/build/build.family.test.mjs +54 -6
- package/api/theme/build/build.mjs +114 -17
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/api/upgrade/_adapter.d.mts +40 -2
- package/api/upgrade/_adapter.mjs +117 -4
- package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
- package/api/upgrade/run/run.mjs +30 -1
- package/api/upgrade/status/status.d.mts +21 -5
- package/api/upgrade/status/status.mjs +45 -8
- package/api/upgrade/upgrade.doc.mjs +5 -3
- package/api/upgrade/upgrade.type.d.mts +23 -0
- package/api/upgrade/upgrade.type.mjs +16 -1
- package/assets/codemods/runner.mjs +7 -1
- package/assets/discover/official-packages.json +367 -0
- package/assets/docs/README.md +10 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -3
- package/assets/docs/browser-support.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +3 -3
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +2 -2
- package/assets/docs/theme.doc.zh.mjs +1 -1
- package/assets/docs/tree/add-a-component.doc.mjs +11 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
- 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 +201 -0
- package/assets/docs/tree/check-your-docs.doc.mjs +65 -7
- package/assets/docs/tree/checks.doc.mjs +26 -18
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +8 -6
- package/assets/docs/tree/component-imports.doc.mjs +10 -2
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
- package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
- package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
- 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 +3 -3
- 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/layout-spacing.doc.mjs +2 -3
- package/assets/docs/tree/layout.doc.mjs +6 -6
- package/assets/docs/tree/links.doc.mjs +6 -5
- package/assets/docs/tree/migration-setup.doc.mjs +3 -2
- package/assets/docs/tree/migration-verification.doc.mjs +0 -1
- package/assets/docs/tree/migration.doc.mjs +0 -1
- 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 +4 -4
- package/assets/docs/tree/quick-start.doc.mjs +38 -22
- 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 +6 -8
- 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 +15 -6
- 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 +5 -16
- 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 +16 -8
- package/assets/docs/tree/type-scale.doc.mjs +3 -3
- package/assets/docs/tree/upgrading.doc.mjs +4 -4
- 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 +7 -6
- package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/theme.template.ts +1 -1
- 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 +30 -27
- package/authoring/doctypes/component/type.ts +21 -8
- 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/hook/type.ts +4 -0
- 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.d.mts +11 -0
- package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
- package/authoring/doctypes/template/parse.d.mts +6 -2
- package/authoring/doctypes/template/parse.mjs +3 -1
- package/authoring/doctypes/template/template.doc.mjs +3 -3
- package/authoring/doctypes/template/type.ts +22 -0
- 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/index.d.ts +1 -0
- package/authoring/integration/integration.doc.mjs +12 -4
- package/authoring/integration/parse.test.mjs +10 -0
- package/authoring/integration/schema.d.mts +2 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +4 -0
- package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
- package/clients/cli/commands/build-theme.mjs +1 -1
- package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
- package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
- package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
- package/clients/cli/commands/discover.doc.mjs +1 -1
- package/clients/cli/commands/discover.mjs +144 -93
- package/clients/cli/commands/discover.no-source.test.mjs +447 -33
- package/clients/cli/commands/discover.sources.test.mjs +20 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +18 -4
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +19 -5
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
- package/clients/cli/commands/doctor-integration.test.mjs +884 -0
- package/clients/cli/commands/doctor.mjs +281 -5
- package/clients/cli/commands/gap-report.doc.mjs +14 -2
- package/clients/cli/commands/gap-report.mjs +24 -2
- package/clients/cli/commands/gap-report.test.mjs +79 -0
- package/clients/cli/commands/integration-authoring.test.mjs +46 -0
- package/clients/cli/commands/integration-check.doc.mjs +85 -0
- package/clients/cli/commands/integration-check.test.mjs +411 -0
- package/clients/cli/commands/integration.doc.mjs +6 -2
- package/clients/cli/commands/integration.mjs +116 -5
- package/clients/cli/commands/json-contract.test.mjs +5 -1
- package/clients/cli/commands/setup-nudge.test.mjs +79 -1
- package/clients/cli/commands/swizzle.mjs +5 -3
- package/clients/cli/commands/swizzle.routing.test.mjs +18 -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/commands/upgrade.doc.mjs +14 -0
- package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
- package/clients/cli/index.mjs +30 -5
- package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
- package/foundation/agent-docs/agent-doc-state.mjs +38 -0
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/config/project.mjs +82 -0
- package/foundation/discovery/authoring-self-docs.mjs +2 -1
- package/foundation/discovery/component-discovery.d.mts +178 -10
- package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
- package/foundation/discovery/component-discovery.mjs +659 -62
- package/foundation/discovery/component-replacement.mjs +18 -0
- package/foundation/discovery/component-replacement.test.mjs +40 -0
- package/foundation/discovery/copied-passages.d.mts +216 -0
- package/foundation/discovery/copied-passages.mjs +720 -0
- package/foundation/discovery/copied-passages.test.mjs +124 -0
- package/foundation/discovery/doc-consistency.d.mts +34 -0
- package/foundation/discovery/doc-consistency.mjs +513 -0
- package/foundation/discovery/doc-consistency.test.mjs +347 -0
- package/foundation/discovery/doc-fluff.d.mts +112 -0
- package/foundation/discovery/doc-fluff.mjs +328 -0
- package/foundation/discovery/doc-fluff.test.mjs +142 -0
- package/foundation/discovery/doc-types.d.mts +157 -0
- package/foundation/discovery/doc-types.mjs +1231 -0
- package/foundation/discovery/doc-types.test.mjs +744 -0
- package/foundation/discovery/docs-discovery.d.mts +88 -0
- package/foundation/discovery/docs-discovery.mjs +83 -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/module-exports.d.mts +27 -0
- package/foundation/discovery/module-exports.mjs +356 -31
- package/foundation/discovery/module-exports.test.mjs +172 -0
- package/foundation/discovery/package-tsconfig.d.mts +14 -0
- package/foundation/discovery/package-tsconfig.mjs +228 -0
- package/foundation/discovery/package-tsconfig.test.mjs +210 -0
- package/foundation/discovery/project-typescript.d.mts +32 -0
- package/foundation/discovery/project-typescript.mjs +89 -0
- package/foundation/discovery/prop-drift.d.mts +297 -0
- package/foundation/discovery/prop-drift.mjs +2428 -0
- package/foundation/discovery/prop-drift.test.mjs +2337 -0
- package/foundation/discovery/stray-pointers.d.mts +52 -0
- package/foundation/discovery/stray-pointers.mjs +293 -0
- package/foundation/discovery/stray-pointers.test.mjs +86 -0
- package/foundation/discovery/type-match.d.mts +53 -0
- package/foundation/discovery/type-match.mjs +660 -0
- package/foundation/discovery/type-match.test.mjs +169 -0
- package/foundation/discovery/type-text.d.mts +68 -0
- package/foundation/discovery/type-text.mjs +658 -0
- package/foundation/discovery/type-text.test.mjs +196 -0
- package/foundation/discovery/unresolved-references.d.mts +62 -0
- package/foundation/discovery/unresolved-references.mjs +790 -0
- package/foundation/discovery/unresolved-references.test.mjs +567 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +26 -0
- package/foundation/doc-compiler/links.d.mts +41 -5
- package/foundation/doc-compiler/links.mjs +167 -28
- package/foundation/doc-compiler/links.test.mjs +97 -4
- package/foundation/doc-compiler/tree.mjs +30 -1
- package/foundation/doc-compiler/tree.test.mjs +7 -0
- package/foundation/env/package-manager.d.mts +32 -0
- package/foundation/env/package-manager.mjs +47 -0
- package/foundation/env/package-manager.test.mjs +194 -7
- package/foundation/fs/module-loader.d.mts +2 -1
- package/foundation/fs/module-loader.mjs +60 -4
- package/foundation/fs/module-loader.test.mjs +194 -0
- package/foundation/integrations/contribution-inventory.d.mts +11 -0
- package/foundation/integrations/contribution-inventory.mjs +56 -3
- package/foundation/integrations/issue.ts +6 -0
- package/foundation/integrations/validate-contributions.mjs +30 -1
- package/foundation/response/response-types.doc.mjs +15 -9
- package/package.json +11 -11
- package/scripts/postinstall.mjs +3 -3
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
* The strings of a doc the CLI resolves links in (spec:AST-047 FR9). In a
|
|
6
|
+
* topic: its description and summary, then the text of prose and heading
|
|
7
|
+
* blocks, list items, and table cells in each section's content, with the
|
|
8
|
+
* section's title. In a component doc (any doc with no sections): every text
|
|
9
|
+
* field, such as its description, usage, best practices, and each prop's and
|
|
10
|
+
* example's description, with the field's path. Code is never read.
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} doc an authored doc object
|
|
13
|
+
* @returns {{text: string, section: string | null, field: string | null}[]}
|
|
14
|
+
*/
|
|
15
|
+
export function linkableStrings(doc: unknown): {
|
|
16
|
+
text: string;
|
|
17
|
+
section: string | null;
|
|
18
|
+
field: string | null;
|
|
19
|
+
}[];
|
|
20
|
+
/**
|
|
21
|
+
* Every pointer span in one prose string, in order.
|
|
22
|
+
* @param {string} text
|
|
23
|
+
* @returns {string[]} the doc name each one points at
|
|
24
|
+
*/
|
|
25
|
+
export function pointersIn(text: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Each stray pointer in a package's topics and component docs.
|
|
28
|
+
*
|
|
29
|
+
* @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[], namespaces?: {doc?: {name?: string}}[], components?: {name: string, file: string}[]}} discovered
|
|
30
|
+
* @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').StrayPointer[]>}
|
|
31
|
+
*/
|
|
32
|
+
export function findStrayPointers(discovered: {
|
|
33
|
+
records: {
|
|
34
|
+
name: string;
|
|
35
|
+
path: string;
|
|
36
|
+
}[];
|
|
37
|
+
guides?: {
|
|
38
|
+
name: string;
|
|
39
|
+
ref?: {
|
|
40
|
+
topicFile?: string;
|
|
41
|
+
};
|
|
42
|
+
}[];
|
|
43
|
+
namespaces?: {
|
|
44
|
+
doc?: {
|
|
45
|
+
name?: string;
|
|
46
|
+
};
|
|
47
|
+
}[];
|
|
48
|
+
components?: {
|
|
49
|
+
name: string;
|
|
50
|
+
file: string;
|
|
51
|
+
}[];
|
|
52
|
+
}): Promise<import("../../api/integration/authoring-checks.type.mjs").StrayPointer[]>;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Stray doc pointers (architecture:cli-surface DEC-8): a code span in
|
|
5
|
+
* prose that is exactly `astryx docs <name>` for a doc that exists. The doc's
|
|
6
|
+
* `{@link}` prints the command that opens the doc and is checked by doctor's
|
|
7
|
+
* link check, so a written command is a pointer nothing checks.
|
|
8
|
+
*
|
|
9
|
+
* @input the docs a package ships, as discoverIntegrationDocs returns them
|
|
10
|
+
* @output each stray pointer, with the link that replaces it
|
|
11
|
+
* @position foundation/discovery, called through api/integration/_adapter.mjs
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
|
|
16
|
+
import {textFields} from '../doc-compiler/links.mjs';
|
|
17
|
+
import {builtinGuideFiles} from './docs-discovery.mjs';
|
|
18
|
+
import {
|
|
19
|
+
fileWords,
|
|
20
|
+
lineAtOffset,
|
|
21
|
+
loadQuietly,
|
|
22
|
+
locateWords,
|
|
23
|
+
textWords,
|
|
24
|
+
} from './copied-passages.mjs';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A code span that is exactly the command opening one doc. A command with
|
|
28
|
+
* more words, a flag, or a route is a walkthrough, not a pointer. A name holds
|
|
29
|
+
* what a topic name may (letters, digits, `_` and `-`), never opening with `-`.
|
|
30
|
+
*/
|
|
31
|
+
const POINTER = /`astryx docs ([A-Za-z0-9_][A-Za-z0-9_-]*)`/g;
|
|
32
|
+
|
|
33
|
+
/** @type {Promise<Map<string, string>> | undefined} */
|
|
34
|
+
let coreKinds;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The CLI's own docs by name, each with the kind a link names it by: a
|
|
38
|
+
* namespace doc as `namespace`, a topic or guide as `generic`.
|
|
39
|
+
* @returns {Promise<Map<string, string>>}
|
|
40
|
+
*/
|
|
41
|
+
function loadCoreKinds() {
|
|
42
|
+
coreKinds ??= (async () => {
|
|
43
|
+
const kinds = new Map();
|
|
44
|
+
for (const file of builtinGuideFiles()) {
|
|
45
|
+
const doc = await loadQuietly(file);
|
|
46
|
+
if (typeof doc?.name === 'string') {
|
|
47
|
+
kinds.set(doc.name, doc.type === 'namespace' ? 'namespace' : 'generic');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return kinds;
|
|
51
|
+
})();
|
|
52
|
+
return coreKinds;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The strings of a doc the CLI resolves links in (spec:AST-047 FR9). In a
|
|
57
|
+
* topic: its description and summary, then the text of prose and heading
|
|
58
|
+
* blocks, list items, and table cells in each section's content, with the
|
|
59
|
+
* section's title. In a component doc (any doc with no sections): every text
|
|
60
|
+
* field, such as its description, usage, best practices, and each prop's and
|
|
61
|
+
* example's description, with the field's path. Code is never read.
|
|
62
|
+
*
|
|
63
|
+
* @param {unknown} doc an authored doc object
|
|
64
|
+
* @returns {{text: string, section: string | null, field: string | null}[]}
|
|
65
|
+
*/
|
|
66
|
+
export function linkableStrings(doc) {
|
|
67
|
+
/** @type {{text: string, section: string | null, field: string | null}[]} */
|
|
68
|
+
const strings = [];
|
|
69
|
+
if (doc == null || typeof doc !== 'object') return strings;
|
|
70
|
+
const top = /** @type {Record<string, any>} */ (doc);
|
|
71
|
+
if (!Array.isArray(top.sections)) {
|
|
72
|
+
for (const {field, text} of textFields(doc)) {
|
|
73
|
+
strings.push({text, section: null, field});
|
|
74
|
+
}
|
|
75
|
+
return strings;
|
|
76
|
+
}
|
|
77
|
+
for (const field of ['description', 'summary']) {
|
|
78
|
+
if (typeof top[field] === 'string') {
|
|
79
|
+
strings.push({text: top[field], section: null, field});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @param {unknown} value
|
|
84
|
+
* @param {string | null} section
|
|
85
|
+
*/
|
|
86
|
+
const walk = (value, section) => {
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
for (const item of value) walk(item, section);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (value == null || typeof value !== 'object') return;
|
|
92
|
+
const record = /** @type {Record<string, any>} */ (value);
|
|
93
|
+
const title = typeof record.title === 'string' ? record.title : section;
|
|
94
|
+
if (Array.isArray(record.sections)) walk(record.sections, section);
|
|
95
|
+
if (!Array.isArray(record.content)) return;
|
|
96
|
+
for (const block of record.content) {
|
|
97
|
+
const add = (/** @type {unknown} */ text) => {
|
|
98
|
+
if (typeof text === 'string') {
|
|
99
|
+
strings.push({text, section: title, field: null});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
switch (block?.type) {
|
|
103
|
+
case 'prose':
|
|
104
|
+
case 'heading':
|
|
105
|
+
add(block.text);
|
|
106
|
+
break;
|
|
107
|
+
case 'list':
|
|
108
|
+
(block.items ?? []).forEach(add);
|
|
109
|
+
break;
|
|
110
|
+
case 'table':
|
|
111
|
+
(block.headers ?? []).forEach(add);
|
|
112
|
+
for (const row of block.rows ?? []) row.forEach(add);
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
walk(block, title);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
walk(doc, null);
|
|
120
|
+
return strings;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Every pointer span in one prose string, in order.
|
|
125
|
+
* @param {string} text
|
|
126
|
+
* @returns {string[]} the doc name each one points at
|
|
127
|
+
*/
|
|
128
|
+
export function pointersIn(text) {
|
|
129
|
+
return [...text.matchAll(POINTER)].map(match => match[1]);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Where a string's words start among a file's words, from `from` on. A
|
|
134
|
+
* one-line string the file holds as a quoted literal is found at that
|
|
135
|
+
* literal, so a list item that is only `astryx docs theme` is not placed at a
|
|
136
|
+
* summary or code block that writes the same words.
|
|
137
|
+
*
|
|
138
|
+
* @param {string[]} lines the file's lines
|
|
139
|
+
* @param {{word: string, line: number}[]} file the file's words
|
|
140
|
+
* @param {string} text
|
|
141
|
+
* @param {{word: string}[]} words the string's words
|
|
142
|
+
* @param {number} from
|
|
143
|
+
* @returns {number}
|
|
144
|
+
*/
|
|
145
|
+
function locateString(lines, file, text, words, from) {
|
|
146
|
+
/** @type {number[]} */
|
|
147
|
+
const starts = [];
|
|
148
|
+
for (let at = locateWords(file, words); at >= 0;) {
|
|
149
|
+
starts.push(at);
|
|
150
|
+
at = locateWords(file, words, at + 1);
|
|
151
|
+
}
|
|
152
|
+
if (starts.length === 0) return -1;
|
|
153
|
+
const literals = text.includes('\n')
|
|
154
|
+
? []
|
|
155
|
+
: [`'${text}'`, `"${text}"`, `'${text.replace(/'/g, "\\'")}'`];
|
|
156
|
+
const quoted = starts.filter(at =>
|
|
157
|
+
literals.some(literal => lines[file[at].line - 1]?.includes(literal)),
|
|
158
|
+
);
|
|
159
|
+
const pool = quoted.length > 0 ? quoted : starts;
|
|
160
|
+
return pool.find(at => at >= from) ?? pool[0];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Each stray pointer in a package's topics and component docs.
|
|
165
|
+
*
|
|
166
|
+
* @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[], namespaces?: {doc?: {name?: string}}[], components?: {name: string, file: string}[]}} discovered
|
|
167
|
+
* @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').StrayPointer[]>}
|
|
168
|
+
*/
|
|
169
|
+
export async function findStrayPointers(discovered) {
|
|
170
|
+
/** @type {{name: string, file: string | undefined, kind: 'topic' | 'component'}[]} */
|
|
171
|
+
const topics = [
|
|
172
|
+
...discovered.records.map(record => ({
|
|
173
|
+
name: record.name,
|
|
174
|
+
file: record.path,
|
|
175
|
+
kind: /** @type {const} */ ('topic'),
|
|
176
|
+
})),
|
|
177
|
+
...(discovered.guides ?? []).map(guide => ({
|
|
178
|
+
name: guide.name,
|
|
179
|
+
file: guide.ref?.topicFile,
|
|
180
|
+
kind: /** @type {const} */ ('topic'),
|
|
181
|
+
})),
|
|
182
|
+
];
|
|
183
|
+
/** @type {Map<string, string>} */
|
|
184
|
+
const own = new Map(topics.map(topic => [topic.name, 'generic']));
|
|
185
|
+
for (const namespace of discovered.namespaces ?? []) {
|
|
186
|
+
const name = namespace?.doc?.name;
|
|
187
|
+
if (typeof name === 'string' && !own.has(name)) own.set(name, 'namespace');
|
|
188
|
+
}
|
|
189
|
+
for (const component of discovered.components ?? []) {
|
|
190
|
+
topics.push({
|
|
191
|
+
name: component.name,
|
|
192
|
+
file: component.file,
|
|
193
|
+
kind: 'component',
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const core = await loadCoreKinds();
|
|
197
|
+
// A topic that extends another has no route of its own: a link to it names
|
|
198
|
+
// the page it shows on, the topic it extends.
|
|
199
|
+
/** @type {Map<string, string>} */
|
|
200
|
+
const extendsOf = new Map();
|
|
201
|
+
for (const topic of topics) {
|
|
202
|
+
if (!topic.file) continue;
|
|
203
|
+
const doc = /** @type {any} */ (await loadQuietly(topic.file));
|
|
204
|
+
if (typeof doc?.extends === 'string')
|
|
205
|
+
extendsOf.set(topic.name, doc.extends);
|
|
206
|
+
}
|
|
207
|
+
/** @param {string} target */
|
|
208
|
+
const linkFor = target => {
|
|
209
|
+
const page = extendsOf.get(target);
|
|
210
|
+
if (page != null) {
|
|
211
|
+
if (own.has(page) && !extendsOf.has(page)) {
|
|
212
|
+
return `{@link ${own.get(page)}:${page}}`;
|
|
213
|
+
}
|
|
214
|
+
return core.has(page)
|
|
215
|
+
? `{@link @astryxdesign/cli:${core.get(page)}:${page}}`
|
|
216
|
+
: null;
|
|
217
|
+
}
|
|
218
|
+
return own.has(target)
|
|
219
|
+
? `{@link ${own.get(target)}:${target}}`
|
|
220
|
+
: core.has(target)
|
|
221
|
+
? `{@link @astryxdesign/cli:${core.get(target)}:${target}}`
|
|
222
|
+
: null;
|
|
223
|
+
};
|
|
224
|
+
/** @type {import('../../api/integration/authoring-checks.type.mjs').StrayPointer[]} */
|
|
225
|
+
const found = [];
|
|
226
|
+
for (const topic of topics) {
|
|
227
|
+
if (!topic.file) continue;
|
|
228
|
+
const doc = await loadQuietly(topic.file);
|
|
229
|
+
if (!doc) continue;
|
|
230
|
+
/** @type {{word: string, line: number}[]} */
|
|
231
|
+
let source = [];
|
|
232
|
+
/** @type {string[]} */
|
|
233
|
+
let lines = [];
|
|
234
|
+
try {
|
|
235
|
+
const raw = fs.readFileSync(topic.file, 'utf8');
|
|
236
|
+
source = fileWords(raw);
|
|
237
|
+
lines = raw.split('\n');
|
|
238
|
+
} catch {
|
|
239
|
+
// No line numbers; the finding still names the section.
|
|
240
|
+
}
|
|
241
|
+
// A component doc is named by its own name: a family doc by the family.
|
|
242
|
+
const name =
|
|
243
|
+
topic.kind === 'component' && typeof doc.name === 'string'
|
|
244
|
+
? doc.name
|
|
245
|
+
: topic.name;
|
|
246
|
+
const label =
|
|
247
|
+
topic.kind === 'component' ? `component "${name}"` : `"${name}"`;
|
|
248
|
+
// Each string is found by its whole run of words, from where the last
|
|
249
|
+
// one was found, so two strings that open alike keep their own lines.
|
|
250
|
+
let cursor = 0;
|
|
251
|
+
for (const {text, section, field} of linkableStrings(doc)) {
|
|
252
|
+
const words = textWords(text);
|
|
253
|
+
const index = locateString(lines, source, text, words, cursor);
|
|
254
|
+
if (index >= 0) cursor = index + words.length;
|
|
255
|
+
for (const match of text.matchAll(POINTER)) {
|
|
256
|
+
const target = match[1];
|
|
257
|
+
const link = linkFor(target);
|
|
258
|
+
if (!link) continue;
|
|
259
|
+
const command = `astryx docs ${target}`;
|
|
260
|
+
const line =
|
|
261
|
+
index < 0
|
|
262
|
+
? null
|
|
263
|
+
: lineAtOffset(
|
|
264
|
+
source,
|
|
265
|
+
index,
|
|
266
|
+
words,
|
|
267
|
+
/** @type {number} */ (match.index) + 1,
|
|
268
|
+
);
|
|
269
|
+
const where = [
|
|
270
|
+
section ? `section "${section}"` : null,
|
|
271
|
+
field ? `field ${field}` : null,
|
|
272
|
+
line == null ? null : `line ${line}`,
|
|
273
|
+
]
|
|
274
|
+
.filter(Boolean)
|
|
275
|
+
.join(', ');
|
|
276
|
+
found.push({
|
|
277
|
+
topic: name,
|
|
278
|
+
kind: topic.kind,
|
|
279
|
+
section,
|
|
280
|
+
field,
|
|
281
|
+
file: topic.file,
|
|
282
|
+
line,
|
|
283
|
+
pointer: command,
|
|
284
|
+
link,
|
|
285
|
+
message:
|
|
286
|
+
`${label}${where ? ` (${where})` : ''} points at a doc with the written command \`${command}\`. ` +
|
|
287
|
+
`Replace \`${command}\`, code ticks included, with ${link}: the CLI prints the command that opens the doc, and doctor checks the link.`,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return found;
|
|
293
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
|
|
5
|
+
import {linkableStrings, pointersIn} from './stray-pointers.mjs';
|
|
6
|
+
|
|
7
|
+
describe('pointersIn', () => {
|
|
8
|
+
it('finds a code span that is exactly the command opening one doc', () => {
|
|
9
|
+
expect(
|
|
10
|
+
pointersIn(
|
|
11
|
+
'Read `astryx docs theme`, then `astryx docs layout-spacing`.',
|
|
12
|
+
),
|
|
13
|
+
).toEqual(['theme', 'layout-spacing']);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('leaves a walkthrough alone: more words, a flag, or a route', () => {
|
|
17
|
+
expect(
|
|
18
|
+
pointersIn(
|
|
19
|
+
'Run `astryx docs theme overview`, `astryx docs --json`, `astryx docs cli/integrations`, or `astryx docs`.',
|
|
20
|
+
),
|
|
21
|
+
).toEqual([]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('leaves the bare name and a runner-written command alone', () => {
|
|
25
|
+
expect(
|
|
26
|
+
pointersIn('See astryx docs theme, or `pnpm astryx docs theme`.'),
|
|
27
|
+
).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('linkableStrings', () => {
|
|
32
|
+
it("reads a topic's description and summary, then prose, headings, list items and table cells, not code", () => {
|
|
33
|
+
const strings = linkableStrings({
|
|
34
|
+
name: 'acme',
|
|
35
|
+
description: 'Read `astryx docs theme`.',
|
|
36
|
+
summary: 'In short.',
|
|
37
|
+
sections: [
|
|
38
|
+
{
|
|
39
|
+
title: 'Use it',
|
|
40
|
+
content: [
|
|
41
|
+
{type: 'prose', text: 'prose'},
|
|
42
|
+
{type: 'heading', level: 3, text: 'heading'},
|
|
43
|
+
{type: 'list', style: 'unordered', items: ['item']},
|
|
44
|
+
{type: 'table', headers: ['head'], rows: [['cell']]},
|
|
45
|
+
{type: 'code', lang: 'bash', code: 'astryx docs theme'},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
expect(strings).toEqual([
|
|
51
|
+
{text: 'Read `astryx docs theme`.', section: null, field: 'description'},
|
|
52
|
+
{text: 'In short.', section: null, field: 'summary'},
|
|
53
|
+
{text: 'prose', section: 'Use it', field: null},
|
|
54
|
+
{text: 'heading', section: 'Use it', field: null},
|
|
55
|
+
{text: 'item', section: 'Use it', field: null},
|
|
56
|
+
{text: 'head', section: 'Use it', field: null},
|
|
57
|
+
{text: 'cell', section: 'Use it', field: null},
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("reads a component doc's text fields, not its names, types, defaults, or code", () => {
|
|
62
|
+
const strings = linkableStrings({
|
|
63
|
+
type: 'component',
|
|
64
|
+
name: 'AcmeButton',
|
|
65
|
+
displayName: 'Acme Button',
|
|
66
|
+
usage: {
|
|
67
|
+
description: 'usage',
|
|
68
|
+
bestPractices: [{guidance: true, description: 'practice'}],
|
|
69
|
+
},
|
|
70
|
+
props: [
|
|
71
|
+
{name: 'tone', type: 'string', default: "'a'", description: 'prop'},
|
|
72
|
+
],
|
|
73
|
+
examples: [{label: 'example', code: 'astryx docs theme'}],
|
|
74
|
+
});
|
|
75
|
+
expect(strings).toEqual([
|
|
76
|
+
{text: 'usage', section: null, field: 'usage.description'},
|
|
77
|
+
{
|
|
78
|
+
text: 'practice',
|
|
79
|
+
section: null,
|
|
80
|
+
field: 'usage.bestPractices[0].description',
|
|
81
|
+
},
|
|
82
|
+
{text: 'prop', section: null, field: 'props[0].description'},
|
|
83
|
+
{text: 'example', section: null, field: 'examples[0].label'},
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
* Judge a documented type. A doc may name an alias and spell out what it
|
|
6
|
+
* stands for, as `Name = expansion` or `Name (expansion)` (text that is not a
|
|
7
|
+
* type by itself): both parts are judged, and a mismatch in either is one;
|
|
8
|
+
* with one value after it (`Size = 'md'`, `Size = Size.Md`), or after a
|
|
9
|
+
* keyword, that part may be a default, and only the name is judged.
|
|
10
|
+
* @param {string} docType
|
|
11
|
+
* @param {any[]} codeTypes the prop's type in each member of the props type
|
|
12
|
+
* @param {JudgeContext} ctx
|
|
13
|
+
* @returns {TypeVerdict}
|
|
14
|
+
*/
|
|
15
|
+
export function judgeType(docType: string, codeTypes: any[], ctx: JudgeContext): TypeVerdict;
|
|
16
|
+
export type TypeVerdict = "match" | "mismatch" | "not_compared";
|
|
17
|
+
export type JudgeContext = {
|
|
18
|
+
ts: any;
|
|
19
|
+
checker: any;
|
|
20
|
+
/**
|
|
21
|
+
* where names in the documented type resolve (the
|
|
22
|
+
* prop's declaration, else the component's source file)
|
|
23
|
+
*/
|
|
24
|
+
location: any;
|
|
25
|
+
/**
|
|
26
|
+
* the prop is optional, so `undefined` is set
|
|
27
|
+
* aside on both sides
|
|
28
|
+
*/
|
|
29
|
+
optional: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* whether a source
|
|
32
|
+
* file is one of TypeScript's own libraries
|
|
33
|
+
*/
|
|
34
|
+
isDefaultLibrary?: ((file: any) => boolean) | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* the project checks without strict null
|
|
37
|
+
* checks, so the compiler drops `null` and `undefined` from every type and
|
|
38
|
+
* both are set aside on both sides
|
|
39
|
+
*/
|
|
40
|
+
nullable?: boolean | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* the project sets
|
|
43
|
+
* `exactOptionalPropertyTypes`: an optional prop takes `undefined` only when
|
|
44
|
+
* its type says so, and the compiler's mark for an absent prop is not a
|
|
45
|
+
* type the prop takes
|
|
46
|
+
*/
|
|
47
|
+
exactOptional?: boolean | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* the code's type as the source writes it and
|
|
50
|
+
* as the compiler prints it, each a list of union members
|
|
51
|
+
*/
|
|
52
|
+
written: string[][];
|
|
53
|
+
};
|