@zenithbuild/compiler 1.0.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.
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/build-analyzer.d.ts +44 -0
- package/dist/build-analyzer.js +87 -0
- package/dist/bundler.d.ts +31 -0
- package/dist/bundler.js +86 -0
- package/dist/core/components/index.d.ts +9 -0
- package/dist/core/components/index.js +13 -0
- package/dist/core/config/index.d.ts +11 -0
- package/dist/core/config/index.js +10 -0
- package/dist/core/config/loader.d.ts +17 -0
- package/dist/core/config/loader.js +60 -0
- package/dist/core/config/types.d.ts +98 -0
- package/dist/core/config/types.js +32 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +6 -0
- package/dist/core/lifecycle/index.d.ts +16 -0
- package/dist/core/lifecycle/index.js +19 -0
- package/dist/core/lifecycle/zen-mount.d.ts +66 -0
- package/dist/core/lifecycle/zen-mount.js +151 -0
- package/dist/core/lifecycle/zen-unmount.d.ts +54 -0
- package/dist/core/lifecycle/zen-unmount.js +76 -0
- package/dist/core/plugins/bridge.d.ts +116 -0
- package/dist/core/plugins/bridge.js +121 -0
- package/dist/core/plugins/index.d.ts +6 -0
- package/dist/core/plugins/index.js +6 -0
- package/dist/core/plugins/registry.d.ts +67 -0
- package/dist/core/plugins/registry.js +113 -0
- package/dist/core/reactivity/index.d.ts +30 -0
- package/dist/core/reactivity/index.js +33 -0
- package/dist/core/reactivity/tracking.d.ts +74 -0
- package/dist/core/reactivity/tracking.js +136 -0
- package/dist/core/reactivity/zen-batch.d.ts +45 -0
- package/dist/core/reactivity/zen-batch.js +54 -0
- package/dist/core/reactivity/zen-effect.d.ts +48 -0
- package/dist/core/reactivity/zen-effect.js +98 -0
- package/dist/core/reactivity/zen-memo.d.ts +43 -0
- package/dist/core/reactivity/zen-memo.js +100 -0
- package/dist/core/reactivity/zen-ref.d.ts +44 -0
- package/dist/core/reactivity/zen-ref.js +34 -0
- package/dist/core/reactivity/zen-signal.d.ts +48 -0
- package/dist/core/reactivity/zen-signal.js +84 -0
- package/dist/core/reactivity/zen-state.d.ts +35 -0
- package/dist/core/reactivity/zen-state.js +147 -0
- package/dist/core/reactivity/zen-untrack.d.ts +38 -0
- package/dist/core/reactivity/zen-untrack.js +41 -0
- package/dist/css/index.d.ts +73 -0
- package/dist/css/index.js +246 -0
- package/dist/discovery/componentDiscovery.d.ts +42 -0
- package/dist/discovery/componentDiscovery.js +56 -0
- package/dist/discovery/layouts.d.ts +13 -0
- package/dist/discovery/layouts.js +41 -0
- package/dist/errors/compilerError.d.ts +31 -0
- package/dist/errors/compilerError.js +51 -0
- package/dist/finalize/finalizeOutput.d.ts +32 -0
- package/dist/finalize/finalizeOutput.js +62 -0
- package/dist/finalize/generateFinalBundle.d.ts +24 -0
- package/dist/finalize/generateFinalBundle.js +68 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +51 -0
- package/dist/ir/types.d.ts +181 -0
- package/dist/ir/types.js +8 -0
- package/dist/output/types.d.ts +30 -0
- package/dist/output/types.js +6 -0
- package/dist/parse/detectMapExpressions.d.ts +45 -0
- package/dist/parse/detectMapExpressions.js +77 -0
- package/dist/parse/parseScript.d.ts +8 -0
- package/dist/parse/parseScript.js +36 -0
- package/dist/parse/parseTemplate.d.ts +11 -0
- package/dist/parse/parseTemplate.js +487 -0
- package/dist/parse/parseZenFile.d.ts +11 -0
- package/dist/parse/parseZenFile.js +50 -0
- package/dist/parse/scriptAnalysis.d.ts +25 -0
- package/dist/parse/scriptAnalysis.js +60 -0
- package/dist/parse/trackLoopContext.d.ts +20 -0
- package/dist/parse/trackLoopContext.js +62 -0
- package/dist/parseZenFile.d.ts +10 -0
- package/dist/parseZenFile.js +55 -0
- package/dist/runtime/analyzeAndEmit.d.ts +20 -0
- package/dist/runtime/analyzeAndEmit.js +70 -0
- package/dist/runtime/build.d.ts +6 -0
- package/dist/runtime/build.js +13 -0
- package/dist/runtime/bundle-generator.d.ts +27 -0
- package/dist/runtime/bundle-generator.js +1263 -0
- package/dist/runtime/client-runtime.d.ts +41 -0
- package/dist/runtime/client-runtime.js +397 -0
- package/dist/runtime/dataExposure.d.ts +52 -0
- package/dist/runtime/dataExposure.js +227 -0
- package/dist/runtime/generateDOM.d.ts +21 -0
- package/dist/runtime/generateDOM.js +194 -0
- package/dist/runtime/generateHydrationBundle.d.ts +15 -0
- package/dist/runtime/generateHydrationBundle.js +399 -0
- package/dist/runtime/hydration.d.ts +53 -0
- package/dist/runtime/hydration.js +271 -0
- package/dist/runtime/navigation.d.ts +58 -0
- package/dist/runtime/navigation.js +372 -0
- package/dist/runtime/serve.d.ts +13 -0
- package/dist/runtime/serve.js +76 -0
- package/dist/runtime/thinRuntime.d.ts +23 -0
- package/dist/runtime/thinRuntime.js +158 -0
- package/dist/runtime/transformIR.d.ts +19 -0
- package/dist/runtime/transformIR.js +285 -0
- package/dist/runtime/wrapExpression.d.ts +24 -0
- package/dist/runtime/wrapExpression.js +76 -0
- package/dist/runtime/wrapExpressionWithLoop.d.ts +17 -0
- package/dist/runtime/wrapExpressionWithLoop.js +75 -0
- package/dist/spa-build.d.ts +26 -0
- package/dist/spa-build.js +866 -0
- package/dist/ssg-build.d.ts +32 -0
- package/dist/ssg-build.js +408 -0
- package/dist/test/analyze-emit.test.d.ts +1 -0
- package/dist/test/analyze-emit.test.js +88 -0
- package/dist/test/bundler-contract.test.d.ts +1 -0
- package/dist/test/bundler-contract.test.js +137 -0
- package/dist/test/compiler-authority.test.d.ts +1 -0
- package/dist/test/compiler-authority.test.js +90 -0
- package/dist/test/component-instance-test.d.ts +1 -0
- package/dist/test/component-instance-test.js +115 -0
- package/dist/test/error-native-bridge.test.d.ts +1 -0
- package/dist/test/error-native-bridge.test.js +51 -0
- package/dist/test/error-serialization.test.d.ts +1 -0
- package/dist/test/error-serialization.test.js +38 -0
- package/dist/test/macro-inlining.test.d.ts +1 -0
- package/dist/test/macro-inlining.test.js +178 -0
- package/dist/test/validate-test.d.ts +6 -0
- package/dist/test/validate-test.js +95 -0
- package/dist/transform/classifyExpression.d.ts +46 -0
- package/dist/transform/classifyExpression.js +354 -0
- package/dist/transform/componentResolver.d.ts +15 -0
- package/dist/transform/componentResolver.js +30 -0
- package/dist/transform/expressionTransformer.d.ts +19 -0
- package/dist/transform/expressionTransformer.js +333 -0
- package/dist/transform/fragmentLowering.d.ts +25 -0
- package/dist/transform/fragmentLowering.js +468 -0
- package/dist/transform/layoutProcessor.d.ts +5 -0
- package/dist/transform/layoutProcessor.js +34 -0
- package/dist/transform/transformTemplate.d.ts +11 -0
- package/dist/transform/transformTemplate.js +33 -0
- package/dist/validate/invariants.d.ts +23 -0
- package/dist/validate/invariants.js +55 -0
- package/native/compiler-native/compiler-native.node +0 -0
- package/native/compiler-native/index.d.ts +113 -0
- package/native/compiler-native/index.js +19 -0
- package/native/compiler-native/package.json +19 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zenith Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @zenithbuild/compiler 🏗️
|
|
2
|
+
|
|
3
|
+
The Iron Heart of the Zenith framework. High-performance native compiler and build-time architect.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
@zenithbuild/compiler owns everything related to structure, wiring, and validation. It is a coordinated companion to `@zenithbuild/core`.
|
|
8
|
+
|
|
9
|
+
### Core Responsibilities
|
|
10
|
+
- **Parsing**: Native AST parsing of `.zen` files (Rust).
|
|
11
|
+
- **Transformation**: Lowering templates to optimized execution plans.
|
|
12
|
+
- **Dependency Management**: Compile-time resolution of imports and reactive graphs.
|
|
13
|
+
- **CSS Engine**: High-speed CSS compilation and Tailwind integration.
|
|
14
|
+
- **Bundle Generation**: Composing the thin client runtime for the browser.
|
|
15
|
+
|
|
16
|
+
## Coordinated System
|
|
17
|
+
|
|
18
|
+
Zenith is built as a coordinated system. The compiler produces artifacts that the Core runtime consumes blindly.
|
|
19
|
+
- **No runtime decisions**: If it can be known at compile time, the compiler decides it.
|
|
20
|
+
- **Tight Coupling**: Versioned and released in lockstep with `@zenithbuild/core`.
|
|
21
|
+
|
|
22
|
+
## Internal Structure
|
|
23
|
+
|
|
24
|
+
- `native/`: The Rust-powered core compiler.
|
|
25
|
+
- `src/parse/`: TypeScript wrappers for the native parser.
|
|
26
|
+
- `src/runtime/`: logic for generating the `bundle.js` target.
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Build Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analyzes .zen page source to determine build strategy:
|
|
5
|
+
* - Static: Pure HTML+CSS, no JS needed
|
|
6
|
+
* - Hydration: Has state/events/hooks, needs page-specific JS
|
|
7
|
+
* - SSR: Uses useFetchServer, needs server rendering
|
|
8
|
+
* - SPA: Uses ZenLink with passHref, needs client router
|
|
9
|
+
*/
|
|
10
|
+
export interface PageAnalysis {
|
|
11
|
+
/** Page has state declarations that need hydration */
|
|
12
|
+
hasState: boolean;
|
|
13
|
+
/** Page has event handlers (onclick, etc.) */
|
|
14
|
+
hasEventHandlers: boolean;
|
|
15
|
+
/** Page uses lifecycle hooks (zenOnMount, zenOnUnmount) */
|
|
16
|
+
hasLifecycleHooks: boolean;
|
|
17
|
+
/** Page uses useFetchServer (requires SSR) */
|
|
18
|
+
usesServerFetch: boolean;
|
|
19
|
+
/** Page uses useFetchClient (client-side data) */
|
|
20
|
+
usesClientFetch: boolean;
|
|
21
|
+
/** Page uses ZenLink with passHref (SPA navigation) */
|
|
22
|
+
usesZenLink: boolean;
|
|
23
|
+
/** Page uses reactive expressions in templates */
|
|
24
|
+
hasReactiveExpressions: boolean;
|
|
25
|
+
/** Computed: page needs any JavaScript */
|
|
26
|
+
needsHydration: boolean;
|
|
27
|
+
/** Computed: page is purely static (no JS) */
|
|
28
|
+
isStatic: boolean;
|
|
29
|
+
/** Computed: page needs SSR */
|
|
30
|
+
needsSSR: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Analyze a .zen page source to determine build requirements
|
|
34
|
+
*/
|
|
35
|
+
export declare function analyzePageSource(source: string): PageAnalysis;
|
|
36
|
+
/**
|
|
37
|
+
* Get a human-readable summary of the page analysis
|
|
38
|
+
*/
|
|
39
|
+
export declare function getAnalysisSummary(analysis: PageAnalysis): string;
|
|
40
|
+
/**
|
|
41
|
+
* Determine build output type for a page
|
|
42
|
+
*/
|
|
43
|
+
export type BuildOutputType = 'static' | 'hydrated' | 'ssr';
|
|
44
|
+
export declare function getBuildOutputType(analysis: PageAnalysis): BuildOutputType;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Build Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analyzes .zen page source to determine build strategy:
|
|
5
|
+
* - Static: Pure HTML+CSS, no JS needed
|
|
6
|
+
* - Hydration: Has state/events/hooks, needs page-specific JS
|
|
7
|
+
* - SSR: Uses useFetchServer, needs server rendering
|
|
8
|
+
* - SPA: Uses ZenLink with passHref, needs client router
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Analyze a .zen page source to determine build requirements
|
|
12
|
+
*/
|
|
13
|
+
export function analyzePageSource(source) {
|
|
14
|
+
// Extract script content for analysis
|
|
15
|
+
const scriptMatch = source.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
|
|
16
|
+
const scriptContent = scriptMatch?.[1] || '';
|
|
17
|
+
// Extract template content (everything outside script/style)
|
|
18
|
+
const templateContent = source
|
|
19
|
+
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
|
20
|
+
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '');
|
|
21
|
+
// Check for state declarations: "state varName = ..."
|
|
22
|
+
const hasState = /\bstate\s+\w+\s*=/.test(scriptContent);
|
|
23
|
+
// Check for event handlers in template
|
|
24
|
+
const hasEventHandlers = /\bon(click|change|input|submit|focus|blur|keydown|keyup|keypress|mousedown|mouseup|mouseover|mouseout|mouseenter|mouseleave)\s*=\s*["'{]/.test(templateContent);
|
|
25
|
+
// Check for lifecycle hooks
|
|
26
|
+
const hasLifecycleHooks = /\bzen(OnMount|OnUnmount)\s*\(/.test(scriptContent);
|
|
27
|
+
// Check for server fetch
|
|
28
|
+
const usesServerFetch = /\buseFetchServer\s*\(/.test(scriptContent);
|
|
29
|
+
// Check for client fetch
|
|
30
|
+
const usesClientFetch = /\buseFetchClient\s*\(/.test(scriptContent);
|
|
31
|
+
// Check for ZenLink with passHref
|
|
32
|
+
const usesZenLink = /<ZenLink[^>]*passHref[^>]*>/.test(templateContent);
|
|
33
|
+
// Check for reactive expressions in template: {expression}
|
|
34
|
+
// Must be actual expressions, not just static text
|
|
35
|
+
// Exclude attribute values like href="/path"
|
|
36
|
+
const hasReactiveExpressions = /{[^{}]+}/.test(templateContent);
|
|
37
|
+
// Compute derived properties
|
|
38
|
+
const needsHydration = hasState || hasEventHandlers || hasLifecycleHooks ||
|
|
39
|
+
usesClientFetch || hasReactiveExpressions;
|
|
40
|
+
const isStatic = !needsHydration && !usesServerFetch;
|
|
41
|
+
const needsSSR = usesServerFetch;
|
|
42
|
+
return {
|
|
43
|
+
hasState,
|
|
44
|
+
hasEventHandlers,
|
|
45
|
+
hasLifecycleHooks,
|
|
46
|
+
usesServerFetch,
|
|
47
|
+
usesClientFetch,
|
|
48
|
+
usesZenLink,
|
|
49
|
+
hasReactiveExpressions,
|
|
50
|
+
needsHydration,
|
|
51
|
+
isStatic,
|
|
52
|
+
needsSSR
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get a human-readable summary of the page analysis
|
|
57
|
+
*/
|
|
58
|
+
export function getAnalysisSummary(analysis) {
|
|
59
|
+
const flags = [];
|
|
60
|
+
if (analysis.isStatic) {
|
|
61
|
+
flags.push('STATIC (no JS)');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (analysis.hasState)
|
|
65
|
+
flags.push('state');
|
|
66
|
+
if (analysis.hasEventHandlers)
|
|
67
|
+
flags.push('events');
|
|
68
|
+
if (analysis.hasLifecycleHooks)
|
|
69
|
+
flags.push('lifecycle');
|
|
70
|
+
if (analysis.hasReactiveExpressions)
|
|
71
|
+
flags.push('reactive');
|
|
72
|
+
if (analysis.usesClientFetch)
|
|
73
|
+
flags.push('clientFetch');
|
|
74
|
+
}
|
|
75
|
+
if (analysis.needsSSR)
|
|
76
|
+
flags.push('SSR');
|
|
77
|
+
if (analysis.usesZenLink)
|
|
78
|
+
flags.push('SPA');
|
|
79
|
+
return flags.length > 0 ? flags.join(', ') : 'minimal';
|
|
80
|
+
}
|
|
81
|
+
export function getBuildOutputType(analysis) {
|
|
82
|
+
if (analysis.needsSSR)
|
|
83
|
+
return 'ssr';
|
|
84
|
+
if (analysis.needsHydration)
|
|
85
|
+
return 'hydrated';
|
|
86
|
+
return 'static';
|
|
87
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zenithbuild/core - Page Script Bundler
|
|
3
|
+
*
|
|
4
|
+
* COMPILER-FIRST ARCHITECTURE
|
|
5
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
6
|
+
*
|
|
7
|
+
* This bundler performs ZERO inference. It executes exactly what the compiler specifies.
|
|
8
|
+
*
|
|
9
|
+
* Rules:
|
|
10
|
+
* - If a BundlePlan is provided, bundling MUST occur
|
|
11
|
+
* - If bundling fails, throw a hard error (no fallback)
|
|
12
|
+
* - The bundler never inspects source code for intent
|
|
13
|
+
* - No temp files, no heuristics, no recovery
|
|
14
|
+
*
|
|
15
|
+
* Bundler failure = compiler bug.
|
|
16
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
17
|
+
*/
|
|
18
|
+
import type { BundlePlan } from './ir/types';
|
|
19
|
+
/**
|
|
20
|
+
* Execute a compiler-emitted BundlePlan
|
|
21
|
+
*
|
|
22
|
+
* This is a PURE PLAN EXECUTOR. It does not:
|
|
23
|
+
* - Inspect source code for imports
|
|
24
|
+
* - Decide whether bundling is needed
|
|
25
|
+
* - Fall back on failure
|
|
26
|
+
* - Use temp files
|
|
27
|
+
*
|
|
28
|
+
* @param plan - Compiler-emitted BundlePlan (must exist; caller must not call if no plan)
|
|
29
|
+
* @throws Error if bundling fails (no fallback, no recovery)
|
|
30
|
+
*/
|
|
31
|
+
export declare function bundlePageScript(plan: BundlePlan): Promise<string>;
|
package/dist/bundler.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zenithbuild/core - Page Script Bundler
|
|
3
|
+
*
|
|
4
|
+
* COMPILER-FIRST ARCHITECTURE
|
|
5
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
6
|
+
*
|
|
7
|
+
* This bundler performs ZERO inference. It executes exactly what the compiler specifies.
|
|
8
|
+
*
|
|
9
|
+
* Rules:
|
|
10
|
+
* - If a BundlePlan is provided, bundling MUST occur
|
|
11
|
+
* - If bundling fails, throw a hard error (no fallback)
|
|
12
|
+
* - The bundler never inspects source code for intent
|
|
13
|
+
* - No temp files, no heuristics, no recovery
|
|
14
|
+
*
|
|
15
|
+
* Bundler failure = compiler bug.
|
|
16
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
17
|
+
*/
|
|
18
|
+
import { rolldown } from 'rolldown';
|
|
19
|
+
/**
|
|
20
|
+
* Execute a compiler-emitted BundlePlan
|
|
21
|
+
*
|
|
22
|
+
* This is a PURE PLAN EXECUTOR. It does not:
|
|
23
|
+
* - Inspect source code for imports
|
|
24
|
+
* - Decide whether bundling is needed
|
|
25
|
+
* - Fall back on failure
|
|
26
|
+
* - Use temp files
|
|
27
|
+
*
|
|
28
|
+
* @param plan - Compiler-emitted BundlePlan (must exist; caller must not call if no plan)
|
|
29
|
+
* @throws Error if bundling fails (no fallback, no recovery)
|
|
30
|
+
*/
|
|
31
|
+
export async function bundlePageScript(plan) {
|
|
32
|
+
// Virtual entry module ID
|
|
33
|
+
const VIRTUAL_ENTRY = '\0zenith:entry';
|
|
34
|
+
// Build virtual modules map from plan
|
|
35
|
+
const virtualModules = new Map();
|
|
36
|
+
virtualModules.set(VIRTUAL_ENTRY, plan.entry);
|
|
37
|
+
for (const vm of plan.virtualModules) {
|
|
38
|
+
virtualModules.set(vm.id, vm.code);
|
|
39
|
+
}
|
|
40
|
+
// Execute Rolldown with plan-specified configuration
|
|
41
|
+
// No inference, no heuristics, no semantic analysis
|
|
42
|
+
const bundle = await rolldown({
|
|
43
|
+
input: VIRTUAL_ENTRY,
|
|
44
|
+
platform: plan.platform,
|
|
45
|
+
resolve: {
|
|
46
|
+
modules: plan.resolveRoots
|
|
47
|
+
},
|
|
48
|
+
plugins: [{
|
|
49
|
+
name: 'zenith-virtual',
|
|
50
|
+
resolveId(source) {
|
|
51
|
+
// Virtual modules from plan
|
|
52
|
+
if (virtualModules.has(source)) {
|
|
53
|
+
return { id: source, moduleSideEffects: false };
|
|
54
|
+
}
|
|
55
|
+
// Special case: zenith:content namespace
|
|
56
|
+
if (source === 'zenith:content') {
|
|
57
|
+
return { id: '\0zenith:content', moduleSideEffects: false };
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
},
|
|
61
|
+
load(id) {
|
|
62
|
+
return virtualModules.get(id) ?? null;
|
|
63
|
+
}
|
|
64
|
+
}],
|
|
65
|
+
// DETERMINISTIC OUTPUT: Disable all semantic optimizations
|
|
66
|
+
// Tree-shaking implies semantic analysis - bundler must not infer
|
|
67
|
+
treeshake: false,
|
|
68
|
+
// HARD FAILURE on unresolved imports - no silent external treatment
|
|
69
|
+
onLog(level, log) {
|
|
70
|
+
if (log.code === 'UNRESOLVED_IMPORT') {
|
|
71
|
+
throw new Error(`[Zenith Bundler] Unresolved import: ${log.message}. ` +
|
|
72
|
+
`This is a compiler error - the BundlePlan references a module that cannot be resolved.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// Generate output with plan-specified format
|
|
77
|
+
const { output } = await bundle.generate({
|
|
78
|
+
format: plan.format
|
|
79
|
+
});
|
|
80
|
+
// Hard failure if no output - this is a compiler bug
|
|
81
|
+
if (!output[0]?.code) {
|
|
82
|
+
throw new Error('[Zenith Bundler] Rolldown produced no output. ' +
|
|
83
|
+
'This is a compiler error - the BundlePlan was invalid or Rolldown failed silently.');
|
|
84
|
+
}
|
|
85
|
+
return output[0].code;
|
|
86
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Components
|
|
3
|
+
*
|
|
4
|
+
* Reusable components provided by zenith-core.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CORE_COMPONENTS: {
|
|
7
|
+
readonly ErrorPage: "@zenithbuild/core/components/ErrorPage.zen";
|
|
8
|
+
};
|
|
9
|
+
export declare function getCoreComponentPath(componentName: keyof typeof CORE_COMPONENTS): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Components
|
|
3
|
+
*
|
|
4
|
+
* Reusable components provided by zenith-core.
|
|
5
|
+
*/
|
|
6
|
+
// Export path constants for component resolution
|
|
7
|
+
export const CORE_COMPONENTS = {
|
|
8
|
+
ErrorPage: '@zenithbuild/core/components/ErrorPage.zen'
|
|
9
|
+
};
|
|
10
|
+
// Component path resolver
|
|
11
|
+
export function getCoreComponentPath(componentName) {
|
|
12
|
+
return CORE_COMPONENTS[componentName];
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Config
|
|
3
|
+
*
|
|
4
|
+
* Public exports for zenith/config
|
|
5
|
+
*
|
|
6
|
+
* Core exports ONLY generic plugin infrastructure.
|
|
7
|
+
* Plugin-specific types are owned by their respective plugins.
|
|
8
|
+
*/
|
|
9
|
+
export { defineConfig } from './types';
|
|
10
|
+
export type { ZenithConfig, ZenithPlugin, PluginContext, PluginData } from './types';
|
|
11
|
+
export { loadZenithConfig, hasZenithConfig } from './loader';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Config
|
|
3
|
+
*
|
|
4
|
+
* Public exports for zenith/config
|
|
5
|
+
*
|
|
6
|
+
* Core exports ONLY generic plugin infrastructure.
|
|
7
|
+
* Plugin-specific types are owned by their respective plugins.
|
|
8
|
+
*/
|
|
9
|
+
export { defineConfig } from './types';
|
|
10
|
+
export { loadZenithConfig, hasZenithConfig } from './loader';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Config Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads zenith.config.ts from the project root
|
|
5
|
+
*/
|
|
6
|
+
import type { ZenithConfig } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Load zenith.config.ts from the project root
|
|
9
|
+
*
|
|
10
|
+
* @param projectRoot - Absolute path to the project root
|
|
11
|
+
* @returns Parsed ZenithConfig or empty config if not found
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadZenithConfig(projectRoot: string): Promise<ZenithConfig>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a zenith.config.ts exists in the project
|
|
16
|
+
*/
|
|
17
|
+
export declare function hasZenithConfig(projectRoot: string): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Config Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads zenith.config.ts from the project root
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
/**
|
|
9
|
+
* Load zenith.config.ts from the project root
|
|
10
|
+
*
|
|
11
|
+
* @param projectRoot - Absolute path to the project root
|
|
12
|
+
* @returns Parsed ZenithConfig or empty config if not found
|
|
13
|
+
*/
|
|
14
|
+
export async function loadZenithConfig(projectRoot) {
|
|
15
|
+
// Check for TypeScript config first, then JavaScript
|
|
16
|
+
const configPaths = [
|
|
17
|
+
path.join(projectRoot, 'zenith.config.ts'),
|
|
18
|
+
path.join(projectRoot, 'zenith.config.js'),
|
|
19
|
+
path.join(projectRoot, 'zenith.config.mjs'),
|
|
20
|
+
];
|
|
21
|
+
let configPath = null;
|
|
22
|
+
for (const p of configPaths) {
|
|
23
|
+
if (fs.existsSync(p)) {
|
|
24
|
+
configPath = p;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!configPath) {
|
|
29
|
+
// No config file found, return empty config
|
|
30
|
+
return { plugins: [] };
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
// Use dynamic import to load the config
|
|
34
|
+
// Bun supports importing TS files directly
|
|
35
|
+
const configModule = await import(configPath);
|
|
36
|
+
const config = configModule.default || configModule;
|
|
37
|
+
// Validate basic structure
|
|
38
|
+
if (typeof config !== 'object' || config === null) {
|
|
39
|
+
console.warn(`[Zenith] Invalid config format in ${configPath}`);
|
|
40
|
+
return { plugins: [] };
|
|
41
|
+
}
|
|
42
|
+
return config;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
46
|
+
console.error(`[Zenith] Failed to load config from ${configPath}:`, message);
|
|
47
|
+
return { plugins: [] };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if a zenith.config.ts exists in the project
|
|
52
|
+
*/
|
|
53
|
+
export function hasZenithConfig(projectRoot) {
|
|
54
|
+
const configPaths = [
|
|
55
|
+
path.join(projectRoot, 'zenith.config.ts'),
|
|
56
|
+
path.join(projectRoot, 'zenith.config.js'),
|
|
57
|
+
path.join(projectRoot, 'zenith.config.mjs'),
|
|
58
|
+
];
|
|
59
|
+
return configPaths.some(p => fs.existsSync(p));
|
|
60
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Config Types
|
|
3
|
+
*
|
|
4
|
+
* Configuration interfaces for zenith.config.ts
|
|
5
|
+
*
|
|
6
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
7
|
+
* HOOK OWNERSHIP RULE (CANONICAL)
|
|
8
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
9
|
+
*
|
|
10
|
+
* Core may ONLY define types that are universally valid in all Zenith applications.
|
|
11
|
+
* Plugin-specific types MUST be owned by their respective plugins.
|
|
12
|
+
*
|
|
13
|
+
* ✅ ALLOWED in Core:
|
|
14
|
+
* - ZenithConfig, ZenithPlugin, PluginContext (generic plugin infrastructure)
|
|
15
|
+
* - Universal lifecycle hooks (onMount, onUnmount)
|
|
16
|
+
* - Reactivity primitives (signal, effect, etc.)
|
|
17
|
+
*
|
|
18
|
+
* ❌ PROHIBITED in Core:
|
|
19
|
+
* - Content plugin types (ContentItem, ContentSourceConfig, etc.)
|
|
20
|
+
* - Router plugin types (RouteState, NavigationGuard, etc.)
|
|
21
|
+
* - Documentation plugin types
|
|
22
|
+
* - Any type that exists only because a plugin exists
|
|
23
|
+
*
|
|
24
|
+
* If removing a plugin would make a type meaningless, that type belongs to the plugin.
|
|
25
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
26
|
+
*/
|
|
27
|
+
import type { CLIBridgeAPI } from '../plugins/bridge';
|
|
28
|
+
/**
|
|
29
|
+
* Generic data record for plugin data exchange
|
|
30
|
+
* Plugins define their own specific types internally
|
|
31
|
+
*/
|
|
32
|
+
export type PluginData = Record<string, unknown[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Context passed to plugins during setup
|
|
35
|
+
*
|
|
36
|
+
* This is intentionally generic - plugins define their own data shapes.
|
|
37
|
+
* Core provides the stage, plugins bring the actors.
|
|
38
|
+
*/
|
|
39
|
+
export interface PluginContext {
|
|
40
|
+
/** Absolute path to project root */
|
|
41
|
+
projectRoot: string;
|
|
42
|
+
/**
|
|
43
|
+
* Set plugin data for the runtime
|
|
44
|
+
*
|
|
45
|
+
* Generic setter - plugins define their own data structures.
|
|
46
|
+
* The runtime stores this data and makes it available to components.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Content plugin uses it for content items
|
|
50
|
+
* ctx.setPluginData('content', contentItems);
|
|
51
|
+
*
|
|
52
|
+
* // Analytics plugin uses it for tracking config
|
|
53
|
+
* ctx.setPluginData('analytics', analyticsConfig);
|
|
54
|
+
*/
|
|
55
|
+
setPluginData: (namespace: string, data: unknown[]) => void;
|
|
56
|
+
/** Additional options passed from config */
|
|
57
|
+
options?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A Zenith plugin definition
|
|
61
|
+
*
|
|
62
|
+
* Plugins are self-contained, removable extensions.
|
|
63
|
+
* Core must build and run identically with or without any plugin installed.
|
|
64
|
+
*/
|
|
65
|
+
export interface ZenithPlugin {
|
|
66
|
+
/** Unique plugin name */
|
|
67
|
+
name: string;
|
|
68
|
+
/** Setup function called during initialization */
|
|
69
|
+
setup: (ctx: PluginContext) => void | Promise<void>;
|
|
70
|
+
/** Plugin-specific configuration (preserved for reference) */
|
|
71
|
+
config?: unknown;
|
|
72
|
+
/**
|
|
73
|
+
* Optional CLI registration
|
|
74
|
+
*
|
|
75
|
+
* Plugin receives the CLI bridge API to register namespaced hooks.
|
|
76
|
+
* CLI lifecycle hooks: 'cli:*' (owned by CLI)
|
|
77
|
+
* Plugin hooks: '<namespace>:*' (owned by plugin)
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* registerCLI(api) {
|
|
81
|
+
* api.on('cli:runtime:collect', (ctx) => {
|
|
82
|
+
* return { namespace: 'myPlugin', payload: ctx.getPluginData('myPlugin') }
|
|
83
|
+
* })
|
|
84
|
+
* }
|
|
85
|
+
*/
|
|
86
|
+
registerCLI?: (api: CLIBridgeAPI) => void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Zenith configuration object
|
|
90
|
+
*/
|
|
91
|
+
export interface ZenithConfig {
|
|
92
|
+
/** List of plugins to load */
|
|
93
|
+
plugins?: ZenithPlugin[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Define a Zenith configuration with full type safety
|
|
97
|
+
*/
|
|
98
|
+
export declare function defineConfig(config: ZenithConfig): ZenithConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Config Types
|
|
3
|
+
*
|
|
4
|
+
* Configuration interfaces for zenith.config.ts
|
|
5
|
+
*
|
|
6
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
7
|
+
* HOOK OWNERSHIP RULE (CANONICAL)
|
|
8
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
9
|
+
*
|
|
10
|
+
* Core may ONLY define types that are universally valid in all Zenith applications.
|
|
11
|
+
* Plugin-specific types MUST be owned by their respective plugins.
|
|
12
|
+
*
|
|
13
|
+
* ✅ ALLOWED in Core:
|
|
14
|
+
* - ZenithConfig, ZenithPlugin, PluginContext (generic plugin infrastructure)
|
|
15
|
+
* - Universal lifecycle hooks (onMount, onUnmount)
|
|
16
|
+
* - Reactivity primitives (signal, effect, etc.)
|
|
17
|
+
*
|
|
18
|
+
* ❌ PROHIBITED in Core:
|
|
19
|
+
* - Content plugin types (ContentItem, ContentSourceConfig, etc.)
|
|
20
|
+
* - Router plugin types (RouteState, NavigationGuard, etc.)
|
|
21
|
+
* - Documentation plugin types
|
|
22
|
+
* - Any type that exists only because a plugin exists
|
|
23
|
+
*
|
|
24
|
+
* If removing a plugin would make a type meaningless, that type belongs to the plugin.
|
|
25
|
+
* ═══════════════════════════════════════════════════════════════════════════════
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Define a Zenith configuration with full type safety
|
|
29
|
+
*/
|
|
30
|
+
export function defineConfig(config) {
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Compiler Core Modules
|
|
3
|
+
*/
|
|
4
|
+
export { loadZenithConfig } from './config/loader';
|
|
5
|
+
export { PluginRegistry, createPluginContext, getPluginDataByNamespace } from './plugins/registry';
|
|
6
|
+
export { createBridgeAPI, runPluginHooks, collectHookReturns, buildRuntimeEnvelope, clearHooks } from './plugins/bridge';
|
|
7
|
+
export type { HookContext } from './plugins/bridge';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Compiler Core Modules
|
|
3
|
+
*/
|
|
4
|
+
export { loadZenithConfig } from './config/loader';
|
|
5
|
+
export { PluginRegistry, createPluginContext, getPluginDataByNamespace } from './plugins/registry';
|
|
6
|
+
export { createBridgeAPI, runPluginHooks, collectHookReturns, buildRuntimeEnvelope, clearHooks } from './plugins/bridge';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Lifecycle Hooks
|
|
3
|
+
*
|
|
4
|
+
* This module exports lifecycle hooks for component mount/unmount events.
|
|
5
|
+
* These are effect wrappers that integrate with the component lifecycle system.
|
|
6
|
+
*
|
|
7
|
+
* Exports both explicit `zen*` names (internal) and clean aliases (public DX).
|
|
8
|
+
*/
|
|
9
|
+
import { zenOnMount as _zenOnMount, triggerMount, triggerUnmount, getIsMounted, resetMountState, type MountCallback } from './zen-mount';
|
|
10
|
+
import { zenOnUnmount as _zenOnUnmount, executeUnmountCallbacks, getUnmountCallbackCount, resetUnmountState, type UnmountCallback } from './zen-unmount';
|
|
11
|
+
export declare const zenOnMount: typeof _zenOnMount;
|
|
12
|
+
export declare const zenOnUnmount: typeof _zenOnUnmount;
|
|
13
|
+
export { triggerMount, triggerUnmount, getIsMounted, resetMountState, executeUnmountCallbacks, getUnmountCallbackCount, resetUnmountState };
|
|
14
|
+
export type { MountCallback, UnmountCallback };
|
|
15
|
+
export declare const onMount: typeof _zenOnMount;
|
|
16
|
+
export declare const onUnmount: typeof _zenOnUnmount;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Lifecycle Hooks
|
|
3
|
+
*
|
|
4
|
+
* This module exports lifecycle hooks for component mount/unmount events.
|
|
5
|
+
* These are effect wrappers that integrate with the component lifecycle system.
|
|
6
|
+
*
|
|
7
|
+
* Exports both explicit `zen*` names (internal) and clean aliases (public DX).
|
|
8
|
+
*/
|
|
9
|
+
// Import lifecycle hooks
|
|
10
|
+
import { zenOnMount as _zenOnMount, triggerMount, triggerUnmount, getIsMounted, resetMountState } from './zen-mount';
|
|
11
|
+
import { zenOnUnmount as _zenOnUnmount, executeUnmountCallbacks, getUnmountCallbackCount, resetUnmountState } from './zen-unmount';
|
|
12
|
+
// Re-export with explicit names
|
|
13
|
+
export const zenOnMount = _zenOnMount;
|
|
14
|
+
export const zenOnUnmount = _zenOnUnmount;
|
|
15
|
+
// Re-export utilities
|
|
16
|
+
export { triggerMount, triggerUnmount, getIsMounted, resetMountState, executeUnmountCallbacks, getUnmountCallbackCount, resetUnmountState };
|
|
17
|
+
// Public DX aliases - clean names
|
|
18
|
+
export const onMount = _zenOnMount;
|
|
19
|
+
export const onUnmount = _zenOnUnmount;
|