bimba-cli 0.7.24 → 0.7.25
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 +61 -12
package/package.json
CHANGED
package/serve.js
CHANGED
|
@@ -219,12 +219,19 @@ const hmrClient = `
|
|
|
219
219
|
const _compileErrors = new Map();
|
|
220
220
|
|
|
221
221
|
function normalizeFile(file) {
|
|
222
|
-
let value = String(file || '').split(String.fromCharCode(92)).join('/');
|
|
222
|
+
let value = String(file || '').split(/[?#]/)[0].split(String.fromCharCode(92)).join('/');
|
|
223
223
|
while (value.startsWith('./')) value = value.slice(2);
|
|
224
224
|
while (value.startsWith('/')) value = value.slice(1);
|
|
225
225
|
return value;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
function sameFile(left, right) {
|
|
229
|
+
const a = normalizeFile(left);
|
|
230
|
+
const b = normalizeFile(right);
|
|
231
|
+
if (!a || !b) return false;
|
|
232
|
+
return a === b || a.endsWith('/' + b) || b.endsWith('/' + a);
|
|
233
|
+
}
|
|
234
|
+
|
|
228
235
|
function escapeHtml(value) {
|
|
229
236
|
return String(value ?? '').replace(/[&<>"']/g, ch => ({
|
|
230
237
|
'&': '&',
|
|
@@ -281,6 +288,9 @@ const hmrClient = `
|
|
|
281
288
|
|
|
282
289
|
function showError(file, errors, time) {
|
|
283
290
|
const displayFile = normalizeFile(file);
|
|
291
|
+
for (const key of Array.from(_compileErrors.keys())) {
|
|
292
|
+
if (sameFile(key, displayFile)) _compileErrors.delete(key);
|
|
293
|
+
}
|
|
284
294
|
_compileErrors.set(displayFile, {
|
|
285
295
|
errors: Array.isArray(errors) ? errors : [errors],
|
|
286
296
|
time: time || new Date().toLocaleTimeString(),
|
|
@@ -289,8 +299,14 @@ const hmrClient = `
|
|
|
289
299
|
}
|
|
290
300
|
|
|
291
301
|
function clearError(file) {
|
|
292
|
-
if (file)
|
|
293
|
-
|
|
302
|
+
if (file) {
|
|
303
|
+
const displayFile = normalizeFile(file);
|
|
304
|
+
for (const key of Array.from(_compileErrors.keys())) {
|
|
305
|
+
if (sameFile(key, displayFile)) _compileErrors.delete(key);
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
_compileErrors.clear();
|
|
309
|
+
}
|
|
294
310
|
renderErrors();
|
|
295
311
|
}
|
|
296
312
|
|
|
@@ -708,6 +724,7 @@ export function serve(entrypoint, flags) {
|
|
|
708
724
|
|
|
709
725
|
function normalizeFile(file) {
|
|
710
726
|
let value = String(file || '')
|
|
727
|
+
value = value.split(/[?#]/)[0]
|
|
711
728
|
if (path.isAbsolute(value)) {
|
|
712
729
|
const rel = path.relative(process.cwd(), value)
|
|
713
730
|
if (!rel.startsWith('..')) value = rel
|
|
@@ -721,6 +738,40 @@ export function serve(entrypoint, flags) {
|
|
|
721
738
|
const srcRoot = path.resolve(srcDir)
|
|
722
739
|
const srcRel = normalizeFile(srcRoot)
|
|
723
740
|
|
|
741
|
+
function fileVariants(file) {
|
|
742
|
+
const key = normalizeFile(file)
|
|
743
|
+
const variants = new Set([key])
|
|
744
|
+
|
|
745
|
+
if (srcRel && key.startsWith(srcRel + '/')) variants.add(key.slice(srcRel.length + 1))
|
|
746
|
+
else if (srcRel && key) variants.add(srcRel + '/' + key)
|
|
747
|
+
|
|
748
|
+
return Array.from(variants).filter(Boolean)
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function sameFile(left, right) {
|
|
752
|
+
const lefts = fileVariants(left)
|
|
753
|
+
const rights = fileVariants(right)
|
|
754
|
+
|
|
755
|
+
for (const a of lefts) {
|
|
756
|
+
for (const b of rights) {
|
|
757
|
+
if (a === b || a.endsWith('/' + b) || b.endsWith('/' + a)) return true
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
return false
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function takeError(file) {
|
|
765
|
+
let previous = null
|
|
766
|
+
const keys = Array.from(_activeErrors.keys())
|
|
767
|
+
for (const key of keys) {
|
|
768
|
+
if (!sameFile(key, file)) continue
|
|
769
|
+
previous ||= _activeErrors.get(key)
|
|
770
|
+
_activeErrors.delete(key)
|
|
771
|
+
}
|
|
772
|
+
return previous
|
|
773
|
+
}
|
|
774
|
+
|
|
724
775
|
function errorMessage(error) {
|
|
725
776
|
return error?.message || String(error)
|
|
726
777
|
}
|
|
@@ -761,7 +812,7 @@ export function serve(entrypoint, flags) {
|
|
|
761
812
|
const key = normalizeFile(file)
|
|
762
813
|
const list = Array.isArray(errors) ? errors : [errors]
|
|
763
814
|
const signature = errorSignature(list)
|
|
764
|
-
const previous =
|
|
815
|
+
const previous = takeError(key)
|
|
765
816
|
|
|
766
817
|
const item = {
|
|
767
818
|
signature,
|
|
@@ -790,18 +841,16 @@ export function serve(entrypoint, flags) {
|
|
|
790
841
|
|
|
791
842
|
function clearError(file) {
|
|
792
843
|
const key = file ? normalizeFile(file) : null
|
|
793
|
-
const
|
|
794
|
-
const
|
|
844
|
+
const hadPanel = _statusKind === 'errors'
|
|
845
|
+
const wasStatusFile = key && _statusFile && sameFile(_statusFile, key)
|
|
846
|
+
const hadError = key ? !!takeError(key) : _activeErrors.size > 0
|
|
795
847
|
|
|
796
|
-
if (key) _activeErrors.
|
|
797
|
-
else _activeErrors.clear()
|
|
798
|
-
|
|
799
|
-
if (key && !hadError && !wasStatusFile) return
|
|
848
|
+
if (!key) _activeErrors.clear()
|
|
800
849
|
|
|
801
850
|
let showedNext = false
|
|
802
|
-
if (_isTTY && (hadError ||
|
|
851
|
+
if (_isTTY && (hadError || wasStatusFile || hadPanel)) {
|
|
803
852
|
showedNext = renderErrorPanel()
|
|
804
|
-
} else {
|
|
853
|
+
} else if (!key || hadError || wasStatusFile) {
|
|
805
854
|
clearStatus(key)
|
|
806
855
|
}
|
|
807
856
|
|