@zenithbuild/bundler 1.3.10 → 1.3.15
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/package.json +9 -9
- package/src/build-analyzer.ts +122 -0
- package/src/bundle-generator.ts +844 -0
- package/src/bundler.rs +81 -0
- package/src/bundler.ts +98 -0
- package/src/css.rs +266 -0
- package/src/css.ts +294 -0
- package/src/generateFinalBundle.ts +80 -0
- package/src/html.rs +147 -0
- package/src/index.ts +7 -0
- package/src/lib.rs +116 -0
- package/src/plugin.rs +354 -0
- package/src/runtime-generator.ts +24 -0
- package/src/store.rs +44 -0
- package/src/types.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenithbuild/bundler",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "napi build --platform --release",
|
|
6
6
|
"artifacts": "napi artifacts",
|
|
@@ -10,18 +10,13 @@
|
|
|
10
10
|
"@napi-rs/cli": "^3.5.1",
|
|
11
11
|
"@types/bun": "latest"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
"typescript": "^5"
|
|
15
|
-
},
|
|
16
|
-
"publishConfig": {
|
|
17
|
-
"access": "public"
|
|
18
|
-
},
|
|
19
|
-
"main": "index.js",
|
|
13
|
+
"main": "src/index.ts",
|
|
20
14
|
"exports": {
|
|
21
|
-
".": "./index.
|
|
15
|
+
".": "./src/index.ts",
|
|
22
16
|
"./dev-server": "./dev-server.js"
|
|
23
17
|
},
|
|
24
18
|
"files": [
|
|
19
|
+
"src",
|
|
25
20
|
"index.js",
|
|
26
21
|
"index.node",
|
|
27
22
|
"dev-server.js",
|
|
@@ -31,6 +26,11 @@
|
|
|
31
26
|
"dependencies": {
|
|
32
27
|
"chokidar": "^5.0.0",
|
|
33
28
|
"express": "^4.21.2",
|
|
29
|
+
"rolldown": "^1.0.0-rc.3",
|
|
34
30
|
"ws": "^8.19.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"typescript": "^5",
|
|
34
|
+
"@zenithbuild/compiler": "workspace:*"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
export interface PageAnalysis {
|
|
12
|
+
/** Page has state declarations that need hydration */
|
|
13
|
+
hasState: boolean
|
|
14
|
+
/** Page has event handlers (onclick, etc.) */
|
|
15
|
+
hasEventHandlers: boolean
|
|
16
|
+
/** Page uses lifecycle hooks (zenOnMount, zenOnUnmount) */
|
|
17
|
+
hasLifecycleHooks: boolean
|
|
18
|
+
/** Page uses useFetchServer (requires SSR) */
|
|
19
|
+
usesServerFetch: boolean
|
|
20
|
+
/** Page uses useFetchClient (client-side data) */
|
|
21
|
+
usesClientFetch: boolean
|
|
22
|
+
/** Page uses ZenLink with passHref (SPA navigation) */
|
|
23
|
+
usesZenLink: boolean
|
|
24
|
+
/** Page uses reactive expressions in templates */
|
|
25
|
+
hasReactiveExpressions: boolean
|
|
26
|
+
|
|
27
|
+
/** Computed: page needs any JavaScript */
|
|
28
|
+
needsHydration: boolean
|
|
29
|
+
/** Computed: page is purely static (no JS) */
|
|
30
|
+
isStatic: boolean
|
|
31
|
+
/** Computed: page needs SSR */
|
|
32
|
+
needsSSR: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Analyze a .zen page source to determine build requirements
|
|
37
|
+
*/
|
|
38
|
+
export function analyzePageSource(source: string): PageAnalysis {
|
|
39
|
+
// Extract script content for analysis
|
|
40
|
+
const scriptMatch = source.match(/<script[^>]*>([\s\S]*?)<\/script>/i)
|
|
41
|
+
const scriptContent = scriptMatch?.[1] || ''
|
|
42
|
+
|
|
43
|
+
// Extract template content (everything outside script/style)
|
|
44
|
+
const templateContent = source
|
|
45
|
+
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
|
46
|
+
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
|
47
|
+
|
|
48
|
+
// Check for state declarations: "state varName = ..."
|
|
49
|
+
const hasState = /\bstate\s+\w+\s*=/.test(scriptContent)
|
|
50
|
+
|
|
51
|
+
// Check for event handlers in template
|
|
52
|
+
const hasEventHandlers = /\bon(click|change|input|submit|focus|blur|keydown|keyup|keypress|mousedown|mouseup|mouseover|mouseout|mouseenter|mouseleave|load)\s*=\s*["'{]/.test(templateContent)
|
|
53
|
+
|
|
54
|
+
// Check for lifecycle hooks
|
|
55
|
+
const hasLifecycleHooks = /\bzen(OnMount|OnUnmount)\s*\(/.test(scriptContent)
|
|
56
|
+
|
|
57
|
+
// Check for server fetch
|
|
58
|
+
const usesServerFetch = /\buseFetchServer\s*\(/.test(scriptContent)
|
|
59
|
+
|
|
60
|
+
// Check for client fetch
|
|
61
|
+
const usesClientFetch = /\buseFetchClient\s*\(/.test(scriptContent)
|
|
62
|
+
|
|
63
|
+
// Check for ZenLink with passHref
|
|
64
|
+
const usesZenLink = /<ZenLink[^>]*passHref[^>]*>/.test(templateContent)
|
|
65
|
+
|
|
66
|
+
// Check for reactive expressions in template: {expression}
|
|
67
|
+
// Must be actual expressions, not just static text
|
|
68
|
+
// Exclude attribute values like href="/path"
|
|
69
|
+
const hasReactiveExpressions = /{[^{}]+}/.test(templateContent)
|
|
70
|
+
|
|
71
|
+
// Compute derived properties
|
|
72
|
+
const needsHydration = hasState || hasEventHandlers || hasLifecycleHooks ||
|
|
73
|
+
usesClientFetch || hasReactiveExpressions
|
|
74
|
+
const isStatic = !needsHydration && !usesServerFetch
|
|
75
|
+
const needsSSR = usesServerFetch
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
hasState,
|
|
79
|
+
hasEventHandlers,
|
|
80
|
+
hasLifecycleHooks,
|
|
81
|
+
usesServerFetch,
|
|
82
|
+
usesClientFetch,
|
|
83
|
+
usesZenLink,
|
|
84
|
+
hasReactiveExpressions,
|
|
85
|
+
needsHydration,
|
|
86
|
+
isStatic,
|
|
87
|
+
needsSSR
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get a human-readable summary of the page analysis
|
|
93
|
+
*/
|
|
94
|
+
export function getAnalysisSummary(analysis: PageAnalysis): string {
|
|
95
|
+
const flags: string[] = []
|
|
96
|
+
|
|
97
|
+
if (analysis.isStatic) {
|
|
98
|
+
flags.push('STATIC (no JS)')
|
|
99
|
+
} else {
|
|
100
|
+
if (analysis.hasState) flags.push('state')
|
|
101
|
+
if (analysis.hasEventHandlers) flags.push('events')
|
|
102
|
+
if (analysis.hasLifecycleHooks) flags.push('lifecycle')
|
|
103
|
+
if (analysis.hasReactiveExpressions) flags.push('reactive')
|
|
104
|
+
if (analysis.usesClientFetch) flags.push('clientFetch')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (analysis.needsSSR) flags.push('SSR')
|
|
108
|
+
if (analysis.usesZenLink) flags.push('SPA')
|
|
109
|
+
|
|
110
|
+
return flags.length > 0 ? flags.join(', ') : 'minimal'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Determine build output type for a page
|
|
115
|
+
*/
|
|
116
|
+
export type BuildOutputType = 'static' | 'hydrated' | 'ssr'
|
|
117
|
+
|
|
118
|
+
export function getBuildOutputType(analysis: PageAnalysis): BuildOutputType {
|
|
119
|
+
if (analysis.needsSSR) return 'ssr'
|
|
120
|
+
if (analysis.needsHydration) return 'hydrated'
|
|
121
|
+
return 'static'
|
|
122
|
+
}
|