@aihu/compiler 1.3.0 → 1.3.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-binary.d.ts","names":[],"sources":["../js/resolve-binary.ts"],"mappings":";;AA2FA;;;;;AAiDA;;;;;;;;;;;;iBAjDgB,kBAAA,CAAmB,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDnB,qBAAA,CAAA"}
1
+ {"version":3,"file":"resolve-binary.d.ts","names":[],"sources":["../js/resolve-binary.ts"],"mappings":";;AA2FA;AAAkC;AAAA;AAAA;AAAkB;AAiDpD;AAAqC;AAAA;AAAA;AAAA;;;;;;;;iBAjDrB,kBAAA,CAAmB,SAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDpC,qBAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- import{dirname as e,join as t,resolve as n}from"node:path";import{accessSync as r,constants as i,statSync as a}from"node:fs";import{fileURLToPath as o}from"node:url";import{createRequire as s}from"node:module";const c=e(o(import.meta.url));function l(){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-darwin-arm64`,binFile:`aihu-compile`};case`darwin-x64`:return{platformId:`darwin-x64`,packageName:`@aihu/compiler-darwin-x64`,binFile:`aihu-compile`};case`linux-x64`:return{platformId:`linux-x64-gnu`,packageName:`@aihu/compiler-linux-x64-gnu`,binFile:`aihu-compile`};case`linux-arm64`:return{platformId:`linux-arm64-gnu`,packageName:`@aihu/compiler-linux-arm64-gnu`,binFile:`aihu-compile`};case`win32-x64`:return{platformId:`win32-x64-msvc`,packageName:`@aihu/compiler-win32-x64-msvc`,binFile:`aihu-compile.exe`};default:return null}}let u=null;function d(e){try{let t=a(e);return!t.isFile()||t.size===0?!1:(r(e,i.X_OK),!0)}catch{return!1}}function f(){if(u!==null)return u;let r=process.env.AIHU_COMPILE_BIN;if(r){if(!d(r))throw Error(`[@aihu/compiler] AIHU_COMPILE_BIN is set to '${r}', which is not an executable file.`);return u=r,u}let i=l(),a=process.platform===`win32`?`.exe`:``,o=[n(c,`../../../target/release`,`aihu-compile${a}`),n(c,`../../../target/debug`,`aihu-compile${a}`),n(c,`../bin`,`aihu-compile${a}`)];for(let e of o)if(d(e))return u=e,u;if(i){let n=s(import.meta.url);try{let r=t(e(n.resolve(`${i.packageName}/package.json`)),i.binFile);if(d(r))return u=r,u}catch{}}throw p(i,o)}function p(e,t){return Error(e===null?`[@aihu/compiler] No prebuilt aihu-compile binary for this platform.\n\n Platform: ${typeof process<`u`?`${process.platform}-${process.arch}`:`unknown`}\n\n @aihu/compiler ships prebuilt binaries for darwin-arm64, darwin-x64,\n linux-x64-gnu (glibc), linux-arm64-gnu (glibc) and win32-x64-msvc.\n Your platform is not in that set.\n\n To build from source you need a Rust toolchain, then run from the repo root:\n cargo build --release -p aihu-compile\n\n Checked dev fallback paths: ${t.join(`, `)}`:`[@aihu/compiler] Native compiler binary not found for this platform.\n\n Platform: ${e.platformId}\n Expected package: ${e.packageName}\n Expected file: ${e.packageName}/${e.binFile}\n\n This binary is distributed as an optionalDependency of @aihu/compiler.\n Your package manager may have skipped it (optionalDependencies are\n silently dropped on install failure).\n\n To reinstall:\n npm install @aihu/compiler\n # or: pnpm install or: bun install\n\n If you are working in the aihu monorepo, build from source instead:\n cargo build --release -p aihu-compile\n Checked dev fallback paths: ${t.join(`, `)}`)}export{d as isUsableExecutable,f as resolveCompilerBinary};
1
+ import{createRequire as e}from"node:module";import{dirname as t,join as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{accessSync as a,constants as o,statSync as s}from"node:fs";const c=t(i(import.meta.url));function l(){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-darwin-arm64`,binFile:`aihu-compile`};case`darwin-x64`:return{platformId:`darwin-x64`,packageName:`@aihu/compiler-darwin-x64`,binFile:`aihu-compile`};case`linux-x64`:return{platformId:`linux-x64-gnu`,packageName:`@aihu/compiler-linux-x64-gnu`,binFile:`aihu-compile`};case`linux-arm64`:return{platformId:`linux-arm64-gnu`,packageName:`@aihu/compiler-linux-arm64-gnu`,binFile:`aihu-compile`};case`win32-x64`:return{platformId:`win32-x64-msvc`,packageName:`@aihu/compiler-win32-x64-msvc`,binFile:`aihu-compile.exe`};default:return null}}let u=null;function d(e){try{let t=s(e);return!t.isFile()||t.size===0?!1:(a(e,o.X_OK),!0)}catch{return!1}}function f(){if(u!==null)return u;let i=process.env.AIHU_COMPILE_BIN;if(i){if(!d(i))throw Error(`[@aihu/compiler] AIHU_COMPILE_BIN is set to '${i}', which is not an executable file.`);return u=i,u}let a=l(),o=process.platform===`win32`?`.exe`:``,s=[r(c,`../../../target/release`,`aihu-compile${o}`),r(c,`../../../target/debug`,`aihu-compile${o}`),r(c,`../bin`,`aihu-compile${o}`)];for(let e of s)if(d(e))return u=e,u;if(a){let r=e(import.meta.url);try{let e=r.resolve(`${a.packageName}/package.json`),i=n(t(e),a.binFile);if(d(i))return u=i,u}catch{}}throw p(a,s)}function p(e,t){return Error(e===null?`[@aihu/compiler] No prebuilt aihu-compile binary for this platform.\n\n Platform: ${typeof process<`u`?`${process.platform}-${process.arch}`:`unknown`}\n\n @aihu/compiler ships prebuilt binaries for darwin-arm64, darwin-x64,\n linux-x64-gnu (glibc), linux-arm64-gnu (glibc) and win32-x64-msvc.\n Your platform is not in that set.\n\n To build from source you need a Rust toolchain, then run from the repo root:\n cargo build --release -p aihu-compile\n\n Checked dev fallback paths: ${t.join(`, `)}`:`[@aihu/compiler] Native compiler binary not found for this platform.\n\n Platform: ${e.platformId}\n Expected package: ${e.packageName}\n Expected file: ${e.packageName}/${e.binFile}\n\n This binary is distributed as an optionalDependency of @aihu/compiler.\n Your package manager may have skipped it (optionalDependencies are\n silently dropped on install failure).\n\n To reinstall:\n npm install @aihu/compiler\n # or: pnpm install or: bun install\n\n If you are working in the aihu monorepo, build from source instead:\n cargo build --release -p aihu-compile\n Checked dev fallback paths: ${t.join(`, `)}`)}export{d as isUsableExecutable,f as resolveCompilerBinary};
2
2
  //# sourceMappingURL=resolve-binary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-binary.js","names":[],"sources":["../js/resolve-binary.ts"],"sourcesContent":["/**\n * resolve-binary.ts — call-time resolver for the `aihu-compile` Rust binary.\n *\n * A near-mechanical clone of packages/css-engine/src/index.ts's resolveBinary()\n * machinery, renamed for the compiler: the per-platform packages are\n * `@aihu/compiler-<platform>`, the executable is `aihu-compile[.exe]`, and the\n * dev/source fallback is the workspace-root `target/release|debug/aihu-compile`.\n *\n * Unlike @aihu/server (a napi `.node` addon loaded via require), the compiler\n * invokes `aihu-compile` as a CLI SUBPROCESS. So the platform package exposes a\n * raw executable file, and we resolve its absolute PATH — we never `require()`\n * the binary itself. The SAME order is used by the bin shim\n * (bin/aihu-compile.mjs) and the vite plugin (js/index.ts).\n */\nimport { accessSync, constants, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\ninterface PlatformDescriptor {\n readonly platformId: string\n readonly packageName: string\n /** Executable filename inside the platform package. */\n readonly binFile: string\n}\n\nfunction detectPlatform(): PlatformDescriptor | null {\n if (typeof process === 'undefined' || !process.platform || !process.arch) {\n return null\n }\n const key = `${process.platform}-${process.arch}`\n switch (key) {\n case 'darwin-arm64':\n return {\n platformId: 'darwin-arm64',\n packageName: '@aihu/compiler-darwin-arm64',\n binFile: 'aihu-compile',\n }\n case 'darwin-x64':\n return {\n platformId: 'darwin-x64',\n packageName: '@aihu/compiler-darwin-x64',\n binFile: 'aihu-compile',\n }\n case 'linux-x64':\n // We only ship glibc; musl users fall through to the dev/source path.\n return {\n platformId: 'linux-x64-gnu',\n packageName: '@aihu/compiler-linux-x64-gnu',\n binFile: 'aihu-compile',\n }\n case 'linux-arm64':\n // glibc aarch64; musl users fall through to the dev/source path.\n return {\n platformId: 'linux-arm64-gnu',\n packageName: '@aihu/compiler-linux-arm64-gnu',\n binFile: 'aihu-compile',\n }\n case 'win32-x64':\n return {\n platformId: 'win32-x64-msvc',\n packageName: '@aihu/compiler-win32-x64-msvc',\n binFile: 'aihu-compile.exe',\n }\n default:\n return null\n }\n}\n\nlet _binPath: string | null = null\n\n/**\n * Whether `candidate` is a usable `aihu-compile` executable — NOT merely a\n * present file.\n *\n * The per-platform packages (`@aihu/compiler-<platform>`) carry a placeholder\n * `aihu-compile` in source; the real prebuilt binary is only injected by the\n * release CI. Once those packages become resolvable in the workspace, a bare\n * `existsSync` would happily return the non-executable placeholder, which then\n * blows up with EACCES inside `spawnSync`/`execFileSync`. So we must verify the\n * candidate is actually runnable before accepting it.\n *\n * POSIX: require the execute bit (X_OK). A zero-byte/text placeholder without\n * +x fails here and we fall through to the dev `target/` fallback.\n *\n * Windows: there is no execute bit — `accessSync(_, X_OK)` is effectively\n * always true — so we additionally require a non-empty regular file, which\n * still rejects a zero-byte placeholder.\n */\nexport function isUsableExecutable(candidate: string): boolean {\n try {\n const st = statSync(candidate)\n if (!st.isFile() || st.size === 0) return false\n accessSync(candidate, constants.X_OK)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Resolve the absolute path to the `aihu-compile` executable.\n *\n * Resolution order:\n * 1. Workspace dev build — `target/release|debug/` or the package-local\n * staged binary (`packages/compiler/bin/aihu-compile`). Only present in a\n * dev clone (`cargo build --release -p aihu-compile`) or a CI job that\n * stages one. Checked FIRST: see FEL-427 / #427 below.\n * 2. The per-platform optionalDependency package (`@aihu/compiler-<platform>`)\n * shipped to npm consumers — resolved via\n * `createRequire(...).resolve('<pkg>/package.json')` so it works in both\n * ESM and CJS and respects the consumer's node_modules layout. This is the\n * ONLY candidate a real npm consumer ever has, since none of the dev paths\n * exist outside this monorepo.\n *\n * If neither path yields a binary, throws a structured error pointing at the\n * missing optionalDependency (platform supported) or the dev fallback (platform\n * unsupported).\n *\n * ## Why dev build wins (#427)\n *\n * `@aihu/compiler`'s optionalDependencies are resolvable inside this very\n * monorepo the moment `bun install` has run once — but the version actually\n * fetched from the registry lags behind whatever the in-repo Rust source can\n * do (per-platform packages are only republished on release, not on every\n * commit). A dev machine or CI job that built `aihu-compile` fresh from HEAD\n * therefore used to have its correct binary silently SHADOWED by an older\n * published one that happened to already be sitting in `node_modules` — and\n * that older binary doesn't error on a flag it doesn't recognize (e.g.\n * `--sidecar-stdout`), it just ignores it and runs its default codegen path,\n * so the caller gets a plausible-looking WRONG answer instead of a crash. That\n * was the actual cause of `packages/tsc/tests/language-plugin.test.ts` failing\n * intermittently depending on whether a given checkout had ever run `bun\n * install`: the published `@aihu/compiler-darwin-arm64` sitting in\n * `node_modules` predates `--sidecar-stdout` entirely, so it fell back to a\n * normal `defineComponent(...)` transform instead of the `__aihu_template`\n * type-check sidecar the fresh binary emits.\n */\nexport function resolveCompilerBinary(): string {\n if (_binPath !== null) return _binPath\n\n // 0. `AIHU_COMPILE_BIN` — an explicit override, checked before everything else.\n const override = process.env.AIHU_COMPILE_BIN\n if (override) {\n if (!isUsableExecutable(override)) {\n throw new Error(\n `[@aihu/compiler] AIHU_COMPILE_BIN is set to '${override}', which is not an executable file.`,\n )\n }\n _binPath = override\n return _binPath\n }\n\n const descriptor = detectPlatform()\n\n // 1. Workspace dev build. Only exists in a dev clone or a CI job that staged\n // one — checked FIRST so it is never shadowed by an older published package\n // (see the #427 note above).\n //\n // This module builds to packages/compiler/dist/resolve-binary.js, so the\n // workspace root is three levels up (dist → compiler → packages → root).\n // `aihu-compile` is a workspace member; cargo emits its [[bin]] to the\n // workspace-root ./target.\n const ext = process.platform === 'win32' ? '.exe' : ''\n const devCandidates = [\n resolve(__dirname, '../../../target/release', `aihu-compile${ext}`),\n resolve(__dirname, '../../../target/debug', `aihu-compile${ext}`),\n // Package-local staged binary: `packages/compiler/bin/aihu-compile`. This is\n // where CI and the release pipeline place a prebuilt binary that was built\n // or downloaded out-of-band — e.g. deploy-docs.yml's \"Build & deploy\" job\n // downloads the linux-x64 artifact here (without a cargo `target/`), and\n // release.yml's \"Stage compiler bin\" step does the same so prepublish builds\n // can compile. In published consumers this dir holds only the `.mjs` shim, so\n // this candidate simply doesn't exist there and we fall through.\n resolve(__dirname, '../bin', `aihu-compile${ext}`),\n ]\n for (const c of devCandidates) {\n if (isUsableExecutable(c)) {\n _binPath = c\n return _binPath\n }\n }\n\n // 2. Per-platform optionalDependency package (the published-consumer path).\n //\n // Accept the candidate ONLY if it is a usable executable. A present-but-\n // non-executable placeholder (the in-source stub that becomes resolvable once\n // the per-platform packages are pinned in the lockfile) must NOT be returned —\n // doing so spawns a non-executable file and fails with EACCES.\n if (descriptor) {\n const requireFn = createRequire(import.meta.url)\n try {\n const pkgJson = requireFn.resolve(`${descriptor.packageName}/package.json`)\n const candidate = join(dirname(pkgJson), descriptor.binFile)\n if (isUsableExecutable(candidate)) {\n _binPath = candidate\n return _binPath\n }\n } catch {\n // Package not installed (optionalDependency skipped for this platform, or\n // a partial install).\n }\n }\n\n throw buildMissingBinaryError(descriptor, devCandidates)\n}\n\nfunction buildMissingBinaryError(\n descriptor: PlatformDescriptor | null,\n devCandidates: string[],\n): Error {\n if (descriptor === null) {\n return new Error(\n `[@aihu/compiler] No prebuilt aihu-compile binary for this platform.\\n\\n` +\n ` Platform: ${typeof process !== 'undefined' ? `${process.platform}-${process.arch}` : 'unknown'}\\n\\n` +\n ` @aihu/compiler ships prebuilt binaries for darwin-arm64, darwin-x64,\\n` +\n ` linux-x64-gnu (glibc), linux-arm64-gnu (glibc) and win32-x64-msvc.\\n` +\n ` Your platform is not in that set.\\n\\n` +\n ` To build from source you need a Rust toolchain, then run from the repo root:\\n` +\n ` cargo build --release -p aihu-compile\\n\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n }\n return new Error(\n `[@aihu/compiler] Native compiler binary not found for this platform.\\n\\n` +\n ` Platform: ${descriptor.platformId}\\n` +\n ` Expected package: ${descriptor.packageName}\\n` +\n ` Expected file: ${descriptor.packageName}/${descriptor.binFile}\\n\\n` +\n ` This binary is distributed as an optionalDependency of @aihu/compiler.\\n` +\n ` Your package manager may have skipped it (optionalDependencies are\\n` +\n ` silently dropped on install failure).\\n\\n` +\n ` To reinstall:\\n` +\n ` npm install @aihu/compiler\\n` +\n ` # or: pnpm install or: bun install\\n\\n` +\n ` If you are working in the aihu monorepo, build from source instead:\\n` +\n ` cargo build --release -p aihu-compile\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n}\n"],"mappings":"kNAmBA,MAAM,EAAY,EAAQ,EAAc,OAAO,KAAK,IAAI,CAAC,CASzD,SAAS,GAA4C,CACnD,GAAI,OAAO,QAAY,KAAe,CAAC,QAAQ,UAAY,CAAC,QAAQ,KAClE,OAAO,KAGT,OAAQ,GADO,QAAQ,SAAS,GAAG,QAAQ,OAC3C,CACE,IAAK,eACH,MAAO,CACL,WAAY,eACZ,YAAa,8BACb,QAAS,eACV,CACH,IAAK,aACH,MAAO,CACL,WAAY,aACZ,YAAa,4BACb,QAAS,eACV,CACH,IAAK,YAEH,MAAO,CACL,WAAY,gBACZ,YAAa,+BACb,QAAS,eACV,CACH,IAAK,cAEH,MAAO,CACL,WAAY,kBACZ,YAAa,iCACb,QAAS,eACV,CACH,IAAK,YACH,MAAO,CACL,WAAY,iBACZ,YAAa,gCACb,QAAS,mBACV,CACH,QACE,OAAO,MAIb,IAAI,EAA0B,KAoB9B,SAAgB,EAAmB,EAA4B,CAC7D,GAAI,CACF,IAAM,EAAK,EAAS,EAAU,CAG9B,MAFI,CAAC,EAAG,QAAQ,EAAI,EAAG,OAAS,EAAU,IAC1C,EAAW,EAAW,EAAU,KAAK,CAC9B,SACD,CACN,MAAO,IA0CX,SAAgB,GAAgC,CAC9C,GAAI,IAAa,KAAM,OAAO,EAG9B,IAAM,EAAW,QAAQ,IAAI,iBAC7B,GAAI,EAAU,CACZ,GAAI,CAAC,EAAmB,EAAS,CAC/B,MAAU,MACR,gDAAgD,EAAS,qCAC1D,CAGH,MADA,GAAW,EACJ,EAGT,IAAM,EAAa,GAAgB,CAU7B,EAAM,QAAQ,WAAa,QAAU,OAAS,GAC9C,EAAgB,CACpB,EAAQ,EAAW,0BAA2B,eAAe,IAAM,CACnE,EAAQ,EAAW,wBAAyB,eAAe,IAAM,CAQjE,EAAQ,EAAW,SAAU,eAAe,IAAM,CACnD,CACD,IAAK,IAAM,KAAK,EACd,GAAI,EAAmB,EAAE,CAEvB,MADA,GAAW,EACJ,EAUX,GAAI,EAAY,CACd,IAAM,EAAY,EAAc,OAAO,KAAK,IAAI,CAChD,GAAI,CAEF,IAAM,EAAY,EAAK,EADP,EAAU,QAAQ,GAAG,EAAW,YAAY,eACtB,CAAC,CAAE,EAAW,QAAQ,CAC5D,GAAI,EAAmB,EAAU,CAE/B,MADA,GAAW,EACJ,OAEH,GAMV,MAAM,EAAwB,EAAY,EAAc,CAG1D,SAAS,EACP,EACA,EACO,CAaP,OAXa,MADT,IAAe,KAEf,6FACwB,OAAO,QAAY,IAAc,GAAG,QAAQ,SAAS,GAAG,QAAQ,OAAS,UAAU,sVAMxE,EAAc,KAAK,KAAK,GAI7D,+FACyB,EAAW,WAAW,wBACtB,EAAW,YAAY,wBACvB,EAAW,YAAY,GAAG,EAAW,QAAQ,8aASnC,EAAc,KAAK,KAAK,GAf1D"}
1
+ {"version":3,"file":"resolve-binary.js","names":[],"sources":["../js/resolve-binary.ts"],"sourcesContent":["/**\n * resolve-binary.ts — call-time resolver for the `aihu-compile` Rust binary.\n *\n * A near-mechanical clone of packages/css-engine/src/index.ts's resolveBinary()\n * machinery, renamed for the compiler: the per-platform packages are\n * `@aihu/compiler-<platform>`, the executable is `aihu-compile[.exe]`, and the\n * dev/source fallback is the workspace-root `target/release|debug/aihu-compile`.\n *\n * Unlike @aihu/server (a napi `.node` addon loaded via require), the compiler\n * invokes `aihu-compile` as a CLI SUBPROCESS. So the platform package exposes a\n * raw executable file, and we resolve its absolute PATH — we never `require()`\n * the binary itself. The SAME order is used by the bin shim\n * (bin/aihu-compile.mjs) and the vite plugin (js/index.ts).\n */\nimport { accessSync, constants, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\ninterface PlatformDescriptor {\n readonly platformId: string\n readonly packageName: string\n /** Executable filename inside the platform package. */\n readonly binFile: string\n}\n\nfunction detectPlatform(): PlatformDescriptor | null {\n if (typeof process === 'undefined' || !process.platform || !process.arch) {\n return null\n }\n const key = `${process.platform}-${process.arch}`\n switch (key) {\n case 'darwin-arm64':\n return {\n platformId: 'darwin-arm64',\n packageName: '@aihu/compiler-darwin-arm64',\n binFile: 'aihu-compile',\n }\n case 'darwin-x64':\n return {\n platformId: 'darwin-x64',\n packageName: '@aihu/compiler-darwin-x64',\n binFile: 'aihu-compile',\n }\n case 'linux-x64':\n // We only ship glibc; musl users fall through to the dev/source path.\n return {\n platformId: 'linux-x64-gnu',\n packageName: '@aihu/compiler-linux-x64-gnu',\n binFile: 'aihu-compile',\n }\n case 'linux-arm64':\n // glibc aarch64; musl users fall through to the dev/source path.\n return {\n platformId: 'linux-arm64-gnu',\n packageName: '@aihu/compiler-linux-arm64-gnu',\n binFile: 'aihu-compile',\n }\n case 'win32-x64':\n return {\n platformId: 'win32-x64-msvc',\n packageName: '@aihu/compiler-win32-x64-msvc',\n binFile: 'aihu-compile.exe',\n }\n default:\n return null\n }\n}\n\nlet _binPath: string | null = null\n\n/**\n * Whether `candidate` is a usable `aihu-compile` executable — NOT merely a\n * present file.\n *\n * The per-platform packages (`@aihu/compiler-<platform>`) carry a placeholder\n * `aihu-compile` in source; the real prebuilt binary is only injected by the\n * release CI. Once those packages become resolvable in the workspace, a bare\n * `existsSync` would happily return the non-executable placeholder, which then\n * blows up with EACCES inside `spawnSync`/`execFileSync`. So we must verify the\n * candidate is actually runnable before accepting it.\n *\n * POSIX: require the execute bit (X_OK). A zero-byte/text placeholder without\n * +x fails here and we fall through to the dev `target/` fallback.\n *\n * Windows: there is no execute bit — `accessSync(_, X_OK)` is effectively\n * always true — so we additionally require a non-empty regular file, which\n * still rejects a zero-byte placeholder.\n */\nexport function isUsableExecutable(candidate: string): boolean {\n try {\n const st = statSync(candidate)\n if (!st.isFile() || st.size === 0) return false\n accessSync(candidate, constants.X_OK)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Resolve the absolute path to the `aihu-compile` executable.\n *\n * Resolution order:\n * 1. Workspace dev build — `target/release|debug/` or the package-local\n * staged binary (`packages/compiler/bin/aihu-compile`). Only present in a\n * dev clone (`cargo build --release -p aihu-compile`) or a CI job that\n * stages one. Checked FIRST: see FEL-427 / #427 below.\n * 2. The per-platform optionalDependency package (`@aihu/compiler-<platform>`)\n * shipped to npm consumers — resolved via\n * `createRequire(...).resolve('<pkg>/package.json')` so it works in both\n * ESM and CJS and respects the consumer's node_modules layout. This is the\n * ONLY candidate a real npm consumer ever has, since none of the dev paths\n * exist outside this monorepo.\n *\n * If neither path yields a binary, throws a structured error pointing at the\n * missing optionalDependency (platform supported) or the dev fallback (platform\n * unsupported).\n *\n * ## Why dev build wins (#427)\n *\n * `@aihu/compiler`'s optionalDependencies are resolvable inside this very\n * monorepo the moment `bun install` has run once — but the version actually\n * fetched from the registry lags behind whatever the in-repo Rust source can\n * do (per-platform packages are only republished on release, not on every\n * commit). A dev machine or CI job that built `aihu-compile` fresh from HEAD\n * therefore used to have its correct binary silently SHADOWED by an older\n * published one that happened to already be sitting in `node_modules` — and\n * that older binary doesn't error on a flag it doesn't recognize (e.g.\n * `--sidecar-stdout`), it just ignores it and runs its default codegen path,\n * so the caller gets a plausible-looking WRONG answer instead of a crash. That\n * was the actual cause of `packages/tsc/tests/language-plugin.test.ts` failing\n * intermittently depending on whether a given checkout had ever run `bun\n * install`: the published `@aihu/compiler-darwin-arm64` sitting in\n * `node_modules` predates `--sidecar-stdout` entirely, so it fell back to a\n * normal `defineComponent(...)` transform instead of the `__aihu_template`\n * type-check sidecar the fresh binary emits.\n */\nexport function resolveCompilerBinary(): string {\n if (_binPath !== null) return _binPath\n\n // 0. `AIHU_COMPILE_BIN` — an explicit override, checked before everything else.\n const override = process.env.AIHU_COMPILE_BIN\n if (override) {\n if (!isUsableExecutable(override)) {\n throw new Error(\n `[@aihu/compiler] AIHU_COMPILE_BIN is set to '${override}', which is not an executable file.`,\n )\n }\n _binPath = override\n return _binPath\n }\n\n const descriptor = detectPlatform()\n\n // 1. Workspace dev build. Only exists in a dev clone or a CI job that staged\n // one — checked FIRST so it is never shadowed by an older published package\n // (see the #427 note above).\n //\n // This module builds to packages/compiler/dist/resolve-binary.js, so the\n // workspace root is three levels up (dist → compiler → packages → root).\n // `aihu-compile` is a workspace member; cargo emits its [[bin]] to the\n // workspace-root ./target.\n const ext = process.platform === 'win32' ? '.exe' : ''\n const devCandidates = [\n resolve(__dirname, '../../../target/release', `aihu-compile${ext}`),\n resolve(__dirname, '../../../target/debug', `aihu-compile${ext}`),\n // Package-local staged binary: `packages/compiler/bin/aihu-compile`. This is\n // where CI and the release pipeline place a prebuilt binary that was built\n // or downloaded out-of-band — e.g. deploy-docs.yml's \"Build & deploy\" job\n // downloads the linux-x64 artifact here (without a cargo `target/`), and\n // release.yml's \"Stage compiler bin\" step does the same so prepublish builds\n // can compile. In published consumers this dir holds only the `.mjs` shim, so\n // this candidate simply doesn't exist there and we fall through.\n resolve(__dirname, '../bin', `aihu-compile${ext}`),\n ]\n for (const c of devCandidates) {\n if (isUsableExecutable(c)) {\n _binPath = c\n return _binPath\n }\n }\n\n // 2. Per-platform optionalDependency package (the published-consumer path).\n //\n // Accept the candidate ONLY if it is a usable executable. A present-but-\n // non-executable placeholder (the in-source stub that becomes resolvable once\n // the per-platform packages are pinned in the lockfile) must NOT be returned —\n // doing so spawns a non-executable file and fails with EACCES.\n if (descriptor) {\n const requireFn = createRequire(import.meta.url)\n try {\n const pkgJson = requireFn.resolve(`${descriptor.packageName}/package.json`)\n const candidate = join(dirname(pkgJson), descriptor.binFile)\n if (isUsableExecutable(candidate)) {\n _binPath = candidate\n return _binPath\n }\n } catch {\n // Package not installed (optionalDependency skipped for this platform, or\n // a partial install).\n }\n }\n\n throw buildMissingBinaryError(descriptor, devCandidates)\n}\n\nfunction buildMissingBinaryError(\n descriptor: PlatformDescriptor | null,\n devCandidates: string[],\n): Error {\n if (descriptor === null) {\n return new Error(\n `[@aihu/compiler] No prebuilt aihu-compile binary for this platform.\\n\\n` +\n ` Platform: ${typeof process !== 'undefined' ? `${process.platform}-${process.arch}` : 'unknown'}\\n\\n` +\n ` @aihu/compiler ships prebuilt binaries for darwin-arm64, darwin-x64,\\n` +\n ` linux-x64-gnu (glibc), linux-arm64-gnu (glibc) and win32-x64-msvc.\\n` +\n ` Your platform is not in that set.\\n\\n` +\n ` To build from source you need a Rust toolchain, then run from the repo root:\\n` +\n ` cargo build --release -p aihu-compile\\n\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n }\n return new Error(\n `[@aihu/compiler] Native compiler binary not found for this platform.\\n\\n` +\n ` Platform: ${descriptor.platformId}\\n` +\n ` Expected package: ${descriptor.packageName}\\n` +\n ` Expected file: ${descriptor.packageName}/${descriptor.binFile}\\n\\n` +\n ` This binary is distributed as an optionalDependency of @aihu/compiler.\\n` +\n ` Your package manager may have skipped it (optionalDependencies are\\n` +\n ` silently dropped on install failure).\\n\\n` +\n ` To reinstall:\\n` +\n ` npm install @aihu/compiler\\n` +\n ` # or: pnpm install or: bun install\\n\\n` +\n ` If you are working in the aihu monorepo, build from source instead:\\n` +\n ` cargo build --release -p aihu-compile\\n` +\n ` Checked dev fallback paths: ${devCandidates.join(', ')}`,\n )\n}\n"],"mappings":"kNAmBA,MAAM,EAAY,EAAQ,EAAc,YAAY,GAAG,CAAC,EASxD,SAAS,GAA4C,CACnD,GAAI,OAAO,QAAY,KAAe,CAAC,QAAQ,UAAY,CAAC,QAAQ,KAClE,OAAO,KAGT,OAAQ,GADO,QAAQ,SAAS,GAAG,QAAQ,OAC3C,CACE,IAAK,eACH,MAAO,CACL,WAAY,eACZ,YAAa,8BACb,QAAS,cACX,EACF,IAAK,aACH,MAAO,CACL,WAAY,aACZ,YAAa,4BACb,QAAS,cACX,EACF,IAAK,YAEH,MAAO,CACL,WAAY,gBACZ,YAAa,+BACb,QAAS,cACX,EACF,IAAK,cAEH,MAAO,CACL,WAAY,kBACZ,YAAa,iCACb,QAAS,cACX,EACF,IAAK,YACH,MAAO,CACL,WAAY,iBACZ,YAAa,gCACb,QAAS,kBACX,EACF,QACE,OAAO,IACX,CACF,CAEA,IAAI,EAA0B,KAoB9B,SAAgB,EAAmB,EAA4B,CAC7D,GAAI,CACF,IAAM,EAAK,EAAS,CAAS,EAG7B,MAFI,CAAC,EAAG,OAAO,GAAK,EAAG,OAAS,EAAU,IAC1C,EAAW,EAAW,EAAU,IAAI,EAC7B,GACT,MAAQ,CACN,MAAO,EACT,CACF,CAwCA,SAAgB,GAAgC,CAC9C,GAAI,IAAa,KAAM,OAAO,EAG9B,IAAM,EAAW,QAAQ,IAAI,iBAC7B,GAAI,EAAU,CACZ,GAAI,CAAC,EAAmB,CAAQ,EAC9B,MAAU,MACR,gDAAgD,EAAS,oCAC3D,EAGF,MADA,GAAW,EACJ,CACT,CAEA,IAAM,EAAa,EAAe,EAU5B,EAAM,QAAQ,WAAa,QAAU,OAAS,GAC9C,EAAgB,CACpB,EAAQ,EAAW,0BAA2B,eAAe,GAAK,EAClE,EAAQ,EAAW,wBAAyB,eAAe,GAAK,EAQhE,EAAQ,EAAW,SAAU,eAAe,GAAK,CACnD,EACA,IAAK,IAAM,KAAK,EACd,GAAI,EAAmB,CAAC,EAEtB,MADA,GAAW,EACJ,EAUX,GAAI,EAAY,CACd,IAAM,EAAY,EAAc,YAAY,GAAG,EAC/C,GAAI,CACF,IAAM,EAAU,EAAU,QAAQ,GAAG,EAAW,YAAY,cAAc,EACpE,EAAY,EAAK,EAAQ,CAAO,EAAG,EAAW,OAAO,EAC3D,GAAI,EAAmB,CAAS,EAE9B,MADA,GAAW,EACJ,CAEX,MAAQ,CAGR,CACF,CAEA,MAAM,EAAwB,EAAY,CAAa,CACzD,CAEA,SAAS,EACP,EACA,EACO,CAaP,OAXa,MADT,IAAe,KAEf,6FACwB,OAAO,QAAY,IAAc,GAAG,QAAQ,SAAS,GAAG,QAAQ,OAAS,UAAU,sVAMxE,EAAc,KAAK,IAAI,IAI5D,+FACyB,EAAW,WAAW,wBACtB,EAAW,YAAY,wBACvB,EAAW,YAAY,GAAG,EAAW,QAAQ,8aASnC,EAAc,KAAK,IAAI,GAf1D,CAiBJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aihu/compiler",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -31,36 +31,39 @@
31
31
  "codemod:template-syntax": "bun js/codemods/template-syntax/run-migration.ts"
32
32
  },
33
33
  "optionalDependencies": {
34
- "@aihu/compiler-darwin-arm64": "0.1.54",
35
- "@aihu/compiler-darwin-x64": "0.1.54",
36
- "@aihu/compiler-linux-x64-gnu": "0.1.54",
37
- "@aihu/compiler-linux-arm64-gnu": "0.1.54",
38
- "@aihu/compiler-win32-x64-msvc": "0.1.54",
39
- "@aihu/compiler-native-darwin-arm64": "0.1.19",
40
- "@aihu/compiler-native-darwin-x64": "0.1.19",
41
- "@aihu/compiler-native-linux-x64-gnu": "0.1.19",
42
- "@aihu/compiler-native-linux-arm64-gnu": "0.1.19",
43
- "@aihu/compiler-native-win32-x64-msvc": "0.1.19"
34
+ "@aihu/compiler-darwin-arm64": "1.3.2",
35
+ "@aihu/compiler-darwin-x64": "1.3.2",
36
+ "@aihu/compiler-linux-x64-gnu": "1.3.2",
37
+ "@aihu/compiler-linux-arm64-gnu": "1.3.2",
38
+ "@aihu/compiler-win32-x64-msvc": "1.3.2",
39
+ "@aihu/compiler-native-darwin-arm64": "1.3.2",
40
+ "@aihu/compiler-native-darwin-x64": "1.3.2",
41
+ "@aihu/compiler-native-linux-x64-gnu": "1.3.2",
42
+ "@aihu/compiler-native-linux-arm64-gnu": "1.3.2",
43
+ "@aihu/compiler-native-win32-x64-msvc": "1.3.2"
44
44
  },
45
45
  "peerDependencies": {
46
- "vite": ">=5.0.0"
46
+ "vite": ">=5.0.0",
47
+ "@aihu/css-engine": ">=0.6.1"
47
48
  },
48
49
  "peerDependenciesMeta": {
49
50
  "vite": {
50
51
  "optional": true
52
+ },
53
+ "@aihu/css-engine": {
54
+ "optional": true
51
55
  }
52
56
  },
53
57
  "devDependencies": {
54
- "@aihu/css-engine": "0.6.1"
58
+ "@aihu/css-engine": "^0.6.1"
55
59
  },
56
60
  "description": "Single File Component (.aihu) compiler — Rust binary + JS glue.",
57
61
  "repository": {
58
62
  "type": "git",
59
- "url": "git+https://github.com/fellwork/aihu.git",
60
- "directory": "packages/compiler"
63
+ "url": "git+https://github.com/aihu-project/aihu-compiler.git"
61
64
  },
62
- "homepage": "https://github.com/fellwork/aihu/tree/main/packages/compiler#readme",
63
- "bugs": "https://github.com/fellwork/aihu/issues",
65
+ "homepage": "https://github.com/aihu-project/aihu-compiler#readme",
66
+ "bugs": "https://github.com/aihu-project/aihu/issues",
64
67
  "publishConfig": {
65
68
  "access": "public"
66
69
  }