@zenithbuild/compiler 1.3.2 → 1.3.9
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/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 +92 -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/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 +112 -0
- package/dist/css/index.d.ts +73 -0
- package/dist/css/index.js +246 -0
- package/dist/discovery/componentDiscovery.d.ts +41 -0
- package/dist/discovery/componentDiscovery.js +66 -0
- package/dist/discovery/layouts.d.ts +14 -0
- package/dist/discovery/layouts.js +36 -0
- package/dist/errors/compilerError.d.ts +31 -0
- package/dist/errors/compilerError.js +51 -0
- package/dist/finalize/generateFinalBundle.d.ts +24 -0
- package/dist/finalize/generateFinalBundle.js +68 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +44 -0
- package/dist/ir/types.d.ts +206 -0
- package/dist/ir/types.js +8 -0
- package/dist/output/types.d.ts +39 -0
- package/dist/output/types.js +6 -0
- package/dist/parseZenFile.d.ts +17 -0
- package/dist/parseZenFile.js +52 -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 +1438 -0
- package/dist/runtime/client-runtime.d.ts +41 -0
- package/dist/runtime/client-runtime.js +397 -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/spa-build.d.ts +26 -0
- package/dist/spa-build.js +849 -0
- package/dist/ssg-build.d.ts +31 -0
- package/dist/ssg-build.js +429 -0
- package/dist/test/bundler-contract.test.d.ts +1 -0
- package/dist/test/bundler-contract.test.js +137 -0
- package/dist/test/compiler-entry.test.d.ts +1 -0
- package/dist/test/compiler-entry.test.js +28 -0
- package/dist/test/error-native-bridge.test.d.ts +1 -0
- package/dist/test/error-native-bridge.test.js +31 -0
- package/dist/test/error-serialization.test.d.ts +1 -0
- package/dist/test/error-serialization.test.js +38 -0
- package/dist/test/phase5-boundary.test.d.ts +1 -0
- package/dist/test/phase5-boundary.test.js +51 -0
- package/dist/transform/layoutProcessor.d.ts +26 -0
- package/dist/transform/layoutProcessor.js +34 -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 +2 -46
- package/native/compiler-native/index.js +1 -16
- package/native/compiler-native/package.json +1 -1
- package/package.json +15 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Development Server
|
|
3
|
+
*
|
|
4
|
+
* SPA-compatible server that:
|
|
5
|
+
* - Serves static assets directly (js, css, ico, images)
|
|
6
|
+
* - Serves index.html for all other routes (SPA fallback)
|
|
7
|
+
*
|
|
8
|
+
* This enables client-side routing to work on:
|
|
9
|
+
* - Direct URL entry
|
|
10
|
+
* - Hard refresh
|
|
11
|
+
* - Back/forward navigation
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith Development Server
|
|
3
|
+
*
|
|
4
|
+
* SPA-compatible server that:
|
|
5
|
+
* - Serves static assets directly (js, css, ico, images)
|
|
6
|
+
* - Serves index.html for all other routes (SPA fallback)
|
|
7
|
+
*
|
|
8
|
+
* This enables client-side routing to work on:
|
|
9
|
+
* - Direct URL entry
|
|
10
|
+
* - Hard refresh
|
|
11
|
+
* - Back/forward navigation
|
|
12
|
+
*/
|
|
13
|
+
import { serve } from "bun";
|
|
14
|
+
import path from "path";
|
|
15
|
+
const distDir = path.resolve(import.meta.dir, "..", "app", "dist");
|
|
16
|
+
// File extensions that should be served as static assets
|
|
17
|
+
const STATIC_EXTENSIONS = new Set([
|
|
18
|
+
".js",
|
|
19
|
+
".css",
|
|
20
|
+
".ico",
|
|
21
|
+
".png",
|
|
22
|
+
".jpg",
|
|
23
|
+
".jpeg",
|
|
24
|
+
".gif",
|
|
25
|
+
".svg",
|
|
26
|
+
".webp",
|
|
27
|
+
".woff",
|
|
28
|
+
".woff2",
|
|
29
|
+
".ttf",
|
|
30
|
+
".eot",
|
|
31
|
+
".json",
|
|
32
|
+
".map"
|
|
33
|
+
]);
|
|
34
|
+
serve({
|
|
35
|
+
port: 3000,
|
|
36
|
+
async fetch(req) {
|
|
37
|
+
const url = new URL(req.url);
|
|
38
|
+
const pathname = url.pathname;
|
|
39
|
+
// Get file extension
|
|
40
|
+
const ext = path.extname(pathname).toLowerCase();
|
|
41
|
+
// Check if this is a static asset request
|
|
42
|
+
if (STATIC_EXTENSIONS.has(ext)) {
|
|
43
|
+
const filePath = path.join(distDir, pathname);
|
|
44
|
+
const file = Bun.file(filePath);
|
|
45
|
+
// Check if file exists
|
|
46
|
+
if (await file.exists()) {
|
|
47
|
+
return new Response(file);
|
|
48
|
+
}
|
|
49
|
+
// Static file not found
|
|
50
|
+
return new Response("Not found", { status: 404 });
|
|
51
|
+
}
|
|
52
|
+
// For all other routes, serve index.html (SPA fallback)
|
|
53
|
+
const indexPath = path.join(distDir, "index.html");
|
|
54
|
+
const indexFile = Bun.file(indexPath);
|
|
55
|
+
if (await indexFile.exists()) {
|
|
56
|
+
return new Response(indexFile, {
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "text/html; charset=utf-8"
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// No index.html found - likely need to run build first
|
|
63
|
+
return new Response(`<html>
|
|
64
|
+
<head><title>Zenith - Build Required</title></head>
|
|
65
|
+
<body style="font-family: system-ui; padding: 2rem; text-align: center;">
|
|
66
|
+
<h1>Build Required</h1>
|
|
67
|
+
<p>Run <code>bun runtime/build.ts</code> first to compile the pages.</p>
|
|
68
|
+
</body>
|
|
69
|
+
</html>`, {
|
|
70
|
+
status: 500,
|
|
71
|
+
headers: { "Content-Type": "text/html; charset=utf-8" }
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
console.log("🚀 Zenith dev server running at http://localhost:3000");
|
|
76
|
+
console.log(" SPA mode: All routes serve index.html");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin Runtime
|
|
3
|
+
*
|
|
4
|
+
* Phase 8/9/10: Declarative runtime for DOM updates and event binding
|
|
5
|
+
*
|
|
6
|
+
* This runtime is purely declarative - it:
|
|
7
|
+
* - Updates DOM nodes by ID
|
|
8
|
+
* - Binds event handlers
|
|
9
|
+
* - Reacts to state changes
|
|
10
|
+
* - Does NOT parse templates or expressions
|
|
11
|
+
* - Does NOT use eval, new Function, or with(window)
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Generate thin declarative runtime code
|
|
15
|
+
*
|
|
16
|
+
* This runtime is minimal and safe - it only:
|
|
17
|
+
* 1. Updates DOM nodes using pre-compiled expression functions
|
|
18
|
+
* 2. Binds event handlers by ID
|
|
19
|
+
* 3. Provides reactive state updates
|
|
20
|
+
*
|
|
21
|
+
* All expressions are pre-compiled at build time.
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateThinRuntime(): string;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin Runtime
|
|
3
|
+
*
|
|
4
|
+
* Phase 8/9/10: Declarative runtime for DOM updates and event binding
|
|
5
|
+
*
|
|
6
|
+
* This runtime is purely declarative - it:
|
|
7
|
+
* - Updates DOM nodes by ID
|
|
8
|
+
* - Binds event handlers
|
|
9
|
+
* - Reacts to state changes
|
|
10
|
+
* - Does NOT parse templates or expressions
|
|
11
|
+
* - Does NOT use eval, new Function, or with(window)
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Generate thin declarative runtime code
|
|
15
|
+
*
|
|
16
|
+
* This runtime is minimal and safe - it only:
|
|
17
|
+
* 1. Updates DOM nodes using pre-compiled expression functions
|
|
18
|
+
* 2. Binds event handlers by ID
|
|
19
|
+
* 3. Provides reactive state updates
|
|
20
|
+
*
|
|
21
|
+
* All expressions are pre-compiled at build time.
|
|
22
|
+
*/
|
|
23
|
+
export function generateThinRuntime() {
|
|
24
|
+
return `
|
|
25
|
+
// Zenith Thin Runtime (Phase 8/9/10)
|
|
26
|
+
// Purely declarative - no template parsing, no eval, no with(window)
|
|
27
|
+
|
|
28
|
+
(function() {
|
|
29
|
+
'use strict';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Update a single DOM node with expression result
|
|
33
|
+
* Node is identified by data-zen-text or data-zen-attr-* attribute
|
|
34
|
+
*/
|
|
35
|
+
function updateNode(node, expressionId, state, loaderData, props, stores) {
|
|
36
|
+
const expression = window.__ZENITH_EXPRESSIONS__.get(expressionId);
|
|
37
|
+
if (!expression) {
|
|
38
|
+
console.warn('[Zenith] Expression not found:', expressionId);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const result = expression(state, loaderData, props, stores);
|
|
44
|
+
|
|
45
|
+
// Update node based on attribute type
|
|
46
|
+
if (node.hasAttribute('data-zen-text')) {
|
|
47
|
+
// Text node update
|
|
48
|
+
if (result === null || result === undefined || result === false) {
|
|
49
|
+
node.textContent = '';
|
|
50
|
+
} else {
|
|
51
|
+
node.textContent = String(result);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
// Attribute update - determine attribute name from data-zen-attr-*
|
|
55
|
+
const attrMatch = Array.from(node.attributes)
|
|
56
|
+
.find(attr => attr.name.startsWith('data-zen-attr-'));
|
|
57
|
+
|
|
58
|
+
if (attrMatch) {
|
|
59
|
+
const attrName = attrMatch.name.replace('data-zen-attr-', '');
|
|
60
|
+
|
|
61
|
+
if (attrName === 'class' || attrName === 'className') {
|
|
62
|
+
node.className = String(result ?? '');
|
|
63
|
+
} else if (attrName === 'style') {
|
|
64
|
+
if (typeof result === 'string') {
|
|
65
|
+
node.setAttribute('style', result);
|
|
66
|
+
}
|
|
67
|
+
} else if (attrName === 'disabled' || attrName === 'checked') {
|
|
68
|
+
if (result) {
|
|
69
|
+
node.setAttribute(attrName, '');
|
|
70
|
+
} else {
|
|
71
|
+
node.removeAttribute(attrName);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
if (result != null && result !== false) {
|
|
75
|
+
node.setAttribute(attrName, String(result));
|
|
76
|
+
} else {
|
|
77
|
+
node.removeAttribute(attrName);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('[Zenith] Error updating node:', expressionId, error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Update all hydrated nodes
|
|
89
|
+
* Called when state changes
|
|
90
|
+
*/
|
|
91
|
+
function updateAll(state, loaderData, props, stores) {
|
|
92
|
+
// Find all nodes with hydration markers
|
|
93
|
+
const textNodes = document.querySelectorAll('[data-zen-text]');
|
|
94
|
+
const attrNodes = document.querySelectorAll('[data-zen-attr-class], [data-zen-attr-style], [data-zen-attr-src], [data-zen-attr-href]');
|
|
95
|
+
|
|
96
|
+
textNodes.forEach(node => {
|
|
97
|
+
const expressionId = node.getAttribute('data-zen-text');
|
|
98
|
+
if (expressionId) {
|
|
99
|
+
updateNode(node, expressionId, state, loaderData, props, stores);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
attrNodes.forEach(node => {
|
|
104
|
+
const attrMatch = Array.from(node.attributes)
|
|
105
|
+
.find(attr => attr.name.startsWith('data-zen-attr-'));
|
|
106
|
+
if (attrMatch) {
|
|
107
|
+
const expressionId = attrMatch.value;
|
|
108
|
+
if (expressionId) {
|
|
109
|
+
updateNode(node, expressionId, state, loaderData, props, stores);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Bind event handlers
|
|
117
|
+
* Handlers are pre-compiled and registered on window
|
|
118
|
+
*/
|
|
119
|
+
function bindEvents(container) {
|
|
120
|
+
container = container || document;
|
|
121
|
+
|
|
122
|
+
const eventTypes = ['click', 'change', 'input', 'submit', 'focus', 'blur', 'keyup', 'keydown', 'mouseenter'];
|
|
123
|
+
|
|
124
|
+
eventTypes.forEach(eventType => {
|
|
125
|
+
const elements = container.querySelectorAll('[data-zen-' + eventType + ']');
|
|
126
|
+
elements.forEach(element => {
|
|
127
|
+
const handlerName = element.getAttribute('data-zen-' + eventType);
|
|
128
|
+
if (!handlerName) return;
|
|
129
|
+
|
|
130
|
+
// Remove existing handler
|
|
131
|
+
const handlerKey = '__zen_' + eventType + '_handler';
|
|
132
|
+
const existingHandler = element[handlerKey];
|
|
133
|
+
if (existingHandler) {
|
|
134
|
+
element.removeEventListener(eventType, existingHandler);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Bind new handler (pre-compiled, registered on window)
|
|
138
|
+
const handler = function(event) {
|
|
139
|
+
const handlerFunc = window[handlerName];
|
|
140
|
+
if (typeof handlerFunc === 'function') {
|
|
141
|
+
handlerFunc(event, element);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
element[handlerKey] = handler;
|
|
146
|
+
element.addEventListener(eventType, handler);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Export to window
|
|
152
|
+
if (typeof window !== 'undefined') {
|
|
153
|
+
window.__zenith_updateAll = updateAll;
|
|
154
|
+
window.__zenith_bindEvents = bindEvents;
|
|
155
|
+
}
|
|
156
|
+
})();
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zenith SPA Build System
|
|
3
|
+
*
|
|
4
|
+
* Builds all pages into a single index.html with:
|
|
5
|
+
* - Route manifest
|
|
6
|
+
* - Compiled page modules (inlined)
|
|
7
|
+
* - Runtime router
|
|
8
|
+
* - Shell HTML with router outlet
|
|
9
|
+
*/
|
|
10
|
+
interface SPABuildOptions {
|
|
11
|
+
/** Pages directory */
|
|
12
|
+
pagesDir: string;
|
|
13
|
+
/** Output directory */
|
|
14
|
+
outDir: string;
|
|
15
|
+
/** Base directory for components/layouts */
|
|
16
|
+
baseDir?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build SPA from pages directory
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildSPA(options: SPABuildOptions): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Watch mode for development (future)
|
|
24
|
+
*/
|
|
25
|
+
export declare function watchSPA(_options: SPABuildOptions): void;
|
|
26
|
+
export {};
|