@astryxdesign/cli 0.6.4 → 0.6.5-canary.031021b
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 +56 -0
- package/README.md +97 -90
- package/api/build/build.doc.mjs +6 -1
- package/api/build/build.test.mjs +22 -0
- package/api/build/kit/kit.mjs +44 -5
- 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 +37 -17
- 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 +8 -3
- package/api/docs/_adapter.mjs +14 -6
- package/api/docs/docOverlays.test.mjs +27 -1
- package/api/docs/docs.doc.mjs +2 -2
- package/api/doctor/doctor.d.mts +8 -3
- package/api/doctor/doctor.doc.mjs +17 -8
- package/api/doctor/doctor.mjs +90 -9
- package/api/doctor/doctor.test.mjs +122 -10
- package/api/doctor/doctor.type.d.mts +1 -1
- package/api/doctor/doctor.type.mjs +1 -1
- package/api/gap-report/gap-report.doc.mjs +19 -10
- package/api/hook/hook.doc.mjs +6 -3
- package/api/index.d.mts +1 -0
- package/api/index.mjs +5 -3
- package/api/init/init.doc.mjs +17 -12
- package/api/integration/add-helpers.d.mts +5 -2
- package/api/integration/add-helpers.mjs +36 -9
- package/api/integration/add-theme.mjs +22 -1
- package/api/integration/add-theme.test.mjs +34 -0
- package/api/integration/authoring-checks.mjs +2 -2
- package/api/integration/integrationPackCheck.doc.mjs +3 -3
- package/api/integration/pack-check.lifecycle-output.test.mjs +107 -0
- package/api/integration/pack-check.mjs +82 -9
- package/api/integration/pack-check.test.mjs +90 -0
- package/api/integration/pack-check.type.mjs +1 -1
- package/api/json/assertResponse.doc.mjs +1 -1
- package/api/json/isError.doc.mjs +1 -1
- package/api/search/search.d.mts +27 -1
- package/api/search/search.doc.mjs +2 -2
- package/api/search/search.mjs +228 -16
- package/api/swizzle/swizzle.doc.mjs +7 -5
- package/api/template/copy/copy.mjs +1 -1
- package/api/template/copy/copy.test.mjs +9 -0
- package/api/template/template.doc.mjs +2 -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/theme/generateTonalPalette.doc.mjs +1 -2
- package/api/theme/listThemes.doc.mjs +1 -1
- package/api/theme/themeAdd.doc.mjs +9 -10
- package/api/theme/themeBuild.doc.mjs +13 -13
- package/api/theme/themeList.doc.mjs +1 -1
- package/api/theme/themeListAvailable.doc.mjs +2 -1
- package/api/theme/themePaletteGenerate.doc.mjs +15 -8
- package/api/theme/themeTargets.doc.mjs +3 -2
- package/api/theme/themeTemplate.doc.mjs +2 -1
- package/api/upgrade/run/files-changed.test.mjs +111 -0
- package/api/upgrade/run/run.mjs +5 -3
- package/api/upgrade/upgrade.doc.mjs +24 -22
- package/api/upgrade/upgrade.type.mjs +2 -2
- 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/runner.mjs +5 -4
- package/assets/docs/README.md +4 -2
- package/assets/docs/browser-support.doc.mjs +11 -11
- package/assets/docs/color.doc.mjs +8 -2
- package/assets/docs/elevation.doc.mjs +6 -4
- package/assets/docs/getting-started.doc.mjs +5 -16
- package/assets/docs/icons.doc.mjs +2 -21
- package/assets/docs/illustrations.doc.mjs +7 -15
- package/assets/docs/internationalization.doc.mjs +7 -5
- package/assets/docs/layout.doc.dense.mjs +130 -82
- package/assets/docs/layout.doc.mjs +133 -77
- package/assets/docs/migration.doc.mjs +19 -21
- package/assets/docs/motion.doc.mjs +16 -3
- package/assets/docs/principles.doc.dense.mjs +5 -5
- package/assets/docs/principles.doc.mjs +8 -0
- package/assets/docs/principles.doc.zh.mjs +6 -6
- package/assets/docs/shape.doc.mjs +8 -3
- package/assets/docs/spacing.doc.mjs +7 -2
- package/assets/docs/styling-libraries.doc.mjs +6 -2
- package/assets/docs/styling.doc.mjs +19 -23
- package/assets/docs/theme.doc.dense.mjs +58 -18
- package/assets/docs/theme.doc.mjs +57 -47
- package/assets/docs/theme.doc.zh.mjs +9 -8
- package/assets/docs/tokens.doc.dense.mjs +2 -2
- package/assets/docs/tokens.doc.mjs +389 -8
- package/assets/docs/tokens.doc.zh.mjs +2 -2
- package/assets/docs/tree/add-a-component.doc.mjs +75 -0
- package/assets/docs/tree/add-a-theme.doc.mjs +85 -0
- package/assets/docs/tree/add-a-topic.doc.mjs +144 -0
- package/assets/docs/tree/agent-guidance.doc.mjs +138 -0
- package/assets/docs/tree/block-template.doc.mjs +130 -0
- package/assets/docs/tree/build-the-template.doc.mjs +28 -0
- package/assets/docs/tree/building-blocks.doc.mjs +46 -0
- package/assets/docs/tree/check-your-docs.doc.mjs +137 -0
- package/assets/docs/tree/checks.doc.mjs +119 -0
- package/assets/docs/tree/codemods.doc.mjs +147 -0
- package/assets/docs/tree/component-family.doc.mjs +113 -0
- package/assets/docs/tree/component-imports.doc.mjs +69 -0
- package/assets/docs/tree/component-lookups.doc.mjs +149 -0
- package/assets/docs/tree/components.doc.mjs +23 -0
- package/assets/docs/tree/configuration.doc.mjs +23 -0
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +182 -0
- package/assets/docs/tree/define-the-theme.doc.mjs +118 -0
- package/assets/docs/tree/describe-the-component.doc.mjs +57 -0
- package/assets/docs/tree/docs.doc.mjs +21 -0
- package/assets/docs/tree/document-the-template.doc.mjs +28 -0
- package/assets/docs/tree/document-the-theme.doc.mjs +68 -0
- package/assets/docs/tree/export-template-assets.doc.mjs +147 -0
- package/assets/docs/tree/extend-or-replace.doc.mjs +103 -0
- package/assets/docs/tree/fonts-and-assets.doc.mjs +106 -0
- package/assets/docs/tree/generate-a-palette.doc.mjs +66 -0
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +105 -0
- package/assets/docs/tree/help.doc.mjs +16 -0
- package/assets/docs/tree/integrations.doc.mjs +25 -451
- package/assets/docs/tree/links.doc.mjs +98 -0
- package/assets/docs/tree/package-and-test.doc.mjs +32 -0
- package/assets/docs/tree/page-template.doc.mjs +71 -0
- package/assets/docs/tree/publishing.doc.mjs +111 -0
- package/assets/docs/tree/quick-start.doc.mjs +272 -0
- package/assets/docs/tree/replace-a-core-component.doc.mjs +104 -0
- package/assets/docs/tree/replace-a-core-template.doc.mjs +172 -0
- package/assets/docs/tree/sections-and-placement.doc.mjs +108 -0
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +59 -0
- package/assets/docs/tree/ship.doc.mjs +16 -0
- package/assets/docs/tree/short-and-findable.doc.mjs +108 -0
- package/assets/docs/tree/single-component.doc.mjs +165 -0
- package/assets/docs/tree/start-a-template.doc.mjs +143 -0
- package/assets/docs/tree/subcomponent.doc.mjs +115 -0
- package/assets/docs/tree/template-assets.doc.mjs +64 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +109 -0
- package/assets/docs/tree/template-fonts.doc.mjs +102 -0
- package/assets/docs/tree/template-grading-rubric.doc.mjs +452 -0
- package/assets/docs/tree/template-icons.doc.mjs +97 -0
- package/assets/docs/tree/template-images-media.doc.mjs +127 -0
- package/assets/docs/tree/template-styles.doc.mjs +93 -0
- package/assets/docs/tree/templates.doc.mjs +34 -0
- package/assets/docs/tree/test-in-an-app.doc.mjs +115 -0
- package/assets/docs/tree/test-template-in-app.doc.mjs +128 -0
- package/assets/docs/tree/themes.doc.mjs +39 -0
- package/assets/docs/tree/troubleshooting.doc.mjs +149 -0
- package/assets/docs/tree/upgrading.doc.mjs +103 -0
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +51 -0
- package/assets/docs/tree/verify-packed-template.doc.mjs +77 -0
- package/assets/docs/tree/versioning.doc.mjs +161 -0
- package/assets/docs/tree/write-good-templates.doc.mjs +64 -0
- package/assets/docs/tree/write-the-template-file.doc.mjs +154 -0
- package/assets/docs/typography.doc.mjs +24 -4
- package/assets/docs/working-with-ai.doc.mjs +30 -22
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- 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 +11 -0
- 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 +3 -2
- package/authoring/doctypes/_schema.mjs +6 -0
- package/authoring/doctypes/base/graph-fields.doc.mjs +3 -3
- package/authoring/doctypes/base/type.ts +4 -2
- package/authoring/doctypes/component/component.doc.mjs +6 -0
- package/authoring/doctypes/component/type.ts +8 -0
- package/authoring/doctypes/reference/reference.doc.mjs +7 -0
- package/authoring/doctypes/reference/type.ts +5 -0
- package/authoring/doctypes/schema/schema.doc.mjs +2 -2
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -2
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +10 -0
- package/authoring/index.mjs +1 -0
- package/authoring/integration/integration.doc.mjs +12 -10
- 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 +27 -9
- 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.doc.mjs +1 -1
- package/clients/cli/commands/docs.mjs +60 -17
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +3 -2
- package/clients/cli/commands/doctor-integration.test.mjs +53 -0
- package/clients/cli/commands/doctor.doc.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +49 -5
- package/clients/cli/commands/gap-report.doc.mjs +10 -9
- package/clients/cli/commands/init.doc.mjs +9 -6
- package/clients/cli/commands/integration-add.doc.mjs +9 -9
- package/clients/cli/commands/integration-authoring.test.mjs +61 -10
- package/clients/cli/commands/integration-pack.doc.mjs +5 -9
- package/clients/cli/commands/integration-real-world.test.mjs +1 -1
- package/clients/cli/commands/integration-verify.doc.mjs +22 -0
- package/clients/cli/commands/integration.doc.mjs +4 -4
- package/clients/cli/commands/integration.mjs +74 -43
- package/clients/cli/commands/manifest.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +10 -3
- package/clients/cli/commands/search.mjs +21 -2
- package/clients/cli/commands/search.test.mjs +21 -4
- package/clients/cli/commands/swizzle.doc.mjs +1 -1
- package/clients/cli/commands/template.doc.mjs +1 -1
- package/clients/cli/commands/text-json-parity.test.mjs +7 -1
- package/clients/cli/commands/theme-add.doc.mjs +1 -1
- package/clients/cli/commands/theme-palette-generate.doc.mjs +3 -2
- package/clients/cli/commands/theme-palette.doc.mjs +1 -2
- package/clients/cli/commands/theme-targets.doc.mjs +2 -2
- package/clients/cli/commands/theme.doc.mjs +2 -1
- package/clients/cli/commands/upgrade.doc.mjs +62 -3
- package/clients/cli/index.mjs +28 -6
- package/clients/cli/lib/define-command.mjs +28 -4
- package/clients/cli/lib/define-command.test.mjs +54 -0
- package/clients/cli/lib/exit-codes.test.mjs +17 -1
- package/clients/cli/lib/json-shim.mjs +24 -14
- package/clients/cli/lib/manifest.mjs +18 -5
- package/clients/cli/lib/manifest.test.mjs +5 -2
- package/clients/cli/lib/parse-error-format.test.mjs +81 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/authoring-self-docs.test.mjs +6 -2
- package/foundation/discovery/cli-self-docs.mjs +16 -2
- package/foundation/discovery/cli-self-docs.test.mjs +20 -0
- package/foundation/discovery/docs-discovery.mjs +5 -1
- package/foundation/discovery/docs-discovery.test.mjs +21 -0
- package/foundation/discovery/docs-section-key.d.mts +1 -1
- package/foundation/discovery/docs-section-key.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -2
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/tree.d.mts +4 -0
- package/foundation/doc-compiler/tree.mjs +6 -1
- package/foundation/integrations/cli-requirement.d.mts +26 -6
- package/foundation/integrations/cli-requirement.mjs +46 -11
- package/foundation/integrations/cli-requirement.test.mjs +7 -2
- package/foundation/integrations/contribution-inventory.mjs +1 -1
- 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/error-codes.doc.mjs +6 -8
- package/foundation/response/error-codes.test.mjs +30 -5
- package/foundation/response/response-types.doc.d.mts +4 -3
- package/foundation/response/response-types.doc.mjs +40 -10
- package/foundation/response/response-types.doc.test.mjs +23 -0
- package/foundation/response/response.doc.mjs +11 -10
- package/package.json +9 -9
- package/api/docs/docs.test.mjs +0 -243
- package/api/docs/integration-tree.test.mjs +0 -555
- package/api/docs/integrationDocs.test.mjs +0 -314
- package/api/search/search.test.mjs +0 -512
- package/assets/docs/tree/integrations.test.mjs +0 -62
- package/assets/docs/tree/writing-docs.doc.mjs +0 -286
- package/clients/cli/commands/docs.test.mjs +0 -294
- package/foundation/agent-docs/agent-docs.test.mjs +0 -1159
- package/foundation/doc-compiler/tree.test.mjs +0 -598
package/api/build/kit/kit.mjs
CHANGED
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import {search} from '../../search/search.mjs';
|
|
31
|
+
import {findCoreDir} from '../../../foundation/fs/paths.mjs';
|
|
32
|
+
import {AstryxError} from '../../error.mjs';
|
|
33
|
+
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
31
34
|
import {getResultCoverage} from '../../search/coverage.mjs';
|
|
32
35
|
import {loadPageTemplates} from '../_adapter.mjs';
|
|
33
36
|
import {pickAlternatives, pickStart, rankPages} from './rank.mjs';
|
|
@@ -188,12 +191,30 @@ function chooseStart(ranked, pages, directMatch, catalog) {
|
|
|
188
191
|
*/
|
|
189
192
|
export async function buildKit(query, options = {}) {
|
|
190
193
|
const {cwd = process.cwd(), type, limit = 60} = options;
|
|
194
|
+
// A kit is built from Core's components, hooks, and templates. An open
|
|
195
|
+
// search without core covers the docs alone, so the kit asks for core here.
|
|
196
|
+
if (type !== 'doc' && !findCoreDir(cwd)) {
|
|
197
|
+
throw new AstryxError(
|
|
198
|
+
'Could not find @astryxdesign/core package',
|
|
199
|
+
undefined,
|
|
200
|
+
ERROR_CODES.ERR_CORE_NOT_FOUND,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
191
203
|
// search()'s JSDoc @returns widens results to object[]; the SearchResponse
|
|
192
204
|
// shape is the contract (api/search/search.type.mjs). Cast locally rather than
|
|
193
205
|
// tightening the search @returns (a separate follow-up).
|
|
194
206
|
const result =
|
|
195
207
|
/** @type {import('../../search/search.type.mjs').SearchResponse} */ (
|
|
196
|
-
await search(query, {
|
|
208
|
+
await search(query, {
|
|
209
|
+
cwd,
|
|
210
|
+
type,
|
|
211
|
+
// Search wider than the surfaced kit so a flood of doc matches cannot
|
|
212
|
+
// bury the page templates past the cutoff; the caller's `limit` still
|
|
213
|
+
// caps the kit below. A non-positive or non-integer limit is passed
|
|
214
|
+
// through unchanged so search rejects it (ERR_INVALID_ARGUMENT).
|
|
215
|
+
limit:
|
|
216
|
+
Number.isInteger(limit) && limit > 0 ? Math.max(limit, 200) : limit,
|
|
217
|
+
})
|
|
197
218
|
);
|
|
198
219
|
const results = result.data.results;
|
|
199
220
|
// The TOTAL number of matches, not the number that survived `limit`. The kit
|
|
@@ -257,6 +278,24 @@ export async function buildKit(query, options = {}) {
|
|
|
257
278
|
command: `${page.command} --skeleton`,
|
|
258
279
|
}));
|
|
259
280
|
|
|
281
|
+
// The caller's `limit` caps the surfaced kit, even though the search above
|
|
282
|
+
// ran wider to find templates that a flood of doc matches would otherwise
|
|
283
|
+
// bury past the cutoff. Keep pages first, then blocks, then components.
|
|
284
|
+
let budget = limit;
|
|
285
|
+
/**
|
|
286
|
+
* @template T
|
|
287
|
+
* @param {T[]} arr
|
|
288
|
+
* @returns {T[]}
|
|
289
|
+
*/
|
|
290
|
+
const toLimit = arr => {
|
|
291
|
+
const out = arr.slice(0, Math.max(0, budget));
|
|
292
|
+
budget -= out.length;
|
|
293
|
+
return out;
|
|
294
|
+
};
|
|
295
|
+
const pagesKept = toLimit(pages);
|
|
296
|
+
const blocksKept = toLimit(blocks);
|
|
297
|
+
const domainKept = toLimit(domain);
|
|
298
|
+
|
|
260
299
|
// A kit narrowed to components or hooks has no page to start from; every
|
|
261
300
|
// other kit does, so the reader is never left to compose a page from scratch.
|
|
262
301
|
const wantsPages = !type || type === 'template';
|
|
@@ -288,7 +327,7 @@ export async function buildKit(query, options = {}) {
|
|
|
288
327
|
// not resolve — the same defect `getCliInvocation` exists to prevent, and
|
|
289
328
|
// the renderer applies it. A JSON caller gets the parts, not a sentence.
|
|
290
329
|
const hint =
|
|
291
|
-
|
|
330
|
+
pagesKept.length + blocksKept.length + domainKept.length < THIN_KIT
|
|
292
331
|
? {
|
|
293
332
|
reason:
|
|
294
333
|
'Few matches. This is keyword search, not semantic — try other wordings.',
|
|
@@ -306,9 +345,9 @@ export async function buildKit(query, options = {}) {
|
|
|
306
345
|
matchCount,
|
|
307
346
|
directMatch,
|
|
308
347
|
start,
|
|
309
|
-
pages,
|
|
310
|
-
blocks,
|
|
311
|
-
domain,
|
|
348
|
+
pages: pagesKept,
|
|
349
|
+
blocks: blocksKept,
|
|
350
|
+
domain: domainKept,
|
|
312
351
|
frame: FRAME,
|
|
313
352
|
foundation: FOUNDATION,
|
|
314
353
|
hint,
|
|
@@ -68,6 +68,16 @@ export function requireCoreDir(cwd: string): string;
|
|
|
68
68
|
* @returns {Promise<import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]>}
|
|
69
69
|
*/
|
|
70
70
|
export function loadIntegrationsSafely(cwd: string): Promise<import("../../foundation/integrations/integrations.mjs").LoadedIntegration[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Read the exact installed version available to a package-qualified component
|
|
73
|
+
* selector. Legacy docs packages do not expose a reliable version here, so a
|
|
74
|
+
* version-qualified lookup never falls through to them.
|
|
75
|
+
* @param {string} coreDir
|
|
76
|
+
* @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
|
|
77
|
+
* @param {string} packageName
|
|
78
|
+
* @returns {string|null}
|
|
79
|
+
*/
|
|
80
|
+
export function installedComponentPackageVersion(coreDir: string, loadedIntegrations: import("../../foundation/integrations/integrations.mjs").LoadedIntegration[], packageName: string): string | null;
|
|
71
81
|
/**
|
|
72
82
|
* Build the set of OWNER packages that provide a component with this name
|
|
73
83
|
* across core + every loaded integration. This is what lets the CLI
|
|
@@ -180,6 +190,20 @@ export function scopeSubComponent(docs: LoadedComponentDoc, dirName: string, cor
|
|
|
180
190
|
matchingComponent: any;
|
|
181
191
|
} | null;
|
|
182
192
|
export { CORE_PACKAGE };
|
|
193
|
+
/**
|
|
194
|
+
* Internal ambiguity marker. Single-component callers still receive the same
|
|
195
|
+
* AstryxError code, message, and suggestions; batch callers can additionally
|
|
196
|
+
* project every installed candidate without parsing prose.
|
|
197
|
+
*/
|
|
198
|
+
export class ComponentAmbiguityError extends AstryxError {
|
|
199
|
+
/**
|
|
200
|
+
* @param {ComponentOwner[]} owners
|
|
201
|
+
* @param {string} dirName
|
|
202
|
+
*/
|
|
203
|
+
constructor(owners: ComponentOwner[], dirName: string);
|
|
204
|
+
/** @type {import('./component.type.mjs').ComponentBatchCandidate[]} */
|
|
205
|
+
candidates: import("./component.type.mjs").ComponentBatchCandidate[];
|
|
206
|
+
}
|
|
183
207
|
/**
|
|
184
208
|
* A loaded component doc. The shared validated loader accepts stamped and legacy
|
|
185
209
|
* component docs; this loose view captures the fields the API reads across both.
|
|
@@ -258,3 +282,4 @@ export type ResolvedUnscopedDoc = {
|
|
|
258
282
|
resolvedSourcePath: string | null;
|
|
259
283
|
};
|
|
260
284
|
import { CORE_PACKAGE } from '../../foundation/discovery/component-discovery.mjs';
|
|
285
|
+
import { AstryxError } from '../error.mjs';
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* deduped, so each leaf stays a thin projection.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import * as fs from 'node:fs';
|
|
22
|
+
import * as path from 'node:path';
|
|
21
23
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
22
24
|
import {
|
|
23
25
|
findCoreDir,
|
|
@@ -146,6 +148,34 @@ function findLoadedIntegration(loadedIntegrations, packageName) {
|
|
|
146
148
|
return loadedIntegrations.find(i => i.name === packageName) ?? null;
|
|
147
149
|
}
|
|
148
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Read the exact installed version available to a package-qualified component
|
|
153
|
+
* selector. Legacy docs packages do not expose a reliable version here, so a
|
|
154
|
+
* version-qualified lookup never falls through to them.
|
|
155
|
+
* @param {string} coreDir
|
|
156
|
+
* @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
|
|
157
|
+
* @param {string} packageName
|
|
158
|
+
* @returns {string|null}
|
|
159
|
+
*/
|
|
160
|
+
export function installedComponentPackageVersion(
|
|
161
|
+
coreDir,
|
|
162
|
+
loadedIntegrations,
|
|
163
|
+
packageName,
|
|
164
|
+
) {
|
|
165
|
+
if (packageName === CORE_PACKAGE) {
|
|
166
|
+
try {
|
|
167
|
+
const pkg = JSON.parse(
|
|
168
|
+
fs.readFileSync(path.join(coreDir, 'package.json'), 'utf8'),
|
|
169
|
+
);
|
|
170
|
+
return typeof pkg.version === 'string' ? pkg.version : null;
|
|
171
|
+
} catch {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const integration = findLoadedIntegration(loadedIntegrations, packageName);
|
|
176
|
+
return typeof integration?.version === 'string' ? integration.version : null;
|
|
177
|
+
}
|
|
178
|
+
|
|
149
179
|
/**
|
|
150
180
|
* Resolve an external package by name from the discovered externals list.
|
|
151
181
|
* @param {string} packageName - e.g. '@acme/xds-widgets'
|
|
@@ -244,6 +274,34 @@ export function classifyScope(
|
|
|
244
274
|
return {kind: 'legacy', ext};
|
|
245
275
|
}
|
|
246
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Internal ambiguity marker. Single-component callers still receive the same
|
|
279
|
+
* AstryxError code, message, and suggestions; batch callers can additionally
|
|
280
|
+
* project every installed candidate without parsing prose.
|
|
281
|
+
*/
|
|
282
|
+
export class ComponentAmbiguityError extends AstryxError {
|
|
283
|
+
/** @type {import('./component.type.mjs').ComponentBatchCandidate[]} */
|
|
284
|
+
candidates;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @param {ComponentOwner[]} owners
|
|
288
|
+
* @param {string} dirName
|
|
289
|
+
*/
|
|
290
|
+
constructor(owners, dirName) {
|
|
291
|
+
super(
|
|
292
|
+
`Component "${dirName}" is provided by multiple packages. Re-run with --package <pkg> to choose one.`,
|
|
293
|
+
owners.map(o => ({name: o.package, reason: 'provides this component'})),
|
|
294
|
+
ERROR_CODES.ERR_UNKNOWN_COMPONENT,
|
|
295
|
+
);
|
|
296
|
+
this.candidates = owners.map(owner => ({
|
|
297
|
+
package: owner.package,
|
|
298
|
+
component: dirName,
|
|
299
|
+
kind: 'component',
|
|
300
|
+
installed: true,
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
247
305
|
/**
|
|
248
306
|
* Refuse to guess when the name is owned by MORE THAN ONE package (core and/or
|
|
249
307
|
* integrations) and the caller did not scope with --package. Legacy
|
|
@@ -254,11 +312,7 @@ export function classifyScope(
|
|
|
254
312
|
*/
|
|
255
313
|
export function assertUnambiguousOwners(owners, dirName) {
|
|
256
314
|
if (owners.length > 1) {
|
|
257
|
-
throw new
|
|
258
|
-
`Component "${dirName}" is provided by multiple packages. Re-run with --package <pkg> to choose one.`,
|
|
259
|
-
owners.map(o => ({name: o.package, reason: 'provides this component'})),
|
|
260
|
-
ERROR_CODES.ERR_UNKNOWN_COMPONENT,
|
|
261
|
-
);
|
|
315
|
+
throw new ComponentAmbiguityError(owners, dirName);
|
|
262
316
|
}
|
|
263
317
|
}
|
|
264
318
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @param {string} [name]
|
|
5
|
+
* @param {string|string[]} [name]
|
|
6
6
|
* @param {object} [options]
|
|
7
7
|
* @param {string} [options.cwd]
|
|
8
8
|
* @param {boolean} [options.list]
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* @param {boolean} [options.dense]
|
|
19
19
|
* @returns {Promise<(
|
|
20
20
|
* import('./component.type.mjs').ComponentListResponse
|
|
21
|
+
* | import('./component.type.mjs').ComponentBatchResponse
|
|
21
22
|
* | import('./component.type.mjs').ComponentDetailResponse
|
|
22
23
|
* | import('./component.type.mjs').ComponentDetailPropsResponse
|
|
23
24
|
* | import('./component.type.mjs').ComponentDetailSourceResponse
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
* | import('./component.type.mjs').ComponentDetailBlocksResponse
|
|
26
27
|
* )>}
|
|
27
28
|
*/
|
|
28
|
-
export function component(name?: string, options?: {
|
|
29
|
+
export function component(name?: string | string[], options?: {
|
|
29
30
|
cwd?: string | undefined;
|
|
30
31
|
list?: boolean | undefined;
|
|
31
32
|
category?: string | undefined;
|
|
@@ -38,4 +39,6 @@ export function component(name?: string, options?: {
|
|
|
38
39
|
lang?: string | undefined;
|
|
39
40
|
zh?: boolean | undefined;
|
|
40
41
|
dense?: boolean | undefined;
|
|
41
|
-
}): Promise<(import("./component.type.mjs").ComponentListResponse | import("./component.type.mjs").ComponentDetailResponse | import("./component.type.mjs").ComponentDetailPropsResponse | import("./component.type.mjs").ComponentDetailSourceResponse | import("./component.type.mjs").ComponentDetailShowcaseResponse | import("./component.type.mjs").ComponentDetailBlocksResponse)>;
|
|
42
|
+
}): Promise<(import("./component.type.mjs").ComponentListResponse | import("./component.type.mjs").ComponentBatchResponse | import("./component.type.mjs").ComponentDetailResponse | import("./component.type.mjs").ComponentDetailPropsResponse | import("./component.type.mjs").ComponentDetailSourceResponse | import("./component.type.mjs").ComponentDetailShowcaseResponse | import("./component.type.mjs").ComponentDetailBlocksResponse)>;
|
|
43
|
+
/** Maximum selectors accepted before any component resolution starts. */
|
|
44
|
+
export const COMPONENT_BATCH_SELECTOR_LIMIT: 100;
|
|
@@ -15,16 +15,16 @@ export const doc = {
|
|
|
15
15
|
namespace: 'cli/api',
|
|
16
16
|
displayName: 'component()',
|
|
17
17
|
summary:
|
|
18
|
-
'Resolve
|
|
18
|
+
'Resolve one or several components by name, or list the catalog, with optional focused slices (props, source, showcase, blocks).',
|
|
19
19
|
description:
|
|
20
|
-
'Routes on its arguments:
|
|
21
|
-
'integration packages
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
20
|
+
'Routes on its arguments: one string resolves that component across core and ' +
|
|
21
|
+
'integration packages; an array returns one ordered result row per selector at ' +
|
|
22
|
+
'every array length; and no name returns the catalog grouped by category. ' +
|
|
23
|
+
'Boolean flags narrow each resolved component to just its props, source, ' +
|
|
24
|
+
'showcase, or example blocks.',
|
|
25
25
|
importPath: '@astryxdesign/cli/api',
|
|
26
26
|
signature:
|
|
27
|
-
'component(name?: string, options?: ComponentOptions): Promise<ComponentListResponse | ComponentDetailResponse | ComponentDetailPropsResponse | ComponentDetailSourceResponse | ComponentDetailShowcaseResponse | ComponentDetailBlocksResponse>',
|
|
27
|
+
'component(name?: string | string[], options?: ComponentOptions): Promise<ComponentListResponse | ComponentBatchResponse | ComponentDetailResponse | ComponentDetailPropsResponse | ComponentDetailSourceResponse | ComponentDetailShowcaseResponse | ComponentDetailBlocksResponse>',
|
|
28
28
|
keywords: [
|
|
29
29
|
'component',
|
|
30
30
|
'components',
|
|
@@ -37,14 +37,15 @@ export const doc = {
|
|
|
37
37
|
params: [
|
|
38
38
|
{
|
|
39
39
|
name: 'name',
|
|
40
|
-
type: 'string',
|
|
40
|
+
type: 'string | string[]',
|
|
41
41
|
description:
|
|
42
|
-
"
|
|
42
|
+
"Pass one selector string for the existing single-result response, or an array of at most 100 selectors for an ordered component.batch response. The limit counts duplicates in every projection mode. An array always requests a batch, including [] and ['Button']. Use 'Button', 'widgets/Button', '@acme/widgets/Button', or '@acme/widgets@1.2.3/Button'. A version applies to the package and must match the installed version. Omit the argument to list the catalog.",
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
name: 'options.cwd',
|
|
46
46
|
type: 'string',
|
|
47
47
|
description: 'Directory to resolve @astryxdesign/core from.',
|
|
48
|
+
default: 'process.cwd()',
|
|
48
49
|
},
|
|
49
50
|
{
|
|
50
51
|
name: 'options.list',
|
|
@@ -54,13 +55,14 @@ export const doc = {
|
|
|
54
55
|
{
|
|
55
56
|
name: 'options.category',
|
|
56
57
|
type: 'string',
|
|
57
|
-
description:
|
|
58
|
+
description:
|
|
59
|
+
"List only the components in this group: a key of the unfiltered list (each component's group field), such as 'Layout' or 'Button'. It is not the category field of a component detail.",
|
|
58
60
|
},
|
|
59
61
|
{
|
|
60
62
|
name: 'options.package',
|
|
61
63
|
type: 'string',
|
|
62
64
|
description:
|
|
63
|
-
"Scope lookup to a specific external package (e.g. '@acme/
|
|
65
|
+
"Scope lookup to a specific external package (e.g. '@acme/widgets').",
|
|
64
66
|
},
|
|
65
67
|
{
|
|
66
68
|
name: 'options.props',
|
|
@@ -87,7 +89,8 @@ export const doc = {
|
|
|
87
89
|
name: 'options.detail',
|
|
88
90
|
type: "'full' | 'compact' | 'brief'",
|
|
89
91
|
description: 'Detail level for list views.',
|
|
90
|
-
default:
|
|
92
|
+
default:
|
|
93
|
+
"'full' for a named component; 'brief' for lists (returned as data.detail: 'names')",
|
|
91
94
|
},
|
|
92
95
|
{
|
|
93
96
|
name: 'options.lang',
|
|
@@ -110,7 +113,12 @@ export const doc = {
|
|
|
110
113
|
{
|
|
111
114
|
type: 'component.list',
|
|
112
115
|
description:
|
|
113
|
-
"The catalog grouped by
|
|
116
|
+
"The catalog grouped by component group. data.detail is the level ('names' | 'compact' | 'full') and data.components is the grouped map: names entries with name, package, and an optional canonical import for integration and legacy package components; brief entries; or full ComponentDoc entries.",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: 'component.batch',
|
|
120
|
+
description:
|
|
121
|
+
'An explicit selector array returns one ordered receipt at every array length: count and one results row per selector, including duplicates. ComponentBatchResponse specializes the shared BatchResponse and BatchRow types. Each row carries selector and status (found, not_found, ambiguous, or error); found rows carry the single-selector result, ambiguous rows carry installed candidates ({package, component, kind, installed}), and failed rows carry code, error, and optional suggestions.',
|
|
114
122
|
},
|
|
115
123
|
{
|
|
116
124
|
type: 'component.detail',
|
|
@@ -137,6 +145,10 @@ export const doc = {
|
|
|
137
145
|
},
|
|
138
146
|
],
|
|
139
147
|
throws: [
|
|
148
|
+
{
|
|
149
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
150
|
+
when: 'a selector array has more than 100 entries, a package-shaped selector has no component item, or its package conflicts with options.package',
|
|
151
|
+
},
|
|
140
152
|
{
|
|
141
153
|
code: 'ERR_INVALID_DETAIL',
|
|
142
154
|
when: "options.detail is not 'full', 'compact', or 'brief'",
|
|
@@ -151,7 +163,7 @@ export const doc = {
|
|
|
151
163
|
},
|
|
152
164
|
{
|
|
153
165
|
code: 'ERR_UNKNOWN_CATEGORY',
|
|
154
|
-
when: 'options.category is not a string or matches no
|
|
166
|
+
when: 'options.category is not a string or matches no component group',
|
|
155
167
|
},
|
|
156
168
|
{
|
|
157
169
|
code: 'ERR_UNKNOWN_COMPONENT',
|
|
@@ -159,12 +171,16 @@ export const doc = {
|
|
|
159
171
|
},
|
|
160
172
|
{
|
|
161
173
|
code: 'ERR_UNKNOWN_PACKAGE',
|
|
162
|
-
when: 'options.package names a legacy external package that cannot be found',
|
|
174
|
+
when: 'options.package names a legacy external package that cannot be found, or a package-qualified selector requests a version that is not installed',
|
|
163
175
|
},
|
|
164
176
|
{
|
|
165
177
|
code: 'ERR_NO_DOC',
|
|
166
178
|
when: 'the resolved component has no .doc.mjs typed doc file',
|
|
167
179
|
},
|
|
180
|
+
{
|
|
181
|
+
code: 'ERR_INVALID_DOC',
|
|
182
|
+
when: "the resolved component's .doc.mjs fails to load or validate",
|
|
183
|
+
},
|
|
168
184
|
{
|
|
169
185
|
code: 'ERR_NO_SOURCE',
|
|
170
186
|
when: 'options.source is set but the component has no source file',
|
|
@@ -179,10 +195,14 @@ export const doc = {
|
|
|
179
195
|
label: 'Look up a component',
|
|
180
196
|
code: "const r = await component('Button');",
|
|
181
197
|
},
|
|
198
|
+
{
|
|
199
|
+
label: 'Look up several components',
|
|
200
|
+
code: "await component(['Button', 'Badge']);",
|
|
201
|
+
},
|
|
182
202
|
{label: 'Props only', code: "await component('Button', {props: true});"},
|
|
183
203
|
{
|
|
184
|
-
label: 'Browse
|
|
185
|
-
code: "await component(undefined, {category: '
|
|
204
|
+
label: 'Browse one group',
|
|
205
|
+
code: "await component(undefined, {category: 'Layout', detail: 'compact'});",
|
|
186
206
|
},
|
|
187
207
|
],
|
|
188
208
|
command: 'component',
|