@astryxdesign/cli 0.6.5-canary.f261d2f → 0.6.5-canary.f2f43e1
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 +58 -55
- package/api/build/_adapter.d.mts +19 -0
- package/api/build/_adapter.mjs +60 -1
- package/api/build/build.test.mjs +74 -1
- package/api/build/build.type.d.mts +8 -0
- package/api/build/build.type.mjs +2 -0
- package/api/build/kit/kit.mjs +40 -7
- package/api/build/kit/rank.d.mts +8 -0
- package/api/build/kit/rank.mjs +14 -0
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/component/_adapter.d.mts +19 -0
- package/api/component/_adapter.mjs +33 -0
- package/api/component/component-replacement.test.mjs +603 -0
- package/api/component/component.mjs +49 -15
- package/api/component/component.test.mjs +32 -0
- package/api/component/component.type.d.mts +33 -3
- package/api/component/component.type.mjs +10 -3
- package/api/component/detail/blocks/blocks.d.mts +2 -1
- package/api/component/detail/blocks/blocks.mjs +5 -2
- package/api/component/detail/detail.mjs +5 -1
- package/api/component/detail/props/props.d.mts +2 -1
- package/api/component/detail/props/props.mjs +3 -2
- package/api/component/detail/showcase/showcase.d.mts +3 -1
- package/api/component/detail/showcase/showcase.mjs +3 -1
- package/api/component/detail/source/source.d.mts +3 -2
- package/api/component/detail/source/source.mjs +7 -3
- package/api/component/list/list.mjs +128 -10
- package/api/docs/_adapter.d.mts +11 -0
- package/api/docs/_adapter.mjs +25 -0
- package/api/docs/detail/detail.mjs +19 -3
- package/api/docs/detail/section/section.mjs +7 -1
- package/api/docs/docOverlays.test.mjs +10 -6
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +134 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +46 -1
- package/api/docs/docs.test.mjs +1 -1
- package/api/docs/docs.type.d.mts +81 -4
- package/api/docs/docs.type.mjs +41 -4
- package/api/docs/index/index.mjs +11 -2
- package/api/docs/index/index.test.mjs +7 -2
- package/api/docs/integrationDocs.test.mjs +6 -5
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +149 -23
- package/api/doctor/_adapter.d.mts +43 -0
- package/api/doctor/_adapter.mjs +142 -0
- package/api/doctor/doctor.d.mts +0 -10
- package/api/doctor/doctor.doc.mjs +1 -3
- package/api/doctor/doctor.mjs +6 -123
- package/api/doctor/theme-checks.d.mts +12 -0
- package/api/doctor/theme-checks.mjs +1117 -0
- package/api/doctor/theme-checks.test.mjs +526 -0
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +27 -3
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/_adapter.d.mts +1 -0
- package/api/hook/_adapter.mjs +3 -0
- package/api/hook/detail/detail.mjs +2 -2
- package/api/hook/detail/params/params.mjs +2 -2
- package/api/hook/hook.type.d.mts +12 -0
- package/api/hook/hook.type.mjs +3 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/hook/list/list.mjs +8 -8
- package/api/index.d.mts +1 -1
- package/api/index.mjs +4 -0
- package/api/init/run/run.d.mts +3 -5
- package/api/init/run/run.mjs +10 -11
- package/api/integration/__fixtures__/released-0.6.5-ocean.d.mts +14 -0
- package/api/integration/__fixtures__/released-0.6.5-ocean.mjs +15 -0
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-helpers.d.mts +26 -5
- package/api/integration/add-helpers.mjs +50 -5
- package/api/integration/add-theme.mjs +352 -27
- package/api/integration/add-theme.test.mjs +379 -15
- package/api/integration/authoring-checks.mjs +31 -8
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +6 -3
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.component-replaces.test.mjs +126 -0
- package/api/integration/pack-check.d.mts +10 -0
- package/api/integration/pack-check.lifecycle-output.test.mjs +21 -2
- package/api/integration/pack-check.mjs +483 -1
- package/api/integration/pack-check.test.mjs +568 -8
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +15 -8
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +179 -67
- package/api/search/search.test.mjs +128 -9
- package/api/search/search.type.d.mts +6 -6
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +23 -0
- package/api/swizzle/copy/copy.d.mts +5 -6
- package/api/swizzle/copy/copy.mjs +95 -13
- package/api/swizzle/list/list.mjs +2 -2
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/swizzle/swizzle.test.mjs +55 -5
- package/api/swizzle/swizzle.type.d.mts +8 -0
- package/api/swizzle/swizzle.type.mjs +2 -0
- package/api/template/copy/copy.mjs +15 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +17 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/skeleton/skeleton.mjs +2 -1
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +2 -0
- package/api/template/template.type.d.mts +14 -0
- package/api/template/template.type.mjs +5 -0
- package/api/theme/_adapter.d.mts +106 -6
- package/api/theme/_adapter.mjs +687 -18
- package/api/theme/add/add.binary.test.mjs +76 -3
- package/api/theme/add/add.d.mts +5 -9
- package/api/theme/add/add.mjs +87 -64
- package/api/theme/add/add.rollback.test.mjs +9 -9
- package/api/theme/add/add.staging.test.mjs +9 -9
- package/api/theme/add/add.test.mjs +461 -55
- package/api/theme/add/add.types.test.mjs +151 -0
- package/api/theme/build/build.d.mts +50 -2
- package/api/theme/build/build.family.test.mjs +13 -4
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +463 -155
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +220 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/eject/eject.binary.test.mjs +90 -0
- package/api/theme/eject/eject.d.mts +17 -0
- package/api/theme/eject/eject.mjs +65 -0
- package/api/theme/eject/eject.rollback.test.mjs +158 -0
- package/api/theme/eject/eject.staging.test.mjs +83 -0
- package/api/theme/eject/eject.test.mjs +160 -0
- package/api/theme/integration-themes.test.mjs +30 -6
- package/api/theme/list/list.d.mts +10 -0
- package/api/theme/list/list.mjs +75 -7
- package/api/theme/list/list.test.mjs +155 -4
- package/api/theme/remove/remove.d.mts +12 -0
- package/api/theme/remove/remove.mjs +15 -0
- package/api/theme/remove/remove.test.mjs +94 -0
- package/api/theme/template/template.mjs +3 -4
- package/api/theme/theme.d.mts +5 -2
- package/api/theme/theme.mjs +13 -8
- package/api/theme/theme.type.d.mts +106 -2
- package/api/theme/theme.type.mjs +54 -5
- package/api/theme/themeAdd.doc.d.mts +1 -3
- package/api/theme/themeAdd.doc.mjs +35 -22
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +15 -4
- package/api/theme/themeEject.doc.d.mts +8 -0
- package/api/theme/themeEject.doc.mjs +89 -0
- package/api/theme/themeListAvailable.doc.mjs +4 -4
- package/api/theme/themeListCopySources.doc.d.mts +8 -0
- package/api/theme/themeListCopySources.doc.mjs +60 -0
- package/api/theme/themeRemove.doc.d.mts +6 -0
- package/api/theme/themeRemove.doc.mjs +50 -0
- package/api/theme/themeTemplate.doc.mjs +4 -3
- package/api/theme/themeUse.doc.d.mts +6 -0
- package/api/theme/themeUse.doc.mjs +47 -0
- package/api/theme/use/use.d.mts +12 -0
- package/api/theme/use/use.mjs +15 -0
- package/api/theme/use/use.test.mjs +98 -0
- package/api/upgrade/_adapter.d.mts +1 -0
- package/api/upgrade/_adapter.mjs +3 -0
- package/api/upgrade/list/list.mjs +9 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +5 -0
- package/api/upgrade/upgrade.type.mjs +2 -0
- package/assets/codemods/integration-discovery.mjs +1 -1
- package/assets/codemods/integration-discovery.test.mjs +64 -0
- package/assets/codemods/transforms/next/__tests__/migrate-copied-themes-to-descriptors.test.mjs +129 -0
- package/assets/codemods/transforms/next/index.mjs +14 -1
- package/assets/codemods/transforms/next/migrate-copied-themes-to-descriptors.mjs +54 -0
- package/assets/docs/author-a-theme.doc.mjs +161 -0
- package/assets/docs/getting-started.doc.mjs +59 -15
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/principles.doc.dense.mjs +2 -2
- package/assets/docs/principles.doc.mjs +2 -2
- package/assets/docs/principles.doc.zh.mjs +2 -2
- package/assets/docs/styling-libraries.doc.mjs +1 -1
- package/assets/docs/styling.doc.mjs +2 -2
- package/assets/docs/theme.doc.dense.mjs +10 -198
- package/assets/docs/theme.doc.mjs +13 -770
- package/assets/docs/theme.doc.zh.mjs +31 -12
- package/assets/docs/tokens.doc.mjs +4 -4
- package/assets/docs/tree/add-a-theme.doc.mjs +6 -2
- package/assets/docs/tree/checks.doc.mjs +5 -4
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +4 -4
- package/assets/docs/tree/fonts-and-assets.doc.mjs +25 -20
- package/assets/docs/tree/headers-and-footers.doc.mjs +68 -0
- package/assets/docs/tree/layout-spacing.doc.mjs +168 -0
- package/assets/docs/tree/layout.doc.mjs +32 -0
- package/assets/docs/tree/replace-a-core-component.doc.mjs +21 -4
- package/assets/docs/tree/responsive.doc.mjs +102 -0
- package/assets/docs/tree/scaffold.doc.mjs +145 -0
- package/assets/docs/tree/side-panels.doc.mjs +82 -0
- package/assets/docs/tree/structure.doc.mjs +144 -0
- package/assets/docs/tree/themes.doc.mjs +2 -2
- package/assets/docs/tree/troubleshooting.doc.mjs +4 -0
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +22 -5
- package/assets/docs/tree/versioning.doc.mjs +4 -1
- package/assets/docs/use-a-theme.doc.mjs +97 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/table-collapsible/page.tsx +1474 -0
- package/assets/templates/pages/table-collapsible/template.doc.mjs +12 -0
- package/assets/templates/pages/table-comparison/page.tsx +1449 -0
- package/assets/templates/pages/table-comparison/template.doc.mjs +12 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/command/command.doc.mjs +5 -0
- package/authoring/doctypes/command/type.ts +2 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/component/type.ts +8 -4
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.mjs +279 -30
- package/clients/cli/commands/build.mjs +7 -6
- package/clients/cli/commands/build.text-fields.test.mjs +1 -1
- package/clients/cli/commands/component/index.mjs +88 -12
- package/clients/cli/commands/component-replacement.text.test.mjs +271 -0
- package/clients/cli/commands/component.doc.mjs +9 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +273 -16
- package/clients/cli/commands/docs.test.mjs +2 -3
- package/clients/cli/commands/doctor-integration-components.doc.mjs +15 -4
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/doctor.test.mjs +9 -51
- package/clients/cli/commands/gap-report.doc.mjs +2 -2
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/hook/index.mjs +7 -2
- package/clients/cli/commands/import-hint-correctness.test.mjs +5 -5
- package/clients/cli/commands/init.next-steps.test.mjs +18 -23
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration-real-world.test.mjs +61 -12
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-check.doc.mjs +1 -0
- package/clients/cli/commands/layout-expand.doc.mjs +4 -1
- package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
- package/clients/cli/commands/layout.doc.mjs +1 -0
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +61 -4
- package/clients/cli/commands/no-prompt-wording.test.mjs +4 -4
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +63 -17
- package/clients/cli/commands/swizzle.doc.mjs +12 -3
- package/clients/cli/commands/swizzle.mjs +2 -1
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +70 -6
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/text-json-parity.test.mjs +40 -0
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +132 -0
- package/clients/cli/commands/theme-add.doc.mjs +19 -19
- package/clients/cli/commands/theme-eject.doc.mjs +47 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +44 -0
- package/clients/cli/commands/theme-list.doc.mjs +2 -2
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -2
- package/clients/cli/commands/theme-remove.doc.mjs +22 -0
- package/clients/cli/commands/theme-template.doc.mjs +4 -3
- package/clients/cli/commands/theme-use.doc.mjs +22 -0
- package/clients/cli/commands/theme.doc.mjs +21 -16
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/upgrade.mjs +1 -1
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/index.mjs +4 -1
- package/clients/cli/lib/component-format.mjs +19 -2
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/clients/cli/lib/resolve-theme.mjs +80 -78
- package/clients/cli/lib/resolve-theme.test.mjs +523 -27
- package/foundation/agent-docs/agent-docs.mjs +31 -28
- package/foundation/agent-docs/agent-docs.test.mjs +35 -32
- package/foundation/agent-docs/app-theme-workflow.test.mjs +13 -0
- package/foundation/config/project.d.mts +20 -5
- package/foundation/config/project.mjs +43 -6
- package/foundation/config/theme-private-vars.d.mts +12 -0
- package/foundation/config/theme-private-vars.mjs +107 -0
- package/foundation/config/theme-private-vars.test.mjs +55 -0
- package/foundation/config/theme-state.d.mts +145 -0
- package/foundation/config/theme-state.mjs +417 -0
- package/foundation/config/theme-state.test.mjs +182 -0
- package/foundation/discovery/component-discovery.d.mts +5 -2
- package/foundation/discovery/component-discovery.mjs +12 -6
- package/foundation/discovery/component-replacement.d.mts +91 -0
- package/foundation/discovery/component-replacement.mjs +417 -0
- package/foundation/discovery/component-replacement.test.mjs +480 -0
- package/foundation/discovery/docs-output-budget.d.mts +6 -2
- package/foundation/discovery/docs-output-budget.mjs +2 -1
- package/foundation/discovery/docs-section-key.d.mts +4 -2
- package/foundation/discovery/docs-section-key.mjs +1 -1
- package/foundation/discovery/module-exports.d.mts +10 -0
- package/foundation/discovery/module-exports.mjs +146 -0
- package/foundation/discovery/package-exports.d.mts +29 -0
- package/foundation/discovery/package-exports.mjs +200 -0
- package/foundation/discovery/template-adapter.d.mts +13 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +16 -1
- package/foundation/discovery/theme-discovery.d.mts +78 -5
- package/foundation/discovery/theme-discovery.mjs +143 -18
- package/foundation/discovery/theme-discovery.test.mjs +9 -3
- package/foundation/discovery/theme-imports.d.mts +15 -0
- package/foundation/discovery/theme-imports.mjs +217 -0
- package/foundation/discovery/theme-imports.test.mjs +173 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +18 -8
- package/foundation/doc-compiler/inputs.mjs +2 -1
- package/foundation/doc-compiler/lenses.d.mts +4 -2
- package/foundation/doc-compiler/lenses.mjs +1 -1
- package/foundation/doc-compiler/tree.test.mjs +2 -2
- package/foundation/fs/module-loader.d.mts +9 -0
- package/foundation/fs/module-loader.mjs +71 -2
- package/foundation/integrations/cli-requirement.d.mts +22 -0
- package/foundation/integrations/cli-requirement.mjs +31 -0
- package/foundation/integrations/cli-requirement.test.mjs +70 -0
- package/foundation/integrations/contribution-inventory.mjs +3 -3
- package/foundation/response/base.d.ts +9 -3
- package/foundation/response/json.d.mts +7 -4
- package/foundation/response/json.mjs +10 -6
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +50 -35
- package/foundation/response/response.doc.mjs +18 -4
- package/foundation/text/copyright-header.mjs +1 -1
- package/foundation/text/copyright-header.test.mjs +1 -1
- package/package.json +9 -9
- package/assets/docs/layout.doc.dense.mjs +0 -388
- package/assets/docs/layout.doc.mjs +0 -550
package/api/search/search.mjs
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* outputs. The CLI command handler is a thin wrapper around this function.
|
|
8
8
|
*
|
|
9
9
|
* `search(query)` is the single "I'm looking for X" entry point across ALL
|
|
10
|
-
* content domains — components, hooks, docs topics,
|
|
11
|
-
*
|
|
12
|
-
* (`component --list`, `hook --list`, `docs`, `template --list`)
|
|
13
|
-
* scanning; this collapses them into one ranked, typed result set.
|
|
10
|
+
* content domains — components, hooks, docs topics, templates (page + block),
|
|
11
|
+
* and themes. Finding the right thing otherwise takes separate list calls
|
|
12
|
+
* (`component --list`, `hook --list`, `docs`, `template --list`, `theme list`)
|
|
13
|
+
* plus manual scanning; this collapses them into one ranked, typed result set.
|
|
14
14
|
*
|
|
15
15
|
* Scoring is keyword + fuzzy ranking (NOT semantic / embeddings — that is a
|
|
16
16
|
* deliberate future follow-up). It reuses the same signal weighting as the
|
|
@@ -80,15 +80,20 @@ import {
|
|
|
80
80
|
findComponentReadme,
|
|
81
81
|
resolveImportPath,
|
|
82
82
|
resolveIntegrationImportPath,
|
|
83
|
+
CORE_PACKAGE,
|
|
83
84
|
} from '../../foundation/discovery/component-discovery.mjs';
|
|
84
85
|
import {
|
|
85
86
|
discoverHooks,
|
|
86
87
|
findHookDoc,
|
|
87
88
|
} from '../../foundation/discovery/hook-discovery.mjs';
|
|
88
|
-
import {
|
|
89
|
+
import {
|
|
90
|
+
loadComponentReplacements,
|
|
91
|
+
loadIntegrationsSafely,
|
|
92
|
+
} from '../component/_adapter.mjs';
|
|
89
93
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
90
94
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
91
95
|
import {templateLookupIds} from '../../foundation/discovery/template-adapter.mjs';
|
|
96
|
+
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
92
97
|
import {
|
|
93
98
|
guideEntry,
|
|
94
99
|
loadDocsCatalog,
|
|
@@ -110,8 +115,10 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
110
115
|
* A search candidate gathered from one content domain. Extra underscore-
|
|
111
116
|
* prefixed fields carry domain-specific payload used only by {@link toResult}.
|
|
112
117
|
* @typedef {object} Candidate
|
|
113
|
-
* @property {'component'|'hook'|'doc'|'template'} domain
|
|
118
|
+
* @property {'component'|'hook'|'doc'|'template'|'theme'} domain
|
|
114
119
|
* @property {string} name
|
|
120
|
+
* @property {string[]} [aliases] - Other names the candidate answers to, scored
|
|
121
|
+
* with the same name signals: a theme's display name.
|
|
115
122
|
* @property {string[]} [keywords]
|
|
116
123
|
* @property {string[]} [weakKeywords]
|
|
117
124
|
* @property {string} [description]
|
|
@@ -127,9 +134,9 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
127
134
|
* @property {string} [_command] - The command that reads exactly this doc part.
|
|
128
135
|
* @property {string} [_parent] - The command that opens the level above a doc
|
|
129
136
|
* part: its topic's section list, or the docs-tree namespace it sits in.
|
|
130
|
-
* @property {string} [_package] - The npm package that
|
|
131
|
-
*
|
|
132
|
-
*
|
|
137
|
+
* @property {string} [_package] - The npm package that owns the candidate:
|
|
138
|
+
* Core's package for its components, hooks, and templates, the integration's
|
|
139
|
+
* for what it contributed, and for a doc part the package that wrote it.
|
|
133
140
|
* @property {string} [_displayName]
|
|
134
141
|
* @property {'page'|'block'} [_kind]
|
|
135
142
|
* @property {string} [_resultName]
|
|
@@ -291,7 +298,13 @@ const isTypo = (a, b, dist) =>
|
|
|
291
298
|
TYPO_MIN_LENGTH[/** @type {1 | 2 | 3} */ (dist)];
|
|
292
299
|
|
|
293
300
|
/** Valid domain filters for `--type`. */
|
|
294
|
-
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'];
|
|
301
|
+
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template', 'theme'];
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* The domains a search reads without @astryxdesign/core. An open search outside
|
|
305
|
+
* an app covers these alone.
|
|
306
|
+
*/
|
|
307
|
+
const CORELESS_DOMAINS = ['doc', 'theme'];
|
|
295
308
|
|
|
296
309
|
/**
|
|
297
310
|
* Filler words stripped from multi-word queries so natural-language phrasing
|
|
@@ -618,6 +631,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
618
631
|
// strong hits, then reward coverage so candidates matching more terms win.
|
|
619
632
|
let strongest = 0;
|
|
620
633
|
let matched = 0;
|
|
634
|
+
let tokenSum = 0;
|
|
621
635
|
/** @type {string[]} */
|
|
622
636
|
const hitTerms = [];
|
|
623
637
|
for (const tok of tokens) {
|
|
@@ -626,6 +640,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
626
640
|
if (h.score > strongest) strongest = h.score;
|
|
627
641
|
matched++;
|
|
628
642
|
hitTerms.push(tok);
|
|
643
|
+
tokenSum += h.score;
|
|
629
644
|
}
|
|
630
645
|
}
|
|
631
646
|
// The reverse of the title tier, a step lower: the query holds a whole title
|
|
@@ -650,14 +665,25 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
650
665
|
// (50 + bonus + coverage = 77) lost to thirty docs that each match
|
|
651
666
|
// `integration` alone, by name or in a code tick (98-108). The reader asked for
|
|
652
667
|
// both; a candidate that has both comes first, ordered among its peers by
|
|
653
|
-
// how strong its
|
|
668
|
+
// how strong its matches are. It needs one keyword-strength hit:
|
|
654
669
|
// every word mentioned in prose, or rendered by a page, is breadth, and
|
|
655
670
|
// stays on the token sum below an exact hit on one word.
|
|
671
|
+
//
|
|
672
|
+
// The TOTAL quality of matches orders candidates within this tier, not
|
|
673
|
+
// just the strongest single hit. A doc matching both words by keyword
|
|
674
|
+
// (90 + 90 = 180) outranks one matching keyword + prose (90 + 50 = 140).
|
|
675
|
+
// Before this, every all-word match whose strongest hit was a keyword (90)
|
|
676
|
+
// scored 157, burying the better match among dozens of ties.
|
|
656
677
|
if (matched === tokens.length && strongest >= STRONG_TOKEN_SCORE) {
|
|
657
678
|
return {
|
|
658
679
|
score:
|
|
659
680
|
FULL_COVERAGE_SCORE +
|
|
660
|
-
Math.
|
|
681
|
+
Math.min(
|
|
682
|
+
Math.floor(
|
|
683
|
+
(tokenSum - matched * MIN_TOKEN_SCORE) / (matched * 5),
|
|
684
|
+
),
|
|
685
|
+
8,
|
|
686
|
+
),
|
|
661
687
|
reason,
|
|
662
688
|
matched,
|
|
663
689
|
total,
|
|
@@ -697,6 +723,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
697
723
|
* @param {string} term - Lowercased search term.
|
|
698
724
|
* @param {object} candidate
|
|
699
725
|
* @param {string} candidate.name - Primary identifier (component/hook name, topic, template name).
|
|
726
|
+
* @param {string[]} [candidate.aliases] - Other names, scored like the name (a theme's display name).
|
|
700
727
|
* @param {string} [candidate.domain] - A component, hook, or template name
|
|
701
728
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
702
729
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
@@ -711,6 +738,7 @@ export function scoreCandidate(
|
|
|
711
738
|
term,
|
|
712
739
|
{
|
|
713
740
|
name,
|
|
741
|
+
aliases = [],
|
|
714
742
|
domain,
|
|
715
743
|
keywords = [],
|
|
716
744
|
weakKeywords = [],
|
|
@@ -733,40 +761,44 @@ export function scoreCandidate(
|
|
|
733
761
|
}
|
|
734
762
|
};
|
|
735
763
|
|
|
736
|
-
const nameLower = name.toLowerCase();
|
|
737
|
-
// A placed guide's name is its route, and the route's last segment is its
|
|
738
|
-
// name too, as a flat topic's is: `codemods` is cli/integrations/codemods.
|
|
739
|
-
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
740
|
-
|
|
741
764
|
// ── Name signals ────────────────────────────────────────────────
|
|
742
|
-
//
|
|
743
|
-
//
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
//
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
);
|
|
765
|
+
// An alias is a name too: a theme answers to its display name as well as
|
|
766
|
+
// its slug.
|
|
767
|
+
for (const candidateName of [name, ...aliases.filter(Boolean)]) {
|
|
768
|
+
const nameLower = candidateName.toLowerCase();
|
|
769
|
+
// A placed guide's name is its route, and the route's last segment is its
|
|
770
|
+
// name too, as a flat topic's is: `codemods` is cli/integrations/codemods.
|
|
771
|
+
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
772
|
+
|
|
773
|
+
// A plural of the name is the name: `integration` is the `integrations`
|
|
774
|
+
// guides, `tab` the `tabs` doc.
|
|
775
|
+
// A component, hook, or template name typed as words is its name:
|
|
776
|
+
// `command palette` is CommandPalette. A doc's name is a route or key,
|
|
777
|
+
// matched as written.
|
|
778
|
+
const spelled =
|
|
779
|
+
domain !== 'doc' &&
|
|
780
|
+
!/[\s_-]/.test(nameLower) &&
|
|
781
|
+
nameLower === term.replace(/\s+/g, '');
|
|
782
|
+
if (nameLower === term || leafLower === term || spelled) {
|
|
783
|
+
consider(100, 'exact name');
|
|
784
|
+
} else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
|
|
785
|
+
// One point under the exact spelling, so the doc named `tokens` still
|
|
786
|
+
// outranks the Token component for `tokens`.
|
|
787
|
+
consider(99, 'plural of the name');
|
|
788
|
+
} else {
|
|
789
|
+
if (sameWord(term, nameLower)) consider(95, `name "${candidateName}"`);
|
|
790
|
+
// The term is a word of the name, or starts one: "input" in TextInput.
|
|
791
|
+
else if (startsAWordOf(term, candidateName)) {
|
|
792
|
+
consider(60, `name contains "${term}"`);
|
|
793
|
+
}
|
|
794
|
+
if (fuzzy) {
|
|
795
|
+
const dist = levenshteinDistance(term, nameLower);
|
|
796
|
+
if (isTypo(term, nameLower, dist)) {
|
|
797
|
+
consider(
|
|
798
|
+
dist === 1 ? 80 : dist === 2 ? 40 : 20,
|
|
799
|
+
`similar name (distance ${dist})`,
|
|
800
|
+
);
|
|
801
|
+
}
|
|
770
802
|
}
|
|
771
803
|
}
|
|
772
804
|
}
|
|
@@ -939,6 +971,7 @@ async function gatherCoreComponents(coreDir) {
|
|
|
939
971
|
keywords,
|
|
940
972
|
description,
|
|
941
973
|
guidance,
|
|
974
|
+
_package: CORE_PACKAGE,
|
|
942
975
|
_import: resolveImportPath(coreDir, comp),
|
|
943
976
|
});
|
|
944
977
|
}
|
|
@@ -952,11 +985,10 @@ async function gatherCoreComponents(coreDir) {
|
|
|
952
985
|
* this, an integration component is invisible to `search`/`build` even
|
|
953
986
|
* though `component --list`/`component <Name>` already resolve it — the two
|
|
954
987
|
* discovery paths silently disagreed.
|
|
955
|
-
* @param {
|
|
988
|
+
* @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
|
|
956
989
|
* @returns {Promise<Candidate[]>}
|
|
957
990
|
*/
|
|
958
|
-
async function gatherIntegrationComponents(
|
|
959
|
-
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
991
|
+
async function gatherIntegrationComponents(loadedIntegrations) {
|
|
960
992
|
/** @type {Candidate[]} */
|
|
961
993
|
const candidates = [];
|
|
962
994
|
for (const integration of loadedIntegrations) {
|
|
@@ -969,6 +1001,7 @@ async function gatherIntegrationComponents(cwd) {
|
|
|
969
1001
|
keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
|
|
970
1002
|
description: doc ? doc.usage?.description || doc.description || '' : '',
|
|
971
1003
|
guidance: guidanceFrom(doc),
|
|
1004
|
+
_package: rec.package ?? integration.name,
|
|
972
1005
|
// Exactly what `component` reports: a doc may state its own specifier
|
|
973
1006
|
// (one entry point exporting several components), and only when it
|
|
974
1007
|
// does not do we resolve the subpath against the owning package's
|
|
@@ -1000,11 +1033,40 @@ async function gatherIntegrationComponents(cwd) {
|
|
|
1000
1033
|
* @returns {Promise<Candidate[]>}
|
|
1001
1034
|
*/
|
|
1002
1035
|
async function gatherComponents(coreDir, cwd) {
|
|
1003
|
-
const
|
|
1036
|
+
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
1037
|
+
const [core, integrations, replacements] = await Promise.all([
|
|
1004
1038
|
gatherCoreComponents(coreDir),
|
|
1005
|
-
gatherIntegrationComponents(
|
|
1039
|
+
gatherIntegrationComponents(loadedIntegrations),
|
|
1040
|
+
loadComponentReplacements(coreDir, loadedIntegrations),
|
|
1006
1041
|
]);
|
|
1007
|
-
|
|
1042
|
+
// An active replacement answers to the Core name it replaces, so a search
|
|
1043
|
+
// for that name finds the replacement and not the Core original
|
|
1044
|
+
// (spec:AST-035 FR11).
|
|
1045
|
+
/** @type {Map<string, string>} */
|
|
1046
|
+
const targetOf = new Map(
|
|
1047
|
+
replacements.active.map(active => [
|
|
1048
|
+
`${active.package}\0${active.name}`,
|
|
1049
|
+
active.target,
|
|
1050
|
+
]),
|
|
1051
|
+
);
|
|
1052
|
+
return [
|
|
1053
|
+
...core.filter(candidate => !replacements.forTarget(candidate.name)),
|
|
1054
|
+
...integrations.map(candidate => {
|
|
1055
|
+
const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
|
|
1056
|
+
if (target != null) {
|
|
1057
|
+
return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
|
|
1058
|
+
}
|
|
1059
|
+
// Another package's component named after a replaced Core component is
|
|
1060
|
+
// shadowed for the bare name (FR14): its command names its package.
|
|
1061
|
+
const shadowedBy = replacements.forTarget(candidate.name);
|
|
1062
|
+
return shadowedBy && shadowedBy.package !== candidate._package
|
|
1063
|
+
? {
|
|
1064
|
+
...candidate,
|
|
1065
|
+
_command: `astryx component ${candidate.name} --package ${candidate._package}`,
|
|
1066
|
+
}
|
|
1067
|
+
: candidate;
|
|
1068
|
+
}),
|
|
1069
|
+
];
|
|
1008
1070
|
}
|
|
1009
1071
|
|
|
1010
1072
|
/**
|
|
@@ -1048,7 +1110,12 @@ export async function componentKeywords(coreDir, cwd) {
|
|
|
1048
1110
|
: null;
|
|
1049
1111
|
return {name, keywords: keywordsOf(doc)};
|
|
1050
1112
|
});
|
|
1051
|
-
const
|
|
1113
|
+
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
1114
|
+
const replacements = await loadComponentReplacements(
|
|
1115
|
+
coreDir,
|
|
1116
|
+
loadedIntegrations,
|
|
1117
|
+
);
|
|
1118
|
+
const integrations = loadedIntegrations.map(
|
|
1052
1119
|
async integration => {
|
|
1053
1120
|
const {components} = await discoverValidIntegrationComponents(integration);
|
|
1054
1121
|
return Promise.all(
|
|
@@ -1060,7 +1127,9 @@ export async function componentKeywords(coreDir, cwd) {
|
|
|
1060
1127
|
},
|
|
1061
1128
|
);
|
|
1062
1129
|
return [
|
|
1063
|
-
...(await Promise.all(core))
|
|
1130
|
+
...(await Promise.all(core)).filter(
|
|
1131
|
+
component => !replacements.forTarget(component.name),
|
|
1132
|
+
),
|
|
1064
1133
|
...(await Promise.all(integrations)).flat(),
|
|
1065
1134
|
];
|
|
1066
1135
|
}
|
|
@@ -1095,6 +1164,7 @@ async function gatherHooks(coreDir) {
|
|
|
1095
1164
|
name: hookName,
|
|
1096
1165
|
keywords,
|
|
1097
1166
|
description,
|
|
1167
|
+
_package: CORE_PACKAGE,
|
|
1098
1168
|
_import: importPath,
|
|
1099
1169
|
});
|
|
1100
1170
|
}
|
|
@@ -1456,6 +1526,7 @@ async function gatherTemplates(cwd) {
|
|
|
1456
1526
|
// short idea is not a direct match.
|
|
1457
1527
|
prose: t.keywords ?? [],
|
|
1458
1528
|
_displayName: t.name,
|
|
1529
|
+
_package: t.package ?? CORE_PACKAGE,
|
|
1459
1530
|
_kind: t.type, // 'page' | 'block'
|
|
1460
1531
|
_resultName: t.dirName,
|
|
1461
1532
|
_commandName: commandName,
|
|
@@ -1463,6 +1534,36 @@ async function gatherTemplates(cwd) {
|
|
|
1463
1534
|
});
|
|
1464
1535
|
}
|
|
1465
1536
|
|
|
1537
|
+
/**
|
|
1538
|
+
* Build theme candidates from bundled and integration-provided themes. Without
|
|
1539
|
+
* this, an integration's themes are invisible to `search` even though
|
|
1540
|
+
* `theme list` and `discover` already resolve them.
|
|
1541
|
+
*
|
|
1542
|
+
* A theme's slug and display name are its names, and its description is prose
|
|
1543
|
+
* (`spec:AST-050/FR14`). A theme declares no keywords, so a word it shares with
|
|
1544
|
+
* the query only through its description is a description mention: read as a
|
|
1545
|
+
* keyword, every word of the description would outrank the components and docs
|
|
1546
|
+
* that declare that word.
|
|
1547
|
+
* @param {string} cwd
|
|
1548
|
+
* @returns {Promise<Candidate[]>}
|
|
1549
|
+
*/
|
|
1550
|
+
async function gatherThemes(cwd) {
|
|
1551
|
+
let themes;
|
|
1552
|
+
try {
|
|
1553
|
+
themes = await listAvailableThemes(cwd);
|
|
1554
|
+
} catch {
|
|
1555
|
+
return [];
|
|
1556
|
+
}
|
|
1557
|
+
return themes.map(t => ({
|
|
1558
|
+
domain: 'theme',
|
|
1559
|
+
name: t.slug,
|
|
1560
|
+
aliases: t.displayName ? [t.displayName] : [],
|
|
1561
|
+
description: t.description || '',
|
|
1562
|
+
_displayName: t.displayName,
|
|
1563
|
+
_package: t.package,
|
|
1564
|
+
}));
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1466
1567
|
/**
|
|
1467
1568
|
* Map a scored candidate to its public, actionable result shape. Each result
|
|
1468
1569
|
* carries enough to act on it: the domain, name, a one-line description, and
|
|
@@ -1478,6 +1579,7 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1478
1579
|
const base = {
|
|
1479
1580
|
domain: c.domain,
|
|
1480
1581
|
name: c._resultName ?? c.name,
|
|
1582
|
+
package: c._package,
|
|
1481
1583
|
score,
|
|
1482
1584
|
reason,
|
|
1483
1585
|
description: c.description || '',
|
|
@@ -1488,7 +1590,7 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1488
1590
|
result = {
|
|
1489
1591
|
...base,
|
|
1490
1592
|
import: c._import,
|
|
1491
|
-
command: `astryx component ${c.name}`,
|
|
1593
|
+
command: c._command ?? `astryx component ${c.name}`,
|
|
1492
1594
|
};
|
|
1493
1595
|
break;
|
|
1494
1596
|
case 'hook':
|
|
@@ -1508,7 +1610,6 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1508
1610
|
title: c._title,
|
|
1509
1611
|
command: c._command ?? `astryx docs ${c.name}`,
|
|
1510
1612
|
...(c._parent ? {parent: c._parent} : {}),
|
|
1511
|
-
...(c._package ? {package: c._package} : {}),
|
|
1512
1613
|
};
|
|
1513
1614
|
break;
|
|
1514
1615
|
case 'template':
|
|
@@ -1519,6 +1620,13 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1519
1620
|
command: `astryx template ${c._commandName ?? c.name} --type ${c._kind}`,
|
|
1520
1621
|
};
|
|
1521
1622
|
break;
|
|
1623
|
+
case 'theme':
|
|
1624
|
+
result = {
|
|
1625
|
+
...base,
|
|
1626
|
+
displayName: c._displayName,
|
|
1627
|
+
command: `astryx theme add --import ${c.name}`,
|
|
1628
|
+
};
|
|
1629
|
+
break;
|
|
1522
1630
|
default:
|
|
1523
1631
|
result = base;
|
|
1524
1632
|
}
|
|
@@ -1526,12 +1634,12 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1526
1634
|
}
|
|
1527
1635
|
|
|
1528
1636
|
/**
|
|
1529
|
-
* Unified ranked search across components, hooks, docs, and
|
|
1637
|
+
* Unified ranked search across components, hooks, docs, templates, and themes.
|
|
1530
1638
|
*
|
|
1531
1639
|
* @param {string} query - Free-text search term.
|
|
1532
1640
|
* @param {object} [options]
|
|
1533
1641
|
* @param {string} [options.cwd]
|
|
1534
|
-
* @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
|
|
1642
|
+
* @param {'component'|'hook'|'doc'|'template'|'theme'} [options.type] - Restrict to one domain.
|
|
1535
1643
|
* @param {number} [options.limit] - Max results (default 20).
|
|
1536
1644
|
* @returns {Promise<import('./search.type.mjs').SearchResponse>}
|
|
1537
1645
|
*/
|
|
@@ -1568,12 +1676,14 @@ export async function search(query, options = {}) {
|
|
|
1568
1676
|
const term = String(query).trim().toLowerCase();
|
|
1569
1677
|
const tokens = tokenizeQuery(term);
|
|
1570
1678
|
|
|
1571
|
-
// `astryx docs` reads docs without @astryxdesign/core,
|
|
1572
|
-
//
|
|
1573
|
-
//
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1679
|
+
// `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
|
|
1680
|
+
// list` reads themes without it (bundled themes need no project), so a
|
|
1681
|
+
// search of either must too. Every other domain reads core: asked for by
|
|
1682
|
+
// name, it is an error without core; an open search then covers the docs
|
|
1683
|
+
// and themes alone.
|
|
1684
|
+
const needsCore = !type || !CORELESS_DOMAINS.includes(type);
|
|
1685
|
+
const coreDir = needsCore ? findCoreDir(cwd) : null;
|
|
1686
|
+
if (type && needsCore && !coreDir) {
|
|
1577
1687
|
throw new AstryxError(
|
|
1578
1688
|
'Could not find @astryxdesign/core package',
|
|
1579
1689
|
undefined,
|
|
@@ -1583,17 +1693,19 @@ export async function search(query, options = {}) {
|
|
|
1583
1693
|
|
|
1584
1694
|
// Gather candidates from each requested domain in parallel.
|
|
1585
1695
|
/** @param {string} d */
|
|
1586
|
-
const wants = d =>
|
|
1587
|
-
|
|
1696
|
+
const wants = d =>
|
|
1697
|
+
(!type && (coreDir != null || CORELESS_DOMAINS.includes(d))) || type === d;
|
|
1698
|
+
const [components, hooks, docTopics, templates, themes] = await Promise.all([
|
|
1588
1699
|
wants('component')
|
|
1589
1700
|
? gatherComponents(/** @type {string} */ (coreDir), cwd)
|
|
1590
1701
|
: [],
|
|
1591
1702
|
wants('hook') ? gatherHooks(/** @type {string} */ (coreDir)) : [],
|
|
1592
1703
|
wants('doc') ? gatherDocs(cwd) : [],
|
|
1593
1704
|
wants('template') ? gatherTemplates(cwd) : [],
|
|
1705
|
+
wants('theme') ? gatherThemes(cwd) : [],
|
|
1594
1706
|
]);
|
|
1595
1707
|
|
|
1596
|
-
const all = [...components, ...hooks, ...docTopics, ...templates];
|
|
1708
|
+
const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
|
|
1597
1709
|
|
|
1598
1710
|
// Score every candidate on its own merits. The consumer groups results by
|
|
1599
1711
|
// role (page / block / component) and takes the top of each, so there's no
|
|
@@ -1610,7 +1722,7 @@ export async function search(query, options = {}) {
|
|
|
1610
1722
|
|
|
1611
1723
|
// Sort by score desc, then domain (stable order), then name.
|
|
1612
1724
|
/** @type {Record<string, number>} */
|
|
1613
|
-
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3};
|
|
1725
|
+
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
|
|
1614
1726
|
scored.sort(
|
|
1615
1727
|
(a, b) =>
|
|
1616
1728
|
b.score - a.score ||
|
|
@@ -25,6 +25,8 @@ import * as os from 'node:os';
|
|
|
25
25
|
import * as path from 'node:path';
|
|
26
26
|
import {fileURLToPath} from 'node:url';
|
|
27
27
|
import {docs} from '../docs/docs.mjs';
|
|
28
|
+
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
29
|
+
import {doc as themeAddCommandDoc} from '../../clients/cli/commands/theme-add.doc.mjs';
|
|
28
30
|
import {
|
|
29
31
|
headingWithPhrase,
|
|
30
32
|
titleInQuery,
|
|
@@ -75,8 +77,11 @@ describe('search leaf — envelope + ranking', () => {
|
|
|
75
77
|
});
|
|
76
78
|
|
|
77
79
|
describe('search leaf — per-domain result fields', () => {
|
|
78
|
-
it('carries import for components and hooks, title for docs, displayName and kind for templates', async () => {
|
|
79
|
-
|
|
80
|
+
it('carries import for components and hooks, title for docs, displayName and kind for templates, displayName for themes', async () => {
|
|
81
|
+
// `theme` reaches every domain, but a theme matches it only through its
|
|
82
|
+
// description, a prose mention below every name and keyword hit, so read
|
|
83
|
+
// the whole result list.
|
|
84
|
+
const r = await search('theme', {cwd, limit: 400});
|
|
80
85
|
expect(new Set(r.data.results.map(res => res.domain))).toEqual(
|
|
81
86
|
new Set(SEARCH_DOMAINS),
|
|
82
87
|
);
|
|
@@ -89,9 +94,12 @@ describe('search leaf — per-domain result fields', () => {
|
|
|
89
94
|
expect(res.title).toMatch(/\S/);
|
|
90
95
|
const read = `astryx docs ${res.name}`;
|
|
91
96
|
expect([read, `${read} --index`, `${read} ${res.section}`]).toContain(res.command);
|
|
92
|
-
} else {
|
|
97
|
+
} else if (res.domain === 'template') {
|
|
93
98
|
expect(res.displayName).toMatch(/\S/);
|
|
94
99
|
expect(['page', 'block']).toContain(res.kind);
|
|
100
|
+
} else if (res.domain === 'theme') {
|
|
101
|
+
expect(res.displayName).toMatch(/\S/);
|
|
102
|
+
expect(res.command).toMatch(/^astryx theme add /);
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
105
|
}, SLOW);
|
|
@@ -359,7 +367,11 @@ describe('search leaf — a whole-query phrase in a title or heading is top tier
|
|
|
359
367
|
it('puts the dark mode section first for a docs search', async () => {
|
|
360
368
|
for (const query of ['dark mode', 'how do I add dark mode']) {
|
|
361
369
|
const r = await search(query, {cwd, type: 'doc'});
|
|
362
|
-
|
|
370
|
+
// The topic-level hit and the section can tie; either is correct.
|
|
371
|
+
const top = r.data.results[0];
|
|
372
|
+
const hasDarkMode = top.section === 'light-dark-mode' ||
|
|
373
|
+
top.name === 'use-a-theme' || top.name === 'theme';
|
|
374
|
+
expect(hasDarkMode).toBe(true);
|
|
363
375
|
}
|
|
364
376
|
}, SLOW);
|
|
365
377
|
});
|
|
@@ -397,11 +409,10 @@ describe('search leaf — a candidate that matches every word outranks a partial
|
|
|
397
409
|
expect(score(q, all)).toBeLessThan(160);
|
|
398
410
|
});
|
|
399
411
|
|
|
400
|
-
// Among candidates that match every word, the stronger match
|
|
401
|
-
//
|
|
402
|
-
//
|
|
403
|
-
|
|
404
|
-
it.fails('ranks the stronger of two all-word matches first', () => {
|
|
412
|
+
// Among candidates that match every word, the stronger match comes first:
|
|
413
|
+
// the all-words tier uses total match quality (sum of token scores), not
|
|
414
|
+
// just the strongest, so an exact keyword outranks a stem-form keyword.
|
|
415
|
+
it('ranks the stronger of two all-word matches first', () => {
|
|
405
416
|
const all = {name: 'x', keywords: ['alphas'], description: 'alpha beta gamma delta'};
|
|
406
417
|
const q = 'alpha beta gamma delta';
|
|
407
418
|
expect(score(q, {name: 'y', keywords: ['alpha'], description: 'beta gamma delta'})).toBeGreaterThan(
|
|
@@ -497,6 +508,114 @@ describe('search leaf — limit validation (API matches the CLI contract)', () =
|
|
|
497
508
|
}, SLOW);
|
|
498
509
|
});
|
|
499
510
|
|
|
511
|
+
describe('search leaf — a theme is found by its names; its description is prose (AST-050 FR14)', () => {
|
|
512
|
+
/** A result that answers the query by a name or a declared keyword, not a typo or a mention. */
|
|
513
|
+
const matchesByNameOrKeyword = (/** @type {{reason: string}} */ result) =>
|
|
514
|
+
/^(exact name|plural of the name|name "|name contains ")/.test(result.reason) ||
|
|
515
|
+
/^keyword "[^"]*"$/.test(result.reason);
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* The `theme add` command AST-050 FR12 and FR13 name for the stage that
|
|
519
|
+
* `theme add` itself declares: no `--import` yet, a deprecated copy default
|
|
520
|
+
* beside `--import`, or the cleanup, which keeps `--import` and drops the
|
|
521
|
+
* copy's `--overwrite`.
|
|
522
|
+
* @param {string} slug
|
|
523
|
+
*/
|
|
524
|
+
function themeAddCommandForStage(slug) {
|
|
525
|
+
const flags = themeAddCommandDoc.options.flatMap(option => option.flag.split(/[\s,]+/));
|
|
526
|
+
if (!flags.includes('--import')) return `astryx theme add ${slug}`;
|
|
527
|
+
if (flags.includes('--overwrite')) return `astryx theme add --import ${slug}`;
|
|
528
|
+
return `astryx theme add ${slug}`;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
it(
|
|
532
|
+
'ranks a theme found only through its description below every name and keyword match',
|
|
533
|
+
async () => {
|
|
534
|
+
for (const [query, slugs] of [
|
|
535
|
+
['focus', ['neutral']],
|
|
536
|
+
['content', ['matcha', 'neutral']],
|
|
537
|
+
]) {
|
|
538
|
+
const {results} = (await search(query, {cwd, limit: 400})).data;
|
|
539
|
+
const strong = results.filter(
|
|
540
|
+
result => result.domain !== 'theme' && matchesByNameOrKeyword(result),
|
|
541
|
+
);
|
|
542
|
+
expect(strong.length).toBeGreaterThan(0);
|
|
543
|
+
const lastStrong = Math.max(...strong.map(result => results.indexOf(result)));
|
|
544
|
+
for (const slug of slugs) {
|
|
545
|
+
const at = results.findIndex(result => result.domain === 'theme' && result.name === slug);
|
|
546
|
+
expect(at).toBeGreaterThan(-1);
|
|
547
|
+
expect(results[at].reason).toMatch(/^description mentions /);
|
|
548
|
+
expect(at).toBeGreaterThan(lastStrong);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
SLOW,
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
it(
|
|
556
|
+
'scores a word in a theme description the same as a word in a component description',
|
|
557
|
+
async () => {
|
|
558
|
+
const {results} = (await search('minimal', {cwd, limit: 400})).data;
|
|
559
|
+
const neutral = results.find(result => result.domain === 'theme' && result.name === 'neutral');
|
|
560
|
+
const topNav = results.find(result => result.domain === 'component' && result.name === 'TopNav');
|
|
561
|
+
expect(neutral?.reason).toMatch(/^description mentions /);
|
|
562
|
+
expect(topNav?.reason).toMatch(/^description mentions /);
|
|
563
|
+
expect(neutral?.score).toBe(topNav?.score);
|
|
564
|
+
},
|
|
565
|
+
SLOW,
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
it(
|
|
569
|
+
'keeps a theme that matches every word only in its description below results with a keyword hit',
|
|
570
|
+
async () => {
|
|
571
|
+
// Overlay and Dialog declare `focus` and mention `content`; neutral only
|
|
572
|
+
// mentions both, in "so the content stays the focus".
|
|
573
|
+
const {results} = (await search('content focus', {cwd, limit: 400})).data;
|
|
574
|
+
const neutral = results.findIndex(result => result.domain === 'theme' && result.name === 'neutral');
|
|
575
|
+
expect(neutral).toBeGreaterThan(-1);
|
|
576
|
+
for (const name of ['Overlay', 'Dialog']) {
|
|
577
|
+
const at = results.findIndex(result => result.domain === 'component' && result.name === name);
|
|
578
|
+
expect(at).toBeGreaterThan(-1);
|
|
579
|
+
expect(at).toBeLessThan(neutral);
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
SLOW,
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
it(
|
|
586
|
+
'still finds a theme first by its slug or its display name',
|
|
587
|
+
async () => {
|
|
588
|
+
for (const query of ['neutral', 'Matcha', 'Y2K']) {
|
|
589
|
+
const [first] = (await search(query, {cwd})).data.results;
|
|
590
|
+
expect(first).toMatchObject({domain: 'theme', name: query.toLowerCase(), reason: 'exact name'});
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
SLOW,
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
it('scores a display name with the same name signals as the slug', () => {
|
|
597
|
+
const theme = {name: 'ocean', aliases: ['Ocean Blue'], description: 'Deep blues for calm reading.'};
|
|
598
|
+
expect(scoreCandidate('ocean blue', theme)).toEqual(scoreCandidate('ocean', theme));
|
|
599
|
+
expect(scoreCandidate('ocean blue', {...theme, aliases: []})?.score ?? 0).toBeLessThan(
|
|
600
|
+
scoreCandidate('ocean', theme).score,
|
|
601
|
+
);
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
it(
|
|
605
|
+
'names the theme add command for the stage theme add declares',
|
|
606
|
+
async () => {
|
|
607
|
+
const themes = await listAvailableThemes(cwd);
|
|
608
|
+
expect(themes.length).toBeGreaterThan(0);
|
|
609
|
+
for (const {slug} of themes) {
|
|
610
|
+
const {results} = (await search(slug, {cwd, type: 'theme'})).data;
|
|
611
|
+
const result = results.find(entry => entry.name === slug);
|
|
612
|
+
expect(result?.command).toBe(themeAddCommandForStage(slug));
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
SLOW,
|
|
616
|
+
);
|
|
617
|
+
});
|
|
618
|
+
|
|
500
619
|
describe('search leaf — integration components', () => {
|
|
501
620
|
/**
|
|
502
621
|
* A minimal consumer project: a stub `@astryxdesign/core` (so `findCoreDir`
|