nanos-lint 2.2.1 → 2.4.0

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.
@@ -2,7 +2,7 @@ import { fileURLToPath } from "node:url";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import os from "node:os";
5
- import childProcess, { execFile } from "node:child_process";
5
+ import childProcess, { execFile, execFileSync } from "node:child_process";
6
6
  import { promisify, stripVTControlCharacters } from "node:util";
7
7
  import { EventEmitter } from "node:events";
8
8
  import process$1 from "node:process";
@@ -31,6 +31,754 @@ function fileUriToPath(uri) {
31
31
  }
32
32
  }
33
33
  //#endregion
34
+ //#region node_modules/jsonc-parser/lib/esm/impl/scanner.js
35
+ /**
36
+ * Creates a JSON scanner on the given text.
37
+ * If ignoreTrivia is set, whitespaces or comments are ignored.
38
+ */
39
+ function createScanner(text, ignoreTrivia = false) {
40
+ const len = text.length;
41
+ let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
42
+ function scanHexDigits(count, exact) {
43
+ let digits = 0;
44
+ let value = 0;
45
+ while (digits < count || !exact) {
46
+ let ch = text.charCodeAt(pos);
47
+ if (ch >= 48 && ch <= 57) value = value * 16 + ch - 48;
48
+ else if (ch >= 65 && ch <= 70) value = value * 16 + ch - 65 + 10;
49
+ else if (ch >= 97 && ch <= 102) value = value * 16 + ch - 97 + 10;
50
+ else break;
51
+ pos++;
52
+ digits++;
53
+ }
54
+ if (digits < count) value = -1;
55
+ return value;
56
+ }
57
+ function setPosition(newPosition) {
58
+ pos = newPosition;
59
+ value = "";
60
+ tokenOffset = 0;
61
+ token = 16;
62
+ scanError = 0;
63
+ }
64
+ function scanNumber() {
65
+ let start = pos;
66
+ if (text.charCodeAt(pos) === 48) pos++;
67
+ else {
68
+ pos++;
69
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
70
+ }
71
+ if (pos < text.length && text.charCodeAt(pos) === 46) {
72
+ pos++;
73
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
74
+ pos++;
75
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
76
+ } else {
77
+ scanError = 3;
78
+ return text.substring(start, pos);
79
+ }
80
+ }
81
+ let end = pos;
82
+ if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
83
+ pos++;
84
+ if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) pos++;
85
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
86
+ pos++;
87
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
88
+ end = pos;
89
+ } else scanError = 3;
90
+ }
91
+ return text.substring(start, end);
92
+ }
93
+ function scanString() {
94
+ let result = "", start = pos;
95
+ while (true) {
96
+ if (pos >= len) {
97
+ result += text.substring(start, pos);
98
+ scanError = 2;
99
+ break;
100
+ }
101
+ const ch = text.charCodeAt(pos);
102
+ if (ch === 34) {
103
+ result += text.substring(start, pos);
104
+ pos++;
105
+ break;
106
+ }
107
+ if (ch === 92) {
108
+ result += text.substring(start, pos);
109
+ pos++;
110
+ if (pos >= len) {
111
+ scanError = 2;
112
+ break;
113
+ }
114
+ switch (text.charCodeAt(pos++)) {
115
+ case 34:
116
+ result += "\"";
117
+ break;
118
+ case 92:
119
+ result += "\\";
120
+ break;
121
+ case 47:
122
+ result += "/";
123
+ break;
124
+ case 98:
125
+ result += "\b";
126
+ break;
127
+ case 102:
128
+ result += "\f";
129
+ break;
130
+ case 110:
131
+ result += "\n";
132
+ break;
133
+ case 114:
134
+ result += "\r";
135
+ break;
136
+ case 116:
137
+ result += " ";
138
+ break;
139
+ case 117:
140
+ const ch3 = scanHexDigits(4, true);
141
+ if (ch3 >= 0) result += String.fromCharCode(ch3);
142
+ else scanError = 4;
143
+ break;
144
+ default: scanError = 5;
145
+ }
146
+ start = pos;
147
+ continue;
148
+ }
149
+ if (ch >= 0 && ch <= 31) {
150
+ if (isLineBreak(ch)) {
151
+ result += text.substring(start, pos);
152
+ scanError = 2;
153
+ break;
154
+ } else scanError = 6;
155
+ }
156
+ pos++;
157
+ }
158
+ return result;
159
+ }
160
+ function scanNext() {
161
+ value = "";
162
+ scanError = 0;
163
+ tokenOffset = pos;
164
+ lineStartOffset = lineNumber;
165
+ prevTokenLineStartOffset = tokenLineStartOffset;
166
+ if (pos >= len) {
167
+ tokenOffset = len;
168
+ return token = 17;
169
+ }
170
+ let code = text.charCodeAt(pos);
171
+ if (isWhiteSpace(code)) {
172
+ do {
173
+ pos++;
174
+ value += String.fromCharCode(code);
175
+ code = text.charCodeAt(pos);
176
+ } while (isWhiteSpace(code));
177
+ return token = 15;
178
+ }
179
+ if (isLineBreak(code)) {
180
+ pos++;
181
+ value += String.fromCharCode(code);
182
+ if (code === 13 && text.charCodeAt(pos) === 10) {
183
+ pos++;
184
+ value += "\n";
185
+ }
186
+ lineNumber++;
187
+ tokenLineStartOffset = pos;
188
+ return token = 14;
189
+ }
190
+ switch (code) {
191
+ case 123:
192
+ pos++;
193
+ return token = 1;
194
+ case 125:
195
+ pos++;
196
+ return token = 2;
197
+ case 91:
198
+ pos++;
199
+ return token = 3;
200
+ case 93:
201
+ pos++;
202
+ return token = 4;
203
+ case 58:
204
+ pos++;
205
+ return token = 6;
206
+ case 44:
207
+ pos++;
208
+ return token = 5;
209
+ case 34:
210
+ pos++;
211
+ value = scanString();
212
+ return token = 10;
213
+ case 47:
214
+ const start = pos - 1;
215
+ if (text.charCodeAt(pos + 1) === 47) {
216
+ pos += 2;
217
+ while (pos < len) {
218
+ if (isLineBreak(text.charCodeAt(pos))) break;
219
+ pos++;
220
+ }
221
+ value = text.substring(start, pos);
222
+ return token = 12;
223
+ }
224
+ if (text.charCodeAt(pos + 1) === 42) {
225
+ pos += 2;
226
+ const safeLength = len - 1;
227
+ let commentClosed = false;
228
+ while (pos < safeLength) {
229
+ const ch = text.charCodeAt(pos);
230
+ if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
231
+ pos += 2;
232
+ commentClosed = true;
233
+ break;
234
+ }
235
+ pos++;
236
+ if (isLineBreak(ch)) {
237
+ if (ch === 13 && text.charCodeAt(pos) === 10) pos++;
238
+ lineNumber++;
239
+ tokenLineStartOffset = pos;
240
+ }
241
+ }
242
+ if (!commentClosed) {
243
+ pos++;
244
+ scanError = 1;
245
+ }
246
+ value = text.substring(start, pos);
247
+ return token = 13;
248
+ }
249
+ value += String.fromCharCode(code);
250
+ pos++;
251
+ return token = 16;
252
+ case 45:
253
+ value += String.fromCharCode(code);
254
+ pos++;
255
+ if (pos === len || !isDigit(text.charCodeAt(pos))) return token = 16;
256
+ case 48:
257
+ case 49:
258
+ case 50:
259
+ case 51:
260
+ case 52:
261
+ case 53:
262
+ case 54:
263
+ case 55:
264
+ case 56:
265
+ case 57:
266
+ value += scanNumber();
267
+ return token = 11;
268
+ default:
269
+ while (pos < len && isUnknownContentCharacter(code)) {
270
+ pos++;
271
+ code = text.charCodeAt(pos);
272
+ }
273
+ if (tokenOffset !== pos) {
274
+ value = text.substring(tokenOffset, pos);
275
+ switch (value) {
276
+ case "true": return token = 8;
277
+ case "false": return token = 9;
278
+ case "null": return token = 7;
279
+ }
280
+ return token = 16;
281
+ }
282
+ value += String.fromCharCode(code);
283
+ pos++;
284
+ return token = 16;
285
+ }
286
+ }
287
+ function isUnknownContentCharacter(code) {
288
+ if (isWhiteSpace(code) || isLineBreak(code)) return false;
289
+ switch (code) {
290
+ case 125:
291
+ case 93:
292
+ case 123:
293
+ case 91:
294
+ case 34:
295
+ case 58:
296
+ case 44:
297
+ case 47: return false;
298
+ }
299
+ return true;
300
+ }
301
+ function scanNextNonTrivia() {
302
+ let result;
303
+ do
304
+ result = scanNext();
305
+ while (result >= 12 && result <= 15);
306
+ return result;
307
+ }
308
+ return {
309
+ setPosition,
310
+ getPosition: () => pos,
311
+ scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
312
+ getToken: () => token,
313
+ getTokenValue: () => value,
314
+ getTokenOffset: () => tokenOffset,
315
+ getTokenLength: () => pos - tokenOffset,
316
+ getTokenStartLine: () => lineStartOffset,
317
+ getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
318
+ getTokenError: () => scanError
319
+ };
320
+ }
321
+ function isWhiteSpace(ch) {
322
+ return ch === 32 || ch === 9;
323
+ }
324
+ function isLineBreak(ch) {
325
+ return ch === 10 || ch === 13;
326
+ }
327
+ function isDigit(ch) {
328
+ return ch >= 48 && ch <= 57;
329
+ }
330
+ var CharacterCodes;
331
+ (function(CharacterCodes) {
332
+ CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
333
+ CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
334
+ CharacterCodes[CharacterCodes["space"] = 32] = "space";
335
+ CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
336
+ CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
337
+ CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
338
+ CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
339
+ CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
340
+ CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
341
+ CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
342
+ CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
343
+ CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
344
+ CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
345
+ CharacterCodes[CharacterCodes["a"] = 97] = "a";
346
+ CharacterCodes[CharacterCodes["b"] = 98] = "b";
347
+ CharacterCodes[CharacterCodes["c"] = 99] = "c";
348
+ CharacterCodes[CharacterCodes["d"] = 100] = "d";
349
+ CharacterCodes[CharacterCodes["e"] = 101] = "e";
350
+ CharacterCodes[CharacterCodes["f"] = 102] = "f";
351
+ CharacterCodes[CharacterCodes["g"] = 103] = "g";
352
+ CharacterCodes[CharacterCodes["h"] = 104] = "h";
353
+ CharacterCodes[CharacterCodes["i"] = 105] = "i";
354
+ CharacterCodes[CharacterCodes["j"] = 106] = "j";
355
+ CharacterCodes[CharacterCodes["k"] = 107] = "k";
356
+ CharacterCodes[CharacterCodes["l"] = 108] = "l";
357
+ CharacterCodes[CharacterCodes["m"] = 109] = "m";
358
+ CharacterCodes[CharacterCodes["n"] = 110] = "n";
359
+ CharacterCodes[CharacterCodes["o"] = 111] = "o";
360
+ CharacterCodes[CharacterCodes["p"] = 112] = "p";
361
+ CharacterCodes[CharacterCodes["q"] = 113] = "q";
362
+ CharacterCodes[CharacterCodes["r"] = 114] = "r";
363
+ CharacterCodes[CharacterCodes["s"] = 115] = "s";
364
+ CharacterCodes[CharacterCodes["t"] = 116] = "t";
365
+ CharacterCodes[CharacterCodes["u"] = 117] = "u";
366
+ CharacterCodes[CharacterCodes["v"] = 118] = "v";
367
+ CharacterCodes[CharacterCodes["w"] = 119] = "w";
368
+ CharacterCodes[CharacterCodes["x"] = 120] = "x";
369
+ CharacterCodes[CharacterCodes["y"] = 121] = "y";
370
+ CharacterCodes[CharacterCodes["z"] = 122] = "z";
371
+ CharacterCodes[CharacterCodes["A"] = 65] = "A";
372
+ CharacterCodes[CharacterCodes["B"] = 66] = "B";
373
+ CharacterCodes[CharacterCodes["C"] = 67] = "C";
374
+ CharacterCodes[CharacterCodes["D"] = 68] = "D";
375
+ CharacterCodes[CharacterCodes["E"] = 69] = "E";
376
+ CharacterCodes[CharacterCodes["F"] = 70] = "F";
377
+ CharacterCodes[CharacterCodes["G"] = 71] = "G";
378
+ CharacterCodes[CharacterCodes["H"] = 72] = "H";
379
+ CharacterCodes[CharacterCodes["I"] = 73] = "I";
380
+ CharacterCodes[CharacterCodes["J"] = 74] = "J";
381
+ CharacterCodes[CharacterCodes["K"] = 75] = "K";
382
+ CharacterCodes[CharacterCodes["L"] = 76] = "L";
383
+ CharacterCodes[CharacterCodes["M"] = 77] = "M";
384
+ CharacterCodes[CharacterCodes["N"] = 78] = "N";
385
+ CharacterCodes[CharacterCodes["O"] = 79] = "O";
386
+ CharacterCodes[CharacterCodes["P"] = 80] = "P";
387
+ CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
388
+ CharacterCodes[CharacterCodes["R"] = 82] = "R";
389
+ CharacterCodes[CharacterCodes["S"] = 83] = "S";
390
+ CharacterCodes[CharacterCodes["T"] = 84] = "T";
391
+ CharacterCodes[CharacterCodes["U"] = 85] = "U";
392
+ CharacterCodes[CharacterCodes["V"] = 86] = "V";
393
+ CharacterCodes[CharacterCodes["W"] = 87] = "W";
394
+ CharacterCodes[CharacterCodes["X"] = 88] = "X";
395
+ CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
396
+ CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
397
+ CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
398
+ CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
399
+ CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
400
+ CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
401
+ CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
402
+ CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
403
+ CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
404
+ CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
405
+ CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
406
+ CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
407
+ CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
408
+ CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
409
+ CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
410
+ CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
411
+ CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
412
+ })(CharacterCodes || (CharacterCodes = {}));
413
+ new Array(20).fill(0).map((_, index) => {
414
+ return " ".repeat(index);
415
+ });
416
+ const maxCachedValues = 200;
417
+ new Array(maxCachedValues).fill(0).map((_, index) => {
418
+ return "\n" + " ".repeat(index);
419
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
420
+ return "\r" + " ".repeat(index);
421
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
422
+ return "\r\n" + " ".repeat(index);
423
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
424
+ return "\n" + " ".repeat(index);
425
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
426
+ return "\r" + " ".repeat(index);
427
+ }), new Array(maxCachedValues).fill(0).map((_, index) => {
428
+ return "\r\n" + " ".repeat(index);
429
+ });
430
+ //#endregion
431
+ //#region node_modules/jsonc-parser/lib/esm/impl/parser.js
432
+ var ParseOptions;
433
+ (function(ParseOptions) {
434
+ ParseOptions.DEFAULT = { allowTrailingComma: false };
435
+ })(ParseOptions || (ParseOptions = {}));
436
+ /**
437
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
438
+ * Therefore always check the errors list to find out if the input was valid.
439
+ */
440
+ function parse$1(text, errors = [], options = ParseOptions.DEFAULT) {
441
+ let currentProperty = null;
442
+ let currentParent = [];
443
+ const previousParents = [];
444
+ function onValue(value) {
445
+ if (Array.isArray(currentParent)) currentParent.push(value);
446
+ else if (currentProperty !== null) currentParent[currentProperty] = value;
447
+ }
448
+ visit(text, {
449
+ onObjectBegin: () => {
450
+ const object = {};
451
+ onValue(object);
452
+ previousParents.push(currentParent);
453
+ currentParent = object;
454
+ currentProperty = null;
455
+ },
456
+ onObjectProperty: (name) => {
457
+ currentProperty = name;
458
+ },
459
+ onObjectEnd: () => {
460
+ currentParent = previousParents.pop();
461
+ },
462
+ onArrayBegin: () => {
463
+ const array = [];
464
+ onValue(array);
465
+ previousParents.push(currentParent);
466
+ currentParent = array;
467
+ currentProperty = null;
468
+ },
469
+ onArrayEnd: () => {
470
+ currentParent = previousParents.pop();
471
+ },
472
+ onLiteralValue: onValue,
473
+ onError: (error, offset, length) => {
474
+ errors.push({
475
+ error,
476
+ offset,
477
+ length
478
+ });
479
+ }
480
+ }, options);
481
+ return currentParent[0];
482
+ }
483
+ /**
484
+ * Parses the given text and invokes the visitor functions for each object, array and literal reached.
485
+ */
486
+ function visit(text, visitor, options = ParseOptions.DEFAULT) {
487
+ const _scanner = createScanner(text, false);
488
+ const _jsonPath = [];
489
+ let suppressedCallbacks = 0;
490
+ function toNoArgVisit(visitFunction) {
491
+ return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
492
+ }
493
+ function toOneArgVisit(visitFunction) {
494
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
495
+ }
496
+ function toOneArgVisitWithPath(visitFunction) {
497
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
498
+ }
499
+ function toBeginVisit(visitFunction) {
500
+ return visitFunction ? () => {
501
+ if (suppressedCallbacks > 0) suppressedCallbacks++;
502
+ else if (visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) === false) suppressedCallbacks = 1;
503
+ } : () => true;
504
+ }
505
+ function toEndVisit(visitFunction) {
506
+ return visitFunction ? () => {
507
+ if (suppressedCallbacks > 0) suppressedCallbacks--;
508
+ if (suppressedCallbacks === 0) visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
509
+ } : () => true;
510
+ }
511
+ const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
512
+ const disallowComments = options && options.disallowComments;
513
+ const allowTrailingComma = options && options.allowTrailingComma;
514
+ function scanNext() {
515
+ while (true) {
516
+ const token = _scanner.scan();
517
+ switch (_scanner.getTokenError()) {
518
+ case 4:
519
+ handleError(14);
520
+ break;
521
+ case 5:
522
+ handleError(15);
523
+ break;
524
+ case 3:
525
+ handleError(13);
526
+ break;
527
+ case 1:
528
+ if (!disallowComments) handleError(11);
529
+ break;
530
+ case 2:
531
+ handleError(12);
532
+ break;
533
+ case 6: handleError(16);
534
+ }
535
+ switch (token) {
536
+ case 12:
537
+ case 13:
538
+ if (disallowComments) handleError(10);
539
+ else onComment();
540
+ break;
541
+ case 16:
542
+ handleError(1);
543
+ break;
544
+ case 15:
545
+ case 14: break;
546
+ default: return token;
547
+ }
548
+ }
549
+ }
550
+ function handleError(error, skipUntilAfter = [], skipUntil = []) {
551
+ onError(error);
552
+ if (skipUntilAfter.length + skipUntil.length > 0) {
553
+ let token = _scanner.getToken();
554
+ while (token !== 17) {
555
+ if (skipUntilAfter.indexOf(token) !== -1) {
556
+ scanNext();
557
+ break;
558
+ } else if (skipUntil.indexOf(token) !== -1) break;
559
+ token = scanNext();
560
+ }
561
+ }
562
+ }
563
+ function parseString(isValue) {
564
+ const value = _scanner.getTokenValue();
565
+ if (isValue) onLiteralValue(value);
566
+ else {
567
+ onObjectProperty(value);
568
+ _jsonPath.push(value);
569
+ }
570
+ scanNext();
571
+ return true;
572
+ }
573
+ function parseLiteral() {
574
+ switch (_scanner.getToken()) {
575
+ case 11:
576
+ const tokenValue = _scanner.getTokenValue();
577
+ let value = Number(tokenValue);
578
+ if (isNaN(value)) {
579
+ handleError(2);
580
+ value = 0;
581
+ }
582
+ onLiteralValue(value);
583
+ break;
584
+ case 7:
585
+ onLiteralValue(null);
586
+ break;
587
+ case 8:
588
+ onLiteralValue(true);
589
+ break;
590
+ case 9:
591
+ onLiteralValue(false);
592
+ break;
593
+ default: return false;
594
+ }
595
+ scanNext();
596
+ return true;
597
+ }
598
+ function parseProperty() {
599
+ if (_scanner.getToken() !== 10) {
600
+ handleError(3, [], [2, 5]);
601
+ return false;
602
+ }
603
+ parseString(false);
604
+ if (_scanner.getToken() === 6) {
605
+ onSeparator(":");
606
+ scanNext();
607
+ if (!parseValue()) handleError(4, [], [2, 5]);
608
+ } else handleError(5, [], [2, 5]);
609
+ _jsonPath.pop();
610
+ return true;
611
+ }
612
+ function parseObject() {
613
+ onObjectBegin();
614
+ scanNext();
615
+ let needsComma = false;
616
+ while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
617
+ if (_scanner.getToken() === 5) {
618
+ if (!needsComma) handleError(4, [], []);
619
+ onSeparator(",");
620
+ scanNext();
621
+ if (_scanner.getToken() === 2 && allowTrailingComma) break;
622
+ } else if (needsComma) handleError(6, [], []);
623
+ if (!parseProperty()) handleError(4, [], [2, 5]);
624
+ needsComma = true;
625
+ }
626
+ onObjectEnd();
627
+ if (_scanner.getToken() !== 2) handleError(7, [2], []);
628
+ else scanNext();
629
+ return true;
630
+ }
631
+ function parseArray() {
632
+ onArrayBegin();
633
+ scanNext();
634
+ let isFirstElement = true;
635
+ let needsComma = false;
636
+ while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
637
+ if (_scanner.getToken() === 5) {
638
+ if (!needsComma) handleError(4, [], []);
639
+ onSeparator(",");
640
+ scanNext();
641
+ if (_scanner.getToken() === 4 && allowTrailingComma) break;
642
+ } else if (needsComma) handleError(6, [], []);
643
+ if (isFirstElement) {
644
+ _jsonPath.push(0);
645
+ isFirstElement = false;
646
+ } else _jsonPath[_jsonPath.length - 1]++;
647
+ if (!parseValue()) handleError(4, [], [4, 5]);
648
+ needsComma = true;
649
+ }
650
+ onArrayEnd();
651
+ if (!isFirstElement) _jsonPath.pop();
652
+ if (_scanner.getToken() !== 4) handleError(8, [4], []);
653
+ else scanNext();
654
+ return true;
655
+ }
656
+ function parseValue() {
657
+ switch (_scanner.getToken()) {
658
+ case 3: return parseArray();
659
+ case 1: return parseObject();
660
+ case 10: return parseString(true);
661
+ default: return parseLiteral();
662
+ }
663
+ }
664
+ scanNext();
665
+ if (_scanner.getToken() === 17) {
666
+ if (options.allowEmptyContent) return true;
667
+ handleError(4, [], []);
668
+ return false;
669
+ }
670
+ if (!parseValue()) {
671
+ handleError(4, [], []);
672
+ return false;
673
+ }
674
+ if (_scanner.getToken() !== 17) handleError(9, [], []);
675
+ return true;
676
+ }
677
+ /**
678
+ * Takes JSON with JavaScript-style comments and remove
679
+ * them. Optionally replaces every none-newline character
680
+ * of comments with a replaceCharacter
681
+ */
682
+ function stripComments$1(text, replaceCh) {
683
+ let _scanner = createScanner(text), parts = [], kind, offset = 0, pos;
684
+ do {
685
+ pos = _scanner.getPosition();
686
+ kind = _scanner.scan();
687
+ switch (kind) {
688
+ case 12:
689
+ case 13:
690
+ case 17:
691
+ if (offset !== pos) parts.push(text.substring(offset, pos));
692
+ if (replaceCh !== void 0) parts.push(_scanner.getTokenValue().replace(/[^\r\n]/g, replaceCh));
693
+ offset = _scanner.getPosition();
694
+ }
695
+ } while (kind !== 17);
696
+ return parts.join("");
697
+ }
698
+ //#endregion
699
+ //#region node_modules/jsonc-parser/lib/esm/main.js
700
+ var ScanError;
701
+ (function(ScanError) {
702
+ ScanError[ScanError["None"] = 0] = "None";
703
+ ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
704
+ ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
705
+ ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
706
+ ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
707
+ ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
708
+ ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
709
+ })(ScanError || (ScanError = {}));
710
+ var SyntaxKind;
711
+ (function(SyntaxKind) {
712
+ SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
713
+ SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
714
+ SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
715
+ SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
716
+ SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
717
+ SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
718
+ SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
719
+ SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
720
+ SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
721
+ SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
722
+ SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
723
+ SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
724
+ SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
725
+ SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
726
+ SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
727
+ SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
728
+ SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
729
+ })(SyntaxKind || (SyntaxKind = {}));
730
+ /**
731
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
732
+ * Therefore, always check the errors list to find out if the input was valid.
733
+ */
734
+ const parse = parse$1;
735
+ /**
736
+ * Takes JSON with JavaScript-style comments and remove
737
+ * them. Optionally replaces every none-newline character
738
+ * of comments with a replaceCharacter
739
+ */
740
+ const stripComments = stripComments$1;
741
+ var ParseErrorCode;
742
+ (function(ParseErrorCode) {
743
+ ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
744
+ ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
745
+ ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
746
+ ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
747
+ ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
748
+ ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
749
+ ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
750
+ ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
751
+ ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
752
+ ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
753
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
754
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
755
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
756
+ ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
757
+ ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
758
+ ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
759
+ })(ParseErrorCode || (ParseErrorCode = {}));
760
+ function printParseErrorCode(code) {
761
+ switch (code) {
762
+ case 1: return "InvalidSymbol";
763
+ case 2: return "InvalidNumberFormat";
764
+ case 3: return "PropertyNameExpected";
765
+ case 4: return "ValueExpected";
766
+ case 5: return "ColonExpected";
767
+ case 6: return "CommaExpected";
768
+ case 7: return "CloseBraceExpected";
769
+ case 8: return "CloseBracketExpected";
770
+ case 9: return "EndOfFileExpected";
771
+ case 10: return "InvalidCommentToken";
772
+ case 11: return "UnexpectedEndOfComment";
773
+ case 12: return "UnexpectedEndOfString";
774
+ case 13: return "UnexpectedEndOfNumber";
775
+ case 14: return "InvalidUnicode";
776
+ case 15: return "InvalidEscapeCharacter";
777
+ case 16: return "InvalidCharacter";
778
+ }
779
+ return "<unknown ParseErrorCode>";
780
+ }
781
+ //#endregion
34
782
  //#region src/config.ts
35
783
  const __filename = fileURLToPath(import.meta.url);
36
784
  const __dirname = path.dirname(__filename);
@@ -54,79 +802,21 @@ function getDefaultTemplatePath() {
54
802
  return path.join(root, "templates", ".luarc.json");
55
803
  }
56
804
  /**
57
- * Strips single-line comments (//), multi-line comments (/* ... *\/),
58
- * and trailing commas before '}' or ']' from JSONC text while preserving string literals.
805
+ * Strips single-line and multi-line comments from JSONC text using jsonc-parser.
59
806
  */
60
807
  function stripJsonComments(text) {
61
808
  const cleanText = text.replace(/^\uFEFF/, "");
62
- let result = "";
63
- let i = 0;
64
- const len = cleanText.length;
65
- while (i < len) {
66
- const ch = cleanText[i];
67
- if (ch === "\"") {
68
- result += ch;
69
- i++;
70
- while (i < len) {
71
- const c = cleanText[i];
72
- result += c;
73
- if (c === "\\") {
74
- i++;
75
- if (i < len) result += cleanText[i];
76
- } else if (c === "\"") break;
77
- i++;
78
- }
79
- i++;
80
- continue;
81
- }
82
- if (ch === "/" && i + 1 < len && cleanText[i + 1] === "/") {
83
- i += 2;
84
- while (i < len && cleanText[i] !== "\n" && cleanText[i] !== "\r") i++;
85
- continue;
86
- }
87
- if (ch === "/" && i + 1 < len && cleanText[i + 1] === "*") {
88
- i += 2;
89
- while (i + 1 < len && !(cleanText[i] === "*" && cleanText[i + 1] === "/")) i++;
90
- i += 2;
91
- continue;
92
- }
93
- if (ch === ",") {
94
- let j = i + 1;
95
- let isTrailing = false;
96
- while (j < len) {
97
- const nextChar = cleanText[j];
98
- if (nextChar === " " || nextChar === " " || nextChar === "\n" || nextChar === "\r") {
99
- j++;
100
- continue;
101
- }
102
- if (nextChar === "/" && j + 1 < len && cleanText[j + 1] === "/") {
103
- j += 2;
104
- while (j < len && cleanText[j] !== "\n" && cleanText[j] !== "\r") j++;
105
- continue;
106
- }
107
- if (nextChar === "/" && j + 1 < len && cleanText[j + 1] === "*") {
108
- j += 2;
109
- while (j + 1 < len && !(cleanText[j] === "*" && cleanText[j + 1] === "/")) j++;
110
- j += 2;
111
- continue;
112
- }
113
- if (nextChar === "}" || nextChar === "]") isTrailing = true;
114
- break;
115
- }
116
- if (isTrailing) {
117
- result += " ";
118
- i++;
119
- continue;
120
- }
121
- }
122
- result += ch;
123
- i++;
124
- }
125
- return result;
809
+ return stripComments(cleanText);
126
810
  }
127
811
  function parseJsonc(text) {
128
- const stripped = stripJsonComments(text);
129
- return JSON.parse(stripped);
812
+ const cleanText = text.replace(/^\uFEFF/, "");
813
+ const errors = [];
814
+ const result = parse(cleanText, errors, { allowTrailingComma: true });
815
+ if (errors.length > 0) {
816
+ const errorDetails = errors.map((e) => `${printParseErrorCode(e.error)} at offset ${e.offset}`).join(", ");
817
+ throw new SyntaxError(`Invalid JSONC: ${errorDetails}`);
818
+ }
819
+ return result;
130
820
  }
131
821
  function loadConfigFile(filePath) {
132
822
  if (!fs.existsSync(filePath)) throw new Error(`Configuration file not found: ${filePath}`);
@@ -161,6 +851,7 @@ function mergeConfigs(base, override = {}, definitionsDir = getDefinitionsDir(),
161
851
  const defaultIgnore = [
162
852
  ".git",
163
853
  ".vscode",
854
+ ".nanos-lint",
164
855
  "node_modules",
165
856
  "dist",
166
857
  "bin",
@@ -290,12 +981,18 @@ function initWorkspace(workspacePath, options) {
290
981
  const template = loadConfigFile(getDefaultTemplatePath());
291
982
  const definitionsDir = getDefinitionsDir();
292
983
  const sourceAnnotations = path.join(definitionsDir, "annotations.lua");
984
+ if (!fs.existsSync(sourceAnnotations)) throw new Error(`Definitions file not found at ${sourceAnnotations}. Make sure submodules are initialized.`);
293
985
  const targetNanosDir = path.join(workspacePath, ".nanos-lint");
294
986
  fs.mkdirSync(targetNanosDir, { recursive: true });
295
987
  const targetAnnotations = path.join(targetNanosDir, "annotations.lua");
296
- if (fs.existsSync(sourceAnnotations)) fs.copyFileSync(sourceAnnotations, targetAnnotations);
988
+ fs.copyFileSync(sourceAnnotations, targetAnnotations);
297
989
  template.workspace = template.workspace ?? {};
298
990
  template.workspace.library = [".nanos-lint/annotations.lua"];
991
+ const existingIgnore = template.workspace.ignoreDir ?? [];
992
+ if (!existingIgnore.includes(".nanos-lint")) template.workspace.ignoreDir = [".nanos-lint", ...existingIgnore];
993
+ template.files = template.files ?? {};
994
+ const existingExclude = template.files.exclude ?? [];
995
+ if (!existingExclude.includes(".nanos-lint/**")) template.files.exclude = [".nanos-lint/**", ...existingExclude];
299
996
  fs.writeFileSync(targetFile, JSON.stringify(template, null, 2), "utf-8");
300
997
  return targetFile;
301
998
  }
@@ -374,15 +1071,50 @@ function getCacheDir(version = FALLBACK_LUALS_VERSION) {
374
1071
  const base = process.platform === "win32" ? process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local") : process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
375
1072
  return path.join(base, "nanos-lint", "luals", version);
376
1073
  }
1074
+ /**
1075
+ * Verifies that a LuaLS binary exists, has non-trivial size, and is executable.
1076
+ */
1077
+ function isBinaryValid(binaryPath) {
1078
+ if (!fs.existsSync(binaryPath)) return false;
1079
+ try {
1080
+ const stats = fs.statSync(binaryPath);
1081
+ if (!stats.isFile() || stats.size < 1e5) return false;
1082
+ const output = execFileSync(binaryPath, ["--version"], {
1083
+ timeout: 5e3,
1084
+ stdio: "pipe",
1085
+ encoding: "utf-8"
1086
+ });
1087
+ return /^\d+\.\d+\.\d+/.test(output.trim());
1088
+ } catch {
1089
+ return false;
1090
+ }
1091
+ }
377
1092
  async function downloadAndExtractLuaLS(version = DEFAULT_LUALS_VERSION, targetDir, options) {
378
1093
  const resolvedVersion = await resolveLuaLSVersion(version);
379
1094
  const info = getPlatformInfo(resolvedVersion);
380
1095
  const destDir = targetDir || getCacheDir(resolvedVersion);
381
1096
  const binaryPath = path.join(destDir, info.binaryRelativePath);
382
- if (fs.existsSync(binaryPath)) return binaryPath;
383
- fs.mkdirSync(destDir, { recursive: true });
1097
+ const completeMarker = path.join(destDir, ".complete");
1098
+ if (fs.existsSync(destDir)) {
1099
+ if (fs.existsSync(binaryPath) && isBinaryValid(binaryPath)) {
1100
+ if (!fs.existsSync(completeMarker)) try {
1101
+ fs.writeFileSync(completeMarker, resolvedVersion, "utf-8");
1102
+ } catch {}
1103
+ return binaryPath;
1104
+ }
1105
+ try {
1106
+ fs.rmSync(destDir, {
1107
+ recursive: true,
1108
+ force: true
1109
+ });
1110
+ } catch {}
1111
+ }
1112
+ const parentDir = path.dirname(destDir);
1113
+ fs.mkdirSync(parentDir, { recursive: true });
1114
+ const tempDir = path.join(parentDir, `.${path.basename(destDir)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`);
1115
+ fs.mkdirSync(tempDir, { recursive: true });
384
1116
  const url = `https://github.com/LuaLS/lua-language-server/releases/download/${resolvedVersion}/${info.assetName}`;
385
- const archivePath = path.join(destDir, info.assetName);
1117
+ const archivePath = path.join(tempDir, info.assetName);
386
1118
  if (!options?.quiet) console.log(`[luals] Downloading LuaLS ${resolvedVersion} from ${url}...`);
387
1119
  let response = null;
388
1120
  let lastErr = null;
@@ -393,54 +1125,108 @@ async function downloadAndExtractLuaLS(version = DEFAULT_LUALS_VERSION, targetDi
393
1125
  response = res;
394
1126
  break;
395
1127
  }
1128
+ await res.body?.cancel();
396
1129
  lastErr = /* @__PURE__ */ new Error(`Failed to download ${url}: ${res.status} ${res.statusText}`);
397
1130
  } catch (err) {
398
1131
  lastErr = err;
399
1132
  }
400
1133
  if (attempt < 3) await new Promise((resolve) => setTimeout(resolve, attempt * 1e3));
401
1134
  }
402
- if (!response || !response.body) throw lastErr || /* @__PURE__ */ new Error(`Failed to download ${url}`);
403
- const arrayBuffer = await response.arrayBuffer();
404
- fs.writeFileSync(archivePath, Buffer.from(arrayBuffer));
405
- if (!options?.quiet) console.log(`[luals] Extracting to ${destDir}...`);
406
- try {
407
- await execFileAsync("tar", [
408
- "-xf",
409
- archivePath,
410
- "-C",
411
- destDir
412
- ]);
413
- } catch (tarErr) {
414
- if (process.platform === "win32" && info.assetName.endsWith(".zip")) await execFileAsync("powershell.exe", [
415
- "-NoProfile",
416
- "-Command",
417
- `Expand-Archive -Path '${escapePowerShellSingleQuote(archivePath)}' -DestinationPath '${escapePowerShellSingleQuote(destDir)}' -Force`
418
- ]);
419
- else throw tarErr;
1135
+ if (!response || !response.body) {
1136
+ try {
1137
+ fs.rmSync(tempDir, {
1138
+ recursive: true,
1139
+ force: true
1140
+ });
1141
+ } catch {}
1142
+ throw lastErr || /* @__PURE__ */ new Error(`Failed to download ${url}`);
420
1143
  }
421
1144
  try {
422
- fs.unlinkSync(archivePath);
423
- } catch {}
424
- if (process.platform !== "win32") try {
425
- fs.chmodSync(binaryPath, 493);
426
- } catch {}
427
- if (!fs.existsSync(binaryPath)) throw new Error(`Failed to extract LuaLS binary to expected path: ${binaryPath}`);
428
- if (!options?.quiet) console.log(`[luals] Ready: ${binaryPath}`);
429
- return binaryPath;
1145
+ const arrayBuffer = await response.arrayBuffer();
1146
+ fs.writeFileSync(archivePath, Buffer.from(arrayBuffer));
1147
+ if (!options?.quiet) console.log(`[luals] Extracting to ${destDir}...`);
1148
+ try {
1149
+ await execFileAsync("tar", [
1150
+ "-xf",
1151
+ archivePath,
1152
+ "-C",
1153
+ tempDir
1154
+ ]);
1155
+ } catch (tarErr) {
1156
+ if (process.platform === "win32" && info.assetName.endsWith(".zip")) await execFileAsync("powershell.exe", [
1157
+ "-NoProfile",
1158
+ "-Command",
1159
+ `Expand-Archive -Path '${escapePowerShellSingleQuote(archivePath)}' -DestinationPath '${escapePowerShellSingleQuote(tempDir)}' -Force`
1160
+ ]);
1161
+ else throw tarErr;
1162
+ }
1163
+ try {
1164
+ fs.unlinkSync(archivePath);
1165
+ } catch {}
1166
+ const tempBinaryPath = path.join(tempDir, info.binaryRelativePath);
1167
+ if (process.platform !== "win32") try {
1168
+ fs.chmodSync(tempBinaryPath, 493);
1169
+ } catch {}
1170
+ if (!fs.existsSync(tempBinaryPath) || fs.statSync(tempBinaryPath).size < 1e5) throw new Error(`Failed to extract valid LuaLS binary to expected path: ${tempBinaryPath}`);
1171
+ fs.writeFileSync(path.join(tempDir, ".complete"), resolvedVersion, "utf-8");
1172
+ for (let attempt = 0; attempt < 5; attempt++) try {
1173
+ fs.renameSync(tempDir, destDir);
1174
+ break;
1175
+ } catch (renameErr) {
1176
+ if (fs.existsSync(binaryPath) && isBinaryValid(binaryPath)) {
1177
+ try {
1178
+ fs.rmSync(tempDir, {
1179
+ recursive: true,
1180
+ force: true
1181
+ });
1182
+ } catch {}
1183
+ if (!options?.quiet) console.log(`[luals] Ready: ${binaryPath}`);
1184
+ return binaryPath;
1185
+ }
1186
+ if (attempt < 4) await new Promise((resolve) => setTimeout(resolve, 100 * (attempt + 1)));
1187
+ else throw renameErr;
1188
+ }
1189
+ if (!isBinaryValid(binaryPath)) throw new Error(`Extracted LuaLS binary at ${binaryPath} is invalid or non-functional.`);
1190
+ if (!options?.quiet) console.log(`[luals] Ready: ${binaryPath}`);
1191
+ return binaryPath;
1192
+ } finally {
1193
+ if (fs.existsSync(tempDir)) try {
1194
+ fs.rmSync(tempDir, {
1195
+ recursive: true,
1196
+ force: true
1197
+ });
1198
+ } catch {}
1199
+ }
430
1200
  }
431
1201
  async function resolveLuaLSBinary(version = DEFAULT_LUALS_VERSION, options) {
432
1202
  if (process.env.LUALS_BIN && fs.existsSync(process.env.LUALS_BIN)) return process.env.LUALS_BIN;
433
1203
  const resolvedVersion = await resolveLuaLSVersion(version);
434
1204
  const info = getPlatformInfo(resolvedVersion);
435
1205
  const bundledPath = path.join(getPackageRoot(), info.binaryRelativePath);
436
- if (fs.existsSync(bundledPath)) return bundledPath;
437
- const cachedPath = path.join(getCacheDir(resolvedVersion), info.binaryRelativePath);
438
- if (fs.existsSync(cachedPath)) return cachedPath;
1206
+ if (fs.existsSync(bundledPath) && isBinaryValid(bundledPath)) return bundledPath;
1207
+ const cachedDir = getCacheDir(resolvedVersion);
1208
+ const cachedPath = path.join(cachedDir, info.binaryRelativePath);
1209
+ const completeMarker = path.join(cachedDir, ".complete");
1210
+ if (fs.existsSync(cachedPath)) {
1211
+ if (isBinaryValid(cachedPath)) {
1212
+ if (!fs.existsSync(completeMarker)) try {
1213
+ fs.writeFileSync(completeMarker, resolvedVersion, "utf-8");
1214
+ } catch {}
1215
+ return cachedPath;
1216
+ }
1217
+ if (!options?.quiet) console.warn(`[luals] Cached LuaLS binary at ${cachedPath} is corrupted or incomplete. Repairing...`);
1218
+ try {
1219
+ fs.rmSync(cachedDir, {
1220
+ recursive: true,
1221
+ force: true
1222
+ });
1223
+ } catch {}
1224
+ }
439
1225
  try {
440
1226
  const cmd = process.platform === "win32" ? "where.exe" : "which";
441
1227
  const { stdout } = await execFileAsync(cmd, ["lua-language-server"]);
442
1228
  const found = stdout.trim().split(/\r?\n/)[0];
443
- if (found && fs.existsSync(found)) return found;
1229
+ if (found && fs.existsSync(found) && isBinaryValid(found)) return found;
444
1230
  } catch {}
445
1231
  return await downloadAndExtractLuaLS(resolvedVersion, void 0, options);
446
1232
  }
@@ -485,8 +1271,9 @@ async function runLuaLSCheck(targetPath, configPath, options) {
485
1271
  } catch {}
486
1272
  }
487
1273
  if (!parseSucceeded) {
488
- if (execError) throw new Error(`LuaLS check failed to execute or produce diagnostic output: ${execError instanceof Error ? execError.message : String(execError)}`);
489
- throw new Error(`LuaLS check failed to produce diagnostic output at: ${checkOutPath}`);
1274
+ const cacheHint = `(Cache location: ${getCacheDir()})`;
1275
+ if (execError) throw new Error(`LuaLS check failed to execute or produce diagnostic output: ${execError instanceof Error ? execError.message : String(execError)}. ${cacheHint}`);
1276
+ throw new Error(`LuaLS check failed to produce diagnostic output at: ${checkOutPath}. ${cacheHint}`);
490
1277
  }
491
1278
  if (targetFileOnly) {
492
1279
  const filtered = {};
@@ -529,6 +1316,7 @@ function countCheckedFiles(targetPath, configPath) {
529
1316
  let ignoreDirs = [
530
1317
  ".git",
531
1318
  ".vscode",
1319
+ ".nanos-lint",
532
1320
  "node_modules"
533
1321
  ];
534
1322
  let excludePatterns = [];
@@ -3832,6 +4620,6 @@ if (isDirectExecution()) runCLI().then((code) => {
3832
4620
  process.exit(1);
3833
4621
  });
3834
4622
  //#endregion
3835
- export { parseJsonc as A, runLuaLSCheck as C, initWorkspace as D, getPackageRoot as E, stripJsonComments as M, fileUriToPath as N, loadConfigFile as O, resolveLuaLSVersion as S, getDefinitionsDir as T, escapePowerShellSingleQuote as _, formatGitHubAnnotations as a, resolveLatestLuaLSVersion as b, formatReport as c, pluralize as d, shouldEnableColor as f, downloadAndExtractLuaLS as g, countCheckedFiles as h, runCLI as i, resolveWorkspaceConfig as j, mergeConfigs as k, formatSeverityBadge as l, FALLBACK_LUALS_VERSION as m, createProgram as n, formatPretty as o, DEFAULT_LUALS_VERSION as p, isDirectExecution as r, formatProblemSummary as s, collectIgnorePatterns as t, getColors as u, getCacheDir as v, getDefaultTemplatePath as w, resolveLuaLSBinary as x, getPlatformInfo as y };
4623
+ export { mergeConfigs as A, resolveLuaLSVersion as C, getPackageRoot as D, getDefinitionsDir as E, resolveWorkspaceConfig as M, stripJsonComments as N, initWorkspace as O, fileUriToPath as P, resolveLuaLSBinary as S, getDefaultTemplatePath as T, escapePowerShellSingleQuote as _, formatGitHubAnnotations as a, isBinaryValid as b, formatReport as c, pluralize as d, shouldEnableColor as f, downloadAndExtractLuaLS as g, countCheckedFiles as h, runCLI as i, parseJsonc as j, loadConfigFile as k, formatSeverityBadge as l, FALLBACK_LUALS_VERSION as m, createProgram as n, formatPretty as o, DEFAULT_LUALS_VERSION as p, isDirectExecution as r, formatProblemSummary as s, collectIgnorePatterns as t, getColors as u, getCacheDir as v, runLuaLSCheck as w, resolveLatestLuaLSVersion as x, getPlatformInfo as y };
3836
4624
 
3837
- //# sourceMappingURL=cli-Dx-1zSOk.js.map
4625
+ //# sourceMappingURL=cli-kmHD4epr.js.map