elit 3.5.3 → 3.5.5

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/server.mjs CHANGED
@@ -55085,199 +55085,8 @@ var WebSocketServer = class extends EventEmitter3 {
55085
55085
  };
55086
55086
 
55087
55087
  // src/chokidar.ts
55088
- init_runtime();
55089
- import { EventEmitter as EventEmitter4 } from "events";
55090
- function normalizePath(path) {
55091
- return path.replace(/\\/g, "/");
55092
- }
55093
- function emitEvent(watcher, eventType, path) {
55094
- watcher.emit(eventType, path);
55095
- watcher.emit("all", eventType, path);
55096
- }
55097
- function matchesAnyPattern(path, patterns) {
55098
- return patterns.some((pattern) => matchesPattern(path, pattern));
55099
- }
55100
- function handleRenameEvent(watcher, fullPath, fs2) {
55101
- try {
55102
- fs2.statSync(fullPath);
55103
- emitEvent(watcher, "add", fullPath);
55104
- } catch {
55105
- emitEvent(watcher, "unlink", fullPath);
55106
- }
55107
- }
55108
- function setupFsWatch(watcher, baseDir, patterns, fs2) {
55109
- try {
55110
- const nativeWatcher = fs2.watch(baseDir, { recursive: true }, (eventType, filename) => {
55111
- if (!filename) return;
55112
- const fullPath = normalizePath(`${baseDir}/${filename}`);
55113
- if (!matchesAnyPattern(fullPath, patterns)) return;
55114
- if (eventType === "rename") {
55115
- handleRenameEvent(watcher, fullPath, fs2);
55116
- } else if (eventType === "change") {
55117
- emitEvent(watcher, "change", fullPath);
55118
- }
55119
- });
55120
- watcher._setWatcher(nativeWatcher);
55121
- watcher["_watched"].add(baseDir);
55122
- queueMicrotask(() => watcher.emit("ready"));
55123
- } catch (error) {
55124
- watcher.emit("error", error);
55125
- }
55126
- }
55127
- var FSWatcher = class extends EventEmitter4 {
55128
- constructor(options) {
55129
- super();
55130
- this._closed = false;
55131
- this._watched = /* @__PURE__ */ new Set();
55132
- this.options = options || {};
55133
- }
55134
- /**
55135
- * Add paths to be watched
55136
- */
55137
- add(paths) {
55138
- if (this._closed) {
55139
- throw new Error("Watcher has been closed");
55140
- }
55141
- const pathArray = Array.isArray(paths) ? paths : [paths];
55142
- if (runtime === "node") {
55143
- if (this._watcher) {
55144
- this._watcher.add(pathArray);
55145
- }
55146
- } else {
55147
- pathArray.forEach((path) => this._watched.add(path));
55148
- }
55149
- return this;
55150
- }
55151
- /**
55152
- * Stop watching paths
55153
- */
55154
- unwatch(paths) {
55155
- if (this._closed) {
55156
- return this;
55157
- }
55158
- const pathArray = Array.isArray(paths) ? paths : [paths];
55159
- if (runtime === "node") {
55160
- if (this._watcher) {
55161
- this._watcher.unwatch(pathArray);
55162
- }
55163
- } else {
55164
- pathArray.forEach((path) => this._watched.delete(path));
55165
- }
55166
- return this;
55167
- }
55168
- /**
55169
- * Close the watcher
55170
- */
55171
- async close() {
55172
- if (this._closed) {
55173
- return;
55174
- }
55175
- this._closed = true;
55176
- if (runtime === "node") {
55177
- if (this._watcher) {
55178
- await this._watcher.close();
55179
- }
55180
- }
55181
- this.removeAllListeners();
55182
- }
55183
- /**
55184
- * Get watched paths
55185
- */
55186
- getWatched() {
55187
- if (runtime === "node" && this._watcher) {
55188
- return this._watcher.getWatched();
55189
- }
55190
- const result2 = {};
55191
- this._watched.forEach((path) => {
55192
- const dir = path.substring(0, path.lastIndexOf("/")) || ".";
55193
- const file = path.substring(path.lastIndexOf("/") + 1);
55194
- if (!result2[dir]) {
55195
- result2[dir] = [];
55196
- }
55197
- result2[dir].push(file);
55198
- });
55199
- return result2;
55200
- }
55201
- /**
55202
- * Internal method to set native watcher
55203
- * @internal
55204
- */
55205
- _setWatcher(watcher) {
55206
- this._watcher = watcher;
55207
- }
55208
- };
55209
- function getBaseDirectory(pattern) {
55210
- const parts = pattern.split(/[\\\/]/);
55211
- let baseDir = "";
55212
- for (const part of parts) {
55213
- if (part.includes("*") || part.includes("?")) {
55214
- break;
55215
- }
55216
- baseDir = baseDir ? `${baseDir}/${part}` : part;
55217
- }
55218
- return baseDir || ".";
55219
- }
55220
- function matchesPattern(filePath, pattern) {
55221
- const regexPattern = normalizePath(pattern).replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\?/g, ".");
55222
- const regex = new RegExp(`^${regexPattern}$`);
55223
- const normalizedPath = normalizePath(filePath);
55224
- return regex.test(normalizedPath);
55225
- }
55226
- function watch(paths, options) {
55227
- const watcher = new FSWatcher(options);
55228
- const pathArray = Array.isArray(paths) ? paths : [paths];
55229
- const watchMap = /* @__PURE__ */ new Map();
55230
- pathArray.forEach((path) => {
55231
- const baseDir = getBaseDirectory(path);
55232
- if (!watchMap.has(baseDir)) {
55233
- watchMap.set(baseDir, []);
55234
- }
55235
- watchMap.get(baseDir).push(path);
55236
- });
55237
- if (runtime === "node") {
55238
- const fs2 = __require("fs");
55239
- watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
55240
- } else if (runtime === "bun") {
55241
- const fs2 = __require("fs");
55242
- watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
55243
- } else if (runtime === "deno") {
55244
- const baseDirs = Array.from(watchMap.keys());
55245
- const allPatterns = Array.from(watchMap.values()).flat();
55246
- (async () => {
55247
- try {
55248
- const denoWatcher = Deno.watchFs(baseDirs);
55249
- for await (const event of denoWatcher) {
55250
- if (watcher["_closed"]) break;
55251
- for (const path of event.paths) {
55252
- const normalizedPath = normalizePath(path);
55253
- if (!matchesAnyPattern(normalizedPath, allPatterns)) continue;
55254
- switch (event.kind) {
55255
- case "create":
55256
- emitEvent(watcher, "add", path);
55257
- break;
55258
- case "modify":
55259
- emitEvent(watcher, "change", path);
55260
- break;
55261
- case "remove":
55262
- emitEvent(watcher, "unlink", path);
55263
- break;
55264
- }
55265
- }
55266
- }
55267
- } catch (error) {
55268
- if (!watcher["_closed"]) {
55269
- watcher.emit("error", error);
55270
- }
55271
- }
55272
- })();
55273
- pathArray.forEach((path) => watcher.add(path));
55274
- queueMicrotask(() => watcher.emit("ready"));
55275
- }
55276
- return watcher;
55277
- }
55278
-
55279
- // src/server.ts
55280
55088
  init_fs();
55089
+ import { EventEmitter as EventEmitter4 } from "events";
55281
55090
 
55282
55091
  // src/path.ts
55283
55092
  init_runtime();
@@ -55299,7 +55108,7 @@ function createPathOps(isWin) {
55299
55108
  return {
55300
55109
  sep: getSeparator(isWin),
55301
55110
  delimiter: isWin ? ";" : ":",
55302
- normalize: (path) => normalizePath2(path, isWin),
55111
+ normalize: (path) => normalizePath(path, isWin),
55303
55112
  join: (...paths) => joinPaths(paths, isWin),
55304
55113
  resolve: (...paths) => resolvePaths(paths, isWin),
55305
55114
  isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
@@ -55342,7 +55151,7 @@ var isWindows = (() => {
55342
55151
  var sep = isWindows ? "\\" : "/";
55343
55152
  var posix = createPathOps(false);
55344
55153
  var win32 = createPathOps(true);
55345
- function normalizePath2(path, isWin) {
55154
+ function normalizePath(path, isWin) {
55346
55155
  if (path.length === 0) return ".";
55347
55156
  const separator = getSeparator(isWin);
55348
55157
  const isAbsolute = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
@@ -55392,7 +55201,7 @@ function joinPaths(paths, isWin) {
55392
55201
  }
55393
55202
  }
55394
55203
  if (joined.length === 0) return ".";
55395
- return normalizePath2(joined, isWin);
55204
+ return normalizePath(joined, isWin);
55396
55205
  }
55397
55206
  function resolvePaths(paths, isWin) {
55398
55207
  const separator = getSeparator(isWin);
@@ -55409,7 +55218,7 @@ function resolvePaths(paths, isWin) {
55409
55218
  const cwd = getCwd();
55410
55219
  resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
55411
55220
  }
55412
- return normalizePath2(resolved, isWin);
55221
+ return normalizePath(resolved, isWin);
55413
55222
  }
55414
55223
  function relativePath(from, to, isWin) {
55415
55224
  from = resolvePaths([from], isWin);
@@ -55440,7 +55249,7 @@ function relativePath(from, to, isWin) {
55440
55249
  function getDirname(path, isWin) {
55441
55250
  if (path.length === 0) return ".";
55442
55251
  const separator = getSeparator(isWin);
55443
- const normalized = normalizePath2(path, isWin);
55252
+ const normalized = normalizePath(path, isWin);
55444
55253
  const lastSepIndex = normalized.lastIndexOf(separator);
55445
55254
  if (lastSepIndex === -1) return ".";
55446
55255
  if (lastSepIndex === 0) return separator;
@@ -55494,7 +55303,7 @@ function formatPath(pathObject, isWin) {
55494
55303
  return dir + separator + base;
55495
55304
  }
55496
55305
  function normalize(path) {
55497
- return normalizePath2(path, isWindows);
55306
+ return normalizePath(path, isWindows);
55498
55307
  }
55499
55308
  function join(...paths) {
55500
55309
  return joinPaths(paths, isWindows);
@@ -55505,10 +55314,224 @@ function resolve(...paths) {
55505
55314
  function relative(from, to) {
55506
55315
  return relativePath(from, to, isWindows);
55507
55316
  }
55317
+ function dirname(path) {
55318
+ return getDirname(path, isWindows);
55319
+ }
55508
55320
  function extname(path) {
55509
55321
  return getExtname(path);
55510
55322
  }
55511
55323
 
55324
+ // src/chokidar.ts
55325
+ init_runtime();
55326
+ function normalizePath2(path) {
55327
+ return path.replace(/\\/g, "/");
55328
+ }
55329
+ function emitEvent(watcher, eventType, path) {
55330
+ watcher.emit(eventType, path);
55331
+ watcher.emit("all", eventType, path);
55332
+ }
55333
+ function matchesAnyPattern(path, patterns) {
55334
+ return patterns.some((pattern) => matchesPattern(path, pattern));
55335
+ }
55336
+ function handleRenameEvent(watcher, fullPath, fs2) {
55337
+ try {
55338
+ fs2.statSync(fullPath);
55339
+ emitEvent(watcher, "add", fullPath);
55340
+ } catch {
55341
+ emitEvent(watcher, "unlink", fullPath);
55342
+ }
55343
+ }
55344
+ function setupFsWatch(watcher, baseDir, patterns, fs2) {
55345
+ try {
55346
+ const nativeWatcher = fs2.watch(baseDir, { recursive: true }, (eventType, filename) => {
55347
+ if (!filename) return;
55348
+ const fullPath = normalizePath2(`${baseDir}/${filename}`);
55349
+ if (!matchesAnyPattern(fullPath, patterns)) return;
55350
+ if (eventType === "rename") {
55351
+ handleRenameEvent(watcher, fullPath, fs2);
55352
+ } else if (eventType === "change") {
55353
+ emitEvent(watcher, "change", fullPath);
55354
+ }
55355
+ });
55356
+ watcher._setWatcher(nativeWatcher);
55357
+ watcher["_watched"].add(baseDir);
55358
+ queueMicrotask(() => watcher.emit("ready"));
55359
+ } catch (error) {
55360
+ watcher.emit("error", error);
55361
+ }
55362
+ }
55363
+ var FSWatcher = class extends EventEmitter4 {
55364
+ constructor(options) {
55365
+ super();
55366
+ this._closed = false;
55367
+ this._watched = /* @__PURE__ */ new Set();
55368
+ this.options = options || {};
55369
+ }
55370
+ /**
55371
+ * Add paths to be watched
55372
+ */
55373
+ add(paths) {
55374
+ if (this._closed) {
55375
+ throw new Error("Watcher has been closed");
55376
+ }
55377
+ const pathArray = Array.isArray(paths) ? paths : [paths];
55378
+ if (runtime === "node") {
55379
+ if (this._watcher) {
55380
+ this._watcher.add(pathArray);
55381
+ }
55382
+ } else {
55383
+ pathArray.forEach((path) => this._watched.add(path));
55384
+ }
55385
+ return this;
55386
+ }
55387
+ /**
55388
+ * Stop watching paths
55389
+ */
55390
+ unwatch(paths) {
55391
+ if (this._closed) {
55392
+ return this;
55393
+ }
55394
+ const pathArray = Array.isArray(paths) ? paths : [paths];
55395
+ if (runtime === "node") {
55396
+ if (this._watcher) {
55397
+ this._watcher.unwatch(pathArray);
55398
+ }
55399
+ } else {
55400
+ pathArray.forEach((path) => this._watched.delete(path));
55401
+ }
55402
+ return this;
55403
+ }
55404
+ /**
55405
+ * Close the watcher
55406
+ */
55407
+ async close() {
55408
+ if (this._closed) {
55409
+ return;
55410
+ }
55411
+ this._closed = true;
55412
+ if (runtime === "node") {
55413
+ if (this._watcher) {
55414
+ await this._watcher.close();
55415
+ }
55416
+ }
55417
+ this.removeAllListeners();
55418
+ }
55419
+ /**
55420
+ * Get watched paths
55421
+ */
55422
+ getWatched() {
55423
+ if (runtime === "node" && this._watcher) {
55424
+ return this._watcher.getWatched();
55425
+ }
55426
+ const result2 = {};
55427
+ this._watched.forEach((path) => {
55428
+ const dir = path.substring(0, path.lastIndexOf("/")) || ".";
55429
+ const file = path.substring(path.lastIndexOf("/") + 1);
55430
+ if (!result2[dir]) {
55431
+ result2[dir] = [];
55432
+ }
55433
+ result2[dir].push(file);
55434
+ });
55435
+ return result2;
55436
+ }
55437
+ /**
55438
+ * Internal method to set native watcher
55439
+ * @internal
55440
+ */
55441
+ _setWatcher(watcher) {
55442
+ this._watcher = watcher;
55443
+ }
55444
+ };
55445
+ function getBaseDirectory(pattern) {
55446
+ const normalizedPattern = normalizePath2(pattern);
55447
+ const parts = normalizedPattern.split(/[\\\/]/);
55448
+ let baseDir = "";
55449
+ let sawGlob = false;
55450
+ for (const part of parts) {
55451
+ if (part.includes("*") || part.includes("?")) {
55452
+ sawGlob = true;
55453
+ break;
55454
+ }
55455
+ baseDir = baseDir ? `${baseDir}/${part}` : part;
55456
+ }
55457
+ if (sawGlob) {
55458
+ return baseDir || ".";
55459
+ }
55460
+ if (normalizedPattern && existsSync(normalizedPattern)) {
55461
+ try {
55462
+ return statSync(normalizedPattern).isDirectory() ? normalizedPattern : normalizePath2(dirname(normalizedPattern)) || ".";
55463
+ } catch {
55464
+ return normalizePath2(dirname(normalizedPattern)) || ".";
55465
+ }
55466
+ }
55467
+ const lastSegment = parts[parts.length - 1] || "";
55468
+ if (lastSegment.includes(".") && !lastSegment.startsWith(".")) {
55469
+ return normalizePath2(dirname(normalizedPattern)) || ".";
55470
+ }
55471
+ return normalizedPattern || ".";
55472
+ }
55473
+ function matchesPattern(filePath, pattern) {
55474
+ const regexPattern = normalizePath2(pattern).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\?/g, ".");
55475
+ const regex = new RegExp(`^${regexPattern}$`);
55476
+ const normalizedPath = normalizePath2(filePath);
55477
+ return regex.test(normalizedPath);
55478
+ }
55479
+ function watch(paths, options) {
55480
+ const watcher = new FSWatcher(options);
55481
+ const pathArray = Array.isArray(paths) ? paths : [paths];
55482
+ const watchMap = /* @__PURE__ */ new Map();
55483
+ pathArray.forEach((path) => {
55484
+ const baseDir = getBaseDirectory(path);
55485
+ if (!watchMap.has(baseDir)) {
55486
+ watchMap.set(baseDir, []);
55487
+ }
55488
+ watchMap.get(baseDir).push(path);
55489
+ });
55490
+ if (runtime === "node") {
55491
+ const fs2 = __require("fs");
55492
+ watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
55493
+ } else if (runtime === "bun") {
55494
+ const fs2 = __require("fs");
55495
+ watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
55496
+ } else if (runtime === "deno") {
55497
+ const baseDirs = Array.from(watchMap.keys());
55498
+ const allPatterns = Array.from(watchMap.values()).flat();
55499
+ (async () => {
55500
+ try {
55501
+ const denoWatcher = Deno.watchFs(baseDirs);
55502
+ for await (const event of denoWatcher) {
55503
+ if (watcher["_closed"]) break;
55504
+ for (const path of event.paths) {
55505
+ const normalizedPath = normalizePath2(path);
55506
+ if (!matchesAnyPattern(normalizedPath, allPatterns)) continue;
55507
+ switch (event.kind) {
55508
+ case "create":
55509
+ emitEvent(watcher, "add", path);
55510
+ break;
55511
+ case "modify":
55512
+ emitEvent(watcher, "change", path);
55513
+ break;
55514
+ case "remove":
55515
+ emitEvent(watcher, "unlink", path);
55516
+ break;
55517
+ }
55518
+ }
55519
+ }
55520
+ } catch (error) {
55521
+ if (!watcher["_closed"]) {
55522
+ watcher.emit("error", error);
55523
+ }
55524
+ }
55525
+ })();
55526
+ pathArray.forEach((path) => watcher.add(path));
55527
+ queueMicrotask(() => watcher.emit("ready"));
55528
+ }
55529
+ return watcher;
55530
+ }
55531
+
55532
+ // src/server.ts
55533
+ init_fs();
55534
+
55512
55535
  // src/mime-types.ts
55513
55536
  init_runtime();
55514
55537
  var MIME_TYPES = {