@astryxdesign/cli 0.7.2-canary.6d4f178 → 0.7.2-canary.72db6f9
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 +31 -0
- package/api/component/_adapter.mjs +116 -0
- package/api/component/component.mjs +60 -10
- package/api/component/doc-links.test.mjs +386 -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 +152 -48
- 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.mjs +1 -1
- 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 +296 -7
- package/api/integration/pack-check.test.mjs +367 -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 +72 -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 +503 -38
- package/api/search/search.test.mjs +139 -0
- 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 +1 -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 +25 -17
- 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 +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 +14 -5
- 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 +8 -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 +6 -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 +29 -26
- package/authoring/doctypes/component/type.ts +15 -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/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 +18 -0
- package/foundation/discovery/component-discovery.mjs +2 -2
- 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/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 +50 -2
- 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,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
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* @param {any} ts the project's own `typescript`
|
|
6
|
+
* @param {string} packageDir
|
|
7
|
+
* @param {string[]} sources the files to read
|
|
8
|
+
* @returns {{options: any, declarations: string[], error?: string}}
|
|
9
|
+
*/
|
|
10
|
+
export function readPackageTsconfig(ts: any, packageDir: string, sources: string[]): {
|
|
11
|
+
options: any;
|
|
12
|
+
declarations: string[];
|
|
13
|
+
error?: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Read a package's TypeScript project the way `tsc` reads it, so a
|
|
5
|
+
* check that reads the package's types with its own compiler sees what the
|
|
6
|
+
* package compiles against.
|
|
7
|
+
*
|
|
8
|
+
* - The config is the nearest `tsconfig.json`: the package's own, or a
|
|
9
|
+
* monorepo's root config for a local package. An app's config above an
|
|
10
|
+
* installed package (one below `node_modules`) is not the package's, and is
|
|
11
|
+
* not read.
|
|
12
|
+
* - A solution-style config (`"files": []` with `references`) lends the
|
|
13
|
+
* referenced config, at any depth, that includes the files to read.
|
|
14
|
+
* - The declaration files the config includes, included files that declare
|
|
15
|
+
* globals or augment a module, and included scripts (no import or export)
|
|
16
|
+
* join the files to read, so ambient types resolve as `tsc` resolves them.
|
|
17
|
+
* - Without a config, defaults read TSX the way bundlers do. A config with
|
|
18
|
+
* errors is reported, never read as defaults.
|
|
19
|
+
*
|
|
20
|
+
* @input The project's own `typescript`, the package directory, and the
|
|
21
|
+
* source files to read.
|
|
22
|
+
* @output Compiler options, the declaration files to add, and the config's
|
|
23
|
+
* error, if any.
|
|
24
|
+
* @position Foundation discovery, used by the documented-props comparison.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import * as fs from 'node:fs';
|
|
28
|
+
import * as path from 'node:path';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Whether a file the config includes declares types every file sees: a
|
|
32
|
+
* declaration file, a file that declares globals or augments a module, or a
|
|
33
|
+
* script (a `.ts` file that TypeScript reads as no module).
|
|
34
|
+
* @param {any} ts
|
|
35
|
+
* @param {string} file
|
|
36
|
+
*/
|
|
37
|
+
function isAmbient(ts, file) {
|
|
38
|
+
if (/\.d\.[cm]?ts$/.test(file)) return true;
|
|
39
|
+
let text;
|
|
40
|
+
try {
|
|
41
|
+
text = fs.readFileSync(file, 'utf8');
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (/\bdeclare\s+(?:global|module)\b/.test(text)) return true;
|
|
46
|
+
if (!/\.tsx?$/.test(file)) return false;
|
|
47
|
+
// Without the words, no module; with them, TypeScript decides.
|
|
48
|
+
return (
|
|
49
|
+
!/\b(?:import|export)\b/.test(text) ||
|
|
50
|
+
!ts.isExternalModule(
|
|
51
|
+
ts.createSourceFile(file, text, ts.ScriptTarget.Latest),
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Read a config's `files` entries as `tsc` does, and report the first it
|
|
58
|
+
* cannot find. TypeScript itself substitutes `${configDir}` (on a version
|
|
59
|
+
* that has it), resolves each entry against the config that writes it, and
|
|
60
|
+
* tries the TypeScript extensions for one written without its own, so this
|
|
61
|
+
* cannot drift from `tsc`. The parsed file names then hold the files found.
|
|
62
|
+
* A file the `include` matched that is gone by the time it is read was
|
|
63
|
+
* another process's, and is not checked here.
|
|
64
|
+
* @param {any} ts
|
|
65
|
+
* @param {any} raw the config's JSON
|
|
66
|
+
* @param {string} configPath
|
|
67
|
+
* @param {any} config the parsed config, whose file names are updated
|
|
68
|
+
* @returns {string | null} the message `tsc` gives for the first entry it
|
|
69
|
+
* cannot find (TS6053, or TS6231 for a folder)
|
|
70
|
+
*/
|
|
71
|
+
function readFilesEntries(ts, raw, configPath, config) {
|
|
72
|
+
const literal = ts.parseJsonConfigFileContent(
|
|
73
|
+
raw,
|
|
74
|
+
{...ts.sys, readDirectory: () => []},
|
|
75
|
+
path.dirname(configPath),
|
|
76
|
+
undefined,
|
|
77
|
+
configPath,
|
|
78
|
+
).fileNames;
|
|
79
|
+
if (literal.length === 0 || typeof ts.createProgram !== 'function') {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
// Only the entries themselves: no library, no types, no imports.
|
|
83
|
+
const program = ts.createProgram({
|
|
84
|
+
rootNames: literal,
|
|
85
|
+
options: {
|
|
86
|
+
...config.options,
|
|
87
|
+
noLib: true,
|
|
88
|
+
noResolve: true,
|
|
89
|
+
types: [],
|
|
90
|
+
noEmit: true,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const missing = program
|
|
94
|
+
.getOptionsDiagnostics()
|
|
95
|
+
.find(/** @param {any} d */ d => d.code === 6053 || d.code === 6231);
|
|
96
|
+
if (missing) {
|
|
97
|
+
const text = missing.messageText;
|
|
98
|
+
return typeof text === 'string' ? text : text.messageText;
|
|
99
|
+
}
|
|
100
|
+
const entries = new Set(
|
|
101
|
+
literal.map(/** @param {string} f */ f => path.resolve(f)),
|
|
102
|
+
);
|
|
103
|
+
config.fileNames = [
|
|
104
|
+
...config.fileNames.filter(
|
|
105
|
+
/** @param {string} f */ f => !entries.has(path.resolve(f)),
|
|
106
|
+
),
|
|
107
|
+
...program.getSourceFiles().map(/** @param {any} sf */ sf => sf.fileName),
|
|
108
|
+
];
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {any} ts the project's own `typescript`
|
|
114
|
+
* @param {string} packageDir
|
|
115
|
+
* @param {string[]} sources the files to read
|
|
116
|
+
* @returns {{options: any, declarations: string[], error?: string}}
|
|
117
|
+
*/
|
|
118
|
+
export function readPackageTsconfig(ts, packageDir, sources) {
|
|
119
|
+
const defaults = {
|
|
120
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
121
|
+
target: ts.ScriptTarget.ES2022,
|
|
122
|
+
module: ts.ModuleKind.ESNext,
|
|
123
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
124
|
+
strict: true,
|
|
125
|
+
allowJs: true,
|
|
126
|
+
esModuleInterop: true,
|
|
127
|
+
resolveJsonModule: true,
|
|
128
|
+
allowImportingTsExtensions: true,
|
|
129
|
+
};
|
|
130
|
+
/** @type {string | undefined} */
|
|
131
|
+
let error;
|
|
132
|
+
/** @type {(configPath: string) => any} */
|
|
133
|
+
const parse = configPath => {
|
|
134
|
+
const read = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
135
|
+
const config = read.error
|
|
136
|
+
? {errors: [read.error], fileNames: [], options: {}}
|
|
137
|
+
: ts.parseJsonConfigFileContent(
|
|
138
|
+
read.config,
|
|
139
|
+
ts.sys,
|
|
140
|
+
path.dirname(configPath),
|
|
141
|
+
undefined,
|
|
142
|
+
configPath,
|
|
143
|
+
);
|
|
144
|
+
// "No inputs were found" is how a solution-style config reads.
|
|
145
|
+
const problem = config.errors.find(
|
|
146
|
+
/** @param {any} d */ d => d.code !== 18003,
|
|
147
|
+
);
|
|
148
|
+
const where = path.relative(packageDir, configPath);
|
|
149
|
+
if (problem) {
|
|
150
|
+
config.error = `${where}: ${ts.flattenDiagnosticMessageText(problem.messageText, ' ')}`;
|
|
151
|
+
} else if (!read.error) {
|
|
152
|
+
const missing = readFilesEntries(ts, read.config, configPath, config);
|
|
153
|
+
if (missing) {
|
|
154
|
+
// Paths read from the package, as the config's other errors are.
|
|
155
|
+
const dir = path.dirname(configPath).split(path.sep).join('/');
|
|
156
|
+
const rel = path.relative(packageDir, path.dirname(configPath));
|
|
157
|
+
config.error = `${where}: ${missing
|
|
158
|
+
.split(`${dir}/`)
|
|
159
|
+
.join(rel ? `${rel.split(path.sep).join('/')}/` : '')}`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return config;
|
|
163
|
+
};
|
|
164
|
+
/** @type {any} */
|
|
165
|
+
let parsed;
|
|
166
|
+
try {
|
|
167
|
+
const found = ts.findConfigFile(
|
|
168
|
+
packageDir,
|
|
169
|
+
ts.sys.fileExists,
|
|
170
|
+
'tsconfig.json',
|
|
171
|
+
);
|
|
172
|
+
// A config above the package is an app's when the package is installed
|
|
173
|
+
// below it (`node_modules`), and the package's own otherwise (a
|
|
174
|
+
// monorepo's root config, as `tsc` reads it).
|
|
175
|
+
const installed =
|
|
176
|
+
found &&
|
|
177
|
+
path
|
|
178
|
+
.relative(path.dirname(found), packageDir)
|
|
179
|
+
.split(path.sep)
|
|
180
|
+
.includes('node_modules');
|
|
181
|
+
parsed = found && !installed ? parse(found) : null;
|
|
182
|
+
const own = new Set(sources.map(file => path.resolve(file)));
|
|
183
|
+
/** @type {(config: any) => boolean} */
|
|
184
|
+
const includes = config =>
|
|
185
|
+
config.fileNames.some(
|
|
186
|
+
/** @param {string} file */ file => own.has(path.resolve(file)),
|
|
187
|
+
);
|
|
188
|
+
// Every reference, at any depth, each config once (a cycle ends). One
|
|
189
|
+
// that is missing or doesn't parse is the project's error when no config
|
|
190
|
+
// includes the sources, as `tsc` reports it.
|
|
191
|
+
const visited = new Set(found ? [path.resolve(found)] : []);
|
|
192
|
+
/** @type {any} */
|
|
193
|
+
let broken = null;
|
|
194
|
+
/** @type {(config: any) => any} */
|
|
195
|
+
const including = config => {
|
|
196
|
+
if (includes(config)) return config;
|
|
197
|
+
for (const ref of config.projectReferences ?? []) {
|
|
198
|
+
const next = path.resolve(ts.resolveProjectReferencePath(ref));
|
|
199
|
+
if (visited.has(next)) continue;
|
|
200
|
+
visited.add(next);
|
|
201
|
+
const referenced = parse(next);
|
|
202
|
+
if (referenced.error) broken ??= referenced;
|
|
203
|
+
const hit = including(referenced);
|
|
204
|
+
if (hit) return hit;
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
};
|
|
208
|
+
if (parsed) parsed = including(parsed) ?? broken ?? parsed;
|
|
209
|
+
} catch {
|
|
210
|
+
parsed = null;
|
|
211
|
+
}
|
|
212
|
+
error = parsed?.error;
|
|
213
|
+
const options = parsed ? {...parsed.options} : defaults;
|
|
214
|
+
if (options.jsx == null) options.jsx = defaults.jsx;
|
|
215
|
+
return {
|
|
216
|
+
options: {
|
|
217
|
+
...options,
|
|
218
|
+
noEmit: true,
|
|
219
|
+
skipLibCheck: true,
|
|
220
|
+
incremental: false,
|
|
221
|
+
composite: false,
|
|
222
|
+
},
|
|
223
|
+
...(error ? {error} : {}),
|
|
224
|
+
declarations: (parsed?.fileNames ?? []).filter(
|
|
225
|
+
/** @param {string} file */ file => isAmbient(ts, file),
|
|
226
|
+
),
|
|
227
|
+
};
|
|
228
|
+
}
|