opencode-dotenv 0.3.3 → 0.3.7

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 (2) hide show
  1. package/dist/index.js +170 -812
  2. package/package.json +8 -2
package/dist/index.js CHANGED
@@ -1,811 +1,173 @@
1
- // @bun
2
- // node_modules/jsonc-parser/lib/esm/impl/scanner.js
3
- function createScanner(text, ignoreTrivia = false) {
4
- const len = text.length;
5
- let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
6
- function scanHexDigits(count, exact) {
7
- let digits = 0;
8
- let value2 = 0;
9
- while (digits < count || !exact) {
10
- let ch = text.charCodeAt(pos);
11
- if (ch >= 48 && ch <= 57) {
12
- value2 = value2 * 16 + ch - 48;
13
- } else if (ch >= 65 && ch <= 70) {
14
- value2 = value2 * 16 + ch - 65 + 10;
15
- } else if (ch >= 97 && ch <= 102) {
16
- value2 = value2 * 16 + ch - 97 + 10;
17
- } else {
18
- break;
19
- }
20
- pos++;
21
- digits++;
22
- }
23
- if (digits < count) {
24
- value2 = -1;
25
- }
26
- return value2;
27
- }
28
- function setPosition(newPosition) {
29
- pos = newPosition;
30
- value = "";
31
- tokenOffset = 0;
32
- token = 16;
33
- scanError = 0;
34
- }
35
- function scanNumber() {
36
- let start = pos;
37
- if (text.charCodeAt(pos) === 48) {
38
- pos++;
39
- } else {
40
- pos++;
41
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
42
- pos++;
43
- }
44
- }
45
- if (pos < text.length && text.charCodeAt(pos) === 46) {
46
- pos++;
47
- if (pos < text.length && isDigit(text.charCodeAt(pos))) {
48
- pos++;
49
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
50
- pos++;
51
- }
52
- } else {
53
- scanError = 3;
54
- return text.substring(start, pos);
55
- }
56
- }
57
- let end = pos;
58
- if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
59
- pos++;
60
- if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
61
- pos++;
62
- }
63
- if (pos < text.length && isDigit(text.charCodeAt(pos))) {
64
- pos++;
65
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
66
- pos++;
67
- }
68
- end = pos;
69
- } else {
70
- scanError = 3;
71
- }
72
- }
73
- return text.substring(start, end);
74
- }
75
- function scanString() {
76
- let result = "", start = pos;
77
- while (true) {
78
- if (pos >= len) {
79
- result += text.substring(start, pos);
80
- scanError = 2;
81
- break;
82
- }
83
- const ch = text.charCodeAt(pos);
84
- if (ch === 34) {
85
- result += text.substring(start, pos);
86
- pos++;
87
- break;
88
- }
89
- if (ch === 92) {
90
- result += text.substring(start, pos);
91
- pos++;
92
- if (pos >= len) {
93
- scanError = 2;
94
- break;
95
- }
96
- const ch2 = text.charCodeAt(pos++);
97
- switch (ch2) {
98
- case 34:
99
- result += '"';
100
- break;
101
- case 92:
102
- result += "\\";
103
- break;
104
- case 47:
105
- result += "/";
106
- break;
107
- case 98:
108
- result += "\b";
109
- break;
110
- case 102:
111
- result += "\f";
112
- break;
113
- case 110:
114
- result += `
115
- `;
116
- break;
117
- case 114:
118
- result += "\r";
119
- break;
120
- case 116:
121
- result += "\t";
122
- break;
123
- case 117:
124
- const ch3 = scanHexDigits(4, true);
125
- if (ch3 >= 0) {
126
- result += String.fromCharCode(ch3);
127
- } else {
128
- scanError = 4;
129
- }
130
- break;
131
- default:
132
- scanError = 5;
133
- }
134
- start = pos;
135
- continue;
136
- }
137
- if (ch >= 0 && ch <= 31) {
138
- if (isLineBreak(ch)) {
139
- result += text.substring(start, pos);
140
- scanError = 2;
141
- break;
142
- } else {
143
- scanError = 6;
144
- }
145
- }
146
- pos++;
147
- }
148
- return result;
149
- }
150
- function scanNext() {
151
- value = "";
152
- scanError = 0;
153
- tokenOffset = pos;
154
- lineStartOffset = lineNumber;
155
- prevTokenLineStartOffset = tokenLineStartOffset;
156
- if (pos >= len) {
157
- tokenOffset = len;
158
- return token = 17;
159
- }
160
- let code = text.charCodeAt(pos);
161
- if (isWhiteSpace(code)) {
162
- do {
163
- pos++;
164
- value += String.fromCharCode(code);
165
- code = text.charCodeAt(pos);
166
- } while (isWhiteSpace(code));
167
- return token = 15;
168
- }
169
- if (isLineBreak(code)) {
170
- pos++;
171
- value += String.fromCharCode(code);
172
- if (code === 13 && text.charCodeAt(pos) === 10) {
173
- pos++;
174
- value += `
175
- `;
176
- }
177
- lineNumber++;
178
- tokenLineStartOffset = pos;
179
- return token = 14;
180
- }
181
- switch (code) {
182
- case 123:
183
- pos++;
184
- return token = 1;
185
- case 125:
186
- pos++;
187
- return token = 2;
188
- case 91:
189
- pos++;
190
- return token = 3;
191
- case 93:
192
- pos++;
193
- return token = 4;
194
- case 58:
195
- pos++;
196
- return token = 6;
197
- case 44:
198
- pos++;
199
- return token = 5;
200
- case 34:
201
- pos++;
202
- value = scanString();
203
- return token = 10;
204
- case 47:
205
- const start = pos - 1;
206
- if (text.charCodeAt(pos + 1) === 47) {
207
- pos += 2;
208
- while (pos < len) {
209
- if (isLineBreak(text.charCodeAt(pos))) {
210
- break;
211
- }
212
- pos++;
213
- }
214
- value = text.substring(start, pos);
215
- return token = 12;
216
- }
217
- if (text.charCodeAt(pos + 1) === 42) {
218
- pos += 2;
219
- const safeLength = len - 1;
220
- let commentClosed = false;
221
- while (pos < safeLength) {
222
- const ch = text.charCodeAt(pos);
223
- if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
224
- pos += 2;
225
- commentClosed = true;
226
- break;
227
- }
228
- pos++;
229
- if (isLineBreak(ch)) {
230
- if (ch === 13 && text.charCodeAt(pos) === 10) {
231
- pos++;
232
- }
233
- lineNumber++;
234
- tokenLineStartOffset = pos;
235
- }
236
- }
237
- if (!commentClosed) {
238
- pos++;
239
- scanError = 1;
240
- }
241
- value = text.substring(start, pos);
242
- return token = 13;
243
- }
244
- value += String.fromCharCode(code);
245
- pos++;
246
- return token = 16;
247
- case 45:
248
- value += String.fromCharCode(code);
249
- pos++;
250
- if (pos === len || !isDigit(text.charCodeAt(pos))) {
251
- return token = 16;
252
- }
253
- case 48:
254
- case 49:
255
- case 50:
256
- case 51:
257
- case 52:
258
- case 53:
259
- case 54:
260
- case 55:
261
- case 56:
262
- case 57:
263
- value += scanNumber();
264
- return token = 11;
265
- default:
266
- while (pos < len && isUnknownContentCharacter(code)) {
267
- pos++;
268
- code = text.charCodeAt(pos);
269
- }
270
- if (tokenOffset !== pos) {
271
- value = text.substring(tokenOffset, pos);
272
- switch (value) {
273
- case "true":
274
- return token = 8;
275
- case "false":
276
- return token = 9;
277
- case "null":
278
- 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)) {
289
- return false;
290
- }
291
- switch (code) {
292
- case 125:
293
- case 93:
294
- case 123:
295
- case 91:
296
- case 34:
297
- case 58:
298
- case 44:
299
- case 47:
300
- return false;
301
- }
302
- return true;
303
- }
304
- function scanNextNonTrivia() {
305
- let result;
306
- do {
307
- result = scanNext();
308
- } while (result >= 12 && result <= 15);
309
- return result;
310
- }
311
- return {
312
- setPosition,
313
- getPosition: () => pos,
314
- scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
315
- getToken: () => token,
316
- getTokenValue: () => value,
317
- getTokenOffset: () => tokenOffset,
318
- getTokenLength: () => pos - tokenOffset,
319
- getTokenStartLine: () => lineStartOffset,
320
- getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
321
- getTokenError: () => scanError
322
- };
323
- }
324
- function isWhiteSpace(ch) {
325
- return ch === 32 || ch === 9;
326
- }
327
- function isLineBreak(ch) {
328
- return ch === 10 || ch === 13;
329
- }
330
- function isDigit(ch) {
331
- return ch >= 48 && ch <= 57;
332
- }
333
- var CharacterCodes;
334
- (function(CharacterCodes2) {
335
- CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
336
- CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
337
- CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
338
- CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
339
- CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
340
- CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
341
- CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
342
- CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
343
- CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
344
- CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
345
- CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
346
- CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
347
- CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
348
- CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
349
- CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
350
- CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
351
- CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
352
- CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
353
- CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
354
- CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
355
- CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
356
- CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
357
- CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
358
- CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
359
- CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
360
- CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
361
- CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
362
- CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
363
- CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
364
- CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
365
- CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
366
- CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
367
- CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
368
- CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
369
- CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
370
- CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
371
- CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
372
- CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
373
- CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
374
- CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
375
- CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
376
- CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
377
- CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
378
- CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
379
- CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
380
- CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
381
- CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
382
- CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
383
- CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
384
- CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
385
- CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
386
- CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
387
- CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
388
- CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
389
- CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
390
- CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
391
- CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
392
- CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
393
- CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
394
- CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
395
- CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
396
- CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
397
- CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
398
- CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
399
- CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
400
- CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
401
- CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
402
- CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
403
- CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
404
- CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
405
- CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
406
- CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
407
- CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
408
- CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
409
- CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
410
- CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
411
- CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
412
- CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
413
- CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
414
- CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
415
- })(CharacterCodes || (CharacterCodes = {}));
416
-
417
- // node_modules/jsonc-parser/lib/esm/impl/string-intern.js
418
- var cachedSpaces = new Array(20).fill(0).map((_, index) => {
419
- return " ".repeat(index);
420
- });
421
- var maxCachedValues = 200;
422
- var cachedBreakLinesWithSpaces = {
423
- " ": {
424
- "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
425
- return `
426
- ` + " ".repeat(index);
427
- }),
428
- "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
429
- return "\r" + " ".repeat(index);
430
- }),
431
- "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
432
- return `\r
433
- ` + " ".repeat(index);
434
- })
435
- },
436
- "\t": {
437
- "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
438
- return `
439
- ` + "\t".repeat(index);
440
- }),
441
- "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
442
- return "\r" + "\t".repeat(index);
443
- }),
444
- "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
445
- return `\r
446
- ` + "\t".repeat(index);
447
- })
448
- }
1
+ import { createRequire } from "node:module";
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
449
17
  };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
450
20
 
451
- // node_modules/jsonc-parser/lib/esm/impl/parser.js
452
- var ParseOptions;
453
- (function(ParseOptions2) {
454
- ParseOptions2.DEFAULT = {
455
- allowTrailingComma: false
456
- };
457
- })(ParseOptions || (ParseOptions = {}));
458
- function parse(text, errors = [], options = ParseOptions.DEFAULT) {
459
- let currentProperty = null;
460
- let currentParent = [];
461
- const previousParents = [];
462
- function onValue(value) {
463
- if (Array.isArray(currentParent)) {
464
- currentParent.push(value);
465
- } else if (currentProperty !== null) {
466
- currentParent[currentProperty] = value;
467
- }
468
- }
469
- const visitor = {
470
- onObjectBegin: () => {
471
- const object = {};
472
- onValue(object);
473
- previousParents.push(currentParent);
474
- currentParent = object;
475
- currentProperty = null;
476
- },
477
- onObjectProperty: (name) => {
478
- currentProperty = name;
479
- },
480
- onObjectEnd: () => {
481
- currentParent = previousParents.pop();
482
- },
483
- onArrayBegin: () => {
484
- const array = [];
485
- onValue(array);
486
- previousParents.push(currentParent);
487
- currentParent = array;
488
- currentProperty = null;
489
- },
490
- onArrayEnd: () => {
491
- currentParent = previousParents.pop();
492
- },
493
- onLiteralValue: onValue,
494
- onError: (error, offset, length) => {
495
- errors.push({ error, offset, length });
496
- }
497
- };
498
- visit(text, visitor, options);
499
- return currentParent[0];
500
- }
501
- function visit(text, visitor, options = ParseOptions.DEFAULT) {
502
- const _scanner = createScanner(text, false);
503
- const _jsonPath = [];
504
- let suppressedCallbacks = 0;
505
- function toNoArgVisit(visitFunction) {
506
- return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
507
- }
508
- function toOneArgVisit(visitFunction) {
509
- return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
510
- }
511
- function toOneArgVisitWithPath(visitFunction) {
512
- return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
513
- }
514
- function toBeginVisit(visitFunction) {
515
- return visitFunction ? () => {
516
- if (suppressedCallbacks > 0) {
517
- suppressedCallbacks++;
518
- } else {
519
- let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
520
- if (cbReturn === false) {
521
- suppressedCallbacks = 1;
522
- }
523
- }
524
- } : () => true;
525
- }
526
- function toEndVisit(visitFunction) {
527
- return visitFunction ? () => {
528
- if (suppressedCallbacks > 0) {
529
- suppressedCallbacks--;
530
- }
531
- if (suppressedCallbacks === 0) {
532
- visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
533
- }
534
- } : () => true;
535
- }
536
- 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);
537
- const disallowComments = options && options.disallowComments;
538
- const allowTrailingComma = options && options.allowTrailingComma;
539
- function scanNext() {
540
- while (true) {
541
- const token = _scanner.scan();
542
- switch (_scanner.getTokenError()) {
543
- case 4:
544
- handleError(14);
545
- break;
546
- case 5:
547
- handleError(15);
548
- break;
549
- case 3:
550
- handleError(13);
551
- break;
21
+ // node_modules/jsonc-parser/lib/umd/main.js
22
+ var require_main = __commonJS((exports, module) => {
23
+ (function(factory) {
24
+ if (typeof module === "object" && typeof module.exports === "object") {
25
+ var v = factory(__require, exports);
26
+ if (v !== undefined)
27
+ module.exports = v;
28
+ } else if (typeof define === "function" && define.amd) {
29
+ define(["require", "exports", "./impl/format", "./impl/edit", "./impl/scanner", "./impl/parser"], factory);
30
+ }
31
+ })(function(require2, exports2) {
32
+ Object.defineProperty(exports2, "__esModule", { value: true });
33
+ exports2.applyEdits = exports2.modify = exports2.format = exports2.printParseErrorCode = exports2.ParseErrorCode = exports2.stripComments = exports2.visit = exports2.getNodeValue = exports2.getNodePath = exports2.findNodeAtOffset = exports2.findNodeAtLocation = exports2.parseTree = exports2.parse = exports2.getLocation = exports2.SyntaxKind = exports2.ScanError = exports2.createScanner = undefined;
34
+ const formatter = require2("./impl/format");
35
+ const edit = require2("./impl/edit");
36
+ const scanner = require2("./impl/scanner");
37
+ const parser = require2("./impl/parser");
38
+ exports2.createScanner = scanner.createScanner;
39
+ var ScanError;
40
+ (function(ScanError2) {
41
+ ScanError2[ScanError2["None"] = 0] = "None";
42
+ ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
43
+ ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
44
+ ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
45
+ ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
46
+ ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
47
+ ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
48
+ })(ScanError || (exports2.ScanError = ScanError = {}));
49
+ var SyntaxKind;
50
+ (function(SyntaxKind2) {
51
+ SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
52
+ SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
53
+ SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
54
+ SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
55
+ SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
56
+ SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
57
+ SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
58
+ SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
59
+ SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
60
+ SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
61
+ SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
62
+ SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
63
+ SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
64
+ SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
65
+ SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
66
+ SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
67
+ SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
68
+ })(SyntaxKind || (exports2.SyntaxKind = SyntaxKind = {}));
69
+ exports2.getLocation = parser.getLocation;
70
+ exports2.parse = parser.parse;
71
+ exports2.parseTree = parser.parseTree;
72
+ exports2.findNodeAtLocation = parser.findNodeAtLocation;
73
+ exports2.findNodeAtOffset = parser.findNodeAtOffset;
74
+ exports2.getNodePath = parser.getNodePath;
75
+ exports2.getNodeValue = parser.getNodeValue;
76
+ exports2.visit = parser.visit;
77
+ exports2.stripComments = parser.stripComments;
78
+ var ParseErrorCode;
79
+ (function(ParseErrorCode2) {
80
+ ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
81
+ ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
82
+ ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
83
+ ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
84
+ ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
85
+ ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
86
+ ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
87
+ ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
88
+ ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
89
+ ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
90
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
91
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
92
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
93
+ ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
94
+ ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
95
+ ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
96
+ })(ParseErrorCode || (exports2.ParseErrorCode = ParseErrorCode = {}));
97
+ function printParseErrorCode(code) {
98
+ switch (code) {
552
99
  case 1:
553
- if (!disallowComments) {
554
- handleError(11);
555
- }
556
- break;
100
+ return "InvalidSymbol";
557
101
  case 2:
558
- handleError(12);
559
- break;
102
+ return "InvalidNumberFormat";
103
+ case 3:
104
+ return "PropertyNameExpected";
105
+ case 4:
106
+ return "ValueExpected";
107
+ case 5:
108
+ return "ColonExpected";
560
109
  case 6:
561
- handleError(16);
562
- break;
563
- }
564
- switch (token) {
110
+ return "CommaExpected";
111
+ case 7:
112
+ return "CloseBraceExpected";
113
+ case 8:
114
+ return "CloseBracketExpected";
115
+ case 9:
116
+ return "EndOfFileExpected";
117
+ case 10:
118
+ return "InvalidCommentToken";
119
+ case 11:
120
+ return "UnexpectedEndOfComment";
565
121
  case 12:
122
+ return "UnexpectedEndOfString";
566
123
  case 13:
567
- if (disallowComments) {
568
- handleError(10);
569
- } else {
570
- onComment();
571
- }
572
- break;
573
- case 16:
574
- handleError(1);
575
- break;
576
- case 15:
124
+ return "UnexpectedEndOfNumber";
577
125
  case 14:
578
- break;
579
- default:
580
- return token;
581
- }
582
- }
583
- }
584
- function handleError(error, skipUntilAfter = [], skipUntil = []) {
585
- onError(error);
586
- if (skipUntilAfter.length + skipUntil.length > 0) {
587
- let token = _scanner.getToken();
588
- while (token !== 17) {
589
- if (skipUntilAfter.indexOf(token) !== -1) {
590
- scanNext();
591
- break;
592
- } else if (skipUntil.indexOf(token) !== -1) {
593
- break;
594
- }
595
- token = scanNext();
596
- }
597
- }
598
- }
599
- function parseString(isValue) {
600
- const value = _scanner.getTokenValue();
601
- if (isValue) {
602
- onLiteralValue(value);
603
- } else {
604
- onObjectProperty(value);
605
- _jsonPath.push(value);
606
- }
607
- scanNext();
608
- return true;
609
- }
610
- function parseLiteral() {
611
- switch (_scanner.getToken()) {
612
- case 11:
613
- const tokenValue = _scanner.getTokenValue();
614
- let value = Number(tokenValue);
615
- if (isNaN(value)) {
616
- handleError(2);
617
- value = 0;
618
- }
619
- onLiteralValue(value);
620
- break;
621
- case 7:
622
- onLiteralValue(null);
623
- break;
624
- case 8:
625
- onLiteralValue(true);
626
- break;
627
- case 9:
628
- onLiteralValue(false);
629
- break;
630
- default:
631
- return false;
632
- }
633
- scanNext();
634
- return true;
635
- }
636
- function parseProperty() {
637
- if (_scanner.getToken() !== 10) {
638
- handleError(3, [], [2, 5]);
639
- return false;
640
- }
641
- parseString(false);
642
- if (_scanner.getToken() === 6) {
643
- onSeparator(":");
644
- scanNext();
645
- if (!parseValue()) {
646
- handleError(4, [], [2, 5]);
647
- }
648
- } else {
649
- handleError(5, [], [2, 5]);
650
- }
651
- _jsonPath.pop();
652
- return true;
653
- }
654
- function parseObject() {
655
- onObjectBegin();
656
- scanNext();
657
- let needsComma = false;
658
- while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
659
- if (_scanner.getToken() === 5) {
660
- if (!needsComma) {
661
- handleError(4, [], []);
662
- }
663
- onSeparator(",");
664
- scanNext();
665
- if (_scanner.getToken() === 2 && allowTrailingComma) {
666
- break;
667
- }
668
- } else if (needsComma) {
669
- handleError(6, [], []);
670
- }
671
- if (!parseProperty()) {
672
- handleError(4, [], [2, 5]);
126
+ return "InvalidUnicode";
127
+ case 15:
128
+ return "InvalidEscapeCharacter";
129
+ case 16:
130
+ return "InvalidCharacter";
673
131
  }
674
- needsComma = true;
675
- }
676
- onObjectEnd();
677
- if (_scanner.getToken() !== 2) {
678
- handleError(7, [2], []);
679
- } else {
680
- scanNext();
681
- }
682
- return true;
683
- }
684
- function parseArray() {
685
- onArrayBegin();
686
- scanNext();
687
- let isFirstElement = true;
688
- let needsComma = false;
689
- while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
690
- if (_scanner.getToken() === 5) {
691
- if (!needsComma) {
692
- handleError(4, [], []);
132
+ return "<unknown ParseErrorCode>";
133
+ }
134
+ exports2.printParseErrorCode = printParseErrorCode;
135
+ function format(documentText, range, options) {
136
+ return formatter.format(documentText, range, options);
137
+ }
138
+ exports2.format = format;
139
+ function modify(text, path, value, options) {
140
+ return edit.setProperty(text, path, value, options);
141
+ }
142
+ exports2.modify = modify;
143
+ function applyEdits(text, edits) {
144
+ let sortedEdits = edits.slice(0).sort((a, b) => {
145
+ const diff = a.offset - b.offset;
146
+ if (diff === 0) {
147
+ return a.length - b.length;
693
148
  }
694
- onSeparator(",");
695
- scanNext();
696
- if (_scanner.getToken() === 4 && allowTrailingComma) {
697
- break;
149
+ return diff;
150
+ });
151
+ let lastModifiedOffset = text.length;
152
+ for (let i = sortedEdits.length - 1;i >= 0; i--) {
153
+ let e = sortedEdits[i];
154
+ if (e.offset + e.length <= lastModifiedOffset) {
155
+ text = edit.applyEdit(text, e);
156
+ } else {
157
+ throw new Error("Overlapping edit");
698
158
  }
699
- } else if (needsComma) {
700
- handleError(6, [], []);
701
- }
702
- if (isFirstElement) {
703
- _jsonPath.push(0);
704
- isFirstElement = false;
705
- } else {
706
- _jsonPath[_jsonPath.length - 1]++;
159
+ lastModifiedOffset = e.offset;
707
160
  }
708
- if (!parseValue()) {
709
- handleError(4, [], [4, 5]);
710
- }
711
- needsComma = true;
712
- }
713
- onArrayEnd();
714
- if (!isFirstElement) {
715
- _jsonPath.pop();
161
+ return text;
716
162
  }
717
- if (_scanner.getToken() !== 4) {
718
- handleError(8, [4], []);
719
- } else {
720
- scanNext();
721
- }
722
- return true;
723
- }
724
- function parseValue() {
725
- switch (_scanner.getToken()) {
726
- case 3:
727
- return parseArray();
728
- case 1:
729
- return parseObject();
730
- case 10:
731
- return parseString(true);
732
- default:
733
- return parseLiteral();
734
- }
735
- }
736
- scanNext();
737
- if (_scanner.getToken() === 17) {
738
- if (options.allowEmptyContent) {
739
- return true;
740
- }
741
- handleError(4, [], []);
742
- return false;
743
- }
744
- if (!parseValue()) {
745
- handleError(4, [], []);
746
- return false;
747
- }
748
- if (_scanner.getToken() !== 17) {
749
- handleError(9, [], []);
750
- }
751
- return true;
752
- }
753
-
754
- // node_modules/jsonc-parser/lib/esm/main.js
755
- var ScanError;
756
- (function(ScanError2) {
757
- ScanError2[ScanError2["None"] = 0] = "None";
758
- ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
759
- ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
760
- ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
761
- ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
762
- ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
763
- ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
764
- })(ScanError || (ScanError = {}));
765
- var SyntaxKind;
766
- (function(SyntaxKind2) {
767
- SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
768
- SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
769
- SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
770
- SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
771
- SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
772
- SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
773
- SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
774
- SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
775
- SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
776
- SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
777
- SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
778
- SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
779
- SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
780
- SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
781
- SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
782
- SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
783
- SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
784
- })(SyntaxKind || (SyntaxKind = {}));
785
- var parse2 = parse;
786
- var ParseErrorCode;
787
- (function(ParseErrorCode2) {
788
- ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
789
- ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
790
- ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
791
- ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
792
- ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
793
- ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
794
- ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
795
- ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
796
- ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
797
- ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
798
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
799
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
800
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
801
- ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
802
- ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
803
- ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
804
- })(ParseErrorCode || (ParseErrorCode = {}));
163
+ exports2.applyEdits = applyEdits;
164
+ });
165
+ });
805
166
 
806
167
  // src/index.ts
807
- import { resolve, normalize } from "path";
808
- import { homedir as osHomedir } from "os";
168
+ var import_jsonc_parser = __toESM(require_main(), 1);
169
+ import { resolve, normalize } from "node:path";
170
+ import { homedir as osHomedir } from "node:os";
809
171
  var LOG_FILE = "/tmp/opencode-dotenv.log";
810
172
  var LOAD_GUARD = "__opencodeDotenvLoaded";
811
173
  var VALID_ENV_KEY = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
@@ -844,6 +206,8 @@ function parseDotenv(content) {
844
206
  return result;
845
207
  }
846
208
  function parseValue(raw) {
209
+ if (typeof raw !== "string")
210
+ return "";
847
211
  let value = raw.trim();
848
212
  if (value.startsWith('"')) {
849
213
  const endQuote = findClosingQuote(value, '"');
@@ -933,9 +297,13 @@ async function loadConfig() {
933
297
  const file = Bun.file(configPath);
934
298
  if (await file.exists()) {
935
299
  const content = await file.text();
936
- const config = parse2(content, [], {
300
+ const config = import_jsonc_parser.parse(content, [], {
937
301
  allowTrailingComma: true
938
302
  });
303
+ if (!config || !Array.isArray(config.files)) {
304
+ logToFile("Invalid config format, using defaults");
305
+ return { files: [], load_cwd_env: true };
306
+ }
939
307
  loggingEnabled = config.logging?.enabled !== false;
940
308
  return config;
941
309
  }
@@ -945,32 +313,25 @@ async function loadConfig() {
945
313
  return { files: [], load_cwd_env: true };
946
314
  }
947
315
  async function loadDotenvFile(filePath, prefix) {
948
- const skipped = [];
949
316
  try {
950
317
  const file = Bun.file(filePath);
951
318
  if (!await file.exists()) {
952
319
  logToFile(`File not found: ${filePath}`);
953
- return { count: 0, success: false, skipped };
320
+ return { count: 0, success: false };
954
321
  }
955
322
  const content = await file.text();
956
323
  const envVars = parseDotenv(content);
957
- let count = 0;
958
324
  for (const [key, value] of Object.entries(envVars)) {
959
- if (!isValidEnvKey(key)) {
960
- skipped.push(key);
961
- continue;
962
- }
963
325
  const envKey = prefix ? `${prefix}${key}` : key;
964
326
  process.env[envKey] = value;
965
- count++;
966
327
  }
967
- return { count, success: true, skipped };
328
+ return { count: Object.keys(envVars).length, success: true };
968
329
  } catch (error) {
969
330
  logToFile(`Failed to load ${filePath}: ${error}`);
970
- return { count: 0, success: false, skipped };
331
+ return { count: 0, success: false };
971
332
  }
972
333
  }
973
- var DotEnvPlugin = async () => {
334
+ var DotEnvPlugin = async (_input) => {
974
335
  if (globalThis[LOAD_GUARD]) {
975
336
  return {};
976
337
  }
@@ -992,9 +353,6 @@ var DotEnvPlugin = async () => {
992
353
  totalFiles++;
993
354
  totalVars += result.count;
994
355
  logToFile(`Loaded ${result.count} vars`);
995
- if (result.skipped.length > 0) {
996
- logToFile(`Skipped invalid keys: ${result.skipped.join(", ")}`);
997
- }
998
356
  }
999
357
  }
1000
358
  if (config.load_cwd_env !== false) {
@@ -1005,14 +363,14 @@ var DotEnvPlugin = async () => {
1005
363
  totalFiles++;
1006
364
  totalVars += result.count;
1007
365
  logToFile(`Loaded ${result.count} vars from cwd`);
1008
- if (result.skipped.length > 0) {
1009
- logToFile(`Skipped invalid keys: ${result.skipped.join(", ")}`);
1010
- }
1011
366
  }
1012
367
  }
1013
368
  logToFile(`Plugin finished: ${totalFiles} files, ${totalVars} vars`);
1014
369
  await flushLogs();
1015
- return {};
370
+ return {
371
+ config: async () => {},
372
+ event: async () => {}
373
+ };
1016
374
  };
1017
375
  var src_default = DotEnvPlugin;
1018
376
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-dotenv",
3
- "version": "0.3.3",
3
+ "version": "0.3.7",
4
4
  "description": "OpenCode plugin to load .env files at startup",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -21,10 +21,16 @@
21
21
  "variables"
22
22
  ],
23
23
  "scripts": {
24
- "build": "bun build src/index.ts --outdir dist --target bun",
24
+ "build": "bun build src/index.ts --outdir dist --target node",
25
25
  "test": "bun test",
26
26
  "prepublishOnly": "bun run build"
27
27
  },
28
+ "exports": {
29
+ ".": {
30
+ "import": "./dist/index.js",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
28
34
  "files": [
29
35
  "dist/",
30
36
  "README.md",