@antheo/morph 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +266 -2
- package/SKILL.md +61 -0
- package/dist/ai/cli-provider.d.ts +80 -0
- package/dist/ai/cli-provider.js +250 -0
- package/dist/ai/gate.d.ts +39 -0
- package/dist/ai/gate.js +124 -0
- package/dist/ai/provider.d.ts +36 -0
- package/dist/ai/provider.js +168 -0
- package/dist/ai/repair.d.ts +90 -0
- package/dist/ai/repair.js +172 -0
- package/dist/analyzer/deps.d.ts +30 -0
- package/dist/analyzer/deps.js +265 -0
- package/dist/analyzer/manifest.d.ts +5 -0
- package/dist/analyzer/manifest.js +119 -0
- package/dist/analyzer/parse.d.ts +21 -0
- package/dist/analyzer/parse.js +29 -0
- package/dist/batch-worker.d.ts +16 -0
- package/dist/batch-worker.js +10 -0
- package/dist/batch.d.ts +26 -0
- package/dist/batch.js +227 -0
- package/dist/bridge/index.d.ts +26 -0
- package/dist/bridge/index.js +138 -0
- package/dist/bridge/props.d.ts +56 -0
- package/dist/bridge/props.js +191 -0
- package/dist/bridge/wrappers.d.ts +24 -0
- package/dist/bridge/wrappers.js +276 -0
- package/dist/cli/format.d.ts +7 -0
- package/dist/cli/format.js +30 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +492 -0
- package/dist/fonts/carry.d.ts +34 -0
- package/dist/fonts/carry.js +113 -0
- package/dist/fonts/fallback.d.ts +11 -0
- package/dist/fonts/fallback.js +21 -0
- package/dist/fonts/google.d.ts +65 -0
- package/dist/fonts/google.js +343 -0
- package/dist/fonts/index.d.ts +27 -0
- package/dist/fonts/index.js +48 -0
- package/dist/fonts/local.d.ts +46 -0
- package/dist/fonts/local.js +150 -0
- package/dist/fonts/sfnt.d.ts +19 -0
- package/dist/fonts/sfnt.js +174 -0
- package/dist/fonts/shim.d.ts +14 -0
- package/dist/fonts/shim.js +96 -0
- package/dist/gate.d.ts +105 -0
- package/dist/gate.js +157 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +74 -0
- package/dist/ir/annotate.d.ts +16 -0
- package/dist/ir/annotate.js +145 -0
- package/dist/ir/as-child.d.ts +18 -0
- package/dist/ir/as-child.js +239 -0
- package/dist/ir/compounds.d.ts +27 -0
- package/dist/ir/compounds.js +183 -0
- package/dist/ir/contexts.d.ts +26 -0
- package/dist/ir/contexts.js +185 -0
- package/dist/ir/dom.d.ts +11 -0
- package/dist/ir/dom.js +60 -0
- package/dist/ir/effect-returns.d.ts +10 -0
- package/dist/ir/effect-returns.js +25 -0
- package/dist/ir/extract-ui-types.d.ts +33 -0
- package/dist/ir/extract-ui-types.js +224 -0
- package/dist/ir/extract-ui.d.ts +34 -0
- package/dist/ir/extract-ui.js +567 -0
- package/dist/ir/falsy.d.ts +13 -0
- package/dist/ir/falsy.js +66 -0
- package/dist/ir/forward-refs.d.ts +11 -0
- package/dist/ir/forward-refs.js +155 -0
- package/dist/ir/fragment-source.d.ts +4 -0
- package/dist/ir/fragment-source.js +13 -0
- package/dist/ir/fragments.d.ts +32 -0
- package/dist/ir/fragments.js +192 -0
- package/dist/ir/helper-snippets.d.ts +30 -0
- package/dist/ir/helper-snippets.js +550 -0
- package/dist/ir/latest-refs.d.ts +11 -0
- package/dist/ir/latest-refs.js +187 -0
- package/dist/ir/live-args.d.ts +26 -0
- package/dist/ir/live-args.js +335 -0
- package/dist/ir/lower.d.ts +83 -0
- package/dist/ir/lower.js +6016 -0
- package/dist/ir/markup-values.d.ts +16 -0
- package/dist/ir/markup-values.js +188 -0
- package/dist/ir/model.d.ts +605 -0
- package/dist/ir/model.js +1 -0
- package/dist/ir/oracle.d.ts +91 -0
- package/dist/ir/oracle.js +610 -0
- package/dist/ir/radix.d.ts +122 -0
- package/dist/ir/radix.js +344 -0
- package/dist/ir/rename.d.ts +15 -0
- package/dist/ir/rename.js +151 -0
- package/dist/ir/render-props.d.ts +31 -0
- package/dist/ir/render-props.js +67 -0
- package/dist/ir/rewrite.d.ts +44 -0
- package/dist/ir/rewrite.js +381 -0
- package/dist/ir/running-index.d.ts +11 -0
- package/dist/ir/running-index.js +217 -0
- package/dist/ir/snapshots.d.ts +12 -0
- package/dist/ir/snapshots.js +140 -0
- package/dist/ir/style.d.ts +19 -0
- package/dist/ir/style.js +76 -0
- package/dist/ir/types.d.ts +42 -0
- package/dist/ir/types.js +271 -0
- package/dist/ir/walk.d.ts +11 -0
- package/dist/ir/walk.js +18 -0
- package/dist/mcp/server.d.ts +81 -0
- package/dist/mcp/server.js +518 -0
- package/dist/pipeline.d.ts +26 -0
- package/dist/pipeline.js +750 -0
- package/dist/registry/add.d.ts +91 -0
- package/dist/registry/add.js +273 -0
- package/dist/registry/fetch.d.ts +40 -0
- package/dist/registry/fetch.js +186 -0
- package/dist/registry/ip.d.ts +18 -0
- package/dist/registry/ip.js +153 -0
- package/dist/registry/item.d.ts +39 -0
- package/dist/registry/item.js +131 -0
- package/dist/registry/load.d.ts +35 -0
- package/dist/registry/load.js +106 -0
- package/dist/registry/paths.d.ts +8 -0
- package/dist/registry/paths.js +43 -0
- package/dist/registry/publish.d.ts +119 -0
- package/dist/registry/publish.js +439 -0
- package/dist/targets/angular/bank/bank.d.ts +39 -0
- package/dist/targets/angular/bank/bank.js +61 -0
- package/dist/targets/angular/bank/helpers.d.ts +64 -0
- package/dist/targets/angular/bank/helpers.js +246 -0
- package/dist/targets/angular/bank/kept.d.ts +98 -0
- package/dist/targets/angular/bank/kept.js +791 -0
- package/dist/targets/angular/bank/plan-helpers.d.ts +17 -0
- package/dist/targets/angular/bank/plan-helpers.js +286 -0
- package/dist/targets/angular/bank/plan.d.ts +22 -0
- package/dist/targets/angular/bank/plan.js +152 -0
- package/dist/targets/angular/bank/receivers.d.ts +66 -0
- package/dist/targets/angular/bank/receivers.js +293 -0
- package/dist/targets/angular/bank/runtime.d.ts +14 -0
- package/dist/targets/angular/bank/runtime.js +152 -0
- package/dist/targets/angular/controlled.d.ts +7 -0
- package/dist/targets/angular/controlled.js +37 -0
- package/dist/targets/angular/dynamic-tags.d.ts +34 -0
- package/dist/targets/angular/dynamic-tags.js +192 -0
- package/dist/targets/angular/emit.d.ts +41 -0
- package/dist/targets/angular/emit.js +5970 -0
- package/dist/targets/angular/exports.d.ts +48 -0
- package/dist/targets/angular/exports.js +243 -0
- package/dist/targets/angular/helpers.d.ts +15 -0
- package/dist/targets/angular/helpers.js +33 -0
- package/dist/targets/angular/host-boundary.d.ts +5 -0
- package/dist/targets/angular/host-boundary.js +166 -0
- package/dist/targets/angular/host-form.d.ts +150 -0
- package/dist/targets/angular/host-form.js +727 -0
- package/dist/targets/angular/markup-values.d.ts +58 -0
- package/dist/targets/angular/markup-values.js +661 -0
- package/dist/targets/angular/motion-directive.d.ts +12 -0
- package/dist/targets/angular/motion-directive.js +257 -0
- package/dist/targets/angular/motion-hooks.d.ts +73 -0
- package/dist/targets/angular/motion-hooks.js +293 -0
- package/dist/targets/angular/motion-layout.d.ts +14 -0
- package/dist/targets/angular/motion-layout.js +74 -0
- package/dist/targets/angular/motion-templates.d.ts +10 -0
- package/dist/targets/angular/motion-templates.js +65 -0
- package/dist/targets/angular/motion.d.ts +57 -0
- package/dist/targets/angular/motion.js +202 -0
- package/dist/targets/angular/narrowing.d.ts +24 -0
- package/dist/targets/angular/narrowing.js +205 -0
- package/dist/targets/angular/ngc.d.ts +23 -0
- package/dist/targets/angular/ngc.js +134 -0
- package/dist/targets/angular/passed-handle.d.ts +39 -0
- package/dist/targets/angular/passed-handle.js +154 -0
- package/dist/targets/angular/projected.d.ts +9 -0
- package/dist/targets/angular/projected.js +63 -0
- package/dist/targets/angular/radix/cores/alert-dialog.d.ts +13 -0
- package/dist/targets/angular/radix/cores/alert-dialog.js +388 -0
- package/dist/targets/angular/radix/cores/index.d.ts +17 -0
- package/dist/targets/angular/radix/cores/index.js +50 -0
- package/dist/targets/angular/radix/cores/slider.d.ts +8 -0
- package/dist/targets/angular/radix/cores/slider.js +202 -0
- package/dist/targets/angular/radix/index.d.ts +21 -0
- package/dist/targets/angular/radix/index.js +35 -0
- package/dist/targets/angular/radix/packages.d.ts +3 -0
- package/dist/targets/angular/radix/packages.js +558 -0
- package/dist/targets/angular/radix/part.d.ts +236 -0
- package/dist/targets/angular/radix/part.js +71 -0
- package/dist/targets/angular/radix/prepare.d.ts +66 -0
- package/dist/targets/angular/radix/prepare.js +548 -0
- package/dist/targets/angular/radix/template.d.ts +43 -0
- package/dist/targets/angular/radix/template.js +172 -0
- package/dist/targets/angular/refs.d.ts +68 -0
- package/dist/targets/angular/refs.js +443 -0
- package/dist/targets/angular/slots.d.ts +22 -0
- package/dist/targets/angular/slots.js +60 -0
- package/dist/targets/angular/source-types.d.ts +10 -0
- package/dist/targets/angular/source-types.js +45 -0
- package/dist/targets/angular/spread-forward.d.ts +24 -0
- package/dist/targets/angular/spread-forward.js +72 -0
- package/dist/targets/angular/spread.d.ts +32 -0
- package/dist/targets/angular/spread.js +182 -0
- package/dist/targets/angular/svg-hosts.d.ts +25 -0
- package/dist/targets/angular/svg-hosts.js +107 -0
- package/dist/targets/angular/template-expr.d.ts +36 -0
- package/dist/targets/angular/template-expr.js +287 -0
- package/dist/targets/angular/types.d.ts +9 -0
- package/dist/targets/angular/types.js +63 -0
- package/dist/targets/angular/walk.d.ts +11 -0
- package/dist/targets/angular/walk.js +26 -0
- package/dist/targets/react-native/emit.d.ts +14 -0
- package/dist/targets/react-native/emit.js +585 -0
- package/dist/targets/react-native/fidelity.d.ts +5 -0
- package/dist/targets/react-native/fidelity.js +43 -0
- package/dist/targets/react-native/motion.d.ts +10 -0
- package/dist/targets/react-native/motion.js +290 -0
- package/dist/targets/react-native/skia.d.ts +30 -0
- package/dist/targets/react-native/skia.js +358 -0
- package/dist/targets/shared/context.d.ts +47 -0
- package/dist/targets/shared/context.js +195 -0
- package/dist/targets/shared/foreign.d.ts +10 -0
- package/dist/targets/shared/foreign.js +72 -0
- package/dist/targets/shared/fragments.d.ts +21 -0
- package/dist/targets/shared/fragments.js +309 -0
- package/dist/targets/shared/handles.d.ts +65 -0
- package/dist/targets/shared/handles.js +299 -0
- package/dist/targets/shared/inline.d.ts +53 -0
- package/dist/targets/shared/inline.js +524 -0
- package/dist/targets/shared/layout.d.ts +70 -0
- package/dist/targets/shared/layout.js +224 -0
- package/dist/targets/shared/markup.d.ts +26 -0
- package/dist/targets/shared/markup.js +65 -0
- package/dist/targets/shared/module.d.ts +84 -0
- package/dist/targets/shared/module.js +468 -0
- package/dist/targets/shared/motion-hooks.d.ts +37 -0
- package/dist/targets/shared/motion-hooks.js +87 -0
- package/dist/targets/shared/motion-layout.d.ts +70 -0
- package/dist/targets/shared/motion-layout.js +392 -0
- package/dist/targets/shared/portal.d.ts +10 -0
- package/dist/targets/shared/portal.js +23 -0
- package/dist/targets/shared/prop-writes.d.ts +11 -0
- package/dist/targets/shared/prop-writes.js +32 -0
- package/dist/targets/shared/prune.d.ts +54 -0
- package/dist/targets/shared/prune.js +405 -0
- package/dist/targets/shared/react-libs.d.ts +25 -0
- package/dist/targets/shared/react-libs.js +142 -0
- package/dist/targets/shared/react-types.d.ts +16 -0
- package/dist/targets/shared/react-types.js +374 -0
- package/dist/targets/shared/react-values.d.ts +20 -0
- package/dist/targets/shared/react-values.js +145 -0
- package/dist/targets/shared/ref-callback.d.ts +16 -0
- package/dist/targets/shared/ref-callback.js +114 -0
- package/dist/targets/shared/script.d.ts +65 -0
- package/dist/targets/shared/script.js +406 -0
- package/dist/targets/shared/unused.d.ts +12 -0
- package/dist/targets/shared/unused.js +146 -0
- package/dist/targets/svelte/dom-spread.d.ts +27 -0
- package/dist/targets/svelte/dom-spread.js +146 -0
- package/dist/targets/svelte/emit.d.ts +15 -0
- package/dist/targets/svelte/emit.js +3784 -0
- package/dist/targets/svelte/handle-branches.d.ts +22 -0
- package/dist/targets/svelte/handle-branches.js +146 -0
- package/dist/targets/svelte/html-keys.d.ts +9 -0
- package/dist/targets/svelte/html-keys.js +40 -0
- package/dist/targets/svelte/markup-data/data.d.ts +51 -0
- package/dist/targets/svelte/markup-data/data.js +305 -0
- package/dist/targets/svelte/markup-data/helper.d.ts +12 -0
- package/dist/targets/svelte/markup-data/helper.js +81 -0
- package/dist/targets/svelte/markup-data/module-data.d.ts +21 -0
- package/dist/targets/svelte/markup-data/module-data.js +473 -0
- package/dist/targets/svelte/markup-data/sites.d.ts +52 -0
- package/dist/targets/svelte/markup-data/sites.js +303 -0
- package/dist/targets/svelte/motion-layout.d.ts +13 -0
- package/dist/targets/svelte/motion-layout.js +70 -0
- package/dist/targets/svelte/motion-table.d.ts +14 -0
- package/dist/targets/svelte/motion-table.js +308 -0
- package/dist/targets/svelte/motion.d.ts +46 -0
- package/dist/targets/svelte/motion.js +405 -0
- package/dist/targets/svelte/presence.d.ts +71 -0
- package/dist/targets/svelte/presence.js +318 -0
- package/dist/targets/svelte/radix/accordion.d.ts +9 -0
- package/dist/targets/svelte/radix/accordion.js +24 -0
- package/dist/targets/svelte/radix/aspect-ratio.d.ts +6 -0
- package/dist/targets/svelte/radix/aspect-ratio.js +8 -0
- package/dist/targets/svelte/radix/avatar.d.ts +6 -0
- package/dist/targets/svelte/radix/avatar.js +10 -0
- package/dist/targets/svelte/radix/checkbox.d.ts +10 -0
- package/dist/targets/svelte/radix/checkbox.js +24 -0
- package/dist/targets/svelte/radix/collapsible.d.ts +7 -0
- package/dist/targets/svelte/radix/collapsible.js +16 -0
- package/dist/targets/svelte/radix/context-menu.d.ts +8 -0
- package/dist/targets/svelte/radix/context-menu.js +49 -0
- package/dist/targets/svelte/radix/cores/alert-dialog.d.ts +17 -0
- package/dist/targets/svelte/radix/cores/alert-dialog.js +449 -0
- package/dist/targets/svelte/radix/cores/collapsible.d.ts +12 -0
- package/dist/targets/svelte/radix/cores/collapsible.js +214 -0
- package/dist/targets/svelte/radix/cores/core.d.ts +32 -0
- package/dist/targets/svelte/radix/cores/core.js +80 -0
- package/dist/targets/svelte/radix/cores/direction.d.ts +10 -0
- package/dist/targets/svelte/radix/cores/direction.js +64 -0
- package/dist/targets/svelte/radix/cores/index.d.ts +19 -0
- package/dist/targets/svelte/radix/cores/index.js +85 -0
- package/dist/targets/svelte/radix/cores/modal-layer.d.ts +11 -0
- package/dist/targets/svelte/radix/cores/modal-layer.js +244 -0
- package/dist/targets/svelte/radix/cores/presence.d.ts +12 -0
- package/dist/targets/svelte/radix/cores/presence.js +129 -0
- package/dist/targets/svelte/radix/cores/slider-logic.d.ts +10 -0
- package/dist/targets/svelte/radix/cores/slider-logic.js +287 -0
- package/dist/targets/svelte/radix/cores/slider.d.ts +13 -0
- package/dist/targets/svelte/radix/cores/slider.js +267 -0
- package/dist/targets/svelte/radix/dialog.d.ts +8 -0
- package/dist/targets/svelte/radix/dialog.js +20 -0
- package/dist/targets/svelte/radix/dropdown-menu.d.ts +9 -0
- package/dist/targets/svelte/radix/dropdown-menu.js +38 -0
- package/dist/targets/svelte/radix/emit.d.ts +12 -0
- package/dist/targets/svelte/radix/emit.js +1339 -0
- package/dist/targets/svelte/radix/hover-card.d.ts +7 -0
- package/dist/targets/svelte/radix/hover-card.js +22 -0
- package/dist/targets/svelte/radix/index.d.ts +12 -0
- package/dist/targets/svelte/radix/index.js +28 -0
- package/dist/targets/svelte/radix/label.d.ts +3 -0
- package/dist/targets/svelte/radix/label.js +5 -0
- package/dist/targets/svelte/radix/menubar.d.ts +7 -0
- package/dist/targets/svelte/radix/menubar.js +34 -0
- package/dist/targets/svelte/radix/navigation-menu.d.ts +8 -0
- package/dist/targets/svelte/radix/navigation-menu.js +25 -0
- package/dist/targets/svelte/radix/packages.d.ts +34 -0
- package/dist/targets/svelte/radix/packages.js +100 -0
- package/dist/targets/svelte/radix/part.d.ts +161 -0
- package/dist/targets/svelte/radix/part.js +85 -0
- package/dist/targets/svelte/radix/popover.d.ts +7 -0
- package/dist/targets/svelte/radix/popover.js +15 -0
- package/dist/targets/svelte/radix/progress.d.ts +11 -0
- package/dist/targets/svelte/radix/progress.js +27 -0
- package/dist/targets/svelte/radix/radio-group.d.ts +9 -0
- package/dist/targets/svelte/radix/radio-group.js +26 -0
- package/dist/targets/svelte/radix/scroll-area.d.ts +7 -0
- package/dist/targets/svelte/radix/scroll-area.js +19 -0
- package/dist/targets/svelte/radix/select.d.ts +13 -0
- package/dist/targets/svelte/radix/select.js +81 -0
- package/dist/targets/svelte/radix/separator.d.ts +3 -0
- package/dist/targets/svelte/radix/separator.js +5 -0
- package/dist/targets/svelte/radix/slider.d.ts +6 -0
- package/dist/targets/svelte/radix/slider.js +8 -0
- package/dist/targets/svelte/radix/switch.d.ts +6 -0
- package/dist/targets/svelte/radix/switch.js +10 -0
- package/dist/targets/svelte/radix/tabs.d.ts +8 -0
- package/dist/targets/svelte/radix/tabs.js +15 -0
- package/dist/targets/svelte/radix/toggle-group.d.ts +9 -0
- package/dist/targets/svelte/radix/toggle-group.js +17 -0
- package/dist/targets/svelte/radix/toggle.d.ts +6 -0
- package/dist/targets/svelte/radix/toggle.js +9 -0
- package/dist/targets/svelte/radix/tooltip.d.ts +6 -0
- package/dist/targets/svelte/radix/tooltip.js +24 -0
- package/dist/targets/svelte/strip.d.ts +2 -0
- package/dist/targets/svelte/strip.js +5 -0
- package/dist/targets/vue/emit.d.ts +15 -0
- package/dist/targets/vue/emit.js +4092 -0
- package/dist/targets/vue/events.d.ts +11 -0
- package/dist/targets/vue/events.js +13 -0
- package/dist/targets/vue/module-builders.d.ts +28 -0
- package/dist/targets/vue/module-builders.js +258 -0
- package/dist/targets/vue/motion-layout.d.ts +19 -0
- package/dist/targets/vue/motion-layout.js +79 -0
- package/dist/targets/vue/motion.d.ts +12 -0
- package/dist/targets/vue/motion.js +46 -0
- package/dist/targets/vue/radix/accordion.d.ts +3 -0
- package/dist/targets/vue/radix/accordion.js +12 -0
- package/dist/targets/vue/radix/alert-dialog.d.ts +6 -0
- package/dist/targets/vue/radix/alert-dialog.js +18 -0
- package/dist/targets/vue/radix/aspect-ratio.d.ts +6 -0
- package/dist/targets/vue/radix/aspect-ratio.js +8 -0
- package/dist/targets/vue/radix/avatar.d.ts +3 -0
- package/dist/targets/vue/radix/avatar.js +7 -0
- package/dist/targets/vue/radix/checkbox.d.ts +3 -0
- package/dist/targets/vue/radix/checkbox.js +9 -0
- package/dist/targets/vue/radix/collapsible.d.ts +7 -0
- package/dist/targets/vue/radix/collapsible.js +11 -0
- package/dist/targets/vue/radix/context-menu.d.ts +3 -0
- package/dist/targets/vue/radix/context-menu.js +30 -0
- package/dist/targets/vue/radix/dialog.d.ts +3 -0
- package/dist/targets/vue/radix/dialog.js +12 -0
- package/dist/targets/vue/radix/direction.d.ts +7 -0
- package/dist/targets/vue/radix/direction.js +9 -0
- package/dist/targets/vue/radix/dropdown-menu.d.ts +3 -0
- package/dist/targets/vue/radix/dropdown-menu.js +29 -0
- package/dist/targets/vue/radix/hover-card.d.ts +3 -0
- package/dist/targets/vue/radix/hover-card.js +11 -0
- package/dist/targets/vue/radix/index.d.ts +65 -0
- package/dist/targets/vue/radix/index.js +225 -0
- package/dist/targets/vue/radix/label.d.ts +3 -0
- package/dist/targets/vue/radix/label.js +5 -0
- package/dist/targets/vue/radix/menubar.d.ts +6 -0
- package/dist/targets/vue/radix/menubar.js +29 -0
- package/dist/targets/vue/radix/navigation-menu.d.ts +6 -0
- package/dist/targets/vue/radix/navigation-menu.js +21 -0
- package/dist/targets/vue/radix/part.d.ts +41 -0
- package/dist/targets/vue/radix/part.js +46 -0
- package/dist/targets/vue/radix/popover.d.ts +3 -0
- package/dist/targets/vue/radix/popover.js +11 -0
- package/dist/targets/vue/radix/progress.d.ts +3 -0
- package/dist/targets/vue/radix/progress.js +6 -0
- package/dist/targets/vue/radix/radio-group.d.ts +3 -0
- package/dist/targets/vue/radix/radio-group.js +10 -0
- package/dist/targets/vue/radix/scroll-area.d.ts +3 -0
- package/dist/targets/vue/radix/scroll-area.js +11 -0
- package/dist/targets/vue/radix/select.d.ts +3 -0
- package/dist/targets/vue/radix/select.js +29 -0
- package/dist/targets/vue/radix/separator.d.ts +3 -0
- package/dist/targets/vue/radix/separator.js +5 -0
- package/dist/targets/vue/radix/slider.d.ts +3 -0
- package/dist/targets/vue/radix/slider.js +13 -0
- package/dist/targets/vue/radix/switch.d.ts +3 -0
- package/dist/targets/vue/radix/switch.js +9 -0
- package/dist/targets/vue/radix/tabs.d.ts +3 -0
- package/dist/targets/vue/radix/tabs.js +12 -0
- package/dist/targets/vue/radix/toggle-group.d.ts +3 -0
- package/dist/targets/vue/radix/toggle-group.js +10 -0
- package/dist/targets/vue/radix/toggle.d.ts +3 -0
- package/dist/targets/vue/radix/toggle.js +8 -0
- package/dist/targets/vue/radix/tooltip.d.ts +3 -0
- package/dist/targets/vue/radix/tooltip.js +14 -0
- package/dist/targets/vue/render-fn/h.d.ts +52 -0
- package/dist/targets/vue/render-fn/h.js +442 -0
- package/dist/targets/vue/render-fn.d.ts +21 -0
- package/dist/targets/vue/render-fn.js +357 -0
- package/dist/targets/vue/slot.d.ts +9 -0
- package/dist/targets/vue/slot.js +57 -0
- package/dist/typecheck/host.d.ts +45 -0
- package/dist/typecheck/host.js +309 -0
- package/dist/typecheck/index.d.ts +16 -0
- package/dist/typecheck/index.js +17 -0
- package/dist/typecheck/lucide.d.ts +8 -0
- package/dist/typecheck/lucide.js +45 -0
- package/dist/typecheck/sourcemap.d.ts +9 -0
- package/dist/typecheck/sourcemap.js +54 -0
- package/dist/typecheck/svelte.d.ts +9 -0
- package/dist/typecheck/svelte.js +116 -0
- package/dist/typecheck/vue.d.ts +8 -0
- package/dist/typecheck/vue.js +78 -0
- package/dist/types.d.ts +446 -0
- package/dist/types.js +11 -0
- package/dist/utils/cleanup.d.ts +32 -0
- package/dist/utils/cleanup.js +119 -0
- package/dist/utils/errors.d.ts +7 -0
- package/dist/utils/errors.js +15 -0
- package/dist/utils/fs-safe.d.ts +14 -0
- package/dist/utils/fs-safe.js +64 -0
- package/dist/validate.d.ts +16 -0
- package/dist/validate.js +204 -0
- package/dist/verify/auto-steps.d.ts +107 -0
- package/dist/verify/auto-steps.js +471 -0
- package/dist/verify/bundle.d.ts +68 -0
- package/dist/verify/bundle.js +548 -0
- package/dist/verify/diff.d.ts +31 -0
- package/dist/verify/diff.js +133 -0
- package/dist/verify/leaks.d.ts +25 -0
- package/dist/verify/leaks.js +261 -0
- package/dist/verify/link-worker.d.ts +1 -0
- package/dist/verify/link-worker.js +27 -0
- package/dist/verify/runner.d.ts +57 -0
- package/dist/verify/runner.js +867 -0
- package/dist/verify/sandbox.d.ts +40 -0
- package/dist/verify/sandbox.js +496 -0
- package/dist/verify/steps.d.ts +42 -0
- package/dist/verify/steps.js +475 -0
- package/dist/verify/verdict.d.ts +15 -0
- package/dist/verify/verdict.js +19 -0
- package/package.json +118 -4
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CompileOptions, Diagnostic, EmittedFile, Status, Target, TargetResult, VerifyOptions, WebTarget } from '../types.js';
|
|
2
|
+
import { type ProviderName, type ProviderOptions } from './provider.js';
|
|
3
|
+
import { type AssistGate, type AssistStop } from './gate.js';
|
|
4
|
+
export { ASSIST_GATES, type AssistGate, type AssistStop } from './gate.js';
|
|
5
|
+
/** What a writer is asked for: one generated file, written again so that it behaves as the React original does. */
|
|
6
|
+
export interface AssistRequest {
|
|
7
|
+
target: WebTarget;
|
|
8
|
+
/** the React original: its path relative to the project root, and its text */
|
|
9
|
+
sourceFile: string;
|
|
10
|
+
source: string;
|
|
11
|
+
/** the generated file to write again: its path in the output, and the compiler's text */
|
|
12
|
+
generatedPath: string;
|
|
13
|
+
generated: string;
|
|
14
|
+
/** the compiler's diagnostics for this target (info notes left out) */
|
|
15
|
+
diagnostics: Diagnostic[];
|
|
16
|
+
/** 1 to 3 */
|
|
17
|
+
attempt: number;
|
|
18
|
+
/** why the previous attempt was rejected (null on the first) */
|
|
19
|
+
previous: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Writes one candidate: returns a reply whose longest fenced code block is the whole new file. The default writer asks
|
|
23
|
+
* the chosen provider; tests and callers with their own writer pass one here (no provider is called then).
|
|
24
|
+
*/
|
|
25
|
+
export type AssistWriter = (request: AssistRequest) => Promise<string>;
|
|
26
|
+
export interface RepairOptions extends CompileOptions, Partial<Omit<ProviderOptions, 'provider'>> {
|
|
27
|
+
target: Target;
|
|
28
|
+
/** the model provider (an HTTPS one, or a local official CLI: see PROVIDERS); needed unless `writer` is given */
|
|
29
|
+
provider?: ProviderName;
|
|
30
|
+
/** writes the candidates in place of a provider (no request is made then) */
|
|
31
|
+
writer?: AssistWriter;
|
|
32
|
+
/** at most 3 */
|
|
33
|
+
maxIterations?: number;
|
|
34
|
+
/**
|
|
35
|
+
* also start when the compiler's own output converts but fails the browser gate (a match under 99% in a state or a
|
|
36
|
+
* step, or a leak): verify runs on it first. Without it, assisted mode starts only on blocking diagnostics.
|
|
37
|
+
*/
|
|
38
|
+
verify?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* how the browser gate renders: export, props, states, steps, viewport, Chrome (`unmount` is always on). Without
|
|
41
|
+
* `steps`, the script is discovered on the React page (`autoSteps`, on by default; `autoSteps: false` turns it off)
|
|
42
|
+
* once, and the same script then judges every attempt.
|
|
43
|
+
*/
|
|
44
|
+
verifyOptions?: Omit<VerifyOptions, 'targets' | 'files' | 'compiled' | 'unmount'>;
|
|
45
|
+
}
|
|
46
|
+
/** Assisted mode for a batch: how to ask (provider or writer) and how to render; each refused target is its own run. */
|
|
47
|
+
export type AssistOptions = Omit<RepairOptions, 'target' | 'verify' | keyof CompileOptions>;
|
|
48
|
+
export interface RepairAttempt {
|
|
49
|
+
iteration: number;
|
|
50
|
+
accepted: boolean;
|
|
51
|
+
/** the gate (or the step before them) that rejected it; null when accepted */
|
|
52
|
+
failedGate: AssistStop | null;
|
|
53
|
+
/** the gates it passed, in order */
|
|
54
|
+
passed: AssistGate[];
|
|
55
|
+
/** the lowest match in the browser gate, when it got that far */
|
|
56
|
+
score: number | null;
|
|
57
|
+
reason: string;
|
|
58
|
+
}
|
|
59
|
+
export interface RepairResult {
|
|
60
|
+
file: string;
|
|
61
|
+
target: Target;
|
|
62
|
+
/** whether assisted mode started (blocking diagnostics, or with `verify` the compiler's output failing the browser gate) */
|
|
63
|
+
triggered: boolean;
|
|
64
|
+
/** whether a model-written candidate passed every gate and replaced the compiler's output */
|
|
65
|
+
accepted: boolean;
|
|
66
|
+
/** `assisted` when accepted; else the compiler's own status */
|
|
67
|
+
status: Status;
|
|
68
|
+
/** with `verify`: the lowest match of the compiler's own output; else null */
|
|
69
|
+
initialScore: number | null;
|
|
70
|
+
/** the lowest match of the result (the accepted candidate's, else `initialScore`) */
|
|
71
|
+
finalScore: number | null;
|
|
72
|
+
attempts: RepairAttempt[];
|
|
73
|
+
/** the accepted candidate's files, or the compiler's own, unchanged */
|
|
74
|
+
files: EmittedFile[];
|
|
75
|
+
/** the target's result: the compiler's own when nothing was accepted (byte for byte), else status `assisted` with an `assisted` warning */
|
|
76
|
+
diagnostics: Diagnostic[];
|
|
77
|
+
result: TargetResult;
|
|
78
|
+
/** why nothing was asked although the conversion needed it (React Native; no component file in the output) */
|
|
79
|
+
skipped?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Assisted mode (opt-in): a model rewrites the file the compiler could not convert, and its result is accepted only if
|
|
83
|
+
* it passes every gate: the target's real compiler, the strict type check, the browser harness against the React
|
|
84
|
+
* original (99% in every state and step, unmount check clean). "Better than before" is not acceptance. It starts only
|
|
85
|
+
* on blocking diagnostics (or, with `verify`, on the compiler's output failing the browser gate) and makes at most 3
|
|
86
|
+
* attempts. An accepted result has status `assisted` and a warning that says a model wrote it and which gates it
|
|
87
|
+
* passed; when nothing is accepted the result is the compiler's own, unchanged, and each attempt names the gate that
|
|
88
|
+
* rejected it. Secrets are redacted from everything reported.
|
|
89
|
+
*/
|
|
90
|
+
export declare function runRepair(file: string, options: RepairOptions): Promise<RepairResult>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { compileFile } from '../pipeline.js';
|
|
4
|
+
import { makeProject } from '../analyzer/deps.js';
|
|
5
|
+
import { runVerify } from '../verify/runner.js';
|
|
6
|
+
import { MorphError, errorMessage } from '../utils/errors.js';
|
|
7
|
+
import { complete, envSecrets, redact } from './provider.js';
|
|
8
|
+
import { ASSIST_GATES, ASSIST_MATCH, NOT_CONVERTED, browserVerdict, extractCode, gateable, staticGates } from './gate.js';
|
|
9
|
+
export { ASSIST_GATES } from './gate.js';
|
|
10
|
+
const MAX_REPAIR_ITERATIONS = 3;
|
|
11
|
+
/** Provider errors that say the options are wrong, not that this attempt failed (provider.ts). */
|
|
12
|
+
// a CLI that is not installed, or one that cannot be started without a shell, fails the same way every time
|
|
13
|
+
const CONFIG_ERRORS = new Set(['ai-no-key', 'ai-no-model', 'ai-provider', 'ai-cli-missing', 'ai-cli-shim']);
|
|
14
|
+
const SYSTEM = 'You rewrite one file of a React-to-framework compiler\'s output. You receive the original React component, the generated file and the compiler diagnostics. Reply with the complete new generated file in one fenced code block, nothing else. It must render and behave exactly as the React original in every state, pass the framework\'s compiler and its strict type check, and tear down on unmount everything it starts. Keep the same props and file name; use only the target framework and the packages the generated file already imports; never add a runtime package.';
|
|
15
|
+
/** The default writer: one request to the chosen provider per attempt. */
|
|
16
|
+
function providerWriter(options, provider) {
|
|
17
|
+
// `executable` (tests only) reaches a CLI provider
|
|
18
|
+
const { model, apiKey, baseUrl, fetchImpl, timeoutMs, executable } = options;
|
|
19
|
+
const opts = { provider, ...(model ? { model } : {}), ...(apiKey !== undefined ? { apiKey } : {}), ...(baseUrl ? { baseUrl } : {}), ...(fetchImpl ? { fetchImpl } : {}), ...(timeoutMs ? { timeoutMs } : {}), ...(executable ? { executable } : {}) };
|
|
20
|
+
return async (r) => {
|
|
21
|
+
const issues = r.diagnostics.map((d) => `- [${d.severity}] ${d.code}: ${d.message}`).join('\n');
|
|
22
|
+
const prompt = `Target: ${r.target}\n\nOriginal React component (${r.sourceFile}):\n\`\`\`tsx\n${r.source}\n\`\`\`\n\nGenerated file (${r.generatedPath}):\n\`\`\`\n${r.generated}\n\`\`\`\n\nDiagnostics:\n${issues || '- (none: the output does not match React in the browser)'}${r.previous ? `\n\nYour previous attempt was rejected: ${r.previous}` : ''}`;
|
|
23
|
+
return complete(opts, SYSTEM, prompt);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
27
|
+
/**
|
|
28
|
+
* Assisted mode (opt-in): a model rewrites the file the compiler could not convert, and its result is accepted only if
|
|
29
|
+
* it passes every gate: the target's real compiler, the strict type check, the browser harness against the React
|
|
30
|
+
* original (99% in every state and step, unmount check clean). "Better than before" is not acceptance. It starts only
|
|
31
|
+
* on blocking diagnostics (or, with `verify`, on the compiler's output failing the browser gate) and makes at most 3
|
|
32
|
+
* attempts. An accepted result has status `assisted` and a warning that says a model wrote it and which gates it
|
|
33
|
+
* passed; when nothing is accepted the result is the compiler's own, unchanged, and each attempt names the gate that
|
|
34
|
+
* rejected it. Secrets are redacted from everything reported.
|
|
35
|
+
*/
|
|
36
|
+
export async function runRepair(file, options) {
|
|
37
|
+
const entry = resolve(file);
|
|
38
|
+
const iterations = Math.max(0, Math.min(options.maxIterations ?? MAX_REPAIR_ITERATIONS, MAX_REPAIR_ITERATIONS));
|
|
39
|
+
const { target } = options;
|
|
40
|
+
if (!options.writer && !options.provider)
|
|
41
|
+
throw new MorphError('ai-provider', 'Assisted mode needs a provider (anthropic, openai, ollama, gemini, openrouter, claude-cli, codex-cli, gemini-cli) or a writer.');
|
|
42
|
+
const project = makeProject(entry, options);
|
|
43
|
+
const compileOptions = { ...(options.root ? { root: options.root } : {}), ...(options.aliases ? { aliases: options.aliases } : {}), ...(options.signal ? { signal: options.signal } : {}), ...(options.typecheck === false ? { typecheck: false } : {}), ...(options.fonts ? { fonts: options.fonts } : {}) };
|
|
44
|
+
const compiled = await compileFile(entry, { ...compileOptions, targets: [target] });
|
|
45
|
+
const own = compiled.targets[0];
|
|
46
|
+
if (!own)
|
|
47
|
+
throw new Error('no target result');
|
|
48
|
+
const base = (triggered, attempts, initialScore, skipped) => ({ file: compiled.file, target, triggered, accepted: false, status: own.status, initialScore, finalScore: initialScore, attempts, files: own.files, diagnostics: own.diagnostics, result: own, ...(skipped ? { skipped } : {}) });
|
|
49
|
+
const blocking = own.diagnostics.some((d) => d.severity === 'error');
|
|
50
|
+
// React Native has no browser harness: a model-written result could never pass every gate, so none is asked for
|
|
51
|
+
if (!gateable(target))
|
|
52
|
+
return base(false, [], null, blocking ? 'react-native has no browser harness, so a model-written result could never pass every gate; nothing was asked' : undefined);
|
|
53
|
+
const render = options.verifyOptions ?? {};
|
|
54
|
+
const states = render.states ?? ['idle', 'hover', 'active'];
|
|
55
|
+
// without a given script, auto-steps is on by default, so every candidate is proved
|
|
56
|
+
// behaviourally as well as visually; the first run's discovered script then judges every later run
|
|
57
|
+
const { autoSteps: autoOption, ...renderRest } = render;
|
|
58
|
+
const discover = render.steps === undefined && autoOption !== false;
|
|
59
|
+
let steps = render.steps ?? [];
|
|
60
|
+
let discovered = !discover;
|
|
61
|
+
const forVerify = (files) => ({
|
|
62
|
+
...compileOptions,
|
|
63
|
+
...renderRest,
|
|
64
|
+
targets: [target],
|
|
65
|
+
compiled,
|
|
66
|
+
unmount: true,
|
|
67
|
+
...(discovered ? { steps } : { autoSteps: autoOption === undefined ? true : autoOption }),
|
|
68
|
+
...(files ? { files: { [target]: files } } : {}),
|
|
69
|
+
});
|
|
70
|
+
// what a run discovered becomes the script of every later run
|
|
71
|
+
const adopt = (r) => {
|
|
72
|
+
if (!discovered && r.discoveredSteps) {
|
|
73
|
+
steps = r.discoveredSteps;
|
|
74
|
+
discovered = true;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
let initialScore = null;
|
|
78
|
+
let triggered = blocking;
|
|
79
|
+
if (!blocking && options.verify && own.validated) {
|
|
80
|
+
const r = await runVerify(entry, forVerify(null));
|
|
81
|
+
adopt(r);
|
|
82
|
+
initialScore = r.minMatch;
|
|
83
|
+
triggered = browserVerdict(r, target, states, steps, own.diagnostics) !== null;
|
|
84
|
+
}
|
|
85
|
+
if (!triggered)
|
|
86
|
+
return base(false, [], initialScore);
|
|
87
|
+
const secrets = [options.apiKey, ...envSecrets()];
|
|
88
|
+
const writer = options.writer ?? providerWriter(options, options.provider ?? 'anthropic');
|
|
89
|
+
// the file to write again: the component holding the compiler's marks, else the first component
|
|
90
|
+
// (Vue, Svelte): a component the compiler refused whole (a class component) has no file at all; the one verify renders
|
|
91
|
+
// is then asked for as a new file where the emitter would have put it, beside the file's other components
|
|
92
|
+
const marked = own.files.find((f) => f.kind === 'component' && NOT_CONVERTED.test(f.contents));
|
|
93
|
+
const ext = target === 'vue' ? '.vue' : target === 'svelte' ? '.svelte' : null;
|
|
94
|
+
const wanted = render.exportName ?? compiled.analysis.components.find((c) => c.isDefault)?.name ?? compiled.analysis.components.find((c) => c.exported)?.name;
|
|
95
|
+
const anyComponent = own.files.find((f) => f.kind === 'component');
|
|
96
|
+
const missing = !marked && ext && wanted && anyComponent && !own.files.some((f) => f.kind === 'component' && f.path.endsWith(`/${wanted}${ext}`))
|
|
97
|
+
? { path: `${anyComponent.path.slice(0, anyComponent.path.lastIndexOf('/') + 1)}${wanted}${ext}`, contents: '', kind: 'component' }
|
|
98
|
+
: null;
|
|
99
|
+
const component = marked ?? missing ?? anyComponent;
|
|
100
|
+
if (!component)
|
|
101
|
+
return base(true, [], initialScore, 'the output has no component file to write again (the refused code is in a module); nothing was asked');
|
|
102
|
+
const baseFiles = missing ? [...own.files, missing] : own.files;
|
|
103
|
+
const source = readFileSync(entry, 'utf8');
|
|
104
|
+
const attempts = [];
|
|
105
|
+
let previous = null;
|
|
106
|
+
for (let i = 1; i <= iterations; i++) {
|
|
107
|
+
const reject = (failure, passed, score) => {
|
|
108
|
+
const reason = redact(failure.reason, secrets);
|
|
109
|
+
attempts.push({ iteration: i, accepted: false, failedGate: failure.gate, passed, score, reason });
|
|
110
|
+
previous = `${failure.gate}: ${reason}`;
|
|
111
|
+
};
|
|
112
|
+
let reply;
|
|
113
|
+
try {
|
|
114
|
+
reply = await writer({ target, sourceFile: compiled.file, source, generatedPath: component.path, generated: component.contents, diagnostics: own.diagnostics.filter((d) => d.severity !== 'info'), attempt: i, previous });
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
reject({ gate: 'provider', reason: errorMessage(error) }, [], null);
|
|
118
|
+
// a missing key, model or provider name fails the same way every time: no further attempt
|
|
119
|
+
if (error instanceof MorphError && CONFIG_ERRORS.has(error.code))
|
|
120
|
+
break;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const code = extractCode(reply);
|
|
124
|
+
if (code === null) {
|
|
125
|
+
reject({ gate: 'reply', reason: 'The reply held no fenced code block.' }, [], null);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const candidate = baseFiles.map((f) => (f.path === component.path ? { ...f, contents: code } : f));
|
|
129
|
+
let failure;
|
|
130
|
+
try {
|
|
131
|
+
failure = await staticGates(candidate, target, project.root);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
failure = { gate: 'compiler', reason: `the check could not run: ${errorMessage(error)}` };
|
|
135
|
+
}
|
|
136
|
+
if (failure) {
|
|
137
|
+
reject(failure, failure.gate === 'typecheck' ? ['compiler'] : [], null);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
let score = null;
|
|
141
|
+
try {
|
|
142
|
+
const r = await runVerify(entry, forVerify(candidate));
|
|
143
|
+
adopt(r);
|
|
144
|
+
score = r.minMatch;
|
|
145
|
+
failure = browserVerdict(r, target, states, steps, own.diagnostics);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
failure = { gate: 'browser', reason: `the browser harness could not run: ${errorMessage(error)}` };
|
|
149
|
+
}
|
|
150
|
+
if (failure) {
|
|
151
|
+
reject(failure, failure.gate === 'unmount' ? ['compiler', 'typecheck', 'browser'] : ['compiler', 'typecheck'], score);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
attempts.push({ iteration: i, accepted: true, failedGate: null, passed: [...ASSIST_GATES], score, reason: 'Passed every gate.' });
|
|
155
|
+
const proof = `${plural(states.length, 'state')}${steps.length ? ` and ${plural(steps.length, 'step')}` : ''}`;
|
|
156
|
+
const typecheck = target === 'angular' ? "the Angular compiler in strict mode (ngtsc, strictTemplates)" : `the ${target} compiler, the strict type check`;
|
|
157
|
+
const assisted = {
|
|
158
|
+
code: 'assisted',
|
|
159
|
+
severity: 'warning',
|
|
160
|
+
message: `${component.path} was written by a model (assisted mode, attempt ${i}), not by the compiler. It passed every gate: ${typecheck}, the browser harness against the React original (${proof}, lowest match ${((score ?? 0) * 100).toFixed(2)}%, at least ${ASSIST_MATCH * 100}% needed) and the unmount check. Only those states and steps were compared; review the file as you would any hand-written code.${blocking ? ` The compiler refused it because: ${own.diagnostics.filter((d) => d.severity === 'error').map((d) => d.message).join(' ')}` : ''}`,
|
|
161
|
+
file: compiled.file,
|
|
162
|
+
target,
|
|
163
|
+
};
|
|
164
|
+
// the compiler's errors were about the code the model replaced, which every gate now checked: they go with it, and
|
|
165
|
+
// the warning repeats them; so do the type check's findings, which the gate ran again on the result and found none.
|
|
166
|
+
// Its other warnings stay: some may be about the replaced file, but a warning kept errs on the side of caution
|
|
167
|
+
const diagnostics = [assisted, ...own.diagnostics.filter((d) => d.severity !== 'error' && d.code !== 'type-error')];
|
|
168
|
+
const result = { target, status: 'assisted', files: candidate, diagnostics, validated: true };
|
|
169
|
+
return { file: compiled.file, target, triggered: true, accepted: true, status: 'assisted', initialScore, finalScore: score, attempts, files: candidate, diagnostics, result };
|
|
170
|
+
}
|
|
171
|
+
return base(true, attempts, initialScore);
|
|
172
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ModuleImport, ProjectOptions } from '../types.js';
|
|
2
|
+
export interface Project {
|
|
3
|
+
root: string;
|
|
4
|
+
/** prefix aliases: { '@/': '<root>/src/' } (a tsconfig `paths` key ending in `*`) */
|
|
5
|
+
aliases: Record<string, string>;
|
|
6
|
+
/** exact aliases: { '@/lib/utils': '<root>/lib/utils' } (a tsconfig `paths` key with no `*`) */
|
|
7
|
+
exact: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
/** The nearest folder above `file` holding a tsconfig.json, else a package.json, else the file's own folder. */
|
|
10
|
+
export declare function findProjectRoot(file: string): string;
|
|
11
|
+
export declare function makeProject(entry: string, options?: ProjectOptions): Project;
|
|
12
|
+
/** Whether `source` names a project file through a tsconfig alias (exact or prefix), whether or not the file exists. */
|
|
13
|
+
export declare function isAliased(source: string, project: Project): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The major version of React's type declarations (`@types/react`) the project compiles with, found in the nearest
|
|
16
|
+
* node_modules at or above its root; null when there are none.
|
|
17
|
+
*/
|
|
18
|
+
export declare function reactTypesMajor(root: string): number | null;
|
|
19
|
+
/** The packages Framer Motion's React API is imported from. */
|
|
20
|
+
export declare const MOTION_PACKAGES: Set<string>;
|
|
21
|
+
export declare function packageName(source: string): string;
|
|
22
|
+
export declare function classifyImport(source: string): ModuleImport['kind'];
|
|
23
|
+
export declare function unsupportedReason(source: string): string;
|
|
24
|
+
/** Applies an alias, if one matches: an exact key first, else the longest matching prefix (TypeScript's order). */
|
|
25
|
+
export declare function applyAlias(source: string, project: Project): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves a relative or aliased import to a file inside the project, trying the TypeScript extensions and index files.
|
|
28
|
+
* Returns null when nothing matches or when the file would be outside the project root.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveLocal(fromFile: string, source: string, project: Project): string | null;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { isInside } from '../utils/fs-safe.js';
|
|
4
|
+
/** The nearest folder above `file` holding a tsconfig.json, else a package.json, else the file's own folder. */
|
|
5
|
+
export function findProjectRoot(file) {
|
|
6
|
+
let dir = dirname(resolve(file));
|
|
7
|
+
let pkg = null;
|
|
8
|
+
for (;;) {
|
|
9
|
+
if (existsSync(join(dir, 'tsconfig.json')))
|
|
10
|
+
return dir;
|
|
11
|
+
if (!pkg && existsSync(join(dir, 'package.json')))
|
|
12
|
+
pkg = dir;
|
|
13
|
+
const parent = dirname(dir);
|
|
14
|
+
if (parent === dir)
|
|
15
|
+
return pkg ?? dirname(resolve(file));
|
|
16
|
+
dir = parent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** JSON with comments and trailing commas (tsconfig) to plain JSON, leaving strings untouched. */
|
|
20
|
+
function stripJsonc(text) {
|
|
21
|
+
let out = '';
|
|
22
|
+
let i = 0;
|
|
23
|
+
while (i < text.length) {
|
|
24
|
+
const c = text[i] ?? '';
|
|
25
|
+
const next = text[i + 1] ?? '';
|
|
26
|
+
if (c === '"') {
|
|
27
|
+
let j = i + 1;
|
|
28
|
+
while (j < text.length && text[j] !== '"')
|
|
29
|
+
j += text[j] === '\\' ? 2 : 1;
|
|
30
|
+
out += text.slice(i, j + 1);
|
|
31
|
+
i = j + 1;
|
|
32
|
+
}
|
|
33
|
+
else if (c === '/' && next === '/') {
|
|
34
|
+
while (i < text.length && text[i] !== '\n')
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
else if (c === '/' && next === '*') {
|
|
38
|
+
const end = text.indexOf('*/', i + 2);
|
|
39
|
+
i = end === -1 ? text.length : end + 2;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
out += c;
|
|
43
|
+
i++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return out.replace(/,(\s*[}\]])/g, '$1');
|
|
47
|
+
}
|
|
48
|
+
function readJsonc(file) {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(stripJsonc(readFileSync(file, 'utf8')));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** The file an `extends` entry names: a relative or absolute path, else a package in a node_modules above `dir`. */
|
|
57
|
+
function extendedFile(dir, spec) {
|
|
58
|
+
const withJson = (p) => (isFile(p) ? p : isFile(p + '.json') ? p + '.json' : isFile(join(p, 'tsconfig.json')) ? join(p, 'tsconfig.json') : null);
|
|
59
|
+
if (spec.startsWith('.') || spec.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(spec))
|
|
60
|
+
return withJson(resolve(dir, spec));
|
|
61
|
+
for (let d = dir;; d = dirname(d)) {
|
|
62
|
+
const hit = withJson(join(d, 'node_modules', spec));
|
|
63
|
+
if (hit)
|
|
64
|
+
return hit;
|
|
65
|
+
if (dirname(d) === d)
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `baseUrl` and `paths` of a tsconfig, following `extends` (a string or a list, later entries and the file itself
|
|
71
|
+
* overriding earlier ones) as TypeScript does: each option keeps the folder of the file that set it.
|
|
72
|
+
*/
|
|
73
|
+
function readPathsConfig(file, seen = new Set()) {
|
|
74
|
+
if (seen.has(file))
|
|
75
|
+
return {};
|
|
76
|
+
seen.add(file);
|
|
77
|
+
const config = readJsonc(file);
|
|
78
|
+
if (!config || typeof config !== 'object')
|
|
79
|
+
return {};
|
|
80
|
+
const dir = dirname(file);
|
|
81
|
+
let out = {};
|
|
82
|
+
const ext = 'extends' in config ? config.extends : undefined;
|
|
83
|
+
for (const spec of typeof ext === 'string' ? [ext] : Array.isArray(ext) ? ext : []) {
|
|
84
|
+
if (typeof spec !== 'string')
|
|
85
|
+
continue;
|
|
86
|
+
const parent = extendedFile(dir, spec);
|
|
87
|
+
if (parent)
|
|
88
|
+
out = { ...out, ...readPathsConfig(parent, seen) };
|
|
89
|
+
}
|
|
90
|
+
const options = 'compilerOptions' in config && config.compilerOptions && typeof config.compilerOptions === 'object' ? config.compilerOptions : null;
|
|
91
|
+
if (options && 'baseUrl' in options && typeof options.baseUrl === 'string')
|
|
92
|
+
out.baseUrl = resolve(dir, options.baseUrl);
|
|
93
|
+
if (options && 'paths' in options && options.paths && typeof options.paths === 'object') {
|
|
94
|
+
const paths = {};
|
|
95
|
+
for (const [key, targets] of Object.entries(options.paths)) {
|
|
96
|
+
if (Array.isArray(targets))
|
|
97
|
+
paths[key] = targets.filter((x) => typeof x === 'string');
|
|
98
|
+
}
|
|
99
|
+
out.paths = paths;
|
|
100
|
+
out.pathsDir = dir;
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* `compilerOptions.paths` of the root tsconfig (through `extends`), relative to `baseUrl` or else to the file that sets
|
|
106
|
+
* them: a key ending in `*` is a prefix alias ({ "@/*": ["./src/*"] } becomes { "@/": "<root>/src/" }), a key with
|
|
107
|
+
* no `*` an exact one ({ "@/lib/utils": ["./lib/utils"] }). A `*` elsewhere in a key has no prefix form and is left
|
|
108
|
+
* to TypeScript (the import then stays a package import).
|
|
109
|
+
*/
|
|
110
|
+
function readAliases(root) {
|
|
111
|
+
const file = join(root, 'tsconfig.json');
|
|
112
|
+
const aliases = {};
|
|
113
|
+
const exact = {};
|
|
114
|
+
if (!existsSync(file))
|
|
115
|
+
return { aliases, exact };
|
|
116
|
+
const config = readPathsConfig(file);
|
|
117
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
118
|
+
for (const [key, targets] of Object.entries(config.paths ?? {})) {
|
|
119
|
+
const first = targets[0];
|
|
120
|
+
if (!first)
|
|
121
|
+
continue;
|
|
122
|
+
const star = key.indexOf('*');
|
|
123
|
+
if (star === -1 && !first.includes('*'))
|
|
124
|
+
exact[key] = resolve(base, first);
|
|
125
|
+
// `"*": [...]` (every bare import) has no prefix to tell a project file from a package: left to TypeScript
|
|
126
|
+
else if (star > 0 && star === key.length - 1 && first.indexOf('*') === first.length - 1) {
|
|
127
|
+
const dir = first.slice(0, -1);
|
|
128
|
+
aliases[key.slice(0, -1)] = resolve(base, dir) + (dir === '' || /[\\/]$/.test(dir) ? '/' : '');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { aliases, exact };
|
|
132
|
+
}
|
|
133
|
+
export function makeProject(entry, options = {}) {
|
|
134
|
+
const root = resolve(options.root ?? findProjectRoot(entry));
|
|
135
|
+
const read = options.aliases ? { aliases: options.aliases, exact: {} } : readAliases(root);
|
|
136
|
+
return { root, ...read };
|
|
137
|
+
}
|
|
138
|
+
/** Whether `source` names a project file through a tsconfig alias (exact or prefix), whether or not the file exists. */
|
|
139
|
+
export function isAliased(source, project) {
|
|
140
|
+
return Object.hasOwn(project.exact, source) || Object.keys(project.aliases).some((a) => source.startsWith(a));
|
|
141
|
+
}
|
|
142
|
+
const typesMajor = new Map();
|
|
143
|
+
/**
|
|
144
|
+
* The major version of React's type declarations (`@types/react`) the project compiles with, found in the nearest
|
|
145
|
+
* node_modules at or above its root; null when there are none.
|
|
146
|
+
*/
|
|
147
|
+
export function reactTypesMajor(root) {
|
|
148
|
+
const hit = typesMajor.get(root);
|
|
149
|
+
if (hit !== undefined)
|
|
150
|
+
return hit;
|
|
151
|
+
let found = null;
|
|
152
|
+
for (let dir = resolve(root);; dir = dirname(dir)) {
|
|
153
|
+
const file = join(dir, 'node_modules', '@types', 'react', 'package.json');
|
|
154
|
+
if (existsSync(file)) {
|
|
155
|
+
try {
|
|
156
|
+
const pkg = JSON.parse(readFileSync(file, 'utf8'));
|
|
157
|
+
const version = pkg && typeof pkg === 'object' && 'version' in pkg ? pkg.version : undefined;
|
|
158
|
+
const major = typeof version === 'string' ? Number.parseInt(version, 10) : Number.NaN;
|
|
159
|
+
found = Number.isFinite(major) ? major : null;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
found = null;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
if (dirname(dir) === dir)
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
typesMajor.set(root, found);
|
|
170
|
+
return found;
|
|
171
|
+
}
|
|
172
|
+
const REACT = new Set(['react', 'react/jsx-runtime', 'react-dom', 'react-dom/client']);
|
|
173
|
+
/** The packages Framer Motion's React API is imported from. */
|
|
174
|
+
export const MOTION_PACKAGES = new Set(['framer-motion', 'motion/react', 'motion/react-client', 'motion/react-m']);
|
|
175
|
+
const NEXT_APP = new Set(['next/navigation', 'next/router', 'next/headers', 'next/server', 'next/dynamic', 'next/script', 'next/cache']);
|
|
176
|
+
const NEXT_WEB = new Set(['next/image', 'next/link']);
|
|
177
|
+
const ICONS = new Set(['lucide-react']);
|
|
178
|
+
/** Framework-free packages: they run the same in Vue, Svelte and a React Native JS engine (DOM ones on the web only). */
|
|
179
|
+
const AGNOSTIC = new Set([
|
|
180
|
+
'clsx', 'classnames', 'tailwind-merge', 'class-variance-authority', 'motion', 'gsap', 'three', 'ogl', 'culori', 'colord',
|
|
181
|
+
'chroma-js', 'simplex-noise', 'nanoid', 'zod', 'date-fns', 'd3', 'swiper', 'popmotion', 'bezier-easing', 'tinycolor2',
|
|
182
|
+
]);
|
|
183
|
+
/** App-level state, styling runtimes and React-only UI libraries: out of scope for a component compiler. */
|
|
184
|
+
const UNSUPPORTED = {
|
|
185
|
+
'redux': 'Redux store (app-level state)',
|
|
186
|
+
'react-redux': 'Redux store (app-level state)',
|
|
187
|
+
'@reduxjs/toolkit': 'Redux store (app-level state)',
|
|
188
|
+
'zustand': 'zustand store (app-level state)',
|
|
189
|
+
'jotai': 'jotai atoms (app-level state)',
|
|
190
|
+
'recoil': 'Recoil atoms (app-level state)',
|
|
191
|
+
'styled-components': 'styled-components (CSS-in-JS runtime)',
|
|
192
|
+
'@emotion/styled': 'Emotion (CSS-in-JS runtime)',
|
|
193
|
+
'@emotion/react': 'Emotion (CSS-in-JS runtime)',
|
|
194
|
+
'@react-three/fiber': 'react-three-fiber (React renderer)',
|
|
195
|
+
'@react-three/drei': 'drei (react-three-fiber helpers)',
|
|
196
|
+
'@tanstack/react-query': 'React Query (app-level data)',
|
|
197
|
+
'swr': 'SWR (app-level data)',
|
|
198
|
+
};
|
|
199
|
+
export function packageName(source) {
|
|
200
|
+
const parts = source.split('/');
|
|
201
|
+
return source.startsWith('@') ? parts.slice(0, 2).join('/') : (parts[0] ?? source);
|
|
202
|
+
}
|
|
203
|
+
export function classifyImport(source) {
|
|
204
|
+
if (source.endsWith('.css'))
|
|
205
|
+
return 'css';
|
|
206
|
+
if (source.startsWith('.') || source.startsWith('/'))
|
|
207
|
+
return 'local';
|
|
208
|
+
if (REACT.has(source))
|
|
209
|
+
return 'react';
|
|
210
|
+
if (MOTION_PACKAGES.has(source))
|
|
211
|
+
return 'motion';
|
|
212
|
+
if (source.startsWith('next/font/'))
|
|
213
|
+
return 'next-font';
|
|
214
|
+
if (NEXT_WEB.has(source))
|
|
215
|
+
return 'next-web';
|
|
216
|
+
if (NEXT_APP.has(source) || source === 'next' || source.startsWith('next/'))
|
|
217
|
+
return 'next-app';
|
|
218
|
+
if (ICONS.has(source))
|
|
219
|
+
return 'icons';
|
|
220
|
+
const pkg = packageName(source);
|
|
221
|
+
if (UNSUPPORTED[pkg])
|
|
222
|
+
return 'unsupported';
|
|
223
|
+
// `swiper/react`, `@lottiefiles/player/react-lottie`: a package's React binding, whatever the package is
|
|
224
|
+
if (source.slice(pkg.length + 1).split('/').some((segment) => /^react($|[-.])/.test(segment)))
|
|
225
|
+
return 'react-lib';
|
|
226
|
+
if (AGNOSTIC.has(pkg) || pkg.startsWith('d3-'))
|
|
227
|
+
return 'agnostic';
|
|
228
|
+
if (/react|radix|headlessui|vaul|cmdk|sonner/.test(source))
|
|
229
|
+
return 'react-lib';
|
|
230
|
+
return 'unknown';
|
|
231
|
+
}
|
|
232
|
+
export function unsupportedReason(source) {
|
|
233
|
+
return UNSUPPORTED[packageName(source)] ?? source;
|
|
234
|
+
}
|
|
235
|
+
const EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mts'];
|
|
236
|
+
function isFile(p) {
|
|
237
|
+
return existsSync(p) && statSync(p).isFile();
|
|
238
|
+
}
|
|
239
|
+
/** Applies an alias, if one matches: an exact key first, else the longest matching prefix (TypeScript's order). */
|
|
240
|
+
export function applyAlias(source, project) {
|
|
241
|
+
if (Object.hasOwn(project.exact, source))
|
|
242
|
+
return project.exact[source] ?? null;
|
|
243
|
+
let best = null;
|
|
244
|
+
for (const prefix of Object.keys(project.aliases)) {
|
|
245
|
+
if (source.startsWith(prefix) && (best === null || prefix.length > best.length))
|
|
246
|
+
best = prefix;
|
|
247
|
+
}
|
|
248
|
+
return best === null ? null : (project.aliases[best] ?? '') + source.slice(best.length);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Resolves a relative or aliased import to a file inside the project, trying the TypeScript extensions and index files.
|
|
252
|
+
* Returns null when nothing matches or when the file would be outside the project root.
|
|
253
|
+
*/
|
|
254
|
+
export function resolveLocal(fromFile, source, project) {
|
|
255
|
+
const aliased = applyAlias(source, project);
|
|
256
|
+
if (!aliased && !source.startsWith('.'))
|
|
257
|
+
return null;
|
|
258
|
+
const base = aliased ?? resolve(dirname(fromFile), source);
|
|
259
|
+
const candidates = [base, ...EXTENSIONS.map((e) => base + e), ...EXTENSIONS.map((e) => join(base, 'index' + e))];
|
|
260
|
+
for (const candidate of candidates) {
|
|
261
|
+
if (isFile(candidate))
|
|
262
|
+
return isInside(project.root, candidate) ? resolve(candidate) : null;
|
|
263
|
+
}
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AnalyzeResult, Diagnostic } from '../types.js';
|
|
2
|
+
import { type Project } from './deps.js';
|
|
3
|
+
import { type GraphNode } from '../pipeline.js';
|
|
4
|
+
/** What a component file is made of: its components, hooks, imports, the web features it uses and every finding. */
|
|
5
|
+
export declare function buildAnalysis(entry: string, nodes: GraphNode[], project: Project, graphDiagnostics: Diagnostic[]): AnalyzeResult;
|