bimba-cli 0.7.26 → 0.7.28

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 (3) hide show
  1. package/package.json +1 -1
  2. package/plugin.js +37 -7
  3. package/serve.js +5 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.7.26",
3
+ "version": "0.7.28",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/bimba.git"
package/plugin.js CHANGED
@@ -22,7 +22,7 @@ export let stats = {
22
22
  const _activeCompileErrors = new Map();
23
23
 
24
24
  function normalizeCompilePath(filepath) {
25
- let value = String(filepath || '');
25
+ let value = String(filepath || '').split(/[?#]/)[0];
26
26
  if (dir.isAbsolute(value)) {
27
27
  const rel = dir.relative(process.cwd(), value);
28
28
  if (!rel.startsWith('..')) value = rel;
@@ -30,6 +30,21 @@ function normalizeCompilePath(filepath) {
30
30
  return value.replaceAll('\\', '/');
31
31
  }
32
32
 
33
+ function physicalCompileKey(filepath) {
34
+ try {
35
+ const stat = fs.statSync(filepath);
36
+ if (!stat.isFile()) return null;
37
+ const real = fs.realpathSync(filepath).replaceAll('\\', '/');
38
+ return `fs:${stat.dev}:${stat.ino}:${real}`;
39
+ } catch(_) {
40
+ return null;
41
+ }
42
+ }
43
+
44
+ function compileErrorKey(filepath) {
45
+ return physicalCompileKey(filepath) || `path:${normalizeCompilePath(filepath)}`;
46
+ }
47
+
33
48
  function compileErrorMessage(error) {
34
49
  return error?.message || String(error);
35
50
  }
@@ -53,15 +68,25 @@ function compileErrorSignature(errors) {
53
68
  }
54
69
 
55
70
  function shouldPrintCompileError(filepath, errors) {
56
- const key = normalizeCompilePath(filepath);
71
+ const key = compileErrorKey(filepath);
57
72
  const signature = compileErrorSignature(errors);
58
73
  const previous = _activeCompileErrors.get(key);
59
- _activeCompileErrors.set(key, { signature, time: Date.now() });
74
+ _activeCompileErrors.set(key, { file: normalizeCompilePath(filepath), signature, time: Date.now() });
60
75
  return previous?.signature !== signature;
61
76
  }
62
77
 
63
78
  function clearCompileError(filepath) {
64
- _activeCompileErrors.delete(normalizeCompilePath(filepath));
79
+ _activeCompileErrors.delete(compileErrorKey(filepath));
80
+ }
81
+
82
+ function printCompileError(error) {
83
+ try {
84
+ printerr(error);
85
+ } catch(_) {
86
+ console.log('');
87
+ console.log(' ' + theme.error(' ' + compileErrorMessage(error) + ' '));
88
+ console.log('');
89
+ }
65
90
  }
66
91
 
67
92
  // Target platform for the Imba compiler: 'browser' or 'node'
@@ -98,11 +123,16 @@ export const imbaPlugin = {
98
123
  // if no cached version read and compile it with the imba compiler
99
124
  const file = await Bun.file(path).text();
100
125
  const platform = target === 'node' || target === 'bun' ? 'node' : 'browser';
101
- const out = compiler.compile(file, {
126
+ let out
127
+ try {
128
+ out = compiler.compile(file, {
102
129
  sourcePath: path,
103
130
  platform: platform,
104
131
  comments: false
105
- })
132
+ })
133
+ } catch (error) {
134
+ out = { js: '', errors: [error] }
135
+ }
106
136
 
107
137
  // the file has been successfully compiled
108
138
  if (!out.errors?.length) {
@@ -121,7 +151,7 @@ export const imbaPlugin = {
121
151
  if (shouldPrint) {
122
152
  stats.reported++;
123
153
  for (let i = 0; i < out.errors.length; i++) {
124
- if(out.errors[i]) printerr(out.errors[i]);
154
+ if(out.errors[i]) printCompileError(out.errors[i]);
125
155
  }
126
156
  }
127
157
  stats.errors++;
package/serve.js CHANGED
@@ -854,6 +854,7 @@ export function serve(entrypoint, flags) {
854
854
  const list = Array.isArray(errors) ? errors : [errors]
855
855
  const signature = errorSignature(list)
856
856
  const previous = takeError(display)
857
+ const duplicate = previous?.signature === signature
857
858
 
858
859
  const item = {
859
860
  file: display,
@@ -863,7 +864,10 @@ export function serve(entrypoint, flags) {
863
864
  time: new Date().toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' }),
864
865
  }
865
866
  _activeErrors.set(key, item)
866
- if (previous?.signature === signature && !_isTTY) {
867
+
868
+ // The terminal is append-only in many real shells. Repeated reports of the
869
+ // same active error update the browser overlay, but must not print again.
870
+ if (duplicate) {
867
871
  broadcast({ type: 'error', file: display, time: item.time, errors: item.payload })
868
872
  return
869
873
  }