bimba-cli 0.7.22 → 0.7.23
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 +41 -21
package/package.json
CHANGED
package/serve.js
CHANGED
|
@@ -265,7 +265,7 @@ const hmrClient = `
|
|
|
265
265
|
|
|
266
266
|
// ─── Server-side compile cache ────────────────────────────────────────────────
|
|
267
267
|
|
|
268
|
-
const _compileCache = new Map() // filepath → {
|
|
268
|
+
const _compileCache = new Map() // filepath → { stamp, result }
|
|
269
269
|
const _prevJs = new Map() // filepath → compiled js — for change detection
|
|
270
270
|
const _prevSlots = new Map() // filepath → previous symbol slot count
|
|
271
271
|
const _importScanner = new Bun.Transpiler({ loader: 'js' })
|
|
@@ -367,7 +367,7 @@ async function compileFile(filepath) {
|
|
|
367
367
|
const abs = path.resolve(filepath)
|
|
368
368
|
if (!existsSync(abs)) return missingCompileResult(abs)
|
|
369
369
|
|
|
370
|
-
const file = Bun.file(
|
|
370
|
+
const file = Bun.file(abs)
|
|
371
371
|
let stat
|
|
372
372
|
try {
|
|
373
373
|
stat = await file.stat()
|
|
@@ -375,10 +375,10 @@ async function compileFile(filepath) {
|
|
|
375
375
|
if (isMissingFileError(error)) return missingCompileResult(abs)
|
|
376
376
|
throw error
|
|
377
377
|
}
|
|
378
|
-
const
|
|
378
|
+
const stamp = `${stat.mtimeMs ?? stat.mtime?.getTime?.() ?? 0}:${stat.size ?? 0}`
|
|
379
379
|
|
|
380
380
|
const cached = _compileCache.get(abs)
|
|
381
|
-
if (cached && cached.
|
|
381
|
+
if (cached && cached.stamp === stamp) return _normalizeResult(cached.result, { changeType: 'cached' })
|
|
382
382
|
|
|
383
383
|
let code
|
|
384
384
|
try {
|
|
@@ -406,7 +406,7 @@ async function compileFile(filepath) {
|
|
|
406
406
|
const baked = { js: result.js, errors, slots: result.slots }
|
|
407
407
|
const changeType = _prevJs.get(abs) === baked.js ? 'none' : 'full'
|
|
408
408
|
_prevJs.set(abs, baked.js)
|
|
409
|
-
_compileCache.set(abs, {
|
|
409
|
+
_compileCache.set(abs, { stamp, result: baked })
|
|
410
410
|
return _normalizeResult(baked, { changeType })
|
|
411
411
|
}
|
|
412
412
|
|
|
@@ -652,6 +652,9 @@ export function serve(entrypoint, flags) {
|
|
|
652
652
|
return value
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
+
const srcRoot = path.resolve(srcDir)
|
|
656
|
+
const srcRel = normalizeFile(srcRoot)
|
|
657
|
+
|
|
655
658
|
function errorMessage(error) {
|
|
656
659
|
return error?.message || String(error)
|
|
657
660
|
}
|
|
@@ -752,33 +755,50 @@ export function serve(entrypoint, flags) {
|
|
|
752
755
|
const _debounce = new Map()
|
|
753
756
|
const _watchVersion = new Map()
|
|
754
757
|
|
|
755
|
-
function
|
|
758
|
+
function watchedFile(filename) {
|
|
756
759
|
filename = filename && String(filename)
|
|
757
|
-
if (!filename
|
|
760
|
+
if (!filename) return null
|
|
761
|
+
|
|
762
|
+
let filepath
|
|
763
|
+
if (path.isAbsolute(filename)) {
|
|
764
|
+
filepath = path.resolve(filename)
|
|
765
|
+
} else {
|
|
766
|
+
const rel = normalizeFile(filename)
|
|
767
|
+
filepath = (rel === srcRel || rel.startsWith(srcRel + '/'))
|
|
768
|
+
? path.resolve(filename)
|
|
769
|
+
: path.resolve(srcRoot, filename)
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const rel = normalizeFile(filepath)
|
|
773
|
+
return { filepath, rel }
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function scheduleCompile(filename) {
|
|
777
|
+
const file = watchedFile(filename)
|
|
778
|
+
if (!file || !file.rel.endsWith('.imba')) return
|
|
758
779
|
|
|
759
|
-
const version = (_watchVersion.get(
|
|
760
|
-
_watchVersion.set(
|
|
780
|
+
const version = (_watchVersion.get(file.rel) || 0) + 1
|
|
781
|
+
_watchVersion.set(file.rel, version)
|
|
761
782
|
|
|
762
|
-
const pending = _debounce.get(
|
|
783
|
+
const pending = _debounce.get(file.rel)
|
|
763
784
|
if (pending) clearTimeout(pending)
|
|
764
785
|
|
|
765
|
-
_debounce.set(
|
|
766
|
-
_debounce.delete(
|
|
767
|
-
compileChangedFile(
|
|
786
|
+
_debounce.set(file.rel, setTimeout(() => {
|
|
787
|
+
_debounce.delete(file.rel)
|
|
788
|
+
compileChangedFile(file, version)
|
|
768
789
|
}, 150))
|
|
769
790
|
}
|
|
770
791
|
|
|
771
|
-
function isCurrentChange(
|
|
772
|
-
return _watchVersion.get(
|
|
792
|
+
function isCurrentChange(file, version) {
|
|
793
|
+
return _watchVersion.get(file.rel) === version
|
|
773
794
|
}
|
|
774
795
|
|
|
775
|
-
async function compileChangedFile(
|
|
776
|
-
const filepath =
|
|
777
|
-
const rel = normalizeFile(path.join(path.relative('.', srcDir), filename))
|
|
796
|
+
async function compileChangedFile(file, version) {
|
|
797
|
+
const { filepath, rel } = file
|
|
778
798
|
|
|
779
799
|
try {
|
|
780
800
|
if (!existsSync(filepath)) {
|
|
781
|
-
if (!isCurrentChange(
|
|
801
|
+
if (!isCurrentChange(file, version)) return
|
|
782
802
|
dropFileState(filepath)
|
|
783
803
|
clearError(rel)
|
|
784
804
|
return
|
|
@@ -786,7 +806,7 @@ export function serve(entrypoint, flags) {
|
|
|
786
806
|
|
|
787
807
|
const out = await compileFile(filepath)
|
|
788
808
|
|
|
789
|
-
if (!isCurrentChange(
|
|
809
|
+
if (!isCurrentChange(file, version)) return
|
|
790
810
|
if (out.missing) {
|
|
791
811
|
clearError(rel)
|
|
792
812
|
return
|
|
@@ -805,7 +825,7 @@ export function serve(entrypoint, flags) {
|
|
|
805
825
|
if (!success.printed && !success.showedNext) printStatus(rel, 'ok')
|
|
806
826
|
broadcast({ type: 'update', file: rel, slots: out.slots || 'shifted' })
|
|
807
827
|
} catch(e) {
|
|
808
|
-
if (!isCurrentChange(
|
|
828
|
+
if (!isCurrentChange(file, version)) return
|
|
809
829
|
if (isMissingFileError(e)) {
|
|
810
830
|
dropFileState(filepath)
|
|
811
831
|
clearError(rel)
|