@astryxdesign/cli 0.6.3-canary.f839b67 → 0.6.4-canary.06c8fa3
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/CHANGELOG.md +194 -0
- package/README.md +64 -66
- package/api/component/_adapter.d.mts +25 -0
- package/api/component/_adapter.mjs +59 -5
- package/api/component/component.d.mts +6 -3
- package/api/component/component.doc.mjs +23 -10
- package/api/component/component.mjs +249 -9
- package/api/component/component.type.d.mts +25 -0
- package/api/component/component.type.mjs +44 -0
- package/api/discover/_adapter.d.mts +114 -6
- package/api/discover/_adapter.mjs +372 -17
- package/api/discover/_adapter.test.mjs +215 -0
- package/api/discover/_catalog-view.d.mts +115 -0
- package/api/discover/_catalog-view.mjs +203 -0
- package/api/discover/_catalog-view.test.mjs +128 -0
- package/api/discover/detail/detail.d.mts +18 -6
- package/api/discover/detail/detail.mjs +67 -13
- package/api/discover/detail/detail.test.mjs +85 -0
- package/api/discover/detail/item/item.d.mts +26 -0
- package/api/discover/detail/item/item.mjs +78 -0
- package/api/discover/detail/item/item.test.mjs +73 -0
- package/api/discover/discover.d.mts +3 -9
- package/api/discover/discover.doc.mjs +61 -18
- package/api/discover/discover.mjs +220 -36
- package/api/discover/discover.test.mjs +11 -2
- package/api/discover/discover.type.d.mts +147 -8
- package/api/discover/discover.type.mjs +102 -12
- package/api/discover/list/list.d.mts +20 -6
- package/api/discover/list/list.mjs +45 -12
- package/api/discover/list/list.test.mjs +46 -0
- package/api/discover/search/search.d.mts +18 -16
- package/api/discover/search/search.mjs +102 -56
- package/api/discover/search/search.test.mjs +144 -10
- package/api/docs/_adapter.d.mts +49 -7
- package/api/docs/_adapter.mjs +284 -33
- package/api/docs/docs.doc.mjs +4 -3
- package/api/docs/docs.test.mjs +2 -0
- package/api/docs/docs.type.d.mts +21 -5
- package/api/docs/docs.type.mjs +21 -5
- package/api/docs/integration-tree.test.mjs +9 -1
- package/api/docs/reference-blocks.test.mjs +406 -0
- package/api/doctor/doctor.d.mts +8 -3
- package/api/doctor/doctor.mjs +95 -10
- package/api/doctor/doctor.test.mjs +122 -10
- package/api/index.d.mts +1 -2
- package/api/index.mjs +4 -4
- package/api/integration/add-helpers.d.mts +5 -2
- package/api/integration/add-helpers.mjs +36 -9
- package/api/integration/authoring-checks.mjs +14 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +105 -0
- package/api/integration/pack-check.mjs +28 -3
- package/api/json/index.ts +0 -1
- package/api/search/search.test.mjs +18 -0
- package/api/template/table-floating-bulk-actions.test.mjs +66 -0
- package/api/template/template-integration.test.mjs +1 -65
- package/api/template/template.mjs +1 -1
- package/api/theme/add/add.mjs +17 -25
- package/api/theme/add/add.rollback.test.mjs +158 -0
- package/api/theme/add/add.staging.test.mjs +40 -23
- package/api/theme/build/build.family.test.mjs +7 -12
- package/api/theme/build/build.mjs +8 -18
- package/api/theme/build/build.rollback.test.mjs +148 -0
- package/api/upgrade/run/files-changed.test.mjs +111 -0
- package/api/upgrade/run/run.mjs +6 -4
- package/api/upgrade/upgrade.type.mjs +2 -2
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- package/assets/codemods/__tests__/runner.test.mjs +3 -1
- package/assets/codemods/file-count.test.mjs +163 -0
- package/assets/codemods/integration-runner.mjs +3 -3
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/next/index.mjs +1 -19
- package/assets/codemods/transforms/v0.6.4/index.mjs +31 -0
- package/assets/docs/internationalization.doc.mjs +7 -5
- package/assets/docs/styling-libraries.doc.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/component-lookups.doc.mjs +149 -0
- package/assets/docs/tree/integrations.doc.mjs +20 -1
- package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
- package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
- package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
- package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
- package/authoring/config/config.doc.mjs +9 -1
- package/authoring/config/parse.d.mts +2 -0
- package/authoring/config/parse.mjs +19 -0
- package/authoring/config/parse.test.mjs +8 -0
- package/authoring/config/type.ts +13 -2
- package/authoring/discover/discover.doc.d.mts +13 -0
- package/authoring/discover/discover.doc.mjs +138 -0
- package/authoring/discover/parse.d.mts +24 -0
- package/authoring/discover/parse.mjs +128 -0
- package/authoring/discover/parse.test.mjs +124 -0
- package/authoring/discover/type.ts +87 -0
- package/authoring/doctypes/_schema.d.mts +72 -0
- package/authoring/doctypes/_schema.mjs +25 -1
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/command/type.ts +1 -1
- package/authoring/doctypes/load-contract.test.mjs +25 -0
- package/authoring/doctypes/reference/reference.doc.mjs +31 -4
- package/authoring/doctypes/reference/type.ts +20 -5
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +10 -0
- package/authoring/index.mjs +1 -0
- package/clients/cli/command-result-coverage.test.mjs +7 -7
- package/clients/cli/commands/component/index.mjs +152 -55
- package/clients/cli/commands/component-batch.test.mjs +341 -0
- package/clients/cli/commands/component-ownership.test.mjs +89 -0
- package/clients/cli/commands/component.doc.mjs +23 -6
- package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
- package/clients/cli/commands/discover.doc.mjs +53 -9
- package/clients/cli/commands/discover.mjs +393 -118
- package/clients/cli/commands/discover.sources.test.mjs +267 -0
- package/clients/cli/commands/docs.mjs +2 -2
- package/clients/cli/commands/docs.test.mjs +29 -0
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/exit-codes.test.mjs +1 -8
- package/clients/cli/lib/json-shim.mjs +24 -14
- package/clients/cli/lib/json-shim.test.mjs +6 -20
- package/clients/cli/lib/manifest.mjs +3 -8
- package/clients/cli/lib/manifest.test.mjs +5 -2
- package/clients/cli/lib/parse-error-format.test.mjs +81 -0
- package/foundation/discovery/authoring-self-docs.d.mts +12 -0
- package/foundation/discovery/authoring-self-docs.mjs +21 -8
- package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
- package/foundation/discovery/docs-discovery.d.mts +4 -1
- package/foundation/discovery/docs-discovery.mjs +40 -6
- package/foundation/discovery/docs-discovery.test.mjs +40 -0
- package/foundation/discovery/template-adapter.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/doc-compiler/lenses.d.mts +5 -3
- package/foundation/doc-compiler/lenses.mjs +48 -3
- package/foundation/doc-compiler/links.d.mts +30 -3
- package/foundation/doc-compiler/links.mjs +46 -5
- package/foundation/doc-compiler/links.test.mjs +53 -0
- package/foundation/doc-compiler/tree.test.mjs +9 -1
- package/foundation/integrations/cli-requirement.test.mjs +17 -42
- package/foundation/integrations/integrations.d.mts +14 -1
- package/foundation/integrations/integrations.mjs +41 -1
- package/foundation/integrations/integrations.test.mjs +31 -0
- package/foundation/response/batch.type.d.mts +33 -0
- package/foundation/response/batch.type.mjs +34 -0
- package/foundation/response/response-types.doc.mjs +15 -21
- package/foundation/response/response-types.doc.test.mjs +23 -0
- package/foundation/xle/browser.d.mts +3 -3
- package/foundation/xle/browser.mjs +3 -3
- package/foundation/xle/expand.mjs +2 -2
- package/foundation/xle/parse.mjs +1 -1
- package/foundation/xle/print.mjs +2 -2
- package/foundation/xle/splice.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -16
- package/api/layout/check/check.mjs +0 -40
- package/api/layout/expand/expand.d.mts +0 -22
- package/api/layout/expand/expand.mjs +0 -155
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/grammar/grammar.d.mts +0 -13
- package/api/layout/grammar/grammar.mjs +0 -87
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -89
- package/api/layout/layout.type.mjs +0 -103
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/clients/cli/commands/layout-check.doc.mjs +0 -65
- package/clients/cli/commands/layout-expand.doc.mjs +0 -83
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -30
- package/clients/cli/commands/layout.doc.mjs +0 -34
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.mjs +0 -275
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
- /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/migrate-native-picker-to-presentation.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/migrate-theme-catalog-to-descriptors.mjs +0 -0
|
@@ -1,33 +1,87 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file discover.detail leaf —
|
|
4
|
+
* @file discover.detail leaf — one package: what it adds, and, when a discover
|
|
5
|
+
* source knows it, every version and the latest one.
|
|
5
6
|
*
|
|
6
|
-
* @position api/discover/detail — pure projection over the packages
|
|
7
|
-
* ../_adapter; throws AstryxError (ERR_UNKNOWN_PACKAGE) for
|
|
7
|
+
* @position api/discover/detail — pure projection over the packages and catalog
|
|
8
|
+
* entry resolved by ../_adapter; throws AstryxError (ERR_UNKNOWN_PACKAGE) for
|
|
9
|
+
* a package neither the project nor any source knows.
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
12
|
import {toEntry} from '../_adapter.mjs';
|
|
13
|
+
import {catalogEntry, defaultVersion} from '../_catalog-view.mjs';
|
|
11
14
|
import {AstryxError} from '../../error.mjs';
|
|
12
15
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
|
-
* Build the discover.detail response for
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* Build the discover.detail response for one package. The project's installed
|
|
19
|
+
* copy describes itself; any other version is described by its source. For a
|
|
20
|
+
* package the project does not have, `install` is the package-manager command
|
|
21
|
+
* that adds it — printed, never run.
|
|
18
22
|
*
|
|
19
|
-
* @param {import('../
|
|
20
|
-
* @param {string}
|
|
23
|
+
* @param {import('../_adapter.mjs').InstalledPackage[]} packages
|
|
24
|
+
* @param {string} name package name, e.g. `@scope/name`
|
|
25
|
+
* @param {{
|
|
26
|
+
* catalog?: import('../_catalog-view.mjs').CatalogPackage,
|
|
27
|
+
* version?: string,
|
|
28
|
+
* add?: (name: string, version?: string) => string,
|
|
29
|
+
* installedAs?: string,
|
|
30
|
+
* }} [options]
|
|
21
31
|
* @returns {import('../discover.type.mjs').DiscoverDetailResponse}
|
|
22
32
|
*/
|
|
23
|
-
export function detail(packages,
|
|
24
|
-
const
|
|
25
|
-
|
|
33
|
+
export function detail(packages, name, options = {}) {
|
|
34
|
+
const {catalog, version, add, installedAs} = options;
|
|
35
|
+
const pkg = packages.find(p => p.name === name);
|
|
36
|
+
if (!pkg && !catalog) {
|
|
26
37
|
throw new AstryxError(
|
|
27
|
-
`Package "${
|
|
38
|
+
`Package "${name}" not found`,
|
|
28
39
|
packages.map(p => ({name: p.name, reason: 'available package'})),
|
|
29
40
|
ERROR_CODES.ERR_UNKNOWN_PACKAGE,
|
|
30
41
|
);
|
|
31
42
|
}
|
|
32
|
-
|
|
43
|
+
|
|
44
|
+
const known = new Set([
|
|
45
|
+
...(catalog?.versions.map(v => v.version) ?? []),
|
|
46
|
+
...(pkg?.version ? [pkg.version] : []),
|
|
47
|
+
]);
|
|
48
|
+
if (version && !known.has(version)) {
|
|
49
|
+
const releases = catalog?.versions.filter(v => !v.prerelease) ?? [];
|
|
50
|
+
throw new AstryxError(
|
|
51
|
+
`Version "${version}" of ${name} not found`,
|
|
52
|
+
(releases.length > 0 ? releases.map(v => v.version) : [...known])
|
|
53
|
+
.slice(0, 5)
|
|
54
|
+
.map(v => ({name: `${name}@${v}`, reason: 'published version'})),
|
|
55
|
+
ERROR_CODES.ERR_NOT_FOUND,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const local = pkg != null && (!version || version === pkg.version);
|
|
60
|
+
/** @type {Record<string, unknown>} */
|
|
61
|
+
const data = local
|
|
62
|
+
? {...toEntry(pkg), installed: true}
|
|
63
|
+
: {
|
|
64
|
+
...catalogEntry(
|
|
65
|
+
/** @type {NonNullable<typeof catalog>} */ (catalog),
|
|
66
|
+
version ?? defaultVersion(/** @type {NonNullable<typeof catalog>} */ (catalog)),
|
|
67
|
+
),
|
|
68
|
+
installed: pkg != null,
|
|
69
|
+
...(pkg?.version ? {installedVersion: pkg.version} : {}),
|
|
70
|
+
};
|
|
71
|
+
if (catalog) {
|
|
72
|
+
if (catalog.latest) data.latest = catalog.latest;
|
|
73
|
+
if (catalog.aliases.length > 0) data.aliases = catalog.aliases;
|
|
74
|
+
data.source = catalog.source;
|
|
75
|
+
}
|
|
76
|
+
if (!pkg) {
|
|
77
|
+
if (installedAs) data.installedAs = installedAs;
|
|
78
|
+
else if (add) data.install = add(name, version);
|
|
79
|
+
}
|
|
80
|
+
if (catalog) data.versions = catalog.versions;
|
|
81
|
+
return {
|
|
82
|
+
type: 'discover.detail',
|
|
83
|
+
data: /** @type {import('../discover.type.mjs').DiscoverDetailResponse['data']} */ (
|
|
84
|
+
data
|
|
85
|
+
),
|
|
86
|
+
};
|
|
33
87
|
}
|
|
@@ -36,6 +36,7 @@ describe('discover.detail leaf', () => {
|
|
|
36
36
|
category: '@acme/widgets',
|
|
37
37
|
components: ['Alpha', 'Beta'],
|
|
38
38
|
version: '1.2.3',
|
|
39
|
+
installed: true,
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
|
|
@@ -55,3 +56,87 @@ describe('discover.detail leaf', () => {
|
|
|
55
56
|
]);
|
|
56
57
|
});
|
|
57
58
|
});
|
|
59
|
+
|
|
60
|
+
describe('discover.detail leaf with a discover source', () => {
|
|
61
|
+
/** @type {any} */
|
|
62
|
+
const catalog = {
|
|
63
|
+
package: '@acme/charts',
|
|
64
|
+
integration: 'acme-charts',
|
|
65
|
+
aliases: ['@acme/charts-legacy'],
|
|
66
|
+
latest: '2.0.0',
|
|
67
|
+
source: 'Acme',
|
|
68
|
+
versions: [
|
|
69
|
+
{version: '2.1.0-beta.1', publishedAt: '2026-09-30T00:00:00.000Z', prerelease: true, status: 'ok'},
|
|
70
|
+
{version: '2.0.0', publishedAt: '2026-09-20T00:00:00.000Z', prerelease: false, status: 'ok'},
|
|
71
|
+
{version: '1.0.0', publishedAt: null, prerelease: false, status: 'manifest_load_error'},
|
|
72
|
+
],
|
|
73
|
+
contributions: [
|
|
74
|
+
{kind: 'component', name: 'Chart'},
|
|
75
|
+
{kind: 'template', name: 'pages/Report'},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
/** @param {string} name @param {string} [version] */
|
|
79
|
+
const add = (name, version) => `pnpm add ${version ? `${name}@${version}` : name}`;
|
|
80
|
+
|
|
81
|
+
it('describes a package the project does not have, with the command that adds it', () => {
|
|
82
|
+
expect(detail(PACKAGES, '@acme/charts', {catalog, add}).data).toEqual({
|
|
83
|
+
name: '@acme/charts',
|
|
84
|
+
category: '@acme/charts',
|
|
85
|
+
components: ['Chart'],
|
|
86
|
+
version: '2.0.0',
|
|
87
|
+
templates: ['pages/Report'],
|
|
88
|
+
installed: false,
|
|
89
|
+
latest: '2.0.0',
|
|
90
|
+
aliases: ['@acme/charts-legacy'],
|
|
91
|
+
source: 'Acme',
|
|
92
|
+
install: 'pnpm add @acme/charts',
|
|
93
|
+
versions: catalog.versions,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('describes any version, prereleases included', () => {
|
|
98
|
+
const {data} = detail(PACKAGES, '@acme/charts', {catalog, add, version: '2.1.0-beta.1'});
|
|
99
|
+
expect(data.version).toBe('2.1.0-beta.1');
|
|
100
|
+
expect(data.install).toBe('pnpm add @acme/charts@2.1.0-beta.1');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('refuses a version that was never published, and suggests releases', () => {
|
|
104
|
+
let err;
|
|
105
|
+
try {
|
|
106
|
+
detail(PACKAGES, '@acme/charts', {catalog, add, version: '3.0.0'});
|
|
107
|
+
} catch (e) {
|
|
108
|
+
err = e;
|
|
109
|
+
}
|
|
110
|
+
expect(err).toBeInstanceOf(AstryxError);
|
|
111
|
+
expect(err.code).toBe('ERR_NOT_FOUND');
|
|
112
|
+
expect(err.suggestions.map(s => s.name)).toEqual([
|
|
113
|
+
'@acme/charts@2.0.0',
|
|
114
|
+
'@acme/charts@1.0.0',
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('names the package the project has instead of offering an alias', () => {
|
|
119
|
+
const {data} = detail(PACKAGES, '@acme/charts', {
|
|
120
|
+
catalog,
|
|
121
|
+
add,
|
|
122
|
+
installedAs: '@acme/charts-legacy',
|
|
123
|
+
});
|
|
124
|
+
expect(data.installedAs).toBe('@acme/charts-legacy');
|
|
125
|
+
expect(data).not.toHaveProperty('install');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("keeps describing the installed copy from the project, with the source's versions", () => {
|
|
129
|
+
const {data} = detail(PACKAGES, '@acme/widgets', {
|
|
130
|
+
catalog: {...catalog, package: '@acme/widgets', latest: '1.3.0'},
|
|
131
|
+
add,
|
|
132
|
+
});
|
|
133
|
+
expect(data).toMatchObject({
|
|
134
|
+
name: '@acme/widgets',
|
|
135
|
+
components: ['Alpha', 'Beta'],
|
|
136
|
+
version: '1.2.3',
|
|
137
|
+
installed: true,
|
|
138
|
+
latest: '1.3.0',
|
|
139
|
+
});
|
|
140
|
+
expect(data).not.toHaveProperty('install');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Find one item of a package: an installed package's own templates, docs,
|
|
6
|
+
* themes, and codemods first, then what a discover source lists for the
|
|
7
|
+
* package. Returns null when neither has it, so the caller can report the
|
|
8
|
+
* component lookup's own error.
|
|
9
|
+
*
|
|
10
|
+
* @param {import('../../_adapter.mjs').InstalledPackage[]} packages
|
|
11
|
+
* @param {string} packageName
|
|
12
|
+
* @param {string} itemName
|
|
13
|
+
* @param {{
|
|
14
|
+
* catalog?: import('../../_catalog-view.mjs').CatalogPackage,
|
|
15
|
+
* version?: string,
|
|
16
|
+
* add?: (name: string, version?: string) => string,
|
|
17
|
+
* installedAs?: string,
|
|
18
|
+
* }} [options]
|
|
19
|
+
* @returns {import('../../discover.type.mjs').DiscoverItemResponse | null}
|
|
20
|
+
*/
|
|
21
|
+
export function item(packages: import("../../_adapter.mjs").InstalledPackage[], packageName: string, itemName: string, options?: {
|
|
22
|
+
catalog?: import("../../_catalog-view.mjs").CatalogPackage;
|
|
23
|
+
version?: string;
|
|
24
|
+
add?: (name: string, version?: string) => string;
|
|
25
|
+
installedAs?: string;
|
|
26
|
+
}): import("../../discover.type.mjs").DiscoverItemResponse | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file discover.item leaf — one item a package adds, when it is not an
|
|
5
|
+
* installed component (those keep resolving to their full doc through
|
|
6
|
+
* ../doc).
|
|
7
|
+
*
|
|
8
|
+
* @position api/discover/detail/item — pure projection over the packages and
|
|
9
|
+
* catalog entry resolved by ../../_adapter.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {KIND_FIELDS} from '../../_adapter.mjs';
|
|
13
|
+
import {defaultVersion} from '../../_catalog-view.mjs';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Find one item of a package: an installed package's own templates, docs,
|
|
17
|
+
* themes, and codemods first, then what a discover source lists for the
|
|
18
|
+
* package. Returns null when neither has it, so the caller can report the
|
|
19
|
+
* component lookup's own error.
|
|
20
|
+
*
|
|
21
|
+
* @param {import('../../_adapter.mjs').InstalledPackage[]} packages
|
|
22
|
+
* @param {string} packageName
|
|
23
|
+
* @param {string} itemName
|
|
24
|
+
* @param {{
|
|
25
|
+
* catalog?: import('../../_catalog-view.mjs').CatalogPackage,
|
|
26
|
+
* version?: string,
|
|
27
|
+
* add?: (name: string, version?: string) => string,
|
|
28
|
+
* installedAs?: string,
|
|
29
|
+
* }} [options]
|
|
30
|
+
* @returns {import('../../discover.type.mjs').DiscoverItemResponse | null}
|
|
31
|
+
*/
|
|
32
|
+
export function item(packages, packageName, itemName, options = {}) {
|
|
33
|
+
const {catalog, version, add, installedAs} = options;
|
|
34
|
+
const pkg = packages.find(p => p.name === packageName);
|
|
35
|
+
if (pkg && (!version || version === pkg.version)) {
|
|
36
|
+
for (const [kind, field] of KIND_FIELDS) {
|
|
37
|
+
if (kind === 'component') continue;
|
|
38
|
+
const names = /** @type {Record<string, unknown>} */ (pkg)[field];
|
|
39
|
+
if (Array.isArray(names) && names.includes(itemName)) {
|
|
40
|
+
return {
|
|
41
|
+
type: 'discover.item',
|
|
42
|
+
data: {
|
|
43
|
+
package: packageName,
|
|
44
|
+
...(pkg.version ? {version: pkg.version} : {}),
|
|
45
|
+
kind,
|
|
46
|
+
name: itemName,
|
|
47
|
+
installed: true,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const lower = itemName.toLowerCase();
|
|
55
|
+
const found =
|
|
56
|
+
catalog?.contributions.find(c => c.name === itemName) ??
|
|
57
|
+
catalog?.contributions.find(c => c.name.toLowerCase() === lower);
|
|
58
|
+
if (!catalog || !found) return null;
|
|
59
|
+
const shown = version ?? defaultVersion(catalog);
|
|
60
|
+
return {
|
|
61
|
+
type: 'discover.item',
|
|
62
|
+
data: {
|
|
63
|
+
package: packageName,
|
|
64
|
+
...(shown ? {version: shown} : {}),
|
|
65
|
+
kind: found.kind,
|
|
66
|
+
name: found.name,
|
|
67
|
+
...(found.title ? {title: found.title} : {}),
|
|
68
|
+
...(found.summary ? {summary: found.summary} : {}),
|
|
69
|
+
...(found.keywords ? {keywords: found.keywords} : {}),
|
|
70
|
+
installed: pkg != null,
|
|
71
|
+
...(pkg == null && installedAs ? {installedAs} : {}),
|
|
72
|
+
...(pkg == null && !installedAs && add
|
|
73
|
+
? {install: add(packageName, version)}
|
|
74
|
+
: {}),
|
|
75
|
+
source: catalog.source,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Tests for the discover.item leaf, a pure projection over installed
|
|
5
|
+
* packages and a source's catalog entry.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {describe, expect, it} from 'vitest';
|
|
9
|
+
import {item} from './item.mjs';
|
|
10
|
+
|
|
11
|
+
/** @type {any[]} */
|
|
12
|
+
const PACKAGES = [
|
|
13
|
+
{
|
|
14
|
+
name: '@acme/widgets',
|
|
15
|
+
category: '@acme/widgets',
|
|
16
|
+
version: '1.2.3',
|
|
17
|
+
components: ['Alpha'],
|
|
18
|
+
templates: ['pages/Home'],
|
|
19
|
+
docs: ['guide'],
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** @type {any} */
|
|
24
|
+
const CATALOG = {
|
|
25
|
+
package: '@acme/charts',
|
|
26
|
+
integration: 'acme-charts',
|
|
27
|
+
aliases: [],
|
|
28
|
+
latest: '2.0.0',
|
|
29
|
+
source: 'Acme',
|
|
30
|
+
versions: [],
|
|
31
|
+
contributions: [{kind: 'template', name: 'pages/Report', title: 'Report page'}],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** @param {string} name @param {string} [version] */
|
|
35
|
+
const add = (name, version) => `pnpm add ${version ? `${name}@${version}` : name}`;
|
|
36
|
+
|
|
37
|
+
describe('discover.item leaf', () => {
|
|
38
|
+
it("finds an installed package's own template, doc, theme, or codemod", () => {
|
|
39
|
+
expect(item(PACKAGES, '@acme/widgets', 'pages/Home')).toEqual({
|
|
40
|
+
type: 'discover.item',
|
|
41
|
+
data: {
|
|
42
|
+
package: '@acme/widgets',
|
|
43
|
+
version: '1.2.3',
|
|
44
|
+
kind: 'template',
|
|
45
|
+
name: 'pages/Home',
|
|
46
|
+
installed: true,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('finds an item a source lists, with the command that adds its package', () => {
|
|
52
|
+
expect(
|
|
53
|
+
item(PACKAGES, '@acme/charts', 'pages/report', {catalog: CATALOG, add}),
|
|
54
|
+
).toEqual({
|
|
55
|
+
type: 'discover.item',
|
|
56
|
+
data: {
|
|
57
|
+
package: '@acme/charts',
|
|
58
|
+
version: '2.0.0',
|
|
59
|
+
kind: 'template',
|
|
60
|
+
name: 'pages/Report',
|
|
61
|
+
title: 'Report page',
|
|
62
|
+
installed: false,
|
|
63
|
+
install: 'pnpm add @acme/charts',
|
|
64
|
+
source: 'Acme',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('returns null when neither the project nor a source has it', () => {
|
|
70
|
+
expect(item(PACKAGES, '@acme/widgets', 'Nope')).toBeNull();
|
|
71
|
+
expect(item(PACKAGES, '@acme/charts', 'Nope', {catalog: CATALOG})).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -3,19 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @param {string} [query]
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {boolean} [options.components]
|
|
8
|
-
* @param {string} [options.lang]
|
|
9
|
-
* @param {boolean} [options.zh]
|
|
6
|
+
* @param {import('./discover.type.mjs').DiscoverOptions} [options]
|
|
10
7
|
* @returns {Promise<
|
|
11
8
|
* import('./discover.type.mjs').DiscoverListResponse |
|
|
12
9
|
* import('./discover.type.mjs').DiscoverDetailResponse |
|
|
13
10
|
* import('./discover.type.mjs').DiscoverDetailDocResponse |
|
|
11
|
+
* import('./discover.type.mjs').DiscoverItemResponse |
|
|
14
12
|
* import('./discover.type.mjs').DiscoverSearchResponse
|
|
15
13
|
* >}
|
|
16
14
|
*/
|
|
17
|
-
export function discover(query?: string, options?:
|
|
18
|
-
components?: boolean | undefined;
|
|
19
|
-
lang?: string | undefined;
|
|
20
|
-
zh?: boolean | undefined;
|
|
21
|
-
}): Promise<import("./discover.type.mjs").DiscoverListResponse | import("./discover.type.mjs").DiscoverDetailResponse | import("./discover.type.mjs").DiscoverDetailDocResponse | import("./discover.type.mjs").DiscoverSearchResponse>;
|
|
15
|
+
export function discover(query?: string, options?: import("./discover.type.mjs").DiscoverOptions): Promise<import("./discover.type.mjs").DiscoverListResponse | import("./discover.type.mjs").DiscoverDetailResponse | import("./discover.type.mjs").DiscoverDetailDocResponse | import("./discover.type.mjs").DiscoverItemResponse | import("./discover.type.mjs").DiscoverSearchResponse>;
|
|
@@ -13,22 +13,25 @@ export const doc = {
|
|
|
13
13
|
name: 'discover',
|
|
14
14
|
namespace: 'cli/api',
|
|
15
15
|
displayName: 'discover()',
|
|
16
|
-
summary:
|
|
16
|
+
summary:
|
|
17
|
+
'Browse and search integrations: the ones a project has and, through discover sources, the ones it could add.',
|
|
17
18
|
description:
|
|
18
|
-
'
|
|
19
|
-
'the
|
|
20
|
-
'
|
|
21
|
-
"
|
|
22
|
-
'
|
|
19
|
+
'Lists the integrations a project loads and, when the project or an integration provides a discover source, ' +
|
|
20
|
+
'the packages it could add, with what each one adds per kind. An @scope/name query shows one package with every ' +
|
|
21
|
+
'version its source knows; @scope/name@version shows one version; @scope/name/Component returns an installed ' +
|
|
22
|
+
"component's validated doc, and any other item path returns that item. A free-text term searches every item and " +
|
|
23
|
+
'package. Discover only reads: it prints the command that adds a package and never runs it.',
|
|
23
24
|
importPath: '@astryxdesign/cli/api',
|
|
24
25
|
signature:
|
|
25
|
-
'discover(query?: string, options?: DiscoverOptions): Promise<DiscoverListResponse | DiscoverDetailResponse | DiscoverDetailDocResponse | DiscoverSearchResponse>',
|
|
26
|
+
'discover(query?: string, options?: DiscoverOptions): Promise<DiscoverListResponse | DiscoverDetailResponse | DiscoverDetailDocResponse | DiscoverItemResponse | DiscoverSearchResponse>',
|
|
26
27
|
keywords: [
|
|
27
28
|
'discover',
|
|
28
29
|
'packages',
|
|
29
30
|
'integrations',
|
|
30
31
|
'external',
|
|
31
32
|
'components',
|
|
33
|
+
'catalog',
|
|
34
|
+
'versions',
|
|
32
35
|
'search',
|
|
33
36
|
],
|
|
34
37
|
params: [
|
|
@@ -36,13 +39,39 @@ export const doc = {
|
|
|
36
39
|
name: 'query',
|
|
37
40
|
type: 'string',
|
|
38
41
|
description:
|
|
39
|
-
'
|
|
42
|
+
'A package (@scope/name, optionally @version), an item path (@scope/name/<item>), or a free-text term. Omit to list packages.',
|
|
40
43
|
},
|
|
41
44
|
{
|
|
42
45
|
name: 'options.components',
|
|
43
46
|
type: 'boolean',
|
|
44
47
|
description:
|
|
45
|
-
'In the CLI package list, print every component of each package instead of the first 10. A display flag for the CLI renderer; the programmatic response is unchanged.',
|
|
48
|
+
'In the CLI package list, print every component, and every other item, of each package instead of the first 10. A display flag for the CLI renderer; the programmatic response is unchanged.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'options.type',
|
|
52
|
+
type: "'component' | 'template' | 'doc' | 'theme' | 'codemod' | 'agent-doc'",
|
|
53
|
+
description:
|
|
54
|
+
'Only one kind: in the list, packages that add it; in a search, items of that kind.',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'options.installed',
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
description:
|
|
60
|
+
'Only what the project has. Cannot be set with options.available.',
|
|
61
|
+
default: 'false',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'options.available',
|
|
65
|
+
type: 'boolean',
|
|
66
|
+
description:
|
|
67
|
+
'Only what the project could add. Cannot be set with options.installed.',
|
|
68
|
+
default: 'false',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'options.limit',
|
|
72
|
+
type: 'number',
|
|
73
|
+
description: 'Max number of search results, a positive integer.',
|
|
74
|
+
default: '20',
|
|
46
75
|
},
|
|
47
76
|
{
|
|
48
77
|
name: 'options.lang',
|
|
@@ -60,21 +89,27 @@ export const doc = {
|
|
|
60
89
|
{
|
|
61
90
|
type: 'discover.list',
|
|
62
91
|
description:
|
|
63
|
-
'The
|
|
92
|
+
'The installed integrations (name, category, components, version, and a list per other kind they add). With a discover source, meta.available lists what the project could add and meta.sources reports each source. When the list is empty it carries meta.configured.',
|
|
64
93
|
},
|
|
65
94
|
{
|
|
66
95
|
type: 'discover.detail',
|
|
67
|
-
description:
|
|
96
|
+
description:
|
|
97
|
+
'One package: what the shown version adds, whether the project has it, its versions and latest release when a source knows them, and the command that adds it when the project does not have it.',
|
|
68
98
|
},
|
|
69
99
|
{
|
|
70
100
|
type: 'discover.detail.doc',
|
|
71
101
|
description:
|
|
72
|
-
'The validated ComponentDoc for one
|
|
102
|
+
'The validated ComponentDoc for one installed component, for an @scope/name/Component query.',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: 'discover.item',
|
|
106
|
+
description:
|
|
107
|
+
'One item that is not an installed component: its kind, name, the package and version that add it, and whether the project has the package.',
|
|
73
108
|
},
|
|
74
109
|
{
|
|
75
110
|
type: 'discover.search',
|
|
76
111
|
description:
|
|
77
|
-
'The query echoed back plus
|
|
112
|
+
'The query echoed back plus every matching item and package, each with its kind and whether the project has it, even when one name matches exactly or only one item matches; total is set when the limit cut the list.',
|
|
78
113
|
},
|
|
79
114
|
],
|
|
80
115
|
throws: [
|
|
@@ -82,17 +117,21 @@ export const doc = {
|
|
|
82
117
|
code: 'ERR_INVALID_ARGUMENT',
|
|
83
118
|
when: 'the query is a non-string value, or a free-text search is run with an empty query',
|
|
84
119
|
},
|
|
120
|
+
{
|
|
121
|
+
code: 'ERR_INVALID_OPTION',
|
|
122
|
+
when: 'options.type is not a known kind, options.limit is not a positive integer, or options.installed and options.available are both set',
|
|
123
|
+
},
|
|
85
124
|
{
|
|
86
125
|
code: 'ERR_UNKNOWN_PACKAGE',
|
|
87
|
-
when: 'the
|
|
126
|
+
when: 'neither the project nor any discover source has the package',
|
|
88
127
|
},
|
|
89
128
|
{
|
|
90
129
|
code: 'ERR_UNKNOWN_COMPONENT',
|
|
91
|
-
when: 'the
|
|
130
|
+
when: 'the item is not in the named package',
|
|
92
131
|
},
|
|
93
132
|
{
|
|
94
133
|
code: 'ERR_NOT_FOUND',
|
|
95
|
-
when: 'a free-text term matches
|
|
134
|
+
when: 'a free-text term matches nothing, or the requested version is not published',
|
|
96
135
|
},
|
|
97
136
|
{
|
|
98
137
|
code: 'ERR_INVALID_DOC',
|
|
@@ -100,10 +139,14 @@ export const doc = {
|
|
|
100
139
|
},
|
|
101
140
|
],
|
|
102
141
|
examples: [
|
|
103
|
-
{label: 'List packages', code: 'const {data} = await discover();'},
|
|
142
|
+
{label: 'List packages', code: 'const {data, meta} = await discover();'},
|
|
104
143
|
{label: 'Browse a package', code: "await discover('@acme/ui');"},
|
|
144
|
+
{label: 'One version', code: "await discover('@acme/ui@2.1.0');"},
|
|
105
145
|
{label: 'Show a component doc', code: "await discover('@acme/ui/Button');"},
|
|
106
|
-
{
|
|
146
|
+
{
|
|
147
|
+
label: 'Search templates to add',
|
|
148
|
+
code: "await discover('dashboard', {type: 'template', available: true});",
|
|
149
|
+
},
|
|
107
150
|
],
|
|
108
151
|
command: 'discover',
|
|
109
152
|
related: ['component', 'search', 'template'],
|