bimba-cli 0.5.12 → 0.5.13
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 +1 -1
- package/serve.js +25 -9
package/package.json
CHANGED
package/serve.js
CHANGED
|
@@ -385,6 +385,19 @@ function stabilizeSymbols(js, filepath) {
|
|
|
385
385
|
return { js: bootstrap + out, slotCount: count }
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
+
// Imba's compile result puts `errors` on the prototype as a getter, so plain
|
|
389
|
+
// object spread (`{...result}`) silently strips it. We always normalize to a
|
|
390
|
+
// plain shape with `errors` as an own property — otherwise downstream callers
|
|
391
|
+
// see no errors and serve empty 200s for broken files.
|
|
392
|
+
function _normalizeResult(result, extras) {
|
|
393
|
+
return {
|
|
394
|
+
js: result.js,
|
|
395
|
+
errors: result.errors || [],
|
|
396
|
+
slots: result.slots,
|
|
397
|
+
...extras,
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
388
401
|
async function compileFile(filepath) {
|
|
389
402
|
const abs = path.resolve(filepath)
|
|
390
403
|
const file = Bun.file(filepath)
|
|
@@ -392,7 +405,7 @@ async function compileFile(filepath) {
|
|
|
392
405
|
const mtime = stat.mtime.getTime()
|
|
393
406
|
|
|
394
407
|
const cached = _compileCache.get(abs)
|
|
395
|
-
if (cached && cached.mtime === mtime) return
|
|
408
|
+
if (cached && cached.mtime === mtime) return _normalizeResult(cached.result, { changeType: 'cached' })
|
|
396
409
|
|
|
397
410
|
const code = await file.text()
|
|
398
411
|
const result = compiler.compile(code, {
|
|
@@ -401,19 +414,22 @@ async function compileFile(filepath) {
|
|
|
401
414
|
sourcemap: 'inline',
|
|
402
415
|
})
|
|
403
416
|
|
|
404
|
-
|
|
417
|
+
const errors = result.errors || []
|
|
418
|
+
if (!errors.length && result.js) {
|
|
405
419
|
const { js, slotCount } = stabilizeSymbols(result.js, filepath)
|
|
406
420
|
result.js = js
|
|
407
|
-
const prev = _prevSlots.get(
|
|
421
|
+
const prev = _prevSlots.get(abs)
|
|
408
422
|
result.slots = (prev === undefined || prev === slotCount) ? 'stable' : 'shifted'
|
|
409
|
-
_prevSlots.set(
|
|
423
|
+
_prevSlots.set(abs, slotCount)
|
|
410
424
|
updateImportGraph(abs, extractImports(js, abs))
|
|
411
425
|
}
|
|
412
426
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
427
|
+
// Bake errors as an own property so caching/spreading preserves them.
|
|
428
|
+
const baked = { js: result.js, errors, slots: result.slots }
|
|
429
|
+
const changeType = _prevJs.get(abs) === baked.js ? 'none' : 'full'
|
|
430
|
+
_prevJs.set(abs, baked.js)
|
|
431
|
+
_compileCache.set(abs, { mtime, result: baked })
|
|
432
|
+
return _normalizeResult(baked, { changeType })
|
|
417
433
|
}
|
|
418
434
|
|
|
419
435
|
// ─── HTML helpers ─────────────────────────────────────────────────────────────
|
|
@@ -580,7 +596,7 @@ export function serve(entrypoint, flags) {
|
|
|
580
596
|
for (const upAbs of ups) {
|
|
581
597
|
const upRel = path.relative('.', upAbs).replaceAll('\\', '/')
|
|
582
598
|
const cached = _compileCache.get(upAbs)
|
|
583
|
-
const slots = cached?.slots || 'shifted'
|
|
599
|
+
const slots = cached?.result?.slots || 'shifted'
|
|
584
600
|
broadcast({ type: 'update', file: upRel, slots })
|
|
585
601
|
}
|
|
586
602
|
} catch(e) {
|