elit 3.2.4 → 3.2.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/dist/config.js ADDED
@@ -0,0 +1,990 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // src/runtime.ts
34
+ var runtime, isNode, isBun, isDeno;
35
+ var init_runtime = __esm({
36
+ "src/runtime.ts"() {
37
+ "use strict";
38
+ runtime = (() => {
39
+ if (typeof Deno !== "undefined") return "deno";
40
+ if (typeof Bun !== "undefined") return "bun";
41
+ return "node";
42
+ })();
43
+ isNode = runtime === "node";
44
+ isBun = runtime === "bun";
45
+ isDeno = runtime === "deno";
46
+ }
47
+ });
48
+
49
+ // src/fs.ts
50
+ var fs_exports = {};
51
+ __export(fs_exports, {
52
+ appendFile: () => appendFile,
53
+ appendFileSync: () => appendFileSync,
54
+ copyFile: () => copyFile,
55
+ copyFileSync: () => copyFileSync,
56
+ default: () => fs_default,
57
+ exists: () => exists,
58
+ existsSync: () => existsSync,
59
+ getRuntime: () => getRuntime,
60
+ mkdir: () => mkdir,
61
+ mkdirSync: () => mkdirSync,
62
+ promises: () => promises,
63
+ readFile: () => readFile,
64
+ readFileSync: () => readFileSync,
65
+ readdir: () => readdir,
66
+ readdirSync: () => readdirSync,
67
+ realpath: () => realpath,
68
+ realpathSync: () => realpathSync,
69
+ rename: () => rename,
70
+ renameSync: () => renameSync,
71
+ rmdir: () => rmdir,
72
+ rmdirSync: () => rmdirSync,
73
+ stat: () => stat,
74
+ statSync: () => statSync,
75
+ unlink: () => unlink,
76
+ unlinkSync: () => unlinkSync,
77
+ writeFile: () => writeFile,
78
+ writeFileSync: () => writeFileSync
79
+ });
80
+ function parseOptions(options, defaultValue) {
81
+ return typeof options === "string" ? { encoding: options } : options || defaultValue;
82
+ }
83
+ function decodeContent(content, encoding) {
84
+ if (encoding) {
85
+ return new TextDecoder(encoding).decode(content);
86
+ }
87
+ return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
88
+ }
89
+ function dataToUint8Array(data) {
90
+ if (typeof data === "string") {
91
+ return new TextEncoder().encode(data);
92
+ }
93
+ if (data instanceof Buffer) {
94
+ return new Uint8Array(data);
95
+ }
96
+ return data;
97
+ }
98
+ function processDenoEntries(iterator, withFileTypes) {
99
+ const entries = [];
100
+ for (const entry of iterator) {
101
+ if (withFileTypes) {
102
+ entries.push(createDirentFromDenoEntry(entry));
103
+ } else {
104
+ entries.push(entry.name);
105
+ }
106
+ }
107
+ return entries;
108
+ }
109
+ async function processDenoEntriesAsync(iterator, withFileTypes) {
110
+ const entries = [];
111
+ for await (const entry of iterator) {
112
+ if (withFileTypes) {
113
+ entries.push(createDirentFromDenoEntry(entry));
114
+ } else {
115
+ entries.push(entry.name);
116
+ }
117
+ }
118
+ return entries;
119
+ }
120
+ async function readFile(path, options) {
121
+ const opts = parseOptions(options, {});
122
+ if (isNode) {
123
+ return fsPromises.readFile(path, opts);
124
+ } else if (isBun) {
125
+ const file = Bun.file(path);
126
+ const content = await file.arrayBuffer();
127
+ return decodeContent(content, opts.encoding);
128
+ } else if (isDeno) {
129
+ const content = await Deno.readFile(path);
130
+ return decodeContent(content, opts.encoding);
131
+ }
132
+ throw new Error("Unsupported runtime");
133
+ }
134
+ function readFileSync(path, options) {
135
+ const opts = parseOptions(options, {});
136
+ if (isNode) {
137
+ return fs.readFileSync(path, opts);
138
+ } else if (isBun) {
139
+ const file = Bun.file(path);
140
+ const content = file.arrayBuffer();
141
+ return decodeContent(content, opts.encoding);
142
+ } else if (isDeno) {
143
+ const content = Deno.readFileSync(path);
144
+ return decodeContent(content, opts.encoding);
145
+ }
146
+ throw new Error("Unsupported runtime");
147
+ }
148
+ async function writeFile(path, data, options) {
149
+ const opts = parseOptions(options, {});
150
+ if (isNode) {
151
+ return fsPromises.writeFile(path, data, opts);
152
+ } else if (isBun) {
153
+ await Bun.write(path, data);
154
+ } else if (isDeno) {
155
+ await Deno.writeFile(path, dataToUint8Array(data));
156
+ }
157
+ }
158
+ function writeFileSync(path, data, options) {
159
+ const opts = parseOptions(options, {});
160
+ if (isNode) {
161
+ fs.writeFileSync(path, data, opts);
162
+ } else if (isBun) {
163
+ Bun.write(path, data);
164
+ } else if (isDeno) {
165
+ Deno.writeFileSync(path, dataToUint8Array(data));
166
+ }
167
+ }
168
+ async function appendFile(path, data, options) {
169
+ const opts = parseOptions(options, {});
170
+ if (isNode) {
171
+ return fsPromises.appendFile(path, data, opts);
172
+ } else {
173
+ if (await exists(path)) {
174
+ const existing = await readFile(path);
175
+ const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
176
+ await writeFile(path, combined, opts);
177
+ } else {
178
+ await writeFile(path, data, opts);
179
+ }
180
+ }
181
+ }
182
+ function appendFileSync(path, data, options) {
183
+ const opts = parseOptions(options, {});
184
+ if (isNode) {
185
+ fs.appendFileSync(path, data, opts);
186
+ } else {
187
+ if (existsSync(path)) {
188
+ const existing = readFileSync(path);
189
+ const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
190
+ writeFileSync(path, combined, opts);
191
+ } else {
192
+ writeFileSync(path, data, opts);
193
+ }
194
+ }
195
+ }
196
+ async function exists(path) {
197
+ try {
198
+ await stat(path);
199
+ return true;
200
+ } catch {
201
+ return false;
202
+ }
203
+ }
204
+ function existsSync(path) {
205
+ try {
206
+ statSync(path);
207
+ return true;
208
+ } catch {
209
+ return false;
210
+ }
211
+ }
212
+ async function stat(path) {
213
+ if (isNode) {
214
+ return fsPromises.stat(path);
215
+ } else if (isBun) {
216
+ const file = Bun.file(path);
217
+ const size = file.size;
218
+ const exists2 = await file.exists();
219
+ if (!exists2) {
220
+ throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
221
+ }
222
+ return createStatsObject(path, size, false);
223
+ } else if (isDeno) {
224
+ const info = await Deno.stat(path);
225
+ return createStatsFromDenoFileInfo(info);
226
+ }
227
+ throw new Error("Unsupported runtime");
228
+ }
229
+ function statSync(path) {
230
+ if (isNode) {
231
+ return fs.statSync(path);
232
+ } else if (isBun) {
233
+ const file = Bun.file(path);
234
+ const size = file.size;
235
+ try {
236
+ file.arrayBuffer();
237
+ } catch {
238
+ throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
239
+ }
240
+ return createStatsObject(path, size, false);
241
+ } else if (isDeno) {
242
+ const info = Deno.statSync(path);
243
+ return createStatsFromDenoFileInfo(info);
244
+ }
245
+ throw new Error("Unsupported runtime");
246
+ }
247
+ async function mkdir(path, options) {
248
+ const opts = typeof options === "number" ? { mode: options } : options || {};
249
+ if (isNode) {
250
+ await fsPromises.mkdir(path, opts);
251
+ } else if (isBun) {
252
+ await Deno.mkdir(path, { recursive: opts.recursive });
253
+ } else if (isDeno) {
254
+ await Deno.mkdir(path, { recursive: opts.recursive });
255
+ }
256
+ }
257
+ function mkdirSync(path, options) {
258
+ const opts = typeof options === "number" ? { mode: options } : options || {};
259
+ if (isNode) {
260
+ fs.mkdirSync(path, opts);
261
+ } else if (isBun) {
262
+ Deno.mkdirSync(path, { recursive: opts.recursive });
263
+ } else if (isDeno) {
264
+ Deno.mkdirSync(path, { recursive: opts.recursive });
265
+ }
266
+ }
267
+ async function readdir(path, options) {
268
+ const opts = parseOptions(options, {});
269
+ if (isNode) {
270
+ return fsPromises.readdir(path, opts);
271
+ } else if (isBunOrDeno) {
272
+ return processDenoEntriesAsync(Deno.readDir(path), opts.withFileTypes);
273
+ }
274
+ throw new Error("Unsupported runtime");
275
+ }
276
+ function readdirSync(path, options) {
277
+ const opts = parseOptions(options, {});
278
+ if (isNode) {
279
+ return fs.readdirSync(path, opts);
280
+ } else if (isBunOrDeno) {
281
+ return processDenoEntries(Deno.readDirSync(path), opts.withFileTypes);
282
+ }
283
+ throw new Error("Unsupported runtime");
284
+ }
285
+ async function unlink(path) {
286
+ if (isNode) {
287
+ return fsPromises.unlink(path);
288
+ } else if (isBun) {
289
+ await Deno.remove(path);
290
+ } else if (isDeno) {
291
+ await Deno.remove(path);
292
+ }
293
+ }
294
+ function unlinkSync(path) {
295
+ if (isNode) {
296
+ fs.unlinkSync(path);
297
+ } else if (isBun) {
298
+ Deno.removeSync(path);
299
+ } else if (isDeno) {
300
+ Deno.removeSync(path);
301
+ }
302
+ }
303
+ async function rmdir(path, options) {
304
+ if (isNode) {
305
+ return fsPromises.rmdir(path, options);
306
+ } else if (isBun) {
307
+ await Deno.remove(path, { recursive: options?.recursive });
308
+ } else if (isDeno) {
309
+ await Deno.remove(path, { recursive: options?.recursive });
310
+ }
311
+ }
312
+ function rmdirSync(path, options) {
313
+ if (isNode) {
314
+ fs.rmdirSync(path, options);
315
+ } else if (isBun) {
316
+ Deno.removeSync(path, { recursive: options?.recursive });
317
+ } else if (isDeno) {
318
+ Deno.removeSync(path, { recursive: options?.recursive });
319
+ }
320
+ }
321
+ async function rename(oldPath, newPath) {
322
+ if (isNode) {
323
+ return fsPromises.rename(oldPath, newPath);
324
+ } else if (isBun) {
325
+ await Deno.rename(oldPath, newPath);
326
+ } else if (isDeno) {
327
+ await Deno.rename(oldPath, newPath);
328
+ }
329
+ }
330
+ function renameSync(oldPath, newPath) {
331
+ if (isNode) {
332
+ fs.renameSync(oldPath, newPath);
333
+ } else if (isBun) {
334
+ Deno.renameSync(oldPath, newPath);
335
+ } else if (isDeno) {
336
+ Deno.renameSync(oldPath, newPath);
337
+ }
338
+ }
339
+ async function copyFile(src, dest, flags) {
340
+ if (isNode) {
341
+ return fsPromises.copyFile(src, dest, flags);
342
+ } else if (isBun) {
343
+ await Deno.copyFile(src, dest);
344
+ } else if (isDeno) {
345
+ await Deno.copyFile(src, dest);
346
+ }
347
+ }
348
+ function copyFileSync(src, dest, flags) {
349
+ if (isNode) {
350
+ fs.copyFileSync(src, dest, flags);
351
+ } else if (isBun) {
352
+ Deno.copyFileSync(src, dest);
353
+ } else if (isDeno) {
354
+ Deno.copyFileSync(src, dest);
355
+ }
356
+ }
357
+ async function realpath(path, options) {
358
+ if (isNode) {
359
+ return fsPromises.realpath(path, options);
360
+ } else if (isBun) {
361
+ const fs2 = require("fs/promises");
362
+ return fs2.realpath(path, options);
363
+ } else if (isDeno) {
364
+ return await Deno.realPath(path);
365
+ }
366
+ return path;
367
+ }
368
+ function realpathSync(path, options) {
369
+ if (isNode) {
370
+ return fs.realpathSync(path, options);
371
+ } else if (isBun) {
372
+ const fs2 = require("fs");
373
+ return fs2.realpathSync(path, options);
374
+ } else if (isDeno) {
375
+ return Deno.realPathSync(path);
376
+ }
377
+ return path;
378
+ }
379
+ function createStatsObject(_path, size, isDir) {
380
+ const now = Date.now();
381
+ return {
382
+ isFile: () => !isDir,
383
+ isDirectory: () => isDir,
384
+ isBlockDevice: () => false,
385
+ isCharacterDevice: () => false,
386
+ isSymbolicLink: () => false,
387
+ isFIFO: () => false,
388
+ isSocket: () => false,
389
+ dev: 0,
390
+ ino: 0,
391
+ mode: isDir ? 16877 : 33188,
392
+ nlink: 1,
393
+ uid: 0,
394
+ gid: 0,
395
+ rdev: 0,
396
+ size,
397
+ blksize: 4096,
398
+ blocks: Math.ceil(size / 512),
399
+ atimeMs: now,
400
+ mtimeMs: now,
401
+ ctimeMs: now,
402
+ birthtimeMs: now,
403
+ atime: new Date(now),
404
+ mtime: new Date(now),
405
+ ctime: new Date(now),
406
+ birthtime: new Date(now)
407
+ };
408
+ }
409
+ function createStatsFromDenoFileInfo(info) {
410
+ return {
411
+ isFile: () => info.isFile,
412
+ isDirectory: () => info.isDirectory,
413
+ isBlockDevice: () => false,
414
+ isCharacterDevice: () => false,
415
+ isSymbolicLink: () => info.isSymlink || false,
416
+ isFIFO: () => false,
417
+ isSocket: () => false,
418
+ dev: info.dev || 0,
419
+ ino: info.ino || 0,
420
+ mode: info.mode || 0,
421
+ nlink: info.nlink || 1,
422
+ uid: info.uid || 0,
423
+ gid: info.gid || 0,
424
+ rdev: 0,
425
+ size: info.size,
426
+ blksize: info.blksize || 4096,
427
+ blocks: info.blocks || Math.ceil(info.size / 512),
428
+ atimeMs: info.atime?.getTime() || Date.now(),
429
+ mtimeMs: info.mtime?.getTime() || Date.now(),
430
+ ctimeMs: info.birthtime?.getTime() || Date.now(),
431
+ birthtimeMs: info.birthtime?.getTime() || Date.now(),
432
+ atime: info.atime || /* @__PURE__ */ new Date(),
433
+ mtime: info.mtime || /* @__PURE__ */ new Date(),
434
+ ctime: info.birthtime || /* @__PURE__ */ new Date(),
435
+ birthtime: info.birthtime || /* @__PURE__ */ new Date()
436
+ };
437
+ }
438
+ function createDirentFromDenoEntry(entry) {
439
+ return {
440
+ name: entry.name,
441
+ isFile: () => entry.isFile,
442
+ isDirectory: () => entry.isDirectory,
443
+ isBlockDevice: () => false,
444
+ isCharacterDevice: () => false,
445
+ isSymbolicLink: () => entry.isSymlink || false,
446
+ isFIFO: () => false,
447
+ isSocket: () => false
448
+ };
449
+ }
450
+ function getRuntime() {
451
+ return runtime;
452
+ }
453
+ var isBunOrDeno, fs, fsPromises, promises, fs_default;
454
+ var init_fs = __esm({
455
+ "src/fs.ts"() {
456
+ "use strict";
457
+ init_runtime();
458
+ isBunOrDeno = isBun || isDeno;
459
+ if (isNode) {
460
+ fs = require("fs");
461
+ fsPromises = require("fs/promises");
462
+ }
463
+ promises = {
464
+ readFile,
465
+ writeFile,
466
+ appendFile,
467
+ stat,
468
+ mkdir,
469
+ readdir,
470
+ unlink,
471
+ rmdir,
472
+ rename,
473
+ copyFile,
474
+ realpath
475
+ };
476
+ fs_default = {
477
+ readFile,
478
+ readFileSync,
479
+ writeFile,
480
+ writeFileSync,
481
+ appendFile,
482
+ appendFileSync,
483
+ exists,
484
+ existsSync,
485
+ stat,
486
+ statSync,
487
+ mkdir,
488
+ mkdirSync,
489
+ readdir,
490
+ readdirSync,
491
+ unlink,
492
+ unlinkSync,
493
+ rmdir,
494
+ rmdirSync,
495
+ rename,
496
+ renameSync,
497
+ copyFile,
498
+ copyFileSync,
499
+ realpath,
500
+ realpathSync,
501
+ promises,
502
+ getRuntime
503
+ };
504
+ }
505
+ });
506
+
507
+ // src/path.ts
508
+ var path_exports = {};
509
+ __export(path_exports, {
510
+ basename: () => basename,
511
+ default: () => path_default,
512
+ delimiter: () => delimiter,
513
+ dirname: () => dirname,
514
+ extname: () => extname,
515
+ format: () => format,
516
+ getRuntime: () => getRuntime2,
517
+ isAbsolute: () => isAbsolute,
518
+ join: () => join,
519
+ normalize: () => normalize,
520
+ parse: () => parse,
521
+ posix: () => posix,
522
+ relative: () => relative,
523
+ resolve: () => resolve,
524
+ sep: () => sep,
525
+ toNamespacedPath: () => toNamespacedPath,
526
+ win32: () => win32
527
+ });
528
+ function getSeparator(isWin) {
529
+ return isWin ? "\\" : "/";
530
+ }
531
+ function getCwd() {
532
+ if (isNode || isBun) {
533
+ return process.cwd();
534
+ } else if (isDeno) {
535
+ return Deno.cwd();
536
+ }
537
+ return "/";
538
+ }
539
+ function findLastSeparator(path) {
540
+ return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
541
+ }
542
+ function createPathOps(isWin) {
543
+ return {
544
+ sep: getSeparator(isWin),
545
+ delimiter: isWin ? ";" : ":",
546
+ normalize: (path) => normalizePath(path, isWin),
547
+ join: (...paths) => joinPaths(paths, isWin),
548
+ resolve: (...paths) => resolvePaths(paths, isWin),
549
+ isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
550
+ relative: (from, to) => relativePath(from, to, isWin),
551
+ dirname: (path) => getDirname(path, isWin),
552
+ basename: (path, ext) => getBasename(path, ext, isWin),
553
+ extname: (path) => getExtname(path),
554
+ parse: (path) => parsePath(path, isWin),
555
+ format: (pathObject) => formatPath(pathObject, isWin)
556
+ };
557
+ }
558
+ function isAbsolutePosix(path) {
559
+ return path.length > 0 && path[0] === "/";
560
+ }
561
+ function isAbsoluteWin(path) {
562
+ const len = path.length;
563
+ if (len === 0) return false;
564
+ const code = path.charCodeAt(0);
565
+ if (code === 47 || code === 92) {
566
+ return true;
567
+ }
568
+ if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
569
+ if (len > 2 && path.charCodeAt(1) === 58) {
570
+ const code2 = path.charCodeAt(2);
571
+ if (code2 === 47 || code2 === 92) {
572
+ return true;
573
+ }
574
+ }
575
+ }
576
+ return false;
577
+ }
578
+ function normalizePath(path, isWin) {
579
+ if (path.length === 0) return ".";
580
+ const separator = getSeparator(isWin);
581
+ const isAbsolute2 = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
582
+ const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
583
+ let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
584
+ const parts = normalized.split(separator);
585
+ const result = [];
586
+ for (let i = 0; i < parts.length; i++) {
587
+ const part = parts[i];
588
+ if (part === "" || part === ".") {
589
+ if (i === 0 && isAbsolute2) result.push("");
590
+ continue;
591
+ }
592
+ if (part === "..") {
593
+ if (result.length > 0 && result[result.length - 1] !== "..") {
594
+ if (!(result.length === 1 && result[0] === "")) {
595
+ result.pop();
596
+ }
597
+ } else if (!isAbsolute2) {
598
+ result.push("..");
599
+ }
600
+ } else {
601
+ result.push(part);
602
+ }
603
+ }
604
+ let final = result.join(separator);
605
+ if (final.length === 0) {
606
+ return isAbsolute2 ? separator : ".";
607
+ }
608
+ if (trailingSeparator && final[final.length - 1] !== separator) {
609
+ final += separator;
610
+ }
611
+ return final;
612
+ }
613
+ function joinPaths(paths, isWin) {
614
+ if (paths.length === 0) return ".";
615
+ const separator = getSeparator(isWin);
616
+ let joined = "";
617
+ for (let i = 0; i < paths.length; i++) {
618
+ const path = paths[i];
619
+ if (path && path.length > 0) {
620
+ if (joined.length === 0) {
621
+ joined = path;
622
+ } else {
623
+ joined += separator + path;
624
+ }
625
+ }
626
+ }
627
+ if (joined.length === 0) return ".";
628
+ return normalizePath(joined, isWin);
629
+ }
630
+ function resolvePaths(paths, isWin) {
631
+ const separator = getSeparator(isWin);
632
+ let resolved = "";
633
+ let isAbsolute2 = false;
634
+ for (let i = paths.length - 1; i >= 0 && !isAbsolute2; i--) {
635
+ const path = paths[i];
636
+ if (path && path.length > 0) {
637
+ resolved = path + (resolved.length > 0 ? separator + resolved : "");
638
+ isAbsolute2 = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
639
+ }
640
+ }
641
+ if (!isAbsolute2) {
642
+ const cwd = getCwd();
643
+ resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
644
+ }
645
+ return normalizePath(resolved, isWin);
646
+ }
647
+ function relativePath(from, to, isWin) {
648
+ from = resolvePaths([from], isWin);
649
+ to = resolvePaths([to], isWin);
650
+ if (from === to) return "";
651
+ const separator = getSeparator(isWin);
652
+ const fromParts = from.split(separator).filter((p) => p.length > 0);
653
+ const toParts = to.split(separator).filter((p) => p.length > 0);
654
+ let commonLength = 0;
655
+ const minLength = Math.min(fromParts.length, toParts.length);
656
+ for (let i = 0; i < minLength; i++) {
657
+ if (fromParts[i] === toParts[i]) {
658
+ commonLength++;
659
+ } else {
660
+ break;
661
+ }
662
+ }
663
+ const upCount = fromParts.length - commonLength;
664
+ const result = [];
665
+ for (let i = 0; i < upCount; i++) {
666
+ result.push("..");
667
+ }
668
+ for (let i = commonLength; i < toParts.length; i++) {
669
+ result.push(toParts[i]);
670
+ }
671
+ return result.join(separator) || ".";
672
+ }
673
+ function getDirname(path, isWin) {
674
+ if (path.length === 0) return ".";
675
+ const separator = getSeparator(isWin);
676
+ const normalized = normalizePath(path, isWin);
677
+ const lastSepIndex = normalized.lastIndexOf(separator);
678
+ if (lastSepIndex === -1) return ".";
679
+ if (lastSepIndex === 0) return separator;
680
+ return normalized.slice(0, lastSepIndex);
681
+ }
682
+ function getBasename(path, ext, isWin) {
683
+ if (path.length === 0) return "";
684
+ const lastSepIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
685
+ let base = lastSepIndex === -1 ? path : path.slice(lastSepIndex + 1);
686
+ if (ext && base.endsWith(ext)) {
687
+ base = base.slice(0, base.length - ext.length);
688
+ }
689
+ return base;
690
+ }
691
+ function getExtname(path) {
692
+ const lastDotIndex = path.lastIndexOf(".");
693
+ const lastSepIndex = findLastSeparator(path);
694
+ if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path.length - 1) {
695
+ return "";
696
+ }
697
+ return path.slice(lastDotIndex);
698
+ }
699
+ function parsePath(path, isWin) {
700
+ let root = "";
701
+ if (isWin) {
702
+ if (path.length >= 2 && path[1] === ":") {
703
+ root = path.slice(0, 2);
704
+ if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
705
+ root += "\\";
706
+ }
707
+ } else if (path[0] === "\\" || path[0] === "/") {
708
+ root = "\\";
709
+ }
710
+ } else {
711
+ if (path[0] === "/") {
712
+ root = "/";
713
+ }
714
+ }
715
+ const dir = getDirname(path, isWin);
716
+ const base = getBasename(path, void 0, isWin);
717
+ const ext = getExtname(path);
718
+ const name = ext ? base.slice(0, base.length - ext.length) : base;
719
+ return { root, dir, base, ext, name };
720
+ }
721
+ function formatPath(pathObject, isWin) {
722
+ const separator = getSeparator(isWin);
723
+ const dir = pathObject.dir || pathObject.root || "";
724
+ const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
725
+ if (!dir) return base;
726
+ if (dir === pathObject.root) return dir + base;
727
+ return dir + separator + base;
728
+ }
729
+ function normalize(path) {
730
+ return normalizePath(path, isWindows);
731
+ }
732
+ function join(...paths) {
733
+ return joinPaths(paths, isWindows);
734
+ }
735
+ function resolve(...paths) {
736
+ return resolvePaths(paths, isWindows);
737
+ }
738
+ function isAbsolute(path) {
739
+ return isWindows ? win32.isAbsolute(path) : posix.isAbsolute(path);
740
+ }
741
+ function relative(from, to) {
742
+ return relativePath(from, to, isWindows);
743
+ }
744
+ function dirname(path) {
745
+ return getDirname(path, isWindows);
746
+ }
747
+ function basename(path, ext) {
748
+ return getBasename(path, ext, isWindows);
749
+ }
750
+ function extname(path) {
751
+ return getExtname(path);
752
+ }
753
+ function parse(path) {
754
+ return parsePath(path, isWindows);
755
+ }
756
+ function format(pathObject) {
757
+ return formatPath(pathObject, isWindows);
758
+ }
759
+ function toNamespacedPath(path) {
760
+ if (!isWindows || path.length === 0) return path;
761
+ const resolved = resolve(path);
762
+ if (resolved.length >= 3) {
763
+ if (resolved[0] === "\\") {
764
+ if (resolved[1] === "\\" && resolved[2] !== "?") {
765
+ return "\\\\?\\UNC\\" + resolved.slice(2);
766
+ }
767
+ } else if (resolved[1] === ":" && resolved[2] === "\\") {
768
+ return "\\\\?\\" + resolved;
769
+ }
770
+ }
771
+ return path;
772
+ }
773
+ function getRuntime2() {
774
+ return runtime;
775
+ }
776
+ var isWindows, sep, delimiter, posix, win32, path_default;
777
+ var init_path = __esm({
778
+ "src/path.ts"() {
779
+ "use strict";
780
+ init_runtime();
781
+ isWindows = (() => {
782
+ if (isNode) {
783
+ return process.platform === "win32";
784
+ } else if (isDeno) {
785
+ return Deno.build.os === "windows";
786
+ }
787
+ return typeof process !== "undefined" && process.platform === "win32";
788
+ })();
789
+ sep = isWindows ? "\\" : "/";
790
+ delimiter = isWindows ? ";" : ":";
791
+ posix = createPathOps(false);
792
+ win32 = createPathOps(true);
793
+ path_default = {
794
+ sep,
795
+ delimiter,
796
+ normalize,
797
+ join,
798
+ resolve,
799
+ isAbsolute,
800
+ relative,
801
+ dirname,
802
+ basename,
803
+ extname,
804
+ parse,
805
+ format,
806
+ toNamespacedPath,
807
+ posix,
808
+ win32,
809
+ getRuntime: getRuntime2
810
+ };
811
+ }
812
+ });
813
+
814
+ // src/config.ts
815
+ var config_exports = {};
816
+ __export(config_exports, {
817
+ defineConfig: () => defineConfig,
818
+ loadConfig: () => loadConfig,
819
+ loadEnv: () => loadEnv,
820
+ mergeConfig: () => mergeConfig
821
+ });
822
+ module.exports = __toCommonJS(config_exports);
823
+ init_fs();
824
+ init_path();
825
+ function readFileAsString(filePath) {
826
+ const contentBuffer = readFileSync(filePath, "utf-8");
827
+ return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
828
+ }
829
+ function removeQuotes(value) {
830
+ const trimmed = value.trim();
831
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
832
+ return trimmed.slice(1, -1);
833
+ }
834
+ return trimmed;
835
+ }
836
+ async function importConfigModule(configPath) {
837
+ const { pathToFileURL } = await import("url");
838
+ const configModule = await import(pathToFileURL(configPath).href);
839
+ return configModule.default || configModule;
840
+ }
841
+ async function safeCleanup(filePath) {
842
+ try {
843
+ const { unlinkSync: unlinkSync2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
844
+ unlinkSync2(filePath);
845
+ } catch {
846
+ }
847
+ }
848
+ function defineConfig(config) {
849
+ return config;
850
+ }
851
+ var CONFIG_FILES = [
852
+ "elit.config.ts",
853
+ "elit.config.js",
854
+ "elit.config.mjs",
855
+ "elit.config.cjs",
856
+ "elit.config.json"
857
+ ];
858
+ function loadEnv(mode = "development", cwd = process.cwd()) {
859
+ const env = { MODE: mode };
860
+ const envFiles = [
861
+ `.env.${mode}.local`,
862
+ `.env.${mode}`,
863
+ `.env.local`,
864
+ `.env`
865
+ ];
866
+ for (const file of envFiles) {
867
+ const filePath = resolve(cwd, file);
868
+ if (existsSync(filePath)) {
869
+ const content = readFileAsString(filePath);
870
+ const lines = content.split("\n");
871
+ for (const line of lines) {
872
+ const trimmed = line.trim();
873
+ if (!trimmed || trimmed.startsWith("#")) continue;
874
+ const match = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/);
875
+ if (match) {
876
+ const [, key, value] = match;
877
+ const cleanValue = removeQuotes(value);
878
+ if (!(key in env)) {
879
+ env[key] = cleanValue;
880
+ }
881
+ }
882
+ }
883
+ }
884
+ }
885
+ return env;
886
+ }
887
+ async function loadConfig(cwd = process.cwd()) {
888
+ for (const configFile of CONFIG_FILES) {
889
+ const configPath = resolve(cwd, configFile);
890
+ if (existsSync(configPath)) {
891
+ try {
892
+ return await loadConfigFile(configPath);
893
+ } catch (error) {
894
+ console.error(`Error loading config file: ${configFile}`);
895
+ console.error(error);
896
+ throw error;
897
+ }
898
+ }
899
+ }
900
+ return null;
901
+ }
902
+ async function loadConfigFile(configPath) {
903
+ const ext = configPath.split(".").pop();
904
+ if (ext === "json") {
905
+ const content = readFileAsString(configPath);
906
+ return JSON.parse(content);
907
+ } else if (ext === "ts") {
908
+ try {
909
+ const { build } = await import("esbuild");
910
+ const { join: join2, dirname: dirname2 } = await Promise.resolve().then(() => (init_path(), path_exports));
911
+ const configDir = dirname2(configPath);
912
+ const tempFile = join2(configDir, `.elit-config-${Date.now()}.mjs`);
913
+ const externalAllPlugin = {
914
+ name: "external-all",
915
+ setup(build2) {
916
+ build2.onResolve({ filter: /.*/ }, (args) => {
917
+ if (args.path.startsWith("./") || args.path.startsWith("../")) {
918
+ return void 0;
919
+ }
920
+ if (args.path.includes("node_modules") || args.resolveDir?.includes("node_modules")) {
921
+ return { path: args.path, external: true };
922
+ }
923
+ const knownPackages = ["esbuild", "elit", "fs", "path", "os", "vm", "crypto", "http", "https", "url", "bun"];
924
+ if (knownPackages.some((pkg) => args.path === pkg || args.path.startsWith(pkg + "/"))) {
925
+ return { path: args.path, external: true };
926
+ }
927
+ if (args.resolveDir?.includes("elit/dist") || args.path.includes("elit/dist")) {
928
+ return { path: args.path, external: true };
929
+ }
930
+ return void 0;
931
+ });
932
+ }
933
+ };
934
+ await build({
935
+ entryPoints: [configPath],
936
+ bundle: true,
937
+ format: "esm",
938
+ platform: "node",
939
+ outfile: tempFile,
940
+ write: true,
941
+ target: "es2020",
942
+ plugins: [externalAllPlugin],
943
+ // External Node.js built-ins and runtime-specific packages
944
+ external: [
945
+ "node:*",
946
+ "fs",
947
+ "path",
948
+ "os",
949
+ "vm",
950
+ "crypto",
951
+ "http",
952
+ "https",
953
+ "bun",
954
+ "bun:*",
955
+ "deno",
956
+ "deno:*"
957
+ ],
958
+ // Use the config directory as the working directory for resolution
959
+ absWorkingDir: configDir
960
+ });
961
+ const config = await importConfigModule(tempFile);
962
+ await safeCleanup(tempFile);
963
+ return config;
964
+ } catch (error) {
965
+ console.error("Failed to load TypeScript config file.");
966
+ console.error("You can use a .js, .mjs, or .json config file instead.");
967
+ throw error;
968
+ }
969
+ } else {
970
+ return await importConfigModule(configPath);
971
+ }
972
+ }
973
+ function mergeConfig(config, cliArgs) {
974
+ if (!config) {
975
+ return cliArgs;
976
+ }
977
+ return {
978
+ ...config,
979
+ ...Object.fromEntries(
980
+ Object.entries(cliArgs).filter(([_, v]) => v !== void 0)
981
+ )
982
+ };
983
+ }
984
+ // Annotate the CommonJS export names for ESM import in node:
985
+ 0 && (module.exports = {
986
+ defineConfig,
987
+ loadConfig,
988
+ loadEnv,
989
+ mergeConfig
990
+ });