@zenithbuild/core 1.3.18 → 1.3.20
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/cli/commands/dev.ts +32 -9
- package/package.json +1 -1
package/cli/commands/dev.ts
CHANGED
|
@@ -219,14 +219,15 @@ export async function dev(options: DevOptions = {}): Promise<void> {
|
|
|
219
219
|
// Remove lines from top that are imports, whitespace, or comments
|
|
220
220
|
while (jsLines.length > 0 && jsLines[0] !== undefined) {
|
|
221
221
|
const line = jsLines[0].trim()
|
|
222
|
-
if (
|
|
223
|
-
line.startsWith('import ') ||
|
|
224
|
-
line === '' ||
|
|
225
|
-
line.startsWith('//') ||
|
|
226
|
-
line.startsWith('/*') ||
|
|
227
|
-
line.startsWith('*')
|
|
228
|
-
) {
|
|
222
|
+
if (line === '' || line.startsWith('//') || line.startsWith('/*') || line.startsWith('*')) {
|
|
229
223
|
jsLines.shift()
|
|
224
|
+
} else if (line.startsWith('import ')) {
|
|
225
|
+
// Handle multiline imports: consume until we find a semicolon or empty line
|
|
226
|
+
let currentLine = jsLines.shift() || ''
|
|
227
|
+
while (!currentLine.trim().endsWith(';') && jsLines.length > 0) {
|
|
228
|
+
const nextPart = jsLines.shift() || ''
|
|
229
|
+
currentLine += ' ' + nextPart
|
|
230
|
+
}
|
|
230
231
|
} else {
|
|
231
232
|
break
|
|
232
233
|
}
|
|
@@ -234,8 +235,23 @@ export async function dev(options: DevOptions = {}): Promise<void> {
|
|
|
234
235
|
|
|
235
236
|
let jsWithoutImports = jsLines.join('\n')
|
|
236
237
|
|
|
238
|
+
const ZEN_RUNTIME_IMPORTS = [
|
|
239
|
+
'import {',
|
|
240
|
+
' signal as zenSignal,',
|
|
241
|
+
' state as zenState,',
|
|
242
|
+
' effect as zenEffect,',
|
|
243
|
+
' memo as zenMemo,',
|
|
244
|
+
' ref as zenRef,',
|
|
245
|
+
' onMount as zenOnMount,',
|
|
246
|
+
' onUnmount as zenOnUnmount,',
|
|
247
|
+
' batch as zenBatch,',
|
|
248
|
+
' untrack as zenUntrack',
|
|
249
|
+
'} from "@zenithbuild/runtime";'
|
|
250
|
+
].join('\n');
|
|
251
|
+
|
|
237
252
|
// Combine: structured imports first, then cleaned script body
|
|
238
|
-
|
|
253
|
+
// We inject runtime imports manually because npmImports excludes them
|
|
254
|
+
const fullScript = ZEN_RUNTIME_IMPORTS + '\n\n' + (result.finalized.npmImports || '') + '\n\n' + jsWithoutImports
|
|
239
255
|
|
|
240
256
|
logger.debug(`Page Imports: ${result.finalized.npmImports ? result.finalized.npmImports.split('\n').length : 0} lines`)
|
|
241
257
|
|
|
@@ -274,8 +290,15 @@ export async function dev(options: DevOptions = {}): Promise<void> {
|
|
|
274
290
|
// Runtime MUST be a regular script (not module) to execute synchronously
|
|
275
291
|
// before the page module script runs and needs its globals
|
|
276
292
|
const runtimeTag = `<script src="/runtime.js"></script>`
|
|
293
|
+
const importMap = `<script type="importmap">
|
|
294
|
+
{
|
|
295
|
+
"imports": {
|
|
296
|
+
"@zenithbuild/runtime": "/runtime.js"
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
</script>`
|
|
277
300
|
const scriptTag = `<script type="module">\n${page.script}\n</script>`
|
|
278
|
-
const allScripts = `${runtimeTag}\n${scriptTag}`
|
|
301
|
+
const allScripts = `${importMap}\n${runtimeTag}\n${scriptTag}`
|
|
279
302
|
|
|
280
303
|
let html = page.html;
|
|
281
304
|
if (html.includes('</head>')) {
|