bimba-cli 0.4.4 → 0.4.6
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 +6 -3
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
|
@@ -206,7 +206,7 @@ export function serve(entrypoint, flags) {
|
|
|
206
206
|
if (errors?.length) {
|
|
207
207
|
process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}\n`)
|
|
208
208
|
for (const err of errors) {
|
|
209
|
-
printerr(err)
|
|
209
|
+
try { printerr(err) } catch(_) { process.stdout.write(' ' + err.message + '\n') }
|
|
210
210
|
}
|
|
211
211
|
} else {
|
|
212
212
|
const myId = ++_fadeId
|
|
@@ -266,7 +266,7 @@ export function serve(entrypoint, flags) {
|
|
|
266
266
|
if (out.errors?.length) {
|
|
267
267
|
if (!out.cached) {
|
|
268
268
|
printStatus(file, 'fail', out.errors)
|
|
269
|
-
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() })) })
|
|
270
270
|
for (const socket of sockets) socket.send(payload)
|
|
271
271
|
}
|
|
272
272
|
return new Response(out.errors.map(e => e.message).join('\n'), { status: 500 })
|
|
@@ -277,7 +277,10 @@ export function serve(entrypoint, flags) {
|
|
|
277
277
|
}
|
|
278
278
|
return new Response(out.js, { headers: { 'Content-Type': 'application/javascript' } })
|
|
279
279
|
} catch (e) {
|
|
280
|
-
|
|
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)
|
|
281
284
|
return new Response(e.message, { status: 500 })
|
|
282
285
|
}
|
|
283
286
|
}
|