@zenithbuild/compiler 0.6.9 → 0.6.11

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 CHANGED
@@ -1,39 +1,12 @@
1
- # @zenithbuild/compiler 🏗️
1
+ # @zenithbuild/compiler
2
2
 
3
- > **⚠️ Internal API:** This package is an internal implementation detail of the Zenith framework. It is not intended for public use and its API may break without warning. Please use `@zenithbuild/core` instead.
3
+ Internal meta package for the Zenith compiler.
4
4
 
5
+ This package resolves the platform-specific `zenith-compiler` binary shipped by:
5
6
 
6
- The Iron Heart of the Zenith framework. High-performance native compiler and build-time architect.
7
+ - `@zenithbuild/compiler-darwin-arm64`
8
+ - `@zenithbuild/compiler-darwin-x64`
9
+ - `@zenithbuild/compiler-linux-x64`
10
+ - `@zenithbuild/compiler-win32-x64`
7
11
 
8
- ## Canonical Docs
9
-
10
- - Compiler boundary: `../zenith-docs/documentation/contracts/compiler-boundary.md`
11
- - IR envelope: `../zenith-docs/documentation/contracts/ir-envelope.md`
12
- - Component script hoisting: `../zenith-docs/documentation/contracts/component-script-hoisting.md`
13
-
14
- ## Overview
15
-
16
- @zenithbuild/compiler owns everything related to structure, wiring, and validation. It is a coordinated companion to `@zenithbuild/core`.
17
-
18
- ### Core Responsibilities
19
- - **Parsing**: Native AST parsing of `.zen` files (Rust).
20
- - **Transformation**: Lowering templates to optimized execution plans.
21
- - **Dependency Management**: Compile-time resolution of imports and reactive graphs.
22
- - **CSS Engine**: High-speed CSS compilation and Tailwind integration.
23
- - **Bundle Generation**: Composing the thin client runtime for the browser.
24
-
25
- ## Coordinated System
26
-
27
- Zenith is built as a coordinated system. The compiler produces artifacts that the Core runtime consumes blindly.
28
- - **No runtime decisions**: If it can be known at compile time, the compiler decides it.
29
- - **Tight Coupling**: Versioned and released in lockstep with `@zenithbuild/core`.
30
-
31
- ## Internal Structure
32
-
33
- - `native/`: The Rust-powered core compiler.
34
- - `src/parse/`: TypeScript wrappers for the native parser.
35
- - `src/runtime/`: logic for generating the `bundle.js` target.
36
-
37
- ## License
38
-
39
- MIT
12
+ The JavaScript bridge remains internal and is not a public framework API.
package/dist/index.js CHANGED
@@ -1,40 +1,94 @@
1
- import { spawnSync } from 'node:child_process'
2
- import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
-
5
- const __filename = fileURLToPath(import.meta.url)
6
- const __dirname = path.dirname(__filename)
7
-
8
- /**
9
- * Compile Zenith source.
10
- *
11
- * Back-compat: compile(filePath) reads from file.
12
- * New mode: compile({ source, filePath }) or compile(source, filePath) uses stdin.
13
- *
14
- * @param {string|{ source: string, filePath: string }} entryPathOrSource - File path, or source string, or { source, filePath }
15
- * @param {string|object} [filePathOrOptions] - File path (when first arg is source string), or options (ignored)
16
- * @returns {object} Parsed JSON output (includes warnings array)
17
- */
18
- export function compile(entryPathOrSource, filePathOrOptions = {}) {
19
- const bin = path.resolve(__dirname, '../target/release/zenith-compiler')
20
- let args
21
- let spawnOpts = { encoding: 'utf8' }
22
-
23
- if (typeof entryPathOrSource === 'object' && entryPathOrSource !== null && 'source' in entryPathOrSource && 'filePath' in entryPathOrSource) {
24
- args = ['--stdin', entryPathOrSource.filePath]
25
- spawnOpts.input = entryPathOrSource.source
26
- } else if (typeof entryPathOrSource === 'string' && typeof filePathOrOptions === 'string') {
27
- args = ['--stdin', filePathOrOptions]
28
- spawnOpts.input = entryPathOrSource
1
+ // meta/index.ts
2
+ import { existsSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { spawnSync } from "node:child_process";
7
+ var __filename2 = fileURLToPath(import.meta.url);
8
+ var __dirname2 = path.dirname(__filename2);
9
+ var require2 = createRequire(import.meta.url);
10
+ var PLATFORM_PACKAGES = {
11
+ "darwin-arm64": {
12
+ packageName: "@zenithbuild/compiler-darwin-arm64",
13
+ binaryName: "zenith-compiler",
14
+ os: "darwin",
15
+ arch: "arm64"
16
+ },
17
+ "darwin-x64": {
18
+ packageName: "@zenithbuild/compiler-darwin-x64",
19
+ binaryName: "zenith-compiler",
20
+ os: "darwin",
21
+ arch: "x64"
22
+ },
23
+ "linux-x64": {
24
+ packageName: "@zenithbuild/compiler-linux-x64",
25
+ binaryName: "zenith-compiler",
26
+ os: "linux",
27
+ arch: "x64"
28
+ },
29
+ "win32-x64": {
30
+ packageName: "@zenithbuild/compiler-win32-x64",
31
+ binaryName: "zenith-compiler.exe",
32
+ os: "win32",
33
+ arch: "x64"
34
+ }
35
+ };
36
+ function safeResolvePackageRoot(packageName) {
37
+ try {
38
+ return path.dirname(require2.resolve(`${packageName}/package.json`));
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+ function currentPlatformPackage() {
44
+ return PLATFORM_PACKAGES[`${process.platform}-${process.arch}`] || null;
45
+ }
46
+ function resolveLegacyCompilerBin() {
47
+ const legacyBinary = path.resolve(__dirname2, "..", "target", "release", process.platform === "win32" ? "zenith-compiler.exe" : "zenith-compiler");
48
+ return existsSync(legacyBinary) ? legacyBinary : null;
49
+ }
50
+ function resolveCompilerBin() {
51
+ const platformPackage = currentPlatformPackage();
52
+ if (platformPackage) {
53
+ const packageRoot = safeResolvePackageRoot(platformPackage.packageName);
54
+ if (packageRoot) {
55
+ const binaryPath = path.resolve(packageRoot, "bin", platformPackage.binaryName);
56
+ if (existsSync(binaryPath)) {
57
+ return binaryPath;
58
+ }
59
+ }
60
+ }
61
+ const legacyBinary = resolveLegacyCompilerBin();
62
+ if (legacyBinary) {
63
+ return legacyBinary;
64
+ }
65
+ const supportedPlatforms = Object.keys(PLATFORM_PACKAGES).join(", ");
66
+ const expectedPackage = platformPackage?.packageName || "@zenithbuild/compiler-<platform>";
67
+ throw new Error(`[zenith] Compiler binary not installed for ${process.platform}-${process.arch}. ` + `Reinstall @zenithbuild/compiler and ensure ${expectedPackage} is present. ` + `Supported platform packages: ${supportedPlatforms}.`);
68
+ }
69
+ function compile(entryPathOrSource, filePathOrOptions = {}) {
70
+ const bin = resolveCompilerBin();
71
+ let args;
72
+ const spawnOptions = { encoding: "utf8" };
73
+ if (typeof entryPathOrSource === "object" && entryPathOrSource !== null && "source" in entryPathOrSource && "filePath" in entryPathOrSource) {
74
+ args = ["--stdin", entryPathOrSource.filePath];
75
+ spawnOptions.input = entryPathOrSource.source;
76
+ } else if (typeof entryPathOrSource === "string" && typeof filePathOrOptions === "string") {
77
+ args = ["--stdin", filePathOrOptions];
78
+ spawnOptions.input = entryPathOrSource;
29
79
  } else {
30
- args = [entryPathOrSource]
80
+ args = [String(entryPathOrSource)];
81
+ }
82
+ const result = spawnSync(bin, args, spawnOptions);
83
+ if (result.error) {
84
+ throw new Error(result.error.message);
31
85
  }
32
-
33
- const result = spawnSync(bin, args, spawnOpts)
34
-
35
86
  if (result.status !== 0) {
36
- throw new Error(result.stderr || 'Compiler execution failed')
87
+ throw new Error(result.stderr || "Compiler execution failed");
37
88
  }
38
-
39
- return JSON.parse(result.stdout)
89
+ return JSON.parse(result.stdout);
40
90
  }
91
+ export {
92
+ resolveCompilerBin,
93
+ compile
94
+ };
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "@zenithbuild/compiler",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
7
- ".": "./dist/index.js"
7
+ ".": "./dist/index.js",
8
+ "./package.json": "./package.json"
8
9
  },
9
10
  "files": [
10
11
  "dist",
11
- "COMPILER_JS_BRIDGE_CONTRACT.md",
12
- "dist/**",
13
- "target/release/zenith-compiler",
14
- "LICENSE",
15
12
  "README.md",
13
+ "LICENSE",
16
14
  "package.json"
17
15
  ],
18
16
  "repository": {
@@ -26,7 +24,17 @@
26
24
  "homepage": "https://github.com/zenithbuild/framework#readme",
27
25
  "private": false,
28
26
  "scripts": {
29
- "build": "cargo build --release",
27
+ "build": "rm -rf dist && bun build meta/index.ts --outdir dist --target node --format esm && node ../../scripts/stage-compiler-platform-package.mjs",
30
28
  "prepublishOnly": "npm run build"
29
+ },
30
+ "optionalDependencies": {
31
+ "@zenithbuild/compiler-darwin-arm64": "0.6.11",
32
+ "@zenithbuild/compiler-darwin-x64": "0.6.11",
33
+ "@zenithbuild/compiler-linux-x64": "0.6.11",
34
+ "@zenithbuild/compiler-win32-x64": "0.6.11"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "latest",
38
+ "typescript": "^5"
31
39
  }
32
40
  }
@@ -1,32 +0,0 @@
1
- # Zenith Compiler JS Bridge Contract (V0)
2
-
3
- Status: FROZEN (V0)
4
-
5
- ## Identity
6
-
7
- `@zenithbuild/compiler` is a deterministic Rust execution bridge.
8
-
9
- ## Allowed Responsibilities
10
-
11
- - Invoke the Rust compiler binary with deterministic arguments.
12
- - Parse Rust compiler JSON stdout.
13
- - Throw deterministic errors on non-zero exit or invalid JSON output.
14
-
15
- ## Explicit Non-Responsibilities
16
-
17
- - It does not parse AST.
18
- - It does not transform IR.
19
- - It does not contain compiler logic.
20
- - It does not import other Zenith layers.
21
-
22
- ## Explicit Prohibitions
23
-
24
- - No `eval`.
25
- - No browser globals.
26
- - No dynamic imports.
27
- - No bundler/runtime knowledge.
28
- - No CLI orchestration logic.
29
-
30
- ## Boundary
31
-
32
- This package only invokes the Rust binary and returns parsed JSON.
Binary file