@aihu/compiler 1.2.0 → 1.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/README.md +17 -17
- package/dist/index.d.ts +296 -139
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/resolve-binary.js +1 -1
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import{resolveCompilerBinary as e}from"./resolve-binary.js";import{execFileSync as t}from"node:child_process";import{basename as n,dirname as r,resolve as
|
|
2
|
-
Candidate: ${t}\n Error: ${e.message}\n Reinstall @aihu/compiler (or rebuild: cargo build --release --manifest-path packages/compiler/src-native/Cargo.toml), or set AIHU_COMPILER_NATIVE=0 to silence this warning.`)),
|
|
1
|
+
import{resolveCompilerBinary as e}from"./resolve-binary.js";import{execFileSync as t}from"node:child_process";import{basename as n,dirname as r,join as i,resolve as a}from"node:path";import{existsSync as o,readFileSync as s,statSync as c}from"node:fs";import{fileURLToPath as l}from"node:url";import{createRequire as u}from"node:module";import{createHash as d}from"node:crypto";const f=r(l(import.meta.url));function p(){if(typeof process>`u`||!process.platform||!process.arch)return null;switch(`${process.platform}-${process.arch}`){case`darwin-arm64`:return{platformId:`darwin-arm64`,packageName:`@aihu/compiler-native-darwin-arm64`,nodeFile:`aihu-compiler-native.darwin-arm64.node`};case`darwin-x64`:return{platformId:`darwin-x64`,packageName:`@aihu/compiler-native-darwin-x64`,nodeFile:`aihu-compiler-native.darwin-x64.node`};case`linux-x64`:return{platformId:`linux-x64-gnu`,packageName:`@aihu/compiler-native-linux-x64-gnu`,nodeFile:`aihu-compiler-native.linux-x64-gnu.node`};case`linux-arm64`:return{platformId:`linux-arm64-gnu`,packageName:`@aihu/compiler-native-linux-arm64-gnu`,nodeFile:`aihu-compiler-native.linux-arm64-gnu.node`};case`win32-x64`:return{platformId:`win32-x64-msvc`,packageName:`@aihu/compiler-native-win32-x64-msvc`,nodeFile:`aihu-compiler-native.win32-x64-msvc.node`};default:return null}}let m=null,h=!1;function g(e){try{let t=i(r(e),`package.json`);if(!o(t))return null;let n=JSON.parse(s(t,`utf8`));return typeof n.name!=`string`||!n.name.startsWith(`@aihu/compiler-native-`)?null:typeof n.version==`string`?n.version:null}catch{return null}}function _(){return p()}function v(e){return typeof e==`object`&&!!e&&typeof e.compileEnvelope==`function`}function y(){if(m!==null)return m;if(typeof process<`u`&&process.env?.AIHU_COMPILER_NATIVE===`0`)return m={kind:`disabled`},m;let e=u(import.meta.url),t=process.env?.AIHU_COMPILER_NATIVE_ADDON;if(t){let n;try{n=e(t)}catch(e){throw Error(`[@aihu/compiler] AIHU_COMPILER_NATIVE_ADDON is set to '${t}', which failed to load: ${e.message}`)}if(!v(n))throw Error(`[@aihu/compiler] AIHU_COMPILER_NATIVE_ADDON module at '${t}' does not export compileEnvelope()`);return m={kind:`loaded`,addon:n,addonPath:t,origin:`override`,packageVersion:g(t)},m}let n=p();if(n===null)return m={kind:`unavailable`},m;let r=null;try{r=e.resolve(n.packageName)}catch{}let i=[a(f,`../src-native/aihu-compiler-native.node`),a(f,`../src-native/target/release/aihu-compiler-native.node`)],s=r?[r]:i.filter(e=>o(e)),c=r?`package`:`dev-build`;for(let t of s)try{let n=e(t);if(v(n))return m={kind:`loaded`,addon:n,addonPath:t,origin:c,packageVersion:g(t)},m;throw Error(`module at ${t} does not export compileEnvelope()`)}catch(e){return h||(h=!0,console.warn(`[@aihu/compiler] native addon found but failed to load; falling back to the aihu-compile spawn path (identical output, slower).
|
|
2
|
+
Candidate: ${t}\n Error: ${e.message}\n Reinstall @aihu/compiler (or rebuild: cargo build --release --manifest-path packages/compiler/src-native/Cargo.toml), or set AIHU_COMPILER_NATIVE=0 to silence this warning.`)),m={kind:`unavailable`,error:e},m}return m={kind:`unavailable`},m}function b(){return y().kind}function x(){m=null,h=!1}const S=64*1024*1024;function C(e=0){let t=Math.ceil(e/1024)*2,n=process.env.AIHU_COMPILE_TIMEOUT_MS;if(n!==void 0&&n!==``){let e=Number(n);if(Number.isFinite(e)&&e>0)return Math.max(e,t)}return Math.max(12e4,t)}function w(e=0){return{timeout:C(e),maxBuffer:S,killSignal:`SIGKILL`}}function T(e,t,n,r,i){let a=e,o=` binary: ${t}\n args: ${n.length>0?n.join(` `):`(none)`}\n stdin: ${r} bytes\n elapsed: ${i} ms`;if(a.code===`ETIMEDOUT`){let e=C(r);return Error(`[@aihu/compiler] aihu-compile TIMED OUT after ${e} ms and the child was killed.\n\n${o}\n\n This is the known spawn stall, not a slow compile: the compiler normally\n finishes in single-digit milliseconds. The child parks in read() waiting for\n an EOF on stdin that the parent's spawnSync loop never delivers, so without\n this timeout the build would hang at 0% CPU indefinitely (two such children\n were once found still running after 2.5 days).\n\n What to do next:\n - Re-run the build. The stall is intermittent and load-dependent; a retry\n normally succeeds.\n - If it reproduces every time, check the binary directly: ${t} --help\n and rebuild it: cargo build --release -p aihu-compiler\n - If a payload genuinely needs longer than ${e} ms, raise the bound with\n AIHU_COMPILE_TIMEOUT_MS=<milliseconds>. Do not remove it.`)}return a.code===`ENOBUFS`?Error(`[@aihu/compiler] aihu-compile produced more than the ${S} byte\n stdout/stderr limit and the child was killed.\n\n${o}\n\n An emit this large almost certainly means the input is wrong rather than a\n real component. Check what is being passed in before raising the cap.`):null}const ee=r(l(import.meta.url));let E=null;function te(){let e=_();if(e===null)return null;try{let t=JSON.parse(s(a(ee,`../package.json`),`utf8`)).optionalDependencies?.[e.packageName];return typeof t==`string`?t:null}catch{return null}}function ne(e){let t=te();if(t===null)return{ok:!0};if(typeof e.addon.compilerVersion!=`function`)return{ok:!1,reason:`missing-method`,actual:`<no compilerVersion()>`,expected:t};let n;try{n=String(e.addon.compilerVersion())}catch(e){return{ok:!1,reason:`missing-method`,actual:`<compilerVersion() threw: ${e.message}>`,expected:t}}return e.packageVersion===null||e.packageVersion===t?{ok:!0}:{ok:!1,reason:`version-mismatch`,actual:`${e.packageVersion} (reports: ${n})`,expected:t}}function re(e,t){return`[@aihu/compiler] native addon version mismatch — ${t.reason===`missing-method`?`the addon does not implement compilerVersion(), so it predates this handshake`:`the installed addon is not the build this source requires`}.\n Required (packages/compiler/package.json pin): ${t.expected}\n Loaded addon: ${t.actual}\n Addon path: ${e.addonPath}\n Cause: the addon is a PUBLISHED artifact, so a branch that changes Rust\n is stale by construction — the pinned version is not on npm yet and\n \`bun install\` cannot fix it. Using it would silently compile with\n pre-change codegen.`}function D(){if(E!==null)return E;let e=typeof process<`u`?process.env:void 0;if(e?.AIHU_COMPILER_NATIVE===`0`||e?.AIHU_COMPILE_BIN)return E={kind:`spawn`},E;let t=y();if(t.kind!==`loaded`)return E={kind:`spawn`},E;let n=ne(t);if(!n.ok){if(t.origin===`override`)throw Error(`${re(t,n)}\n AIHU_COMPILER_NATIVE_ADDON pinned this addon explicitly, so this fails\n rather than falling back. Unset it (the CLI spawn path is byte-identical),\n set AIHU_COMPILER_NATIVE=0, or rebuild:\n bun packages/compiler/scripts/build-native.ts`);return console.warn(`${re(t,n)}\n Falling back to the aihu-compile spawn path (built from source,\n byte-identical output, slower). Set AIHU_COMPILER_NATIVE=0 to silence\n this, or build the addon from source:\n bun packages/compiler/scripts/build-native.ts`),E={kind:`spawn`},E}return E={kind:`native`,compileEnvelope:t.addon.compileEnvelope.bind(t.addon),stampPath:t.addonPath},E}function ie(){E=null}function O(){let e=D();return e.kind===`native`?e.stampPath:k()}function k(){return process.env.AIHU_COMPILE_BIN??e()}function ae(e){let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(typeof e==`object`&&e&&e.envelope===1)return{kind:`envelope`,envelope:e}}catch{}return{kind:`legacy`,output:e}}function A(e,n,r){let i=D(),a=JSON.stringify(r);if(i.kind===`native`)return{kind:`envelope`,envelope:JSON.parse(i.compileEnvelope(e,a))};let o=k(),s=[...n,`--envelope`,a],c=Date.now(),l;try{l=t(o,s,{input:e,encoding:`utf8`,...w(e.length)})}catch(t){throw T(t,o,s,e.length,Date.now()-c)??t}return ae(l)}const oe=1024,j=new Map;let M=0,N=0,P=0;function se(e){try{let t=c(e);return`${e}:${t.mtimeMs}:${t.size}`}catch{return e}}function F(e,t,n,r,i){return d(`sha256`).update(e).update(`\0`).update(n).update(`\0`).update(r).update(`\0`).update(se(i)).update(`\0`).update(t).digest(`hex`)}function I(e,t,n,r,i,a){let o=F(e,t,n,r,i),s=j.get(o);if(s!==void 0)return M++,s;let c=a();if(N++,j.size>=1024){let e=j.keys().next().value;e!==void 0&&j.delete(e)}return j.set(o,c),c}function L(e,t,n,r,i,a){let o=F(e,t,n,r,i);if(!j.has(o)){if(j.size>=1024){let e=j.keys().next().value;e!==void 0&&j.delete(e)}j.set(o,a),P++}}function ce(){j.clear(),M=0,N=0,P=0}function le(){return{size:j.size,hits:M,misses:N,seeds:P}}function R(){return process.env.AIHU_COMPILE_BIN??e()}function ue(e,t){let n=[{kind:`code`,brace:0}],r=0;for(let i=t;i<e.length;i++){let t=n[n.length-1];if(t===void 0)return-1;let a=e[i];if(t.kind===`tpl`){a===`\\`?i++:a==="`"?n.pop():a===`$`&&e[i+1]===`{`&&(n.push({kind:`code`,brace:0}),i++);continue}if(a===`'`||a===`"`)for(i++;i<e.length&&e[i]!==a;)e[i]===`\\`&&i++,i++;else if(a==="`")n.push({kind:`tpl`});else if(a===`/`&&e[i+1]===`/`)for(;i<e.length&&e[i]!==`
|
|
3
|
+
`;)i++;else if(a===`/`&&e[i+1]===`*`){for(i+=2;i<e.length&&!(e[i]===`*`&&e[i+1]===`/`);)i++;i++}else if(a===`(`)r++;else if(a===`)`){if(r--,r===0)return i}else a===`{`?t.brace++:a===`}`&&(t.brace===0&&n.length>1?n.pop():t.brace--)}return-1}function z(e,t,n){let r=/defineElement\(\s*['"][^'"]+['"]\s*,\s*defineComponent\(/.exec(e);if(r==null)return e;let i=ue(e,r.index+r[0].length-1);if(i===-1)return e;let a=`shadowMode: '${t}'${n?`, lightScopeId: '${n}'`:``}`,o=e.slice(i+1);if(/^\s*\)/.test(o))return`${e.slice(0,i+1)}, { ${a} }${o}`;let s=/^\s*,\s*\{/.exec(o);if(s&&!/^\s*,\s*\{[^}]*\bshadowMode\b/.test(o)){let t=i+1+s[0].length;return`${e.slice(0,t)} ${a},${e.slice(t)}`}return e}function B(e,t){return e.replace(`const __AIHU_LIGHT_SCOPE_ID__: string | undefined = undefined`,`const __AIHU_LIGHT_SCOPE_ID__: string | undefined = '${t}'`)}function V(e){return e.replace(/\(ctx\.host as ShadowRoot\)\.adoptedStyleSheets\s*=\s*\[__style__\];?/,`if (!document.adoptedStyleSheets.includes(__style__)) document.adoptedStyleSheets = [...document.adoptedStyleSheets, __style__];`)}function H(e){return/^\/\/ @aihu:island (static|interactive)$/m.exec(e)?.[1]===`static`?`static`:`interactive`}function U(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;let t=e?.message;return typeof t==`string`?t:String(e)}function W(e){let t=U(e),n=e?.code;return n===`ERR_MODULE_NOT_FOUND`||n===`MODULE_NOT_FOUND`||/cannot find (module|package)/i.test(t)?/['"`]vite['"`]/.test(t):!1}function G(e,t,n,r,i){return`[@aihu/compiler] TypeScript strip failed for ${t} — vite ${n} \`${e}\` (${r?`server`:`client`} environment) threw. Returning the un-stripped TypeScript would corrupt the build silently and resurface as an unrelated bundler PARSE_ERROR on this file, so it fails here instead. Underlying error: ${U(i)}`}async function K(e,t,n,r){let i=e.version??`unknown`;if(typeof e.transformWithOxc==`function`)try{return{code:(await e.transformWithOxc(t,`component.ts`,{lang:`ts`,sourcemap:!1})).code,map:null}}catch(e){throw Error(G(`transformWithOxc`,n,i,r,e),{cause:e})}if(typeof e.transformWithEsbuild==`function`)try{return{code:(await e.transformWithEsbuild(t,`component.ts`,{target:`esnext`,sourcemap:!1})).code,map:null}}catch(e){throw Error(G(`transformWithEsbuild`,n,i,r,e),{cause:e})}return{code:t,moduleType:`ts`,map:null}}function q(e){let t=/^\/\/ @aihu:component-tags (.+)$/m.exec(e);return t===null?[]:t[1].split(`,`)}function J(e){return[...new Set(Array.from(e.matchAll(/__aihu_schild\('([^']+)'/g),e=>e[1]))].sort()}function Y(e){let t=/^\/\/ @aihu:extract read=(\S+) call=(\S+)$/m.exec(e);return t?{read:t[1],call:t[2]}:null}function X(e){if(e.size===0)return[];let t=new Map,n=new Map;for(let{read:r,call:i}of e.values())t.set(r,(t.get(r)??0)+1),n.set(i,(n.get(i)??0)+1);let r=[`[aihu] extract census — ${e.size} surface(s)`];for(let[e,n]of[...t.entries()].sort())r.push(` read=${e}: ${n}`);for(let[e,t]of[...n.entries()].sort())r.push(` call=${e}: ${t}`);return r}function de(e){let t=/defineElement\(\s*['"]([^'"]+)['"]/m.exec(e);return t?t[1]??null:null}function fe(e){let t=/defineComponent\(\s*\{/.exec(e);if(t===null)return!1;let n=/\bbase\s*:/g;return n.lastIndex=t.index+t[0].length,n.test(e)}function pe(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===47;)t--;return e.slice(0,t)}function me(e,t){let n=pe(t.replace(/\\/g,`/`).replace(/^\.?\//,``));return n?e.replace(/\\/g,`/`).includes(`/${n}/`):!1}function he(e){return`aihu-layout-${e.toLowerCase()}`}function ge(e){let t=``;for(let n=0;n<e.length;n++){let r=e.charAt(n);if(n>0&&r>=`A`&&r<=`Z`){let r=e.charAt(n-1),i=e.charAt(n+1);(r>=`a`&&r<=`z`||r>=`0`&&r<=`9`||r>=`A`&&r<=`Z`&&i>=`a`&&i<=`z`)&&(t+=`-`)}t+=r.toLowerCase()}return t}function _e(e){let t=e.indexOf(`const createOutletBoundary = () => {`);if(t===-1)return e;let n=/return host;[^\S\n]*\n\};/g;n.lastIndex=t+36;let r=n.exec(e);return r===null?e:e.slice(0,t)+`const createOutletBoundary = () => branch('div', { 'data-aihu-outlet': '' }, []);`+e.slice(r.index+r[0].length)}function ve(e,t){let n=e.replace(/import\s*\{([^{}]*)\}\s*from\s*'@aihu\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_hmrReplace`)||n.push(`_hmrReplace`),`import { ${n.join(`, `)} } from '@aihu/runtime'`}).replace(/\bdefineComponent\(/,`defineComponent(__aihu_setup__ = `),r=`
|
|
3
4
|
export { __aihu_setup__ as default }
|
|
4
5
|
|
|
5
6
|
if (typeof __DEV__ !== 'undefined' && __DEV__ && import.meta.hot) {
|
|
@@ -14,7 +15,7 @@ if (typeof __DEV__ !== 'undefined' && __DEV__ && import.meta.hot) {
|
|
|
14
15
|
})
|
|
15
16
|
}
|
|
16
17
|
`;return`let __aihu_setup__: ((ctx: any) => any) | undefined
|
|
17
|
-
`+n+r}function
|
|
18
|
+
`+n+r}function ye(e,t){let n=e.replace(/import\s*\{([^{}]*)\}\s*from\s*'@aihu\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_hydrateOnVisible`)||n.push(`_hydrateOnVisible`),`import { ${n.join(`, `)} } from '@aihu/runtime'`}),r=n.replace(/defineElement\(\s*('[^']+'|"[^"]+")\s*,\s*defineComponent\(/,(e,t)=>`defineElement(${t}, __aihu_wrap_defer__(defineComponent(`);if(r===n)return e;let i=r.replace(/\)\s*\)\s*\nexport\s/,`)))
|
|
18
19
|
export `);return i===r&&(i=r.replace(/\)\s*\)\s*$/,`)))
|
|
19
20
|
`)),i===r?e:`
|
|
20
21
|
// Plan 3.3 (Islands) — defer attribute support. Wraps the constructor
|
|
@@ -33,13 +34,13 @@ function __aihu_wrap_defer__<T extends typeof HTMLElement>(Ctor: T): T {
|
|
|
33
34
|
}
|
|
34
35
|
return Ctor
|
|
35
36
|
}
|
|
36
|
-
`+i}function
|
|
37
|
+
`+i}function be(e,t){if(!/defineElement\(\s*['"][^'"]+['"]\s*,\s*defineComponent\(/.test(e))return e;let n=e.replace(/^[^\S\r\n]*import\s*\{[^{}]*\}\s*from\s*'@aihu\/runtime'(?:\s*;)?\s*$/m,``).replace(/import\s*\{([^{}]*)\}\s*from\s*'@aihu\/arbor'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`mount`)||n.push(`mount`),`import { ${n.join(`, `)} } from '@aihu/arbor'`}),r=/\)\s*\)\s*$/,i=/\),\s*\{\s*shadowMode:\s*'shadow'\s*\}\)\s*$/,a=r.test(n)?r:i.test(n)?i:null;if(a===null)return e;let o=JSON.stringify(t);return`// AIHU_STATIC_ISLAND — zero @aihu/runtime references\n${n.replace(/defineElement\(\s*['"][^'"]+['"]\s*,\s*defineComponent\(/,`customElements.define(${o}, class extends HTMLElement {\n connectedCallback() {\n const root = this.attachShadow({ mode: 'open' })\n const __aihu_setup__ = (`).replace(a,`)
|
|
37
38
|
mount(__aihu_setup__({ host: root, element: this }), root)
|
|
38
39
|
}
|
|
39
40
|
})
|
|
40
|
-
`)}`}function
|
|
41
|
+
`)}`}function xe(e,r,i){let a=n(r,`.aihu`),o=ge(a),s=/^[A-Z]/.test(a)&&!o.includes(`-`)?a:o,c=[`--stdin`,`--tag`,i?.tag??s,`--path`,r];if(i?.sidecarOut&&c.push(`--sidecar-out`,i.sidecarOut),i?.target&&c.push(`--target`,i.target),i?.strictTemplates&&c.push(`--strict-templates`),i?.sidecarOut){let n=R(),r=Date.now();try{return{code:t(n,c,{input:e,encoding:`utf8`,...w(e.length)}),map:null}}catch(t){throw T(t,n,c,e.length,Date.now()-r)??t}}let l=O(),u=i?.target??`universal`,d=i?.tag===void 0;return{code:I(`transform`,e,r,`target=${i?.target??``}|tag=${i?.tag??``}|strict=${i?.strictTemplates===!0}`,l,()=>{let t=A(e,c,{tag:i?.tag??s,path:r,targets:[u],emits:d?[`js`,`ast`,`route`]:[`js`],...i?.strictTemplates?{strictTemplates:!0}:{}});if(t.kind===`legacy`)return t.output;let n=t.envelope;d&&(n.astJson!==void 0&&L(`ast`,e,r,``,l,n.astJson),L(`route`,e,r,``,l,n.routeJson??`null`));let a=n.targets[u]?.js;if(a===void 0)throw Error(`[@aihu/compiler] envelope reply missing js for target '${u}'`);return a}),map:null}}function Se(e){return e.replace(/\\/g,`\\\\`).replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Ce(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=i+t.length,o=e.indexOf(n,a);return o===-1?null:e.slice(0,a)+r+e.slice(o)}function we(e,t){if(!t.trim())return e;let n=Se(t),r=Ce(e,"export const __aihu_css__ = `","`",n);return r===null?`${e}\nexport const __aihu_css__ = \`${n}\`\n`:r}function Te(e,t){if(!t.trim())return e;let n=Se(t),r=Ce(e,"__style__.replaceSync(`","`);",n);if(r!==null)return r;let i=/defineComponent\(\s*\((__?[A-Za-z0-9_]+)\)\s*=>\s*\{/,a=i.exec(e);if(a==null)return e;let o=a[1]===`_ctx`?`ctx`:a[1],s=e.split(`
|
|
41
42
|
`),c=-1;for(let e=s.length-1;e>=0;e--){let t=(s[e]??``).trim();if(t.startsWith(`import `)||t.startsWith(`import{`)){c=e;break}}let l=`const __style__ = new CSSStyleSheet();\n__style__.replaceSync(\`${n}\`);`;c===-1?s.unshift(l):s.splice(c+1,0,l);let u=s.join(`
|
|
42
|
-
`);return u=u.replace(i,`defineComponent((${o}) => {\n (${o}.host as ShadowRoot).adoptedStyleSheets = [__style__];`),u}const
|
|
43
|
+
`);return u=u.replace(i,`defineComponent((${o}) => {\n (${o}.host as ShadowRoot).adoptedStyleSheets = [__style__];`),u}const Ee=`\0virtual:aihu-utility/`;function De(e){let t=5381;for(let n=0;n<e.length;n++)t=(t*33^e.charCodeAt(n))>>>0;return t}function Oe(e){return De(e).toString(36)}function ke(e){return De(e).toString(16).padStart(8,`0`)}function Ae(e,t,n){if(!t.trim())return null;let r=`${Ee}${Oe(n)}.css`;return{code:`import ${JSON.stringify(r)};\n`+e,virtualId:r}}function je(e,r,i){let a=[`--stdin`,`--tag`,r?n(r,`.aihu`):`Component`,`--sidecar-stdout`];r&&a.push(`--path`,r),i?.strictTemplates&&a.push(`--strict-templates`),i?.target&&a.push(`--target`,i.target);let o=R(),s=Date.now();try{return t(o,a,{input:e,encoding:`utf8`,stdio:[`pipe`,`pipe`,`pipe`],...w(e.length)})}catch(t){throw T(t,o,a,e.length,Date.now()-s)??t}}function Me(e,t){let r=t?n(t,`.aihu`):`Component`,i=[`--stdin`,`--tag`,r,`--ast-json`];t&&i.push(`--path`,t);let a=O(),o=I(`ast`,e,t??``,``,a,()=>{let n=A(e,i,{tag:r,...t?{path:t}:{},emits:[`ast`]});if(n.kind===`legacy`)return n.output;let a=n.envelope.astJson;if(a===void 0)throw Error(`[@aihu/compiler] envelope reply missing astJson`);return a});return JSON.parse(o)}function Ne(e,t){let r=t?n(t,`.aihu`):`Component`,i=[`--stdin`,`--tag`,r,`--route-json`];t&&i.push(`--path`,t);let a=O(),o=I(`route`,e,t??``,``,a,()=>{let n=A(e,i,{tag:r,...t?{path:t}:{},emits:[`route`]});return n.kind===`legacy`?n.output:n.envelope.routeJson??`null`}).trim();return o===``||o===`null`?null:JSON.parse(o)}function Z(e){let t;t=e.includes(`from '@aihu/arbor'`)?e.replace(/import\s*\{([^{}]*)\}\s*from\s*'@aihu\/arbor'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`mount`)||n.push(`mount`),`import { ${n.join(`, `)} } from '@aihu/arbor'`}):`import { mount } from '@aihu/arbor'\n${e}`,/import\s+\{[^{}]*\}\s+from\s+'@aihu\/signals'/.test(t)?t=t.replace(/import\s*\{([^{}]*)\}\s*from\s*'@aihu\/signals'/,(e,t)=>{if(e.startsWith(`import type`))return e;let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`signal`)||n.push(`signal`),`import { ${n.join(`, `)} } from '@aihu/signals'`}):/^[^\S\n]*import\b[^\n]*from[^\S\n]*'@aihu\/signals'/m.test(t)?/import\s+type\s+\{[^{}]*\}\s+from\s+'@aihu\/signals'/.test(t)&&!t.match(/import\s+\{[^{}]*\}\s+from\s+'@aihu\/signals'/)&&(t=t.replace(/(import\s+type\s+\{[^{}]*\}\s+from\s+'@aihu\/signals')/,(e,t)=>`${t}\nimport { signal } from '@aihu/signals'`)):t=t.replace(/import\s*\{[^{}]*\}\s*from\s*'@aihu\/arbor'/,e=>`${e}\nimport { signal } from '@aihu/signals'`),t=t.replace(/import\s*\{([^{}]*)\}\s*from\s*'@aihu\/runtime'/,(e,t)=>{let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.includes(`_setMount`)||n.push(`_setMount`),n.includes(`_setSignal`)||n.push(`_setSignal`),`import { ${n.join(`, `)} } from '@aihu/runtime'`});let n=t.split(`
|
|
43
44
|
`),r=-1;for(let e=n.length-1;e>=0;e--){let t=(n[e]??``).trim();if(t.startsWith(`import `)||t.startsWith(`import{`)){r=e;break}}return r!==-1&&(n.splice(r+1,0,`_setMount(mount)`,`_setSignal(signal)`,``),t=n.join(`
|
|
44
|
-
`)),t}let Q,$=!1;async function
|
|
45
|
+
`)),t}let Q,$=!1;async function Pe(e,t,n){if(Q===null)return``;if(process.env.AIHU_COMPILE_BIN==null)try{process.env.AIHU_COMPILE_BIN=R()}catch{}if(Q===void 0)try{Q=await import(`@aihu/css-engine`)}catch{return Q=null,``}try{return Q.compileSfc(e,t,n)}catch(e){if(!$){$=!0;let t=e instanceof Error?e.message:String(e);console.warn(`[@aihu/compiler] @aihu/css-engine is installed but compileSfc() failed; utility classes will not emit. Original error: ${t}\nHint: ensure the native css-core binary is installed (install/upgrade @aihu/css-engine + its per-platform optional dep, or run \`cargo build --release -p aihu-css-core\` in a dev clone).`)}return``}}function Fe(e){let t=e?.islands!==!1,r=e?.shadowMode,i=e?.target,a=e?.layoutsDir??`src/layouts`,o=new Map,s=new Map;return{name:`aihu-compiler`,enforce:`pre`,buildEnd(){for(let e of X(s))console.info(e)},resolveId(e){return e.startsWith(`\0virtual:aihu-utility/`)?e:null},load(e){return e.startsWith(`\0virtual:aihu-utility/`)?o.get(e)??null:null},transform(e,c){let l=c.split(`?`)[0];if(!l.endsWith(`.aihu`))return;let u=this?.environment?.config?.consumer===`server`,d=i??(u?`server`:void 0);return(async()=>{let i=me(l,a),c=i?he(n(l,`.aihu`)):void 0,f=xe(e,l,{...d?{target:d}:{},...c?{tag:c}:{}}),p=Y(f.code);p&&s.set(l,p);let m=/^\/\/ @aihu:shadow (light|shadow)\b/m.exec(f.code)?.[1],h=/^\/\/ @aihu:shadow-default (light|shadow)\b/m.exec(f.code)?.[1]??(i?`light`:void 0),g=m??r??h,_=g===`light`?ke(l):void 0,v=g==null?f.code:z(f.code,g,_);_&&(v=B(v,_)),g===`light`&&(v=V(v)),i&&(v=_e(v));let y=await Pe(e,l,_);if(y)if(g===`light`){let e=Ae(v,y,l);e&&(o.set(e.virtualId,y),v=e.code)}else v=Te(v,y),u&&(v=we(v,y));let b=de(v),x,S=fe(v);if(u){x=v,_&&(x+=`\nexport const __aihu_light_scope__ = '${_}'\n`),b!==null&&(x+=`\nexport const __aihu_tag__ = '${b}'\n`),g!=null&&(x+=`\nexport const __aihu_shadow__ = '${g}'\n`);let e=J(x);e.length>0&&(x+=`\nexport const __aihu_child_tags__ = ${JSON.stringify(e)}\n`);let t=q(v);t.length>0&&(x+=`\nexport const __aihu_referenced_tags__ = ${JSON.stringify(t)}\n`)}else t&&b!==null&&!S&&g!==`light`&&H(v)===`static`?x=be(v,b):b===null?(x=v,x=Z(x)):(x=ve(v,b),x=ye(x,b),x=Z(x));let C;try{C=await import(`vite`)}catch(e){if(W(e))return{code:x,map:null};throw Error(`[@aihu/compiler] Could not load \`vite\` to strip TypeScript from ${l}. Vite appears to be installed but failed to load, so this is NOT the "running outside Vite" case and the TypeScript must not be handed back un-stripped. Underlying error: ${U(e)}`,{cause:e})}return await K(C,x,l,u)})()}}}export{Ee as VIRTUAL_UTILITY_PREFIX,oe as _MEMO_MAX_ENTRIES,ye as _buildDeferredHydration,be as _buildStaticIsland,ce as _clearTransformMemo,A as _compileViaBackend,J as _deriveChildTags,U as _errMessage,Te as _foldCssEngineStyles,Ae as _foldCssEngineStylesGlobal,we as _foldSsrCssExport,X as _formatExtractCensus,b as _getCompilerNativeStateKind,V as _globalizeAuthoredStyle,Oe as _hashIdForUtilityCss,Z as _injectAutoWiring,B as _injectLightScopeId,z as _injectShadowMode,me as _isLayoutFile,W as _isViteMissing,he as _layoutTag,ke as _lightScopeId,q as _parseComponentTagsMarker,Y as _parseExtractMarker,H as _parseIslandMarker,_e as _passivizeOutlet,ie as _resetCompileBackend,x as _resetCompilerNative,D as _resolveCompileBackend,G as _stripFailure,K as _stripTypes,le as _transformMemoStats,Fe as aihuCompilerPlugin,Ne as compileRouteMeta,je as compileSidecar,Me as compileToAst,ge as kebabComponentTag,y as loadCompilerNative,xe as transform};
|
|
45
46
|
//# sourceMappingURL=index.js.map
|