elit 3.2.1 → 3.2.3

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/cli.js CHANGED
@@ -121,205 +121,205 @@ async function processDenoEntriesAsync(iterator, withFileTypes) {
121
121
  }
122
122
  return entries;
123
123
  }
124
- async function readFile(path2, options) {
124
+ async function readFile(path, options) {
125
125
  const opts = parseOptions(options, {});
126
126
  if (isNode) {
127
- return fsPromises.readFile(path2, opts);
127
+ return fsPromises.readFile(path, opts);
128
128
  } else if (isBun) {
129
- const file = Bun.file(path2);
129
+ const file = Bun.file(path);
130
130
  const content = await file.arrayBuffer();
131
131
  return decodeContent(content, opts.encoding);
132
132
  } else if (isDeno) {
133
- const content = await Deno.readFile(path2);
133
+ const content = await Deno.readFile(path);
134
134
  return decodeContent(content, opts.encoding);
135
135
  }
136
136
  throw new Error("Unsupported runtime");
137
137
  }
138
- function readFileSync(path2, options) {
138
+ function readFileSync(path, options) {
139
139
  const opts = parseOptions(options, {});
140
140
  if (isNode) {
141
- return fs.readFileSync(path2, opts);
141
+ return fs.readFileSync(path, opts);
142
142
  } else if (isBun) {
143
- const file = Bun.file(path2);
143
+ const file = Bun.file(path);
144
144
  const content = file.arrayBuffer();
145
145
  return decodeContent(content, opts.encoding);
146
146
  } else if (isDeno) {
147
- const content = Deno.readFileSync(path2);
147
+ const content = Deno.readFileSync(path);
148
148
  return decodeContent(content, opts.encoding);
149
149
  }
150
150
  throw new Error("Unsupported runtime");
151
151
  }
152
- async function writeFile(path2, data, options) {
152
+ async function writeFile(path, data, options) {
153
153
  const opts = parseOptions(options, {});
154
154
  if (isNode) {
155
- return fsPromises.writeFile(path2, data, opts);
155
+ return fsPromises.writeFile(path, data, opts);
156
156
  } else if (isBun) {
157
- await Bun.write(path2, data);
157
+ await Bun.write(path, data);
158
158
  } else if (isDeno) {
159
- await Deno.writeFile(path2, dataToUint8Array(data));
159
+ await Deno.writeFile(path, dataToUint8Array(data));
160
160
  }
161
161
  }
162
- function writeFileSync(path2, data, options) {
162
+ function writeFileSync(path, data, options) {
163
163
  const opts = parseOptions(options, {});
164
164
  if (isNode) {
165
- fs.writeFileSync(path2, data, opts);
165
+ fs.writeFileSync(path, data, opts);
166
166
  } else if (isBun) {
167
- Bun.write(path2, data);
167
+ Bun.write(path, data);
168
168
  } else if (isDeno) {
169
- Deno.writeFileSync(path2, dataToUint8Array(data));
169
+ Deno.writeFileSync(path, dataToUint8Array(data));
170
170
  }
171
171
  }
172
- async function appendFile(path2, data, options) {
172
+ async function appendFile(path, data, options) {
173
173
  const opts = parseOptions(options, {});
174
174
  if (isNode) {
175
- return fsPromises.appendFile(path2, data, opts);
175
+ return fsPromises.appendFile(path, data, opts);
176
176
  } else {
177
- if (await exists(path2)) {
178
- const existing = await readFile(path2);
177
+ if (await exists(path)) {
178
+ const existing = await readFile(path);
179
179
  const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
180
- await writeFile(path2, combined, opts);
180
+ await writeFile(path, combined, opts);
181
181
  } else {
182
- await writeFile(path2, data, opts);
182
+ await writeFile(path, data, opts);
183
183
  }
184
184
  }
185
185
  }
186
- function appendFileSync(path2, data, options) {
186
+ function appendFileSync(path, data, options) {
187
187
  const opts = parseOptions(options, {});
188
188
  if (isNode) {
189
- fs.appendFileSync(path2, data, opts);
189
+ fs.appendFileSync(path, data, opts);
190
190
  } else {
191
- if (existsSync(path2)) {
192
- const existing = readFileSync(path2);
191
+ if (existsSync(path)) {
192
+ const existing = readFileSync(path);
193
193
  const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
194
- writeFileSync(path2, combined, opts);
194
+ writeFileSync(path, combined, opts);
195
195
  } else {
196
- writeFileSync(path2, data, opts);
196
+ writeFileSync(path, data, opts);
197
197
  }
198
198
  }
199
199
  }
200
- async function exists(path2) {
200
+ async function exists(path) {
201
201
  try {
202
- await stat(path2);
202
+ await stat(path);
203
203
  return true;
204
204
  } catch {
205
205
  return false;
206
206
  }
207
207
  }
208
- function existsSync(path2) {
208
+ function existsSync(path) {
209
209
  try {
210
- statSync(path2);
210
+ statSync(path);
211
211
  return true;
212
212
  } catch {
213
213
  return false;
214
214
  }
215
215
  }
216
- async function stat(path2) {
216
+ async function stat(path) {
217
217
  if (isNode) {
218
- return fsPromises.stat(path2);
218
+ return fsPromises.stat(path);
219
219
  } else if (isBun) {
220
- const file = Bun.file(path2);
220
+ const file = Bun.file(path);
221
221
  const size = file.size;
222
222
  const exists2 = await file.exists();
223
223
  if (!exists2) {
224
- throw new Error(`ENOENT: no such file or directory, stat '${path2}'`);
224
+ throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
225
225
  }
226
- return createStatsObject(path2, size, false);
226
+ return createStatsObject(path, size, false);
227
227
  } else if (isDeno) {
228
- const info = await Deno.stat(path2);
228
+ const info = await Deno.stat(path);
229
229
  return createStatsFromDenoFileInfo(info);
230
230
  }
231
231
  throw new Error("Unsupported runtime");
232
232
  }
233
- function statSync(path2) {
233
+ function statSync(path) {
234
234
  if (isNode) {
235
- return fs.statSync(path2);
235
+ return fs.statSync(path);
236
236
  } else if (isBun) {
237
- const file = Bun.file(path2);
237
+ const file = Bun.file(path);
238
238
  const size = file.size;
239
239
  try {
240
240
  file.arrayBuffer();
241
241
  } catch {
242
- throw new Error(`ENOENT: no such file or directory, stat '${path2}'`);
242
+ throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
243
243
  }
244
- return createStatsObject(path2, size, false);
244
+ return createStatsObject(path, size, false);
245
245
  } else if (isDeno) {
246
- const info = Deno.statSync(path2);
246
+ const info = Deno.statSync(path);
247
247
  return createStatsFromDenoFileInfo(info);
248
248
  }
249
249
  throw new Error("Unsupported runtime");
250
250
  }
251
- async function mkdir(path2, options) {
251
+ async function mkdir(path, options) {
252
252
  const opts = typeof options === "number" ? { mode: options } : options || {};
253
253
  if (isNode) {
254
- await fsPromises.mkdir(path2, opts);
254
+ await fsPromises.mkdir(path, opts);
255
255
  } else if (isBun) {
256
- await Deno.mkdir(path2, { recursive: opts.recursive });
256
+ await Deno.mkdir(path, { recursive: opts.recursive });
257
257
  } else if (isDeno) {
258
- await Deno.mkdir(path2, { recursive: opts.recursive });
258
+ await Deno.mkdir(path, { recursive: opts.recursive });
259
259
  }
260
260
  }
261
- function mkdirSync(path2, options) {
261
+ function mkdirSync(path, options) {
262
262
  const opts = typeof options === "number" ? { mode: options } : options || {};
263
263
  if (isNode) {
264
- fs.mkdirSync(path2, opts);
264
+ fs.mkdirSync(path, opts);
265
265
  } else if (isBun) {
266
- Deno.mkdirSync(path2, { recursive: opts.recursive });
266
+ Deno.mkdirSync(path, { recursive: opts.recursive });
267
267
  } else if (isDeno) {
268
- Deno.mkdirSync(path2, { recursive: opts.recursive });
268
+ Deno.mkdirSync(path, { recursive: opts.recursive });
269
269
  }
270
270
  }
271
- async function readdir(path2, options) {
271
+ async function readdir(path, options) {
272
272
  const opts = parseOptions(options, {});
273
273
  if (isNode) {
274
- return fsPromises.readdir(path2, opts);
274
+ return fsPromises.readdir(path, opts);
275
275
  } else if (isBunOrDeno) {
276
- return processDenoEntriesAsync(Deno.readDir(path2), opts.withFileTypes);
276
+ return processDenoEntriesAsync(Deno.readDir(path), opts.withFileTypes);
277
277
  }
278
278
  throw new Error("Unsupported runtime");
279
279
  }
280
- function readdirSync(path2, options) {
280
+ function readdirSync(path, options) {
281
281
  const opts = parseOptions(options, {});
282
282
  if (isNode) {
283
- return fs.readdirSync(path2, opts);
283
+ return fs.readdirSync(path, opts);
284
284
  } else if (isBunOrDeno) {
285
- return processDenoEntries(Deno.readDirSync(path2), opts.withFileTypes);
285
+ return processDenoEntries(Deno.readDirSync(path), opts.withFileTypes);
286
286
  }
287
287
  throw new Error("Unsupported runtime");
288
288
  }
289
- async function unlink(path2) {
289
+ async function unlink(path) {
290
290
  if (isNode) {
291
- return fsPromises.unlink(path2);
291
+ return fsPromises.unlink(path);
292
292
  } else if (isBun) {
293
- await Deno.remove(path2);
293
+ await Deno.remove(path);
294
294
  } else if (isDeno) {
295
- await Deno.remove(path2);
295
+ await Deno.remove(path);
296
296
  }
297
297
  }
298
- function unlinkSync(path2) {
298
+ function unlinkSync(path) {
299
299
  if (isNode) {
300
- fs.unlinkSync(path2);
300
+ fs.unlinkSync(path);
301
301
  } else if (isBun) {
302
- Deno.removeSync(path2);
302
+ Deno.removeSync(path);
303
303
  } else if (isDeno) {
304
- Deno.removeSync(path2);
304
+ Deno.removeSync(path);
305
305
  }
306
306
  }
307
- async function rmdir(path2, options) {
307
+ async function rmdir(path, options) {
308
308
  if (isNode) {
309
- return fsPromises.rmdir(path2, options);
309
+ return fsPromises.rmdir(path, options);
310
310
  } else if (isBun) {
311
- await Deno.remove(path2, { recursive: options?.recursive });
311
+ await Deno.remove(path, { recursive: options?.recursive });
312
312
  } else if (isDeno) {
313
- await Deno.remove(path2, { recursive: options?.recursive });
313
+ await Deno.remove(path, { recursive: options?.recursive });
314
314
  }
315
315
  }
316
- function rmdirSync(path2, options) {
316
+ function rmdirSync(path, options) {
317
317
  if (isNode) {
318
- fs.rmdirSync(path2, options);
318
+ fs.rmdirSync(path, options);
319
319
  } else if (isBun) {
320
- Deno.removeSync(path2, { recursive: options?.recursive });
320
+ Deno.removeSync(path, { recursive: options?.recursive });
321
321
  } else if (isDeno) {
322
- Deno.removeSync(path2, { recursive: options?.recursive });
322
+ Deno.removeSync(path, { recursive: options?.recursive });
323
323
  }
324
324
  }
325
325
  async function rename(oldPath, newPath) {
@@ -358,27 +358,27 @@ function copyFileSync(src, dest, flags) {
358
358
  Deno.copyFileSync(src, dest);
359
359
  }
360
360
  }
361
- async function realpath(path2, options) {
361
+ async function realpath(path, options) {
362
362
  if (isNode) {
363
- return fsPromises.realpath(path2, options);
363
+ return fsPromises.realpath(path, options);
364
364
  } else if (isBun) {
365
- const fs3 = require("fs/promises");
366
- return fs3.realpath(path2, options);
365
+ const fs2 = require("fs/promises");
366
+ return fs2.realpath(path, options);
367
367
  } else if (isDeno) {
368
- return await Deno.realPath(path2);
368
+ return await Deno.realPath(path);
369
369
  }
370
- return path2;
370
+ return path;
371
371
  }
372
- function realpathSync(path2, options) {
372
+ function realpathSync(path, options) {
373
373
  if (isNode) {
374
- return fs.realpathSync(path2, options);
374
+ return fs.realpathSync(path, options);
375
375
  } else if (isBun) {
376
- const fs3 = require("fs");
377
- return fs3.realpathSync(path2, options);
376
+ const fs2 = require("fs");
377
+ return fs2.realpathSync(path, options);
378
378
  } else if (isDeno) {
379
- return Deno.realPathSync(path2);
379
+ return Deno.realPathSync(path);
380
380
  }
381
- return path2;
381
+ return path;
382
382
  }
383
383
  function createStatsObject(_path, size, isDir) {
384
384
  const now = Date.now();
@@ -540,38 +540,38 @@ function getCwd() {
540
540
  }
541
541
  return "/";
542
542
  }
543
- function findLastSeparator(path2) {
544
- return Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\"));
543
+ function findLastSeparator(path) {
544
+ return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
545
545
  }
546
546
  function createPathOps(isWin) {
547
547
  return {
548
548
  sep: getSeparator(isWin),
549
549
  delimiter: isWin ? ";" : ":",
550
- normalize: (path2) => normalizePath(path2, isWin),
550
+ normalize: (path) => normalizePath(path, isWin),
551
551
  join: (...paths) => joinPaths(paths, isWin),
552
552
  resolve: (...paths) => resolvePaths(paths, isWin),
553
- isAbsolute: (path2) => isWin ? isAbsoluteWin(path2) : isAbsolutePosix(path2),
553
+ isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
554
554
  relative: (from, to) => relativePath(from, to, isWin),
555
- dirname: (path2) => getDirname(path2, isWin),
556
- basename: (path2, ext) => getBasename(path2, ext, isWin),
557
- extname: (path2) => getExtname(path2),
558
- parse: (path2) => parsePath(path2, isWin),
555
+ dirname: (path) => getDirname(path, isWin),
556
+ basename: (path, ext) => getBasename(path, ext, isWin),
557
+ extname: (path) => getExtname(path),
558
+ parse: (path) => parsePath(path, isWin),
559
559
  format: (pathObject) => formatPath(pathObject, isWin)
560
560
  };
561
561
  }
562
- function isAbsolutePosix(path2) {
563
- return path2.length > 0 && path2[0] === "/";
562
+ function isAbsolutePosix(path) {
563
+ return path.length > 0 && path[0] === "/";
564
564
  }
565
- function isAbsoluteWin(path2) {
566
- const len = path2.length;
565
+ function isAbsoluteWin(path) {
566
+ const len = path.length;
567
567
  if (len === 0) return false;
568
- const code = path2.charCodeAt(0);
568
+ const code = path.charCodeAt(0);
569
569
  if (code === 47 || code === 92) {
570
570
  return true;
571
571
  }
572
572
  if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
573
- if (len > 2 && path2.charCodeAt(1) === 58) {
574
- const code2 = path2.charCodeAt(2);
573
+ if (len > 2 && path.charCodeAt(1) === 58) {
574
+ const code2 = path.charCodeAt(2);
575
575
  if (code2 === 47 || code2 === 92) {
576
576
  return true;
577
577
  }
@@ -579,12 +579,12 @@ function isAbsoluteWin(path2) {
579
579
  }
580
580
  return false;
581
581
  }
582
- function normalizePath(path2, isWin) {
583
- if (path2.length === 0) return ".";
582
+ function normalizePath(path, isWin) {
583
+ if (path.length === 0) return ".";
584
584
  const separator = getSeparator(isWin);
585
- const isAbsolute2 = isWin ? isAbsoluteWin(path2) : isAbsolutePosix(path2);
586
- const trailingSeparator = path2[path2.length - 1] === separator || isWin && path2[path2.length - 1] === "/";
587
- let normalized = path2.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
585
+ const isAbsolute2 = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
586
+ const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
587
+ let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
588
588
  const parts = normalized.split(separator);
589
589
  const result = [];
590
590
  for (let i = 0; i < parts.length; i++) {
@@ -619,12 +619,12 @@ function joinPaths(paths, isWin) {
619
619
  const separator = getSeparator(isWin);
620
620
  let joined = "";
621
621
  for (let i = 0; i < paths.length; i++) {
622
- const path2 = paths[i];
623
- if (path2 && path2.length > 0) {
622
+ const path = paths[i];
623
+ if (path && path.length > 0) {
624
624
  if (joined.length === 0) {
625
- joined = path2;
625
+ joined = path;
626
626
  } else {
627
- joined += separator + path2;
627
+ joined += separator + path;
628
628
  }
629
629
  }
630
630
  }
@@ -636,9 +636,9 @@ function resolvePaths(paths, isWin) {
636
636
  let resolved = "";
637
637
  let isAbsolute2 = false;
638
638
  for (let i = paths.length - 1; i >= 0 && !isAbsolute2; i--) {
639
- const path2 = paths[i];
640
- if (path2 && path2.length > 0) {
641
- resolved = path2 + (resolved.length > 0 ? separator + resolved : "");
639
+ const path = paths[i];
640
+ if (path && path.length > 0) {
641
+ resolved = path + (resolved.length > 0 ? separator + resolved : "");
642
642
  isAbsolute2 = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
643
643
  }
644
644
  }
@@ -674,51 +674,51 @@ function relativePath(from, to, isWin) {
674
674
  }
675
675
  return result.join(separator) || ".";
676
676
  }
677
- function getDirname(path2, isWin) {
678
- if (path2.length === 0) return ".";
677
+ function getDirname(path, isWin) {
678
+ if (path.length === 0) return ".";
679
679
  const separator = getSeparator(isWin);
680
- const normalized = normalizePath(path2, isWin);
680
+ const normalized = normalizePath(path, isWin);
681
681
  const lastSepIndex = normalized.lastIndexOf(separator);
682
682
  if (lastSepIndex === -1) return ".";
683
683
  if (lastSepIndex === 0) return separator;
684
684
  return normalized.slice(0, lastSepIndex);
685
685
  }
686
- function getBasename(path2, ext, isWin) {
687
- if (path2.length === 0) return "";
688
- const lastSepIndex = isWin ? findLastSeparator(path2) : path2.lastIndexOf("/");
689
- let base = lastSepIndex === -1 ? path2 : path2.slice(lastSepIndex + 1);
686
+ function getBasename(path, ext, isWin) {
687
+ if (path.length === 0) return "";
688
+ const lastSepIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
689
+ let base = lastSepIndex === -1 ? path : path.slice(lastSepIndex + 1);
690
690
  if (ext && base.endsWith(ext)) {
691
691
  base = base.slice(0, base.length - ext.length);
692
692
  }
693
693
  return base;
694
694
  }
695
- function getExtname(path2) {
696
- const lastDotIndex = path2.lastIndexOf(".");
697
- const lastSepIndex = findLastSeparator(path2);
698
- if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path2.length - 1) {
695
+ function getExtname(path) {
696
+ const lastDotIndex = path.lastIndexOf(".");
697
+ const lastSepIndex = findLastSeparator(path);
698
+ if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path.length - 1) {
699
699
  return "";
700
700
  }
701
- return path2.slice(lastDotIndex);
701
+ return path.slice(lastDotIndex);
702
702
  }
703
- function parsePath(path2, isWin) {
703
+ function parsePath(path, isWin) {
704
704
  let root = "";
705
705
  if (isWin) {
706
- if (path2.length >= 2 && path2[1] === ":") {
707
- root = path2.slice(0, 2);
708
- if (path2.length > 2 && (path2[2] === "\\" || path2[2] === "/")) {
706
+ if (path.length >= 2 && path[1] === ":") {
707
+ root = path.slice(0, 2);
708
+ if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
709
709
  root += "\\";
710
710
  }
711
- } else if (path2[0] === "\\" || path2[0] === "/") {
711
+ } else if (path[0] === "\\" || path[0] === "/") {
712
712
  root = "\\";
713
713
  }
714
714
  } else {
715
- if (path2[0] === "/") {
715
+ if (path[0] === "/") {
716
716
  root = "/";
717
717
  }
718
718
  }
719
- const dir = getDirname(path2, isWin);
720
- const base = getBasename(path2, void 0, isWin);
721
- const ext = getExtname(path2);
719
+ const dir = getDirname(path, isWin);
720
+ const base = getBasename(path, void 0, isWin);
721
+ const ext = getExtname(path);
722
722
  const name = ext ? base.slice(0, base.length - ext.length) : base;
723
723
  return { root, dir, base, ext, name };
724
724
  }
@@ -730,8 +730,8 @@ function formatPath(pathObject, isWin) {
730
730
  if (dir === pathObject.root) return dir + base;
731
731
  return dir + separator + base;
732
732
  }
733
- function normalize(path2) {
734
- return normalizePath(path2, isWindows);
733
+ function normalize(path) {
734
+ return normalizePath(path, isWindows);
735
735
  }
736
736
  function join(...paths) {
737
737
  return joinPaths(paths, isWindows);
@@ -739,30 +739,30 @@ function join(...paths) {
739
739
  function resolve(...paths) {
740
740
  return resolvePaths(paths, isWindows);
741
741
  }
742
- function isAbsolute(path2) {
743
- return isWindows ? win32.isAbsolute(path2) : posix.isAbsolute(path2);
742
+ function isAbsolute(path) {
743
+ return isWindows ? win32.isAbsolute(path) : posix.isAbsolute(path);
744
744
  }
745
745
  function relative(from, to) {
746
746
  return relativePath(from, to, isWindows);
747
747
  }
748
- function dirname(path2) {
749
- return getDirname(path2, isWindows);
748
+ function dirname(path) {
749
+ return getDirname(path, isWindows);
750
750
  }
751
- function basename(path2, ext) {
752
- return getBasename(path2, ext, isWindows);
751
+ function basename(path, ext) {
752
+ return getBasename(path, ext, isWindows);
753
753
  }
754
- function extname(path2) {
755
- return getExtname(path2);
754
+ function extname(path) {
755
+ return getExtname(path);
756
756
  }
757
- function parse(path2) {
758
- return parsePath(path2, isWindows);
757
+ function parse(path) {
758
+ return parsePath(path, isWindows);
759
759
  }
760
760
  function format(pathObject) {
761
761
  return formatPath(pathObject, isWindows);
762
762
  }
763
- function toNamespacedPath(path2) {
764
- if (!isWindows || path2.length === 0) return path2;
765
- const resolved = resolve(path2);
763
+ function toNamespacedPath(path) {
764
+ if (!isWindows || path.length === 0) return path;
765
+ const resolved = resolve(path);
766
766
  if (resolved.length >= 3) {
767
767
  if (resolved[0] === "\\") {
768
768
  if (resolved[1] === "\\" && resolved[2] !== "?") {
@@ -772,7 +772,7 @@ function toNamespacedPath(path2) {
772
772
  return "\\\\?\\" + resolved;
773
773
  }
774
774
  }
775
- return path2;
775
+ return path;
776
776
  }
777
777
  function getRuntime2() {
778
778
  return runtime;
@@ -1435,7 +1435,7 @@ var require_package = __commonJS({
1435
1435
  "package.json"(exports2, module2) {
1436
1436
  module2.exports = {
1437
1437
  name: "elit",
1438
- version: "3.2.1",
1438
+ version: "3.2.3",
1439
1439
  description: "Optimized lightweight library for creating DOM elements with reactive state",
1440
1440
  main: "dist/index.js",
1441
1441
  module: "dist/index.mjs",
@@ -1697,12 +1697,12 @@ async function loadConfigFile(configPath) {
1697
1697
  return JSON.parse(content);
1698
1698
  } else if (ext === "ts") {
1699
1699
  try {
1700
- const { build: build3 } = await import("esbuild");
1700
+ const { build: build2 } = await import("esbuild");
1701
1701
  const { tmpdir } = await import("os");
1702
1702
  const { join: join2, dirname: dirname2 } = await Promise.resolve().then(() => (init_path(), path_exports));
1703
1703
  const tempFile = join2(tmpdir(), `elit-config-${Date.now()}.mjs`);
1704
1704
  const configDir = dirname2(configPath);
1705
- await build3({
1705
+ await build2({
1706
1706
  entryPoints: [configPath],
1707
1707
  bundle: true,
1708
1708
  format: "esm",
@@ -1710,43 +1710,9 @@ async function loadConfigFile(configPath) {
1710
1710
  outfile: tempFile,
1711
1711
  write: true,
1712
1712
  target: "es2020",
1713
- // Don't bundle any dependencies, only bundle the config file itself
1714
- packages: "external",
1715
- // Mark all Node.js built-ins as external
1716
- external: [
1717
- "fs",
1718
- "path",
1719
- "os",
1720
- "crypto",
1721
- "http",
1722
- "https",
1723
- "stream",
1724
- "util",
1725
- "url",
1726
- "querystring",
1727
- "events",
1728
- "buffer",
1729
- "child_process",
1730
- "cluster",
1731
- "dgram",
1732
- "dns",
1733
- "net",
1734
- "tls",
1735
- "worker_threads",
1736
- "zlib",
1737
- "readline",
1738
- "repl",
1739
- "vm",
1740
- "assert",
1741
- "console",
1742
- "timers",
1743
- "async_hooks",
1744
- "perf_hooks",
1745
- "module",
1746
- "process",
1747
- "v8",
1748
- "inspector"
1749
- ],
1713
+ // Bundle everything including elit/* so config can use elit modules
1714
+ // Only mark Node.js built-ins as external
1715
+ external: ["node:*"],
1750
1716
  // Use the config directory as the working directory for resolution
1751
1717
  absWorkingDir: configDir
1752
1718
  });
@@ -2159,32 +2125,32 @@ var WebSocketServer = class extends import_events2.EventEmitter {
2159
2125
  // src/chokidar.ts
2160
2126
  var import_events3 = require("events");
2161
2127
  init_runtime();
2162
- function normalizePath2(path2) {
2163
- return path2.replace(/\\/g, "/");
2128
+ function normalizePath2(path) {
2129
+ return path.replace(/\\/g, "/");
2164
2130
  }
2165
- function emitEvent(watcher, eventType, path2) {
2166
- watcher.emit(eventType, path2);
2167
- watcher.emit("all", eventType, path2);
2131
+ function emitEvent(watcher, eventType, path) {
2132
+ watcher.emit(eventType, path);
2133
+ watcher.emit("all", eventType, path);
2168
2134
  }
2169
- function matchesAnyPattern(path2, patterns) {
2170
- return patterns.some((pattern) => matchesPattern(path2, pattern));
2135
+ function matchesAnyPattern(path, patterns) {
2136
+ return patterns.some((pattern) => matchesPattern(path, pattern));
2171
2137
  }
2172
- function handleRenameEvent(watcher, fullPath, fs3) {
2138
+ function handleRenameEvent(watcher, fullPath, fs2) {
2173
2139
  try {
2174
- fs3.statSync(fullPath);
2140
+ fs2.statSync(fullPath);
2175
2141
  emitEvent(watcher, "add", fullPath);
2176
2142
  } catch {
2177
2143
  emitEvent(watcher, "unlink", fullPath);
2178
2144
  }
2179
2145
  }
2180
- function setupFsWatch(watcher, baseDir, patterns, fs3) {
2146
+ function setupFsWatch(watcher, baseDir, patterns, fs2) {
2181
2147
  try {
2182
- const nativeWatcher = fs3.watch(baseDir, { recursive: true }, (eventType, filename) => {
2148
+ const nativeWatcher = fs2.watch(baseDir, { recursive: true }, (eventType, filename) => {
2183
2149
  if (!filename) return;
2184
2150
  const fullPath = normalizePath2(`${baseDir}/${filename}`);
2185
2151
  if (!matchesAnyPattern(fullPath, patterns)) return;
2186
2152
  if (eventType === "rename") {
2187
- handleRenameEvent(watcher, fullPath, fs3);
2153
+ handleRenameEvent(watcher, fullPath, fs2);
2188
2154
  } else if (eventType === "change") {
2189
2155
  emitEvent(watcher, "change", fullPath);
2190
2156
  }
@@ -2216,7 +2182,7 @@ var FSWatcher = class extends import_events3.EventEmitter {
2216
2182
  this._watcher.add(pathArray);
2217
2183
  }
2218
2184
  } else {
2219
- pathArray.forEach((path2) => this._watched.add(path2));
2185
+ pathArray.forEach((path) => this._watched.add(path));
2220
2186
  }
2221
2187
  return this;
2222
2188
  }
@@ -2233,7 +2199,7 @@ var FSWatcher = class extends import_events3.EventEmitter {
2233
2199
  this._watcher.unwatch(pathArray);
2234
2200
  }
2235
2201
  } else {
2236
- pathArray.forEach((path2) => this._watched.delete(path2));
2202
+ pathArray.forEach((path) => this._watched.delete(path));
2237
2203
  }
2238
2204
  return this;
2239
2205
  }
@@ -2260,9 +2226,9 @@ var FSWatcher = class extends import_events3.EventEmitter {
2260
2226
  return this._watcher.getWatched();
2261
2227
  }
2262
2228
  const result = {};
2263
- this._watched.forEach((path2) => {
2264
- const dir = path2.substring(0, path2.lastIndexOf("/")) || ".";
2265
- const file = path2.substring(path2.lastIndexOf("/") + 1);
2229
+ this._watched.forEach((path) => {
2230
+ const dir = path.substring(0, path.lastIndexOf("/")) || ".";
2231
+ const file = path.substring(path.lastIndexOf("/") + 1);
2266
2232
  if (!result[dir]) {
2267
2233
  result[dir] = [];
2268
2234
  }
@@ -2299,19 +2265,19 @@ function watch(paths, options) {
2299
2265
  const watcher = new FSWatcher(options);
2300
2266
  const pathArray = Array.isArray(paths) ? paths : [paths];
2301
2267
  const watchMap = /* @__PURE__ */ new Map();
2302
- pathArray.forEach((path2) => {
2303
- const baseDir = getBaseDirectory(path2);
2268
+ pathArray.forEach((path) => {
2269
+ const baseDir = getBaseDirectory(path);
2304
2270
  if (!watchMap.has(baseDir)) {
2305
2271
  watchMap.set(baseDir, []);
2306
2272
  }
2307
- watchMap.get(baseDir).push(path2);
2273
+ watchMap.get(baseDir).push(path);
2308
2274
  });
2309
2275
  if (runtime === "node") {
2310
- const fs3 = require("fs");
2311
- watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs3));
2276
+ const fs2 = require("fs");
2277
+ watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
2312
2278
  } else if (runtime === "bun") {
2313
- const fs3 = require("fs");
2314
- watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs3));
2279
+ const fs2 = require("fs");
2280
+ watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
2315
2281
  } else if (runtime === "deno") {
2316
2282
  const baseDirs = Array.from(watchMap.keys());
2317
2283
  const allPatterns = Array.from(watchMap.values()).flat();
@@ -2320,18 +2286,18 @@ function watch(paths, options) {
2320
2286
  const denoWatcher = Deno.watchFs(baseDirs);
2321
2287
  for await (const event of denoWatcher) {
2322
2288
  if (watcher["_closed"]) break;
2323
- for (const path2 of event.paths) {
2324
- const normalizedPath = normalizePath2(path2);
2289
+ for (const path of event.paths) {
2290
+ const normalizedPath = normalizePath2(path);
2325
2291
  if (!matchesAnyPattern(normalizedPath, allPatterns)) continue;
2326
2292
  switch (event.kind) {
2327
2293
  case "create":
2328
- emitEvent(watcher, "add", path2);
2294
+ emitEvent(watcher, "add", path);
2329
2295
  break;
2330
2296
  case "modify":
2331
- emitEvent(watcher, "change", path2);
2297
+ emitEvent(watcher, "change", path);
2332
2298
  break;
2333
2299
  case "remove":
2334
- emitEvent(watcher, "unlink", path2);
2300
+ emitEvent(watcher, "unlink", path);
2335
2301
  break;
2336
2302
  }
2337
2303
  }
@@ -2342,7 +2308,7 @@ function watch(paths, options) {
2342
2308
  }
2343
2309
  }
2344
2310
  })();
2345
- pathArray.forEach((path2) => watcher.add(path2));
2311
+ pathArray.forEach((path) => watcher.add(path));
2346
2312
  queueMicrotask(() => watcher.emit("ready"));
2347
2313
  }
2348
2314
  return watcher;
@@ -2432,12 +2398,12 @@ for (const ext in MIME_TYPES) {
2432
2398
  }
2433
2399
  TYPE_TO_EXTENSIONS[type].push(ext);
2434
2400
  }
2435
- function getExtension(path2) {
2436
- const match = /\.([^./\\]+)$/.exec(path2);
2401
+ function getExtension(path) {
2402
+ const match = /\.([^./\\]+)$/.exec(path);
2437
2403
  return match ? match[1].toLowerCase() : "";
2438
2404
  }
2439
- function lookup(path2) {
2440
- const ext = getExtension(path2) || path2.toLowerCase();
2405
+ function lookup(path) {
2406
+ const ext = getExtension(path) || path.toLowerCase();
2441
2407
  return MIME_TYPES[ext] || false;
2442
2408
  }
2443
2409
 
@@ -3084,476 +3050,7 @@ var dom = new DomNode();
3084
3050
  var render = dom.render.bind(dom);
3085
3051
  var renderToString = dom.renderToString.bind(dom);
3086
3052
 
3087
- // src/database.ts
3088
- var import_node_vm = __toESM(require("vm"));
3089
- init_path();
3090
- var import_node_path = __toESM(require("path"));
3091
- var import_node_fs = __toESM(require("fs"));
3092
- var esbuild = __toESM(require("esbuild"));
3093
- var Database = class {
3094
- constructor(config) {
3095
- this._config = {
3096
- dir: resolve(process.cwd(), "databases")
3097
- };
3098
- this._config = { ...this._config, ...config };
3099
- this._registerModules = config.registerModules || {};
3100
- this._ctx = import_node_vm.default.createContext(this._registerModules);
3101
- }
3102
- set config(config) {
3103
- this._config = { ...this._config, ...config };
3104
- }
3105
- register(context) {
3106
- this._registerModules = { ...this._registerModules, ...context };
3107
- this._ctx = import_node_vm.default.createContext(this._registerModules);
3108
- }
3109
- plugin(moduleName, moduleContent) {
3110
- this.register({ [moduleName]: moduleContent });
3111
- }
3112
- resolvePath(fileList, query) {
3113
- const aliases = { "@db": this._config.dir || resolve(process.cwd(), "databases") };
3114
- let resolvedPath = query;
3115
- for (const [alias, target] of Object.entries(aliases)) {
3116
- if (resolvedPath.startsWith(alias + "/")) {
3117
- resolvedPath = resolvedPath.replace(alias, target);
3118
- break;
3119
- }
3120
- }
3121
- resolvedPath = import_node_path.default.normalize(resolvedPath);
3122
- return fileList.find((file) => {
3123
- const normalizedFile = import_node_path.default.normalize(file);
3124
- const fileWithoutExt = normalizedFile.replace(/\.[^/.]+$/, "");
3125
- return normalizedFile === resolvedPath || fileWithoutExt === resolvedPath || normalizedFile === resolvedPath + ".ts" || normalizedFile === resolvedPath + ".js";
3126
- });
3127
- }
3128
- async moduleLinker(specifier, referencingModule) {
3129
- const dbFiles = import_node_fs.default.readdirSync(this._config.dir || resolve(process.cwd(), "databases")).filter((f) => f.endsWith(".ts")).map((f) => import_node_path.default.join(this._config.dir || resolve(process.cwd(), "databases"), f));
3130
- const dbResult = this.resolvePath(dbFiles, specifier);
3131
- if (dbResult) {
3132
- try {
3133
- const actualModule = await import(dbResult);
3134
- const exportNames = Object.keys(actualModule);
3135
- return new import_node_vm.default.SyntheticModule(
3136
- exportNames,
3137
- function() {
3138
- exportNames.forEach((key) => {
3139
- this.setExport(key, actualModule[key]);
3140
- });
3141
- },
3142
- { identifier: specifier, context: referencingModule.context }
3143
- );
3144
- } catch (err) {
3145
- console.error(`Failed to load database module ${specifier}:`, err);
3146
- throw err;
3147
- }
3148
- }
3149
- throw new Error(`Module ${specifier} is not allowed or not found.`);
3150
- }
3151
- async vmRun(code, _options) {
3152
- const logs = [];
3153
- const customConsole = ["log", "error", "warn", "info", "debug", "trace"].reduce((acc, type) => {
3154
- acc[type] = (...args) => logs.push({ type, args });
3155
- return acc;
3156
- }, {});
3157
- const systemBase = {
3158
- update,
3159
- remove,
3160
- rename: rename2,
3161
- read,
3162
- create,
3163
- save
3164
- };
3165
- this.register({
3166
- dbConsole: { ...customConsole, ...systemBase }
3167
- });
3168
- let stringCode;
3169
- if (typeof code === "function") {
3170
- const funcStr = code.toString();
3171
- if (funcStr.includes("=>")) {
3172
- const arrowIndex = funcStr.indexOf("=>");
3173
- let start = arrowIndex + 2;
3174
- while (start < funcStr.length && funcStr[start] === " ") start++;
3175
- if (funcStr[start] === "{") start++;
3176
- let end = funcStr.lastIndexOf("}");
3177
- if (start < end) {
3178
- stringCode = funcStr.substring(start, end);
3179
- } else {
3180
- stringCode = funcStr.substring(start);
3181
- }
3182
- } else if (funcStr.includes("function")) {
3183
- const funcIndex = funcStr.indexOf("function");
3184
- let start = funcIndex + 8;
3185
- while (start < funcStr.length && funcStr[start] === " ") start++;
3186
- if (funcStr[start] === "(") start++;
3187
- if (start < funcStr.length && funcStr[start] !== "(") {
3188
- while (start < funcStr.length && funcStr[start] !== " " && funcStr[start] !== "(") start++;
3189
- }
3190
- if (funcStr[start] === "(") start++;
3191
- while (start < funcStr.length && funcStr[start] === " ") start++;
3192
- if (funcStr[start] === "{") start++;
3193
- const end = funcStr.lastIndexOf("}");
3194
- if (start < end) {
3195
- stringCode = funcStr.substring(start, end);
3196
- } else {
3197
- stringCode = funcStr.substring(start);
3198
- }
3199
- } else {
3200
- stringCode = funcStr;
3201
- }
3202
- stringCode = stringCode.trim();
3203
- let importPos = 0;
3204
- while ((importPos = stringCode.indexOf("import(", importPos)) !== -1) {
3205
- const fromPos = stringCode.indexOf(".from(", importPos);
3206
- if (fromPos === -1) break;
3207
- const quoteStart = stringCode.indexOf("(", fromPos + 7) + 1;
3208
- if (quoteStart === -1) break;
3209
- const quoteChar = stringCode[quoteStart];
3210
- if (quoteChar !== '"' && quoteChar !== "'") break;
3211
- const quoteEnd = stringCode.indexOf(quoteChar, quoteStart + 1);
3212
- if (quoteEnd === -1) break;
3213
- const modulePath = stringCode.substring(quoteStart + 1, quoteEnd);
3214
- const importArgEnd = fromPos - 1;
3215
- const importArgStart = importPos + 7;
3216
- const trimmed = stringCode.substring(importArgStart, importArgEnd).trim();
3217
- let replacement;
3218
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
3219
- const inner = trimmed.slice(1, -1).trim();
3220
- replacement = `import { ${inner} } from "${modulePath}"`;
3221
- } else {
3222
- replacement = `import ${trimmed} from "${modulePath}"`;
3223
- }
3224
- const before = stringCode.substring(0, importPos);
3225
- const after = stringCode.substring(quoteEnd + 2);
3226
- stringCode = before + replacement + after;
3227
- }
3228
- const lines = stringCode.split("\n");
3229
- const trimmedLines = lines.map((line) => line.trim());
3230
- stringCode = trimmedLines.join("\n").trim();
3231
- } else {
3232
- stringCode = code;
3233
- }
3234
- const result = await esbuild.build({
3235
- stdin: {
3236
- contents: stringCode,
3237
- loader: this._config.language || "ts"
3238
- },
3239
- format: "esm",
3240
- target: "es2020",
3241
- write: false,
3242
- bundle: false,
3243
- sourcemap: false
3244
- });
3245
- const js = result.outputFiles[0].text;
3246
- const mod = new import_node_vm.default.SourceTextModule(js, { context: this._ctx, identifier: import_node_path.default.join(this._config.dir || resolve(process.cwd(), "databases"), "virtual-entry.js") });
3247
- await mod.link(this.moduleLinker.bind(this));
3248
- await mod.evaluate();
3249
- return {
3250
- namespace: mod.namespace,
3251
- logs
3252
- };
3253
- }
3254
- /**
3255
- * Execute database code and return results
3256
- */
3257
- async execute(code, options) {
3258
- return await this.vmRun(code, options);
3259
- }
3260
- };
3261
- function create(dbName, code) {
3262
- const DIR = "databases";
3263
- const basePath = process.cwd();
3264
- const baseDir = import_node_path.default.resolve(basePath, DIR);
3265
- const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
3266
- import_node_fs.default.appendFileSync(dbPath, code.toString(), "utf8");
3267
- }
3268
- function read(dbName) {
3269
- const DIR = "databases";
3270
- const basePath = process.cwd();
3271
- const baseDir = import_node_path.default.resolve(basePath, DIR);
3272
- const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
3273
- if (!import_node_fs.default.existsSync(dbPath)) {
3274
- throw new Error(`Database '${dbName}' not found`);
3275
- }
3276
- return import_node_fs.default.readFileSync(dbPath, "utf8");
3277
- }
3278
- function remove(dbName, fnName) {
3279
- const DIR = "databases";
3280
- const basePath = process.cwd();
3281
- const baseDir = import_node_path.default.resolve(basePath, DIR);
3282
- const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
3283
- if (!import_node_fs.default.existsSync(dbPath)) return false;
3284
- if (!fnName) {
3285
- const bak2 = `${dbPath}.bak`;
3286
- try {
3287
- import_node_fs.default.copyFileSync(dbPath, bak2);
3288
- } catch (e) {
3289
- }
3290
- try {
3291
- import_node_fs.default.unlinkSync(dbPath);
3292
- return "Removed successfully";
3293
- } catch (e) {
3294
- return "Removed failed";
3295
- }
3296
- }
3297
- const bak = `${dbPath}.bak`;
3298
- try {
3299
- import_node_fs.default.copyFileSync(dbPath, bak);
3300
- } catch (e) {
3301
- }
3302
- let src = import_node_fs.default.readFileSync(dbPath, "utf8");
3303
- const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
3304
- const startRe = new RegExp(
3305
- `function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
3306
- "m"
3307
- );
3308
- const startMatch = src.match(startRe);
3309
- if (startMatch) {
3310
- const startIdx = startMatch.index;
3311
- const len = src.length;
3312
- const idxCurly = src.indexOf("{", startIdx);
3313
- const idxBracket = src.indexOf("[", startIdx);
3314
- let braceOpen = -1;
3315
- if (idxCurly === -1) braceOpen = idxBracket;
3316
- else if (idxBracket === -1) braceOpen = idxCurly;
3317
- else braceOpen = Math.min(idxCurly, idxBracket);
3318
- if (braceOpen !== -1) {
3319
- const openingChar = src[braceOpen];
3320
- const closingChar = openingChar === "[" ? "]" : "}";
3321
- let i = braceOpen + 1;
3322
- let depth = 1;
3323
- while (i < len && depth > 0) {
3324
- const ch = src[i];
3325
- if (ch === openingChar) depth++;
3326
- else if (ch === closingChar) depth--;
3327
- i++;
3328
- }
3329
- let braceClose = i;
3330
- let endIdx = braceClose;
3331
- if (src.slice(braceClose, braceClose + 1) === ";")
3332
- endIdx = braceClose + 1;
3333
- const before = src.slice(0, startIdx);
3334
- const after = src.slice(endIdx);
3335
- src = before + after;
3336
- } else {
3337
- const semi = src.indexOf(";", startIdx);
3338
- let endIdx = semi !== -1 ? semi + 1 : src.indexOf("\n\n", startIdx);
3339
- if (endIdx === -1) endIdx = len;
3340
- src = src.slice(0, startIdx) + src.slice(endIdx);
3341
- }
3342
- }
3343
- const exportRe = new RegExp(
3344
- `export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
3345
- "g"
3346
- );
3347
- src = src.replace(exportRe, "");
3348
- src = src.replace(/\n{3,}/g, "\n\n");
3349
- import_node_fs.default.writeFileSync(dbPath, src, "utf8");
3350
- return `Removed ${fnName} from database ${dbName}.`;
3351
- }
3352
- function rename2(oldName, newName) {
3353
- const DIR = "databases";
3354
- const basePath = process.cwd();
3355
- const baseDir = import_node_path.default.resolve(basePath, DIR);
3356
- const oldPath = import_node_path.default.join(baseDir, `${oldName}.ts`);
3357
- const newPath = import_node_path.default.join(baseDir, `${newName}.ts`);
3358
- if (!import_node_fs.default.existsSync(oldPath)) {
3359
- return `Error: File '${oldName}.ts' does not exist in the database`;
3360
- }
3361
- if (import_node_fs.default.existsSync(newPath)) {
3362
- return `Error: File '${newName}.ts' already exists in the database`;
3363
- }
3364
- try {
3365
- import_node_fs.default.renameSync(oldPath, newPath);
3366
- return `Successfully renamed '${oldName}.ts' to '${newName}.ts'`;
3367
- } catch (error) {
3368
- return `Error renaming file: ${error instanceof Error ? error.message : String(error)}`;
3369
- }
3370
- }
3371
- function save(dbName, code) {
3372
- const DIR = "databases";
3373
- const basePath = process.cwd();
3374
- const baseDir = import_node_path.default.resolve(basePath, DIR);
3375
- const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
3376
- let fileContent = typeof code === "function" ? code.toString() : code;
3377
- import_node_fs.default.writeFileSync(dbPath, fileContent, "utf8");
3378
- }
3379
- function update(dbName, fnName, code) {
3380
- const DIR = "databases";
3381
- const basePath = process.cwd();
3382
- const baseDir = import_node_path.default.resolve(basePath, DIR);
3383
- const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
3384
- let src;
3385
- if (!import_node_fs.default.existsSync(dbPath)) {
3386
- try {
3387
- import_node_fs.default.writeFileSync(dbPath, "", "utf8");
3388
- return `Created new database file: ${dbPath}`;
3389
- } catch (e) {
3390
- return `Failed to create dbPath file: ${dbPath}`;
3391
- }
3392
- }
3393
- src = import_node_fs.default.readFileSync(dbPath, "utf8");
3394
- const originalSrc = src;
3395
- const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
3396
- const startRe = new RegExp(
3397
- `function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
3398
- "m"
3399
- );
3400
- const startMatch = src.match(startRe);
3401
- let declKind = null;
3402
- if (startMatch) {
3403
- let startIdx = startMatch.index;
3404
- const snippet = src.slice(startIdx, startIdx + 80);
3405
- if (/^function\b/.test(snippet)) declKind = "functionDecl";
3406
- else if (/^class\b/.test(snippet)) declKind = "classDecl";
3407
- else if (/^\b(?:const|let|var)\b/.test(snippet)) declKind = "varAssign";
3408
- }
3409
- let newCode;
3410
- if (typeof code === "function") {
3411
- const fnStr = code.toString();
3412
- if (declKind === "functionDecl") {
3413
- if (/^function\s+\w+/.test(fnStr)) newCode = fnStr;
3414
- else
3415
- newCode = `function ${fnName}${fnStr.replace(
3416
- /^function\s*\(/,
3417
- "("
3418
- )}`;
3419
- } else if (declKind === "classDecl") {
3420
- if (/^class\s+\w+/.test(fnStr)) newCode = fnStr;
3421
- else if (/^class\s*\{/.test(fnStr))
3422
- newCode = fnStr.replace(/^class\s*\{/, `class ${fnName} {`);
3423
- else newCode = `const ${fnName} = ${fnStr};`;
3424
- } else {
3425
- newCode = `const ${fnName} = ${fnStr};`;
3426
- }
3427
- } else {
3428
- newCode = `const ${fnName} = ${valueToCode(code, 0)};`;
3429
- }
3430
- if (startMatch) {
3431
- const startIdx = startMatch.index;
3432
- const idxCurly = src.indexOf("{", startIdx);
3433
- const idxBracket = src.indexOf("[", startIdx);
3434
- let braceOpen = -1;
3435
- if (idxCurly === -1) braceOpen = idxBracket;
3436
- else if (idxBracket === -1) braceOpen = idxCurly;
3437
- else braceOpen = Math.min(idxCurly, idxBracket);
3438
- if (braceOpen === -1) {
3439
- const exportRe = new RegExp(
3440
- `export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
3441
- "m"
3442
- );
3443
- if (exportRe.test(src)) {
3444
- src = src.replace(
3445
- exportRe,
3446
- `${newCode}
3447
-
3448
- export const ${fnName}: any = ${fnName};`
3449
- );
3450
- } else {
3451
- src = src + `
3452
-
3453
- ${newCode}
3454
-
3455
- export const ${fnName}: any = ${fnName};`;
3456
- }
3457
- } else {
3458
- const openingChar = src[braceOpen];
3459
- const closingChar = openingChar === "[" ? "]" : "}";
3460
- let i = braceOpen + 1;
3461
- let depth = 1;
3462
- const len = src.length;
3463
- while (i < len && depth > 0) {
3464
- const ch = src[i];
3465
- if (ch === openingChar) depth++;
3466
- else if (ch === closingChar) depth--;
3467
- i++;
3468
- }
3469
- let braceClose = i;
3470
- let endIdx = braceClose;
3471
- if (src.slice(braceClose, braceClose + 1) === ";")
3472
- endIdx = braceClose + 1;
3473
- const before = src.slice(0, startIdx);
3474
- const after = src.slice(endIdx);
3475
- src = before + newCode + after;
3476
- }
3477
- } else {
3478
- const exportRe = new RegExp(
3479
- `export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
3480
- "m"
3481
- );
3482
- if (exportRe.test(src)) {
3483
- src = src.replace(
3484
- exportRe,
3485
- `${newCode}
3486
-
3487
- export const ${fnName}: any = ${fnName};`
3488
- );
3489
- } else {
3490
- src = src + `
3491
-
3492
- ${newCode}
3493
-
3494
- export const ${fnName}: any = ${fnName};`;
3495
- }
3496
- }
3497
- import_node_fs.default.writeFileSync(dbPath, src, "utf8");
3498
- if (src === originalSrc) {
3499
- return `Saved ${fnName} to database ${dbName}.`;
3500
- } else {
3501
- return `Updated ${dbName} with ${fnName}.`;
3502
- }
3503
- }
3504
- function valueToCode(val, depth = 0) {
3505
- const indentUnit = " ";
3506
- const indent = indentUnit.repeat(depth);
3507
- const indentInner = indentUnit.repeat(depth + 1);
3508
- if (val === null) return "null";
3509
- const t = typeof val;
3510
- if (t === "string") return JSON.stringify(val);
3511
- if (t === "number" || t === "boolean") return String(val);
3512
- if (t === "function") return val.toString();
3513
- if (Array.isArray(val)) {
3514
- if (val.length === 0) return "[]";
3515
- const items = val.map((v) => valueToCode(v, depth + 1));
3516
- return "[\n" + items.map((it) => indentInner + it).join(",\n") + "\n" + indent + "]";
3517
- }
3518
- if (t === "object") {
3519
- const keys = Object.keys(val);
3520
- if (keys.length === 0) return "{}";
3521
- const entries = keys.map((k) => {
3522
- const keyPart = isIdentifier(k) ? k : JSON.stringify(k);
3523
- const v = valueToCode(val[k], depth + 1);
3524
- return indentInner + keyPart + ": " + v;
3525
- });
3526
- return "{\n" + entries.join(",\n") + "\n" + indent + "}";
3527
- }
3528
- return String(val);
3529
- }
3530
- function isIdentifier(key) {
3531
- return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
3532
- }
3533
- var dbConsole = {
3534
- create,
3535
- read,
3536
- remove,
3537
- rename: rename2,
3538
- save,
3539
- update,
3540
- ...console
3541
- };
3542
-
3543
3053
  // src/server.ts
3544
- var ServerDatabase = class {
3545
- constructor() {
3546
- this._db = null;
3547
- }
3548
- async initialize(config) {
3549
- this._db = new Database(config);
3550
- }
3551
- database() {
3552
- return this._db;
3553
- }
3554
- };
3555
- var serverDatabase = new ServerDatabase();
3556
- var database = serverDatabase.database;
3557
3054
  var json = (res, data, status = 200) => (res.writeHead(status, { "Content-Type": "application/json" }), res.end(JSON.stringify(data)));
3558
3055
  var sendError = (res, code, msg) => {
3559
3056
  res.writeHead(code, { "Content-Type": "text/plain" });
@@ -3823,21 +3320,21 @@ function resolveExport(exportValue) {
3823
3320
  }
3824
3321
  return null;
3825
3322
  }
3826
- function rewritePath(path2, pathRewrite) {
3827
- if (!pathRewrite) return path2;
3323
+ function rewritePath(path, pathRewrite) {
3324
+ if (!pathRewrite) return path;
3828
3325
  for (const [from, to] of Object.entries(pathRewrite)) {
3829
3326
  const regex = new RegExp(from);
3830
- if (regex.test(path2)) {
3831
- return path2.replace(regex, to);
3327
+ if (regex.test(path)) {
3328
+ return path.replace(regex, to);
3832
3329
  }
3833
3330
  }
3834
- return path2;
3331
+ return path;
3835
3332
  }
3836
3333
  function createProxyHandler(proxyConfigs) {
3837
3334
  return async (req, res) => {
3838
3335
  const url = req.url || "/";
3839
- const path2 = url.split("?")[0];
3840
- const proxy = proxyConfigs.find((p) => path2.startsWith(p.context));
3336
+ const path = url.split("?")[0];
3337
+ const proxy = proxyConfigs.find((p) => path.startsWith(p.context));
3841
3338
  if (!proxy) return false;
3842
3339
  const { target, changeOrigin, pathRewrite, headers } = proxy;
3843
3340
  try {
@@ -3889,7 +3386,7 @@ function createProxyHandler(proxyConfigs) {
3889
3386
  req.on("end", () => proxyReq.end());
3890
3387
  return true;
3891
3388
  } catch (error) {
3892
- console.error("[Proxy] Invalid proxy configuration for %s:", path2, error);
3389
+ console.error("[Proxy] Invalid proxy configuration for %s:", path, error);
3893
3390
  return false;
3894
3391
  }
3895
3392
  };
@@ -4010,9 +3507,6 @@ function createDevServer(options) {
4010
3507
  if (config.mode === "dev") {
4011
3508
  clearImportMapCache();
4012
3509
  }
4013
- serverDatabase.initialize(config.database ? config.database : {
4014
- dir: resolve(process.cwd(), "databases")
4015
- });
4016
3510
  const clientsToNormalize = config.clients?.length ? config.clients : config.root ? [{ root: config.root, basePath: config.basePath || "", index: config.index, ssr: config.ssr, api: config.api, proxy: config.proxy, mode: config.mode }] : null;
4017
3511
  if (!clientsToNormalize) throw new Error('DevServerOptions must include either "clients" array or "root" directory');
4018
3512
  const normalizedClients = clientsToNormalize.map((client) => {
@@ -4304,8 +3798,8 @@ export default css;
4304
3798
  });
4305
3799
  transpiled = transpiler.transformSync(content.toString());
4306
3800
  } else {
4307
- const { build: build3 } = await import("esbuild");
4308
- const result = await build3({
3801
+ const { build: build2 } = await import("esbuild");
3802
+ const result = await build2({
4309
3803
  stdin: {
4310
3804
  contents: content.toString(),
4311
3805
  loader: ext === ".tsx" ? "tsx" : "ts",
@@ -4322,19 +3816,19 @@ export default css;
4322
3816
  }
4323
3817
  transpiled = transpiled.replace(
4324
3818
  /from\s+["']([^"']+)\.ts(x?)["']/g,
4325
- (_, path2, tsx) => `from "${path2}.js${tsx}"`
3819
+ (_, path, tsx) => `from "${path}.js${tsx}"`
4326
3820
  );
4327
3821
  transpiled = transpiled.replace(
4328
3822
  /import\s+["']([^"']+)\.ts(x?)["']/g,
4329
- (_, path2, tsx) => `import "${path2}.js${tsx}"`
3823
+ (_, path, tsx) => `import "${path}.js${tsx}"`
4330
3824
  );
4331
3825
  transpiled = transpiled.replace(
4332
3826
  /import\s+["']([^"']+\.css)["']/g,
4333
- (_, path2) => `import "${path2}?inline"`
3827
+ (_, path) => `import "${path}?inline"`
4334
3828
  );
4335
3829
  transpiled = transpiled.replace(
4336
3830
  /from\s+["']([^"']+\.css)["']/g,
4337
- (_, path2) => `from "${path2}?inline"`
3831
+ (_, path) => `from "${path}?inline"`
4338
3832
  );
4339
3833
  content = Buffer.from(transpiled);
4340
3834
  mimeType = "application/javascript";
@@ -4496,17 +3990,17 @@ ${elitImportMap}` : elitImportMap;
4496
3990
  (client) => config.watch.map((pattern) => join(client.root, pattern))
4497
3991
  );
4498
3992
  const watcher = watch(watchPaths, {
4499
- ignored: (path2) => config.ignore.some((pattern) => path2.includes(pattern.replace("/**", "").replace("**/", ""))),
3993
+ ignored: (path) => config.ignore.some((pattern) => path.includes(pattern.replace("/**", "").replace("**/", ""))),
4500
3994
  ignoreInitial: true,
4501
3995
  persistent: true
4502
3996
  });
4503
- watcher.on("change", (path2) => {
4504
- if (config.logging) console.log(`[HMR] File changed: ${path2}`);
4505
- const message = JSON.stringify({ type: "update", path: path2, timestamp: Date.now() });
3997
+ watcher.on("change", (path) => {
3998
+ if (config.logging) console.log(`[HMR] File changed: ${path}`);
3999
+ const message = JSON.stringify({ type: "update", path, timestamp: Date.now() });
4506
4000
  wsClients.forEach((client) => client.readyState === 1 /* OPEN */ && client.send(message));
4507
4001
  });
4508
- watcher.on("add", (path2) => config.logging && console.log(`[HMR] File added: ${path2}`));
4509
- watcher.on("unlink", (path2) => config.logging && console.log(`[HMR] File removed: ${path2}`));
4002
+ watcher.on("add", (path) => config.logging && console.log(`[HMR] File added: ${path}`));
4003
+ watcher.on("unlink", (path) => config.logging && console.log(`[HMR] File removed: ${path}`));
4510
4004
  server.setMaxListeners(20);
4511
4005
  server.listen(config.port, config.host, () => {
4512
4006
  if (config.logging) {
@@ -4620,7 +4114,7 @@ var defaultOptions2 = {
4620
4114
  logging: true,
4621
4115
  external: []
4622
4116
  };
4623
- async function build2(options) {
4117
+ async function build(options) {
4624
4118
  const config = { ...defaultOptions2, ...options };
4625
4119
  const startTime = Date.now();
4626
4120
  if (!config.entry) {
@@ -4641,14 +4135,14 @@ async function build2(options) {
4641
4135
  }
4642
4136
  const browserOnlyPlugin = {
4643
4137
  name: "browser-only",
4644
- setup(build3) {
4645
- build3.onResolve({ filter: /^(node:.*|fs|path|http|https|url|os|child_process|net|tls|crypto|stream|util|events|buffer|zlib|readline|process|assert|constants|dns|domain|punycode|querystring|repl|string_decoder|sys|timers|tty|v8|vm)$/ }, () => {
4138
+ setup(build2) {
4139
+ build2.onResolve({ filter: /^(node:.*|fs|path|http|https|url|os|child_process|net|tls|crypto|stream|util|events|buffer|zlib|readline|process|assert|constants|dns|domain|punycode|querystring|repl|string_decoder|sys|timers|tty|v8|vm)$/ }, () => {
4646
4140
  return { path: "node-builtin", external: true, sideEffects: false };
4647
4141
  });
4648
- build3.onResolve({ filter: /^(chokidar|esbuild|mime-types|open|ws|fs\/promises)$/ }, () => {
4142
+ build2.onResolve({ filter: /^(chokidar|esbuild|mime-types|open|ws|fs\/promises)$/ }, () => {
4649
4143
  return { path: "server-dep", external: true, sideEffects: false };
4650
4144
  });
4651
- build3.onLoad({ filter: /[\\/](server|config|cli)\.ts$/ }, () => {
4145
+ build2.onLoad({ filter: /[\\/](server|config|cli)\.ts$/ }, () => {
4652
4146
  return {
4653
4147
  contents: "export {}",
4654
4148
  loader: "js"
@@ -4676,7 +4170,7 @@ async function build2(options) {
4676
4170
  let buildTime;
4677
4171
  let size;
4678
4172
  if (runtime === "node") {
4679
- const { build: esbuild2 } = await import("esbuild");
4173
+ const { build: esbuild } = await import("esbuild");
4680
4174
  const baseOptions = {
4681
4175
  entryPoints: [entryPath],
4682
4176
  bundle: true,
@@ -4703,7 +4197,7 @@ async function build2(options) {
4703
4197
  if (config.resolve?.alias) {
4704
4198
  esbuildOptions.resolve = { alias: config.resolve.alias };
4705
4199
  }
4706
- result = await esbuild2(esbuildOptions);
4200
+ result = await esbuild(esbuildOptions);
4707
4201
  ({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
4708
4202
  } else if (runtime === "bun") {
4709
4203
  result = await Bun.build({
@@ -4831,7 +4325,7 @@ function setupShutdownHandlers(closeFunc) {
4831
4325
  }
4832
4326
  async function executeBuild(options) {
4833
4327
  try {
4834
- await build2(options);
4328
+ await build(options);
4835
4329
  } catch (error) {
4836
4330
  process.exit(1);
4837
4331
  }
@@ -4924,7 +4418,7 @@ async function runBuild(args) {
4924
4418
  validateEntry(buildConfig.entry, i);
4925
4419
  console.log(`[${i + 1}/${builds.length}] Building ${buildConfig.entry}...`);
4926
4420
  try {
4927
- await build2(buildConfig);
4421
+ await build(buildConfig);
4928
4422
  } catch (error) {
4929
4423
  console.error(`Build #${i + 1} failed`);
4930
4424
  process.exit(1);