@aihu/compiler
v1.3.13
Published
Single File Component (.aihu) compiler — Rust binary + JS glue.
Readme
@aihu/compiler
Aihu — agentic discovery and interaction, for human purpose.
Single File Component (.aihu) compiler — Rust binary + JS glue.
Part of the compiler + toolchain layer of Aihu. Build-time only — does not ship to the client. The compiler reads .aihu SFC source (per the Block Structure spec) and emits standards-compliant Web Components.
The package exposes the compiler plugin and transform API from its root entry point. Migration tools are available as stable subpath exports so framework tooling does not need to import compiler source files:
import { migrate } from '@aihu/compiler/codemods/macro-simplification'
import { migrateStateWrappers } from '@aihu/compiler/codemods/state-wrapper'
import { migrateTemplateGrammar } from '@aihu/compiler/codemods/template-grammar-v2'CSS providers
CSS integration is opt-in. The default plugin behavior continues to discover
@aihu/css-engine when it is installed. A project that uses another CSS
engine can provide its own complete stylesheet producer without importing the
legacy engine:
import { aihuCompilerPlugin, type AihuCssProvider } from '@aihu/compiler'
const cssProvider: AihuCssProvider = ({ source, id, shadowMode, target, lightScopeId }) => {
return myCssEngine.compileAihu({ source, id, shadowMode, target, lightScopeId })
}
export default {
plugins: [aihuCompilerPlugin({ cssProvider })],
}The provider receives the source and file id plus the compiler's resolved
shadowMode ('light' or 'shadow'), build target, and optional light-DOM
scope id. A non-empty result is authoritative: it must be the complete
stylesheet for that SFC, including utility rules, tokens, and authored
@style rules that should ship. The compiler replaces the component's shadow
stylesheet with it, or sends it through the Vite CSS pipeline for light DOM.
Return an empty string, null, or undefined to emit no provider stylesheet.
The explicit provider replaces automatic css-engine resolution for that plugin instance, so alternate CSS engines remain independent and opt-in.
Programmatic API
Outside the Vite plugin, the root entry also exports functions for tooling
that needs to drive the compiler directly (editor integrations, the router's
build-time route scan, @aihu/tsc):
import { compileRouteMeta, compileToAst, transform } from '@aihu/compiler'
const { code } = transform(source, id, { target: 'universal' }) // compiled JS
const ast = compileToAst(source, id) // parsed SFC AST (SfcAst)
const route = compileRouteMeta(source, id) // `@route` metadata, or nullAll three spawn (or reuse, via an in-process memo) the same aihu-compile
binary the Vite plugin uses internally.
Install
npm install @aihu/compiler
# or
bun add @aihu/compilerAuto-generated against @aihu/[email protected].
Package facts
| | |
|---|---|
| Version | 1.3.11 |
| Tier | D — Compiler — Single-File Component (.aihu) → Web Component |
| Published files | 4 entries |
| License | MIT |
Auto-generated against @aihu/[email protected].
Exports
| Subpath | ESM | CJS |
|---|---|---|
| . | ./dist/index.js | — |
| ./codemods/macro-simplification | ./dist/codemods/macro-simplification.js | — |
| ./codemods/state-wrapper | ./dist/codemods/state-wrapper.js | — |
| ./codemods/template-grammar-v2 | ./dist/codemods/template-grammar-v2.js | — |
Auto-generated against @aihu/[email protected].
Dependencies
Peer dependencies:
vite—>=5.0.0@aihu/css-engine—>=0.6.1
Optional dependencies (platform-specific):
@aihu/compiler-darwin-arm64—1.3.11@aihu/compiler-darwin-x64—1.3.11@aihu/compiler-linux-x64-gnu—1.3.11@aihu/compiler-linux-arm64-gnu—1.3.11@aihu/compiler-win32-x64-msvc—1.3.11@aihu/compiler-native-darwin-arm64—1.3.11@aihu/compiler-native-darwin-x64—1.3.11@aihu/compiler-native-linux-x64-gnu—1.3.11@aihu/compiler-native-linux-arm64-gnu—1.3.11@aihu/compiler-native-win32-x64-msvc—1.3.11
Auto-generated against @aihu/[email protected].
See also
Auto-generated against @aihu/[email protected].
License
MIT — see LICENSE.
Auto-generated against @aihu/[email protected].
