@zenithbuild/core 0.6.2 → 0.6.4

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.
Files changed (112) hide show
  1. package/CORE_CONTRACT.md +145 -0
  2. package/README.md +14 -29
  3. package/bin/zenith.js +89 -0
  4. package/package.json +39 -56
  5. package/src/config.js +136 -0
  6. package/src/core-template.js +30 -0
  7. package/src/errors.js +54 -0
  8. package/src/guards.js +61 -0
  9. package/src/hash.js +52 -0
  10. package/src/index.js +26 -0
  11. package/src/ir/index.js +1 -0
  12. package/src/order.js +69 -0
  13. package/src/path.js +131 -0
  14. package/src/schema.js +28 -0
  15. package/src/version.js +67 -0
  16. package/bin/zen-build.ts +0 -2
  17. package/bin/zen-dev.ts +0 -2
  18. package/bin/zen-preview.ts +0 -2
  19. package/bin/zenith.ts +0 -2
  20. package/cli/commands/add.ts +0 -37
  21. package/cli/commands/build.ts +0 -37
  22. package/cli/commands/create.ts +0 -702
  23. package/cli/commands/dev.ts +0 -388
  24. package/cli/commands/index.ts +0 -112
  25. package/cli/commands/preview.ts +0 -62
  26. package/cli/commands/remove.ts +0 -33
  27. package/cli/index.ts +0 -10
  28. package/cli/main.ts +0 -101
  29. package/cli/utils/branding.ts +0 -178
  30. package/cli/utils/content.ts +0 -112
  31. package/cli/utils/logger.ts +0 -46
  32. package/cli/utils/plugin-manager.ts +0 -114
  33. package/cli/utils/project.ts +0 -77
  34. package/compiler/README.md +0 -380
  35. package/compiler/build-analyzer.ts +0 -122
  36. package/compiler/css/index.ts +0 -317
  37. package/compiler/discovery/componentDiscovery.ts +0 -178
  38. package/compiler/discovery/layouts.ts +0 -70
  39. package/compiler/errors/compilerError.ts +0 -56
  40. package/compiler/finalize/finalizeOutput.ts +0 -192
  41. package/compiler/finalize/generateFinalBundle.ts +0 -82
  42. package/compiler/index.ts +0 -83
  43. package/compiler/ir/types.ts +0 -174
  44. package/compiler/output/types.ts +0 -34
  45. package/compiler/parse/detectMapExpressions.ts +0 -102
  46. package/compiler/parse/importTypes.ts +0 -78
  47. package/compiler/parse/parseImports.ts +0 -309
  48. package/compiler/parse/parseScript.ts +0 -46
  49. package/compiler/parse/parseTemplate.ts +0 -599
  50. package/compiler/parse/parseZenFile.ts +0 -66
  51. package/compiler/parse/scriptAnalysis.ts +0 -91
  52. package/compiler/parse/trackLoopContext.ts +0 -82
  53. package/compiler/runtime/dataExposure.ts +0 -317
  54. package/compiler/runtime/generateDOM.ts +0 -246
  55. package/compiler/runtime/generateHydrationBundle.ts +0 -407
  56. package/compiler/runtime/hydration.ts +0 -309
  57. package/compiler/runtime/navigation.ts +0 -432
  58. package/compiler/runtime/thinRuntime.ts +0 -160
  59. package/compiler/runtime/transformIR.ts +0 -370
  60. package/compiler/runtime/wrapExpression.ts +0 -95
  61. package/compiler/runtime/wrapExpressionWithLoop.ts +0 -83
  62. package/compiler/spa-build.ts +0 -917
  63. package/compiler/ssg-build.ts +0 -422
  64. package/compiler/test/validate-test.ts +0 -104
  65. package/compiler/transform/classifyExpression.ts +0 -444
  66. package/compiler/transform/componentResolver.ts +0 -312
  67. package/compiler/transform/componentScriptTransformer.ts +0 -303
  68. package/compiler/transform/expressionTransformer.ts +0 -385
  69. package/compiler/transform/fragmentLowering.ts +0 -634
  70. package/compiler/transform/generateBindings.ts +0 -47
  71. package/compiler/transform/generateHTML.ts +0 -28
  72. package/compiler/transform/layoutProcessor.ts +0 -132
  73. package/compiler/transform/slotResolver.ts +0 -292
  74. package/compiler/transform/transformNode.ts +0 -126
  75. package/compiler/transform/transformTemplate.ts +0 -38
  76. package/compiler/validate/invariants.ts +0 -292
  77. package/compiler/validate/validateExpressions.ts +0 -168
  78. package/core/config/index.ts +0 -16
  79. package/core/config/loader.ts +0 -69
  80. package/core/config/types.ts +0 -89
  81. package/core/index.ts +0 -135
  82. package/core/lifecycle/index.ts +0 -49
  83. package/core/lifecycle/zen-mount.ts +0 -182
  84. package/core/lifecycle/zen-unmount.ts +0 -88
  85. package/core/plugins/index.ts +0 -7
  86. package/core/plugins/registry.ts +0 -81
  87. package/core/reactivity/index.ts +0 -54
  88. package/core/reactivity/tracking.ts +0 -167
  89. package/core/reactivity/zen-batch.ts +0 -57
  90. package/core/reactivity/zen-effect.ts +0 -139
  91. package/core/reactivity/zen-memo.ts +0 -146
  92. package/core/reactivity/zen-ref.ts +0 -52
  93. package/core/reactivity/zen-signal.ts +0 -121
  94. package/core/reactivity/zen-state.ts +0 -180
  95. package/core/reactivity/zen-untrack.ts +0 -44
  96. package/dist/cli.js +0 -11665
  97. package/dist/zen-build.js +0 -21172
  98. package/dist/zen-dev.js +0 -21172
  99. package/dist/zen-preview.js +0 -21172
  100. package/dist/zenith.js +0 -21172
  101. package/router/index.ts +0 -28
  102. package/router/manifest.ts +0 -314
  103. package/router/navigation/ZenLink.zen +0 -231
  104. package/router/navigation/index.ts +0 -78
  105. package/router/navigation/zen-link.ts +0 -584
  106. package/router/runtime.ts +0 -458
  107. package/router/types.ts +0 -168
  108. package/runtime/build.ts +0 -17
  109. package/runtime/bundle-generator.ts +0 -1247
  110. package/runtime/client-runtime.ts +0 -549
  111. package/runtime/serve.ts +0 -93
  112. package/tsconfig.json +0 -28
package/core/index.ts DELETED
@@ -1,135 +0,0 @@
1
- /**
2
- * Zenith Core Runtime
3
- *
4
- * This is the foundational layer of the Zenith framework, providing:
5
- * - Reactive primitives (signals, state, effects, memos)
6
- * - Lifecycle hooks (onMount, onUnmount)
7
- *
8
- * Design principles:
9
- * - Auto-tracked reactivity (no dependency arrays)
10
- * - No VDOM or render loops
11
- * - Runtime-agnostic (works in browser, SSR, tests)
12
- * - Hybrid naming: internal `zen*` + public clean names
13
- *
14
- * @example
15
- * ```ts
16
- * // Using clean names (recommended for application code)
17
- * import { signal, effect, onMount } from 'zenith/core'
18
- *
19
- * const count = signal(0)
20
- *
21
- * effect(() => {
22
- * console.log('Count:', count())
23
- * })
24
- *
25
- * onMount(() => {
26
- * console.log('Mounted!')
27
- * })
28
- * ```
29
- *
30
- * @example
31
- * ```ts
32
- * // Using explicit zen* names (for library/internal code)
33
- * import { zenSignal, zenEffect, zenOnMount } from 'zenith/core'
34
- *
35
- * const count = zenSignal(0)
36
- * zenEffect(() => console.log(count()))
37
- * zenOnMount(() => console.log('Ready'))
38
- * ```
39
- *
40
- * @example
41
- * ```ts
42
- * // For navigation, import from router
43
- * import { navigate, isActive } from 'zenith/router'
44
- *
45
- * navigate('/about')
46
- * if (isActive('/blog')) {
47
- * // Handle active state
48
- * }
49
- * ```
50
- */
51
-
52
- // ============================================
53
- // Reactivity Primitives
54
- // ============================================
55
-
56
- // Explicit zen* exports (internal naming)
57
- export {
58
- zenSignal,
59
- zenState,
60
- zenEffect,
61
- zenMemo,
62
- zenRef,
63
- zenBatch,
64
- zenUntrack
65
- } from './reactivity'
66
-
67
- // Types
68
- export type {
69
- Signal,
70
- Memo,
71
- Ref,
72
- EffectFn,
73
- DisposeFn,
74
- Subscriber,
75
- TrackingContext
76
- } from './reactivity'
77
-
78
- // Clean name exports (public DX)
79
- export {
80
- signal,
81
- state,
82
- effect,
83
- memo,
84
- ref,
85
- batch,
86
- untrack
87
- } from './reactivity'
88
-
89
- // Internal tracking utilities (advanced use)
90
- export {
91
- trackDependency,
92
- notifySubscribers,
93
- getCurrentContext,
94
- pushContext,
95
- popContext,
96
- cleanupContext,
97
- runUntracked,
98
- startBatch,
99
- endBatch,
100
- isBatching
101
- } from './reactivity'
102
-
103
- // ============================================
104
- // Lifecycle Hooks
105
- // ============================================
106
-
107
- // Explicit zen* exports (internal naming)
108
- export {
109
- zenOnMount,
110
- zenOnUnmount
111
- } from './lifecycle'
112
-
113
- // Clean name exports (public DX)
114
- export {
115
- onMount,
116
- onUnmount
117
- } from './lifecycle'
118
-
119
- // Types
120
- export type {
121
- MountCallback,
122
- UnmountCallback
123
- } from './lifecycle'
124
-
125
- // Internal lifecycle utilities (for component system)
126
- export {
127
- triggerMount,
128
- triggerUnmount,
129
- executeUnmountCallbacks,
130
- getIsMounted,
131
- getUnmountCallbackCount,
132
- resetMountState,
133
- resetUnmountState
134
- } from './lifecycle'
135
-
@@ -1,49 +0,0 @@
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
-
10
- // Import lifecycle hooks
11
- import {
12
- zenOnMount as _zenOnMount,
13
- triggerMount,
14
- triggerUnmount,
15
- getIsMounted,
16
- resetMountState,
17
- type MountCallback
18
- } from './zen-mount'
19
-
20
- import {
21
- zenOnUnmount as _zenOnUnmount,
22
- executeUnmountCallbacks,
23
- getUnmountCallbackCount,
24
- resetUnmountState,
25
- type UnmountCallback
26
- } from './zen-unmount'
27
-
28
- // Re-export with explicit names
29
- export const zenOnMount = _zenOnMount
30
- export const zenOnUnmount = _zenOnUnmount
31
-
32
- // Re-export utilities
33
- export {
34
- triggerMount,
35
- triggerUnmount,
36
- getIsMounted,
37
- resetMountState,
38
- executeUnmountCallbacks,
39
- getUnmountCallbackCount,
40
- resetUnmountState
41
- }
42
-
43
- // Re-export types
44
- export type { MountCallback, UnmountCallback }
45
-
46
- // Public DX aliases - clean names
47
- export const onMount = _zenOnMount
48
- export const onUnmount = _zenOnUnmount
49
-
@@ -1,182 +0,0 @@
1
- /**
2
- * Zenith OnMount - Post-Mount Lifecycle Hook
3
- *
4
- * Registers a callback to run after a component's DOM is inserted.
5
- * This is an effect wrapper that defers execution until the mount phase.
6
- *
7
- * Features:
8
- * - Runs after DOM is available
9
- * - Only runs once per mount
10
- * - Supports cleanup function return
11
- * - Works with component lifecycle system
12
- *
13
- * @example
14
- * ```ts
15
- * zenOnMount(() => {
16
- * console.log('Component mounted!')
17
- * const el = document.querySelector('.my-element')
18
- *
19
- * // Optional cleanup - runs on unmount
20
- * return () => {
21
- * console.log('Component will unmount')
22
- * }
23
- * })
24
- * ```
25
- *
26
- * Note: This hook registers callbacks that will be executed by the
27
- * component lifecycle system. If no mount scheduler is active,
28
- * callbacks are queued for later execution.
29
- */
30
-
31
- /**
32
- * Mount callback type - can optionally return a cleanup function
33
- */
34
- export type MountCallback = () => void | (() => void)
35
-
36
- /**
37
- * Mount hook state
38
- */
39
- interface MountHookState {
40
- callback: MountCallback
41
- cleanup: (() => void) | null
42
- mounted: boolean
43
- }
44
-
45
- /**
46
- * Queue of pending mount callbacks
47
- * These are registered but not yet executed because mount hasn't occurred
48
- */
49
- const pendingMountCallbacks: MountHookState[] = []
50
-
51
- /**
52
- * Currently active mount hooks (for cleanup on unmount)
53
- */
54
- const activeMountHooks: Set<MountHookState> = new Set()
55
-
56
- /**
57
- * Flag indicating whether we're in a mounted state
58
- * This is controlled by the component lifecycle system
59
- */
60
- let isMounted = false
61
-
62
- /**
63
- * Register a callback to run after component mount
64
- *
65
- * @param callback - Function to run after mount (can return cleanup function)
66
- * @returns Dispose function to cancel the mount callback
67
- */
68
- export function zenOnMount(callback: MountCallback): () => void {
69
- const state: MountHookState = {
70
- callback,
71
- cleanup: null,
72
- mounted: false
73
- }
74
-
75
- if (isMounted) {
76
- // Already mounted - run immediately
77
- executeMountCallback(state)
78
- } else {
79
- // Queue for later execution
80
- pendingMountCallbacks.push(state)
81
- }
82
-
83
- activeMountHooks.add(state)
84
-
85
- // Return dispose function
86
- return () => {
87
- // Remove from pending if not yet executed
88
- const pendingIndex = pendingMountCallbacks.indexOf(state)
89
- if (pendingIndex !== -1) {
90
- pendingMountCallbacks.splice(pendingIndex, 1)
91
- }
92
-
93
- // Run cleanup if already mounted
94
- if (state.mounted && state.cleanup) {
95
- state.cleanup()
96
- state.cleanup = null
97
- }
98
-
99
- activeMountHooks.delete(state)
100
- }
101
- }
102
-
103
- /**
104
- * Execute a mount callback
105
- */
106
- function executeMountCallback(state: MountHookState): void {
107
- if (state.mounted) return
108
-
109
- state.mounted = true
110
-
111
- try {
112
- const result = state.callback()
113
-
114
- if (typeof result === 'function') {
115
- state.cleanup = result
116
- }
117
- } catch (error) {
118
- console.error('[Zenith] Error in onMount callback:', error)
119
- }
120
- }
121
-
122
- /**
123
- * Trigger mount phase - called by component lifecycle system
124
- * Executes all pending mount callbacks
125
- *
126
- * @internal
127
- */
128
- export function triggerMount(): void {
129
- isMounted = true
130
-
131
- // Execute all pending callbacks
132
- const callbacks = [...pendingMountCallbacks]
133
- pendingMountCallbacks.length = 0
134
-
135
- for (const state of callbacks) {
136
- executeMountCallback(state)
137
- }
138
- }
139
-
140
- /**
141
- * Trigger unmount phase - called by component lifecycle system
142
- * Runs cleanup functions for all active mount hooks
143
- *
144
- * @internal
145
- */
146
- export function triggerUnmount(): void {
147
- isMounted = false
148
-
149
- // Run all cleanup functions
150
- for (const state of activeMountHooks) {
151
- if (state.cleanup) {
152
- try {
153
- state.cleanup()
154
- } catch (error) {
155
- console.error('[Zenith] Error in onMount cleanup:', error)
156
- }
157
- state.cleanup = null
158
- }
159
- state.mounted = false
160
- }
161
- }
162
-
163
- /**
164
- * Check if currently in mounted state
165
- *
166
- * @internal
167
- */
168
- export function getIsMounted(): boolean {
169
- return isMounted
170
- }
171
-
172
- /**
173
- * Reset mount state - for testing purposes
174
- *
175
- * @internal
176
- */
177
- export function resetMountState(): void {
178
- isMounted = false
179
- pendingMountCallbacks.length = 0
180
- activeMountHooks.clear()
181
- }
182
-
@@ -1,88 +0,0 @@
1
- /**
2
- * Zenith OnUnmount - Pre-Unmount Lifecycle Hook
3
- *
4
- * Registers a cleanup callback to run before a component is disposed.
5
- * Useful for cleaning up subscriptions, timers, event listeners, etc.
6
- *
7
- * Features:
8
- * - Runs before component is removed from DOM
9
- * - Can register multiple callbacks
10
- * - Callbacks run in registration order
11
- *
12
- * @example
13
- * ```ts
14
- * zenOnUnmount(() => {
15
- * console.log('Cleaning up...')
16
- * subscription.unsubscribe()
17
- * clearInterval(timerId)
18
- * })
19
- * ```
20
- *
21
- * Note: This hook registers callbacks that will be executed by the
22
- * component lifecycle system when the component is disposed.
23
- */
24
-
25
- /**
26
- * Unmount callback type
27
- */
28
- export type UnmountCallback = () => void
29
-
30
- /**
31
- * Queue of registered unmount callbacks
32
- */
33
- const unmountCallbacks: Set<UnmountCallback> = new Set()
34
-
35
- /**
36
- * Register a callback to run before component unmount
37
- *
38
- * @param callback - Function to run before unmount
39
- * @returns Dispose function to cancel the unmount callback
40
- */
41
- export function zenOnUnmount(callback: UnmountCallback): () => void {
42
- unmountCallbacks.add(callback)
43
-
44
- // Return dispose function
45
- return () => {
46
- unmountCallbacks.delete(callback)
47
- }
48
- }
49
-
50
- /**
51
- * Execute all unmount callbacks
52
- * Called by the component lifecycle system before disposal
53
- *
54
- * @internal
55
- */
56
- export function executeUnmountCallbacks(): void {
57
- // Execute in registration order
58
- for (const callback of unmountCallbacks) {
59
- try {
60
- callback()
61
- } catch (error) {
62
- console.error('[Zenith] Error in onUnmount callback:', error)
63
- }
64
- }
65
-
66
- // Clear all callbacks after execution
67
- unmountCallbacks.clear()
68
- }
69
-
70
- /**
71
- * Get count of registered unmount callbacks
72
- * Useful for testing
73
- *
74
- * @internal
75
- */
76
- export function getUnmountCallbackCount(): number {
77
- return unmountCallbacks.size
78
- }
79
-
80
- /**
81
- * Reset unmount state - for testing purposes
82
- *
83
- * @internal
84
- */
85
- export function resetUnmountState(): void {
86
- unmountCallbacks.clear()
87
- }
88
-
@@ -1,7 +0,0 @@
1
- /**
2
- * Zenith Plugins
3
- *
4
- * Public exports for plugin system
5
- */
6
-
7
- export { PluginRegistry, createPluginContext } from './registry';
@@ -1,81 +0,0 @@
1
- /**
2
- * Zenith Plugin Registry
3
- *
4
- * Manages plugin registration and initialization
5
- */
6
-
7
- import type { ZenithPlugin, PluginContext, ContentItem } from '../config/types';
8
-
9
- /**
10
- * Plugin registry for managing Zenith plugins
11
- */
12
- export class PluginRegistry {
13
- private plugins = new Map<string, ZenithPlugin>();
14
-
15
- /**
16
- * Register a plugin
17
- */
18
- register(plugin: ZenithPlugin): void {
19
- if (this.plugins.has(plugin.name)) {
20
- console.warn(`[Zenith] Plugin "${plugin.name}" is already registered. Overwriting.`);
21
- }
22
- this.plugins.set(plugin.name, plugin);
23
- }
24
-
25
- /**
26
- * Get a plugin by name
27
- */
28
- get(name: string): ZenithPlugin | undefined {
29
- return this.plugins.get(name);
30
- }
31
-
32
- /**
33
- * Check if a plugin is registered
34
- */
35
- has(name: string): boolean {
36
- return this.plugins.has(name);
37
- }
38
-
39
- /**
40
- * Get all registered plugins
41
- */
42
- all(): ZenithPlugin[] {
43
- return Array.from(this.plugins.values());
44
- }
45
-
46
- /**
47
- * Initialize all plugins with the provided context
48
- */
49
- async initAll(ctx: PluginContext): Promise<void> {
50
- for (const plugin of this.plugins.values()) {
51
- try {
52
- await plugin.setup(ctx);
53
- console.log(`[Zenith] Plugin "${plugin.name}" initialized`);
54
- } catch (error: unknown) {
55
- const message = error instanceof Error ? error.message : String(error);
56
- console.error(`[Zenith] Failed to initialize plugin "${plugin.name}":`, message);
57
- }
58
- }
59
- }
60
-
61
- /**
62
- * Clear all registered plugins
63
- */
64
- clear(): void {
65
- this.plugins.clear();
66
- }
67
- }
68
-
69
- /**
70
- * Create a plugin context for initialization
71
- */
72
- export function createPluginContext(
73
- projectRoot: string,
74
- contentSetter: (data: Record<string, ContentItem[]>) => void
75
- ): PluginContext {
76
- return {
77
- projectRoot,
78
- setContentData: contentSetter,
79
- options: {}
80
- };
81
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * Zenith Reactivity System
3
- *
4
- * This module exports all reactive primitives for the Zenith framework.
5
- *
6
- * Exports both explicit `zen*` names (internal) and clean aliases (public DX).
7
- */
8
-
9
- // Core primitives - explicit names
10
- import { zenSignal as _zenSignal, type Signal } from './zen-signal'
11
- import { zenState as _zenState } from './zen-state'
12
- import { zenEffect as _zenEffect, type EffectFn, type DisposeFn } from './zen-effect'
13
- import { zenMemo as _zenMemo, type Memo } from './zen-memo'
14
- import { zenRef as _zenRef, type Ref } from './zen-ref'
15
- import { zenBatch as _zenBatch } from './zen-batch'
16
- import { zenUntrack as _zenUntrack } from './zen-untrack'
17
-
18
- // Re-export with explicit names
19
- export const zenSignal = _zenSignal
20
- export const zenState = _zenState
21
- export const zenEffect = _zenEffect
22
- export const zenMemo = _zenMemo
23
- export const zenRef = _zenRef
24
- export const zenBatch = _zenBatch
25
- export const zenUntrack = _zenUntrack
26
-
27
- // Re-export types
28
- export type { Signal, Memo, Ref, EffectFn, DisposeFn }
29
-
30
- // Internal tracking utilities (for advanced use)
31
- export {
32
- type Subscriber,
33
- type TrackingContext,
34
- trackDependency,
35
- notifySubscribers,
36
- getCurrentContext,
37
- pushContext,
38
- popContext,
39
- cleanupContext,
40
- runUntracked,
41
- startBatch,
42
- endBatch,
43
- isBatching
44
- } from './tracking'
45
-
46
- // Public DX aliases - clean names
47
- export const signal = _zenSignal
48
- export const state = _zenState
49
- export const effect = _zenEffect
50
- export const memo = _zenMemo
51
- export const ref = _zenRef
52
- export const batch = _zenBatch
53
- export const untrack = _zenUntrack
54
-