bimba-cli 0.7.17 → 0.7.18

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 (2) hide show
  1. package/package.json +1 -1
  2. package/serve.js +28 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.7.17",
3
+ "version": "0.7.18",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/bimba.git"
package/serve.js CHANGED
@@ -609,17 +609,35 @@ export function serve(entrypoint, flags) {
609
609
  }
610
610
 
611
611
  const _debounce = new Map()
612
+ const _watchVersion = new Map()
612
613
 
613
- watch(srcDir, { recursive: true }, async (_event, filename) => {
614
+ function scheduleCompile(filename) {
615
+ filename = filename && String(filename)
614
616
  if (!filename || !filename.endsWith('.imba')) return
615
- if (_debounce.has(filename)) return
616
- _debounce.set(filename, setTimeout(() => _debounce.delete(filename), 150))
617
617
 
618
+ const version = (_watchVersion.get(filename) || 0) + 1
619
+ _watchVersion.set(filename, version)
620
+
621
+ const pending = _debounce.get(filename)
622
+ if (pending) clearTimeout(pending)
623
+
624
+ _debounce.set(filename, setTimeout(() => {
625
+ _debounce.delete(filename)
626
+ compileChangedFile(filename, version)
627
+ }, 150))
628
+ }
629
+
630
+ function isCurrentChange(filename, version) {
631
+ return _watchVersion.get(filename) === version
632
+ }
633
+
634
+ async function compileChangedFile(filename, version) {
618
635
  const filepath = path.join(srcDir, filename)
619
636
  const rel = path.join(path.relative('.', srcDir), filename).replaceAll('\\', '/')
620
637
 
621
638
  try {
622
639
  if (!existsSync(filepath)) {
640
+ if (!isCurrentChange(filename, version)) return
623
641
  dropFileState(filepath)
624
642
  clearError(rel)
625
643
  return
@@ -627,6 +645,7 @@ export function serve(entrypoint, flags) {
627
645
 
628
646
  const out = await compileFile(filepath)
629
647
 
648
+ if (!isCurrentChange(filename, version)) return
630
649
 
631
650
  if (out.errors?.length) {
632
651
  printStatus(rel, 'fail', out.errors)
@@ -638,7 +657,7 @@ export function serve(entrypoint, flags) {
638
657
  return
639
658
  }
640
659
 
641
- clearError()
660
+ clearError(rel)
642
661
 
643
662
  // No change at all — skip
644
663
  if (out.changeType === 'none' || out.changeType === 'cached') return
@@ -646,9 +665,14 @@ export function serve(entrypoint, flags) {
646
665
  printStatus(rel, 'ok')
647
666
  broadcast({ type: 'update', file: rel, slots: out.slots || 'shifted' })
648
667
  } catch(e) {
668
+ if (!isCurrentChange(filename, version)) return
649
669
  printStatus(rel, 'fail', [{ message: e.message }])
650
670
  broadcast({ type: 'error', file: rel, errors: [{ message: e.message, snippet: e.stack || e.message }] })
651
671
  }
672
+ }
673
+
674
+ watch(srcDir, { recursive: true }, (_event, filename) => {
675
+ scheduleCompile(filename)
652
676
  })
653
677
 
654
678
  // ── HTTP + WebSocket server ────────────────────────────────────────────────