bimba-cli 0.4.7 → 0.4.8
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/plugin.js +15 -5
- package/serve.js +15 -20
package/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -89,18 +89,28 @@ plugin(imbaPlugin);
|
|
|
89
89
|
|
|
90
90
|
// print an error generated by the imba compiler
|
|
91
91
|
export function printerr(err) {
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
// halper function to produce empty strings
|
|
94
94
|
const fill = (len = 0) => {return new Array(len + 1).join(' ')}
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
|
|
96
|
+
// gather the needed information from the compiler error
|
|
97
97
|
const snippet = err.toSnippet().split("\n");
|
|
98
|
+
const errs = snippet[2] ? snippet[2].indexOf('^') : -1;
|
|
99
|
+
|
|
100
|
+
// no source context available — print compact fallback
|
|
101
|
+
if (!snippet[1] || errs === -1) {
|
|
102
|
+
console.log('');
|
|
103
|
+
console.log(fill(10) + theme.error(" " + err.message + " "));
|
|
104
|
+
console.log('');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
98
108
|
const display = {
|
|
99
109
|
error: " " + err.message + " ",
|
|
100
110
|
outdent: fill(10),
|
|
101
111
|
source: snippet[1] + " ",
|
|
102
|
-
margin: " line " + err.range.start.line + " ",
|
|
103
|
-
errs:
|
|
112
|
+
margin: " line " + (err.range.start.line + 1) + " ",
|
|
113
|
+
errs: errs,
|
|
104
114
|
erre: snippet[2].lastIndexOf('^') + 1,
|
|
105
115
|
};
|
|
106
116
|
|
package/serve.js
CHANGED
|
@@ -184,10 +184,9 @@ export function serve(entrypoint, flags) {
|
|
|
184
184
|
const sockets = new Set()
|
|
185
185
|
let importMapTag = null
|
|
186
186
|
|
|
187
|
-
let _lastLines = 0
|
|
188
187
|
let _fadeTimers = []
|
|
189
188
|
let _fadeId = 0
|
|
190
|
-
let
|
|
189
|
+
let _statusSaved = false
|
|
191
190
|
|
|
192
191
|
function cancelFade() {
|
|
193
192
|
_fadeTimers.forEach(t => clearTimeout(t))
|
|
@@ -196,22 +195,18 @@ export function serve(entrypoint, flags) {
|
|
|
196
195
|
|
|
197
196
|
function printStatus(file, state, errors) {
|
|
198
197
|
cancelFade()
|
|
199
|
-
if (
|
|
200
|
-
process.stdout.write('\x1b[
|
|
201
|
-
|
|
202
|
-
_cursorOnLine = false
|
|
203
|
-
} else if (_lastLines > 0) {
|
|
204
|
-
process.stdout.write(`\x1b[${_lastLines}A\x1b[J`)
|
|
205
|
-
_lastLines = 0
|
|
198
|
+
if (_statusSaved) {
|
|
199
|
+
process.stdout.write('\x1b[u\x1b[J')
|
|
200
|
+
_statusSaved = false
|
|
206
201
|
}
|
|
207
202
|
const now = new Date().toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
|
208
203
|
const status = state === 'ok' ? theme.success(' ok ') : theme.failure(' fail ')
|
|
204
|
+
process.stdout.write('\x1b[s')
|
|
205
|
+
_statusSaved = true
|
|
209
206
|
if (errors?.length) {
|
|
210
207
|
process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}\n`)
|
|
211
|
-
_lastLines = 1
|
|
212
208
|
for (const err of errors) {
|
|
213
|
-
printerr(err)
|
|
214
|
-
_lastLines += 5
|
|
209
|
+
try { printerr(err) } catch(_) { process.stdout.write(' ' + err.message + '\n') }
|
|
215
210
|
}
|
|
216
211
|
} else {
|
|
217
212
|
const myId = ++_fadeId
|
|
@@ -221,16 +216,13 @@ export function serve(entrypoint, flags) {
|
|
|
221
216
|
const charDelay = 22
|
|
222
217
|
|
|
223
218
|
process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}`)
|
|
224
|
-
_lastLines = 1
|
|
225
|
-
_cursorOnLine = true
|
|
226
219
|
|
|
227
220
|
for (let i = 1; i <= totalLen; i++) {
|
|
228
221
|
_fadeTimers.push(setTimeout(() => {
|
|
229
|
-
if (_fadeId !== myId
|
|
230
|
-
process.stdout.write('\x1b[1D\x1b[
|
|
222
|
+
if (_fadeId !== myId) return
|
|
223
|
+
process.stdout.write('\x1b[1D \x1b[1D')
|
|
231
224
|
if (i === totalLen) {
|
|
232
|
-
|
|
233
|
-
_cursorOnLine = false
|
|
225
|
+
_statusSaved = false
|
|
234
226
|
}
|
|
235
227
|
}, startDelay + i * charDelay))
|
|
236
228
|
}
|
|
@@ -274,7 +266,7 @@ export function serve(entrypoint, flags) {
|
|
|
274
266
|
if (out.errors?.length) {
|
|
275
267
|
if (!out.cached) {
|
|
276
268
|
printStatus(file, 'fail', out.errors)
|
|
277
|
-
const payload = JSON.stringify({ type: 'error', file, errors: out.errors.map(e => ({ message: e.message, line: e.range?.start?.line, snippet: e.toSnippet() })) })
|
|
269
|
+
const payload = JSON.stringify({ type: 'error', file, errors: out.errors.map(e => ({ message: e.message, line: e.range?.start?.line, snippet: e.toSnippet().split('\n').slice(1).join('\n').trim() })) })
|
|
278
270
|
for (const socket of sockets) socket.send(payload)
|
|
279
271
|
}
|
|
280
272
|
return new Response(out.errors.map(e => e.message).join('\n'), { status: 500 })
|
|
@@ -285,7 +277,10 @@ export function serve(entrypoint, flags) {
|
|
|
285
277
|
}
|
|
286
278
|
return new Response(out.js, { headers: { 'Content-Type': 'application/javascript' } })
|
|
287
279
|
} catch (e) {
|
|
288
|
-
|
|
280
|
+
const file = pathname.replace(/^\//, '')
|
|
281
|
+
printStatus(file, 'fail', [{ message: e.message }])
|
|
282
|
+
const payload = JSON.stringify({ type: 'error', file, errors: [{ message: e.message }] })
|
|
283
|
+
for (const socket of sockets) socket.send(payload)
|
|
289
284
|
return new Response(e.message, { status: 500 })
|
|
290
285
|
}
|
|
291
286
|
}
|